TreatmentsExtendedBolusesFragment -> jetpack

This commit is contained in:
Milos Kozak 2021-02-02 21:38:22 +01:00
parent 609c1dfad3
commit 29e33a68c2
4 changed files with 88 additions and 89 deletions

View file

@ -18,7 +18,6 @@ import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.tidepool_fragment.*
import javax.inject.Inject import javax.inject.Inject
class TidepoolFragment : DaggerFragment() { class TidepoolFragment : DaggerFragment() {

View file

@ -7,14 +7,14 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Intervals import info.nightscout.androidaps.data.Intervals
import info.nightscout.androidaps.databinding.TreatmentsExtendedbolusFragmentBinding
import info.nightscout.androidaps.databinding.TreatmentsExtendedbolusItemBinding
import info.nightscout.androidaps.db.ExtendedBolus import info.nightscout.androidaps.db.ExtendedBolus
import info.nightscout.androidaps.db.Source import info.nightscout.androidaps.db.Source
import info.nightscout.androidaps.events.EventExtendedBolusChange import info.nightscout.androidaps.events.EventExtendedBolusChange
@ -31,10 +31,10 @@ import info.nightscout.androidaps.utils.alertDialogs.OKDialog.showConfirmation
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.treatments_extendedbolus_fragment.*
import javax.inject.Inject import javax.inject.Inject
class TreatmentsExtendedBolusesFragment : DaggerFragment() { class TreatmentsExtendedBolusesFragment : DaggerFragment() {
private val disposable = CompositeDisposable() private val disposable = CompositeDisposable()
@Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var activePlugin: ActivePluginProvider
@ -46,18 +46,26 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
@Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var dateUtil: DateUtil @Inject lateinit var dateUtil: DateUtil
private var _binding: TreatmentsExtendedbolusFragmentBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? { savedInstanceState: Bundle?): View {
return inflater.inflate(R.layout.treatments_extendedbolus_fragment, container, false) _binding = TreatmentsExtendedbolusFragmentBinding.inflate(inflater, container, false)
return binding.root
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
extendedboluses_recyclerview.setHasFixedSize(true) binding.recyclerview.setHasFixedSize(true)
extendedboluses_recyclerview.layoutManager = LinearLayoutManager(view.context) binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
extendedboluses_recyclerview.adapter = RecyclerViewAdapter(activePlugin.activeTreatments.extendedBolusesFromHistory) binding.recyclerview.adapter = RecyclerViewAdapter(activePlugin.activeTreatments.extendedBolusesFromHistory)
} }
inner class RecyclerViewAdapter internal constructor(private var extendedBolusList: Intervals<ExtendedBolus>) : RecyclerView.Adapter<ExtendedBolusesViewHolder>() { private inner class RecyclerViewAdapter(private var extendedBolusList: Intervals<ExtendedBolus>) : RecyclerView.Adapter<ExtendedBolusesViewHolder>() {
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ExtendedBolusesViewHolder { override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ExtendedBolusesViewHolder {
val v = LayoutInflater.from(viewGroup.context).inflate(R.layout.treatments_extendedbolus_item, viewGroup, false) val v = LayoutInflater.from(viewGroup.context).inflate(R.layout.treatments_extendedbolus_item, viewGroup, false)
return ExtendedBolusesViewHolder(v) return ExtendedBolusesViewHolder(v)
@ -65,32 +73,32 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
override fun onBindViewHolder(holder: ExtendedBolusesViewHolder, position: Int) { override fun onBindViewHolder(holder: ExtendedBolusesViewHolder, position: Int) {
val extendedBolus = extendedBolusList.getReversed(position) val extendedBolus = extendedBolusList.getReversed(position)
holder.ph.visibility = if (extendedBolus.source == Source.PUMP) View.VISIBLE else View.GONE holder.binding.ph.visibility = if (extendedBolus.source == Source.PUMP) View.VISIBLE else View.GONE
holder.ns.visibility = if (NSUpload.isIdValid(extendedBolus._id)) View.VISIBLE else View.GONE holder.binding.ns.visibility = if (NSUpload.isIdValid(extendedBolus._id)) View.VISIBLE else View.GONE
if (extendedBolus.isEndingEvent) { if (extendedBolus.isEndingEvent) {
holder.date.text = dateUtil.dateAndTimeString(extendedBolus.date) holder.binding.date.text = dateUtil.dateAndTimeString(extendedBolus.date)
holder.duration.text = resourceHelper.gs(R.string.cancel) holder.binding.duration.text = resourceHelper.gs(R.string.cancel)
holder.insulin.text = "" holder.binding.insulin.text = ""
holder.realDuration.text = "" holder.binding.realDuration.text = ""
holder.iob.text = "" holder.binding.iob.text = ""
holder.insulinSoFar.text = "" holder.binding.insulinSoFar.text = ""
holder.ratio.text = "" holder.binding.ratio.text = ""
} else { } else {
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
if (extendedBolus.isInProgress) holder.date.text = dateUtil.dateAndTimeString(extendedBolus.date) if (extendedBolus.isInProgress) holder.binding.date.text = dateUtil.dateAndTimeString(extendedBolus.date)
else holder.date.text = dateUtil.dateAndTimeString(extendedBolus.date) + " - " + dateUtil.timeString(extendedBolus.end()) else holder.binding.date.text = dateUtil.dateAndTimeString(extendedBolus.date) + " - " + dateUtil.timeString(extendedBolus.end())
val profile = profileFunction.getProfile(extendedBolus.date) val profile = profileFunction.getProfile(extendedBolus.date)
holder.duration.text = resourceHelper.gs(R.string.format_mins, extendedBolus.durationInMinutes) holder.binding.duration.text = resourceHelper.gs(R.string.format_mins, extendedBolus.durationInMinutes)
holder.insulin.text = resourceHelper.gs(R.string.formatinsulinunits, extendedBolus.insulin) holder.binding.insulin.text = resourceHelper.gs(R.string.formatinsulinunits, extendedBolus.insulin)
holder.realDuration.text = resourceHelper.gs(R.string.format_mins, extendedBolus.realDuration) holder.binding.realDuration.text = resourceHelper.gs(R.string.format_mins, extendedBolus.realDuration)
val iob = extendedBolus.iobCalc(System.currentTimeMillis(), profile) val iob = extendedBolus.iobCalc(System.currentTimeMillis(), profile)
holder.iob.text = resourceHelper.gs(R.string.formatinsulinunits, iob.iob) holder.binding.iob.text = resourceHelper.gs(R.string.formatinsulinunits, iob.iob)
holder.insulinSoFar.text = resourceHelper.gs(R.string.formatinsulinunits, extendedBolus.insulinSoFar()) holder.binding.insulinSoFar.text = resourceHelper.gs(R.string.formatinsulinunits, extendedBolus.insulinSoFar())
holder.ratio.text = resourceHelper.gs(R.string.pump_basebasalrate, extendedBolus.absoluteRate()) holder.binding.ratio.text = resourceHelper.gs(R.string.pump_basebasalrate, extendedBolus.absoluteRate())
if (extendedBolus.isInProgress) holder.date.setTextColor(resourceHelper.gc(R.color.colorActive)) else holder.date.setTextColor(holder.insulin.currentTextColor) if (extendedBolus.isInProgress) holder.binding.date.setTextColor(resourceHelper.gc(R.color.colorActive)) else holder.binding.date.setTextColor(holder.binding.insulin.currentTextColor)
if (iob.iob != 0.0) holder.iob.setTextColor(resourceHelper.gc(R.color.colorActive)) else holder.iob.setTextColor(holder.insulin.currentTextColor) if (iob.iob != 0.0) holder.binding.iob.setTextColor(resourceHelper.gc(R.color.colorActive)) else holder.binding.iob.setTextColor(holder.binding.insulin.currentTextColor)
} }
holder.remove.tag = extendedBolus holder.binding.remove.tag = extendedBolus
} }
override fun getItemCount(): Int { override fun getItemCount(): Int {
@ -98,20 +106,11 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
} }
inner class ExtendedBolusesViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { inner class ExtendedBolusesViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
var cv: CardView = itemView.findViewById(R.id.extendedboluses_cardview)
var date: TextView = itemView.findViewById(R.id.extendedboluses_date) val binding = TreatmentsExtendedbolusItemBinding.bind(itemView)
var duration: TextView = itemView.findViewById(R.id.extendedboluses_duration)
var insulin: TextView = itemView.findViewById(R.id.extendedboluses_insulin)
var realDuration: TextView = itemView.findViewById(R.id.extendedboluses_realduration)
var ratio: TextView = itemView.findViewById(R.id.extendedboluses_ratio)
var insulinSoFar: TextView = itemView.findViewById(R.id.extendedboluses_netinsulin)
var iob: TextView = itemView.findViewById(R.id.extendedboluses_iob)
var remove: TextView = itemView.findViewById(R.id.extendedboluses_remove)
var ph: TextView = itemView.findViewById(R.id.pump_sign)
var ns: TextView = itemView.findViewById(R.id.ns_sign)
init { init {
remove.setOnClickListener { v: View -> binding.remove.setOnClickListener { v: View ->
val extendedBolus = v.tag as ExtendedBolus val extendedBolus = v.tag as ExtendedBolus
context?.let { context?.let {
showConfirmation(it, resourceHelper.gs(R.string.removerecord), showConfirmation(it, resourceHelper.gs(R.string.removerecord),
@ -126,7 +125,7 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
}, null) }, null)
} }
} }
remove.paintFlags = remove.paintFlags or Paint.UNDERLINE_TEXT_FLAG binding.remove.paintFlags = binding.remove.paintFlags or Paint.UNDERLINE_TEXT_FLAG
} }
} }
@ -152,6 +151,14 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
disposable.clear() disposable.clear()
} }
private fun updateGui() = @Synchronized
extendedboluses_recyclerview.swapAdapter(RecyclerViewAdapter(activePlugin.activeTreatments.extendedBolusesFromHistory), false) override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
private fun updateGui() {
if (_binding == null) return
binding.recyclerview.swapAdapter(RecyclerViewAdapter(activePlugin.activeTreatments.extendedBolusesFromHistory), false)
}
} }

View file

@ -1,20 +1,15 @@
<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" 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"
tools:context="info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsExtendedBolusesFragment"> android:orientation="vertical"
tools:context=".plugins.treatments.fragments.TreatmentsExtendedBolusesFragment">
<LinearLayout <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView </androidx.recyclerview.widget.RecyclerView>
android:id="@+id/extendedboluses_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView> </LinearLayout>
</LinearLayout>
</FrameLayout>

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/extendedboluses_cardview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
@ -23,31 +22,31 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:gravity="center_vertical|right" android:gravity="center_vertical"
android:paddingLeft="10dp" android:paddingStart="10dp"
android:paddingRight="5dp" android:paddingEnd="5dp"
android:text="{fa-clock-o}" /> android:text="{fa-clock-o}" />
<TextView <TextView
android:id="@+id/extendedboluses_date" android:id="@+id/date"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="1.1.2000 18:00" android:text="1.1.2000 18:00"
android:textAppearance="?android:attr/textAppearanceSmall" /> android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView <TextView
android:id="@+id/extendedboluses_insulin" android:id="@+id/insulin"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="10dp" android:paddingStart="10dp"
android:text="150%" android:text="150%"
android:textAppearance="?android:attr/textAppearanceSmall" /> android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView <TextView
android:id="@+id/extendedboluses_duration" android:id="@+id/duration"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="10dp" android:paddingStart="10dp"
android:text="30 min" android:text="30 min"
android:textAppearance="?android:attr/textAppearanceSmall" /> android:textAppearance="?android:attr/textAppearanceSmall" />
@ -62,17 +61,17 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="top" android:layout_gravity="top"
android:paddingLeft="10dp" android:paddingStart="10dp"
android:paddingRight="5dp" android:paddingEnd="5dp"
android:text="@string/tempbasals_realduration_label_string" android:text="@string/tempbasals_realduration_label_string"
android:textAppearance="?android:attr/textAppearanceSmall" /> android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView <TextView
android:id="@+id/extendedboluses_realduration" android:id="@+id/real_duration"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:paddingRight="10dp" android:paddingEnd="10dp"
android:text="10 min" android:text="10 min"
android:textStyle="bold" /> android:textStyle="bold" />
@ -80,16 +79,16 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="top" android:layout_gravity="top"
android:paddingRight="5dp" android:paddingEnd="5dp"
android:text="@string/tempbasals_netratio_label_string" android:text="@string/tempbasals_netratio_label_string"
android:textAppearance="?android:attr/textAppearanceSmall" /> android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView <TextView
android:id="@+id/extendedboluses_ratio" android:id="@+id/ratio"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:paddingRight="10dp" android:paddingEnd="10dp"
android:text="0.05 U/h" android:text="0.05 U/h"
android:textStyle="bold" /> android:textStyle="bold" />
@ -97,39 +96,39 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="top" android:layout_gravity="top"
android:paddingRight="5dp" android:paddingEnd="5dp"
android:text="@string/tempbasals_netinsulin_label_string" android:text="@string/tempbasals_netinsulin_label_string"
android:textAppearance="?android:attr/textAppearanceSmall" /> android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView <TextView
android:id="@+id/extendedboluses_netinsulin" android:id="@+id/insulin_so_far"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:paddingRight="10dp" android:paddingEnd="10dp"
android:text="0.05 U" android:text="0.05 U"
android:textStyle="bold" /> android:textStyle="bold" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="10dp" android:layout_marginEnd="10dp"
android:layout_weight="1" android:layout_weight="1"
android:text="" /> android:text="" />
<TextView <TextView
android:id="@+id/pump_sign" android:id="@+id/ph"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="10dp" android:layout_marginEnd="10dp"
android:text="PH" android:text="PH"
android:textColor="@color/colorSetTempButton" /> android:textColor="@color/colorSetTempButton" />
<TextView <TextView
android:id="@+id/ns_sign" android:id="@+id/ns"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="10dp" android:layout_marginEnd="10dp"
android:text="NS" android:text="NS"
android:textColor="@color/colorSetTempButton" /> android:textColor="@color/colorSetTempButton" />
@ -150,19 +149,19 @@
android:textAppearance="?android:attr/textAppearanceSmall" /> android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView <TextView
android:id="@+id/extendedboluses_iob" android:id="@+id/iob"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginRight="30dp" android:layout_marginEnd="30dp"
android:text="0.12 U" android:text="0.12 U"
android:textStyle="bold" /> android:textStyle="bold" />
<TextView <TextView
android:id="@+id/extendedboluses_remove" android:id="@+id/remove"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="10dp" android:layout_marginEnd="10dp"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/overview_quickwizard_item_remove_button" android:text="@string/overview_quickwizard_item_remove_button"
android:textAlignment="viewEnd" android:textAlignment="viewEnd"
@ -173,7 +172,6 @@
<View <View
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="2dip" android:layout_height="2dip"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp" android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" android:layout_marginRight="5dp"