From cf5e7001a5e17d2cbdeaec83dc0930e9db092c51 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 19 Aug 2023 14:37:41 +0200 Subject: [PATCH] DashPodHistoryActivity: toolbar --- .../omnipod-dash/src/main/AndroidManifest.xml | 2 +- .../omnipod/dash/ui/DashPodHistoryActivity.kt | 37 +++++++++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/pump/omnipod-dash/src/main/AndroidManifest.xml b/pump/omnipod-dash/src/main/AndroidManifest.xml index 8b0969edc3..c34c2b807a 100644 --- a/pump/omnipod-dash/src/main/AndroidManifest.xml +++ b/pump/omnipod-dash/src/main/AndroidManifest.xml @@ -23,6 +23,6 @@ + android:theme="@style/AppTheme" /> \ No newline at end of file diff --git a/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt b/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt index dc66e19bd9..8565ddf6f6 100644 --- a/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt +++ b/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodHistoryActivity.kt @@ -3,12 +3,16 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.ui import android.os.Bundle import android.os.SystemClock import android.view.LayoutInflater +import android.view.Menu +import android.view.MenuInflater +import android.view.MenuItem import android.view.View import android.view.ViewGroup import android.widget.AdapterView import android.widget.ArrayAdapter import android.widget.Spinner import android.widget.TextView +import androidx.core.view.MenuProvider import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType @@ -44,8 +48,8 @@ class DashPodHistoryActivity : TranslatedDaggerAppCompatActivity() { private var statusView: TextView? = null private var recyclerView: RecyclerView? = null private var linearLayoutManager: LinearLayoutManager? = null - private val fullHistoryList: MutableList = ArrayList() - private val filteredHistoryList: MutableList = ArrayList() + private val fullHistoryList: MutableList = ArrayList() + private val filteredHistoryList: MutableList = ArrayList() private var recyclerViewAdapter: RecyclerViewAdapter? = null private var manualChange = false private var typeListFull: List? = null @@ -147,6 +151,10 @@ class DashPodHistoryActivity : TranslatedDaggerAppCompatActivity() { setContentView(R.layout.omnipod_dash_pod_history_activity) prepareData() + title = rh.gs(info.nightscout.androidaps.plugins.pump.omnipod.common.R.string.omnipod_common_pod_management_button_pod_history) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + supportActionBar?.setDisplayShowHomeEnabled(true) + recyclerView = findViewById(R.id.omnipod_history_recyclerview) recyclerViewAdapter = RecyclerViewAdapter(filteredHistoryList) linearLayoutManager = LinearLayoutManager(this) @@ -178,6 +186,21 @@ class DashPodHistoryActivity : TranslatedDaggerAppCompatActivity() { } } } + + // Add menu items without overriding methods in the Activity + addMenuProvider(object : MenuProvider { + override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {} + + override fun onMenuItemSelected(menuItem: MenuItem): Boolean = + when (menuItem.itemId) { + android.R.id.home -> { + onBackPressedDispatcher.onBackPressed() + true + } + + else -> false + } + }) } private fun getTypeList(list: List): List { @@ -217,8 +240,8 @@ class DashPodHistoryActivity : TranslatedDaggerAppCompatActivity() { } } - private fun setTextViewColor(check_result: Boolean, textview: TextView, record: HistoryRecord) { - if (check_result && !record.isSuccess()) { + private fun setTextViewColor(checkResult: Boolean, textview: TextView, record: HistoryRecord) { + if (checkResult && !record.isSuccess()) { // Record says not success textview.setTextColor(rh.gac(textview.context, info.nightscout.core.ui.R.attr.omniYellowColor)) return @@ -258,7 +281,7 @@ class DashPodHistoryActivity : TranslatedDaggerAppCompatActivity() { private fun setType(record: HistoryRecord, typeView: TextView) { typeView.text = rh.gs(record.commandType.resourceId) // Set some color, include result - setTextViewColor(check_result = true, typeView, record) + setTextViewColor(checkResult = true, typeView, record) } private fun setValue(historyEntry: HistoryRecord, valueView: TextView) { @@ -295,13 +318,13 @@ class DashPodHistoryActivity : TranslatedDaggerAppCompatActivity() { "" } // Set some color - setTextViewColor(check_result = false, valueView, historyEntry) + setTextViewColor(checkResult = false, valueView, historyEntry) } private fun setAmount(historyEntry: HistoryRecord, amountView: TextView) { amountView.text = historyEntry.totalAmountDelivered?.let { rh.gs(R.string.omnipod_common_history_total_delivered, it) } // Set some color - setTextViewColor(check_result = false, amountView, historyEntry) + setTextViewColor(checkResult = false, amountView, historyEntry) } override fun getItemCount(): Int {