TreatmentsTemporaryBasalsFragment -> jetpack

This commit is contained in:
Milos Kozak 2021-02-03 20:22:03 +01:00
parent 327f1ca63b
commit a6b7beb2d7
4 changed files with 156 additions and 148 deletions

View file

@ -70,11 +70,8 @@ class ObjectivesFragment : DaggerFragment() {
// onDestroyView.
private val binding get() = _binding!!
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View {
_binding = ObjectivesFragmentBinding.inflate(inflater, container, false)
return binding.root
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
ObjectivesFragmentBinding.inflate(inflater, container, false).also { _binding = it }.root
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

View file

@ -6,14 +6,14 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Intervals
import info.nightscout.androidaps.data.IobTotal
import info.nightscout.androidaps.databinding.TreatmentsTempbasalsFragmentBinding
import info.nightscout.androidaps.databinding.TreatmentsTempbasalsItemBinding
import info.nightscout.androidaps.db.Source
import info.nightscout.androidaps.db.TemporaryBasal
import info.nightscout.androidaps.events.EventTempBasalChange
@ -29,7 +29,6 @@ import info.nightscout.androidaps.utils.alertDialogs.OKDialog.showConfirmation
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.treatments_tempbasals_fragment.*
import javax.inject.Inject
class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
@ -43,38 +42,50 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
@Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var dateUtil: DateUtil
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.treatments_tempbasals_fragment, container, false)
}
private var _binding: TreatmentsTempbasalsFragmentBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
TreatmentsTempbasalsFragmentBinding.inflate(inflater, container, false).also { _binding = it }.root
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
tempbasals_recyclerview.setHasFixedSize(true)
tempbasals_recyclerview.layoutManager = LinearLayoutManager(view.context)
tempbasals_recyclerview.adapter = RecyclerViewAdapter(activePlugin.activeTreatments.temporaryBasalsFromHistory)
binding.recyclerview.setHasFixedSize(true)
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
binding.recyclerview.adapter = RecyclerViewAdapter(activePlugin.activeTreatments.temporaryBasalsFromHistory)
}
@Synchronized override fun onResume() {
@Synchronized
override fun onResume() {
super.onResume()
disposable.add(rxBus
.toObservable(EventTempBasalChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGui() }) { fabricPrivacy.logException(it) }
.subscribe({ updateGui() }, fabricPrivacy::logException)
)
disposable.add(rxBus
.toObservable(EventAutosensCalculationFinished::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGui() }) { fabricPrivacy.logException(it) }
.subscribe({ updateGui() }, fabricPrivacy::logException)
)
updateGui()
}
@Synchronized override fun onPause() {
@Synchronized
override fun onPause() {
super.onPause()
disposable.clear()
}
@Synchronized
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
inner class RecyclerViewAdapter internal constructor(private var tempBasalList: Intervals<TemporaryBasal>) : RecyclerView.Adapter<TempBasalsViewHolder>() {
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): TempBasalsViewHolder {
@ -84,53 +95,53 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
override fun onBindViewHolder(holder: TempBasalsViewHolder, position: Int) {
val tempBasal = tempBasalList.getReversed(position)
holder.ph.visibility = if (tempBasal.source == Source.PUMP) View.VISIBLE else View.GONE
holder.ns.visibility = if (NSUpload.isIdValid(tempBasal._id)) View.VISIBLE else View.GONE
holder.binding.ph.visibility = if (tempBasal.source == Source.PUMP) View.VISIBLE else View.GONE
holder.binding.ns.visibility = if (NSUpload.isIdValid(tempBasal._id)) View.VISIBLE else View.GONE
if (tempBasal.isEndingEvent) {
holder.date.text = dateUtil.dateAndTimeString(tempBasal.date)
holder.duration.text = resourceHelper.gs(R.string.cancel)
holder.absolute.text = ""
holder.percent.text = ""
holder.realDuration.text = ""
holder.iob.text = ""
holder.netInsulin.text = ""
holder.netRatio.text = ""
holder.extendedFlag.visibility = View.GONE
holder.iob.setTextColor(holder.netRatio.currentTextColor)
holder.binding.date.text = dateUtil.dateAndTimeString(tempBasal.date)
holder.binding.duration.text = resourceHelper.gs(R.string.cancel)
holder.binding.absolute.text = ""
holder.binding.percent.text = ""
holder.binding.realDuration.text = ""
holder.binding.iob.text = ""
holder.binding.netInsulin.text = ""
holder.binding.netRatio.text = ""
holder.binding.extendedFlag.visibility = View.GONE
holder.binding.iob.setTextColor(holder.binding.netRatio.currentTextColor)
} else {
if (tempBasal.isInProgress) {
holder.date.text = dateUtil.dateAndTimeString(tempBasal.date)
holder.date.setTextColor(resourceHelper.gc(R.color.colorActive))
holder.binding.date.text = dateUtil.dateAndTimeString(tempBasal.date)
holder.binding.date.setTextColor(resourceHelper.gc(R.color.colorActive))
} else {
holder.date.text = dateUtil.dateAndTimeRangeString(tempBasal.date, tempBasal.end())
holder.date.setTextColor(holder.netRatio.currentTextColor)
holder.binding.date.text = dateUtil.dateAndTimeRangeString(tempBasal.date, tempBasal.end())
holder.binding.date.setTextColor(holder.binding.netRatio.currentTextColor)
}
holder.duration.text = resourceHelper.gs(R.string.format_mins, tempBasal.durationInMinutes)
holder.binding.duration.text = resourceHelper.gs(R.string.format_mins, tempBasal.durationInMinutes)
if (tempBasal.isAbsolute) {
val profile = profileFunction.getProfile(tempBasal.date)
if (profile != null) {
holder.absolute.text = resourceHelper.gs(R.string.pump_basebasalrate, tempBasal.tempBasalConvertedToAbsolute(tempBasal.date, profile))
holder.percent.text = ""
holder.binding.absolute.text = resourceHelper.gs(R.string.pump_basebasalrate, tempBasal.tempBasalConvertedToAbsolute(tempBasal.date, profile))
holder.binding.percent.text = ""
} else {
holder.absolute.text = resourceHelper.gs(R.string.noprofile)
holder.percent.text = ""
holder.binding.absolute.text = resourceHelper.gs(R.string.noprofile)
holder.binding.percent.text = ""
}
} else {
holder.absolute.text = ""
holder.percent.text = resourceHelper.gs(R.string.format_percent, tempBasal.percentRate)
holder.binding.absolute.text = ""
holder.binding.percent.text = resourceHelper.gs(R.string.format_percent, tempBasal.percentRate)
}
holder.realDuration.text = resourceHelper.gs(R.string.format_mins, tempBasal.realDuration)
holder.binding.realDuration.text = resourceHelper.gs(R.string.format_mins, tempBasal.realDuration)
val now = DateUtil.now()
var iob = IobTotal(now)
val profile = profileFunction.getProfile(now)
if (profile != null) iob = tempBasal.iobCalc(now, profile)
holder.iob.text = resourceHelper.gs(R.string.formatinsulinunits, iob.basaliob)
holder.netInsulin.text = resourceHelper.gs(R.string.formatinsulinunits, iob.netInsulin)
holder.netRatio.text = resourceHelper.gs(R.string.pump_basebasalrate, iob.netRatio)
holder.extendedFlag.visibility = View.GONE
if (iob.basaliob != 0.0) holder.iob.setTextColor(resourceHelper.gc(R.color.colorActive)) else holder.iob.setTextColor(holder.netRatio.currentTextColor)
holder.binding.iob.text = resourceHelper.gs(R.string.formatinsulinunits, iob.basaliob)
holder.binding.netInsulin.text = resourceHelper.gs(R.string.formatinsulinunits, iob.netInsulin)
holder.binding.netRatio.text = resourceHelper.gs(R.string.pump_basebasalrate, iob.netRatio)
holder.binding.extendedFlag.visibility = View.GONE
if (iob.basaliob != 0.0) holder.binding.iob.setTextColor(resourceHelper.gc(R.color.colorActive)) else holder.binding.iob.setTextColor(holder.binding.netRatio.currentTextColor)
}
holder.remove.tag = tempBasal
holder.binding.remove.tag = tempBasal
}
override fun getItemCount(): Int {
@ -139,22 +150,10 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
inner class TempBasalsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
var cv: CardView = itemView.findViewById(R.id.tempbasals_cardview)
var date: TextView = itemView.findViewById(R.id.tempbasals_date)
var duration: TextView = itemView.findViewById(R.id.tempbasals_duration)
var absolute: TextView = itemView.findViewById(R.id.tempbasals_absolute)
var percent: TextView = itemView.findViewById(R.id.tempbasals_percent)
var realDuration: TextView = itemView.findViewById(R.id.tempbasals_realduration)
var netRatio: TextView = itemView.findViewById(R.id.tempbasals_netratio)
var netInsulin: TextView = itemView.findViewById(R.id.tempbasals_netinsulin)
var iob: TextView = itemView.findViewById(R.id.tempbasals_iob)
var extendedFlag: TextView = itemView.findViewById(R.id.tempbasals_extendedflag)
var remove: TextView = itemView.findViewById(R.id.tempbasals_remove)
var ph: TextView = itemView.findViewById(R.id.pump_sign)
var ns: TextView = itemView.findViewById(R.id.ns_sign)
val binding = TreatmentsTempbasalsItemBinding.bind(itemView)
init {
remove.setOnClickListener { v: View ->
binding.remove.setOnClickListener { v: View ->
val tempBasal = v.tag as TemporaryBasal
context?.let {
showConfirmation(it, resourceHelper.gs(R.string.removerecord),
@ -167,15 +166,16 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
}, null)
}
}
remove.paintFlags = remove.paintFlags or Paint.UNDERLINE_TEXT_FLAG
binding.remove.paintFlags = binding.remove.paintFlags or Paint.UNDERLINE_TEXT_FLAG
}
}
}
private fun updateGui() {
tempbasals_recyclerview?.swapAdapter(RecyclerViewAdapter(activePlugin.activeTreatments.temporaryBasalsFromHistory), false)
if (_binding == null) return
binding.recyclerview.swapAdapter(RecyclerViewAdapter(activePlugin.activeTreatments.temporaryBasalsFromHistory), false)
val tempBasalsCalculation = activePlugin.activeTreatments.lastCalculationTempBasals
if (tempBasalsCalculation != null) tempbasals_totaltempiob?.text = resourceHelper.gs(R.string.formatinsulinunits, tempBasalsCalculation.basaliob)
if (tempBasalsCalculation != null) binding.totalTempIob.text = resourceHelper.gs(R.string.formatinsulinunits, tempBasalsCalculation.basaliob)
}
}

View file

@ -1,44 +1,42 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsTemporaryBasalsFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<LinearLayout
android:layout_width="match_parent"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingTop="10dp">
android:paddingStart="10dp"
android:text="@string/tempbasals_iobtotal_label_string"
android:textAppearance="?android:attr/textAppearanceSmall"
tools:ignore="RtlSymmetry" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="@string/tempbasals_iobtotal_label_string"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/total_temp_iob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold"
tools:ignore="RtlSymmetry" />
<TextView
android:id="@+id/tempbasals_totaltempiob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/tempbasals_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
</FrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/tempbasals_cardview"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -23,51 +23,57 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical|right"
android:paddingLeft="10dp"
android:paddingRight="5dp"
android:text="{fa-clock-o}" />
android:gravity="center"
android:paddingStart="10dp"
android:paddingEnd="5dp"
android:text="{fa-clock-o}"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/tempbasals_date"
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.1.2000 18:00"
android:textAppearance="?android:attr/textAppearanceSmall" />
android:textAppearance="?android:attr/textAppearanceSmall"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/tempbasals_absolute"
android:id="@+id/absolute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingStart="10dp"
android:text="0.25 U"
android:textAppearance="?android:attr/textAppearanceSmall" />
android:textAppearance="?android:attr/textAppearanceSmall"
tools:ignore="HardcodedText,RtlSymmetry" />
<TextView
android:id="@+id/tempbasals_percent"
android:id="@+id/percent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingStart="10dp"
android:text="150%"
android:textAppearance="?android:attr/textAppearanceSmall" />
android:textAppearance="?android:attr/textAppearanceSmall"
tools:ignore="HardcodedText,RtlSymmetry" />
<TextView
android:id="@+id/tempbasals_duration"
android:id="@+id/duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingStart="10dp"
android:text="30 min"
android:textAppearance="?android:attr/textAppearanceSmall" />
android:textAppearance="?android:attr/textAppearanceSmall"
tools:ignore="HardcodedText,RtlSymmetry" />
<TextView
android:id="@+id/tempbasals_extendedflag"
android:layout_width="wrap_content"
android:id="@+id/extended_flag"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:paddingRight="5dp"
android:gravity="end"
android:paddingEnd="5dp"
android:text="E"
android:textColor="@color/colorSetExtendedButton" />
android:textColor="@color/colorSetExtendedButton"
tools:ignore="HardcodedText,RtlSymmetry" />
</LinearLayout>
@ -81,76 +87,83 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:paddingLeft="10dp"
android:paddingRight="5dp"
android:paddingStart="10dp"
android:paddingEnd="5dp"
android:text="@string/tempbasals_realduration_label_string"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/tempbasals_realduration"
android:id="@+id/real_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingRight="10dp"
android:paddingEnd="10dp"
android:text="10 min"
android:textStyle="bold" />
android:textStyle="bold"
tools:ignore="HardcodedText,RtlSymmetry" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:paddingRight="5dp"
android:paddingEnd="5dp"
android:text="@string/tempbasals_netratio_label_string"
android:textAppearance="?android:attr/textAppearanceSmall" />
android:textAppearance="?android:attr/textAppearanceSmall"
tools:ignore="RtlSymmetry" />
<TextView
android:id="@+id/tempbasals_netratio"
android:id="@+id/net_ratio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingRight="10dp"
android:paddingEnd="10dp"
android:text="0.05 U/h"
android:textStyle="bold" />
android:textStyle="bold"
tools:ignore="HardcodedText,RtlSymmetry" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:paddingRight="5dp"
android:paddingEnd="5dp"
android:text="@string/tempbasals_netinsulin_label_string"
android:textAppearance="?android:attr/textAppearanceSmall" />
android:textAppearance="?android:attr/textAppearanceSmall"
tools:ignore="RtlSymmetry" />
<TextView
android:id="@+id/tempbasals_netinsulin"
android:id="@+id/net_insulin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingRight="10dp"
android:paddingEnd="10dp"
android:text="0.05 U"
android:textStyle="bold" />
android:textStyle="bold"
tools:ignore="HardcodedText,RtlSymmetry" />
<TextView
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:text="" />
<TextView
android:id="@+id/pump_sign"
android:id="@+id/ph"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:text="PH"
android:textColor="@color/colorSetTempButton" />
android:textColor="@color/colorSetTempButton"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/ns_sign"
android:id="@+id/ns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:text="NS"
android:textColor="@color/colorSetTempButton" />
android:textColor="@color/colorSetTempButton"
tools:ignore="HardcodedText" />
</LinearLayout>
@ -169,19 +182,20 @@
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/tempbasals_iob"
android:id="@+id/iob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="30dp"
android:layout_marginEnd="30dp"
android:text="0.12 U"
android:textStyle="bold" />
android:textStyle="bold"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/tempbasals_remove"
android:layout_width="wrap_content"
android:id="@+id/remove"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:text="@string/overview_quickwizard_item_remove_button"
android:textAlignment="viewEnd"
@ -192,7 +206,6 @@
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"