This commit is contained in:
Milos Kozak 2022-09-12 13:46:48 +02:00
parent 05733a72eb
commit 0ccc5bfdfc
8 changed files with 42 additions and 30 deletions

View file

@ -69,13 +69,13 @@ class PreferencesActivity : NoSplashAppCompatActivity(), PreferenceFragmentCompa
super.attachBaseContext(LocaleHelper.wrap(newBase)) super.attachBaseContext(LocaleHelper.wrap(newBase))
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean =
when (item.itemId) { when (item.itemId) {
android.R.id.home -> { android.R.id.home -> {
onBackPressed() onBackPressed()
return true true
} }
else -> super.onOptionsItemSelected(item)
} }
return super.onOptionsItemSelected(item)
}
} }

View file

@ -27,25 +27,31 @@ class SingleFragmentActivity : DaggerAppCompatActivityWithResult() {
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true)
if (savedInstanceState == null) { if (savedInstanceState == null) {
supportFragmentManager.beginTransaction().replace(R.id.frame_layout, supportFragmentManager.beginTransaction().replace(
supportFragmentManager.fragmentFactory.instantiate(ClassLoader.getSystemClassLoader(), plugin?.pluginDescription?.fragmentClass!!)).commit() R.id.frame_layout,
supportFragmentManager.fragmentFactory.instantiate(ClassLoader.getSystemClassLoader(), plugin?.pluginDescription?.fragmentClass!!)
).commit()
} }
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean =
if (item.itemId == android.R.id.home) { when (item.itemId) {
finish() android.R.id.home -> {
return true finish()
} else if (item.itemId == R.id.nav_plugin_preferences) { true
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, Runnable { }
val i = Intent(this, PreferencesActivity::class.java)
i.putExtra("id", plugin?.preferencesId) R.id.nav_plugin_preferences -> {
startActivity(i) protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
}, null) val i = Intent(this, PreferencesActivity::class.java)
return true i.putExtra("id", plugin?.preferencesId)
startActivity(i)
}, null)
true
}
else -> super.onOptionsItemSelected(item)
} }
return false
}
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
if (plugin?.preferencesId != -1) menuInflater.inflate(R.menu.menu_single_fragment, menu) if (plugin?.preferencesId != -1) menuInflater.inflate(R.menu.menu_single_fragment, menu)

View file

@ -7,7 +7,13 @@ import androidx.fragment.app.FragmentTransaction
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayout.OnTabSelectedListener import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.fragments.* import info.nightscout.androidaps.activities.fragments.TreatmentsBolusCarbsFragment
import info.nightscout.androidaps.activities.fragments.TreatmentsCareportalFragment
import info.nightscout.androidaps.activities.fragments.TreatmentsExtendedBolusesFragment
import info.nightscout.androidaps.activities.fragments.TreatmentsProfileSwitchFragment
import info.nightscout.androidaps.activities.fragments.TreatmentsTempTargetFragment
import info.nightscout.androidaps.activities.fragments.TreatmentsTemporaryBasalsFragment
import info.nightscout.androidaps.activities.fragments.TreatmentsUserEntryFragment
import info.nightscout.androidaps.databinding.TreatmentsFragmentBinding import info.nightscout.androidaps.databinding.TreatmentsFragmentBinding
import info.nightscout.androidaps.extensions.toVisibility import info.nightscout.androidaps.extensions.toVisibility
import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ActivePlugin
@ -25,7 +31,7 @@ class TreatmentsActivity : NoSplashAppCompatActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = TreatmentsFragmentBinding.inflate(layoutInflater) binding = TreatmentsFragmentBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
// Use index, TabItems crashes with an id // Use index, TabItems crashes with an id
val useFakeTempBasal = activePlugin.activePump.isFakingTempsByExtendedBoluses val useFakeTempBasal = activePlugin.activePump.isFakingTempsByExtendedBoluses
binding.treatmentsTabs.getTabAt(1)?.view?.visibility = useFakeTempBasal.toVisibility() binding.treatmentsTabs.getTabAt(1)?.view?.visibility = useFakeTempBasal.toVisibility()
@ -55,16 +61,15 @@ class TreatmentsActivity : NoSplashAppCompatActivity() {
}) })
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean =
return when (item.itemId) { when (item.itemId) {
android.R.id.home -> { android.R.id.home -> {
finish() finish()
true true
} }
else -> false else -> super.onOptionsItemSelected(item)
} }
}
private fun setFragment(selectedFragment: Fragment) { private fun setFragment(selectedFragment: Fragment) {
supportFragmentManager.beginTransaction() supportFragmentManager.beginTransaction()

View file

@ -119,7 +119,8 @@ class BGSourceFragment : DaggerFragment(), MenuProvider {
} }
override fun onMenuItemSelected(item: MenuItem) = override fun onMenuItemSelected(item: MenuItem) =
actionHelper.onOptionsItemSelected(item) if (actionHelper.onOptionsItemSelected(item)) true
else super.onContextItemSelected(item)
inner class RecyclerViewAdapter internal constructor(private var glucoseValues: List<GlucoseValue>) : RecyclerView.Adapter<RecyclerViewAdapter.GlucoseValuesViewHolder>() { inner class RecyclerViewAdapter internal constructor(private var glucoseValues: List<GlucoseValue>) : RecyclerView.Adapter<RecyclerViewAdapter.GlucoseValuesViewHolder>() {

View file

@ -121,7 +121,7 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener, MenuProvider {
true true
} }
else -> false else -> super.onContextItemSelected(item)
} }
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")

View file

@ -114,7 +114,7 @@ class PrefImportListActivity : DaggerAppCompatActivity() {
finish() finish()
return true return true
} }
return false return super.onOptionsItemSelected(item)
} }
override fun attachBaseContext(newBase: Context) { override fun attachBaseContext(newBase: Context) {

View file

@ -165,7 +165,7 @@ class PumpBLEConfigActivity : DaggerAppCompatActivity() {
true true
} }
else -> false else -> super.onOptionsItemSelected(item)
} }
override fun onResume() { override fun onResume() {

View file

@ -155,7 +155,7 @@ class RileyLinkBLEConfigActivity : DaggerAppCompatActivity() {
true true
} }
else -> false else -> super.onOptionsItemSelected(item)
} }
private fun prepareForScanning() { private fun prepareForScanning() {