style: profile helper use material tabs
This commit is contained in:
parent
875c4144fd
commit
7ec4b855e5
2 changed files with 23 additions and 38 deletions
|
@ -1,12 +1,12 @@
|
||||||
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.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import com.google.android.material.tabs.TabLayout
|
||||||
import com.google.common.collect.Lists
|
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
|
||||||
|
@ -71,13 +71,15 @@ 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])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onTabUnselected(tab: TabLayout.Tab) {}
|
||||||
|
override fun onTabReselected(tab: TabLayout.Tab) {}
|
||||||
|
})
|
||||||
|
|
||||||
val profileTypeList = Lists.newArrayList(
|
val profileTypeList = Lists.newArrayList(
|
||||||
rh.gs(R.string.motoldefaultprofile),
|
rh.gs(R.string.motoldefaultprofile),
|
||||||
rh.gs(R.string.dpvdefaultprofile),
|
rh.gs(R.string.dpvdefaultprofile),
|
||||||
|
@ -235,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())
|
||||||
|
@ -264,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)
|
||||||
|
@ -288,7 +288,7 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
|
||||||
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]
|
||||||
|
@ -303,8 +303,4 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,34 +12,23 @@
|
||||||
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"
|
||||||
|
|
Loading…
Reference in a new issue