EOpatch: cleanup

This commit is contained in:
Milos Kozak 2022-11-03 17:06:59 +01:00
parent 37da844b5e
commit 84d49fc453
19 changed files with 70 additions and 38 deletions

View file

@ -189,8 +189,8 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang
addPreferencesFromResourceIfEnabled(comboPlugin, rootKey, config.PUMPDRIVERS)
addPreferencesFromResourceIfEnabled(medtronicPumpPlugin, rootKey, config.PUMPDRIVERS)
addPreferencesFromResourceIfEnabled(diaconnG8Plugin, rootKey, config.PUMPDRIVERS)
addPreferencesFromResource(R.xml.pref_pump, rootKey, config.PUMPDRIVERS)
addPreferencesFromResourceIfEnabled(eopatchPumpPlugin, rootKey, config.PUMPDRIVERS)
addPreferencesFromResource(R.xml.pref_pump, rootKey, config.PUMPDRIVERS)
addPreferencesFromResourceIfEnabled(virtualPumpPlugin, rootKey)
addPreferencesFromResourceIfEnabled(insulinOrefFreePeakPlugin, rootKey)
addPreferencesFromResourceIfEnabled(nsClientPlugin, rootKey)

View file

@ -70,7 +70,6 @@ import javax.inject.Singleton
WorkersModule::class,
DiaconnG8Module::class,
OpenHumansModule::class,
SharedModule::class,
EopatchModule::class,
SharedModule::class,
UiModule::class,

View file

@ -16,6 +16,7 @@ import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.DecimalFormatter
import info.nightscout.androidaps.utils.WarnColors
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.pump.eopatch.AppConstant
import info.nightscout.shared.sharedPreferences.SP
import javax.inject.Inject
import javax.inject.Singleton
@ -34,7 +35,15 @@ class StatusLightHandler @Inject constructor(
/**
* applies the extended statusLight subview on the overview fragment
*/
fun updateStatusLights(careportal_cannula_age: TextView?, careportal_insulin_age: TextView?, careportal_reservoir_level: TextView?, careportal_sensor_age: TextView?, careportal_sensor_battery_level: TextView?, careportal_pb_age: TextView?, careportal_battery_level: TextView?) {
fun updateStatusLights(
careportal_cannula_age: TextView?,
careportal_insulin_age: TextView?,
careportal_reservoir_level: TextView?,
careportal_sensor_age: TextView?,
careportal_sensor_battery_level: TextView?,
careportal_pb_age: TextView?,
careportal_battery_level: TextView?
) {
val pump = activePlugin.activePump
val bgSource = activePlugin.activeBgSource
handleAge(careportal_cannula_age, TherapyEvent.Type.CANNULA_CHANGE, R.string.key_statuslights_cage_warning, 48.0, R.string.key_statuslights_cage_critical, 72.0)
@ -46,9 +55,11 @@ class StatusLightHandler @Inject constructor(
val insulinUnit = rh.gs(R.string.insulin_unit_shortname)
if (pump.model() == PumpType.OMNIPOD_EROS || pump.model() == PumpType.OMNIPOD_DASH) {
handleOmnipodReservoirLevel(careportal_reservoir_level, R.string.key_statuslights_res_critical, 10.0, R.string.key_statuslights_res_warning, 80.0, pump.reservoirLevel, insulinUnit)
handlePatchReservoirLevel(careportal_reservoir_level, R.string.key_statuslights_res_critical, 10.0, R.string.key_statuslights_res_warning, 80.0, pump.reservoirLevel, insulinUnit,
OmnipodConstants.MAX_RESERVOIR_READING)
} else if (pump.model() == PumpType.EOFLOW_EOPATCH2) {
handleEopatchReservoirLevel(careportal_reservoir_level, R.string.key_statuslights_res_critical, 10.0, R.string.key_statuslights_res_warning, 80.0, pump.reservoirLevel, insulinUnit)
handlePatchReservoirLevel(careportal_reservoir_level, R.string.key_statuslights_res_critical, 10.0, R.string.key_statuslights_res_warning, 80.0, pump.reservoirLevel, insulinUnit,
AppConstant.MAX_RESERVOIR_READING)
} else {
handleLevel(careportal_reservoir_level, R.string.key_statuslights_res_critical, 10.0, R.string.key_statuslights_res_warning, 80.0, pump.reservoirLevel, insulinUnit)
}
@ -97,21 +108,13 @@ class StatusLightHandler @Inject constructor(
// Omnipod only reports reservoir level when it's 50 units or less, so we display "50+U" for any value > 50
@Suppress("SameParameterValue")
private fun handleOmnipodReservoirLevel(view: TextView?, criticalSetting: Int, criticalDefaultValue: Double, warnSetting: Int, warnDefaultValue: Double, level: Double, units: String) {
if (level >= OmnipodConstants.MAX_RESERVOIR_READING) {
private fun handlePatchReservoirLevel(
view: TextView?, criticalSetting: Int, criticalDefaultValue: Double, warnSetting: Int,
warnDefaultValue: Double, level: Double, units: String, maxReading: Double
) {
if (level >= maxReading) {
@Suppress("SetTextI18n")
view?.text = " 50+$units"
view?.setTextColor(rh.gac(view.context, R.attr.defaultTextColor))
} else {
handleLevel(view, criticalSetting, criticalDefaultValue, warnSetting, warnDefaultValue, level, units)
}
}
@Suppress("SameParameterValue")
private fun handleEopatchReservoirLevel(view: TextView?, criticalSetting: Int, criticalDefaultValue: Double, warnSetting: Int, warnDefaultValue: Double, level: Double, units: String) {
if (level > 50.0) {
@Suppress("SetTextI18n")
view?.text = " 50+$units"
view?.text = " ${maxReading.toInt()}+$units"
view?.setTextColor(rh.gac(view.context, R.attr.defaultTextColor))
} else {
handleLevel(view, criticalSetting, criticalDefaultValue, warnSetting, warnDefaultValue, level, units)

View file

@ -150,7 +150,6 @@
<string name="nochangerequested">변경사항 없음</string>
<!-- ProfileSwitch-->
<string name="zerovalueinprofile">유효하지 않은 프로파일: %1$s</string>
<!-- Temptarget-->
<string name="mins">%1$d 분</string>
<!-- Translator-->

1
pump/eopatch-core/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build

View file

@ -0,0 +1,2 @@
configurations.create("default")
artifacts.add("default", file('libs/eopatch_core.aar'))

View file

21
pump/eopatch-core/proguard-rules.pro vendored Normal file
View file

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>

View file

@ -18,7 +18,7 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation (files("libs/eopatch_core.aar"))
implementation project(':pump:eopatch-core')
implementation project(':libraries')
implementation project(':shared')
implementation project(':database')

Binary file not shown.

View file

@ -25,5 +25,6 @@ interface AppConstant {
const val DAY_START_MINUTE = 0 * 60
const val DAY_END_MINUTE = 24 * 60
const val INSULIN_DURATION_MIN = 2.0f
const val MAX_RESERVOIR_READING = 50.0
}
}

View file

@ -10,7 +10,7 @@ object EoPatchRxBus {
publishSubject.onNext(event)
}
fun <T> listen(eventType: Class<T>): Observable<T> {
fun <T: Any> listen(eventType: Class<T>): Observable<T> {
return publishSubject.ofType(eventType)
}

View file

@ -7,26 +7,26 @@ import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers
fun <T> Observable<T>.observeOnMainThread(): Observable<T> = observeOn(AndroidSchedulers.mainThread())
fun <T: Any> Observable<T>.observeOnMainThread(): Observable<T> = observeOn(AndroidSchedulers.mainThread())
fun <T> Observable<T>.observeOnComputation(): Observable<T> = observeOn(Schedulers.computation())
fun <T: Any> Observable<T>.observeOnComputation(): Observable<T> = observeOn(Schedulers.computation())
fun <T> Observable<T>.observeOnIo(): Observable<T> = observeOn(Schedulers.io())
fun <T: Any> Observable<T>.observeOnIo(): Observable<T> = observeOn(Schedulers.io())
fun <T> Observable<T>.subscribeEmpty(): Disposable = subscribe({}, {}, {})
fun <T: Any> Observable<T>.subscribeEmpty(): Disposable = subscribe({}, {}, {})
fun <T> Observable<T>.subscribeEmpty(onSuccess: (T) -> Unit): Disposable = subscribe(onSuccess, {}, {})
fun <T: Any> Observable<T>.subscribeEmpty(onSuccess: (T) -> Unit): Disposable = subscribe(onSuccess, {}, {})
fun <T> Observable<T>.subscribeEmpty(onSuccess: (T) -> Unit, onError: (Throwable) -> Unit): Disposable = subscribe(onSuccess, onError, {})
fun <T: Any> Observable<T>.subscribeEmpty(onSuccess: (T) -> Unit, onError: (Throwable) -> Unit): Disposable = subscribe(onSuccess, onError, {})
fun <T> Observable<T>.subscribeDefault(aapsLogger: AAPSLogger): Disposable = subscribe({ aapsLogger.debug(LTag.PUMP, "onSuccess") }, { aapsLogger.error(LTag.PUMP, "onError", it) }, {
fun <T: Any> Observable<T>.subscribeDefault(aapsLogger: AAPSLogger): Disposable = subscribe({ aapsLogger.debug(LTag.PUMP, "onSuccess") }, { aapsLogger.error(LTag.PUMP, "onError", it) }, {
aapsLogger.debug(LTag.PUMP, "onComplete")
})
fun <T> Observable<T>.subscribeDefault(aapsLogger: AAPSLogger, onSuccess: (T) -> Unit): Disposable =
fun <T: Any> Observable<T>.subscribeDefault(aapsLogger: AAPSLogger, onSuccess: (T) -> Unit): Disposable =
subscribe(onSuccess, { aapsLogger.error(LTag.PUMP, "onError", it) }, { aapsLogger.debug(LTag.PUMP, "onComplete") })
fun <T> Observable<T>.subscribeDefault(aapsLogger: AAPSLogger, onSuccess: (T) -> Unit, onError: (Throwable) -> Unit): Disposable =
fun <T: Any> Observable<T>.subscribeDefault(aapsLogger: AAPSLogger, onSuccess: (T) -> Unit, onError: (Throwable) -> Unit): Disposable =
subscribe(onSuccess, onError, { aapsLogger.debug(LTag.PUMP, "onComplete") })
fun <T> Observable<T>.with(): Observable<T> = subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
fun <T: Any> Observable<T>.with(): Observable<T> = subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())

View file

@ -7,8 +7,8 @@ import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers
fun <T> Single<T>.subscribeDefault(aapsLogger: AAPSLogger, onSuccess: (T) -> Unit): Disposable = subscribe(onSuccess, {
fun <T: Any> Single<T>.subscribeDefault(aapsLogger: AAPSLogger, onSuccess: (T) -> Unit): Disposable = subscribe(onSuccess) {
aapsLogger.error(LTag.PUMP, "onError", it)
})
}
fun <T> Single<T>.with(): Single<T> = subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
fun <T: Any> Single<T>.with(): Single<T> = subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())

View file

@ -9,10 +9,11 @@ import android.os.Bundle
import android.view.MotionEvent
import androidx.appcompat.app.AlertDialog
import androidx.lifecycle.ViewModelProvider
import info.nightscout.androidaps.extensions.safeGetSerializableExtra
import info.nightscout.androidaps.plugins.pump.eopatch.R
import info.nightscout.androidaps.plugins.pump.eopatch.code.EventType
import info.nightscout.androidaps.plugins.pump.eopatch.code.PatchLifecycle
import info.nightscout.androidaps.plugins.pump.eopatch.code.PatchStep
import info.nightscout.androidaps.plugins.pump.eopatch.code.EventType
import info.nightscout.androidaps.plugins.pump.eopatch.databinding.ActivityEopatchBinding
import info.nightscout.androidaps.plugins.pump.eopatch.extension.replaceFragmentInActivity
import info.nightscout.androidaps.plugins.pump.eopatch.extension.takeOne
@ -117,7 +118,7 @@ class EopatchActivity : EoBaseActivity<ActivityEopatchBinding>() {
binding.viewModel?.apply {
intent?.run {
val step = intent.getSerializableExtra(EXTRA_START_PATCH_STEP) as PatchStep?
val step = intent.safeGetSerializableExtra(EXTRA_START_PATCH_STEP, PatchStep::class.java)
forceDiscard = intent.getBooleanExtra(EXTRA_FORCE_DISCARD, false)
if (intent.getBooleanExtra(EXTRA_START_WITH_COMM_CHECK, false)) {

View file

@ -3,7 +3,7 @@ package info.nightscout.androidaps.plugins.pump.eopatch.vo
import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.rxjava3.core.Observable
interface IPreference<T>{
interface IPreference<T: Any>{
fun flush(sp: SP)
fun observe(): Observable<T>
}

View file

@ -14,6 +14,7 @@ include ':pump:danar'
include ':pump:danars'
include ':pump:diaconn'
include ':pump:eopatch'
include ':pump:eopatch-core'
include ':insight'
include ':pump:medtronic'
include ':pump:omnipod-common'