ProfileHelperActivity -> jetpack

This commit is contained in:
Milos Kozak 2021-01-22 14:16:59 +01:00
parent 3022214105
commit b9477eef16
2 changed files with 94 additions and 91 deletions

View file

@ -10,6 +10,7 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.data.defaultProfile.DefaultProfile
import info.nightscout.androidaps.data.defaultProfile.DefaultProfileDPV
import info.nightscout.androidaps.databinding.ActivityProfilehelperBinding
import info.nightscout.androidaps.db.ProfileSwitch
import info.nightscout.androidaps.dialogs.ProfileViewerDialog
import info.nightscout.androidaps.interfaces.ActivePluginProvider
@ -25,7 +26,6 @@ import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.extensions.toVisibility
import info.nightscout.androidaps.utils.stats.TddCalculator
import kotlinx.android.synthetic.main.activity_profilehelper.*
import java.text.DecimalFormat
import javax.inject.Inject
@ -64,22 +64,26 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
private lateinit var profileSwitch: List<ProfileSwitch>
private val profileSwitchUsed = arrayOf(0, 0)
private lateinit var binding: ActivityProfilehelperBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_profilehelper)
profilehelper_menu1.setOnClickListener {
binding = ActivityProfilehelperBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.menu1.setOnClickListener {
switchTab(0, typeSelected[0])
}
profilehelper_menu2.setOnClickListener {
binding.menu2.setOnClickListener {
switchTab(1, typeSelected[1])
}
profilehelper_profiletype.setOnClickListener {
PopupMenu(this, profilehelper_profiletype).apply {
binding.profiletype.setOnClickListener {
PopupMenu(this, binding.profiletype).apply {
menuInflater.inflate(R.menu.menu_profilehelper, menu)
setOnMenuItemClickListener { item ->
profilehelper_profiletype.setText(item.title)
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)
@ -96,12 +100,12 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
// Active profile
profileList = activePlugin.activeProfileInterface.profile?.getProfileList() ?: ArrayList()
profilehelper_available_profile_list.setOnClickListener {
PopupMenu(this, profilehelper_available_profile_list).apply {
binding.availableProfileList.setOnClickListener {
PopupMenu(this, binding.availableProfileList).apply {
var order = 0
for (name in profileList) menu.add(Menu.NONE, order, order++, name)
setOnMenuItemClickListener { item ->
profilehelper_available_profile_list.setText(item.title)
binding.availableProfileList.setText(item.title)
profileUsed[tabSelected] = item.itemId
true
}
@ -112,12 +116,12 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
// Profile switch
profileSwitch = databaseHelper.getProfileSwitchData(dateUtil._now() - T.months(2).msecs(), true)
profilehelper_profileswitch_list.setOnClickListener {
PopupMenu(this, profilehelper_profileswitch_list).apply {
binding.profileswitchList.setOnClickListener {
PopupMenu(this, binding.profileswitchList).apply {
var order = 0
for (name in profileSwitch) menu.add(Menu.NONE, order, order++, name.customizedName)
setOnMenuItemClickListener { item ->
profilehelper_profileswitch_list.setText(item.title)
binding.profileswitchList.setText(item.title)
profileSwitchUsed[tabSelected] = item.itemId
true
}
@ -126,7 +130,7 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
}
// Default profile
profilehelper_copytolocalprofile.setOnClickListener {
binding.copytolocalprofile.setOnClickListener {
val age = ageUsed[tabSelected]
val weight = weightUsed[tabSelected]
val tdd = tddUsed[tabSelected]
@ -141,31 +145,31 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
}
}
profilehelper_age.setParams(0.0, 1.0, 18.0, 1.0, DecimalFormat("0"), false, null)
profilehelper_weight.setParams(0.0, 0.0, 150.0, 1.0, DecimalFormat("0"), false, null, object : TextWatcher {
binding.age.setParams(0.0, 1.0, 18.0, 1.0, DecimalFormat("0"), false, null)
binding.weight.setParams(0.0, 0.0, 150.0, 1.0, DecimalFormat("0"), false, null, object : TextWatcher {
override fun afterTextChanged(s: Editable) {}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
profilehelper_tdd_row.visibility = (profilehelper_weight.value == 0.0).toVisibility()
binding.tddRow.visibility = (binding.weight.value == 0.0).toVisibility()
}
})
profilehelper_tdd.setParams(0.0, 0.0, 200.0, 1.0, DecimalFormat("0"), false, null, object : TextWatcher {
binding.tdd.setParams(0.0, 0.0, 200.0, 1.0, DecimalFormat("0"), false, null, object : TextWatcher {
override fun afterTextChanged(s: Editable) {}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
profilehelper_weight_row.visibility = (profilehelper_tdd.value == 0.0).toVisibility()
binding.weightRow.visibility = (binding.tdd.value == 0.0).toVisibility()
}
})
profilehelper_basalpctfromtdd.setParams(32.0, 32.0, 37.0, 1.0, DecimalFormat("0"), false, null)
binding.basalpctfromtdd.setParams(32.0, 32.0, 37.0, 1.0, DecimalFormat("0"), false, null)
profilehelper_tdds.text = tddCalculator.stats()
binding.tdds.text = tddCalculator.stats()
// Current profile
profilehelper_current_profile_text.text = profileFunction.getProfileName()
binding.currentProfileText.text = profileFunction.getProfileName()
// General
profilehelper_compareprofile.setOnClickListener {
binding.compareprofile.setOnClickListener {
storeValues()
for (i in 0..1) {
if (typeSelected[i] == ProfileType.MOTOL_DEFAULT) {
@ -242,10 +246,10 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
}
private fun storeValues() {
ageUsed[tabSelected] = profilehelper_age.value
weightUsed[tabSelected] = profilehelper_weight.value
tddUsed[tabSelected] = profilehelper_tdd.value
pctUsed[tabSelected] = profilehelper_basalpctfromtdd.value
ageUsed[tabSelected] = binding.age.value
weightUsed[tabSelected] = binding.weight.value
tddUsed[tabSelected] = binding.tdd.value
pctUsed[tabSelected] = binding.basalpctfromtdd.value
}
private fun switchTab(tab: Int, newContent: ProfileType, storeOld: Boolean = true) {
@ -255,10 +259,10 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
tabSelected = tab
typeSelected[tabSelected] = newContent
profilehelper_profiletype_title.defaultHintTextColor = ColorStateList.valueOf(resourceHelper.gc(if (tab == 0) R.color.tabBgColorSelected else R.color.examinedProfile))
binding.profiletypeTitle.defaultHintTextColor = ColorStateList.valueOf(resourceHelper.gc(if (tab == 0) R.color.tabBgColorSelected else R.color.examinedProfile))
// show new content
profilehelper_profiletype.setText(
binding.profiletype.setText(
when (typeSelected[tabSelected]) {
ProfileType.MOTOL_DEFAULT -> resourceHelper.gs(R.string.motoldefaultprofile)
ProfileType.DPV_DEFAULT -> resourceHelper.gs(R.string.dpvdefaultprofile)
@ -266,26 +270,26 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
ProfileType.AVAILABLE_PROFILE -> resourceHelper.gs(R.string.availableprofile)
ProfileType.PROFILE_SWITCH -> resourceHelper.gs(R.string.careportal_profileswitch)
})
profilehelper_default_profile.visibility = (newContent == ProfileType.MOTOL_DEFAULT || newContent == ProfileType.DPV_DEFAULT).toVisibility()
profilehelper_current_profile.visibility = (newContent == ProfileType.CURRENT).toVisibility()
profilehelper_available_profile.visibility = (newContent == ProfileType.AVAILABLE_PROFILE).toVisibility()
profilehelper_profile_switch.visibility = (newContent == ProfileType.PROFILE_SWITCH).toVisibility()
binding.defaultProfile.visibility = (newContent == ProfileType.MOTOL_DEFAULT || newContent == ProfileType.DPV_DEFAULT).toVisibility()
binding.currentProfile.visibility = (newContent == ProfileType.CURRENT).toVisibility()
binding.availableProfile.visibility = (newContent == ProfileType.AVAILABLE_PROFILE).toVisibility()
binding.profileSwitch.visibility = (newContent == ProfileType.PROFILE_SWITCH).toVisibility()
// restore selected values
profilehelper_age.value = ageUsed[tabSelected]
profilehelper_weight.value = weightUsed[tabSelected]
profilehelper_tdd.value = tddUsed[tabSelected]
profilehelper_basalpctfromtdd.value = pctUsed[tabSelected]
binding.age.value = ageUsed[tabSelected]
binding.weight.value = weightUsed[tabSelected]
binding.tdd.value = tddUsed[tabSelected]
binding.basalpctfromtdd.value = pctUsed[tabSelected]
profilehelper_basalpctfromtdd_row.visibility = (newContent == ProfileType.DPV_DEFAULT).toVisibility()
binding.basalpctfromtddRow.visibility = (newContent == ProfileType.DPV_DEFAULT).toVisibility()
if (profileList.isNotEmpty())
profilehelper_available_profile_list.setText(profileList[profileUsed[tabSelected]].toString())
binding.availableProfileList.setText(profileList[profileUsed[tabSelected]].toString())
if (profileSwitch.isNotEmpty())
profilehelper_profileswitch_list.setText(profileSwitch[profileSwitchUsed[tabSelected]].customizedName)
binding.profileswitchList.setText(profileSwitch[profileSwitchUsed[tabSelected]].customizedName)
}
private fun setBackgroundColorOnSelected(tab: Int) {
profilehelper_menu1.setBackgroundColor(resourceHelper.gc(if (tab == 1) R.color.defaultbackground else R.color.tabBgColorSelected))
profilehelper_menu2.setBackgroundColor(resourceHelper.gc(if (tab == 0) R.color.defaultbackground else R.color.examinedProfile))
binding.menu1.setBackgroundColor(resourceHelper.gc(if (tab == 1) R.color.defaultbackground else R.color.tabBgColorSelected))
binding.menu2.setBackgroundColor(resourceHelper.gc(if (tab == 0) R.color.defaultbackground else R.color.examinedProfile))
}
}

View file

@ -12,14 +12,6 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/profilehelper_compareprofile"
style="?android:attr/buttonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@drawable/ic_compare_profiles"
android:text="@string/comapareprofile" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -28,7 +20,7 @@
android:orientation="horizontal">
<TextView
android:id="@+id/profilehelper_menu1"
android:id="@+id/menu1"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
@ -38,7 +30,7 @@
android:text="1" />
<TextView
android:id="@+id/profilehelper_menu2"
android:id="@+id/menu2"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
@ -50,7 +42,7 @@
</LinearLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/profilehelper_profiletype_title"
android:id="@+id/profiletype_title"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -59,7 +51,7 @@
app:boxStrokeColor="@color/tabBgColorSelected">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/profilehelper_profiletype"
android:id="@+id/profiletype"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
@ -72,7 +64,7 @@
</com.google.android.material.textfield.TextInputLayout>
<LinearLayout
android:id="@+id/profilehelper_default_profile"
android:id="@+id/default_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -87,82 +79,82 @@
android:gravity="center_vertical">
<TextView
android:id="@+id/profilehelper_age_label"
android:id="@+id/age_label"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:labelFor="@+id/profilehelper_age"
android:labelFor="@+id/age"
android:text="@string/age"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
<info.nightscout.androidaps.utils.ui.NumberPicker
android:id="@+id/profilehelper_age"
android:id="@+id/age"
android:layout_width="130dp"
android:layout_height="40dp" />
</TableRow>
<TableRow
android:id="@+id/profilehelper_tdd_row"
android:id="@+id/tdd_row"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">
<TextView
android:id="@+id/profilehelper_tdd_label"
android:id="@+id/tdd_label"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:labelFor="@+id/profilehelper_weight"
android:labelFor="@+id/weight"
android:text="@string/tdd_total"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
<info.nightscout.androidaps.utils.ui.NumberPicker
android:id="@+id/profilehelper_tdd"
android:id="@+id/tdd"
android:layout_width="130dp"
android:layout_height="40dp" />
</TableRow>
<TableRow
android:id="@+id/profilehelper_weight_row"
android:id="@+id/weight_row"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">
<TextView
android:id="@+id/profilehelper_weigth_label"
android:id="@+id/weigth_label"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:labelFor="@+id/profilehelper_weight"
android:labelFor="@+id/weight"
android:text="@string/weight_label"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
<info.nightscout.androidaps.utils.ui.NumberPicker
android:id="@+id/profilehelper_weight"
android:id="@+id/weight"
android:layout_width="130dp"
android:layout_height="40dp" />
</TableRow>
<TableRow
android:id="@+id/profilehelper_basalpctfromtdd_row"
android:id="@+id/basalpctfromtdd_row"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">
<TextView
android:id="@+id/profilehelper_basalpctfromtdd_label"
android:id="@+id/basalpctfromtdd_label"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:labelFor="@+id/profilehelper_basalpctfromtdd"
android:labelFor="@+id/basalpctfromtdd"
android:text="@string/basalpctfromtdd_label"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
<info.nightscout.androidaps.utils.ui.NumberPicker
android:id="@+id/profilehelper_basalpctfromtdd"
android:id="@+id/basalpctfromtdd"
android:layout_width="130dp"
android:layout_height="40dp" />
@ -171,14 +163,14 @@
</TableLayout>
<TextView
android:id="@+id/profilehelper_tdds"
android:id="@+id/tdds"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
<info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/profilehelper_copytolocalprofile"
android:id="@+id/copytolocalprofile"
style="?android:attr/buttonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -188,13 +180,13 @@
</LinearLayout>
<LinearLayout
android:id="@+id/profilehelper_current_profile"
android:id="@+id/current_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/profilehelper_current_profile_text"
android:id="@+id/current_profile_text"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
@ -203,7 +195,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/profilehelper_available_profile"
android:id="@+id/available_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -217,7 +209,7 @@
app:boxStrokeColor="@color/white">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/profilehelper_available_profile_list"
android:id="@+id/available_profile_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
@ -232,7 +224,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/profilehelper_profile_switch"
android:id="@+id/profile_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -246,7 +238,7 @@
app:boxStrokeColor="@color/white">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/profilehelper_profileswitch_list"
android:id="@+id/profileswitch_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
@ -258,9 +250,16 @@
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/compareprofile"
style="?android:attr/buttonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@drawable/ic_compare_profiles"
android:text="@string/comapareprofile" />
</LinearLayout>
</ScrollView>