ActivityStats: toolbar

This commit is contained in:
Milos Kozak 2023-08-19 10:00:47 +02:00
parent 36dee44ffc
commit 69f06f598b
3 changed files with 41 additions and 71 deletions

View file

@ -43,7 +43,7 @@
<activity <activity
android:name=".activities.StatsActivity" android:name=".activities.StatsActivity"
android:exported="false" android:exported="false"
android:theme="@style/AppTheme.NoActionBar" /> android:theme="@style/AppTheme" />
<activity <activity
android:name=".activities.TreatmentsActivity" android:name=".activities.TreatmentsActivity"
android:exported="false" android:exported="false"

View file

@ -4,7 +4,11 @@ import android.annotation.SuppressLint
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.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.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.fabric.FabricPrivacy
@ -47,6 +51,10 @@ class StatsActivity : TranslatedDaggerAppCompatActivity() {
binding = ActivityStatsBinding.inflate(layoutInflater) binding = ActivityStatsBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
title = rh.gs(R.string.statistics)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
binding.tdds.addView(TextView(this).apply { text = getString(info.nightscout.core.ui.R.string.tdd) + ": " + rh.gs(R.string.calculation_in_progress) }) binding.tdds.addView(TextView(this).apply { text = getString(info.nightscout.core.ui.R.string.tdd) + ": " + rh.gs(R.string.calculation_in_progress) })
binding.tir.addView(TextView(this).apply { text = getString(info.nightscout.core.ui.R.string.tir) + ": " + rh.gs(R.string.calculation_in_progress) }) binding.tir.addView(TextView(this).apply { text = getString(info.nightscout.core.ui.R.string.tir) + ": " + rh.gs(R.string.calculation_in_progress) })
binding.activity.addView(TextView(this).apply { text = getString(R.string.activity_monitor) + ": " + rh.gs(R.string.calculation_in_progress) }) binding.activity.addView(TextView(this).apply { text = getString(R.string.activity_monitor) + ": " + rh.gs(R.string.calculation_in_progress) })
@ -80,7 +88,6 @@ class StatsActivity : TranslatedDaggerAppCompatActivity() {
binding.activity.addView(it) binding.activity.addView(it)
}, fabricPrivacy::logException) }, fabricPrivacy::logException)
binding.close.setOnClickListener { finish() }
binding.resetActivity.setOnClickListener { binding.resetActivity.setOnClickListener {
OKDialog.showConfirmation(this, rh.gs(R.string.do_you_want_reset_stats)) { OKDialog.showConfirmation(this, rh.gs(R.string.do_you_want_reset_stats)) {
uel.log(Action.STAT_RESET, Sources.Stats) uel.log(Action.STAT_RESET, Sources.Stats)
@ -97,6 +104,20 @@ class StatsActivity : TranslatedDaggerAppCompatActivity() {
} }
} }
} }
// 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 onPause() { override fun onPause() {

View file

@ -12,43 +12,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="?attr/activity_title_backgroundColor"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:importantForAccessibility="no"
app:srcCompat="@mipmap/ic_launcher" />
<TextView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:text="@string/statistics"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<LinearLayout
android:id="@+id/spacer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp" />
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
android:id="@+id/cardview_tdds"
style="@style/Widget.MaterialComponents.CardView" style="@style/Widget.MaterialComponents.CardView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -73,20 +37,23 @@
android:orientation="vertical" /> android:orientation="vertical" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="50dp" android:layout_height="50dp"
android:layout_gravity="center_vertical" android:layout_gravity="center"
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:gravity="end"
android:orientation="horizontal"> android:orientation="horizontal">
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/reset_tdd" android:id="@+id/reset_tdd"
style="@style/OkCancelButton.Text" style="@style/GrayButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="8dp" android:layout_gravity="center"
android:text="@string/reset" /> android:paddingStart="1dp"
android:paddingEnd="1dp"
android:text="@string/reset"
app:icon="@drawable/ic_local_reset"
app:iconTint="@color/ic_local_reset" />
</LinearLayout> </LinearLayout>
@ -95,7 +62,6 @@
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
android:id="@+id/cardview_tir"
style="@style/Widget.MaterialComponents.CardView" style="@style/Widget.MaterialComponents.CardView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -118,7 +84,6 @@
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
android:id="@+id/cardview_dexcom_tir"
style="@style/Widget.MaterialComponents.CardView" style="@style/Widget.MaterialComponents.CardView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -141,7 +106,6 @@
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
android:id="@+id/cardview_activity"
style="@style/Widget.MaterialComponents.CardView" style="@style/Widget.MaterialComponents.CardView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -167,20 +131,23 @@
android:orientation="vertical" /> android:orientation="vertical" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="50dp" android:layout_height="50dp"
android:layout_gravity="center_vertical" android:layout_gravity="center"
android:background="@android:color/transparent"
android:gravity="end"
android:orientation="horizontal"> android:orientation="horizontal">
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/reset_activity" android:id="@+id/reset_activity"
style="@style/OkCancelButton.Text" style="@style/GrayButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingStart="1dp"
android:paddingEnd="1dp"
android:text="@string/reset"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:text="@string/reset" /> app:icon="@drawable/ic_local_reset"
app:iconTint="@color/ic_local_reset" />
</LinearLayout> </LinearLayout>
@ -188,24 +155,6 @@
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:background="@android:color/transparent"
android:gravity="end"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:id="@+id/close"
style="@style/OkCancelButton.Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/close" />
</LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>