ActionsFragment binding

This commit is contained in:
Milos Kozak 2021-02-04 00:19:34 +01:00
parent 32637b97e0
commit ff28f26bda

View file

@ -40,7 +40,6 @@ import info.nightscout.androidaps.utils.ui.SingleClickButton
import info.nightscout.androidaps.utils.ui.UIRunnable import info.nightscout.androidaps.utils.ui.UIRunnable
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.actions_fragment.*
import kotlinx.android.synthetic.main.careportal_stats_fragment.* import kotlinx.android.synthetic.main.careportal_stats_fragment.*
import java.util.* import java.util.*
import javax.inject.Inject import javax.inject.Inject
@ -70,6 +69,18 @@ class ActionsFragment : DaggerFragment() {
private var smallHeight = false private var smallHeight = false
private lateinit var dm: DisplayMetrics private lateinit var dm: DisplayMetrics
private var buttonsLayout: LinearLayout? = null
private var profileSwitch: SingleClickButton? = null
private var tempTarget: SingleClickButton? = null
private var extendedBolus: SingleClickButton? = null
private var extendedBolusCancel: SingleClickButton? = null
private var setTempBasal: SingleClickButton? = null
private var cancelTempBasal: SingleClickButton? = null
private var fill: SingleClickButton? = null
private var historyBrowser: SingleClickButton? = null
private var tddStats: SingleClickButton? = null
private var pumpBatteryChange: SingleClickButton? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? { savedInstanceState: Bundle?): View? {
//check screen width //check screen width
@ -88,13 +99,25 @@ class ActionsFragment : DaggerFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
actions_profileswitch.setOnClickListener { buttonsLayout = view.findViewById(R.id.action_buttons_layout)
profileSwitch = view.findViewById(R.id.actions_profileswitch)
tempTarget = view.findViewById(R.id.actions_temptarget)
extendedBolus = view.findViewById(R.id.actions_extendedbolus)
extendedBolusCancel = view.findViewById(R.id.actions_extendedbolus_cancel)
setTempBasal = view.findViewById(R.id.actions_settempbasal)
cancelTempBasal = view.findViewById(R.id.actions_canceltempbasal)
fill = view.findViewById(R.id.actions_fill)
historyBrowser = view.findViewById(R.id.actions_historybrowser)
tddStats = view.findViewById(R.id.actions_tddstats)
pumpBatteryChange = view.findViewById(R.id.actions_pumpbatterychange)
profileSwitch?.setOnClickListener {
ProfileSwitchDialog().show(childFragmentManager, "Actions") ProfileSwitchDialog().show(childFragmentManager, "Actions")
} }
actions_temptarget.setOnClickListener { tempTarget?.setOnClickListener {
TempTargetDialog().show(childFragmentManager, "Actions") TempTargetDialog().show(childFragmentManager, "Actions")
} }
actions_extendedbolus.setOnClickListener { extendedBolus?.setOnClickListener {
activity?.let { activity -> activity?.let { activity ->
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable {
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.extended_bolus), resourceHelper.gs(R.string.ebstopsloop), OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.extended_bolus), resourceHelper.gs(R.string.ebstopsloop),
@ -104,7 +127,7 @@ class ActionsFragment : DaggerFragment() {
}) })
} }
} }
actions_extendedbolus_cancel.setOnClickListener { extendedBolusCancel?.setOnClickListener {
if (activePlugin.activeTreatments.isInHistoryExtendedBoluslInProgress) { if (activePlugin.activeTreatments.isInHistoryExtendedBoluslInProgress) {
aapsLogger.debug("USER ENTRY: CANCEL EXTENDED BOLUS") aapsLogger.debug("USER ENTRY: CANCEL EXTENDED BOLUS")
commandQueue.cancelExtended(object : Callback() { commandQueue.cancelExtended(object : Callback() {
@ -121,10 +144,10 @@ class ActionsFragment : DaggerFragment() {
}) })
} }
} }
actions_settempbasal.setOnClickListener { setTempBasal?.setOnClickListener {
TempBasalDialog().show(childFragmentManager, "Actions") TempBasalDialog().show(childFragmentManager, "Actions")
} }
actions_canceltempbasal.setOnClickListener { cancelTempBasal?.setOnClickListener {
if (activePlugin.activeTreatments.isTempBasalInProgress) { if (activePlugin.activeTreatments.isTempBasalInProgress) {
aapsLogger.debug("USER ENTRY: CANCEL TEMP BASAL") aapsLogger.debug("USER ENTRY: CANCEL TEMP BASAL")
commandQueue.cancelTempBasal(true, object : Callback() { commandQueue.cancelTempBasal(true, object : Callback() {
@ -141,32 +164,32 @@ class ActionsFragment : DaggerFragment() {
}) })
} }
} }
actions_fill.setOnClickListener { fill?.setOnClickListener {
activity?.let { activity -> activity?.let { activity ->
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { FillDialog().show(childFragmentManager, "FillDialog") }) protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { FillDialog().show(childFragmentManager, "FillDialog") })
} }
} }
actions_historybrowser.setOnClickListener { startActivity(Intent(context, HistoryBrowseActivity::class.java)) } historyBrowser?.setOnClickListener { startActivity(Intent(context, HistoryBrowseActivity::class.java)) }
actions_tddstats.setOnClickListener { startActivity(Intent(context, TDDStatsActivity::class.java)) } tddStats?.setOnClickListener { startActivity(Intent(context, TDDStatsActivity::class.java)) }
actions_bgcheck.setOnClickListener { view.findViewById<SingleClickButton>(R.id.actions_bgcheck).setOnClickListener {
CareDialog().setOptions(CareDialog.EventType.BGCHECK, R.string.careportal_bgcheck).show(childFragmentManager, "Actions") CareDialog().setOptions(CareDialog.EventType.BGCHECK, R.string.careportal_bgcheck).show(childFragmentManager, "Actions")
} }
actions_cgmsensorinsert.setOnClickListener { view.findViewById<SingleClickButton>(R.id.actions_cgmsensorinsert).setOnClickListener {
CareDialog().setOptions(CareDialog.EventType.SENSOR_INSERT, R.string.careportal_cgmsensorinsert).show(childFragmentManager, "Actions") CareDialog().setOptions(CareDialog.EventType.SENSOR_INSERT, R.string.careportal_cgmsensorinsert).show(childFragmentManager, "Actions")
} }
actions_pumpbatterychange.setOnClickListener { pumpBatteryChange?.setOnClickListener {
CareDialog().setOptions(CareDialog.EventType.BATTERY_CHANGE, R.string.careportal_pumpbatterychange).show(childFragmentManager, "Actions") CareDialog().setOptions(CareDialog.EventType.BATTERY_CHANGE, R.string.careportal_pumpbatterychange).show(childFragmentManager, "Actions")
} }
actions_note.setOnClickListener { view.findViewById<SingleClickButton>(R.id.actions_note).setOnClickListener {
CareDialog().setOptions(CareDialog.EventType.NOTE, R.string.careportal_note).show(childFragmentManager, "Actions") CareDialog().setOptions(CareDialog.EventType.NOTE, R.string.careportal_note).show(childFragmentManager, "Actions")
} }
actions_exercise.setOnClickListener { view.findViewById<SingleClickButton>(R.id.actions_exercise).setOnClickListener {
CareDialog().setOptions(CareDialog.EventType.EXERCISE, R.string.careportal_exercise).show(childFragmentManager, "Actions") CareDialog().setOptions(CareDialog.EventType.EXERCISE, R.string.careportal_exercise).show(childFragmentManager, "Actions")
} }
actions_question.setOnClickListener { view.findViewById<SingleClickButton>(R.id.actions_question).setOnClickListener {
CareDialog().setOptions(CareDialog.EventType.QUESTION, R.string.careportal_question).show(childFragmentManager, "Actions") CareDialog().setOptions(CareDialog.EventType.QUESTION, R.string.careportal_question).show(childFragmentManager, "Actions")
} }
actions_announcement.setOnClickListener { view.findViewById<SingleClickButton>(R.id.actions_announcement).setOnClickListener {
CareDialog().setOptions(CareDialog.EventType.ANNOUNCEMENT, R.string.careportal_announcement).show(childFragmentManager, "Actions") CareDialog().setOptions(CareDialog.EventType.ANNOUNCEMENT, R.string.careportal_announcement).show(childFragmentManager, "Actions")
} }
@ -179,27 +202,27 @@ class ActionsFragment : DaggerFragment() {
disposable += rxBus disposable += rxBus
.toObservable(EventInitializationChanged::class.java) .toObservable(EventInitializationChanged::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGui() }, { fabricPrivacy.logException(it) }) .subscribe({ updateGui() }, fabricPrivacy::logException)
disposable += rxBus disposable += rxBus
.toObservable(EventRefreshOverview::class.java) .toObservable(EventRefreshOverview::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGui() }, { fabricPrivacy.logException(it) }) .subscribe({ updateGui() }, fabricPrivacy::logException)
disposable += rxBus disposable += rxBus
.toObservable(EventExtendedBolusChange::class.java) .toObservable(EventExtendedBolusChange::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGui() }, { fabricPrivacy.logException(it) }) .subscribe({ updateGui() }, fabricPrivacy::logException)
disposable += rxBus disposable += rxBus
.toObservable(EventTempBasalChange::class.java) .toObservable(EventTempBasalChange::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGui() }, { fabricPrivacy.logException(it) }) .subscribe({ updateGui() }, fabricPrivacy::logException)
disposable += rxBus disposable += rxBus
.toObservable(EventCustomActionsChanged::class.java) .toObservable(EventCustomActionsChanged::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGui() }, { fabricPrivacy.logException(it) }) .subscribe({ updateGui() }, fabricPrivacy::logException)
disposable += rxBus disposable += rxBus
.toObservable(EventCareportalEventChange::class.java) .toObservable(EventCareportalEventChange::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGui() }, { fabricPrivacy.logException(it) }) .subscribe({ updateGui() }, fabricPrivacy::logException)
updateGui() updateGui()
} }
@ -215,49 +238,49 @@ class ActionsFragment : DaggerFragment() {
val profile = profileFunction.getProfile() val profile = profileFunction.getProfile()
val pump = activePlugin.activePump val pump = activePlugin.activePump
actions_profileswitch?.visibility = ( profileSwitch?.visibility = (
activePlugin.activeProfileInterface.profile != null && activePlugin.activeProfileInterface.profile != null &&
pump.pumpDescription.isSetBasalProfileCapable && pump.pumpDescription.isSetBasalProfileCapable &&
pump.isInitialized && pump.isInitialized &&
!pump.isSuspended).toVisibility() !pump.isSuspended).toVisibility()
if (!pump.pumpDescription.isExtendedBolusCapable || !pump.isInitialized || pump.isSuspended || pump.isFakingTempsByExtendedBoluses) { if (!pump.pumpDescription.isExtendedBolusCapable || !pump.isInitialized || pump.isSuspended || pump.isFakingTempsByExtendedBoluses) {
actions_extendedbolus?.visibility = View.GONE extendedBolus?.visibility = View.GONE
actions_extendedbolus_cancel?.visibility = View.GONE extendedBolusCancel?.visibility = View.GONE
} else { } else {
val activeExtendedBolus = activePlugin.activeTreatments.getExtendedBolusFromHistory(System.currentTimeMillis()) val activeExtendedBolus = activePlugin.activeTreatments.getExtendedBolusFromHistory(System.currentTimeMillis())
if (activeExtendedBolus != null) { if (activeExtendedBolus != null) {
actions_extendedbolus?.visibility = View.GONE extendedBolus?.visibility = View.GONE
actions_extendedbolus_cancel?.visibility = View.VISIBLE extendedBolusCancel?.visibility = View.VISIBLE
@Suppress("SetTextI18n") @Suppress("SetTextI18n")
actions_extendedbolus_cancel?.text = resourceHelper.gs(R.string.cancel) + " " + activeExtendedBolus.toStringMedium() extendedBolusCancel?.text = resourceHelper.gs(R.string.cancel) + " " + activeExtendedBolus.toStringMedium()
} else { } else {
actions_extendedbolus?.visibility = View.VISIBLE extendedBolus?.visibility = View.VISIBLE
actions_extendedbolus_cancel?.visibility = View.GONE extendedBolusCancel?.visibility = View.GONE
} }
} }
if (!pump.pumpDescription.isTempBasalCapable || !pump.isInitialized || pump.isSuspended) { if (!pump.pumpDescription.isTempBasalCapable || !pump.isInitialized || pump.isSuspended) {
actions_settempbasal?.visibility = View.GONE setTempBasal?.visibility = View.GONE
actions_canceltempbasal?.visibility = View.GONE cancelTempBasal?.visibility = View.GONE
} else { } else {
val activeTemp = activePlugin.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis()) val activeTemp = activePlugin.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis())
if (activeTemp != null) { if (activeTemp != null) {
actions_settempbasal?.visibility = View.GONE setTempBasal?.visibility = View.GONE
actions_canceltempbasal?.visibility = View.VISIBLE cancelTempBasal?.visibility = View.VISIBLE
@Suppress("SetTextI18n") @Suppress("SetTextI18n")
actions_canceltempbasal?.text = resourceHelper.gs(R.string.cancel) + " " + activeTemp.toStringShort() cancelTempBasal?.text = resourceHelper.gs(R.string.cancel) + " " + activeTemp.toStringShort()
} else { } else {
actions_settempbasal?.visibility = View.VISIBLE setTempBasal?.visibility = View.VISIBLE
actions_canceltempbasal?.visibility = View.GONE cancelTempBasal?.visibility = View.GONE
} }
} }
val activeBgSource = activePlugin.activeBgSource val activeBgSource = activePlugin.activeBgSource
actions_historybrowser.visibility = (profile != null).toVisibility() historyBrowser?.visibility = (profile != null).toVisibility()
actions_fill?.visibility = (pump.pumpDescription.isRefillingCapable && pump.isInitialized && !pump.isSuspended).toVisibility() fill?.visibility = (pump.pumpDescription.isRefillingCapable && pump.isInitialized && !pump.isSuspended).toVisibility()
actions_pumpbatterychange?.visibility = (pump.pumpDescription.isBatteryReplaceable || (pump is OmnipodPumpPlugin && pump.isUseRileyLinkBatteryLevel && pump.isBatteryChangeLoggingEnabled)).toVisibility() pumpBatteryChange?.visibility = (pump.pumpDescription.isBatteryReplaceable || (pump is OmnipodPumpPlugin && pump.isUseRileyLinkBatteryLevel && pump.isBatteryChangeLoggingEnabled)).toVisibility()
actions_temptarget?.visibility = (profile != null && config.APS).toVisibility() tempTarget?.visibility = (profile != null && config.APS).toVisibility()
actions_tddstats?.visibility = pump.pumpDescription.supportsTDDs.toVisibility() tddStats?.visibility = pump.pumpDescription.supportsTDDs.toVisibility()
if (!config.NSCLIENT) { if (!config.NSCLIENT) {
statusLightHandler.updateStatusLights(careportal_canulaage, careportal_insulinage, careportal_reservoirlevel, careportal_sensorage, careportal_sensorlevel, careportal_pbage, careportal_batterylevel) statusLightHandler.updateStatusLights(careportal_canulaage, careportal_insulinage, careportal_reservoirlevel, careportal_sensorage, careportal_sensorlevel, careportal_pbage, careportal_batterylevel)
@ -298,7 +321,7 @@ class ActionsFragment : DaggerFragment() {
val top = activity?.let { ContextCompat.getDrawable(it, customAction.iconResourceId) } val top = activity?.let { ContextCompat.getDrawable(it, customAction.iconResourceId) }
btn.setCompoundDrawablesWithIntrinsicBounds(null, top, null, null) btn.setCompoundDrawablesWithIntrinsicBounds(null, top, null, null)
action_buttons_layout?.addView(btn) buttonsLayout?.addView(btn)
this.pumpCustomActions[resourceHelper.gs(customAction.name)] = customAction this.pumpCustomActions[resourceHelper.gs(customAction.name)] = customAction
this.pumpCustomButtons.add(btn) this.pumpCustomButtons.add(btn)
@ -306,7 +329,7 @@ class ActionsFragment : DaggerFragment() {
} }
private fun removePumpCustomActions() { private fun removePumpCustomActions() {
for (customButton in pumpCustomButtons) action_buttons_layout?.removeView(customButton) for (customButton in pumpCustomButtons) buttonsLayout?.removeView(customButton)
pumpCustomButtons.clear() pumpCustomButtons.clear()
} }
} }