Resolve onBackPressed deprecation

This commit is contained in:
Milos Kozak 2023-08-14 16:28:29 +02:00
parent 896acb94b5
commit 968c9fb4c1
14 changed files with 223 additions and 169 deletions

View file

@ -21,6 +21,7 @@ import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.TextView
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.widget.Toolbar
import androidx.core.view.GravityCompat
@ -151,7 +152,7 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
.subscribe({ processPreferenceChange(it) }, fabricPrivacy::logException)
if (startWizard() && !isRunningRealPumpTest()) {
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
startActivity(Intent(this, SetupWizardActivity::class.java))
startActivity(Intent(this, SetupWizardActivity::class.java).setAction("info.nightscout.androidaps.MainActivity"))
})
}
androidPermission.notifyForStoragePermission(this)
@ -163,6 +164,17 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
androidPermission.notifyForBtConnectPermission(this)
}
passwordResetCheck(this)
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (binding.mainDrawerLayout.isDrawerOpen(GravityCompat.START))
binding.mainDrawerLayout.closeDrawers()
else if (menuOpen)
menu?.close()
else if (binding.mainPager.currentItem != 0)
binding.mainPager.currentItem = 0
else finish()
}
})
}
private fun checkPluginPreferences(viewPager: ViewPager2) {
@ -219,9 +231,11 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
menuItem.setIcon(info.nightscout.core.ui.R.drawable.ic_settings)
}
menuItem.setOnMenuItemClickListener {
val intent = Intent(this, SingleFragmentActivity::class.java)
intent.putExtra("plugin", activePlugin.getPluginsList().indexOf(p))
startActivity(intent)
startActivity(
Intent(this, SingleFragmentActivity::class.java)
.setAction("info.nightscout.androidaps.MainActivity")
.putExtra("plugin", activePlugin.getPluginsList().indexOf(p))
)
binding.mainDrawerLayout.closeDrawers()
true
}
@ -318,26 +332,28 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
when (item.itemId) {
R.id.nav_preferences -> {
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
val i = Intent(this, PreferencesActivity::class.java)
i.putExtra("id", -1)
startActivity(i)
startActivity(
Intent(this, PreferencesActivity::class.java)
.setAction("info.nightscout.androidaps.MainActivity")
.putExtra("id", -1)
)
})
return true
}
R.id.nav_historybrowser -> {
startActivity(Intent(this, HistoryBrowseActivity::class.java))
startActivity(Intent(this, HistoryBrowseActivity::class.java).setAction("info.nightscout.androidaps.MainActivity"))
return true
}
R.id.nav_treatments -> {
startActivity(Intent(this, TreatmentsActivity::class.java))
startActivity(Intent(this, TreatmentsActivity::class.java).setAction("info.nightscout.androidaps.MainActivity"))
return true
}
R.id.nav_setupwizard -> {
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
startActivity(Intent(this, SetupWizardActivity::class.java))
startActivity(Intent(this, SetupWizardActivity::class.java).setAction("info.nightscout.androidaps.MainActivity"))
})
return true
}
@ -384,9 +400,11 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
R.id.nav_plugin_preferences -> {
val plugin = (binding.mainPager.adapter as TabPageAdapter).getPluginAt(binding.mainPager.currentItem)
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
val i = Intent(this, PreferencesActivity::class.java)
i.putExtra("id", plugin.preferencesId)
startActivity(i)
startActivity(
Intent(this, PreferencesActivity::class.java)
.setAction("info.nightscout.androidaps.MainActivity")
.putExtra("id", plugin.preferencesId)
)
})
return true
}
@ -397,35 +415,18 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
}
*/
R.id.nav_defaultprofile -> {
startActivity(Intent(this, ProfileHelperActivity::class.java))
startActivity(Intent(this, ProfileHelperActivity::class.java).setAction("info.nightscout.androidaps.MainActivity"))
return true
}
R.id.nav_stats -> {
startActivity(Intent(this, StatsActivity::class.java))
startActivity(Intent(this, StatsActivity::class.java).setAction("info.nightscout.androidaps.MainActivity"))
return true
}
}
return actionBarDrawerToggle.onOptionsItemSelected(item)
}
override fun onBackPressed() {
if (binding.mainDrawerLayout.isDrawerOpen(GravityCompat.START)) {
binding.mainDrawerLayout.closeDrawers()
return
}
if (menuOpen) {
this.menu?.close()
return
}
if (binding.mainPager.currentItem != 0) {
binding.mainPager.currentItem = 0
return
}
@Suppress("DEPRECATION")
super.onBackPressed()
}
// Correct place for calling setUserStats() would be probably MainApp
// but we need to have it called at least once a day. Thus this location

View file

@ -2,8 +2,10 @@ package info.nightscout.androidaps.activities
import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuProvider
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceScreen
import info.nightscout.androidaps.R
@ -33,10 +35,13 @@ class PreferencesActivity : DaggerAppCompatActivityWithResult(), PreferenceFragm
it.putInt("id", preferenceId)
}
if (savedInstanceState == null)
@Suppress("CommitTransaction")
supportFragmentManager.beginTransaction().replace(R.id.frame_layout, myPreferenceFragment!!).commit()
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Add menu items without overriding methods in the Activity
addMenuProvider(object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
// Add menu items here
menuInflater.inflate(R.menu.menu_preferences, menu)
val searchItem = menu.findItem(R.id.menu_search)
searchView = searchItem.actionView as SearchView
@ -47,11 +52,20 @@ class PreferencesActivity : DaggerAppCompatActivityWithResult(), PreferenceFragm
return false
}
override fun onQueryTextSubmit(query: String): Boolean {
return false
override fun onQueryTextSubmit(query: String): Boolean = false
})
}
override fun onMenuItemSelected(menuItem: MenuItem): Boolean =
when (menuItem.itemId) {
android.R.id.home -> {
onBackPressedDispatcher.onBackPressed()
true
}
else -> false
}
})
return super.onCreateOptionsMenu(menu)
}
override fun onPreferenceStartScreen(caller: PreferenceFragmentCompat, pref: PreferenceScreen): Boolean {
@ -60,18 +74,8 @@ class PreferencesActivity : DaggerAppCompatActivityWithResult(), PreferenceFragm
it.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, pref.key)
it.putInt("id", preferenceId)
}
@Suppress("CommitTransaction")
supportFragmentManager.beginTransaction().replace(R.id.frame_layout, fragment, pref.key).addToBackStack(pref.key).commit()
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean =
when (item.itemId) {
android.R.id.home -> {
@Suppress("DEPRECATION")
onBackPressed()
true
}
else -> super.onOptionsItemSelected(item)
}
}

View file

@ -3,7 +3,9 @@ package info.nightscout.configuration.activities
import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import androidx.core.view.MenuProvider
import info.nightscout.configuration.R
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.plugin.PluginBase
@ -33,29 +35,32 @@ class SingleFragmentActivity : DaggerAppCompatActivityWithResult() {
supportFragmentManager.fragmentFactory.instantiate(ClassLoader.getSystemClassLoader(), plugin?.pluginDescription?.fragmentClass!!)
).commit()
}
// Add menu items without overriding methods in the Activity
addMenuProvider(object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
if (plugin?.preferencesId != -1) menuInflater.inflate(R.menu.menu_single_fragment, menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean =
when (item.itemId) {
override fun onMenuItemSelected(menuItem: MenuItem): Boolean =
when (menuItem.itemId) {
android.R.id.home -> {
finish()
onBackPressedDispatcher.onBackPressed()
true
}
R.id.nav_plugin_preferences -> {
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
val i = Intent(this, uiInteraction.preferencesActivity)
i.putExtra("id", plugin?.preferencesId)
protectionCheck.queryProtection(this@SingleFragmentActivity, ProtectionCheck.Protection.PREFERENCES, {
val i = Intent(this@SingleFragmentActivity, uiInteraction.preferencesActivity)
.setAction("info.nightscout.configuration.activities.SingleFragmentActivity")
.putExtra("id", plugin?.preferencesId)
startActivity(i)
}, null)
true
}
else -> super.onOptionsItemSelected(item)
else -> false
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
if (plugin?.preferencesId != -1) menuInflater.inflate(R.menu.menu_single_fragment, menu)
return super.onCreateOptionsMenu(menu)
})
}
}

View file

@ -3,9 +3,12 @@ package info.nightscout.configuration.maintenance.activities
import android.content.Intent
import android.os.Bundle
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 androidx.core.view.MenuProvider
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
@ -41,6 +44,21 @@ class PrefImportListActivity : TranslatedDaggerAppCompatActivity() {
binding.recyclerview.layoutManager = LinearLayoutManager(this)
binding.recyclerview.adapter = RecyclerViewAdapter(prefFileListProvider.listPreferenceFiles(loadMetadata = true))
// 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
}
})
}
inner class RecyclerViewAdapter internal constructor(private var prefFileList: List<PrefsFile>) : RecyclerView.Adapter<RecyclerViewAdapter.PrefFileViewHolder>() {
@ -106,12 +124,4 @@ class PrefImportListActivity : TranslatedDaggerAppCompatActivity() {
}
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
finish()
return true
}
return super.onOptionsItemSelected(item)
}
}

View file

@ -4,6 +4,7 @@ import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.activity.OnBackPressedCallback
import dagger.android.HasAndroidInjector
import info.nightscout.configuration.R
import info.nightscout.configuration.activities.DaggerAppCompatActivityWithResult
@ -64,6 +65,12 @@ class SetupWizardActivity : DaggerAppCompatActivityWithResult() {
generateLayout()
updateButtons()
}
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (currentWizardPage == 0)
OKDialog.showConfirmation(this@SetupWizardActivity, rh.gs(R.string.exitwizard)) { finish() } else showPreviousPage(null)
}
})
}
override fun onPause() {
@ -134,10 +141,6 @@ class SetupWizardActivity : DaggerAppCompatActivityWithResult() {
}
}
override fun onBackPressed() {
if (currentWizardPage == 0) OKDialog.showConfirmation(this, rh.gs(R.string.exitwizard)) { finish() } else showPreviousPage(null)
}
@Suppress("UNUSED_PARAMETER")
fun exitPressed(view: View?) {
sp.putBoolean(R.string.key_setupwizard_processed, true)
@ -147,7 +150,7 @@ class SetupWizardActivity : DaggerAppCompatActivityWithResult() {
@Suppress("UNUSED_PARAMETER")
fun showNextPage(view: View?) {
finish()
val intent = Intent(this, SetupWizardActivity::class.java)
val intent = Intent(this, SetupWizardActivity::class.java).setAction("info.nightscout.configuration.setupwizard.SetupWizardActivity")
intent.putExtra(intentMessage, nextPage(null))
startActivity(intent)
}
@ -155,7 +158,7 @@ class SetupWizardActivity : DaggerAppCompatActivityWithResult() {
@Suppress("UNUSED_PARAMETER")
fun showPreviousPage(view: View?) {
finish()
val intent = Intent(this, SetupWizardActivity::class.java)
val intent = Intent(this, SetupWizardActivity::class.java).setAction("info.nightscout.configuration.setupwizard.SetupWizardActivity")
intent.putExtra(intentMessage, previousPage(null))
startActivity(intent)
}
@ -164,7 +167,7 @@ class SetupWizardActivity : DaggerAppCompatActivityWithResult() {
@Suppress("UNUSED_PARAMETER")
fun finishSetupWizard(view: View?) {
sp.putBoolean(R.string.key_setupwizard_processed, true)
val intent = Intent(this, uiInteraction.mainActivity)
val intent = Intent(this, uiInteraction.mainActivity).setAction("info.nightscout.configuration.setupwizard.SetupWizardActivity")
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(intent)
finish()

View file

@ -3,11 +3,15 @@ package info.nightscout.plugins.sync.openhumans.ui
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.widget.CheckBox
import androidx.activity.OnBackPressedCallback
import androidx.activity.viewModels
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.view.MenuProvider
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
@ -94,6 +98,25 @@ class OHLoginActivity : TranslatedDaggerAppCompatActivity() {
if (code != null) {
viewModel.submitBearerToken(code)
}
// 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
}
})
onBackPressedDispatcher.addCallback(this, object: OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (!viewModel.goBack()) finish()
}
})
}
override fun onNewIntent(intent: Intent) {
@ -103,21 +126,4 @@ class OHLoginActivity : TranslatedDaggerAppCompatActivity() {
viewModel.submitBearerToken(code)
}
}
override fun onBackPressed() {
if (!viewModel.goBack()) {
@Suppress("DEPRECATION")
super.onBackPressed()
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean =
if (item.itemId == android.R.id.home) {
@Suppress("DEPRECATION")
onBackPressed()
true
} else {
super.onOptionsItemSelected(item)
}
}

View file

@ -9,6 +9,7 @@ import android.text.Editable
import android.text.TextWatcher
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
@ -186,13 +187,13 @@ class ComboV2PairingActivity : TranslatedDaggerAppCompatActivity() {
.launchIn(this)
}
}
}
override fun onBackPressed() {
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
aapsLogger.info(LTag.PUMP, "User pressed the back button; cancelling any ongoing pairing")
combov2Plugin.cancelPairing()
@Suppress("DEPRECATION")
super.onBackPressed()
finish()
}
})
}
override fun onDestroy() {

View file

@ -6,6 +6,7 @@ import android.content.Intent
import android.content.pm.ActivityInfo
import android.os.Bundle
import android.view.MotionEvent
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AlertDialog
import androidx.lifecycle.ViewModelProvider
import info.nightscout.androidaps.plugins.pump.eopatch.R
@ -103,6 +104,16 @@ class EopatchActivity : EoBaseActivity<ActivityEopatchBinding>() {
}
}
}
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
binding.viewModel?.apply {
when (patchStep.value) {
PatchStep.SAFE_DEACTIVATION -> this@EopatchActivity.finish()
else -> Unit
}
}
}
})
}
override fun onNewIntent(intent: Intent?) {
@ -274,15 +285,6 @@ class EopatchActivity : EoBaseActivity<ActivityEopatchBinding>() {
this@EopatchActivity.finish()
}
override fun onBackPressed() {
binding.viewModel?.apply{
when(patchStep.value){
PatchStep.SAFE_DEACTIVATION -> this@EopatchActivity.finish()
else -> Unit
}
}
}
companion object {
const val RESULT_DISCARDED = RESULT_FIRST_USER + 1
const val EXTRA_START_PATCH_STEP = "EXTRA_START_PATCH_FRAGMENT_UI"

View file

@ -29,7 +29,7 @@ class MedtrumActivity : MedtrumBaseActivity<ActivityMedtrumBinding>() {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
binding.apply {
viewModel = ViewModelProvider(this@MedtrumActivity, viewModelFactory).get(MedtrumViewModel::class.java)
viewModel = ViewModelProvider(this@MedtrumActivity, viewModelFactory)[MedtrumViewModel::class.java]
viewModel?.apply {
processIntent(intent)
@ -88,20 +88,10 @@ class MedtrumActivity : MedtrumBaseActivity<ActivityMedtrumBinding>() {
}
}
override fun onDestroy() {
super.onDestroy()
}
override fun onBackPressed() {
binding.viewModel?.apply {
// Do nothing
}
}
companion object {
const val EXTRA_START_PATCH_STEP = "EXTRA_START_PATCH_FRAGMENT_UI"
const val EXTRA_START_FROM_MENU = "EXTRA_START_FROM_MENU"
private const val EXTRA_START_FROM_MENU = "EXTRA_START_FROM_MENU"
@JvmStatic fun createIntentFromMenu(context: Context, patchStep: PatchStep): Intent {
return Intent(context, MedtrumActivity::class.java).apply {

View file

@ -1,5 +1,8 @@
package info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.activity
import android.os.Bundle
import android.os.PersistableBundle
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AlertDialog
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
@ -8,7 +11,14 @@ import info.nightscout.core.ui.activities.TranslatedDaggerAppCompatActivity
abstract class OmnipodWizardActivityBase : TranslatedDaggerAppCompatActivity() {
override fun onBackPressed() = exitActivityAfterConfirmation()
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
exitActivityAfterConfirmation()
}
})
}
fun exitActivityAfterConfirmation() {
if (getNavController().previousBackStackEntry == null) {

View file

@ -2,11 +2,11 @@
<application>
<activity
android:name="info.nightscout.androidaps.plugins.pump.common.ui.PumpBLEConfigActivity"
android:name="info.nightscout.pump.common.ui.PumpBLEConfigActivity"
android:theme="@style/AppTheme"
android:exported="false">
<intent-filter>
<action android:name="info.nightscout.androidaps.plugins.pump.common.ui.PumpBLEConfigActivity" />
<action android:name="info.nightscout.pump.common.ui.PumpBLEConfigActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

View file

@ -13,6 +13,8 @@ import android.content.Context
import android.os.Bundle
import android.os.Handler
import android.os.HandlerThread
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
@ -20,6 +22,7 @@ import android.widget.AdapterView
import android.widget.AdapterView.OnItemClickListener
import android.widget.BaseAdapter
import android.widget.TextView
import androidx.core.view.MenuProvider
import info.nightscout.core.ui.activities.TranslatedDaggerAppCompatActivity
import info.nightscout.core.ui.dialogs.OKDialog
import info.nightscout.interfaces.plugin.ActivePlugin
@ -140,6 +143,21 @@ class PumpBLEConfigActivity : TranslatedDaggerAppCompatActivity() {
updateCurrentlySelectedBTDevice()
})
}
// 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 updateCurrentlySelectedBTDevice() {
@ -156,16 +174,6 @@ class PumpBLEConfigActivity : TranslatedDaggerAppCompatActivity() {
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean =
when (item.itemId) {
android.R.id.home -> {
finish()
true
}
else -> super.onOptionsItemSelected(item)
}
override fun onResume() {
super.onResume()
bleSelector.onResume()

View file

@ -17,6 +17,8 @@ import android.os.Bundle
import android.os.Handler
import android.os.HandlerThread
import android.os.ParcelUuid
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
@ -26,6 +28,7 @@ import android.widget.BaseAdapter
import android.widget.TextView
import android.widget.Toast
import androidx.core.app.ActivityCompat
import androidx.core.view.MenuProvider
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.R
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil
@ -118,6 +121,21 @@ class RileyLinkBLEConfigActivity : TranslatedDaggerAppCompatActivity() {
updateCurrentlySelectedRileyLink()
})
}
// 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 updateCurrentlySelectedRileyLink() {
@ -148,16 +166,6 @@ class RileyLinkBLEConfigActivity : TranslatedDaggerAppCompatActivity() {
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean =
when (item.itemId) {
android.R.id.home -> {
finish()
true
}
else -> super.onOptionsItemSelected(item)
}
private fun prepareForScanning() {
val checkOK = blePreCheck.prerequisitesCheck(this)
if (checkOK) {

View file

@ -1,7 +1,10 @@
package info.nightscout.ui.activities
import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import androidx.core.view.MenuProvider
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import com.google.android.material.tabs.TabLayout
@ -61,16 +64,20 @@ class TreatmentsActivity : TranslatedDaggerAppCompatActivity() {
override fun onTabUnselected(tab: TabLayout.Tab) {}
override fun onTabReselected(tab: TabLayout.Tab) {}
})
}
override fun onOptionsItemSelected(item: MenuItem): Boolean =
when (item.itemId) {
addMenuProvider(object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {}
override fun onMenuItemSelected(menuItem: MenuItem): Boolean =
when (menuItem.itemId) {
android.R.id.home -> {
finish()
onBackPressedDispatcher.onBackPressed()
true
}
else -> super.onOptionsItemSelected(item)
else -> false
}
})
}
private fun setFragment(selectedFragment: Fragment) {
@ -79,5 +86,4 @@ class TreatmentsActivity : TranslatedDaggerAppCompatActivity() {
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit()
}
}