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" /> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<application> <application>
<activity android:name=".ui.MedtrumActivity" /> <activity
android:name=".ui.MedtrumActivity"
android:theme="@style/AppTheme" />
<service <service
android:name=".services.MedtrumService" android:name=".services.MedtrumService"
android:enabled="true" android:enabled="true"

View file

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

View file

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