:shared module cleanup
This commit is contained in:
parent
c86b6adad8
commit
1f8796fd34
76 changed files with 86 additions and 1796 deletions
|
@ -1,32 +0,0 @@
|
||||||
package info.nightscout.shared.extensions
|
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import android.content.pm.PackageInfo
|
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import android.content.pm.ResolveInfo
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Safe version of getInstalledPackages depending on Android version running
|
|
||||||
*/
|
|
||||||
fun PackageManager.safeGetInstalledPackages(flags: Int): List<PackageInfo> =
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) getInstalledPackages(PackageManager.PackageInfoFlags.of(flags.toLong()))
|
|
||||||
else @Suppress("DEPRECATION") getInstalledPackages(flags)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Safe version of queryBroadcastReceivers depending on Android version running
|
|
||||||
*/
|
|
||||||
fun PackageManager.safeQueryBroadcastReceivers(intent: Intent, flags: Int): List<ResolveInfo> =
|
|
||||||
try {
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) queryBroadcastReceivers(intent, PackageManager.ResolveInfoFlags.of(flags.toLong()))
|
|
||||||
else @Suppress("DEPRECATION") queryBroadcastReceivers(intent, flags)
|
|
||||||
} catch (ignored: Exception) {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Safe version of getPackageInfo depending on Android version running
|
|
||||||
*/
|
|
||||||
@Throws(PackageManager.NameNotFoundException::class)
|
|
||||||
fun PackageManager.safeGetPackageInfo(packageName: String, flags: Int): PackageInfo =
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(flags.toLong()))
|
|
||||||
else @Suppress("DEPRECATION") getPackageInfo(packageName, flags)
|
|
|
@ -1,50 +0,0 @@
|
||||||
package info.nightscout.shared.impl.di
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import dagger.Module
|
|
||||||
import dagger.Provides
|
|
||||||
import info.nightscout.rx.AapsSchedulers
|
|
||||||
import info.nightscout.rx.bus.RxBus
|
|
||||||
import info.nightscout.rx.interfaces.L
|
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
|
||||||
import info.nightscout.shared.impl.logging.AAPSLoggerProduction
|
|
||||||
import info.nightscout.shared.impl.logging.LImpl
|
|
||||||
import info.nightscout.shared.impl.rx.AapsSchedulersImpl
|
|
||||||
import info.nightscout.shared.impl.rx.bus.RxBusImpl
|
|
||||||
import info.nightscout.shared.impl.sharedPreferences.SPImplementation
|
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
|
||||||
import info.nightscout.shared.utils.DateUtil
|
|
||||||
import info.nightscout.shared.utils.DateUtilImpl
|
|
||||||
import javax.inject.Singleton
|
|
||||||
|
|
||||||
@Module(
|
|
||||||
includes = [
|
|
||||||
]
|
|
||||||
)
|
|
||||||
open class SharedImplModule {
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideSharedPreferences(context: Context): SP = SPImplementation(PreferenceManager.getDefaultSharedPreferences(context), context)
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideL(sp: SP): L = LImpl(sp)
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideDateUtil(context: Context): DateUtil = DateUtilImpl(context)
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideAAPSLogger(l: L): AAPSLogger = AAPSLoggerProduction(l)
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideRxBus(aapsSchedulers: AapsSchedulers, aapsLogger: AAPSLogger): RxBus = RxBusImpl(aapsSchedulers, aapsLogger)
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
internal fun provideSchedulers(): AapsSchedulers = AapsSchedulersImpl()
|
|
||||||
}
|
|
|
@ -1,106 +0,0 @@
|
||||||
package info.nightscout.shared.impl.logging
|
|
||||||
|
|
||||||
import info.nightscout.rx.interfaces.L
|
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
|
||||||
import info.nightscout.rx.logging.LTag
|
|
||||||
import org.slf4j.LoggerFactory
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by adrian on 2019-12-27.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class AAPSLoggerProduction constructor(val l: L) : AAPSLogger {
|
|
||||||
|
|
||||||
override fun debug(message: String) {
|
|
||||||
LoggerFactory.getLogger(LTag.CORE.tag).debug(stackLogMarker() + message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun debug(enable: Boolean, tag: LTag, message: String) {
|
|
||||||
if (enable && l.findByName(tag.tag).enabled)
|
|
||||||
LoggerFactory.getLogger(tag.tag).debug(stackLogMarker() + message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun debug(tag: LTag, message: String) {
|
|
||||||
if (l.findByName(tag.tag).enabled)
|
|
||||||
LoggerFactory.getLogger(tag.tag).debug(stackLogMarker() + message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun debug(tag: LTag, accessor: () -> String) {
|
|
||||||
if (l.findByName(tag.tag).enabled)
|
|
||||||
LoggerFactory.getLogger(tag.tag).debug(stackLogMarker() + accessor.invoke())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun debug(tag: LTag, format: String, vararg arguments: Any?) {
|
|
||||||
if (l.findByName(tag.tag).enabled)
|
|
||||||
LoggerFactory.getLogger(tag.tag).debug(stackLogMarker() + format, arguments)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun warn(tag: LTag, message: String) {
|
|
||||||
if (l.findByName(tag.tag).enabled)
|
|
||||||
LoggerFactory.getLogger(tag.tag).warn(stackLogMarker() + message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun warn(tag: LTag, format: String, vararg arguments: Any?) {
|
|
||||||
LoggerFactory.getLogger(tag.tag).warn(stackLogMarker() + format, arguments)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun info(tag: LTag, message: String) {
|
|
||||||
if (l.findByName(tag.tag).enabled)
|
|
||||||
LoggerFactory.getLogger(tag.tag).info(stackLogMarker() + message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun info(tag: LTag, format: String, vararg arguments: Any?) {
|
|
||||||
if (l.findByName(tag.tag).enabled)
|
|
||||||
LoggerFactory.getLogger(tag.tag).info(stackLogMarker() + format, arguments)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun error(tag: LTag, message: String) {
|
|
||||||
LoggerFactory.getLogger(tag.tag).error(stackLogMarker() + message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun error(message: String) {
|
|
||||||
LoggerFactory.getLogger(LTag.CORE.tag).error(stackLogMarker() + message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun error(message: String, throwable: Throwable) {
|
|
||||||
LoggerFactory.getLogger(LTag.CORE.tag).error(stackLogMarker() + message, throwable)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun error(format: String, vararg arguments: Any?) {
|
|
||||||
LoggerFactory.getLogger(LTag.CORE.tag).error(stackLogMarker() + format, arguments)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun error(tag: LTag, message: String, throwable: Throwable) {
|
|
||||||
LoggerFactory.getLogger(tag.tag).error(stackLogMarker() + message, throwable)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun error(tag: LTag, format: String, vararg arguments: Any?) {
|
|
||||||
LoggerFactory.getLogger(tag.tag).error(stackLogMarker() + format, arguments)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun debug(className: String, methodName: String, lineNumber: Int, tag: LTag, message: String) {
|
|
||||||
LoggerFactory.getLogger(tag.tag).debug(logLocationPrefix(className, methodName, lineNumber) + message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun info(className: String, methodName: String, lineNumber: Int, tag: LTag, message: String) {
|
|
||||||
LoggerFactory.getLogger(tag.tag).info(logLocationPrefix(className, methodName, lineNumber) + message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun warn(className: String, methodName: String, lineNumber: Int, tag: LTag, message: String) {
|
|
||||||
LoggerFactory.getLogger(tag.tag).warn(logLocationPrefix(className, methodName, lineNumber) + message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun error(className: String, methodName: String, lineNumber: Int, tag: LTag, message: String) {
|
|
||||||
LoggerFactory.getLogger(tag.tag).error(logLocationPrefix(className, methodName, lineNumber) + message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun logLocationPrefix(className: String, methodName: String, lineNumber: Int) =
|
|
||||||
"[$className.$methodName():$lineNumber]: "
|
|
||||||
|
|
||||||
fun StackTraceElement.toLogString(): String =
|
|
||||||
logLocationPrefix(this.className.substringAfterLast("."), this.methodName, this.lineNumber)
|
|
||||||
|
|
||||||
/* Needs to be inline. Don't remove even if IDE suggests it. */
|
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
|
||||||
inline fun stackLogMarker() = Throwable().stackTrace[1].toLogString()
|
|
|
@ -1,72 +0,0 @@
|
||||||
package info.nightscout.shared.impl.logging
|
|
||||||
|
|
||||||
import info.nightscout.rx.interfaces.L
|
|
||||||
import info.nightscout.rx.interfaces.LogElement
|
|
||||||
import info.nightscout.rx.logging.LTag
|
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Singleton
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
class LImpl @Inject constructor(
|
|
||||||
private val sp: SP
|
|
||||||
) : L {
|
|
||||||
|
|
||||||
private var logElements: MutableList<LogElement> = ArrayList()
|
|
||||||
|
|
||||||
init {
|
|
||||||
LTag.values().forEach { logElements.add(LogElementImpl(it, sp)) }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun findByName(name: String): LogElement {
|
|
||||||
for (element in logElements) {
|
|
||||||
if (element.name == name) return element
|
|
||||||
}
|
|
||||||
return LogElementImpl(false, sp)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getLogElements(): List<LogElement> {
|
|
||||||
return logElements
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun resetToDefaults() {
|
|
||||||
for (element in logElements) {
|
|
||||||
element.resetToDefault()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class LogElementImpl : LogElement {
|
|
||||||
|
|
||||||
var sp: SP
|
|
||||||
override var name: String
|
|
||||||
override var defaultValue: Boolean
|
|
||||||
override var enabled: Boolean
|
|
||||||
private var requiresRestart = false
|
|
||||||
|
|
||||||
internal constructor(tag: LTag, sp: SP) {
|
|
||||||
this.sp = sp
|
|
||||||
this.name = tag.tag
|
|
||||||
this.defaultValue = tag.defaultValue
|
|
||||||
this.requiresRestart = tag.requiresRestart
|
|
||||||
enabled = sp.getBoolean(getSPName(), defaultValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal constructor(defaultValue: Boolean, sp: SP) {
|
|
||||||
this.sp = sp
|
|
||||||
name = "NONEXISTENT"
|
|
||||||
this.defaultValue = defaultValue
|
|
||||||
enabled = defaultValue
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getSPName(): String = "log_$name"
|
|
||||||
|
|
||||||
override fun enable(enabled: Boolean) {
|
|
||||||
this.enabled = enabled
|
|
||||||
sp.putBoolean(getSPName(), enabled)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun resetToDefault() {
|
|
||||||
enable(defaultValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package info.nightscout.shared.impl.rx
|
|
||||||
|
|
||||||
import info.nightscout.rx.AapsSchedulers
|
|
||||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
|
||||||
import io.reactivex.rxjava3.core.Scheduler
|
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
|
||||||
import javax.inject.Singleton
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
class AapsSchedulersImpl : AapsSchedulers {
|
|
||||||
|
|
||||||
override val main: Scheduler = AndroidSchedulers.mainThread()
|
|
||||||
override val io: Scheduler = Schedulers.io()
|
|
||||||
override val cpu: Scheduler = Schedulers.computation()
|
|
||||||
override val newThread: Scheduler = Schedulers.newThread()
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
package info.nightscout.shared.impl.rx.bus
|
|
||||||
|
|
||||||
import info.nightscout.annotations.OpenForTesting
|
|
||||||
import info.nightscout.rx.AapsSchedulers
|
|
||||||
import info.nightscout.rx.bus.RxBus
|
|
||||||
import info.nightscout.rx.events.Event
|
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
|
||||||
import info.nightscout.rx.logging.LTag
|
|
||||||
import io.reactivex.rxjava3.core.Observable
|
|
||||||
import io.reactivex.rxjava3.subjects.PublishSubject
|
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Singleton
|
|
||||||
|
|
||||||
@OpenForTesting
|
|
||||||
@Singleton
|
|
||||||
class RxBusImpl @Inject constructor(
|
|
||||||
val aapsSchedulers: AapsSchedulers,
|
|
||||||
val aapsLogger: AAPSLogger
|
|
||||||
) : RxBus {
|
|
||||||
|
|
||||||
private val publisher = PublishSubject.create<Event>()
|
|
||||||
|
|
||||||
override fun send(event: Event) {
|
|
||||||
aapsLogger.debug(LTag.EVENTS, "Sending $event")
|
|
||||||
publisher.onNext(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Listen should return an Observable and not the publisher
|
|
||||||
// Using ofType we filter only events that match that class type
|
|
||||||
override fun <T : Any> toObservable(eventType: Class<T>): Observable<T> =
|
|
||||||
publisher
|
|
||||||
.subscribeOn(aapsSchedulers.io)
|
|
||||||
.ofType(eventType)
|
|
||||||
}
|
|
|
@ -1,204 +0,0 @@
|
||||||
package info.nightscout.shared.impl.sharedPreferences
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.SharedPreferences
|
|
||||||
import androidx.annotation.StringRes
|
|
||||||
import info.nightscout.shared.SafeParse
|
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Singleton
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
class SPImplementation @Inject constructor(
|
|
||||||
private val sharedPreferences: SharedPreferences,
|
|
||||||
private val context: Context
|
|
||||||
) : SP {
|
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
|
||||||
override fun edit(commit: Boolean, block: SP.Editor.() -> Unit) {
|
|
||||||
val spEdit = sharedPreferences.edit()
|
|
||||||
|
|
||||||
val edit = object : SP.Editor {
|
|
||||||
override fun clear() {
|
|
||||||
spEdit.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun remove(@StringRes resourceID: Int) {
|
|
||||||
spEdit.remove(context.getString(resourceID))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun remove(key: String) {
|
|
||||||
spEdit.remove(key)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun putBoolean(key: String, value: Boolean) {
|
|
||||||
spEdit.putBoolean(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun putBoolean(@StringRes resourceID: Int, value: Boolean) {
|
|
||||||
spEdit.putBoolean(context.getString(resourceID), value)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun putDouble(key: String, value: Double) {
|
|
||||||
spEdit.putString(key, value.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun putDouble(@StringRes resourceID: Int, value: Double) {
|
|
||||||
spEdit.putString(context.getString(resourceID), value.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun putLong(key: String, value: Long) {
|
|
||||||
spEdit.putLong(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun putLong(@StringRes resourceID: Int, value: Long) {
|
|
||||||
spEdit.putLong(context.getString(resourceID), value)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun putInt(key: String, value: Int) {
|
|
||||||
spEdit.putInt(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun putInt(@StringRes resourceID: Int, value: Int) {
|
|
||||||
spEdit.putInt(context.getString(resourceID), value)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun putString(key: String, value: String) {
|
|
||||||
spEdit.putString(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun putString(@StringRes resourceID: Int, value: String) {
|
|
||||||
spEdit.putString(context.getString(resourceID), value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
block(edit)
|
|
||||||
|
|
||||||
if (commit)
|
|
||||||
spEdit.commit()
|
|
||||||
else
|
|
||||||
spEdit.apply()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getAll(): Map<String, *> = sharedPreferences.all
|
|
||||||
|
|
||||||
override fun clear() = sharedPreferences.edit().clear().apply()
|
|
||||||
|
|
||||||
override fun contains(key: String): Boolean = sharedPreferences.contains(key)
|
|
||||||
|
|
||||||
override fun contains(resourceId: Int): Boolean = sharedPreferences.contains(context.getString(resourceId))
|
|
||||||
|
|
||||||
override fun remove(resourceID: Int) =
|
|
||||||
sharedPreferences.edit().remove(context.getString(resourceID)).apply()
|
|
||||||
|
|
||||||
override fun remove(key: String) =
|
|
||||||
sharedPreferences.edit().remove(key).apply()
|
|
||||||
|
|
||||||
override fun getString(resourceID: Int, defaultValue: String): String =
|
|
||||||
sharedPreferences.getString(context.getString(resourceID), defaultValue) ?: defaultValue
|
|
||||||
|
|
||||||
override fun getString(key: String, defaultValue: String): String =
|
|
||||||
sharedPreferences.getString(key, defaultValue) ?: defaultValue
|
|
||||||
|
|
||||||
override fun getStringOrNull(resourceID: Int, defaultValue: String?): String? =
|
|
||||||
sharedPreferences.getString(context.getString(resourceID), defaultValue) ?: defaultValue
|
|
||||||
|
|
||||||
override fun getStringOrNull(key: String, defaultValue: String?): String? =
|
|
||||||
sharedPreferences.getString(key, defaultValue)
|
|
||||||
|
|
||||||
override fun getBoolean(resourceID: Int, defaultValue: Boolean): Boolean {
|
|
||||||
return try {
|
|
||||||
sharedPreferences.getBoolean(context.getString(resourceID), defaultValue)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
defaultValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getBoolean(key: String, defaultValue: Boolean): Boolean {
|
|
||||||
return try {
|
|
||||||
sharedPreferences.getBoolean(key, defaultValue)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
defaultValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getDouble(resourceID: Int, defaultValue: Double): Double =
|
|
||||||
SafeParse.stringToDouble(sharedPreferences.getString(context.getString(resourceID), defaultValue.toString()), defaultValue)
|
|
||||||
|
|
||||||
override fun getDouble(key: String, defaultValue: Double): Double =
|
|
||||||
SafeParse.stringToDouble(sharedPreferences.getString(key, defaultValue.toString()), defaultValue)
|
|
||||||
|
|
||||||
override fun getInt(resourceID: Int, defaultValue: Int): Int {
|
|
||||||
return try {
|
|
||||||
sharedPreferences.getInt(context.getString(resourceID), defaultValue)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
SafeParse.stringToInt(sharedPreferences.getString(context.getString(resourceID), defaultValue.toString()), defaultValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getInt(key: String, defaultValue: Int): Int {
|
|
||||||
return try {
|
|
||||||
sharedPreferences.getInt(key, defaultValue)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
SafeParse.stringToInt(sharedPreferences.getString(key, defaultValue.toString()), defaultValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getLong(resourceID: Int, defaultValue: Long): Long {
|
|
||||||
return try {
|
|
||||||
sharedPreferences.getLong(context.getString(resourceID), defaultValue)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
SafeParse.stringToLong(sharedPreferences.getString(context.getString(resourceID), defaultValue.toString()), defaultValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getLong(key: String, defaultValue: Long): Long {
|
|
||||||
return try {
|
|
||||||
sharedPreferences.getLong(key, defaultValue)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
SafeParse.stringToLong(sharedPreferences.getString(key, defaultValue.toString()), defaultValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun incLong(resourceID: Int) {
|
|
||||||
val value = getLong(resourceID, 0) + 1L
|
|
||||||
sharedPreferences.edit().putLong(context.getString(resourceID), value).apply()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun putBoolean(key: String, value: Boolean) = sharedPreferences.edit().putBoolean(key, value).apply()
|
|
||||||
|
|
||||||
override fun putBoolean(resourceID: Int, value: Boolean) =
|
|
||||||
sharedPreferences.edit().putBoolean(context.getString(resourceID), value).apply()
|
|
||||||
|
|
||||||
override fun putDouble(key: String, value: Double) =
|
|
||||||
sharedPreferences.edit().putString(key, value.toString()).apply()
|
|
||||||
|
|
||||||
override fun putDouble(resourceID: Int, value: Double) {
|
|
||||||
sharedPreferences.edit().putString(context.getString(resourceID), value.toString()).apply()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun putLong(key: String, value: Long) =
|
|
||||||
sharedPreferences.edit().putLong(key, value).apply()
|
|
||||||
|
|
||||||
override fun putLong(resourceID: Int, value: Long) =
|
|
||||||
sharedPreferences.edit().putLong(context.getString(resourceID), value).apply()
|
|
||||||
|
|
||||||
override fun putInt(key: String, value: Int) =
|
|
||||||
sharedPreferences.edit().putInt(key, value).apply()
|
|
||||||
|
|
||||||
override fun putInt(resourceID: Int, value: Int) =
|
|
||||||
sharedPreferences.edit().putInt(context.getString(resourceID), value).apply()
|
|
||||||
|
|
||||||
override fun incInt(resourceID: Int) {
|
|
||||||
val value = getInt(resourceID, 0) + 1
|
|
||||||
sharedPreferences.edit().putInt(context.getString(resourceID), value).apply()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun putString(resourceID: Int, value: String) =
|
|
||||||
sharedPreferences.edit().putString(context.getString(resourceID), value).apply()
|
|
||||||
|
|
||||||
override fun putString(key: String, value: String) =
|
|
||||||
sharedPreferences.edit().putString(key, value).apply()
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,470 +0,0 @@
|
||||||
package info.nightscout.shared.utils
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.os.Build
|
|
||||||
import androidx.annotation.RequiresApi
|
|
||||||
import androidx.collection.LongSparseArray
|
|
||||||
import info.nightscout.annotations.OpenForTesting
|
|
||||||
import info.nightscout.interfaces.R
|
|
||||||
import info.nightscout.shared.SafeParse
|
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
|
||||||
import org.apache.commons.lang3.time.DateUtils.isSameDay
|
|
||||||
import org.joda.time.DateTime
|
|
||||||
import org.joda.time.format.DateTimeFormat
|
|
||||||
import org.joda.time.format.ISODateTimeFormat
|
|
||||||
import java.security.SecureRandom
|
|
||||||
import java.text.DateFormat
|
|
||||||
import java.text.DecimalFormat
|
|
||||||
import java.text.DecimalFormatSymbols
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.time.Instant
|
|
||||||
import java.time.ZoneId
|
|
||||||
import java.time.ZoneOffset
|
|
||||||
import java.util.Calendar
|
|
||||||
import java.util.Date
|
|
||||||
import java.util.EnumSet
|
|
||||||
import java.util.GregorianCalendar
|
|
||||||
import java.util.Locale
|
|
||||||
import java.util.TimeZone
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import java.util.regex.Pattern
|
|
||||||
import java.util.stream.Collectors
|
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Singleton
|
|
||||||
import kotlin.math.ceil
|
|
||||||
import kotlin.math.floor
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Class DateUtil. A simple wrapper around SimpleDateFormat to ease the handling of iso date string <-> date obj
|
|
||||||
* with TZ
|
|
||||||
*/
|
|
||||||
@OpenForTesting
|
|
||||||
@Singleton
|
|
||||||
class DateUtilImpl @Inject constructor(private val context: Context) : DateUtil {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The date format in iso.
|
|
||||||
*/
|
|
||||||
@Suppress("PrivatePropertyName", "SpellCheckingInspection")
|
|
||||||
private val FORMAT_DATE_ISO_OUT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Takes in an ISO date string of the following format:
|
|
||||||
* yyyy-mm-ddThh:mm:ss.ms+HoMo
|
|
||||||
*
|
|
||||||
* @param isoDateString the iso date string
|
|
||||||
* @return the date
|
|
||||||
*/
|
|
||||||
override fun fromISODateString(isoDateString: String): Long {
|
|
||||||
val parser = ISODateTimeFormat.dateTimeParser()
|
|
||||||
val dateTime = DateTime.parse(isoDateString, parser)
|
|
||||||
return dateTime.toDate().time
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render date
|
|
||||||
*
|
|
||||||
* @param date the date obj
|
|
||||||
* @return the iso-formatted date string
|
|
||||||
*/
|
|
||||||
override fun toISOString(date: Long): String {
|
|
||||||
val f: DateFormat = SimpleDateFormat(FORMAT_DATE_ISO_OUT, Locale.getDefault())
|
|
||||||
f.timeZone = TimeZone.getTimeZone("UTC")
|
|
||||||
return f.format(date)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("SpellCheckingInspection")
|
|
||||||
override fun toISOAsUTC(timestamp: Long): String {
|
|
||||||
val format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'0000Z'", Locale.US)
|
|
||||||
format.timeZone = TimeZone.getTimeZone("UTC")
|
|
||||||
return format.format(timestamp)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("SpellCheckingInspection")
|
|
||||||
override fun toISONoZone(timestamp: Long): String {
|
|
||||||
val format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US)
|
|
||||||
format.timeZone = TimeZone.getDefault()
|
|
||||||
return format.format(timestamp)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun secondsOfTheDayToMilliseconds(seconds: Int): Long {
|
|
||||||
val calendar: Calendar = GregorianCalendar()
|
|
||||||
calendar[Calendar.MONTH] = 0 // Set january to be sure we miss DST changing
|
|
||||||
calendar[Calendar.HOUR_OF_DAY] = seconds / 60 / 60
|
|
||||||
calendar[Calendar.MINUTE] = seconds / 60 % 60
|
|
||||||
calendar[Calendar.SECOND] = 0
|
|
||||||
return calendar.timeInMillis
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toSeconds(hhColonMm: String): Int {
|
|
||||||
val p = Pattern.compile("(\\d+):(\\d+)( a.m.| p.m.| AM| PM|AM|PM|)")
|
|
||||||
val m = p.matcher(hhColonMm)
|
|
||||||
var retVal = 0
|
|
||||||
if (m.find()) {
|
|
||||||
retVal = SafeParse.stringToInt(m.group(1)) * 60 * 60 + SafeParse.stringToInt(m.group(2)) * 60
|
|
||||||
if ((m.group(3) == " a.m." || m.group(3) == " AM" || m.group(3) == "AM") && m.group(1) == "12") retVal -= 12 * 60 * 60
|
|
||||||
if ((m.group(3) == " p.m." || m.group(3) == " PM" || m.group(3) == "PM") && m.group(1) != "12") retVal += 12 * 60 * 60
|
|
||||||
}
|
|
||||||
return retVal
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun dateString(mills: Long): String {
|
|
||||||
val df = DateFormat.getDateInstance(DateFormat.SHORT)
|
|
||||||
return df.format(mills)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun dateStringRelative(mills: Long, rh: ResourceHelper): String {
|
|
||||||
val df = DateFormat.getDateInstance(DateFormat.SHORT)
|
|
||||||
val day = df.format(mills)
|
|
||||||
val beginOfToday = beginOfDay(now())
|
|
||||||
return if (mills < now()) // Past
|
|
||||||
when {
|
|
||||||
mills > beginOfToday -> rh.gs(R.string.today)
|
|
||||||
mills > beginOfToday - T.days(1).msecs() -> rh.gs(R.string.yesterday)
|
|
||||||
mills > beginOfToday - T.days(7).msecs() -> dayAgo(mills, rh, true)
|
|
||||||
else -> day
|
|
||||||
}
|
|
||||||
else // Future
|
|
||||||
when {
|
|
||||||
mills < beginOfToday + T.days(1).msecs() -> rh.gs(R.string.later_today)
|
|
||||||
mills < beginOfToday + T.days(2).msecs() -> rh.gs(R.string.tomorrow)
|
|
||||||
mills < beginOfToday + T.days(7).msecs() -> dayAgo(mills, rh, true)
|
|
||||||
else -> day
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun dateStringShort(mills: Long): String {
|
|
||||||
var format = "MM/dd"
|
|
||||||
if (android.text.format.DateFormat.is24HourFormat(context)) {
|
|
||||||
format = "dd/MM"
|
|
||||||
}
|
|
||||||
return DateTime(mills).toString(DateTimeFormat.forPattern(format))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun timeString(): String = timeString(now())
|
|
||||||
override fun timeString(mills: Long): String {
|
|
||||||
var format = "hh:mma"
|
|
||||||
if (android.text.format.DateFormat.is24HourFormat(context)) {
|
|
||||||
format = "HH:mm"
|
|
||||||
}
|
|
||||||
return DateTime(mills).toString(DateTimeFormat.forPattern(format))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun secondString(): String = secondString(now())
|
|
||||||
override fun secondString(mills: Long): String =
|
|
||||||
DateTime(mills).toString(DateTimeFormat.forPattern("ss"))
|
|
||||||
|
|
||||||
override fun minuteString(): String = minuteString(now())
|
|
||||||
override fun minuteString(mills: Long): String =
|
|
||||||
DateTime(mills).toString(DateTimeFormat.forPattern("mm"))
|
|
||||||
|
|
||||||
override fun hourString(): String = hourString(now())
|
|
||||||
override fun hourString(mills: Long): String {
|
|
||||||
var format = "hh"
|
|
||||||
if (android.text.format.DateFormat.is24HourFormat(context)) {
|
|
||||||
format = "HH"
|
|
||||||
}
|
|
||||||
return DateTime(mills).toString(DateTimeFormat.forPattern(format))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun amPm(): String = amPm(now())
|
|
||||||
override fun amPm(mills: Long): String =
|
|
||||||
DateTime(mills).toString(DateTimeFormat.forPattern("a"))
|
|
||||||
|
|
||||||
override fun dayNameString(format: String): String = dayNameString(now(), format)
|
|
||||||
override fun dayNameString(mills: Long, format: String): String =
|
|
||||||
DateTime(mills).toString(DateTimeFormat.forPattern(format))
|
|
||||||
|
|
||||||
override fun dayString(): String = dayString(now())
|
|
||||||
override fun dayString(mills: Long): String =
|
|
||||||
DateTime(mills).toString(DateTimeFormat.forPattern("dd"))
|
|
||||||
|
|
||||||
override fun monthString(format: String): String = monthString(now(), format)
|
|
||||||
override fun monthString(mills: Long, format: String): String =
|
|
||||||
DateTime(mills).toString(DateTimeFormat.forPattern(format))
|
|
||||||
|
|
||||||
override fun weekString(): String = weekString(now())
|
|
||||||
override fun weekString(mills: Long): String =
|
|
||||||
DateTime(mills).toString(DateTimeFormat.forPattern("ww"))
|
|
||||||
|
|
||||||
override fun timeStringWithSeconds(mills: Long): String {
|
|
||||||
var format = "hh:mm:ssa"
|
|
||||||
if (android.text.format.DateFormat.is24HourFormat(context)) {
|
|
||||||
format = "HH:mm:ss"
|
|
||||||
}
|
|
||||||
return DateTime(mills).toString(DateTimeFormat.forPattern(format))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun dateAndTimeRangeString(start: Long, end: Long): String {
|
|
||||||
return dateAndTimeString(start) + " - " + timeString(end)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun timeRangeString(start: Long, end: Long): String {
|
|
||||||
return timeString(start) + " - " + timeString(end)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun dateAndTimeString(mills: Long): String {
|
|
||||||
return if (mills == 0L) "" else dateString(mills) + " " + timeString(mills)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun dateAndTimeAndSecondsString(mills: Long): String {
|
|
||||||
return if (mills == 0L) "" else dateString(mills) + " " + timeStringWithSeconds(mills)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun minAgo(rh: ResourceHelper, time: Long?): String {
|
|
||||||
if (time == null) return ""
|
|
||||||
val minutes = ((now() - time) / 1000 / 60).toInt()
|
|
||||||
return rh.gs(R.string.minago, minutes)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun minAgoShort(time: Long?): String {
|
|
||||||
if (time == null) return ""
|
|
||||||
val minutes = ((time - now()) / 1000 / 60).toInt()
|
|
||||||
return (if (minutes > 0) "+" else "") + minutes
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun minAgoLong(rh: ResourceHelper, time: Long?): String {
|
|
||||||
if (time == null) return ""
|
|
||||||
val minutes = ((now() - time) / 1000 / 60).toInt()
|
|
||||||
return rh.gs(R.string.minago_long, minutes)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hourAgo(time: Long, rh: ResourceHelper): String {
|
|
||||||
val hours = (now() - time) / 1000.0 / 60 / 60
|
|
||||||
return rh.gs(R.string.hoursago, hours)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun dayAgo(time: Long, rh: ResourceHelper, round: Boolean): String {
|
|
||||||
var days = (now() - time) / 1000.0 / 60 / 60 / 24
|
|
||||||
if (round) {
|
|
||||||
return if (now() > time) {
|
|
||||||
days = ceil(days)
|
|
||||||
rh.gs(R.string.days_ago_round, days)
|
|
||||||
} else {
|
|
||||||
days = floor(days)
|
|
||||||
rh.gs(R.string.in_days_round, days)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return if (now() > time)
|
|
||||||
rh.gs(R.string.days_ago, days)
|
|
||||||
else
|
|
||||||
rh.gs(R.string.in_days, days)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun beginOfDay(mills: Long): Long {
|
|
||||||
val givenDate = Calendar.getInstance()
|
|
||||||
givenDate.timeInMillis = mills
|
|
||||||
givenDate[Calendar.HOUR_OF_DAY] = 0
|
|
||||||
givenDate[Calendar.MINUTE] = 0
|
|
||||||
givenDate[Calendar.SECOND] = 0
|
|
||||||
givenDate[Calendar.MILLISECOND] = 0
|
|
||||||
return givenDate.timeInMillis
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun timeStringFromSeconds(seconds: Int): String {
|
|
||||||
val cached = timeStrings[seconds.toLong()]
|
|
||||||
if (cached != null) return cached
|
|
||||||
val t = timeString(secondsOfTheDayToMilliseconds(seconds))
|
|
||||||
timeStrings.put(seconds.toLong(), t)
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun timeFrameString(timeInMillis: Long, rh: ResourceHelper): String {
|
|
||||||
var remainingTimeMinutes = timeInMillis / (1000 * 60)
|
|
||||||
val remainingTimeHours = remainingTimeMinutes / 60
|
|
||||||
remainingTimeMinutes %= 60
|
|
||||||
return "(" + (if (remainingTimeHours > 0) remainingTimeHours.toString() + rh.gs(R.string.shorthour) + " " else "") + remainingTimeMinutes + "')"
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun sinceString(timestamp: Long, rh: ResourceHelper): String {
|
|
||||||
return timeFrameString(System.currentTimeMillis() - timestamp, rh)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun untilString(timestamp: Long, rh: ResourceHelper): String {
|
|
||||||
return timeFrameString(timestamp - System.currentTimeMillis(), rh)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun now(): Long {
|
|
||||||
return System.currentTimeMillis()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun nowWithoutMilliseconds(): Long {
|
|
||||||
var n = System.currentTimeMillis()
|
|
||||||
n -= n % 1000
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isOlderThan(date: Long, minutes: Long): Boolean {
|
|
||||||
val diff = now() - date
|
|
||||||
return diff > T.mins(minutes).msecs()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getTimeZoneOffsetMs(): Long {
|
|
||||||
return GregorianCalendar().timeZone.rawOffset.toLong()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getTimeZoneOffsetMinutes(timestamp: Long): Int {
|
|
||||||
return TimeZone.getDefault().getOffset(timestamp) / 60000
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isSameDay(timestamp1: Long, timestamp2: Long) = isSameDay(Date(timestamp1), Date(timestamp2))
|
|
||||||
|
|
||||||
override fun isSameDayGroup(timestamp1: Long, timestamp2: Long): Boolean {
|
|
||||||
val now = now()
|
|
||||||
if (now in (timestamp1 + 1) until timestamp2 || now in (timestamp2 + 1) until timestamp1)
|
|
||||||
return false
|
|
||||||
return isSameDay(Date(timestamp1), Date(timestamp2))
|
|
||||||
}
|
|
||||||
|
|
||||||
//Map:{DAYS=1, HOURS=3, MINUTES=46, SECONDS=40, MILLISECONDS=0, MICROSECONDS=0, NANOSECONDS=0}
|
|
||||||
override fun computeDiff(date1: Long, date2: Long): Map<TimeUnit, Long> {
|
|
||||||
val units: MutableList<TimeUnit> = ArrayList(EnumSet.allOf(TimeUnit::class.java))
|
|
||||||
units.reverse()
|
|
||||||
val result: MutableMap<TimeUnit, Long> = LinkedHashMap()
|
|
||||||
var millisecondsRest = date2 - date1
|
|
||||||
for (unit in units) {
|
|
||||||
val diff = unit.convert(millisecondsRest, TimeUnit.MILLISECONDS)
|
|
||||||
val diffInMillisecondsForUnit = unit.toMillis(diff)
|
|
||||||
millisecondsRest -= diffInMillisecondsForUnit
|
|
||||||
result[unit] = diff
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun age(milliseconds: Long, useShortText: Boolean, rh: ResourceHelper): String {
|
|
||||||
val diff = computeDiff(0L, milliseconds)
|
|
||||||
var days = " " + rh.gs(R.string.days) + " "
|
|
||||||
var hours = " " + rh.gs(R.string.hours) + " "
|
|
||||||
var minutes = " " + rh.gs(R.string.unit_minutes) + " "
|
|
||||||
if (useShortText) {
|
|
||||||
days = rh.gs(R.string.shortday)
|
|
||||||
hours = rh.gs(R.string.shorthour)
|
|
||||||
minutes = rh.gs(R.string.shortminute)
|
|
||||||
}
|
|
||||||
var result = ""
|
|
||||||
if (diff.getOrDefault(TimeUnit.DAYS, -1) > 0) result += diff[TimeUnit.DAYS].toString() + days
|
|
||||||
if (diff.getOrDefault(TimeUnit.HOURS, -1) > 0) result += diff[TimeUnit.HOURS].toString() + hours
|
|
||||||
if (diff[TimeUnit.DAYS] == 0L) result += diff[TimeUnit.MINUTES].toString() + minutes
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun niceTimeScalar(time: Long, rh: ResourceHelper): String {
|
|
||||||
var t = time
|
|
||||||
var unit = rh.gs(R.string.unit_second)
|
|
||||||
t /= 1000
|
|
||||||
if (t != 1L) unit = rh.gs(R.string.unit_seconds)
|
|
||||||
if (t > 59) {
|
|
||||||
unit = rh.gs(R.string.unit_minute)
|
|
||||||
t /= 60
|
|
||||||
if (t != 1L) unit = rh.gs(R.string.unit_minutes)
|
|
||||||
if (t > 59) {
|
|
||||||
unit = rh.gs(R.string.unit_hour)
|
|
||||||
t /= 60
|
|
||||||
if (t != 1L) unit = rh.gs(R.string.unit_hours)
|
|
||||||
if (t > 24) {
|
|
||||||
unit = rh.gs(R.string.unit_day)
|
|
||||||
t /= 24
|
|
||||||
if (t != 1L) unit = rh.gs(R.string.unit_days)
|
|
||||||
if (t > 28) {
|
|
||||||
unit = rh.gs(R.string.unit_week)
|
|
||||||
t /= 7
|
|
||||||
@Suppress("KotlinConstantConditions")
|
|
||||||
if (t != 1L) unit = rh.gs(R.string.unit_weeks)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//if (t != 1) unit = unit + "s"; //implemented plurality in every step, because in other languages plurality of time is not every time adding the same character
|
|
||||||
return qs(t.toDouble(), 0) + " " + unit
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun qs(x: Double, numDigits: Int): String {
|
|
||||||
var digits = numDigits
|
|
||||||
if (digits == -1) {
|
|
||||||
digits = 0
|
|
||||||
if ((x.toInt() % x == 0.0)) {
|
|
||||||
digits++
|
|
||||||
if ((x.toInt() * 10 / 10).toDouble() != x) {
|
|
||||||
digits++
|
|
||||||
if ((x.toInt() * 100 / 100).toDouble() != x) digits++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (dfs == null) {
|
|
||||||
val localDfs = DecimalFormatSymbols()
|
|
||||||
localDfs.decimalSeparator = '.'
|
|
||||||
dfs = localDfs // avoid race condition
|
|
||||||
}
|
|
||||||
val thisDf: DecimalFormat?
|
|
||||||
// use singleton if on ui thread otherwise allocate new as DecimalFormat is not thread safe
|
|
||||||
if (Thread.currentThread().id == 1L) {
|
|
||||||
if (df == null) {
|
|
||||||
val localDf = DecimalFormat("#", dfs)
|
|
||||||
localDf.minimumIntegerDigits = 1
|
|
||||||
df = localDf // avoid race condition
|
|
||||||
}
|
|
||||||
thisDf = df
|
|
||||||
} else {
|
|
||||||
thisDf = DecimalFormat("#", dfs)
|
|
||||||
}
|
|
||||||
thisDf?.maximumFractionDigits = digits
|
|
||||||
return thisDf?.format(x) ?: ""
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun formatHHMM(timeAsSeconds: Int): String {
|
|
||||||
val hour = timeAsSeconds / 60 / 60
|
|
||||||
val minutes = (timeAsSeconds - hour * 60 * 60) / 60
|
|
||||||
val df = DecimalFormat("00")
|
|
||||||
return df.format(hour.toLong()) + ":" + df.format(minutes.toLong())
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
|
||||||
override fun timeZoneByOffset(offsetInMilliseconds: Long): TimeZone =
|
|
||||||
TimeZone.getTimeZone(
|
|
||||||
if (offsetInMilliseconds == 0L) ZoneId.of("UTC")
|
|
||||||
else ZoneId.getAvailableZoneIds()
|
|
||||||
.stream()
|
|
||||||
.map(ZoneId::of)
|
|
||||||
.filter { z -> z.rules.getOffset(Instant.now()).totalSeconds == ZoneOffset.ofHours((offsetInMilliseconds / 1000 / 3600).toInt()).totalSeconds }
|
|
||||||
.collect(Collectors.toList())
|
|
||||||
.firstOrNull() ?: ZoneId.of("UTC")
|
|
||||||
)
|
|
||||||
|
|
||||||
override fun timeStampToUtcDateMillis(timestamp: Long): Long {
|
|
||||||
val current = Calendar.getInstance().apply { timeInMillis = timestamp }
|
|
||||||
return Calendar.getInstance().apply {
|
|
||||||
set(Calendar.YEAR, current[Calendar.YEAR])
|
|
||||||
set(Calendar.MONTH, current[Calendar.MONTH])
|
|
||||||
set(Calendar.DAY_OF_MONTH, current[Calendar.DAY_OF_MONTH])
|
|
||||||
}.timeInMillis
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun mergeUtcDateToTimestamp(timestamp: Long, dateUtcMillis: Long): Long {
|
|
||||||
val selected = Calendar.getInstance().apply { timeInMillis = dateUtcMillis }
|
|
||||||
return Calendar.getInstance().apply {
|
|
||||||
timeInMillis = timestamp
|
|
||||||
set(Calendar.YEAR, selected[Calendar.YEAR])
|
|
||||||
set(Calendar.MONTH, selected[Calendar.MONTH])
|
|
||||||
set(Calendar.DAY_OF_MONTH, selected[Calendar.DAY_OF_MONTH])
|
|
||||||
}.timeInMillis
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun mergeHourMinuteToTimestamp(timestamp: Long, hour: Int, minute: Int, randomSecond: Boolean): Long {
|
|
||||||
return Calendar.getInstance().apply {
|
|
||||||
timeInMillis = timestamp
|
|
||||||
set(Calendar.HOUR_OF_DAY, hour)
|
|
||||||
set(Calendar.MINUTE, minute)
|
|
||||||
if (randomSecond) set(Calendar.SECOND, seconds++)
|
|
||||||
}.timeInMillis
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
private val timeStrings = LongSparseArray<String>()
|
|
||||||
private var seconds: Int = (SecureRandom().nextDouble() * 59.0).toInt()
|
|
||||||
|
|
||||||
// singletons to avoid repeated allocation
|
|
||||||
private var dfs: DecimalFormatSymbols? = null
|
|
||||||
private var df: DecimalFormat? = null
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,87 +0,0 @@
|
||||||
package info.nightscout.sharedtests
|
|
||||||
|
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
|
||||||
import info.nightscout.rx.logging.LTag
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by adrian on 2019-12-27.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class AAPSLoggerTest : AAPSLogger {
|
|
||||||
|
|
||||||
override fun debug(message: String) {
|
|
||||||
println("DEBUG: $message")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun debug(enable: Boolean, tag: LTag, message: String) {
|
|
||||||
println("DEBUG: " + message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun debug(tag: LTag, message: String) {
|
|
||||||
println("DEBUG: : " + tag.tag + " " + message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun debug(tag: LTag, accessor: () -> String) {
|
|
||||||
println("DEBUG: : " + tag.tag + " " + accessor.invoke())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun debug(tag: LTag, format: String, vararg arguments: Any?) {
|
|
||||||
println("DEBUG: : " + tag.tag + " " + String.format(format, arguments))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun warn(tag: LTag, message: String) {
|
|
||||||
println("WARN: " + tag.tag + " " + message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun warn(tag: LTag, format: String, vararg arguments: Any?) {
|
|
||||||
println("INFO: : " + tag.tag + " " + String.format(format, arguments))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun info(tag: LTag, message: String) {
|
|
||||||
println("INFO: " + tag.tag + " " + message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun info(tag: LTag, format: String, vararg arguments: Any?) {
|
|
||||||
println("INFO: : " + tag.tag + " " + String.format(format, arguments))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun error(tag: LTag, message: String) {
|
|
||||||
println("ERROR: " + tag.tag + " " + message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun error(message: String) {
|
|
||||||
println("ERROR: " + message)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun error(message: String, throwable: Throwable) {
|
|
||||||
println("ERROR: " + message + " " + throwable)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun error(format: String, vararg arguments: Any?) {
|
|
||||||
println("ERROR: : " + String.format(format, arguments))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun error(tag: LTag, message: String, throwable: Throwable) {
|
|
||||||
println("ERROR: " + tag.tag + " " + message + " " + throwable)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun error(tag: LTag, format: String, vararg arguments: Any?) {
|
|
||||||
println("ERROR: : " + tag.tag + " " + String.format(format, arguments))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun debug(className: String, methodName: String, lineNumber: Int, tag: LTag, message: String) {
|
|
||||||
println("DEBUG: : ${tag.tag} $className.$methodName():$lineNumber $message")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun info(className: String, methodName: String, lineNumber: Int, tag: LTag, message: String) {
|
|
||||||
println("INFO: : ${tag.tag} $className.$methodName():$lineNumber $message")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun warn(className: String, methodName: String, lineNumber: Int, tag: LTag, message: String) {
|
|
||||||
println("WARN: : ${tag.tag} $className.$methodName():$lineNumber $message")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun error(className: String, methodName: String, lineNumber: Int, tag: LTag, message: String) {
|
|
||||||
println("ERROR: : ${tag.tag} $className.$methodName():$lineNumber $message")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,173 +0,0 @@
|
||||||
package info.nightscout.sharedtests;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyByte;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyChar;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyFloat;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyLong;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyShort;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
|
||||||
import static org.mockito.Mockito.doAnswer;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.util.SparseArray;
|
|
||||||
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.mockito.stubbing.Answer;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
@SuppressWarnings({"unused", "rawtypes", "SuspiciousMethodCalls", "unchecked", "deprecation"})
|
|
||||||
public final class BundleMock {
|
|
||||||
|
|
||||||
public static Bundle mock() {
|
|
||||||
return mock(new HashMap<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Bundle mock(final HashMap<String, Object> map) {
|
|
||||||
|
|
||||||
Answer unsupported = invocation -> {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
};
|
|
||||||
Answer put = invocation -> {
|
|
||||||
map.put((String) invocation.getArguments()[0], invocation.getArguments()[1]);
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
Answer<Object> get = invocation -> map.get(invocation.getArguments()[0]);
|
|
||||||
Answer<Object> getOrDefault = invocation -> {
|
|
||||||
Object key = invocation.getArguments()[0];
|
|
||||||
return map.containsKey(key) ? map.get(key) : invocation.getArguments()[1];
|
|
||||||
};
|
|
||||||
|
|
||||||
Bundle bundle = Mockito.mock(Bundle.class);
|
|
||||||
|
|
||||||
doAnswer(invocation -> map.size()).when(bundle).size();
|
|
||||||
doAnswer(invocation -> map.isEmpty()).when(bundle).isEmpty();
|
|
||||||
doAnswer(invocation -> {
|
|
||||||
map.clear();
|
|
||||||
return null;
|
|
||||||
}).when(bundle).clear();
|
|
||||||
doAnswer(invocation -> map.containsKey(invocation.getArguments()[0])).when(bundle).containsKey(anyString());
|
|
||||||
doAnswer(invocation -> map.get(invocation.getArguments()[0])).when(bundle).get(anyString());
|
|
||||||
doAnswer(invocation -> {
|
|
||||||
map.remove(invocation.getArguments()[0]);
|
|
||||||
return null;
|
|
||||||
}).when(bundle).remove(anyString());
|
|
||||||
doAnswer(invocation -> map.keySet()).when(bundle).keySet();
|
|
||||||
doAnswer(invocation -> BundleMock.class.getSimpleName() + "{map=" + map.toString() + "}").when(bundle).toString();
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putBoolean(anyString(), anyBoolean());
|
|
||||||
when(bundle.getBoolean(anyString())).thenAnswer(get);
|
|
||||||
when(bundle.getBoolean(anyString(), anyBoolean())).thenAnswer(getOrDefault);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putByte(anyString(), anyByte());
|
|
||||||
when(bundle.getByte(anyString())).thenAnswer(get);
|
|
||||||
when(bundle.getByte(anyString(), anyByte())).thenAnswer(getOrDefault);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putChar(anyString(), anyChar());
|
|
||||||
when(bundle.getChar(anyString())).thenAnswer(get);
|
|
||||||
when(bundle.getChar(anyString(), anyChar())).thenAnswer(getOrDefault);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putInt(anyString(), anyShort());
|
|
||||||
when(bundle.getShort(anyString())).thenAnswer(get);
|
|
||||||
when(bundle.getShort(anyString(), anyShort())).thenAnswer(getOrDefault);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putLong(anyString(), anyLong());
|
|
||||||
when(bundle.getLong(anyString())).thenAnswer(get);
|
|
||||||
when(bundle.getLong(anyString(), anyLong())).thenAnswer(getOrDefault);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putFloat(anyString(), anyFloat());
|
|
||||||
when(bundle.getFloat(anyString())).thenAnswer(get);
|
|
||||||
when(bundle.getFloat(anyString(), anyFloat())).thenAnswer(getOrDefault);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putDouble(anyString(), anyDouble());
|
|
||||||
when(bundle.getDouble(anyString())).thenAnswer(get);
|
|
||||||
when(bundle.getDouble(anyString(), anyDouble())).thenAnswer(getOrDefault);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putString(anyString(), anyString());
|
|
||||||
when(bundle.getString(anyString())).thenAnswer(get);
|
|
||||||
when(bundle.getString(anyString(), anyString())).thenAnswer(getOrDefault);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putBooleanArray(anyString(), any(boolean[].class));
|
|
||||||
when(bundle.getBooleanArray(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putLongArray(anyString(), any(long[].class));
|
|
||||||
when(bundle.getLongArray(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putDoubleArray(anyString(), any(double[].class));
|
|
||||||
when(bundle.getDoubleArray(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putIntArray(anyString(), any(int[].class));
|
|
||||||
when(bundle.getIntArray(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putInt(anyString(), anyInt());
|
|
||||||
when(bundle.getInt(anyString())).thenAnswer(get);
|
|
||||||
when(bundle.getInt(anyString(), anyInt())).thenAnswer(getOrDefault);
|
|
||||||
|
|
||||||
doAnswer(unsupported).when(bundle).putAll(any(Bundle.class));
|
|
||||||
when(bundle.hasFileDescriptors()).thenAnswer(unsupported);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putShort(anyString(), anyShort());
|
|
||||||
when(bundle.getShort(anyString())).thenAnswer(get);
|
|
||||||
when(bundle.getShort(anyString(), anyShort())).thenAnswer(getOrDefault);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putFloat(anyString(), anyFloat());
|
|
||||||
when(bundle.getFloat(anyString())).thenAnswer(get);
|
|
||||||
when(bundle.getFloat(anyString(), anyFloat())).thenAnswer(getOrDefault);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putCharSequence(anyString(), any(CharSequence.class));
|
|
||||||
when(bundle.getCharSequence(anyString())).thenAnswer(get);
|
|
||||||
when(bundle.getCharSequence(anyString(), any(CharSequence.class))).thenAnswer(getOrDefault);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putBundle(anyString(), any(Bundle.class));
|
|
||||||
when(bundle.getBundle(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putParcelable(anyString(), any(Parcelable.class));
|
|
||||||
when(bundle.getParcelable(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putParcelableArray(anyString(), any(Parcelable[].class));
|
|
||||||
when(bundle.getParcelableArray(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putParcelableArrayList(anyString(), any(ArrayList.class));
|
|
||||||
when(bundle.getParcelableArrayList(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putSparseParcelableArray(anyString(), any(SparseArray.class));
|
|
||||||
when(bundle.getSparseParcelableArray(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putSerializable(anyString(), any(Serializable.class));
|
|
||||||
when(bundle.getSerializable(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putIntegerArrayList(anyString(), any(ArrayList.class));
|
|
||||||
when(bundle.getIntegerArrayList(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putStringArrayList(anyString(), any(ArrayList.class));
|
|
||||||
when(bundle.getStringArrayList(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putCharSequenceArrayList(anyString(), any(ArrayList.class));
|
|
||||||
when(bundle.getCharSequenceArrayList(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putCharArray(anyString(), any(char[].class));
|
|
||||||
when(bundle.getCharArray(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putByteArray(anyString(), any(byte[].class));
|
|
||||||
when(bundle.getByteArray(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putShortArray(anyString(), any(short[].class));
|
|
||||||
when(bundle.getShortArray(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putFloatArray(anyString(), any(float[].class));
|
|
||||||
when(bundle.getFloatArray(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
doAnswer(put).when(bundle).putCharSequenceArray(anyString(), any(CharSequence[].class));
|
|
||||||
when(bundle.getCharSequenceArray(anyString())).thenAnswer(get);
|
|
||||||
|
|
||||||
return bundle;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,83 +0,0 @@
|
||||||
package info.nightscout.sharedtests
|
|
||||||
|
|
||||||
import info.nightscout.interfaces.utils.HardLimits
|
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlin.math.max
|
|
||||||
import kotlin.math.min
|
|
||||||
|
|
||||||
@Suppress("unused") class HardLimitsMock @Inject constructor(
|
|
||||||
private val sp: SP,
|
|
||||||
private val rh: ResourceHelper
|
|
||||||
) : HardLimits {
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
private const val CHILD = 0
|
|
||||||
private const val TEENAGE = 1
|
|
||||||
private const val ADULT = 2
|
|
||||||
private const val RESISTANT_ADULT = 3
|
|
||||||
private const val PREGNANT = 4
|
|
||||||
private val MAX_BOLUS = doubleArrayOf(5.0, 10.0, 17.0, 25.0, 60.0)
|
|
||||||
|
|
||||||
// Very Hard Limits Ranges
|
|
||||||
// First value is the Lowest and second value is the Highest a Limit can define
|
|
||||||
val VERY_HARD_LIMIT_MIN_BG = doubleArrayOf(80.0, 180.0)
|
|
||||||
val VERY_HARD_LIMIT_MAX_BG = doubleArrayOf(90.0, 200.0)
|
|
||||||
val VERY_HARD_LIMIT_TARGET_BG = doubleArrayOf(80.0, 200.0)
|
|
||||||
|
|
||||||
// Very Hard Limits Ranges for Temp Targets
|
|
||||||
val VERY_HARD_LIMIT_TEMP_MIN_BG = intArrayOf(72, 180)
|
|
||||||
val VERY_HARD_LIMIT_TEMP_MAX_BG = intArrayOf(72, 270)
|
|
||||||
val VERY_HARD_LIMIT_TEMP_TARGET_BG = intArrayOf(72, 200)
|
|
||||||
val MIN_DIA = doubleArrayOf(5.0, 5.0, 5.0, 5.0, 5.0)
|
|
||||||
val MAX_DIA = doubleArrayOf(9.0, 9.0, 9.0, 9.0, 10.0)
|
|
||||||
val MIN_IC = doubleArrayOf(2.0, 2.0, 2.0, 2.0, 0.3)
|
|
||||||
val MAX_IC = doubleArrayOf(100.0, 100.0, 100.0, 100.0, 100.0)
|
|
||||||
const val MIN_ISF = 2.0 // mgdl
|
|
||||||
const val MAX_ISF = 1000.0 // mgdl
|
|
||||||
val MAX_IOB_AMA = doubleArrayOf(3.0, 5.0, 7.0, 12.0, 25.0)
|
|
||||||
val MAX_IOB_SMB = doubleArrayOf(7.0, 13.0, 22.0, 30.0, 70.0)
|
|
||||||
val MAX_BASAL = doubleArrayOf(2.0, 5.0, 10.0, 12.0, 25.0)
|
|
||||||
|
|
||||||
//LGS Hard limits
|
|
||||||
//No IOB at all
|
|
||||||
const val MAX_IOB_LGS = 0.0
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun loadAge(): Int = when (sp.getString(info.nightscout.core.utils.R.string.key_age, "")) {
|
|
||||||
rh.gs(info.nightscout.core.utils.R.string.key_child) -> CHILD
|
|
||||||
rh.gs(info.nightscout.core.utils.R.string.key_teenage) -> TEENAGE
|
|
||||||
rh.gs(info.nightscout.core.utils.R.string.key_adult) -> ADULT
|
|
||||||
rh.gs(info.nightscout.core.utils.R.string.key_resistantadult) -> RESISTANT_ADULT
|
|
||||||
rh.gs(info.nightscout.core.utils.R.string.key_pregnant) -> PREGNANT
|
|
||||||
else -> ADULT
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun maxBolus(): Double = MAX_BOLUS[loadAge()]
|
|
||||||
override fun maxIobAMA(): Double = MAX_IOB_AMA[loadAge()]
|
|
||||||
override fun maxIobSMB(): Double = MAX_IOB_SMB[loadAge()]
|
|
||||||
override fun maxBasal(): Double = MAX_BASAL[loadAge()]
|
|
||||||
override fun minDia(): Double = MIN_DIA[loadAge()]
|
|
||||||
override fun maxDia(): Double = MAX_DIA[loadAge()]
|
|
||||||
override fun minIC(): Double = MIN_IC[loadAge()]
|
|
||||||
override fun maxIC(): Double = MAX_IC[loadAge()]
|
|
||||||
|
|
||||||
// safety checks
|
|
||||||
override fun checkHardLimits(value: Double, valueName: Int, lowLimit: Double, highLimit: Double): Boolean =
|
|
||||||
value == verifyHardLimits(value, valueName, lowLimit, highLimit)
|
|
||||||
|
|
||||||
override fun isInRange(value: Double, lowLimit: Double, highLimit: Double): Boolean =
|
|
||||||
value in lowLimit..highLimit
|
|
||||||
|
|
||||||
override fun verifyHardLimits(value: Double, valueName: Int, lowLimit: Double, highLimit: Double): Double {
|
|
||||||
var newValue = value
|
|
||||||
if (newValue < lowLimit || newValue > highLimit) {
|
|
||||||
newValue = max(newValue, lowLimit)
|
|
||||||
newValue = min(newValue, highLimit)
|
|
||||||
}
|
|
||||||
return newValue
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
package info.nightscout.sharedtests
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import info.nightscout.rx.AapsSchedulers
|
|
||||||
import info.nightscout.rx.bus.RxBus
|
|
||||||
import info.nightscout.shared.impl.rx.bus.RxBusImpl
|
|
||||||
import info.nightscout.sharedtests.rx.TestAapsSchedulers
|
|
||||||
import org.junit.jupiter.api.BeforeEach
|
|
||||||
import org.junit.jupiter.api.extension.ExtendWith
|
|
||||||
import org.mockito.ArgumentMatcher
|
|
||||||
import org.mockito.Mockito
|
|
||||||
import org.mockito.junit.jupiter.MockitoExtension
|
|
||||||
import org.mockito.junit.jupiter.MockitoSettings
|
|
||||||
import org.mockito.quality.Strictness
|
|
||||||
import java.util.Locale
|
|
||||||
|
|
||||||
@Suppress("SpellCheckingInspection")
|
|
||||||
@ExtendWith(MockitoExtension::class)
|
|
||||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
|
||||||
open class TestBase {
|
|
||||||
|
|
||||||
val aapsLogger = AAPSLoggerTest()
|
|
||||||
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
|
|
||||||
lateinit var rxBus: RxBus
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
fun setupLocale() {
|
|
||||||
Locale.setDefault(Locale.ENGLISH)
|
|
||||||
System.setProperty("disableFirebase", "true")
|
|
||||||
rxBus = RxBusImpl(aapsSchedulers, aapsLogger)
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("CheckResult")
|
|
||||||
fun <T> argThatKotlin(matcher: ArgumentMatcher<T>): T {
|
|
||||||
Mockito.argThat(matcher)
|
|
||||||
return uninitialized()
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("CheckResult")
|
|
||||||
fun <T> eqObject(expected: T): T {
|
|
||||||
Mockito.eq<T>(expected)
|
|
||||||
return uninitialized()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Workaround for Kotlin nullability.
|
|
||||||
// https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791
|
|
||||||
// https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin
|
|
||||||
@SuppressLint("CheckResult")
|
|
||||||
fun <T> anyObject(): T {
|
|
||||||
Mockito.any<T>()
|
|
||||||
return uninitialized()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("Unchecked_Cast")
|
|
||||||
private fun <T> uninitialized(): T = null as T
|
|
||||||
}
|
|
|
@ -1,230 +0,0 @@
|
||||||
package info.nightscout.sharedtests
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import dagger.android.AndroidInjector
|
|
||||||
import dagger.android.HasAndroidInjector
|
|
||||||
import info.nightscout.core.extensions.pureProfileFromJson
|
|
||||||
import info.nightscout.core.profile.ProfileSealed
|
|
||||||
import info.nightscout.core.utils.fabric.FabricPrivacy
|
|
||||||
import info.nightscout.database.entities.EffectiveProfileSwitch
|
|
||||||
import info.nightscout.database.entities.embedments.InsulinConfiguration
|
|
||||||
import info.nightscout.implementation.profile.ProfileStoreObject
|
|
||||||
import info.nightscout.implementation.profile.ProfileUtilImpl
|
|
||||||
import info.nightscout.implementation.utils.DecimalFormatterImpl
|
|
||||||
import info.nightscout.interfaces.Config
|
|
||||||
import info.nightscout.interfaces.GlucoseUnit
|
|
||||||
import info.nightscout.interfaces.iob.IobCobCalculator
|
|
||||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
|
||||||
import info.nightscout.interfaces.profile.ProfileFunction
|
|
||||||
import info.nightscout.interfaces.profile.ProfileStore
|
|
||||||
import info.nightscout.interfaces.utils.DecimalFormatter
|
|
||||||
import info.nightscout.interfaces.utils.HardLimits
|
|
||||||
import info.nightscout.shared.interfaces.ProfileUtil
|
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
|
||||||
import info.nightscout.shared.utils.DateUtil
|
|
||||||
import info.nightscout.shared.utils.DateUtilImpl
|
|
||||||
import org.json.JSONObject
|
|
||||||
import org.junit.jupiter.api.BeforeEach
|
|
||||||
import org.mockito.ArgumentMatchers.anyDouble
|
|
||||||
import org.mockito.ArgumentMatchers.anyInt
|
|
||||||
import org.mockito.ArgumentMatchers.anyString
|
|
||||||
import org.mockito.Mock
|
|
||||||
import org.mockito.Mockito
|
|
||||||
import org.mockito.invocation.InvocationOnMock
|
|
||||||
|
|
||||||
@Suppress("SpellCheckingInspection")
|
|
||||||
open class TestBaseWithProfile : TestBase() {
|
|
||||||
|
|
||||||
@Mock lateinit var activePlugin: ActivePlugin
|
|
||||||
@Mock lateinit var rh: ResourceHelper
|
|
||||||
@Mock lateinit var iobCobCalculator: IobCobCalculator
|
|
||||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
|
||||||
@Mock lateinit var config: Config
|
|
||||||
@Mock lateinit var context: Context
|
|
||||||
@Mock lateinit var sp: SP
|
|
||||||
|
|
||||||
lateinit var dateUtil: DateUtil
|
|
||||||
lateinit var profileUtil: ProfileUtil
|
|
||||||
lateinit var decimalFormatter: DecimalFormatter
|
|
||||||
lateinit var hardLimits: HardLimits
|
|
||||||
|
|
||||||
val profileInjector = HasAndroidInjector {
|
|
||||||
AndroidInjector {
|
|
||||||
if (it is ProfileStoreObject) {
|
|
||||||
it.aapsLogger = aapsLogger
|
|
||||||
it.activePlugin = activePlugin
|
|
||||||
it.config = config
|
|
||||||
it.rh = rh
|
|
||||||
it.rxBus = rxBus
|
|
||||||
it.hardLimits = hardLimits
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private lateinit var validProfileJSON: String
|
|
||||||
private lateinit var invalidProfileJSON: String
|
|
||||||
lateinit var validProfile: ProfileSealed.Pure
|
|
||||||
lateinit var effectiveProfileSwitch: EffectiveProfileSwitch
|
|
||||||
lateinit var testPumpPlugin: TestPumpPlugin
|
|
||||||
|
|
||||||
var now = 1656358822000L
|
|
||||||
|
|
||||||
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
fun prepareMock() {
|
|
||||||
validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," +
|
|
||||||
"{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," +
|
|
||||||
"\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
|
|
||||||
invalidProfileJSON = "{\"dia\":\"1\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," +
|
|
||||||
"{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," +
|
|
||||||
"\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
|
|
||||||
dateUtil = Mockito.spy(DateUtilImpl(context))
|
|
||||||
decimalFormatter = DecimalFormatterImpl(rh)
|
|
||||||
profileUtil = ProfileUtilImpl(sp, decimalFormatter)
|
|
||||||
testPumpPlugin = TestPumpPlugin(profileInjector)
|
|
||||||
Mockito.`when`(dateUtil.now()).thenReturn(now)
|
|
||||||
Mockito.`when`(activePlugin.activePump).thenReturn(testPumpPlugin)
|
|
||||||
Mockito.`when`(sp.getString(info.nightscout.core.utils.R.string.key_units, GlucoseUnit.MGDL.asText)).thenReturn(GlucoseUnit.MGDL.asText)
|
|
||||||
hardLimits = HardLimitsMock(sp, rh)
|
|
||||||
validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!)
|
|
||||||
effectiveProfileSwitch = EffectiveProfileSwitch(
|
|
||||||
timestamp = dateUtil.now(),
|
|
||||||
basalBlocks = validProfile.basalBlocks,
|
|
||||||
isfBlocks = validProfile.isfBlocks,
|
|
||||||
icBlocks = validProfile.icBlocks,
|
|
||||||
targetBlocks = validProfile.targetBlocks,
|
|
||||||
glucoseUnit = EffectiveProfileSwitch.GlucoseUnit.MMOL,
|
|
||||||
originalProfileName = "",
|
|
||||||
originalCustomizedName = "",
|
|
||||||
originalTimeshift = 0,
|
|
||||||
originalPercentage = 100,
|
|
||||||
originalDuration = 0,
|
|
||||||
originalEnd = 0,
|
|
||||||
insulinConfiguration = InsulinConfiguration("", 0, 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
|
||||||
val string = invocation.getArgument<Int>(0)
|
|
||||||
val arg1 = invocation.getArgument<Int?>(1)
|
|
||||||
String.format(rh.gs(string), arg1)
|
|
||||||
}.`when`(rh).gs(anyInt(), anyInt())
|
|
||||||
|
|
||||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
|
||||||
val string = invocation.getArgument<Int>(0)
|
|
||||||
val arg1 = invocation.getArgument<Double?>(1)
|
|
||||||
String.format(rh.gs(string), arg1)
|
|
||||||
}.`when`(rh).gs(anyInt(), anyDouble())
|
|
||||||
|
|
||||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
|
||||||
val string = invocation.getArgument<Int>(0)
|
|
||||||
val arg1 = invocation.getArgument<String?>(1)
|
|
||||||
String.format(rh.gs(string), arg1)
|
|
||||||
}.`when`(rh).gs(anyInt(), anyString())
|
|
||||||
|
|
||||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
|
||||||
val string = invocation.getArgument<Int>(0)
|
|
||||||
val arg1 = invocation.getArgument<String?>(1)
|
|
||||||
val arg2 = invocation.getArgument<String?>(2)
|
|
||||||
String.format(rh.gs(string), arg1, arg2)
|
|
||||||
}.`when`(rh).gs(anyInt(), anyString(), anyString())
|
|
||||||
|
|
||||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
|
||||||
val string = invocation.getArgument<Int>(0)
|
|
||||||
val arg1 = invocation.getArgument<String?>(1)
|
|
||||||
val arg2 = invocation.getArgument<Int?>(2)
|
|
||||||
String.format(rh.gs(string), arg1, arg2)
|
|
||||||
}.`when`(rh).gs(anyInt(), anyString(), anyInt())
|
|
||||||
|
|
||||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
|
||||||
val string = invocation.getArgument<Int>(0)
|
|
||||||
val arg1 = invocation.getArgument<Double?>(1)
|
|
||||||
val arg2 = invocation.getArgument<String?>(2)
|
|
||||||
String.format(rh.gs(string), arg1, arg2)
|
|
||||||
}.`when`(rh).gs(anyInt(), anyDouble(), anyString())
|
|
||||||
|
|
||||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
|
||||||
val string = invocation.getArgument<Int>(0)
|
|
||||||
val arg1 = invocation.getArgument<Double?>(1)
|
|
||||||
val arg2 = invocation.getArgument<Int?>(2)
|
|
||||||
String.format(rh.gs(string), arg1, arg2)
|
|
||||||
}.`when`(rh).gs(anyInt(), anyDouble(), anyInt())
|
|
||||||
|
|
||||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
|
||||||
val string = invocation.getArgument<Int>(0)
|
|
||||||
val arg1 = invocation.getArgument<Int?>(1)
|
|
||||||
val arg2 = invocation.getArgument<Int?>(2)
|
|
||||||
String.format(rh.gs(string), arg1, arg2)
|
|
||||||
}.`when`(rh).gs(anyInt(), anyInt(), anyInt())
|
|
||||||
|
|
||||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
|
||||||
val string = invocation.getArgument<Int>(0)
|
|
||||||
val arg1 = invocation.getArgument<Int?>(1)
|
|
||||||
val arg2 = invocation.getArgument<String?>(2)
|
|
||||||
String.format(rh.gs(string), arg1, arg2)
|
|
||||||
}.`when`(rh).gs(anyInt(), anyInt(), anyString())
|
|
||||||
|
|
||||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
|
||||||
val string = invocation.getArgument<Int>(0)
|
|
||||||
val arg1 = invocation.getArgument<Int?>(1)
|
|
||||||
val arg2 = invocation.getArgument<Int?>(2)
|
|
||||||
val arg3 = invocation.getArgument<String?>(3)
|
|
||||||
String.format(rh.gs(string), arg1, arg2, arg3)
|
|
||||||
}.`when`(rh).gs(anyInt(), anyInt(), anyInt(), anyString())
|
|
||||||
|
|
||||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
|
||||||
val string = invocation.getArgument<Int>(0)
|
|
||||||
val arg1 = invocation.getArgument<Int?>(1)
|
|
||||||
val arg2 = invocation.getArgument<String?>(2)
|
|
||||||
val arg3 = invocation.getArgument<String?>(3)
|
|
||||||
String.format(rh.gs(string), arg1, arg2, arg3)
|
|
||||||
}.`when`(rh).gs(anyInt(), anyInt(), anyString(), anyString())
|
|
||||||
|
|
||||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
|
||||||
val string = invocation.getArgument<Int>(0)
|
|
||||||
val arg1 = invocation.getArgument<Double?>(1)
|
|
||||||
val arg2 = invocation.getArgument<Int?>(2)
|
|
||||||
val arg3 = invocation.getArgument<String?>(3)
|
|
||||||
String.format(rh.gs(string), arg1, arg2, arg3)
|
|
||||||
}.`when`(rh).gs(anyInt(), anyDouble(), anyInt(), anyString())
|
|
||||||
|
|
||||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
|
||||||
val string = invocation.getArgument<Int>(0)
|
|
||||||
val arg1 = invocation.getArgument<String?>(1)
|
|
||||||
val arg2 = invocation.getArgument<Int?>(2)
|
|
||||||
val arg3 = invocation.getArgument<String?>(3)
|
|
||||||
String.format(rh.gs(string), arg1, arg2, arg3)
|
|
||||||
}.`when`(rh).gs(anyInt(), anyString(), anyInt(), anyString())
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getValidProfileStore(): ProfileStore {
|
|
||||||
val json = JSONObject()
|
|
||||||
val store = JSONObject()
|
|
||||||
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
|
|
||||||
json.put("defaultProfile", TESTPROFILENAME)
|
|
||||||
json.put("store", store)
|
|
||||||
return ProfileStoreObject(profileInjector, json, dateUtil)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getInvalidProfileStore1(): ProfileStore {
|
|
||||||
val json = JSONObject()
|
|
||||||
val store = JSONObject()
|
|
||||||
store.put(TESTPROFILENAME, JSONObject(invalidProfileJSON))
|
|
||||||
json.put("defaultProfile", TESTPROFILENAME)
|
|
||||||
json.put("store", store)
|
|
||||||
return ProfileStoreObject(profileInjector, json, dateUtil)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getInvalidProfileStore2(): ProfileStore {
|
|
||||||
val json = JSONObject()
|
|
||||||
val store = JSONObject()
|
|
||||||
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
|
|
||||||
store.put("invalid", JSONObject(invalidProfileJSON))
|
|
||||||
json.put("defaultProfile", TESTPROFILENAME + "invalid")
|
|
||||||
json.put("store", store)
|
|
||||||
return ProfileStoreObject(profileInjector, json, dateUtil)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,80 +0,0 @@
|
||||||
package info.nightscout.sharedtests
|
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector
|
|
||||||
import info.nightscout.annotations.OpenForTesting
|
|
||||||
import info.nightscout.interfaces.profile.Profile
|
|
||||||
import info.nightscout.interfaces.pump.DetailedBolusInfo
|
|
||||||
import info.nightscout.interfaces.pump.Pump
|
|
||||||
import info.nightscout.interfaces.pump.PumpEnactResult
|
|
||||||
import info.nightscout.interfaces.pump.PumpSync
|
|
||||||
import info.nightscout.interfaces.pump.defs.ManufacturerType
|
|
||||||
import info.nightscout.interfaces.pump.defs.PumpDescription
|
|
||||||
import info.nightscout.interfaces.pump.defs.PumpType
|
|
||||||
import info.nightscout.interfaces.utils.TimeChangeType
|
|
||||||
import org.json.JSONObject
|
|
||||||
|
|
||||||
@Suppress("MemberVisibilityCanBePrivate")
|
|
||||||
@OpenForTesting
|
|
||||||
class TestPumpPlugin(val injector: HasAndroidInjector) : Pump {
|
|
||||||
|
|
||||||
var connected = false
|
|
||||||
var isProfileSet = true
|
|
||||||
var pumpSuspended = false
|
|
||||||
|
|
||||||
override fun isConnected() = connected
|
|
||||||
override fun isConnecting() = false
|
|
||||||
override fun isHandshakeInProgress() = false
|
|
||||||
val lastData = 0L
|
|
||||||
|
|
||||||
val baseBasal = 0.0
|
|
||||||
override var pumpDescription = PumpDescription()
|
|
||||||
|
|
||||||
override fun isInitialized(): Boolean = true
|
|
||||||
override fun isSuspended(): Boolean = pumpSuspended
|
|
||||||
override fun isBusy(): Boolean = false
|
|
||||||
override fun connect(reason: String) {
|
|
||||||
connected = true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun disconnect(reason: String) {
|
|
||||||
connected = false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun stopConnecting() {
|
|
||||||
connected = false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun waitForDisconnectionInSeconds(): Int = 0
|
|
||||||
override fun getPumpStatus(reason: String) { /* not needed */
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setNewBasalProfile(profile: Profile): PumpEnactResult = PumpEnactResult(injector)
|
|
||||||
override fun isThisProfileSet(profile: Profile): Boolean = isProfileSet
|
|
||||||
override fun lastDataTime(): Long = lastData
|
|
||||||
override val baseBasalRate: Double get() = baseBasal
|
|
||||||
override val reservoirLevel: Double = 0.0
|
|
||||||
override val batteryLevel: Int = 0
|
|
||||||
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult = PumpEnactResult(injector).success(true)
|
|
||||||
override fun stopBolusDelivering() { /* not needed */
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult =
|
|
||||||
PumpEnactResult(injector).success(true)
|
|
||||||
|
|
||||||
override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult =
|
|
||||||
PumpEnactResult(injector).success(true)
|
|
||||||
|
|
||||||
override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult = PumpEnactResult(injector).success(true)
|
|
||||||
override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult = PumpEnactResult(injector).success(true)
|
|
||||||
override fun cancelExtendedBolus(): PumpEnactResult = PumpEnactResult(injector).success(true)
|
|
||||||
override fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject = JSONObject()
|
|
||||||
override fun manufacturer(): ManufacturerType = ManufacturerType.AAPS
|
|
||||||
override fun model(): PumpType = PumpType.GENERIC_AAPS
|
|
||||||
override fun serialNumber(): String = "1"
|
|
||||||
override fun shortStatus(veryShort: Boolean): String = "Virtual Pump"
|
|
||||||
override val isFakingTempsByExtendedBoluses: Boolean = false
|
|
||||||
override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector).success(true)
|
|
||||||
override fun canHandleDST(): Boolean = true
|
|
||||||
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) { /* not needed */
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package info.nightscout.sharedtests.rx
|
|
||||||
|
|
||||||
import info.nightscout.rx.AapsSchedulers
|
|
||||||
import io.reactivex.rxjava3.core.Scheduler
|
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by adrian on 12.04.20.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class TestAapsSchedulers : AapsSchedulers {
|
|
||||||
|
|
||||||
override val main: Scheduler = Schedulers.trampoline()
|
|
||||||
override val io: Scheduler = Schedulers.trampoline()
|
|
||||||
override val cpu: Scheduler = Schedulers.trampoline()
|
|
||||||
override val newThread: Scheduler = Schedulers.trampoline()
|
|
||||||
}
|
|
|
@ -181,7 +181,7 @@ dependencies {
|
||||||
// in order to use internet's versions you'd need to enable Jetifier again
|
// in order to use internet's versions you'd need to enable Jetifier again
|
||||||
// https://github.com/nightscout/graphview.git
|
// https://github.com/nightscout/graphview.git
|
||||||
// https://github.com/nightscout/iconify.git
|
// https://github.com/nightscout/iconify.git
|
||||||
implementation project(':app-wear-shared:shared-impl')
|
implementation project(':shared:impl')
|
||||||
implementation project(':core:main')
|
implementation project(':core:main')
|
||||||
implementation project(':core:graphview')
|
implementation project(':core:graphview')
|
||||||
implementation project(':core:interfaces')
|
implementation project(':core:interfaces')
|
||||||
|
@ -222,7 +222,7 @@ dependencies {
|
||||||
implementation project(':pump:virtual')
|
implementation project(':pump:virtual')
|
||||||
implementation project(':workflow')
|
implementation project(':workflow')
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
|
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package info.nightscout.androidaps.di
|
package info.nightscout.androidaps.di
|
||||||
|
|
||||||
|
import app.aaps.shared.impl.di.SharedImplModule
|
||||||
import dagger.BindsInstance
|
import dagger.BindsInstance
|
||||||
import dagger.Component
|
import dagger.Component
|
||||||
import dagger.android.AndroidInjectionModule
|
import dagger.android.AndroidInjectionModule
|
||||||
|
@ -34,7 +35,6 @@ import info.nightscout.pump.danars.di.DanaRSModule
|
||||||
import info.nightscout.pump.diaconn.di.DiaconnG8Module
|
import info.nightscout.pump.diaconn.di.DiaconnG8Module
|
||||||
import info.nightscout.pump.medtrum.di.MedtrumModule
|
import info.nightscout.pump.medtrum.di.MedtrumModule
|
||||||
import info.nightscout.pump.virtual.di.VirtualPumpModule
|
import info.nightscout.pump.virtual.di.VirtualPumpModule
|
||||||
import info.nightscout.shared.impl.di.SharedImplModule
|
|
||||||
import info.nightscout.source.di.SourceModule
|
import info.nightscout.source.di.SourceModule
|
||||||
import info.nightscout.ui.di.UiModule
|
import info.nightscout.ui.di.UiModule
|
||||||
import info.nightscout.workflow.di.WorkflowModule
|
import info.nightscout.workflow.di.WorkflowModule
|
||||||
|
|
|
@ -19,8 +19,8 @@ dependencies {
|
||||||
implementation project(':core:ui')
|
implementation project(':core:ui')
|
||||||
implementation project(':core:utils')
|
implementation project(':core:utils')
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
testImplementation project(':app-wear-shared:shared-impl')
|
testImplementation project(':shared:impl')
|
||||||
|
|
||||||
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.core.data
|
package info.nightscout.core.data
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import app.aaps.shared.impl.utils.DateUtilImpl
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import info.nightscout.core.iob.combine
|
import info.nightscout.core.iob.combine
|
||||||
import info.nightscout.core.iob.copy
|
import info.nightscout.core.iob.copy
|
||||||
|
@ -10,7 +11,6 @@ import info.nightscout.core.iob.plus
|
||||||
import info.nightscout.core.iob.round
|
import info.nightscout.core.iob.round
|
||||||
import info.nightscout.interfaces.iob.IobTotal
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.DateUtilImpl
|
|
||||||
import info.nightscout.sharedtests.TestBase
|
import info.nightscout.sharedtests.TestBase
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.core.data
|
package info.nightscout.core.data
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import app.aaps.shared.impl.utils.DateUtilImpl
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import info.nightscout.core.extensions.pureProfileFromJson
|
import info.nightscout.core.extensions.pureProfileFromJson
|
||||||
|
@ -11,7 +12,6 @@ import info.nightscout.interfaces.utils.HardLimits
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.DateUtilImpl
|
|
||||||
import info.nightscout.sharedtests.HardLimitsMock
|
import info.nightscout.sharedtests.HardLimitsMock
|
||||||
import info.nightscout.sharedtests.TestBase
|
import info.nightscout.sharedtests.TestBase
|
||||||
import info.nightscout.sharedtests.TestPumpPlugin
|
import info.nightscout.sharedtests.TestPumpPlugin
|
||||||
|
@ -90,7 +90,7 @@ class ProfileTest : TestBase() {
|
||||||
"""
|
"""
|
||||||
00:00 6,0 mmol/U
|
00:00 6,0 mmol/U
|
||||||
02:00 6,2 mmol/U
|
02:00 6,2 mmol/U
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
assertThat(p.getIc(c.timeInMillis)).isWithin(0.01).of(30.0)
|
assertThat(p.getIc(c.timeInMillis)).isWithin(0.01).of(30.0)
|
||||||
assertThat(p.getIcTimeFromMidnight(2 * 60 * 60)).isWithin(0.01).of(30.0)
|
assertThat(p.getIcTimeFromMidnight(2 * 60 * 60)).isWithin(0.01).of(30.0)
|
||||||
|
@ -103,9 +103,9 @@ class ProfileTest : TestBase() {
|
||||||
assertThat(p.percentageBasalSum()).isWithin(0.01).of(2.4)
|
assertThat(p.percentageBasalSum()).isWithin(0.01).of(2.4)
|
||||||
assertThat(p.baseBasalSum()).isWithin(0.01).of(2.4)
|
assertThat(p.baseBasalSum()).isWithin(0.01).of(2.4)
|
||||||
// assertThat( p.getTargetMgdl(2 * 60 * 60)).isWithin(0.01).of(81.0)
|
// assertThat( p.getTargetMgdl(2 * 60 * 60)).isWithin(0.01).of(81.0)
|
||||||
assertThat( p.getTargetLowMgdl(c.timeInMillis)).isWithin(0.01).of(90.0)
|
assertThat(p.getTargetLowMgdl(c.timeInMillis)).isWithin(0.01).of(90.0)
|
||||||
// assertThat( p.getTargetLowTimeFromMidnight(2 * 60 * 60)).isWithin(0.01).of(4.0)
|
// assertThat( p.getTargetLowTimeFromMidnight(2 * 60 * 60)).isWithin(0.01).of(4.0)
|
||||||
assertThat( p.getTargetHighMgdl(c.timeInMillis)).isWithin(0.01).of(90.0)
|
assertThat(p.getTargetHighMgdl(c.timeInMillis)).isWithin(0.01).of(90.0)
|
||||||
// assertThat( p.getTargetHighTimeFromMidnight(2 * 60 * 60)).isWithin(0.01).of(5.0)
|
// assertThat( p.getTargetHighTimeFromMidnight(2 * 60 * 60)).isWithin(0.01).of(5.0)
|
||||||
assertThat(p.getTargetList(rh, dateUtil).replace(".", ",")).isEqualTo("00:00 5,0 - 5,0 mmol")
|
assertThat(p.getTargetList(rh, dateUtil).replace(".", ",")).isEqualTo("00:00 5,0 - 5,0 mmol")
|
||||||
assertThat(p.percentage).isEqualTo(100)
|
assertThat(p.percentage).isEqualTo(100)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package info.nightscout.core.utils
|
package info.nightscout.core.utils
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import app.aaps.shared.impl.utils.DateUtilImpl
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.utils.DateUtilImpl
|
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
import info.nightscout.sharedtests.TestBase
|
import info.nightscout.sharedtests.TestBase
|
||||||
import org.junit.jupiter.api.AfterAll
|
import org.junit.jupiter.api.AfterAll
|
||||||
|
|
|
@ -17,6 +17,6 @@ android {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(':core:interfaces')
|
implementation project(':core:interfaces')
|
||||||
implementation project(':app-wear-shared:shared-impl')
|
implementation project(':shared:impl')
|
||||||
api "com.google.android.material:material:$material_version"
|
api "com.google.android.material:material:$material_version"
|
||||||
}
|
}
|
|
@ -23,7 +23,7 @@ dependencies {
|
||||||
implementation project(':core:ui')
|
implementation project(':core:ui')
|
||||||
implementation project(':core:utils')
|
implementation project(':core:utils')
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
|
|
||||||
// Protection
|
// Protection
|
||||||
api 'androidx.biometric:biometric:1.1.0'
|
api 'androidx.biometric:biometric:1.1.0'
|
||||||
|
|
|
@ -24,7 +24,7 @@ dependencies {
|
||||||
implementation project(':core:ui')
|
implementation project(':core:ui')
|
||||||
implementation project(':core:validators')
|
implementation project(':core:validators')
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
|
|
||||||
api "androidx.appcompat:appcompat:$appcompat_version"
|
api "androidx.appcompat:appcompat:$appcompat_version"
|
||||||
api "androidx.swiperefreshlayout:swiperefreshlayout:$swipe_version"
|
api "androidx.swiperefreshlayout:swiperefreshlayout:$swipe_version"
|
||||||
|
|
|
@ -25,8 +25,8 @@ dependencies {
|
||||||
implementation project(':database:entities')
|
implementation project(':database:entities')
|
||||||
implementation project(':database:impl')
|
implementation project(':database:impl')
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
testImplementation project(':app-wear-shared:shared-impl')
|
testImplementation project(':shared:impl')
|
||||||
testImplementation project(':implementation')
|
testImplementation project(':implementation')
|
||||||
testImplementation project(':plugins:main')
|
testImplementation project(':plugins:main')
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.automation
|
package info.nightscout.automation
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import app.aaps.shared.impl.utils.DateUtilImpl
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.automation.services.LocationServiceHelper
|
import info.nightscout.automation.services.LocationServiceHelper
|
||||||
|
@ -16,7 +17,6 @@ import info.nightscout.interfaces.profile.ProfileFunction
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.DateUtilImpl
|
|
||||||
import info.nightscout.sharedtests.TestBase
|
import info.nightscout.sharedtests.TestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.automation
|
package info.nightscout.automation
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import app.aaps.shared.impl.utils.DateUtilImpl
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.automation.services.LocationServiceHelper
|
import info.nightscout.automation.services.LocationServiceHelper
|
||||||
|
@ -16,7 +17,6 @@ import info.nightscout.interfaces.profile.ProfileFunction
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.DateUtilImpl
|
|
||||||
import info.nightscout.sharedtests.TestBase
|
import info.nightscout.sharedtests.TestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
|
|
@ -25,7 +25,7 @@ dependencies {
|
||||||
implementation project(':core:ui')
|
implementation project(':core:ui')
|
||||||
implementation project(':core:validators')
|
implementation project(':core:validators')
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
|
|
||||||
//WorkManager
|
//WorkManager
|
||||||
api "androidx.work:work-runtime-ktx:$work_version"
|
api "androidx.work:work-runtime-ktx:$work_version"
|
||||||
|
|
|
@ -23,7 +23,7 @@ dependencies {
|
||||||
implementation project(':core:validators')
|
implementation project(':core:validators')
|
||||||
implementation project(':database:entities')
|
implementation project(':database:entities')
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
|
|
||||||
// Phone checker
|
// Phone checker
|
||||||
api 'com.scottyab:rootbeer-lib:0.1.0'
|
api 'com.scottyab:rootbeer-lib:0.1.0'
|
||||||
|
|
|
@ -24,6 +24,6 @@ dependencies {
|
||||||
implementation project(':core:validators')
|
implementation project(':core:validators')
|
||||||
implementation project(':database:entities')
|
implementation project(':database:entities')
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
testImplementation project(':core:main')
|
testImplementation project(':core:main')
|
||||||
}
|
}
|
|
@ -15,7 +15,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(':app-wear-shared:shared-impl')
|
implementation project(':shared:impl')
|
||||||
implementation project(':database:entities')
|
implementation project(':database:entities')
|
||||||
implementation project(':database:impl')
|
implementation project(':database:impl')
|
||||||
implementation project(':core:graphview')
|
implementation project(':core:graphview')
|
||||||
|
@ -28,7 +28,7 @@ dependencies {
|
||||||
|
|
||||||
testImplementation project(':implementation')
|
testImplementation project(':implementation')
|
||||||
testImplementation project(':plugins:insulin')
|
testImplementation project(':plugins:insulin')
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
|
|
||||||
api "androidx.appcompat:appcompat:$appcompat_version"
|
api "androidx.appcompat:appcompat:$appcompat_version"
|
||||||
api "com.google.android.material:material:$material_version"
|
api "com.google.android.material:material:$material_version"
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import androidx.preference.SwitchPreference
|
import androidx.preference.SwitchPreference
|
||||||
|
import app.aaps.shared.impl.rx.bus.RxBusImpl
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.core.events.EventIobCalculationProgress
|
import info.nightscout.core.events.EventIobCalculationProgress
|
||||||
import info.nightscout.core.events.EventNewNotification
|
import info.nightscout.core.events.EventNewNotification
|
||||||
|
@ -34,7 +35,6 @@ import info.nightscout.rx.events.EventNewHistoryData
|
||||||
import info.nightscout.rx.events.EventPumpStatusChanged
|
import info.nightscout.rx.events.EventPumpStatusChanged
|
||||||
import info.nightscout.rx.events.EventUpdateOverviewCalcProgress
|
import info.nightscout.rx.events.EventUpdateOverviewCalcProgress
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.shared.impl.rx.bus.RxBusImpl
|
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.plugins.iob
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.collection.LongSparseArray
|
import androidx.collection.LongSparseArray
|
||||||
|
import app.aaps.shared.impl.utils.DateUtilImpl
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.database.entities.GlucoseValue
|
import info.nightscout.database.entities.GlucoseValue
|
||||||
|
@ -12,7 +13,6 @@ import info.nightscout.plugins.iob.iobCobCalculator.data.AutosensDataStoreObject
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.DateUtilImpl
|
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
import info.nightscout.sharedtests.TestBase
|
import info.nightscout.sharedtests.TestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
|
|
|
@ -16,7 +16,7 @@ android {
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(':app-wear-shared:shared-impl')
|
implementation project(':shared:impl')
|
||||||
implementation project(':database:entities')
|
implementation project(':database:entities')
|
||||||
implementation project(':database:impl')
|
implementation project(':database:impl')
|
||||||
implementation project(':core:interfaces')
|
implementation project(':core:interfaces')
|
||||||
|
@ -25,5 +25,5 @@ dependencies {
|
||||||
implementation project(':core:ui')
|
implementation project(':core:ui')
|
||||||
implementation project(':core:utils')
|
implementation project(':core:utils')
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
}
|
}
|
|
@ -6,6 +6,7 @@ import android.content.pm.PackageManager
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.work.WorkerParameters
|
import androidx.work.WorkerParameters
|
||||||
import androidx.work.workDataOf
|
import androidx.work.workDataOf
|
||||||
|
import app.aaps.shared.impl.extensions.safeGetInstalledPackages
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.core.extensions.fromConstant
|
import info.nightscout.core.extensions.fromConstant
|
||||||
import info.nightscout.core.utils.receivers.DataWorkerStorage
|
import info.nightscout.core.utils.receivers.DataWorkerStorage
|
||||||
|
@ -28,7 +29,6 @@ import info.nightscout.interfaces.source.BgSource
|
||||||
import info.nightscout.interfaces.source.DexcomBoyda
|
import info.nightscout.interfaces.source.DexcomBoyda
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
import info.nightscout.shared.extensions.safeGetInstalledPackages
|
|
||||||
import info.nightscout.shared.interfaces.ProfileUtil
|
import info.nightscout.shared.interfaces.ProfileUtil
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
|
|
|
@ -6,6 +6,7 @@ import android.net.Uri
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.HandlerThread
|
import android.os.HandlerThread
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import app.aaps.shared.impl.extensions.safeGetInstalledPackages
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.core.utils.fabric.FabricPrivacy
|
import info.nightscout.core.utils.fabric.FabricPrivacy
|
||||||
import info.nightscout.database.entities.GlucoseValue
|
import info.nightscout.database.entities.GlucoseValue
|
||||||
|
@ -23,7 +24,6 @@ import info.nightscout.interfaces.plugin.PluginType
|
||||||
import info.nightscout.interfaces.source.BgSource
|
import info.nightscout.interfaces.source.BgSource
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
import info.nightscout.shared.extensions.safeGetInstalledPackages
|
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
|
|
|
@ -15,7 +15,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(':app-wear-shared:shared-impl')
|
implementation project(':shared:impl')
|
||||||
implementation project(':database:entities')
|
implementation project(':database:entities')
|
||||||
implementation project(':database:impl')
|
implementation project(':database:impl')
|
||||||
implementation project(':core:main')
|
implementation project(':core:main')
|
||||||
|
@ -28,7 +28,7 @@ dependencies {
|
||||||
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version"
|
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version"
|
||||||
testImplementation "androidx.work:work-testing:$work_version"
|
testImplementation "androidx.work:work-testing:$work_version"
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
testImplementation project(':implementation')
|
testImplementation project(':implementation')
|
||||||
testImplementation project(':plugins:aps')
|
testImplementation project(':plugins:aps')
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.ResolveInfo
|
import android.content.pm.ResolveInfo
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import app.aaps.shared.impl.extensions.safeQueryBroadcastReceivers
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.core.extensions.durationInMinutes
|
import info.nightscout.core.extensions.durationInMinutes
|
||||||
import info.nightscout.core.extensions.toStringFull
|
import info.nightscout.core.extensions.toStringFull
|
||||||
|
@ -32,7 +33,6 @@ import info.nightscout.rx.events.EventLoopUpdateGui
|
||||||
import info.nightscout.rx.events.EventOverviewBolusProgress
|
import info.nightscout.rx.events.EventOverviewBolusProgress
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
import info.nightscout.shared.extensions.safeQueryBroadcastReceivers
|
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||||
|
|
|
@ -10,6 +10,7 @@ import androidx.work.ExistingWorkPolicy
|
||||||
import androidx.work.OneTimeWorkRequest
|
import androidx.work.OneTimeWorkRequest
|
||||||
import androidx.work.WorkInfo
|
import androidx.work.WorkInfo
|
||||||
import androidx.work.WorkManager
|
import androidx.work.WorkManager
|
||||||
|
import app.aaps.shared.impl.extensions.safeQueryBroadcastReceivers
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.core.extensions.toStringShort
|
import info.nightscout.core.extensions.toStringShort
|
||||||
import info.nightscout.core.iob.generateCOBString
|
import info.nightscout.core.iob.generateCOBString
|
||||||
|
@ -47,7 +48,6 @@ import info.nightscout.rx.events.EventNewHistoryData
|
||||||
import info.nightscout.rx.events.EventXdripNewLog
|
import info.nightscout.rx.events.EventXdripNewLog
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
import info.nightscout.shared.extensions.safeQueryBroadcastReceivers
|
|
||||||
import info.nightscout.shared.interfaces.ProfileUtil
|
import info.nightscout.shared.interfaces.ProfileUtil
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
|
|
|
@ -25,7 +25,7 @@ dependencies {
|
||||||
implementation project(':core:ui')
|
implementation project(':core:ui')
|
||||||
implementation project(':core:utils')
|
implementation project(':core:utils')
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
|
|
||||||
// RuffyScripter
|
// RuffyScripter
|
||||||
api "com.google.guava:guava:$guava_version"
|
api "com.google.guava:guava:$guava_version"
|
||||||
|
|
|
@ -36,6 +36,6 @@ dependencies {
|
||||||
api "androidx.room:room-rxjava3:$room_version"
|
api "androidx.room:room-rxjava3:$room_version"
|
||||||
kapt "androidx.room:room-compiler:$room_version"
|
kapt "androidx.room:room-compiler:$room_version"
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
testImplementation project(':core:main') // create profile from json
|
testImplementation project(':core:main') // create profile from json
|
||||||
}
|
}
|
|
@ -24,6 +24,6 @@ dependencies {
|
||||||
|
|
||||||
api 'androidx.media3:media3-common:1.1.1'
|
api 'androidx.media3:media3-common:1.1.1'
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
testImplementation project(':core:main')
|
testImplementation project(':core:main')
|
||||||
}
|
}
|
|
@ -37,6 +37,6 @@ dependencies {
|
||||||
implementation project(':core:validators')
|
implementation project(':core:validators')
|
||||||
implementation project(':pump:dana')
|
implementation project(':pump:dana')
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
testImplementation project(':core:main')
|
testImplementation project(':core:main')
|
||||||
}
|
}
|
|
@ -25,7 +25,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(':app-wear-shared:shared-impl')
|
implementation project(':shared:impl')
|
||||||
implementation project(':core:libraries')
|
implementation project(':core:libraries')
|
||||||
implementation project(':core:interfaces')
|
implementation project(':core:interfaces')
|
||||||
implementation project(':core:main')
|
implementation project(':core:main')
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.pump.diaconn.packet
|
package info.nightscout.pump.diaconn.packet
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import app.aaps.shared.impl.extensions.safeGetPackageInfo
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||||
import info.nightscout.interfaces.pump.DetailedBolusInfo
|
import info.nightscout.interfaces.pump.DetailedBolusInfo
|
||||||
|
@ -48,7 +49,6 @@ import info.nightscout.pump.diaconn.pumplog.PumpLogUtil
|
||||||
import info.nightscout.rx.bus.RxBus
|
import info.nightscout.rx.bus.RxBus
|
||||||
import info.nightscout.rx.events.EventPumpStatusChanged
|
import info.nightscout.rx.events.EventPumpStatusChanged
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
import info.nightscout.shared.extensions.safeGetPackageInfo
|
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
|
@ -151,7 +151,7 @@ class BigLogInquireResponsePacket(
|
||||||
|
|
||||||
when (pumpLogKind) {
|
when (pumpLogKind) {
|
||||||
|
|
||||||
LogInjectMealSuccess.LOG_KIND -> {
|
LogInjectMealSuccess.LOG_KIND -> {
|
||||||
val logItem = LogInjectMealSuccess.parse(logDataToHexString)
|
val logItem = LogInjectMealSuccess.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -186,7 +186,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "MEAL_BOLUS_SUCCESS" + dateUtil.timeString(logDateTime)
|
status = "MEAL_BOLUS_SUCCESS" + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogInjectMealFail.LOG_KIND -> {
|
LogInjectMealFail.LOG_KIND -> {
|
||||||
val logItem = LogInjectMealFail.parse(logDataToHexString)
|
val logItem = LogInjectMealFail.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -221,7 +221,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "MEAL_BOLUS_FAIL " + dateUtil.timeString(logDateTime)
|
status = "MEAL_BOLUS_FAIL " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogInjectNormalSuccess.LOG_KIND -> {
|
LogInjectNormalSuccess.LOG_KIND -> {
|
||||||
val logItem = LogInjectNormalSuccess.parse(logDataToHexString)
|
val logItem = LogInjectNormalSuccess.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "BOLUS_SUCCESS" + dateUtil.timeString(logDateTime)
|
status = "BOLUS_SUCCESS" + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogInjectNormalFail.LOG_KIND -> {
|
LogInjectNormalFail.LOG_KIND -> {
|
||||||
val logItem = LogInjectNormalFail.parse(logDataToHexString)
|
val logItem = LogInjectNormalFail.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -295,7 +295,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "BOLUS_FAIL " + dateUtil.timeString(logDateTime)
|
status = "BOLUS_FAIL " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogSetSquareInjection.LOG_KIND -> {
|
LogSetSquareInjection.LOG_KIND -> {
|
||||||
val logItem = LogSetSquareInjection.parse(logDataToHexString)
|
val logItem = LogSetSquareInjection.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -326,7 +326,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "EXTENDED_BOLUS_START " + dateUtil.timeString(logDateTime)
|
status = "EXTENDED_BOLUS_START " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogInjectSquareSuccess.LOG_KIND -> {
|
LogInjectSquareSuccess.LOG_KIND -> {
|
||||||
val logItem = LogInjectSquareSuccess.parse(logDataToHexString)
|
val logItem = LogInjectSquareSuccess.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -343,7 +343,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "EXTENDED_BOLUS_END " + dateUtil.timeString(logDateTime)
|
status = "EXTENDED_BOLUS_END " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogInjectSquareFail.LOG_KIND -> {
|
LogInjectSquareFail.LOG_KIND -> {
|
||||||
val logItem = LogInjectSquareFail.parse(logDataToHexString)
|
val logItem = LogInjectSquareFail.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -371,7 +371,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "EXTENDED_BOLUS_FAIL " + dateUtil.timeString(logDateTime)
|
status = "EXTENDED_BOLUS_FAIL " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogSetDualInjection.LOG_KIND -> {
|
LogSetDualInjection.LOG_KIND -> {
|
||||||
val logItem = LogSetDualInjection.parse(logDataToHexString)
|
val logItem = LogSetDualInjection.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -405,7 +405,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "DUAL_EXTENDED_START " + dateUtil.timeString(logDateTime)
|
status = "DUAL_EXTENDED_START " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogInjectionDualNormal.LOG_KIND -> {
|
LogInjectionDualNormal.LOG_KIND -> {
|
||||||
val logItem = LogInjectionDualNormal.parse(logDataToHexString)
|
val logItem = LogInjectionDualNormal.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -445,7 +445,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "DUAL_BOLUS" + dateUtil.timeString(logDateTime)
|
status = "DUAL_BOLUS" + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogInjectDualSuccess.LOG_KIND -> {
|
LogInjectDualSuccess.LOG_KIND -> {
|
||||||
val logItem = LogInjectDualSuccess.parse(logDataToHexString)
|
val logItem = LogInjectDualSuccess.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -464,7 +464,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "DUAL_BOLUS_SQUARE_SUCCESS " + dateUtil.timeString(logDateTime)
|
status = "DUAL_BOLUS_SQUARE_SUCCESS " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogInjectDualFail.LOG_KIND -> {
|
LogInjectDualFail.LOG_KIND -> {
|
||||||
val logItem = LogInjectDualFail.parse(logDataToHexString)
|
val logItem = LogInjectDualFail.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -493,7 +493,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "DUAL_BOLUS FAIL " + dateUtil.timeString(logDateTime)
|
status = "DUAL_BOLUS FAIL " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogInjection1HourBasal.LOG_KIND -> {
|
LogInjection1HourBasal.LOG_KIND -> {
|
||||||
val logItem = LogInjection1HourBasal.parse(logDataToHexString)
|
val logItem = LogInjection1HourBasal.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -509,7 +509,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "1HOUR BASAL " + dateUtil.dateAndTimeString(logDateTime)
|
status = "1HOUR BASAL " + dateUtil.dateAndTimeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogSuspendV2.LOG_KIND -> {
|
LogSuspendV2.LOG_KIND -> {
|
||||||
val logItem = LogSuspendV2.parse(logDataToHexString)
|
val logItem = LogSuspendV2.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -524,7 +524,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "SUSPEND " + dateUtil.timeString(logDateTime)
|
status = "SUSPEND " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogSuspendReleaseV2.LOG_KIND -> {
|
LogSuspendReleaseV2.LOG_KIND -> {
|
||||||
val logItem = LogSuspendReleaseV2.parse(logDataToHexString)
|
val logItem = LogSuspendReleaseV2.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -568,7 +568,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "INSULIN_CHANGE " + dateUtil.timeString(logDateTime)
|
status = "INSULIN_CHANGE " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogChangeTubeSuccess.LOG_KIND -> {
|
LogChangeTubeSuccess.LOG_KIND -> {
|
||||||
val logItem = LogChangeTubeSuccess.parse(logDataToHexString)
|
val logItem = LogChangeTubeSuccess.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -600,7 +600,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "TUBE_CHANGE " + dateUtil.timeString(logDateTime)
|
status = "TUBE_CHANGE " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogInjection1Day.LOG_KIND -> { // Daily Bolus Log
|
LogInjection1Day.LOG_KIND -> { // Daily Bolus Log
|
||||||
val logItem = LogInjection1Day.parse(logDataToHexString)
|
val logItem = LogInjection1Day.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -649,7 +649,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "DAILY_BOLUS " + dateUtil.timeString(logDateTime)
|
status = "DAILY_BOLUS " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogInjection1DayBasal.LOG_KIND -> { // Daily Basal Log
|
LogInjection1DayBasal.LOG_KIND -> { // Daily Basal Log
|
||||||
val logItem = LogInjection1DayBasal.parse(logDataToHexString)
|
val logItem = LogInjection1DayBasal.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -698,7 +698,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "DAILY_BASAL " + dateUtil.timeString(logDateTime)
|
status = "DAILY_BASAL " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogChangeNeedleSuccess.LOG_KIND -> {
|
LogChangeNeedleSuccess.LOG_KIND -> {
|
||||||
val logItem = LogChangeNeedleSuccess.parse(logDataToHexString)
|
val logItem = LogChangeNeedleSuccess.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -728,7 +728,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "NEEDLE_CHANGE " + dateUtil.timeString(logDateTime)
|
status = "NEEDLE_CHANGE " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogTbStartV3.LOG_KIND -> {
|
LogTbStartV3.LOG_KIND -> {
|
||||||
val logItem = LogTbStartV3.parse(logDataToHexString)
|
val logItem = LogTbStartV3.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
|
|
||||||
|
@ -772,7 +772,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "TEMP_START " + dateUtil.timeString(logDateTime)
|
status = "TEMP_START " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogTbStopV3.LOG_KIND -> {
|
LogTbStopV3.LOG_KIND -> {
|
||||||
val logItem = LogTbStopV3.parse(logDataToHexString)
|
val logItem = LogTbStopV3.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -806,7 +806,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "TEMP_STOP " + dateUtil.timeString(logDateTime)
|
status = "TEMP_STOP " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogAlarmBattery.LOG_KIND -> { // BATTERY SHORTAGE ALARM
|
LogAlarmBattery.LOG_KIND -> { // BATTERY SHORTAGE ALARM
|
||||||
val logItem = LogAlarmBattery.parse(logDataToHexString)
|
val logItem = LogAlarmBattery.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ -822,7 +822,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "BATTERY_ALARM " + dateUtil.timeString(logDateTime)
|
status = "BATTERY_ALARM " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogAlarmBlock.LOG_KIND -> { // INJECTION BLOCKED ALARM
|
LogAlarmBlock.LOG_KIND -> { // INJECTION BLOCKED ALARM
|
||||||
val logItem = LogAlarmBlock.parse(logDataToHexString)
|
val logItem = LogAlarmBlock.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
|
|
||||||
|
@ -840,7 +840,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "BLOCK_ALARM " + dateUtil.timeString(logDateTime)
|
status = "BLOCK_ALARM " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogAlarmShortAge.LOG_KIND -> { // INSULIN SHORTAGE ALARM
|
LogAlarmShortAge.LOG_KIND -> { // INSULIN SHORTAGE ALARM
|
||||||
val logItem = LogAlarmShortAge.parse(logDataToHexString)
|
val logItem = LogAlarmShortAge.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
|
|
||||||
|
@ -858,7 +858,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "SHORT_AGE_ALARM " + dateUtil.timeString(logDateTime)
|
status = "SHORT_AGE_ALARM " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
LogResetSysV3.LOG_KIND -> {
|
LogResetSysV3.LOG_KIND -> {
|
||||||
val logItem = LogResetSysV3.parse(logDataToHexString)
|
val logItem = LogResetSysV3.parse(logDataToHexString)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
aapsLogger.debug(LTag.PUMPCOMM, "$logItem ")
|
||||||
|
|
||||||
|
@ -887,7 +887,7 @@ class BigLogInquireResponsePacket(
|
||||||
status = "RESET " + dateUtil.timeString(logDateTime)
|
status = "RESET " + dateUtil.timeString(logDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
status = rh.gs(R.string.diaconn_g8_logsyncinprogress)
|
status = rh.gs(R.string.diaconn_g8_logsyncinprogress)
|
||||||
rxBus.send(EventPumpStatusChanged(status))
|
rxBus.send(EventPumpStatusChanged(status))
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -24,6 +24,6 @@ dependencies {
|
||||||
implementation project(':pump:pump-common')
|
implementation project(':pump:pump-common')
|
||||||
implementation project(':pump:rileylink')
|
implementation project(':pump:rileylink')
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
testImplementation project(':database:impl')
|
testImplementation project(':database:impl')
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,6 @@ dependencies {
|
||||||
implementation project(':core:validators')
|
implementation project(':core:validators')
|
||||||
implementation project(':pump:pump-common')
|
implementation project(':pump:pump-common')
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
testImplementation project(':core:main')
|
testImplementation project(':core:main')
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,8 @@ dependencies {
|
||||||
api "androidx.room:room-rxjava3:$room_version"
|
api "androidx.room:room-rxjava3:$room_version"
|
||||||
kapt "androidx.room:room-compiler:$room_version"
|
kapt "androidx.room:room-compiler:$room_version"
|
||||||
|
|
||||||
androidTestImplementation project(':app-wear-shared:shared-tests')
|
androidTestImplementation project(':shared:tests')
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
testImplementation "commons-codec:commons-codec:$commonscodec_version"
|
testImplementation "commons-codec:commons-codec:$commonscodec_version"
|
||||||
|
|
||||||
api 'com.github.guepardoapps:kulid:2.0.0.0'
|
api 'com.github.guepardoapps:kulid:2.0.0.0'
|
||||||
|
|
|
@ -37,14 +37,14 @@ dependencies {
|
||||||
implementation project(':pump:rileylink')
|
implementation project(':pump:rileylink')
|
||||||
implementation project(':pump:omnipod-common')
|
implementation project(':pump:omnipod-common')
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-impl')
|
testImplementation project(':shared:impl')
|
||||||
|
|
||||||
api "androidx.room:room-ktx:$room_version"
|
api "androidx.room:room-ktx:$room_version"
|
||||||
api "androidx.room:room-runtime:$room_version"
|
api "androidx.room:room-runtime:$room_version"
|
||||||
api "androidx.room:room-rxjava3:$room_version"
|
api "androidx.room:room-rxjava3:$room_version"
|
||||||
kapt "androidx.room:room-compiler:$room_version"
|
kapt "androidx.room:room-compiler:$room_version"
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
// optional - Test helpers
|
// optional - Test helpers
|
||||||
testImplementation("androidx.room:room-testing:$room_version")
|
testImplementation("androidx.room:room-testing:$room_version")
|
||||||
testImplementation project(':implementation')
|
testImplementation project(':implementation')
|
||||||
|
|
|
@ -19,5 +19,5 @@ dependencies {
|
||||||
implementation project(':core:ui')
|
implementation project(':core:ui')
|
||||||
implementation project(':pump:pump-common')
|
implementation project(':pump:pump-common')
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,5 +23,5 @@ dependencies {
|
||||||
implementation project(':core:ui')
|
implementation project(':core:ui')
|
||||||
implementation project(':core:utils')
|
implementation project(':core:utils')
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
include ':app'
|
include ':app'
|
||||||
include ':wear'
|
include ':wear'
|
||||||
include ':app-wear-shared:shared-impl'
|
include ':shared:impl'
|
||||||
include ':app-wear-shared:shared-tests'
|
include ':shared:tests'
|
||||||
include ':core:main'
|
include ':core:main'
|
||||||
include ':core:graphview'
|
include ':core:graphview'
|
||||||
include ':core:interfaces'
|
include ':core:interfaces'
|
||||||
|
|
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 41 KiB |
|
@ -1,4 +1,4 @@
|
||||||
package info.nightscout.shared.impl
|
package app.aaps.shared.impl
|
||||||
|
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
|
|
@ -1,4 +1,4 @@
|
||||||
package info.nightscout.shared.impl.logging
|
package app.aaps.shared.impl.logging
|
||||||
|
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
|
@ -1,8 +1,8 @@
|
||||||
package info.nightscout.shared.impl.sharedPreferences
|
package app.aaps.shared.impl.sharedPreferences
|
||||||
|
|
||||||
import com.google.common.truth.Truth.assertThat
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import info.nightscout.shared.impl.SharedPreferencesMock
|
import app.aaps.shared.impl.SharedPreferencesMock
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.extension.ExtendWith
|
import org.junit.jupiter.api.extension.ExtendWith
|
|
@ -18,7 +18,7 @@ android {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(':database:entities')
|
implementation project(':database:entities')
|
||||||
implementation project(':app-wear-shared:shared-impl')
|
implementation project(':shared:impl')
|
||||||
implementation project(':core:interfaces')
|
implementation project(':core:interfaces')
|
||||||
implementation project(':core:main')
|
implementation project(':core:main')
|
||||||
implementation project(':core:utils')
|
implementation project(':core:utils')
|
|
@ -24,5 +24,5 @@ dependencies {
|
||||||
implementation project(':core:ui')
|
implementation project(':core:ui')
|
||||||
implementation project(':core:utils')
|
implementation project(':core:utils')
|
||||||
|
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
}
|
}
|
|
@ -93,7 +93,7 @@ allprojects {
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(':app-wear-shared:shared-impl')
|
implementation project(':shared:impl')
|
||||||
implementation project(':core:interfaces')
|
implementation project(':core:interfaces')
|
||||||
|
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
|
@ -105,7 +105,7 @@ dependencies {
|
||||||
implementation 'androidx.wear:wear:1.3.0'
|
implementation 'androidx.wear:wear:1.3.0'
|
||||||
implementation 'androidx.wear.tiles:tiles:1.1.0'
|
implementation 'androidx.wear.tiles:tiles:1.1.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
testImplementation project(':app-wear-shared:shared-tests')
|
testImplementation project(':shared:tests')
|
||||||
|
|
||||||
compileOnly "com.google.android.wearable:wearable:$wearable_version"
|
compileOnly "com.google.android.wearable:wearable:$wearable_version"
|
||||||
implementation "com.google.android.support:wearable:$wearable_version"
|
implementation "com.google.android.support:wearable:$wearable_version"
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package info.nightscout.androidaps.di
|
package info.nightscout.androidaps.di
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import app.aaps.shared.impl.di.SharedImplModule
|
||||||
import dagger.Binds
|
import dagger.Binds
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.WearApp
|
import info.nightscout.androidaps.WearApp
|
||||||
import info.nightscout.shared.impl.di.SharedImplModule
|
|
||||||
import kotlinx.datetime.Clock
|
import kotlinx.datetime.Clock
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
|
|
|
@ -5,11 +5,11 @@ import android.content.pm.PackageManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import app.aaps.shared.impl.extensions.safeGetPackageInfo
|
||||||
import dagger.android.DaggerActivity
|
import dagger.android.DaggerActivity
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.rx.events.EventWearToMobile
|
|
||||||
import info.nightscout.shared.extensions.safeGetPackageInfo
|
|
||||||
import info.nightscout.rx.bus.RxBus
|
import info.nightscout.rx.bus.RxBus
|
||||||
|
import info.nightscout.rx.events.EventWearToMobile
|
||||||
import info.nightscout.rx.weardata.EventData
|
import info.nightscout.rx.weardata.EventData
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue