Merge pull request #1576 from Andries-Smit/chore/treatment-tabs
Chore convert treatment buttons to tabs
This commit is contained in:
commit
48086c470d
|
@ -2,12 +2,14 @@ package info.nightscout.androidaps.activities
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentTransaction
|
import androidx.fragment.app.FragmentTransaction
|
||||||
|
import com.google.android.material.tabs.TabLayout
|
||||||
|
import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.activities.fragments.*
|
import info.nightscout.androidaps.activities.fragments.*
|
||||||
import info.nightscout.androidaps.databinding.TreatmentsFragmentBinding
|
import info.nightscout.androidaps.databinding.TreatmentsFragmentBinding
|
||||||
|
import info.nightscout.androidaps.extensions.toVisibility
|
||||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||||
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -23,49 +25,34 @@ class TreatmentsActivity : NoSplashAppCompatActivity() {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = TreatmentsFragmentBinding.inflate(layoutInflater)
|
binding = TreatmentsFragmentBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
//binding.tempBasals.visibility = buildHelper.isEngineeringMode().toVisibility()
|
|
||||||
//binding.extendedBoluses.visibility = (buildHelper.isEngineeringMode() && !activePlugin.activePump.isFakingTempsByExtendedBoluses).toVisibility()
|
|
||||||
|
|
||||||
binding.treatments.setOnClickListener {
|
// Use index, TabItems crashes with an id
|
||||||
|
val useFakeTempBasal = activePlugin.activePump.isFakingTempsByExtendedBoluses
|
||||||
|
binding.treatmentsTabs.getTabAt(1)?.view?.visibility = useFakeTempBasal.toVisibility()
|
||||||
|
|
||||||
setFragment(TreatmentsBolusCarbsFragment())
|
setFragment(TreatmentsBolusCarbsFragment())
|
||||||
setBackgroundColorOnSelected(it)
|
|
||||||
supportActionBar?.title = rh.gs(R.string.carbs_and_bolus)
|
|
||||||
}
|
|
||||||
binding.extendedBoluses.setOnClickListener {
|
|
||||||
setFragment(TreatmentsExtendedBolusesFragment())
|
|
||||||
setBackgroundColorOnSelected(it)
|
|
||||||
supportActionBar?.title = rh.gs(R.string.extended_bolus)
|
|
||||||
}
|
|
||||||
binding.tempBasals.setOnClickListener {
|
|
||||||
setFragment(TreatmentsTemporaryBasalsFragment())
|
|
||||||
setBackgroundColorOnSelected(it)
|
|
||||||
supportActionBar?.title = rh.gs(R.string.tempbasal_label)
|
|
||||||
}
|
|
||||||
binding.tempTargets.setOnClickListener {
|
|
||||||
setFragment(TreatmentsTempTargetFragment())
|
|
||||||
setBackgroundColorOnSelected(it)
|
|
||||||
supportActionBar?.title = rh.gs(R.string.tempt_targets)
|
|
||||||
}
|
|
||||||
binding.profileSwitches.setOnClickListener {
|
|
||||||
setFragment(TreatmentsProfileSwitchFragment())
|
|
||||||
setBackgroundColorOnSelected(it)
|
|
||||||
supportActionBar?.title = rh.gs(R.string.profile_changes)
|
|
||||||
}
|
|
||||||
binding.careportal.setOnClickListener {
|
|
||||||
setFragment(TreatmentsCareportalFragment())
|
|
||||||
setBackgroundColorOnSelected(it)
|
|
||||||
supportActionBar?.title = rh.gs(R.string.careportal)
|
|
||||||
}
|
|
||||||
binding.userentry.setOnClickListener {
|
|
||||||
setFragment(TreatmentsUserEntryFragment())
|
|
||||||
setBackgroundColorOnSelected(it)
|
|
||||||
supportActionBar?.title = rh.gs(R.string.user_action)
|
|
||||||
}
|
|
||||||
setFragment(TreatmentsBolusCarbsFragment())
|
|
||||||
setBackgroundColorOnSelected(binding.treatments)
|
|
||||||
setSupportActionBar(binding.toolbar)
|
setSupportActionBar(binding.toolbar)
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
supportActionBar?.title = rh.gs(R.string.carbs_and_bolus)
|
supportActionBar?.title = rh.gs(R.string.carbs_and_bolus)
|
||||||
|
|
||||||
|
binding.treatmentsTabs.addOnTabSelectedListener(object : OnTabSelectedListener {
|
||||||
|
override fun onTabSelected(tab: TabLayout.Tab) {
|
||||||
|
val fragment = when (tab.position) {
|
||||||
|
0 -> TreatmentsBolusCarbsFragment::class.java
|
||||||
|
1 -> TreatmentsExtendedBolusesFragment::class.java
|
||||||
|
2 -> TreatmentsTemporaryBasalsFragment::class.java
|
||||||
|
3 -> TreatmentsTempTargetFragment::class.java
|
||||||
|
4 -> TreatmentsProfileSwitchFragment::class.java
|
||||||
|
5 -> TreatmentsCareportalFragment::class.java
|
||||||
|
else -> TreatmentsUserEntryFragment::class.java
|
||||||
|
}
|
||||||
|
setFragment(fragment.newInstance())
|
||||||
|
supportActionBar?.title = tab.contentDescription
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTabUnselected(tab: TabLayout.Tab) {}
|
||||||
|
override fun onTabReselected(tab: TabLayout.Tab) {}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
|
@ -86,15 +73,4 @@ class TreatmentsActivity : NoSplashAppCompatActivity() {
|
||||||
.commit()
|
.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setBackgroundColorOnSelected(selected: View) {
|
|
||||||
binding.treatments.setBackgroundColor(rh.gac(this, R.attr.defaultbackground))
|
|
||||||
binding.extendedBoluses.setBackgroundColor(rh.gac(this, R.attr.defaultbackground))
|
|
||||||
binding.tempBasals.setBackgroundColor(rh.gac(this, R.attr.defaultbackground))
|
|
||||||
binding.tempTargets.setBackgroundColor(rh.gac(this, R.attr.defaultbackground))
|
|
||||||
binding.profileSwitches.setBackgroundColor(rh.gac(this, R.attr.defaultbackground))
|
|
||||||
binding.careportal.setBackgroundColor(rh.gac(this, R.attr.defaultbackground))
|
|
||||||
binding.userentry.setBackgroundColor(rh.gac(this, R.attr.defaultbackground))
|
|
||||||
selected.setBackgroundColor(rh.gac(this, R.attr.tabBgColorSelected))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
@ -12,101 +11,54 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minHeight="?attr/actionBarSize" />
|
android:minHeight="?attr/actionBarSize" />
|
||||||
|
|
||||||
<com.google.android.flexbox.FlexboxLayout
|
<com.google.android.material.tabs.TabLayout
|
||||||
|
android:id="@+id/treatments_tabs"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
android:background="?attr/defaultbackground"
|
|
||||||
app:alignContent="stretch"
|
|
||||||
app:alignItems="stretch"
|
|
||||||
app:flexDirection="row"
|
|
||||||
app:flexWrap="wrap"
|
|
||||||
app:justifyContent="center">
|
|
||||||
|
|
||||||
<ImageView
|
<com.google.android.material.tabs.TabItem
|
||||||
android:id="@+id/treatments"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="1dp"
|
|
||||||
android:paddingEnd="1dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:contentDescription="@string/bolus"
|
android:contentDescription="@string/bolus"
|
||||||
android:scaleX="0.8"
|
android:icon="@drawable/ic_cp_bolus_carbs" />
|
||||||
android:scaleY="0.8"
|
|
||||||
app:srcCompat="@drawable/ic_cp_bolus_carbs" />
|
|
||||||
|
|
||||||
<ImageView
|
<com.google.android.material.tabs.TabItem
|
||||||
android:id="@+id/extended_boluses"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
|
||||||
android:contentDescription="@string/extended_bolus"
|
android:contentDescription="@string/extended_bolus"
|
||||||
android:paddingStart="1dp"
|
android:icon="@drawable/ic_actions_startextbolus" />
|
||||||
android:paddingEnd="1dp"
|
|
||||||
android:scaleX="0.7"
|
|
||||||
android:scaleY="0.7"
|
|
||||||
app:srcCompat="@drawable/ic_actions_startextbolus" />
|
|
||||||
|
|
||||||
<ImageView
|
<com.google.android.material.tabs.TabItem
|
||||||
android:id="@+id/temp_basals"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="1dp"
|
|
||||||
android:paddingEnd="1dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:contentDescription="@string/tempbasal_label"
|
android:contentDescription="@string/tempbasal_label"
|
||||||
android:scaleX="0.7"
|
android:icon="@drawable/ic_actions_starttempbasal" />
|
||||||
android:scaleY="0.7"
|
|
||||||
app:srcCompat="@drawable/ic_actions_starttempbasal" />
|
|
||||||
|
|
||||||
<ImageView
|
<com.google.android.material.tabs.TabItem
|
||||||
android:id="@+id/temp_targets"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="1dp"
|
|
||||||
android:paddingEnd="1dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:contentDescription="@string/careportal_temporarytarget"
|
android:contentDescription="@string/careportal_temporarytarget"
|
||||||
android:scaleX="0.7"
|
android:icon="@drawable/ic_temptarget_high" />
|
||||||
android:scaleY="0.7"
|
|
||||||
app:srcCompat="@drawable/ic_temptarget_high" />
|
|
||||||
|
|
||||||
<ImageView
|
<com.google.android.material.tabs.TabItem
|
||||||
android:id="@+id/profile_switches"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="1dp"
|
|
||||||
android:paddingEnd="1dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:contentDescription="@string/careportal_profileswitch"
|
android:contentDescription="@string/careportal_profileswitch"
|
||||||
android:scaleX="0.7"
|
android:icon="@drawable/ic_actions_profileswitch" />
|
||||||
android:scaleY="0.7"
|
|
||||||
app:srcCompat="@drawable/ic_actions_profileswitch" />
|
|
||||||
|
|
||||||
<ImageView
|
<com.google.android.material.tabs.TabItem
|
||||||
android:id="@+id/careportal"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="1dp"
|
|
||||||
android:paddingEnd="1dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:contentDescription="@string/careportal"
|
android:contentDescription="@string/careportal"
|
||||||
android:scaleX="0.7"
|
android:icon="@drawable/ic_cp_note" />
|
||||||
android:scaleY="0.7"
|
|
||||||
app:srcCompat="@drawable/ic_cp_note" />
|
|
||||||
|
|
||||||
<ImageView
|
<com.google.android.material.tabs.TabItem
|
||||||
android:id="@+id/userentry"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
|
||||||
android:contentDescription="@string/userentry"
|
android:contentDescription="@string/userentry"
|
||||||
android:paddingStart="1dp"
|
android:icon="@drawable/ic_danar_useropt" />
|
||||||
android:paddingEnd="1dp"
|
|
||||||
android:scaleX="0.7"
|
|
||||||
android:scaleY="0.7"
|
|
||||||
app:srcCompat="@drawable/ic_danar_useropt" />
|
|
||||||
|
|
||||||
</com.google.android.flexbox.FlexboxLayout>
|
</com.google.android.material.tabs.TabLayout>
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/fragment_container"
|
android:id="@+id/fragment_container"
|
||||||
|
|
Loading…
Reference in a new issue