chore: convert treamtents buttons to tabs
This commit is contained in:
parent
75032c571f
commit
1fbc6d24cb
|
@ -2,12 +2,14 @@ package info.nightscout.androidaps.activities
|
|||
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.fragment.app.Fragment
|
||||
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.activities.fragments.*
|
||||
import info.nightscout.androidaps.databinding.TreatmentsFragmentBinding
|
||||
import info.nightscout.androidaps.extensions.toVisibility
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
||||
import javax.inject.Inject
|
||||
|
@ -23,49 +25,34 @@ class TreatmentsActivity : NoSplashAppCompatActivity() {
|
|||
super.onCreate(savedInstanceState)
|
||||
binding = TreatmentsFragmentBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
//binding.tempBasals.visibility = buildHelper.isEngineeringMode().toVisibility()
|
||||
//binding.extendedBoluses.visibility = (buildHelper.isEngineeringMode() && !activePlugin.activePump.isFakingTempsByExtendedBoluses).toVisibility()
|
||||
|
||||
// Use index, TabItems crashes with an id
|
||||
val useFakeTempBasal = activePlugin.activePump.isFakingTempsByExtendedBoluses
|
||||
binding.treatmentsTabs.getTabAt(1)?.view?.visibility = useFakeTempBasal.toVisibility()
|
||||
|
||||
binding.treatments.setOnClickListener {
|
||||
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)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
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 {
|
||||
|
@ -86,15 +73,4 @@ class TreatmentsActivity : NoSplashAppCompatActivity() {
|
|||
.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"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -12,101 +11,54 @@
|
|||
android:layout_height="wrap_content"
|
||||
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_height="wrap_content"
|
||||
android:background="?attr/defaultbackground"
|
||||
app:alignContent="stretch"
|
||||
app:alignItems="stretch"
|
||||
app:flexDirection="row"
|
||||
app:flexWrap="wrap"
|
||||
app:justifyContent="center">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/treatments"
|
||||
<com.google.android.material.tabs.TabItem
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="1dp"
|
||||
android:paddingEnd="1dp"
|
||||
android:layout_weight="1"
|
||||
android:contentDescription="@string/bolus"
|
||||
android:scaleX="0.8"
|
||||
android:scaleY="0.8"
|
||||
app:srcCompat="@drawable/ic_cp_bolus_carbs" />
|
||||
android:icon="@drawable/ic_cp_bolus_carbs" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/extended_boluses"
|
||||
<com.google.android.material.tabs.TabItem
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:contentDescription="@string/extended_bolus"
|
||||
android:paddingStart="1dp"
|
||||
android:paddingEnd="1dp"
|
||||
android:scaleX="0.7"
|
||||
android:scaleY="0.7"
|
||||
app:srcCompat="@drawable/ic_actions_startextbolus" />
|
||||
android:icon="@drawable/ic_actions_startextbolus" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/temp_basals"
|
||||
<com.google.android.material.tabs.TabItem
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="1dp"
|
||||
android:paddingEnd="1dp"
|
||||
android:layout_weight="1"
|
||||
android:contentDescription="@string/tempbasal_label"
|
||||
android:scaleX="0.7"
|
||||
android:scaleY="0.7"
|
||||
app:srcCompat="@drawable/ic_actions_starttempbasal" />
|
||||
android:icon="@drawable/ic_actions_starttempbasal" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/temp_targets"
|
||||
<com.google.android.material.tabs.TabItem
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="1dp"
|
||||
android:paddingEnd="1dp"
|
||||
android:layout_weight="1"
|
||||
android:contentDescription="@string/careportal_temporarytarget"
|
||||
android:scaleX="0.7"
|
||||
android:scaleY="0.7"
|
||||
app:srcCompat="@drawable/ic_temptarget_high" />
|
||||
android:icon="@drawable/ic_temptarget_high" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/profile_switches"
|
||||
<com.google.android.material.tabs.TabItem
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="1dp"
|
||||
android:paddingEnd="1dp"
|
||||
android:layout_weight="1"
|
||||
android:contentDescription="@string/careportal_profileswitch"
|
||||
android:scaleX="0.7"
|
||||
android:scaleY="0.7"
|
||||
app:srcCompat="@drawable/ic_actions_profileswitch" />
|
||||
android:icon="@drawable/ic_actions_profileswitch" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/careportal"
|
||||
<com.google.android.material.tabs.TabItem
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="1dp"
|
||||
android:paddingEnd="1dp"
|
||||
android:layout_weight="1"
|
||||
android:contentDescription="@string/careportal"
|
||||
android:scaleX="0.7"
|
||||
android:scaleY="0.7"
|
||||
app:srcCompat="@drawable/ic_cp_note" />
|
||||
android:icon="@drawable/ic_cp_note" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/userentry"
|
||||
<com.google.android.material.tabs.TabItem
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:contentDescription="@string/userentry"
|
||||
android:paddingStart="1dp"
|
||||
android:paddingEnd="1dp"
|
||||
android:scaleX="0.7"
|
||||
android:scaleY="0.7"
|
||||
app:srcCompat="@drawable/ic_danar_useropt" />
|
||||
android:icon="@drawable/ic_danar_useropt" />
|
||||
|
||||
</com.google.android.flexbox.FlexboxLayout>
|
||||
</com.google.android.material.tabs.TabLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragment_container"
|
||||
|
|
Loading…
Reference in a new issue