Merge pull request #1909 from Andries-Smit/style/material-profile-helper

Style material profile helper tabs and dropdown
This commit is contained in:
Milos Kozak 2022-07-13 11:26:01 +02:00 committed by GitHub
commit 48ebc0973c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 71 additions and 126 deletions

View file

@ -1,13 +1,13 @@
package info.nightscout.androidaps.activities package info.nightscout.androidaps.activities
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.res.ColorStateList
import android.os.Bundle import android.os.Bundle
import android.text.Editable import android.text.Editable
import android.text.TextWatcher import android.text.TextWatcher
import android.view.Menu import android.widget.ArrayAdapter
import android.widget.PopupMenu
import android.widget.TextView import android.widget.TextView
import com.google.android.material.tabs.TabLayout
import com.google.common.collect.Lists
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.ProfileSealed import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.data.PureProfile import info.nightscout.androidaps.data.PureProfile
@ -18,7 +18,6 @@ import info.nightscout.androidaps.dialogs.ProfileViewerDialog
import info.nightscout.androidaps.extensions.toVisibility import info.nightscout.androidaps.extensions.toVisibility
import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin
import info.nightscout.androidaps.plugins.profile.local.events.EventLocalProfileChanged import info.nightscout.androidaps.plugins.profile.local.events.EventLocalProfileChanged
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
@ -72,61 +71,49 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
binding = ActivityProfilehelperBinding.inflate(layoutInflater) binding = ActivityProfilehelperBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
binding.menu1.setOnClickListener { binding.tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
switchTab(0, typeSelected[0]) override fun onTabSelected(tab: TabLayout.Tab) {
} switchTab(tab.position, typeSelected[tab.position])
binding.menu2.setOnClickListener { }
switchTab(1, typeSelected[1])
}
binding.profileType.setOnClickListener { override fun onTabUnselected(tab: TabLayout.Tab) {}
PopupMenu(this, binding.profileType).apply { override fun onTabReselected(tab: TabLayout.Tab) {}
menuInflater.inflate(R.menu.menu_profilehelper, menu) })
setOnMenuItemClickListener { item ->
binding.profileType.setText(item.title) val profileTypeList = Lists.newArrayList(
when (item.itemId) { rh.gs(R.string.motoldefaultprofile),
R.id.menu_default -> switchTab(tabSelected, ProfileType.MOTOL_DEFAULT) rh.gs(R.string.dpvdefaultprofile),
R.id.menu_default_dpv -> switchTab(tabSelected, ProfileType.DPV_DEFAULT) rh.gs(R.string.currentprofile),
R.id.menu_current -> switchTab(tabSelected, ProfileType.CURRENT) rh.gs(R.string.availableprofile),
R.id.menu_available -> switchTab(tabSelected, ProfileType.AVAILABLE_PROFILE) rh.gs(R.string.careportal_profileswitch)
R.id.menu_profileswitch -> switchTab(tabSelected, ProfileType.PROFILE_SWITCH) )
} binding.profileType.setAdapter(ArrayAdapter(this, R.layout.spinner_centered, profileTypeList))
true
} binding.profileType.setOnItemClickListener { _, _, _, _ ->
show() when (binding.profileType.text.toString()) {
rh.gs(R.string.motoldefaultprofile) -> switchTab(tabSelected, ProfileType.MOTOL_DEFAULT)
rh.gs(R.string.dpvdefaultprofile) -> switchTab(tabSelected, ProfileType.DPV_DEFAULT)
rh.gs(R.string.currentprofile) -> switchTab(tabSelected, ProfileType.CURRENT)
rh.gs(R.string.availableprofile) -> switchTab(tabSelected, ProfileType.AVAILABLE_PROFILE)
rh.gs(R.string.careportal_profileswitch) -> switchTab(tabSelected, ProfileType.PROFILE_SWITCH)
} }
} }
// Active profile // Active profile
profileList = activePlugin.activeProfileSource.profile?.getProfileList() ?: ArrayList() profileList = activePlugin.activeProfileSource.profile?.getProfileList() ?: ArrayList()
binding.availableProfileList.setOnClickListener { binding.availableProfileList.setAdapter(ArrayAdapter(this, R.layout.spinner_centered, profileList))
PopupMenu(this, binding.availableProfileList).apply { binding.availableProfileList.setOnItemClickListener { _, _, index, _ ->
var order = 0 profileUsed[tabSelected] = index
for (name in profileList) menu.add(Menu.NONE, order, order++, name)
setOnMenuItemClickListener { item ->
binding.availableProfileList.setText(item.title)
profileUsed[tabSelected] = item.itemId
true
}
show()
}
} }
// Profile switch // Profile switch
profileSwitch = repository.getEffectiveProfileSwitchDataFromTime(dateUtil.now() - T.months(2).msecs(), true).blockingGet() profileSwitch = repository.getEffectiveProfileSwitchDataFromTime(dateUtil.now() - T.months(2).msecs(), true).blockingGet()
binding.profileswitchList.setOnClickListener { val profileswitchListNames = profileSwitch.map { it.originalCustomizedName }
PopupMenu(this, binding.profileswitchList).apply { binding.profileswitchList.setAdapter(ArrayAdapter(this, R.layout.spinner_centered, profileswitchListNames))
var order = 0 binding.profileswitchList.setOnItemClickListener { _, _, index, _ ->
for (name in profileSwitch) menu.add(Menu.NONE, order, order++, name.originalCustomizedName) profileSwitchUsed[tabSelected] = index
setOnMenuItemClickListener { item ->
binding.profileswitchList.setText(item.title)
profileSwitchUsed[tabSelected] = item.itemId
true
}
show()
}
} }
// Default profile // Default profile
@ -250,7 +237,7 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
} }
private fun getProfile(age: Double, tdd: Double, weight: Double, basalPct: Double, tab: Int): PureProfile? = private fun getProfile(age: Double, tdd: Double, weight: Double, basalPct: Double, tab: Int): PureProfile? =
try { // profile must not exist try { // Profile must not exist
when (typeSelected[tab]) { when (typeSelected[tab]) {
ProfileType.MOTOL_DEFAULT -> defaultProfile.profile(age, tdd, weight, profileFunction.getUnits()) ProfileType.MOTOL_DEFAULT -> defaultProfile.profile(age, tdd, weight, profileFunction.getUnits())
ProfileType.DPV_DEFAULT -> defaultProfileDPV.profile(age, tdd, basalPct, profileFunction.getUnits()) ProfileType.DPV_DEFAULT -> defaultProfileDPV.profile(age, tdd, basalPct, profileFunction.getUnits())
@ -279,15 +266,13 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
} }
private fun switchTab(tab: Int, newContent: ProfileType, storeOld: Boolean = true) { private fun switchTab(tab: Int, newContent: ProfileType, storeOld: Boolean = true) {
setBackgroundColorOnSelected(tab)
// Store values for selected tab. listBox values are stored on selection change // Store values for selected tab. listBox values are stored on selection change
if (storeOld) storeValues() if (storeOld) storeValues()
tabSelected = tab tabSelected = tab
typeSelected[tabSelected] = newContent typeSelected[tabSelected] = newContent
binding.profileTypeTitle.defaultHintTextColor = ColorStateList.valueOf(rh.gac( this, if (tab == 0) R.attr.helperProfileColor else R.attr.examinedProfileColor))
// show new content // Show new content
binding.profileType.setText( binding.profileType.setText(
when (typeSelected[tabSelected]) { when (typeSelected[tabSelected]) {
ProfileType.MOTOL_DEFAULT -> rh.gs(R.string.motoldefaultprofile) ProfileType.MOTOL_DEFAULT -> rh.gs(R.string.motoldefaultprofile)
@ -295,28 +280,27 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
ProfileType.CURRENT -> rh.gs(R.string.currentprofile) ProfileType.CURRENT -> rh.gs(R.string.currentprofile)
ProfileType.AVAILABLE_PROFILE -> rh.gs(R.string.availableprofile) ProfileType.AVAILABLE_PROFILE -> rh.gs(R.string.availableprofile)
ProfileType.PROFILE_SWITCH -> rh.gs(R.string.careportal_profileswitch) ProfileType.PROFILE_SWITCH -> rh.gs(R.string.careportal_profileswitch)
} },
false
) )
binding.defaultProfile.visibility = (newContent == ProfileType.MOTOL_DEFAULT || newContent == ProfileType.DPV_DEFAULT).toVisibility() binding.defaultProfile.visibility = (newContent == ProfileType.MOTOL_DEFAULT || newContent == ProfileType.DPV_DEFAULT).toVisibility()
binding.currentProfile.visibility = (newContent == ProfileType.CURRENT).toVisibility() binding.currentProfile.visibility = (newContent == ProfileType.CURRENT).toVisibility()
binding.availableProfile.visibility = (newContent == ProfileType.AVAILABLE_PROFILE).toVisibility() binding.availableProfile.visibility = (newContent == ProfileType.AVAILABLE_PROFILE).toVisibility()
binding.profileSwitch.visibility = (newContent == ProfileType.PROFILE_SWITCH).toVisibility() binding.profileSwitch.visibility = (newContent == ProfileType.PROFILE_SWITCH).toVisibility()
// restore selected values // Restore selected values
binding.age.value = ageUsed[tabSelected] binding.age.value = ageUsed[tabSelected]
binding.weight.value = weightUsed[tabSelected] binding.weight.value = weightUsed[tabSelected]
binding.tdd.value = tddUsed[tabSelected] binding.tdd.value = tddUsed[tabSelected]
binding.basalPctFromTdd.value = pctUsed[tabSelected] binding.basalPctFromTdd.value = pctUsed[tabSelected]
binding.basalPctFromTddRow.visibility = (newContent == ProfileType.DPV_DEFAULT).toVisibility() binding.basalPctFromTddRow.visibility = (newContent == ProfileType.DPV_DEFAULT).toVisibility()
if (profileList.isNotEmpty()) if (profileList.isNotEmpty()) {
binding.availableProfileList.setText(profileList[profileUsed[tabSelected]].toString()) binding.availableProfileList.setText(profileList[profileUsed[tabSelected]].toString(), false)
if (profileSwitch.isNotEmpty()) }
binding.profileswitchList.setText(profileSwitch[profileSwitchUsed[tabSelected]].originalCustomizedName) if (profileSwitch.isNotEmpty()) {
binding.profileswitchList.setText(profileSwitch[profileSwitchUsed[tabSelected]].originalCustomizedName, false)
}
} }
private fun setBackgroundColorOnSelected(tab: Int) {
binding.menu1.setBackgroundColor(rh.gac(this, if (tab == 1) R.attr.defaultBackground else R.attr.helperProfileColor))
binding.menu2.setBackgroundColor(rh.gac(this, if (tab == 0) R.attr.defaultBackground else R.attr.examinedProfileColor))
}
} }

View file

@ -12,52 +12,38 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/defaultBackground" android:layout_marginBottom="10dp">
android:orientation="horizontal"
android:paddingBottom="10dp">
<TextView <com.google.android.material.tabs.TabItem
android:id="@+id/menu1" android:layout_width="wrap_content"
android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:gravity="center"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:text="@string/profile1" /> android:text="@string/profile1" />
<TextView <com.google.android.material.tabs.TabItem
android:id="@+id/menu2" android:layout_width="wrap_content"
android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:gravity="center"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:text="@string/profile2" /> android:text="@string/profile2" />
</LinearLayout> </com.google.android.material.tabs.TabLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/profile_type_title" android:id="@+id/profile_type_title"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:hint="@string/profiletype"> android:hint="@string/profiletype"
android:paddingHorizontal="5dp">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.MaterialAutoCompleteTextView
android:id="@+id/profile_type" android:id="@+id/profile_type"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:clickable="true" android:inputType="none" />
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:importantForAutofill="no" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
@ -206,21 +192,18 @@
android:orientation="vertical"> android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/selected_profile"> android:hint="@string/selected_profile"
android:paddingHorizontal="5dp">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.MaterialAutoCompleteTextView
android:id="@+id/available_profile_list" android:id="@+id/available_profile_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:clickable="true" android:inputType="none" />
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:importantForAutofill="no" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
@ -233,21 +216,19 @@
android:orientation="vertical"> android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/careportal_profileswitch"> android:hint="@string/careportal_profileswitch"
android:paddingHorizontal="5dp">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.MaterialAutoCompleteTextView
android:id="@+id/profileswitch_list" android:id="@+id/profileswitch_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:clickable="true"
android:cursorVisible="false" android:inputType="none" />
android:focusable="false"
android:focusableInTouchMode="false"
android:importantForAutofill="no" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>

View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_default"
android:title="@string/motoldefaultprofile" />
<item
android:id="@+id/menu_default_dpv"
android:title="@string/dpvdefaultprofile" />
<item
android:id="@+id/menu_current"
android:title="@string/currentprofile" />
<item
android:id="@+id/menu_available"
android:title="@string/availableprofile" />
<item
android:id="@+id/menu_profileswitch"
android:title="@string/careportal_profileswitch" />
</menu>