Resolve onBackPressed deprecation
This commit is contained in:
parent
896acb94b5
commit
968c9fb4c1
14 changed files with 223 additions and 169 deletions
|
@ -21,6 +21,7 @@ import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.appcompat.app.ActionBarDrawerToggle
|
import androidx.appcompat.app.ActionBarDrawerToggle
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.core.view.GravityCompat
|
import androidx.core.view.GravityCompat
|
||||||
|
@ -151,7 +152,7 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
|
||||||
.subscribe({ processPreferenceChange(it) }, fabricPrivacy::logException)
|
.subscribe({ processPreferenceChange(it) }, fabricPrivacy::logException)
|
||||||
if (startWizard() && !isRunningRealPumpTest()) {
|
if (startWizard() && !isRunningRealPumpTest()) {
|
||||||
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
|
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)
|
androidPermission.notifyForStoragePermission(this)
|
||||||
|
@ -163,6 +164,17 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
|
||||||
androidPermission.notifyForBtConnectPermission(this)
|
androidPermission.notifyForBtConnectPermission(this)
|
||||||
}
|
}
|
||||||
passwordResetCheck(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) {
|
private fun checkPluginPreferences(viewPager: ViewPager2) {
|
||||||
|
@ -219,9 +231,11 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
|
||||||
menuItem.setIcon(info.nightscout.core.ui.R.drawable.ic_settings)
|
menuItem.setIcon(info.nightscout.core.ui.R.drawable.ic_settings)
|
||||||
}
|
}
|
||||||
menuItem.setOnMenuItemClickListener {
|
menuItem.setOnMenuItemClickListener {
|
||||||
val intent = Intent(this, SingleFragmentActivity::class.java)
|
startActivity(
|
||||||
intent.putExtra("plugin", activePlugin.getPluginsList().indexOf(p))
|
Intent(this, SingleFragmentActivity::class.java)
|
||||||
startActivity(intent)
|
.setAction("info.nightscout.androidaps.MainActivity")
|
||||||
|
.putExtra("plugin", activePlugin.getPluginsList().indexOf(p))
|
||||||
|
)
|
||||||
binding.mainDrawerLayout.closeDrawers()
|
binding.mainDrawerLayout.closeDrawers()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -318,26 +332,28 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.nav_preferences -> {
|
R.id.nav_preferences -> {
|
||||||
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
|
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
|
||||||
val i = Intent(this, PreferencesActivity::class.java)
|
startActivity(
|
||||||
i.putExtra("id", -1)
|
Intent(this, PreferencesActivity::class.java)
|
||||||
startActivity(i)
|
.setAction("info.nightscout.androidaps.MainActivity")
|
||||||
|
.putExtra("id", -1)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.nav_historybrowser -> {
|
R.id.nav_historybrowser -> {
|
||||||
startActivity(Intent(this, HistoryBrowseActivity::class.java))
|
startActivity(Intent(this, HistoryBrowseActivity::class.java).setAction("info.nightscout.androidaps.MainActivity"))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.nav_treatments -> {
|
R.id.nav_treatments -> {
|
||||||
startActivity(Intent(this, TreatmentsActivity::class.java))
|
startActivity(Intent(this, TreatmentsActivity::class.java).setAction("info.nightscout.androidaps.MainActivity"))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.nav_setupwizard -> {
|
R.id.nav_setupwizard -> {
|
||||||
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
@ -384,9 +400,11 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
|
||||||
R.id.nav_plugin_preferences -> {
|
R.id.nav_plugin_preferences -> {
|
||||||
val plugin = (binding.mainPager.adapter as TabPageAdapter).getPluginAt(binding.mainPager.currentItem)
|
val plugin = (binding.mainPager.adapter as TabPageAdapter).getPluginAt(binding.mainPager.currentItem)
|
||||||
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
|
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
|
||||||
val i = Intent(this, PreferencesActivity::class.java)
|
startActivity(
|
||||||
i.putExtra("id", plugin.preferencesId)
|
Intent(this, PreferencesActivity::class.java)
|
||||||
startActivity(i)
|
.setAction("info.nightscout.androidaps.MainActivity")
|
||||||
|
.putExtra("id", plugin.preferencesId)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -397,35 +415,18 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
R.id.nav_defaultprofile -> {
|
R.id.nav_defaultprofile -> {
|
||||||
startActivity(Intent(this, ProfileHelperActivity::class.java))
|
startActivity(Intent(this, ProfileHelperActivity::class.java).setAction("info.nightscout.androidaps.MainActivity"))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.nav_stats -> {
|
R.id.nav_stats -> {
|
||||||
startActivity(Intent(this, StatsActivity::class.java))
|
startActivity(Intent(this, StatsActivity::class.java).setAction("info.nightscout.androidaps.MainActivity"))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return actionBarDrawerToggle.onOptionsItemSelected(item)
|
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
|
// Correct place for calling setUserStats() would be probably MainApp
|
||||||
// but we need to have it called at least once a day. Thus this location
|
// but we need to have it called at least once a day. Thus this location
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,10 @@ package info.nightscout.androidaps.activities
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
|
import androidx.core.view.MenuProvider
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
|
@ -33,10 +35,13 @@ class PreferencesActivity : DaggerAppCompatActivityWithResult(), PreferenceFragm
|
||||||
it.putInt("id", preferenceId)
|
it.putInt("id", preferenceId)
|
||||||
}
|
}
|
||||||
if (savedInstanceState == null)
|
if (savedInstanceState == null)
|
||||||
|
@Suppress("CommitTransaction")
|
||||||
supportFragmentManager.beginTransaction().replace(R.id.frame_layout, myPreferenceFragment!!).commit()
|
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)
|
menuInflater.inflate(R.menu.menu_preferences, menu)
|
||||||
val searchItem = menu.findItem(R.id.menu_search)
|
val searchItem = menu.findItem(R.id.menu_search)
|
||||||
searchView = searchItem.actionView as SearchView
|
searchView = searchItem.actionView as SearchView
|
||||||
|
@ -47,11 +52,20 @@ class PreferencesActivity : DaggerAppCompatActivityWithResult(), PreferenceFragm
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onQueryTextSubmit(query: String): Boolean {
|
override fun onQueryTextSubmit(query: String): Boolean = false
|
||||||
return 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 {
|
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.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, pref.key)
|
||||||
it.putInt("id", preferenceId)
|
it.putInt("id", preferenceId)
|
||||||
}
|
}
|
||||||
|
@Suppress("CommitTransaction")
|
||||||
supportFragmentManager.beginTransaction().replace(R.id.frame_layout, fragment, pref.key).addToBackStack(pref.key).commit()
|
supportFragmentManager.beginTransaction().replace(R.id.frame_layout, fragment, pref.key).addToBackStack(pref.key).commit()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
|
||||||
when (item.itemId) {
|
|
||||||
android.R.id.home -> {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
onBackPressed()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> super.onOptionsItemSelected(item)
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -3,7 +3,9 @@ package info.nightscout.configuration.activities
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
import androidx.core.view.MenuProvider
|
||||||
import info.nightscout.configuration.R
|
import info.nightscout.configuration.R
|
||||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||||
import info.nightscout.interfaces.plugin.PluginBase
|
import info.nightscout.interfaces.plugin.PluginBase
|
||||||
|
@ -33,29 +35,32 @@ class SingleFragmentActivity : DaggerAppCompatActivityWithResult() {
|
||||||
supportFragmentManager.fragmentFactory.instantiate(ClassLoader.getSystemClassLoader(), plugin?.pluginDescription?.fragmentClass!!)
|
supportFragmentManager.fragmentFactory.instantiate(ClassLoader.getSystemClassLoader(), plugin?.pluginDescription?.fragmentClass!!)
|
||||||
).commit()
|
).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 =
|
override fun onMenuItemSelected(menuItem: MenuItem): Boolean =
|
||||||
when (item.itemId) {
|
when (menuItem.itemId) {
|
||||||
android.R.id.home -> {
|
android.R.id.home -> {
|
||||||
finish()
|
onBackPressedDispatcher.onBackPressed()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.nav_plugin_preferences -> {
|
R.id.nav_plugin_preferences -> {
|
||||||
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
|
protectionCheck.queryProtection(this@SingleFragmentActivity, ProtectionCheck.Protection.PREFERENCES, {
|
||||||
val i = Intent(this, uiInteraction.preferencesActivity)
|
val i = Intent(this@SingleFragmentActivity, uiInteraction.preferencesActivity)
|
||||||
i.putExtra("id", plugin?.preferencesId)
|
.setAction("info.nightscout.configuration.activities.SingleFragmentActivity")
|
||||||
|
.putExtra("id", plugin?.preferencesId)
|
||||||
startActivity(i)
|
startActivity(i)
|
||||||
}, null)
|
}, null)
|
||||||
true
|
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,9 +3,12 @@ package info.nightscout.configuration.maintenance.activities
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.view.MenuProvider
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
@ -41,6 +44,21 @@ class PrefImportListActivity : TranslatedDaggerAppCompatActivity() {
|
||||||
|
|
||||||
binding.recyclerview.layoutManager = LinearLayoutManager(this)
|
binding.recyclerview.layoutManager = LinearLayoutManager(this)
|
||||||
binding.recyclerview.adapter = RecyclerViewAdapter(prefFileListProvider.listPreferenceFiles(loadMetadata = true))
|
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>() {
|
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.configuration.R
|
import info.nightscout.configuration.R
|
||||||
import info.nightscout.configuration.activities.DaggerAppCompatActivityWithResult
|
import info.nightscout.configuration.activities.DaggerAppCompatActivityWithResult
|
||||||
|
@ -64,6 +65,12 @@ class SetupWizardActivity : DaggerAppCompatActivityWithResult() {
|
||||||
generateLayout()
|
generateLayout()
|
||||||
updateButtons()
|
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() {
|
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")
|
@Suppress("UNUSED_PARAMETER")
|
||||||
fun exitPressed(view: View?) {
|
fun exitPressed(view: View?) {
|
||||||
sp.putBoolean(R.string.key_setupwizard_processed, true)
|
sp.putBoolean(R.string.key_setupwizard_processed, true)
|
||||||
|
@ -147,7 +150,7 @@ class SetupWizardActivity : DaggerAppCompatActivityWithResult() {
|
||||||
@Suppress("UNUSED_PARAMETER")
|
@Suppress("UNUSED_PARAMETER")
|
||||||
fun showNextPage(view: View?) {
|
fun showNextPage(view: View?) {
|
||||||
finish()
|
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))
|
intent.putExtra(intentMessage, nextPage(null))
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
@ -155,7 +158,7 @@ class SetupWizardActivity : DaggerAppCompatActivityWithResult() {
|
||||||
@Suppress("UNUSED_PARAMETER")
|
@Suppress("UNUSED_PARAMETER")
|
||||||
fun showPreviousPage(view: View?) {
|
fun showPreviousPage(view: View?) {
|
||||||
finish()
|
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))
|
intent.putExtra(intentMessage, previousPage(null))
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
@ -164,7 +167,7 @@ class SetupWizardActivity : DaggerAppCompatActivityWithResult() {
|
||||||
@Suppress("UNUSED_PARAMETER")
|
@Suppress("UNUSED_PARAMETER")
|
||||||
fun finishSetupWizard(view: View?) {
|
fun finishSetupWizard(view: View?) {
|
||||||
sp.putBoolean(R.string.key_setupwizard_processed, true)
|
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)
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
finish()
|
finish()
|
||||||
|
|
|
@ -3,11 +3,15 @@ package info.nightscout.plugins.sync.openhumans.ui
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.CheckBox
|
import android.widget.CheckBox
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.browser.customtabs.CustomTabsIntent
|
import androidx.browser.customtabs.CustomTabsIntent
|
||||||
|
import androidx.core.view.MenuProvider
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowCompat
|
import androidx.core.view.WindowCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
@ -94,6 +98,25 @@ class OHLoginActivity : TranslatedDaggerAppCompatActivity() {
|
||||||
if (code != null) {
|
if (code != null) {
|
||||||
viewModel.submitBearerToken(code)
|
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) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
|
@ -103,21 +126,4 @@ class OHLoginActivity : TranslatedDaggerAppCompatActivity() {
|
||||||
viewModel.submitBearerToken(code)
|
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ import android.text.Editable
|
||||||
import android.text.TextWatcher
|
import android.text.TextWatcher
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
@ -186,13 +187,13 @@ class ComboV2PairingActivity : TranslatedDaggerAppCompatActivity() {
|
||||||
.launchIn(this)
|
.launchIn(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
|
||||||
|
override fun handleOnBackPressed() {
|
||||||
override fun onBackPressed() {
|
|
||||||
aapsLogger.info(LTag.PUMP, "User pressed the back button; cancelling any ongoing pairing")
|
aapsLogger.info(LTag.PUMP, "User pressed the back button; cancelling any ongoing pairing")
|
||||||
combov2Plugin.cancelPairing()
|
combov2Plugin.cancelPairing()
|
||||||
@Suppress("DEPRECATION")
|
finish()
|
||||||
super.onBackPressed()
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import android.content.Intent
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import info.nightscout.androidaps.plugins.pump.eopatch.R
|
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?) {
|
override fun onNewIntent(intent: Intent?) {
|
||||||
|
@ -274,15 +285,6 @@ class EopatchActivity : EoBaseActivity<ActivityEopatchBinding>() {
|
||||||
this@EopatchActivity.finish()
|
this@EopatchActivity.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
|
||||||
binding.viewModel?.apply{
|
|
||||||
when(patchStep.value){
|
|
||||||
PatchStep.SAFE_DEACTIVATION -> this@EopatchActivity.finish()
|
|
||||||
else -> Unit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val RESULT_DISCARDED = RESULT_FIRST_USER + 1
|
const val RESULT_DISCARDED = RESULT_FIRST_USER + 1
|
||||||
const val EXTRA_START_PATCH_STEP = "EXTRA_START_PATCH_FRAGMENT_UI"
|
const val EXTRA_START_PATCH_STEP = "EXTRA_START_PATCH_FRAGMENT_UI"
|
||||||
|
|
|
@ -29,7 +29,7 @@ class MedtrumActivity : MedtrumBaseActivity<ActivityMedtrumBinding>() {
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
|
|
||||||
binding.apply {
|
binding.apply {
|
||||||
viewModel = ViewModelProvider(this@MedtrumActivity, viewModelFactory).get(MedtrumViewModel::class.java)
|
viewModel = ViewModelProvider(this@MedtrumActivity, viewModelFactory)[MedtrumViewModel::class.java]
|
||||||
viewModel?.apply {
|
viewModel?.apply {
|
||||||
processIntent(intent)
|
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 {
|
companion object {
|
||||||
|
|
||||||
const val EXTRA_START_PATCH_STEP = "EXTRA_START_PATCH_FRAGMENT_UI"
|
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 {
|
@JvmStatic fun createIntentFromMenu(context: Context, patchStep: PatchStep): Intent {
|
||||||
return Intent(context, MedtrumActivity::class.java).apply {
|
return Intent(context, MedtrumActivity::class.java).apply {
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.activity
|
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.appcompat.app.AlertDialog
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.fragment.NavHostFragment
|
import androidx.navigation.fragment.NavHostFragment
|
||||||
|
@ -8,7 +11,14 @@ import info.nightscout.core.ui.activities.TranslatedDaggerAppCompatActivity
|
||||||
|
|
||||||
abstract class OmnipodWizardActivityBase : 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() {
|
fun exitActivityAfterConfirmation() {
|
||||||
if (getNavController().previousBackStackEntry == null) {
|
if (getNavController().previousBackStackEntry == null) {
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
<application>
|
<application>
|
||||||
<activity
|
<activity
|
||||||
android:name="info.nightscout.androidaps.plugins.pump.common.ui.PumpBLEConfigActivity"
|
android:name="info.nightscout.pump.common.ui.PumpBLEConfigActivity"
|
||||||
android:theme="@style/AppTheme"
|
android:theme="@style/AppTheme"
|
||||||
android:exported="false">
|
android:exported="false">
|
||||||
<intent-filter>
|
<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" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
|
@ -13,6 +13,8 @@ import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.HandlerThread
|
import android.os.HandlerThread
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -20,6 +22,7 @@ import android.widget.AdapterView
|
||||||
import android.widget.AdapterView.OnItemClickListener
|
import android.widget.AdapterView.OnItemClickListener
|
||||||
import android.widget.BaseAdapter
|
import android.widget.BaseAdapter
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.core.view.MenuProvider
|
||||||
import info.nightscout.core.ui.activities.TranslatedDaggerAppCompatActivity
|
import info.nightscout.core.ui.activities.TranslatedDaggerAppCompatActivity
|
||||||
import info.nightscout.core.ui.dialogs.OKDialog
|
import info.nightscout.core.ui.dialogs.OKDialog
|
||||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||||
|
@ -140,6 +143,21 @@ class PumpBLEConfigActivity : TranslatedDaggerAppCompatActivity() {
|
||||||
updateCurrentlySelectedBTDevice()
|
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() {
|
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() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
bleSelector.onResume()
|
bleSelector.onResume()
|
||||||
|
|
|
@ -17,6 +17,8 @@ import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.HandlerThread
|
import android.os.HandlerThread
|
||||||
import android.os.ParcelUuid
|
import android.os.ParcelUuid
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -26,6 +28,7 @@ import android.widget.BaseAdapter
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.core.app.ActivityCompat
|
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.R
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil
|
||||||
|
@ -118,6 +121,21 @@ class RileyLinkBLEConfigActivity : TranslatedDaggerAppCompatActivity() {
|
||||||
updateCurrentlySelectedRileyLink()
|
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() {
|
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() {
|
private fun prepareForScanning() {
|
||||||
val checkOK = blePreCheck.prerequisitesCheck(this)
|
val checkOK = blePreCheck.prerequisitesCheck(this)
|
||||||
if (checkOK) {
|
if (checkOK) {
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package info.nightscout.ui.activities
|
package info.nightscout.ui.activities
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
import androidx.core.view.MenuProvider
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentTransaction
|
import androidx.fragment.app.FragmentTransaction
|
||||||
import com.google.android.material.tabs.TabLayout
|
import com.google.android.material.tabs.TabLayout
|
||||||
|
@ -61,16 +64,20 @@ class TreatmentsActivity : TranslatedDaggerAppCompatActivity() {
|
||||||
override fun onTabUnselected(tab: TabLayout.Tab) {}
|
override fun onTabUnselected(tab: TabLayout.Tab) {}
|
||||||
override fun onTabReselected(tab: TabLayout.Tab) {}
|
override fun onTabReselected(tab: TabLayout.Tab) {}
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
addMenuProvider(object : MenuProvider {
|
||||||
when (item.itemId) {
|
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {}
|
||||||
|
|
||||||
|
override fun onMenuItemSelected(menuItem: MenuItem): Boolean =
|
||||||
|
when (menuItem.itemId) {
|
||||||
android.R.id.home -> {
|
android.R.id.home -> {
|
||||||
finish()
|
onBackPressedDispatcher.onBackPressed()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> super.onOptionsItemSelected(item)
|
else -> false
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setFragment(selectedFragment: Fragment) {
|
private fun setFragment(selectedFragment: Fragment) {
|
||||||
|
@ -79,5 +86,4 @@ class TreatmentsActivity : TranslatedDaggerAppCompatActivity() {
|
||||||
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
||||||
.commit()
|
.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue