style: profile helper use dropdowns
This commit is contained in:
parent
2b0670921e
commit
875c4144fd
3 changed files with 51 additions and 91 deletions
|
@ -5,9 +5,9 @@ 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.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
|
||||||
|
@ -79,54 +78,40 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
|
||||||
switchTab(1, typeSelected[1])
|
switchTab(1, typeSelected[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.profileType.setOnClickListener {
|
val profileTypeList = Lists.newArrayList(
|
||||||
PopupMenu(this, binding.profileType).apply {
|
rh.gs(R.string.motoldefaultprofile),
|
||||||
menuInflater.inflate(R.menu.menu_profilehelper, menu)
|
rh.gs(R.string.dpvdefaultprofile),
|
||||||
setOnMenuItemClickListener { item ->
|
rh.gs(R.string.currentprofile),
|
||||||
binding.profileType.setText(item.title)
|
rh.gs(R.string.availableprofile),
|
||||||
when (item.itemId) {
|
rh.gs(R.string.careportal_profileswitch)
|
||||||
R.id.menu_default -> switchTab(tabSelected, ProfileType.MOTOL_DEFAULT)
|
)
|
||||||
R.id.menu_default_dpv -> switchTab(tabSelected, ProfileType.DPV_DEFAULT)
|
binding.profileType.setAdapter(ArrayAdapter(this, R.layout.spinner_centered, profileTypeList))
|
||||||
R.id.menu_current -> switchTab(tabSelected, ProfileType.CURRENT)
|
|
||||||
R.id.menu_available -> switchTab(tabSelected, ProfileType.AVAILABLE_PROFILE)
|
binding.profileType.setOnItemClickListener { _, _, _, _ ->
|
||||||
R.id.menu_profileswitch -> switchTab(tabSelected, ProfileType.PROFILE_SWITCH)
|
when (binding.profileType.text.toString()) {
|
||||||
}
|
rh.gs(R.string.motoldefaultprofile) -> switchTab(tabSelected, ProfileType.MOTOL_DEFAULT)
|
||||||
true
|
rh.gs(R.string.dpvdefaultprofile) -> switchTab(tabSelected, ProfileType.DPV_DEFAULT)
|
||||||
}
|
rh.gs(R.string.currentprofile) -> switchTab(tabSelected, ProfileType.CURRENT)
|
||||||
show()
|
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
|
||||||
|
@ -285,7 +270,7 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
|
||||||
|
|
||||||
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))
|
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(
|
||||||
|
@ -295,7 +280,8 @@ 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()
|
||||||
|
@ -309,10 +295,12 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
|
||||||
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) {
|
private fun setBackgroundColorOnSelected(tab: Int) {
|
||||||
|
|
|
@ -43,21 +43,18 @@
|
||||||
|
|
||||||
<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 +203,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 +227,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>
|
||||||
|
|
||||||
|
|
|
@ -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>
|
|
Loading…
Reference in a new issue