Madtrum: toolbar

This commit is contained in:
Milos Kozak 2023-08-19 16:03:13 +02:00
parent 8d0bba379a
commit 50043a4a18
3 changed files with 25 additions and 2 deletions

View file

@ -7,7 +7,9 @@
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<application>
<activity android:name=".ui.MedtrumActivity" />
<activity
android:name=".ui.MedtrumActivity"
android:theme="@style/AppTheme" />
<service
android:name=".services.MedtrumService"
android:enabled="true"

View file

@ -4,9 +4,13 @@ import android.content.Context
import android.content.Intent
import android.content.pm.ActivityInfo
import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.MotionEvent
import android.view.WindowManager
import androidx.activity.OnBackPressedCallback
import androidx.core.view.MenuProvider
import androidx.lifecycle.ViewModelProvider
import info.nightscout.core.utils.extensions.safeGetSerializableExtra
import info.nightscout.pump.medtrum.R
@ -25,6 +29,10 @@ class MedtrumActivity : MedtrumBaseActivity<ActivityMedtrumBinding>() {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LOCKED
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
title = getString(R.string.step_prepare_patch)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
binding.apply {
viewModel = ViewModelProvider(this@MedtrumActivity, viewModelFactory)[MedtrumViewModel::class.java]
viewModel?.apply {
@ -89,6 +97,20 @@ class MedtrumActivity : MedtrumBaseActivity<ActivityMedtrumBinding>() {
}
}
})
// 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 onNewIntent(intent: Intent?) {

View file

@ -32,7 +32,6 @@ abstract class MedtrumBaseActivity<B : ViewDataBinding> : DaggerAppCompatActivit
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setTheme(R.style.AppTheme_NoActionBar)
binding = DataBindingUtil.setContentView(this, getLayoutId())
binding.lifecycleOwner = this