From 510e640673104049c832dcfab35f2b56a6b75679 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 19 Aug 2023 10:41:35 +0200 Subject: [PATCH] ComboV2PairingActivity: toolbar --- pump/combov2/src/main/AndroidManifest.xml | 2 +- .../activities/ComboV2PairingActivity.kt | 30 ++++++++++++++--- .../res/layout/combov2_pairing_activity.xml | 33 ------------------- 3 files changed, 27 insertions(+), 38 deletions(-) diff --git a/pump/combov2/src/main/AndroidManifest.xml b/pump/combov2/src/main/AndroidManifest.xml index b7420b34af..5df8536ab0 100644 --- a/pump/combov2/src/main/AndroidManifest.xml +++ b/pump/combov2/src/main/AndroidManifest.xml @@ -8,6 +8,6 @@ + android:theme="@style/AppTheme" /> diff --git a/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/activities/ComboV2PairingActivity.kt b/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/activities/ComboV2PairingActivity.kt index cc5c220f89..6add815fd0 100644 --- a/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/activities/ComboV2PairingActivity.kt +++ b/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/activities/ComboV2PairingActivity.kt @@ -7,12 +7,16 @@ import android.os.Build import android.os.Bundle import android.text.Editable import android.text.TextWatcher +import android.view.Menu +import android.view.MenuInflater +import android.view.MenuItem import android.view.View import androidx.activity.ComponentActivity import androidx.activity.OnBackPressedCallback import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts import androidx.core.content.ContextCompat +import androidx.core.view.MenuProvider import androidx.databinding.DataBindingUtil import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope @@ -113,6 +117,10 @@ class ComboV2PairingActivity : TranslatedDaggerAppCompatActivity() { val binding: Combov2PairingActivityBinding = DataBindingUtil.setContentView( this, R.layout.combov2_pairing_activity) + title = rh.gs(R.string.combov2_pair_with_pump_title) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + supportActionBar?.setDisplayShowHomeEnabled(true) + val thisActivity = this // Set the pairing sections to initially show the "not initialized" one @@ -194,6 +202,20 @@ class ComboV2PairingActivity : TranslatedDaggerAppCompatActivity() { finish() } }) + // 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 + } + }) } override fun onDestroy() { @@ -342,8 +364,8 @@ class ComboV2PairingActivity : TranslatedDaggerAppCompatActivity() { return@setOnClickListener } runBlocking { - val PIN = PairingPIN(pinString.map { it - '0' }.toIntArray()) - combov2Plugin.providePairingPIN(PIN) + val pin = PairingPIN(pinString.map { it - '0' }.toIntArray()) + combov2Plugin.providePairingPIN(pin) } } @@ -383,14 +405,14 @@ class ComboV2PairingActivity : TranslatedDaggerAppCompatActivity() { } } - binding.combov2CurrentPairingStepDesc.text = when (val progStage = stage) { + binding.combov2CurrentPairingStepDesc.text = when (stage) { BasicProgressStage.ScanningForPumpStage -> rh.gs(R.string.combov2_scanning_for_pump) is BasicProgressStage.EstablishingBtConnection -> { rh.gs( R.string.combov2_establishing_bt_connection, - progStage.currentAttemptNr + stage.currentAttemptNr ) } diff --git a/pump/combov2/src/main/res/layout/combov2_pairing_activity.xml b/pump/combov2/src/main/res/layout/combov2_pairing_activity.xml index 40a9ff7571..6827535276 100644 --- a/pump/combov2/src/main/res/layout/combov2_pairing_activity.xml +++ b/pump/combov2/src/main/res/layout/combov2_pairing_activity.xml @@ -1,6 +1,5 @@ - - - - - - - -