ProfileSwitchDialog spinner replacement

This commit is contained in:
Milos Kozak 2022-03-19 12:00:58 +01:00
parent c24d2798ff
commit 6d27f5fad0
4 changed files with 23 additions and 29 deletions

View file

@ -117,8 +117,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
// profile
context?.let { context ->
val profileStore = activePlugin.activeProfileSource.profile
?: return
val profileStore = activePlugin.activeProfileSource.profile ?: return
val profileListToCheck = profileStore.getProfileList()
val profileList = ArrayList<CharSequence>()
for (profileName in profileListToCheck) {
@ -130,15 +129,16 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
dismiss()
return
}
val adapter = ArrayAdapter(context, R.layout.spinner_centered, profileList)
binding.profile.adapter = adapter
binding.profileList.setAdapter(ArrayAdapter(context, R.layout.spinner_centered, profileList))
// set selected to actual profile
if (profileIndex != null)
binding.profile.setSelection(profileIndex as Int)
else
binding.profileList.setText(profileList[profileIndex as Int], false)
else {
binding.profileList.setText(profileList[0], false)
for (p in profileList.indices)
if (profileList[p] == profileFunction.getOriginalProfileName())
binding.profile.setSelection(p)
binding.profileList.setText(profileList[p], false)
}
}
profileFunction.getProfile()?.let { profile ->
@ -173,7 +173,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
val duration = binding.duration.value.toInt()
if (duration > 0L)
actions.add(rh.gs(R.string.duration) + ": " + rh.gs(R.string.format_mins, duration))
val profileName = binding.profile.selectedItem.toString()
val profileName = binding.profileList.text.toString()
actions.add(rh.gs(R.string.profile) + ": " + profileName)
val percent = binding.percentage.value.toInt()
if (percent != 100)

View file

@ -128,12 +128,12 @@ class OverviewData @Inject constructor(
var lastBg: GlucoseValue? = null
val isLow: Boolean
private val isLow: Boolean
get() = lastBg?.let { lastBg ->
lastBg.valueToUnits(profileFunction.getUnits()) < defaultValueHelper.determineLowLine()
} ?: false
val isHigh: Boolean
private val isHigh: Boolean
get() = lastBg?.let { lastBg ->
lastBg.valueToUnits(profileFunction.getUnits()) > defaultValueHelper.determineHighLine()
} ?: false

View file

@ -58,7 +58,6 @@ class LocalProfileFragment : DaggerFragment() {
private var disposable: CompositeDisposable = CompositeDisposable()
private var basalView: TimeListEdit? = null
// private var spinner: SpinnerHelper? = null
private val save = Runnable {
doEdit()
@ -240,7 +239,6 @@ class LocalProfileFragment : DaggerFragment() {
)
}
// Spinner
context?.let { context ->
val profileList: ArrayList<CharSequence> = localProfilePlugin.profile?.getProfileList() ?: ArrayList()
binding.profileList.setAdapter(ArrayAdapter(context, R.layout.spinner_centered, profileList))

View file

@ -48,29 +48,25 @@
android:orientation="horizontal"
android:padding="5dp" />
<LinearLayout
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:hint="@string/profile"
app:boxStrokeColor="@color/list_delimiter">
<TextView
android:layout_width="wrap_content"
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
android:id="@+id/profileList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:width="120dp"
android:labelFor="@+id/profile"
android:padding="10dp"
android:text="@string/profile_label"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="bold" />
android:clickable="true"
android:enabled="false"
tools:ignore="KeyboardInaccessibleWidget" />
<Spinner
android:id="@+id/profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/reuselayout"