chore: convert buttons to tabs
This commit is contained in:
parent
fbddfa6dee
commit
bbc16f80b4
2 changed files with 37 additions and 82 deletions
|
@ -9,6 +9,7 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.AdapterView
|
import android.widget.AdapterView
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
|
import com.google.android.material.tabs.TabLayout
|
||||||
import dagger.android.support.DaggerFragment
|
import dagger.android.support.DaggerFragment
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
|
@ -105,30 +106,16 @@ class LocalProfileFragment : DaggerFragment() {
|
||||||
val parentClass = this.activity?.let { it::class.java }
|
val parentClass = this.activity?.let { it::class.java }
|
||||||
inMenu = parentClass == SingleFragmentActivity::class.java
|
inMenu = parentClass == SingleFragmentActivity::class.java
|
||||||
updateProtectedUi()
|
updateProtectedUi()
|
||||||
// activate DIA tab
|
processVisibility(0)
|
||||||
processVisibilityOnClick(binding.diaTab)
|
binding.tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
|
||||||
binding.diaPlaceholder.visibility = View.VISIBLE
|
override fun onTabSelected(tab: TabLayout.Tab) {
|
||||||
// setup listeners
|
processVisibility(tab.position)
|
||||||
binding.diaTab.setOnClickListener {
|
|
||||||
processVisibilityOnClick(it)
|
|
||||||
binding.diaPlaceholder.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
binding.icTab.setOnClickListener {
|
|
||||||
processVisibilityOnClick(it)
|
|
||||||
binding.ic.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
binding.isfTab.setOnClickListener {
|
|
||||||
processVisibilityOnClick(it)
|
|
||||||
binding.isf.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
binding.basalTab.setOnClickListener {
|
|
||||||
processVisibilityOnClick(it)
|
|
||||||
binding.basal.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
binding.targetTab.setOnClickListener {
|
|
||||||
processVisibilityOnClick(it)
|
|
||||||
binding.target.visibility = View.VISIBLE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onTabUnselected(tab: TabLayout.Tab) {}
|
||||||
|
override fun onTabReselected(tab: TabLayout.Tab) {}
|
||||||
|
})
|
||||||
|
|
||||||
binding.dia.editText?.id?.let { binding.diaLabel.labelFor = it }
|
binding.dia.editText?.id?.let { binding.diaLabel.labelFor = it }
|
||||||
|
|
||||||
binding.unlock.setOnClickListener { queryProtection() }
|
binding.unlock.setOnClickListener { queryProtection() }
|
||||||
|
@ -400,18 +387,12 @@ class LocalProfileFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processVisibilityOnClick(selected: View) {
|
private fun processVisibility(position: Int) {
|
||||||
binding.diaTab.setBackgroundColor(rh.gac(context, R.attr.defaultbackground))
|
binding.diaPlaceholder.visibility = (position == 0).toVisibility()
|
||||||
binding.icTab.setBackgroundColor(rh.gac(context, R.attr.defaultbackground))
|
binding.ic.visibility = (position == 1).toVisibility()
|
||||||
binding.isfTab.setBackgroundColor(rh.gac(context, R.attr.defaultbackground))
|
binding.isf.visibility = (position == 2).toVisibility()
|
||||||
binding.basalTab.setBackgroundColor(rh.gac(context, R.attr.defaultbackground))
|
binding.basal.visibility = (position == 3).toVisibility()
|
||||||
binding.targetTab.setBackgroundColor(rh.gac(context, R.attr.defaultbackground))
|
binding.target.visibility = (position == 4).toVisibility()
|
||||||
selected.setBackgroundColor(rh.gac(context, R.attr.tabBgColorSelected))
|
|
||||||
binding.diaPlaceholder.visibility = View.GONE
|
|
||||||
binding.ic.visibility = View.GONE
|
|
||||||
binding.isf.visibility = View.GONE
|
|
||||||
binding.basal.visibility = View.GONE
|
|
||||||
binding.target.visibility = View.GONE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateProtectedUi() {
|
private fun updateProtectedUi() {
|
||||||
|
|
|
@ -120,63 +120,37 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<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="match_parent"
|
android:layout_height="wrap_content">
|
||||||
android:orientation="horizontal"
|
|
||||||
android:paddingBottom="10dp"
|
|
||||||
android:weightSum="5">
|
|
||||||
|
|
||||||
<TextView
|
<com.google.android.material.tabs.TabItem
|
||||||
android:id="@+id/dia_tab"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:text="@string/dia_short" />
|
||||||
android:text="@string/dia_short"
|
|
||||||
android:textAlignment="center"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<TextView
|
<com.google.android.material.tabs.TabItem
|
||||||
android:id="@+id/ic_tab"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:text="@string/ic_short" />
|
||||||
android:text="@string/ic_short"
|
|
||||||
android:textAlignment="center"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<TextView
|
<com.google.android.material.tabs.TabItem
|
||||||
android:id="@+id/isf_tab"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:text="@string/isf_short" />
|
||||||
android:text="@string/isf_short"
|
|
||||||
android:textAlignment="center"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<TextView
|
<com.google.android.material.tabs.TabItem
|
||||||
android:id="@+id/basal_tab"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:text="@string/basal_short" />
|
||||||
android:text="@string/basal_short"
|
|
||||||
android:textAlignment="center"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<TextView
|
<com.google.android.material.tabs.TabItem
|
||||||
android:id="@+id/target_tab"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:text="@string/target_short" />
|
||||||
android:text="@string/target_short"
|
|
||||||
android:textAlignment="center"
|
</com.google.android.material.tabs.TabLayout>
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/dia_placeholder"
|
android:id="@+id/dia_placeholder"
|
||||||
|
|
Loading…
Reference in a new issue