style: profile helper use dropdowns

This commit is contained in:
Andries Smit 2022-07-13 08:54:18 +02:00
parent 2b0670921e
commit 875c4144fd
3 changed files with 51 additions and 91 deletions

View file

@ -5,9 +5,9 @@ import android.content.res.ColorStateList
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.Menu
import android.widget.PopupMenu
import android.widget.ArrayAdapter
import android.widget.TextView
import com.google.common.collect.Lists
import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.ProfileSealed
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.interfaces.ActivePlugin
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.events.EventLocalProfileChanged
import info.nightscout.androidaps.utils.DateUtil
@ -79,54 +78,40 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
switchTab(1, typeSelected[1])
}
binding.profileType.setOnClickListener {
PopupMenu(this, binding.profileType).apply {
menuInflater.inflate(R.menu.menu_profilehelper, menu)
setOnMenuItemClickListener { item ->
binding.profileType.setText(item.title)
when (item.itemId) {
R.id.menu_default -> switchTab(tabSelected, ProfileType.MOTOL_DEFAULT)
R.id.menu_default_dpv -> switchTab(tabSelected, ProfileType.DPV_DEFAULT)
R.id.menu_current -> switchTab(tabSelected, ProfileType.CURRENT)
R.id.menu_available -> switchTab(tabSelected, ProfileType.AVAILABLE_PROFILE)
R.id.menu_profileswitch -> switchTab(tabSelected, ProfileType.PROFILE_SWITCH)
}
true
}
show()
val profileTypeList = Lists.newArrayList(
rh.gs(R.string.motoldefaultprofile),
rh.gs(R.string.dpvdefaultprofile),
rh.gs(R.string.currentprofile),
rh.gs(R.string.availableprofile),
rh.gs(R.string.careportal_profileswitch)
)
binding.profileType.setAdapter(ArrayAdapter(this, R.layout.spinner_centered, profileTypeList))
binding.profileType.setOnItemClickListener { _, _, _, _ ->
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
profileList = activePlugin.activeProfileSource.profile?.getProfileList() ?: ArrayList()
binding.availableProfileList.setOnClickListener {
PopupMenu(this, binding.availableProfileList).apply {
var order = 0
for (name in profileList) menu.add(Menu.NONE, order, order++, name)
setOnMenuItemClickListener { item ->
binding.availableProfileList.setText(item.title)
profileUsed[tabSelected] = item.itemId
true
}
show()
}
binding.availableProfileList.setAdapter(ArrayAdapter(this, R.layout.spinner_centered, profileList))
binding.availableProfileList.setOnItemClickListener { _, _, index, _ ->
profileUsed[tabSelected] = index
}
// Profile switch
profileSwitch = repository.getEffectiveProfileSwitchDataFromTime(dateUtil.now() - T.months(2).msecs(), true).blockingGet()
binding.profileswitchList.setOnClickListener {
PopupMenu(this, binding.profileswitchList).apply {
var order = 0
for (name in profileSwitch) menu.add(Menu.NONE, order, order++, name.originalCustomizedName)
setOnMenuItemClickListener { item ->
binding.profileswitchList.setText(item.title)
profileSwitchUsed[tabSelected] = item.itemId
true
}
show()
}
val profileswitchListNames = profileSwitch.map { it.originalCustomizedName }
binding.profileswitchList.setAdapter(ArrayAdapter(this, R.layout.spinner_centered, profileswitchListNames))
binding.profileswitchList.setOnItemClickListener { _, _, index, _ ->
profileSwitchUsed[tabSelected] = index
}
// Default profile
@ -285,7 +270,7 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
tabSelected = tab
typeSelected[tabSelected] = newContent
binding.profileTypeTitle.defaultHintTextColor = ColorStateList.valueOf(rh.gac( this, if (tab == 0) R.attr.helperProfileColor else R.attr.examinedProfileColor))
binding.profileTypeTitle.defaultHintTextColor = ColorStateList.valueOf(rh.gac(this, if (tab == 0) R.attr.helperProfileColor else R.attr.examinedProfileColor))
// show new content
binding.profileType.setText(
@ -295,7 +280,8 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
ProfileType.CURRENT -> rh.gs(R.string.currentprofile)
ProfileType.AVAILABLE_PROFILE -> rh.gs(R.string.availableprofile)
ProfileType.PROFILE_SWITCH -> rh.gs(R.string.careportal_profileswitch)
}
},
false
)
binding.defaultProfile.visibility = (newContent == ProfileType.MOTOL_DEFAULT || newContent == ProfileType.DPV_DEFAULT).toVisibility()
binding.currentProfile.visibility = (newContent == ProfileType.CURRENT).toVisibility()
@ -309,10 +295,12 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
binding.basalPctFromTdd.value = pctUsed[tabSelected]
binding.basalPctFromTddRow.visibility = (newContent == ProfileType.DPV_DEFAULT).toVisibility()
if (profileList.isNotEmpty())
binding.availableProfileList.setText(profileList[profileUsed[tabSelected]].toString())
if (profileSwitch.isNotEmpty())
binding.profileswitchList.setText(profileSwitch[profileSwitchUsed[tabSelected]].originalCustomizedName)
if (profileList.isNotEmpty()) {
binding.availableProfileList.setText(profileList[profileUsed[tabSelected]].toString(), false)
}
if (profileSwitch.isNotEmpty()) {
binding.profileswitchList.setText(profileSwitch[profileSwitchUsed[tabSelected]].originalCustomizedName, false)
}
}
private fun setBackgroundColorOnSelected(tab: Int) {

View file

@ -43,21 +43,18 @@
<com.google.android.material.textfield.TextInputLayout
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_height="wrap_content"
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:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:importantForAutofill="no" />
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
@ -206,21 +203,18 @@
android:orientation="vertical">
<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_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:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:clickable="true"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:importantForAutofill="no" />
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
@ -233,21 +227,19 @@
android:orientation="vertical">
<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_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:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:clickable="true"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:importantForAutofill="no" />
android:inputType="none" />
</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>