merge upstream changes
This commit is contained in:
parent
8318202755
commit
b86a81bdff
1 changed files with 85 additions and 43 deletions
|
@ -1,10 +1,9 @@
|
||||||
package info.nightscout.androidaps.plugins.source
|
package info.nightscout.androidaps.plugins.source
|
||||||
|
|
||||||
import android.graphics.Paint
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.util.SparseArray
|
||||||
import android.view.View
|
import android.view.*
|
||||||
import android.view.ViewGroup
|
import androidx.core.util.forEach
|
||||||
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
|
||||||
|
@ -26,6 +25,7 @@ import info.nightscout.androidaps.interfaces.PluginBase
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
|
import info.nightscout.androidaps.utils.ActionModeHelper
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.T
|
import info.nightscout.androidaps.utils.T
|
||||||
|
@ -54,11 +54,10 @@ class BGSourceFragment : DaggerFragment() {
|
||||||
|
|
||||||
private val disposable = CompositeDisposable()
|
private val disposable = CompositeDisposable()
|
||||||
private val millsToThePast = T.hours(36).msecs()
|
private val millsToThePast = T.hours(36).msecs()
|
||||||
|
private lateinit var actionHelper: ActionModeHelper<GlucoseValue>
|
||||||
private var _binding: BgsourceFragmentBinding? = null
|
private var _binding: BgsourceFragmentBinding? = null
|
||||||
|
|
||||||
// This property is only valid between onCreateView and
|
// This property is only valid between onCreateView and onDestroyView.
|
||||||
// onDestroyView.
|
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||||
|
@ -66,6 +65,10 @@ class BGSourceFragment : DaggerFragment() {
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
actionHelper = ActionModeHelper(rh, activity)
|
||||||
|
actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() }
|
||||||
|
actionHelper.setOnRemoveHandler { removeSelected(it) }
|
||||||
|
setHasOptionsMenu(actionHelper.inMenu)
|
||||||
|
|
||||||
binding.recyclerview.setHasFixedSize(true)
|
binding.recyclerview.setHasFixedSize(true)
|
||||||
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
|
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
|
||||||
|
@ -94,10 +97,21 @@ class BGSourceFragment : DaggerFragment() {
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
|
actionHelper.finish()
|
||||||
disposable.clear()
|
disposable.clear()
|
||||||
super.onPause()
|
super.onPause()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||||
|
super.onCreateOptionsMenu(menu, inflater)
|
||||||
|
actionHelper.onCreateOptionsMenu(menu, inflater)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||||
|
super.onPrepareOptionsMenu(menu)
|
||||||
|
actionHelper.onPrepareOptionsMenu(menu)
|
||||||
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
|
@ -105,6 +119,9 @@ class BGSourceFragment : DaggerFragment() {
|
||||||
_binding = null
|
_binding = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem) =
|
||||||
|
actionHelper.onOptionsItemSelected(item)
|
||||||
|
|
||||||
inner class RecyclerViewAdapter internal constructor(private var glucoseValues: List<GlucoseValue>) : RecyclerView.Adapter<RecyclerViewAdapter.GlucoseValuesViewHolder>() {
|
inner class RecyclerViewAdapter internal constructor(private var glucoseValues: List<GlucoseValue>) : RecyclerView.Adapter<RecyclerViewAdapter.GlucoseValuesViewHolder>() {
|
||||||
|
|
||||||
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): GlucoseValuesViewHolder {
|
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): GlucoseValuesViewHolder {
|
||||||
|
@ -116,59 +133,84 @@ class BGSourceFragment : DaggerFragment() {
|
||||||
val glucoseValue = glucoseValues[position]
|
val glucoseValue = glucoseValues[position]
|
||||||
holder.binding.ns.visibility = (glucoseValue.interfaceIDs.nightscoutId != null).toVisibility()
|
holder.binding.ns.visibility = (glucoseValue.interfaceIDs.nightscoutId != null).toVisibility()
|
||||||
holder.binding.invalid.visibility = (!glucoseValue.isValid).toVisibility()
|
holder.binding.invalid.visibility = (!glucoseValue.isValid).toVisibility()
|
||||||
val sameDayPrevious = position > 0 && dateUtil.isSameDay(glucoseValue.timestamp, glucoseValues[position-1].timestamp)
|
val newDay = position == 0 || !dateUtil.isSameDay(glucoseValue.timestamp, glucoseValues[position - 1].timestamp)
|
||||||
holder.binding.date.visibility = sameDayPrevious.not().toVisibility()
|
holder.binding.date.visibility = newDay.toVisibility()
|
||||||
holder.binding.date.text = dateUtil.dateString(glucoseValue.timestamp)
|
holder.binding.date.text = if (newDay) dateUtil.dateStringRelative(glucoseValue.timestamp, rh) else ""
|
||||||
holder.binding.time.text = dateUtil.timeString(glucoseValue.timestamp)
|
holder.binding.time.text = dateUtil.timeString(glucoseValue.timestamp)
|
||||||
holder.binding.value.text = glucoseValue.valueToUnitsString(profileFunction.getUnits())
|
holder.binding.value.text = glucoseValue.valueToUnitsString(profileFunction.getUnits())
|
||||||
holder.binding.direction.setImageResource(glucoseValue.trendArrow.directionToIcon())
|
holder.binding.direction.setImageResource(glucoseValue.trendArrow.directionToIcon())
|
||||||
holder.binding.remove.tag = glucoseValue
|
|
||||||
if (position > 0) {
|
if (position > 0) {
|
||||||
val previous = glucoseValues[position - 1]
|
val previous = glucoseValues[position - 1]
|
||||||
val diff = previous.timestamp - glucoseValue.timestamp
|
val diff = previous.timestamp - glucoseValue.timestamp
|
||||||
if (diff < T.secs(20).msecs())
|
if (diff < T.secs(20).msecs())
|
||||||
holder.binding.root.setBackgroundColor(rh.gc(R.color.errorAlertBackground))
|
holder.binding.root.setBackgroundColor(rh.gac(context, R.attr.bgsourceError))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
holder.binding.root.setOnLongClickListener {
|
||||||
|
if (actionHelper.startRemove()) {
|
||||||
|
holder.binding.cbRemove.toggle()
|
||||||
|
actionHelper.updateSelection(position, glucoseValue, holder.binding.cbRemove.isChecked)
|
||||||
|
return@setOnLongClickListener true
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
holder.binding.root.setOnClickListener {
|
||||||
|
if (actionHelper.isRemoving) {
|
||||||
|
holder.binding.cbRemove.toggle()
|
||||||
|
actionHelper.updateSelection(position, glucoseValue, holder.binding.cbRemove.isChecked)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
holder.binding.cbRemove.setOnCheckedChangeListener { _, value ->
|
||||||
|
actionHelper.updateSelection(position, glucoseValue, value)
|
||||||
|
}
|
||||||
|
holder.binding.cbRemove.isChecked = actionHelper.isSelected(position)
|
||||||
|
holder.binding.cbRemove.visibility = actionHelper.isRemoving.toVisibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int = glucoseValues.size
|
override fun getItemCount() = glucoseValues.size
|
||||||
|
|
||||||
inner class GlucoseValuesViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
inner class GlucoseValuesViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||||
|
|
||||||
val binding = BgsourceItemBinding.bind(view)
|
val binding = BgsourceItemBinding.bind(view)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
private fun getConfirmationText(selectedItems: SparseArray<GlucoseValue>): String {
|
||||||
binding.remove.paintFlags = binding.remove.paintFlags or Paint.UNDERLINE_TEXT_FLAG
|
if (selectedItems.size() == 1) {
|
||||||
binding.remove.setOnClickListener { v: View ->
|
val glucoseValue = selectedItems.valueAt(0)
|
||||||
val glucoseValue = v.tag as GlucoseValue
|
return dateUtil.dateAndTimeString(glucoseValue.timestamp) + "\n" + glucoseValue.valueToUnitsString(profileFunction.getUnits())
|
||||||
activity?.let { activity ->
|
}
|
||||||
val text = dateUtil.dateAndTimeString(glucoseValue.timestamp) + "\n" + glucoseValue.valueToUnitsString(profileFunction.getUnits())
|
return rh.gs(R.string.confirm_remove_multiple_items, selectedItems.size())
|
||||||
OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), text, Runnable {
|
}
|
||||||
val source = when ((activePlugin.activeBgSource as PluginBase).pluginDescription.pluginName) {
|
|
||||||
R.string.dexcom_app_patched -> Sources.Dexcom
|
private fun removeSelected(selectedItems: SparseArray<GlucoseValue>) {
|
||||||
R.string.eversense -> Sources.Eversense
|
activity?.let { activity ->
|
||||||
R.string.Glimp -> Sources.Glimp
|
OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), getConfirmationText(selectedItems), Runnable {
|
||||||
R.string.MM640g -> Sources.MM640g
|
selectedItems.forEach { _, glucoseValue ->
|
||||||
R.string.nsclientbg -> Sources.NSClientSource
|
val source = when ((activePlugin.activeBgSource as PluginBase).pluginDescription.pluginName) {
|
||||||
R.string.poctech -> Sources.PocTech
|
R.string.dexcom_app_patched -> Sources.Dexcom
|
||||||
R.string.tomato -> Sources.Tomato
|
R.string.eversense -> Sources.Eversense
|
||||||
R.string.glunovo -> Sources.Glunovo
|
R.string.Glimp -> Sources.Glimp
|
||||||
R.string.aidex -> Sources.Aidex
|
R.string.MM640g -> Sources.MM640g
|
||||||
R.string.xdrip -> Sources.Xdrip
|
R.string.nsclientbg -> Sources.NSClientSource
|
||||||
else -> Sources.Unknown
|
R.string.poctech -> Sources.PocTech
|
||||||
}
|
R.string.tomato -> Sources.Tomato
|
||||||
uel.log(
|
R.string.glunovo -> Sources.Glunovo
|
||||||
Action.BG_REMOVED, source,
|
R.string.xdrip -> Sources.Xdrip
|
||||||
ValueWithUnit.Timestamp(glucoseValue.timestamp)
|
R.string.aidex -> Sources.Aidex
|
||||||
)
|
else -> Sources.Unknown
|
||||||
repository.runTransactionForResult(InvalidateGlucoseValueTransaction(glucoseValue.id))
|
|
||||||
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating BG value", it) }
|
|
||||||
.blockingGet()
|
|
||||||
.also { result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated bg $it") } }
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
uel.log(
|
||||||
|
Action.BG_REMOVED, source,
|
||||||
|
ValueWithUnit.Timestamp(glucoseValue.timestamp)
|
||||||
|
)
|
||||||
|
repository.runTransactionForResult(InvalidateGlucoseValueTransaction(glucoseValue.id))
|
||||||
|
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating BG value", it) }
|
||||||
|
.blockingGet()
|
||||||
|
.also { result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated bg $it") } }
|
||||||
}
|
}
|
||||||
}
|
actionHelper.finish()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue