share code between aap and wear

This commit is contained in:
Milos Kozak 2021-12-10 08:58:23 +01:00
parent d08b018edf
commit 0a25fa3c9a
52 changed files with 240 additions and 164 deletions

View file

@ -176,6 +176,7 @@ allprojects {
dependencies { dependencies {
wearApp project(':wear') wearApp project(':wear')
implementation project(':shared')
implementation project(':core') implementation project(':core')
implementation project(':automation') implementation project(':automation')
implementation project(':combo') implementation project(':combo')

View file

@ -49,7 +49,7 @@ import info.nightscout.androidaps.plugins.source.GlimpPlugin
import info.nightscout.androidaps.plugins.source.PoctechPlugin import info.nightscout.androidaps.plugins.source.PoctechPlugin
import info.nightscout.androidaps.plugins.source.TomatoPlugin import info.nightscout.androidaps.plugins.source.TomatoPlugin
import info.nightscout.androidaps.plugins.source.GlunovoPlugin import info.nightscout.androidaps.plugins.source.GlunovoPlugin
import info.nightscout.androidaps.utils.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.androidaps.utils.alertDialogs.OKDialog.show import info.nightscout.androidaps.utils.alertDialogs.OKDialog.show
import info.nightscout.androidaps.utils.protection.PasswordCheck import info.nightscout.androidaps.utils.protection.PasswordCheck
import info.nightscout.androidaps.utils.protection.ProtectionCheck import info.nightscout.androidaps.utils.protection.ProtectionCheck

View file

@ -15,7 +15,7 @@ import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.utils.ActivityMonitor import info.nightscout.androidaps.utils.ActivityMonitor
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.InstanceId import info.nightscout.androidaps.utils.InstanceId
import info.nightscout.androidaps.utils.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.stats.TddCalculator import info.nightscout.androidaps.utils.stats.TddCalculator
import info.nightscout.androidaps.utils.stats.TirCalculator import info.nightscout.androidaps.utils.stats.TirCalculator

View file

@ -19,7 +19,7 @@ import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.HtmlHelper import info.nightscout.androidaps.utils.HtmlHelper
import info.nightscout.androidaps.utils.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.extensions.formatColor import info.nightscout.androidaps.extensions.formatColor
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper

View file

@ -25,7 +25,7 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.DecimalFormatter
import info.nightscout.androidaps.utils.HtmlHelper import info.nightscout.androidaps.utils.HtmlHelper
import info.nightscout.androidaps.utils.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.extensions.formatColor import info.nightscout.androidaps.extensions.formatColor
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper

View file

@ -12,23 +12,24 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.database.entities.TemporaryTarget
import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.transactions.InsertAndCancelCurrentTemporaryTargetTransaction import info.nightscout.androidaps.database.transactions.InsertAndCancelCurrentTemporaryTargetTransaction
import info.nightscout.androidaps.databinding.DialogInsulinBinding import info.nightscout.androidaps.databinding.DialogInsulinBinding
import info.nightscout.androidaps.extensions.formatColor
import info.nightscout.androidaps.extensions.toVisibility
import info.nightscout.androidaps.interfaces.*
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.* import info.nightscout.androidaps.utils.*
import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.extensions.formatColor
import info.nightscout.androidaps.utils.extensions.toSignedString import info.nightscout.androidaps.utils.extensions.toSignedString
import info.nightscout.androidaps.extensions.toVisibility
import info.nightscout.androidaps.interfaces.*
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.shared.SafeParse
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.plusAssign import io.reactivex.rxkotlin.plusAssign
import java.text.DecimalFormat import java.text.DecimalFormat

View file

@ -17,7 +17,7 @@ import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.HtmlHelper import info.nightscout.androidaps.utils.HtmlHelper
import info.nightscout.androidaps.utils.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.extensions.formatColor import info.nightscout.androidaps.extensions.formatColor
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper

View file

@ -27,7 +27,7 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.DecimalFormatter
import info.nightscout.androidaps.utils.HtmlHelper import info.nightscout.androidaps.utils.HtmlHelper
import info.nightscout.androidaps.utils.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.extensions.formatColor import info.nightscout.androidaps.extensions.formatColor

View file

@ -30,7 +30,7 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.DecimalFormatter
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.extensions.toVisibility import info.nightscout.androidaps.extensions.toVisibility
import info.nightscout.androidaps.extensions.valueToUnits import info.nightscout.androidaps.extensions.valueToUnits

View file

@ -18,7 +18,7 @@ import info.nightscout.androidaps.plugins.aps.logger.LoggerCallback
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader import info.nightscout.androidaps.plugins.aps.loop.ScriptReader
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
import info.nightscout.androidaps.utils.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.json.JSONArray import org.json.JSONArray

View file

@ -14,7 +14,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.general.overview.events.EventQuickWizardChange import info.nightscout.androidaps.plugins.general.overview.events.EventQuickWizardChange
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.extensions.selectedItemPosition import info.nightscout.androidaps.utils.extensions.selectedItemPosition
import info.nightscout.androidaps.utils.extensions.setEnableForChildren import info.nightscout.androidaps.utils.extensions.setEnableForChildren

View file

@ -47,6 +47,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import info.nightscout.androidaps.utils.textValidator.ValidatingEditTextPreference import info.nightscout.androidaps.utils.textValidator.ValidatingEditTextPreference
import info.nightscout.shared.SafeParse
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.plusAssign import io.reactivex.rxkotlin.plusAssign
import org.apache.commons.lang3.StringUtils import org.apache.commons.lang3.StringUtils

View file

@ -39,6 +39,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import info.nightscout.androidaps.utils.wizard.BolusWizard import info.nightscout.androidaps.utils.wizard.BolusWizard
import info.nightscout.shared.SafeParse
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.plusAssign import io.reactivex.rxkotlin.plusAssign
import java.text.DateFormat import java.text.DateFormat

View file

@ -30,6 +30,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.ui.SpinnerHelper import info.nightscout.androidaps.utils.ui.SpinnerHelper
import info.nightscout.androidaps.utils.ui.TimeListEdit import info.nightscout.androidaps.utils.ui.TimeListEdit
import info.nightscout.shared.SafeParse
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.plusAssign import io.reactivex.rxkotlin.plusAssign
import java.text.DecimalFormat import java.text.DecimalFormat

View file

@ -10,7 +10,7 @@ import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensDataStore import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensDataStore
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult
import info.nightscout.androidaps.utils.Round import info.nightscout.androidaps.utils.Round
import info.nightscout.androidaps.utils.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import kotlin.math.max import kotlin.math.max

View file

@ -8,7 +8,7 @@ import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.setupwizard.SWIntNumberValidator import info.nightscout.androidaps.setupwizard.SWIntNumberValidator
import info.nightscout.androidaps.utils.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.androidaps.utils.ui.NumberPicker import info.nightscout.androidaps.utils.ui.NumberPicker
import java.text.DecimalFormat import java.text.DecimalFormat

View file

@ -8,7 +8,7 @@ import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.setupwizard.SWNumberValidator import info.nightscout.androidaps.setupwizard.SWNumberValidator
import info.nightscout.androidaps.utils.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.androidaps.utils.ui.NumberPicker import info.nightscout.androidaps.utils.ui.NumberPicker
import java.text.DecimalFormat import java.text.DecimalFormat

View file

@ -11,7 +11,7 @@ import info.nightscout.androidaps.interfaces.GlucoseUnit
import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.setupwizard.SWNumberValidator import info.nightscout.androidaps.setupwizard.SWNumberValidator
import info.nightscout.androidaps.utils.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.androidaps.utils.ui.NumberPicker import info.nightscout.androidaps.utils.ui.NumberPicker
import java.text.DecimalFormat import java.text.DecimalFormat
import javax.inject.Inject import javax.inject.Inject

View file

@ -9,6 +9,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import info.nightscout.shared.SafeParse
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -64,7 +65,7 @@ class ActivityMonitor @Inject constructor(
if (key.startsWith("Monitor") && key.endsWith("total")) { if (key.startsWith("Monitor") && key.endsWith("total")) {
val v = if (value is Long) value else SafeParse.stringToLong(value as String) val v = if (value is Long) value else SafeParse.stringToLong(value as String)
val activity = key.split("_")[1].replace("Activity", "") val activity = key.split("_")[1].replace("Activity", "")
val duration = dateUtil.niceTimeScalar(v as Long, rh) val duration = dateUtil.niceTimeScalar(v, rh)
val start = sp.getLong(key.replace("total", "start"), 0) val start = sp.getLong(key.replace("total", "start"), 0)
val days = T.msecs(dateUtil.now() - start).days() val days = T.msecs(dateUtil.now() - start).days()
result += rh.gs(R.string.activitymonitorformat, activity, duration, days) result += rh.gs(R.string.activitymonitorformat, activity, duration, days)

View file

@ -27,7 +27,7 @@ import java.util.List;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.SafeParse; import info.nightscout.shared.SafeParse;
/** /**
* Created by mike on 29.12.2016. * Created by mike on 29.12.2016.

View file

@ -12,5 +12,6 @@ apply from: "${project.rootDir}/gradle/test_dependencies.gradle"
apply from: "${project.rootDir}/gradle/jacoco_global.gradle" apply from: "${project.rootDir}/gradle/jacoco_global.gradle"
dependencies { dependencies {
implementation project(':shared')
implementation project(':database') implementation project(':database')
} }

View file

@ -30,10 +30,10 @@ import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.SafeParse
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import info.nightscout.shared.SafeParse
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import java.text.DateFormat import java.text.DateFormat
import java.text.DecimalFormat import java.text.DecimalFormat

View file

@ -5,6 +5,7 @@ import androidx.collection.LongSparseArray
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.annotations.OpenForTesting
import info.nightscout.androidaps.core.R import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.shared.SafeParse
import org.joda.time.DateTime import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat import org.joda.time.format.DateTimeFormat
import org.joda.time.format.ISODateTimeFormat import org.joda.time.format.ISODateTimeFormat

View file

@ -1,50 +0,0 @@
package info.nightscout.androidaps.utils;
/**
* Created by mike on 23.06.2016.
*/
public class SafeParse {
// TODO return logging with dagger
// private static Logger log = StacktraceLoggerWrapper.getLogger(SafeParse.class);
public static Double stringToDouble(String input) {
Double result = 0d;
input = input.replace(",", ".");
input = input.replace("", "-");
if (input.equals(""))
return 0d;
try {
result = Double.parseDouble(input);
} catch (Exception e) {
// log.error("Error parsing " + input + " to double");
}
return result;
}
public static Integer stringToInt(String input) {
Integer result = 0;
input = input.replace(",", ".");
input = input.replace("", "-");
if (input.equals(""))
return 0;
try {
result = Integer.parseInt(input);
} catch (Exception e) {
// log.error("Error parsing " + input + " to int");
}
return result;
}
public static Long stringToLong(String input) {
Long result = 0L;
input = input.replace(",", ".");
input = input.replace("", "-");
if (input.equals(""))
return 0L;
try {
result = Long.parseLong(input);
} catch (Exception e) {
// log.error("Error parsing " + input + " to long");
}
return result;
}
}

View file

@ -1,8 +1,8 @@
package info.nightscout.androidaps.utils.sharedPreferences package info.nightscout.androidaps.utils.sharedPreferences
import android.content.SharedPreferences import android.content.SharedPreferences
import info.nightscout.androidaps.utils.SafeParse
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.shared.SafeParse
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton

View file

@ -20,8 +20,8 @@ import android.widget.Button
import android.widget.EditText import android.widget.EditText
import android.widget.LinearLayout import android.widget.LinearLayout
import info.nightscout.androidaps.core.R import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.utils.SafeParse
import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.shared.SafeParse
import java.text.NumberFormat import java.text.NumberFormat
import java.util.concurrent.Executors import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService import java.util.concurrent.ScheduledExecutorService

View file

@ -17,3 +17,4 @@ include ':omnipod-dash'
include ':diaconn' include ':diaconn'
include ':openhumans' include ':openhumans'
include ':shared'

1
shared/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build

16
shared/build.gradle Normal file
View file

@ -0,0 +1,16 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-allopen'
apply plugin: 'com.hiya.jacoco-android'
apply from: "${project.rootDir}/gradle/android_dependencies.gradle"
apply from: "${project.rootDir}/gradle/android_module_dependencies.gradle"
apply from: "${project.rootDir}/gradle/test_dependencies.gradle"
apply from: "${project.rootDir}/gradle/jacoco_global.gradle"
android {
defaultConfig {
minSdkVersion 23 // for wear
}
}

View file

21
shared/proguard-rules.pro vendored Normal file
View file

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

View file

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

View file

@ -0,0 +1,64 @@
package info.nightscout.shared
import java.lang.Exception
object SafeParse {
// TODO return logging with dagger
// private static Logger log = StacktraceLoggerWrapper.getLogger(SafeParse.class);
@JvmStatic fun stringToDouble(inputString: String?): Double {
var input = inputString ?: return 0.0
var result = 0.0
input = input.replace(",", ".")
input = input.replace("", "-")
if (input == "") return 0.0
try {
result = input.toDouble()
} catch (e: Exception) {
// log.error("Error parsing " + input + " to double");
}
return result
}
@JvmStatic fun stringToFloat(inputString: String?): Float {
var input = inputString ?: return 0f
var result = 0f
input = input.replace(",", ".")
input = input.replace("", "-")
if (input == "") return 0f
try {
result = input.toFloat()
} catch (e: Exception) {
// log.error("Error parsing " + input + " to float");
}
return result
}
@JvmStatic fun stringToInt(inputString: String?): Int {
var input = inputString ?: return 0
var result = 0
input = input.replace(",", ".")
input = input.replace("", "-")
if (input == "") return 0
try {
result = input.toInt()
} catch (e: Exception) {
// log.error("Error parsing " + input + " to int");
}
return result
}
fun stringToLong(inputString: String?): Long {
var input = inputString ?: return 0L
var result = 0L
input = input.replace(",", ".")
input = input.replace("", "-")
if (input == "") return 0L
try {
result = input.toLong()
} catch (e: Exception) {
// log.error("Error parsing " + input + " to long");
}
return result
}
}

View file

@ -1,10 +1,8 @@
package info.nightscout.androidaps.interaction.utils package info.nightscout.shared
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import java.lang.NullPointerException
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
class SafeParseTest { class SafeParseTest {

View file

@ -114,6 +114,8 @@ allprojects {
dependencies { dependencies {
implementation project(':shared')
implementation fileTree(include: ['*.jar'], dir: 'libs') implementation fileTree(include: ['*.jar'], dir: 'libs')
//implementation files("libs/hellocharts-library-1.5.5.jar") //implementation files("libs/hellocharts-library-1.5.5.jar")
//compile "com.ustwo.android:clockwise-wearable:1.0.2" //compile "com.ustwo.android:clockwise-wearable:1.0.2"

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps; package info.nightscout.androidaps;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;

View file

@ -18,6 +18,10 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import javax.inject.Inject;
import dagger.android.AndroidInjection;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Aaps; import info.nightscout.androidaps.Aaps;
import info.nightscout.androidaps.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
@ -35,6 +39,15 @@ import info.nightscout.androidaps.interaction.utils.WearUtil;
*/ */
public abstract class BaseComplicationProviderService extends ComplicationProviderService { public abstract class BaseComplicationProviderService extends ComplicationProviderService {
@Inject Inevitable inevitable;
// Not derived from DaggerService, do injection here
@Override
public void onCreate() {
AndroidInjection.inject(this);
super.onCreate();
}
private static final String TAG = BaseComplicationProviderService.class.getSimpleName(); private static final String TAG = BaseComplicationProviderService.class.getSimpleName();
private static final String KEY_COMPLICATIONS = "complications"; private static final String KEY_COMPLICATIONS = "complications";
@ -286,13 +299,13 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
/* /*
* Schedule check for field update * Schedule check for field update
*/ */
public static void checkIfUpdateNeeded() { public void checkIfUpdateNeeded() {
Persistence p = new Persistence(); Persistence p = new Persistence();
Log.d(TAG, "Pending check if update needed - "+p.getString(KEY_COMPLICATIONS, "")); Log.d(TAG, "Pending check if update needed - "+p.getString(KEY_COMPLICATIONS, ""));
Inevitable.task(TASK_ID_REFRESH_COMPLICATION, 15 * Constants.SECOND_IN_MS, () -> { inevitable.task(TASK_ID_REFRESH_COMPLICATION, 15 * Constants.SECOND_IN_MS, () -> {
if (WearUtil.isBelowRateLimit("complication-checkIfUpdateNeeded", 5)) { if (WearUtil.isBelowRateLimit("complication-checkIfUpdateNeeded", 5)) {
Log.d(TAG, "Checking if update needed"); Log.d(TAG, "Checking if update needed");
requestUpdateIfSinceChanged(); requestUpdateIfSinceChanged();
@ -307,7 +320,7 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
* Check if displayed since field (field that shows how old, in minutes, is reading) * Check if displayed since field (field that shows how old, in minutes, is reading)
* is up-to-date or need to be changed (a minute or more elapsed) * is up-to-date or need to be changed (a minute or more elapsed)
*/ */
private static void requestUpdateIfSinceChanged() { private void requestUpdateIfSinceChanged() {
final Persistence persistence = new Persistence(); final Persistence persistence = new Persistence();
final RawDisplayData raw = new RawDisplayData(); final RawDisplayData raw = new RawDisplayData();
@ -342,11 +355,11 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
/* /*
* Request update for specified list of providers * Request update for specified list of providers
*/ */
private static void requestUpdate(Set<String> providers) { private void requestUpdate(Set<String> providers) {
for (String provider: providers) { for (String provider: providers) {
Log.d(TAG, "Pending update of "+provider); Log.d(TAG, "Pending update of "+provider);
// We wait with updating allowing all request, from various sources, to arrive // We wait with updating allowing all request, from various sources, to arrive
Inevitable.task("update-req-"+provider, 700, () -> { inevitable.task("update-req-"+provider, 700, () -> {
if (WearUtil.isBelowRateLimit("update-req-"+provider, 2)) { if (WearUtil.isBelowRateLimit("update-req-"+provider, 2)) {
Log.d(TAG, "Requesting update of "+provider); Log.d(TAG, "Requesting update of "+provider);
final ComponentName componentName = new ComponentName(Aaps.getAppContext(), provider); final ComponentName componentName = new ComponentName(Aaps.getAppContext(), provider);
@ -395,7 +408,7 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
/* /*
* Listen to broadcast --> new data was stored by ListenerService to Persistence * Listen to broadcast --> new data was stored by ListenerService to Persistence
*/ */
public static class MessageReceiver extends BroadcastReceiver { public class MessageReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Set<String> complications = Persistence.setOf(KEY_COMPLICATIONS); Set<String> complications = Persistence.setOf(KEY_COMPLICATIONS);

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.complications; package info.nightscout.androidaps.complications;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -12,8 +11,11 @@ import android.widget.Toast;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import info.nightscout.androidaps.R; import javax.inject.Inject;
import dagger.android.DaggerBroadcastReceiver;
import info.nightscout.androidaps.Aaps; import info.nightscout.androidaps.Aaps;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interaction.actions.BolusActivity; import info.nightscout.androidaps.interaction.actions.BolusActivity;
import info.nightscout.androidaps.interaction.actions.ECarbActivity; import info.nightscout.androidaps.interaction.actions.ECarbActivity;
import info.nightscout.androidaps.interaction.actions.WizardActivity; import info.nightscout.androidaps.interaction.actions.WizardActivity;
@ -26,7 +28,9 @@ import info.nightscout.androidaps.interaction.utils.WearUtil;
/* /*
* Created by dlvoy on 2019-11-12 * Created by dlvoy on 2019-11-12
*/ */
public class ComplicationTapBroadcastReceiver extends BroadcastReceiver { public class ComplicationTapBroadcastReceiver extends DaggerBroadcastReceiver {
@Inject WearUtil wearUtil;
private static final String TAG = ComplicationTapBroadcastReceiver.class.getSimpleName(); private static final String TAG = ComplicationTapBroadcastReceiver.class.getSimpleName();
@ -41,6 +45,7 @@ public class ComplicationTapBroadcastReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
Bundle extras = intent.getExtras(); Bundle extras = intent.getExtras();
ComponentName provider = extras.getParcelable(EXTRA_PROVIDER_COMPONENT); ComponentName provider = extras.getParcelable(EXTRA_PROVIDER_COMPONENT);
int complicationId = extras.getInt(EXTRA_COMPLICATION_ID); int complicationId = extras.getInt(EXTRA_COMPLICATION_ID);
@ -51,7 +56,7 @@ public class ComplicationTapBroadcastReceiver extends BroadcastReceiver {
action = ComplicationAction.valueOf(ComplicationAction.class, complicationAction); action = ComplicationAction.valueOf(ComplicationAction.class, complicationAction);
} catch (IllegalArgumentException | NullPointerException ex) { } catch (IllegalArgumentException | NullPointerException ex) {
// but how? // but how?
Log.e(TAG, "Cannot interpret complication action: "+complicationAction); Log.e(TAG, "Cannot interpret complication action: " + complicationAction);
} }
action = remapActionWithUserPreferences(action); action = remapActionWithUserPreferences(action);
@ -67,35 +72,36 @@ public class ComplicationTapBroadcastReceiver extends BroadcastReceiver {
// do nothing // do nothing
return; return;
case WIZARD: case WIZARD:
intentOpen = new Intent(Aaps.getAppContext(), WizardActivity.class); intentOpen = new Intent(context, WizardActivity.class);
break; break;
case BOLUS: case BOLUS:
intentOpen = new Intent(Aaps.getAppContext(), BolusActivity.class); intentOpen = new Intent(context, BolusActivity.class);
break; break;
case ECARB: case ECARB:
intentOpen = new Intent(Aaps.getAppContext(), ECarbActivity.class); intentOpen = new Intent(context, ECarbActivity.class);
break; break;
case STATUS: case STATUS:
intentOpen = new Intent(Aaps.getAppContext(), StatusMenuActivity.class); intentOpen = new Intent(context, StatusMenuActivity.class);
break; break;
case WARNING_OLD: case WARNING_OLD:
case WARNING_SYNC: case WARNING_SYNC:
long oneAndHalfMinuteAgo = WearUtil.timestamp() - (Constants.MINUTE_IN_MS+Constants.SECOND_IN_MS * 30); long oneAndHalfMinuteAgo =
wearUtil.timestamp() - (Constants.MINUTE_IN_MS + Constants.SECOND_IN_MS * 30);
long since = extras.getLong(EXTRA_COMPLICATION_SINCE, oneAndHalfMinuteAgo); long since = extras.getLong(EXTRA_COMPLICATION_SINCE, oneAndHalfMinuteAgo);
@StringRes int labelId = (action == ComplicationAction.WARNING_SYNC) ? @StringRes int labelId = (action == ComplicationAction.WARNING_SYNC) ?
R.string.msg_warning_sync : R.string.msg_warning_old; R.string.msg_warning_sync : R.string.msg_warning_old;
String msg = String.format(context.getString(labelId), DisplayFormat.shortTimeSince(since)); String msg = String.format(context.getString(labelId), DisplayFormat.shortTimeSince(since));
Toast.makeText(Aaps.getAppContext(), msg, Toast.LENGTH_LONG).show(); Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
break; break;
case MENU: case MENU:
default: default:
intentOpen = new Intent(Aaps.getAppContext(), MainMenuActivity.class); intentOpen = new Intent(context, MainMenuActivity.class);
} }
if (intentOpen != null) { if (intentOpen != null) {
// Perform intent - open dialog // Perform intent - open dialog
intentOpen.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intentOpen.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Aaps.getAppContext().startActivity(intentOpen); context.startActivity(intentOpen);
} }
} }

View file

@ -38,12 +38,15 @@ import com.google.android.gms.wearable.WearableListenerService;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import dagger.android.AndroidInjection;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interaction.AAPSPreferences; import info.nightscout.androidaps.interaction.AAPSPreferences;
import info.nightscout.androidaps.interaction.actions.AcceptActivity; import info.nightscout.androidaps.interaction.actions.AcceptActivity;
import info.nightscout.androidaps.interaction.actions.CPPActivity; import info.nightscout.androidaps.interaction.actions.CPPActivity;
import info.nightscout.androidaps.interaction.utils.Persistence; import info.nightscout.androidaps.interaction.utils.Persistence;
import info.nightscout.androidaps.interaction.utils.SafeParse; import info.nightscout.shared.SafeParse;
import info.nightscout.androidaps.interaction.utils.WearUtil; import info.nightscout.androidaps.interaction.utils.WearUtil;
@ -53,6 +56,8 @@ import info.nightscout.androidaps.interaction.utils.WearUtil;
public class ListenerService extends WearableListenerService implements GoogleApiClient.ConnectionCallbacks, public class ListenerService extends WearableListenerService implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener, ChannelApi.ChannelListener { GoogleApiClient.OnConnectionFailedListener, ChannelApi.ChannelListener {
@Inject WearUtil wearUtil;
private static final String WEARABLE_DATA_PATH = "/nightscout_watch_data"; private static final String WEARABLE_DATA_PATH = "/nightscout_watch_data";
private static final String WEARABLE_RESEND_PATH = "/nightscout_watch_data_resend"; private static final String WEARABLE_RESEND_PATH = "/nightscout_watch_data_resend";
private static final String WEARABLE_CANCELBOLUS_PATH = "/nightscout_watch_cancel_bolus"; private static final String WEARABLE_CANCELBOLUS_PATH = "/nightscout_watch_cancel_bolus";
@ -69,8 +74,8 @@ public class ListenerService extends WearableListenerService implements GoogleAp
public static final String ACTION_CANCELNOTIFICATION_REQUEST_PATH = "/nightscout_watch_cancelnotificationrequest"; public static final String ACTION_CANCELNOTIFICATION_REQUEST_PATH = "/nightscout_watch_cancelnotificationrequest";
public static final int BOLUS_PROGRESS_NOTIF_ID = 001; public static final int BOLUS_PROGRESS_NOTIF_ID = 1;
public static final int CONFIRM_NOTIF_ID = 002; public static final int CONFIRM_NOTIF_ID = 2;
public static final int CHANGE_NOTIF_ID = 556677; public static final int CHANGE_NOTIF_ID = 556677;
private static final String ACTION_RESEND = "com.dexdrip.stephenblack.nightwatch.RESEND_DATA"; private static final String ACTION_RESEND = "com.dexdrip.stephenblack.nightwatch.RESEND_DATA";
@ -104,6 +109,13 @@ public class ListenerService extends WearableListenerService implements GoogleAp
private String localnode = null; private String localnode = null;
private final String logPrefix = ""; // "WR: " private final String logPrefix = ""; // "WR: "
// Not derived from DaggerService, do injection here
@Override
public void onCreate() {
AndroidInjection.inject(this);
super.onCreate();
}
public class DataRequester extends AsyncTask<Void, Void, Void> { public class DataRequester extends AsyncTask<Void, Void, Void> {
Context mContext; Context mContext;
String path; String path;
@ -364,7 +376,8 @@ public class ListenerService extends WearableListenerService implements GoogleAp
} }
} }
Log.d(TAG, logPrefix + "sendData: execute lastRequest:" + WearUtil.dateTimeText(lastRequest)); Log.d(TAG,
logPrefix + "sendData: execute lastRequest:" + wearUtil.dateTimeText(lastRequest));
mDataRequester = (DataRequester) new DataRequester(this, path, payload).execute(); mDataRequester = (DataRequester) new DataRequester(this, path, payload).execute();
// executeTask(mDataRequester); // executeTask(mDataRequester);

View file

@ -11,7 +11,8 @@ import javax.inject.Singleton
@Component( @Component(
modules = [ modules = [
AndroidInjectionModule::class, AndroidInjectionModule::class,
WearModule::class WearModule::class,
ServicesModule::class
] ]
) )
interface AppComponent : AndroidInjector<Aaps> { interface AppComponent : AndroidInjector<Aaps> {

View file

@ -0,0 +1,14 @@
package info.nightscout.androidaps.di
import dagger.Module
import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.complications.BaseComplicationProviderService
import info.nightscout.androidaps.data.ListenerService
@Module
@Suppress("unused")
abstract class ServicesModule {
@ContributesAndroidInjector abstract fun contributesListenerService(): ListenerService
@ContributesAndroidInjector abstract fun contributesBaseComplicationProviderService(): BaseComplicationProviderService
}

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.interaction.actions; package info.nightscout.androidaps.interaction.actions;
import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.support.wearable.view.DotsPageIndicator; import android.support.wearable.view.DotsPageIndicator;
import android.support.wearable.view.GridPagerAdapter; import android.support.wearable.view.GridPagerAdapter;
@ -17,7 +16,7 @@ import java.text.DecimalFormat;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText;
import info.nightscout.androidaps.interaction.utils.SafeParse; import info.nightscout.shared.SafeParse;
/** /**
* Created by adrian on 09/02/17. * Created by adrian on 09/02/17.

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.interaction.actions; package info.nightscout.androidaps.interaction.actions;
import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.support.wearable.view.DotsPageIndicator; import android.support.wearable.view.DotsPageIndicator;
import android.support.wearable.view.GridPagerAdapter; import android.support.wearable.view.GridPagerAdapter;
@ -17,7 +16,7 @@ import java.text.DecimalFormat;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText;
import info.nightscout.androidaps.interaction.utils.SafeParse; import info.nightscout.shared.SafeParse;
/** /**
* Created by adrian on 09/02/17. * Created by adrian on 09/02/17.

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.interaction.actions; package info.nightscout.androidaps.interaction.actions;
import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.support.wearable.view.DotsPageIndicator; import android.support.wearable.view.DotsPageIndicator;
import android.support.wearable.view.GridPagerAdapter; import android.support.wearable.view.GridPagerAdapter;
@ -17,7 +16,7 @@ import java.text.DecimalFormat;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText;
import info.nightscout.androidaps.interaction.utils.SafeParse; import info.nightscout.shared.SafeParse;
/** /**
* Created by adrian on 04/08/18. * Created by adrian on 04/08/18.

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.interaction.actions; package info.nightscout.androidaps.interaction.actions;
import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.support.wearable.view.DotsPageIndicator; import android.support.wearable.view.DotsPageIndicator;
import android.support.wearable.view.GridPagerAdapter; import android.support.wearable.view.GridPagerAdapter;
@ -17,7 +16,7 @@ import java.text.DecimalFormat;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText;
import info.nightscout.androidaps.interaction.utils.SafeParse; import info.nightscout.shared.SafeParse;
/** /**
* Created by adrian on 09/02/17. * Created by adrian on 09/02/17.

View file

@ -2,7 +2,6 @@ package info.nightscout.androidaps.interaction.actions;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.wearable.view.DotsPageIndicator; import android.support.wearable.view.DotsPageIndicator;
@ -19,7 +18,7 @@ import java.text.DecimalFormat;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText;
import info.nightscout.androidaps.interaction.utils.SafeParse; import info.nightscout.shared.SafeParse;
/** /**
* Created by adrian on 09/02/17. * Created by adrian on 09/02/17.

View file

@ -2,7 +2,6 @@ package info.nightscout.androidaps.interaction.actions;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.wearable.view.DotsPageIndicator; import android.support.wearable.view.DotsPageIndicator;
@ -19,7 +18,7 @@ import java.text.DecimalFormat;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText;
import info.nightscout.androidaps.interaction.utils.SafeParse; import info.nightscout.shared.SafeParse;
/** /**
* Created by adrian on 09/02/17. * Created by adrian on 09/02/17.

View file

@ -5,6 +5,9 @@ import android.util.Log;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.BuildConfig;
/** /**
@ -16,15 +19,20 @@ import info.nightscout.androidaps.BuildConfig;
* *
*/ */
@Singleton
public class Inevitable { public class Inevitable {
@Inject WearUtil wearUtil;
@Inject Inevitable() {}
private static final String TAG = Inevitable.class.getSimpleName(); private static final String TAG = Inevitable.class.getSimpleName();
private static final int MAX_QUEUE_TIME = (int) Constants.MINUTE_IN_MS * 6; private static final int MAX_QUEUE_TIME = (int) Constants.MINUTE_IN_MS * 6;
private static final boolean debug = BuildConfig.DEBUG; private static final boolean debug = BuildConfig.DEBUG;
private static final ConcurrentHashMap<String, Task> tasks = new ConcurrentHashMap<>(); private static final ConcurrentHashMap<String, Task> tasks = new ConcurrentHashMap<>();
public static synchronized void task(final String id, long idle_for, Runnable runnable) { public void task(final String id, long idle_for, Runnable runnable) {
if (idle_for > MAX_QUEUE_TIME) { if (idle_for > MAX_QUEUE_TIME) {
throw new RuntimeException(id + " Requested time: " + idle_for + " beyond max queue time"); throw new RuntimeException(id + " Requested time: " + idle_for + " beyond max queue time");
} }
@ -34,14 +42,15 @@ public class Inevitable {
task.extendTime(idle_for); task.extendTime(idle_for);
if (debug) if (debug)
Log.d(TAG, "Extending time for: " + id + " to " + WearUtil.dateTimeText(task.when)); Log.d(TAG, "Extending time for: " + id + " to " + wearUtil.dateTimeText(task.when));
} else { } else {
// otherwise create new task // otherwise create new task
if (runnable == null) return; // extension only if already exists if (runnable == null) return; // extension only if already exists
tasks.put(id, new Task(id, idle_for, runnable)); tasks.put(id, new Task(id, idle_for, runnable));
if (debug) { if (debug) {
Log.d(TAG, "Creating task: " + id + " due: " + WearUtil.dateTimeText(tasks.get(id).when)); Log.d(TAG,
"Creating task: " + id + " due: " + wearUtil.dateTimeText(tasks.get(id).when));
} }
// create a thread to wait and execute in background // create a thread to wait and execute in background
@ -64,7 +73,7 @@ public class Inevitable {
} }
} }
public static synchronized void stackableTask(String id, long idle_for, Runnable runnable) { public void stackableTask(String id, long idle_for, Runnable runnable) {
int stack = 0; int stack = 0;
while (tasks.get(id = id + "-" + stack) != null) { while (tasks.get(id = id + "-" + stack) != null) {
stack++; stack++;

View file

@ -1,46 +0,0 @@
package info.nightscout.androidaps.interaction.utils;
/**
* Created by mike on 23.06.2016.
*/
public class SafeParse {
public static Double stringToDouble(String input) {
Double result = 0d;
input = input.replace(",", ".");
try {
result = Double.parseDouble(input);
} catch (Exception e) {
}
return result;
}
public static Integer stringToInt(String input) {
Integer result = 0;
input = input.replace(",", ".");
try {
result = Integer.parseInt(input);
} catch (Exception e) {
}
return result;
}
public static Long stringToLong(String input) {
Long result = 0L;
input = input.replace(",", ".");
try {
result = Long.parseLong(input);
} catch (Exception e) {
}
return result;
}
public static Float stringToFloat(String input) {
Float result = 0f;
input = input.replace(",", ".");
try {
result = Float.valueOf(input);
} catch (Exception e) {
}
return result;
}
}

View file

@ -15,6 +15,8 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import info.nightscout.androidaps.Aaps; import info.nightscout.androidaps.Aaps;
import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
/** /**
@ -25,6 +27,10 @@ import javax.inject.Singleton;
@Singleton @Singleton
public class WearUtil { public class WearUtil {
@Inject Context context;
@Inject WearUtil() {}
private final static boolean debug_wakelocks = false; private final static boolean debug_wakelocks = false;
private static final Map<String, Long> rateLimits = new HashMap<String, Long>(); private static final Map<String, Long> rateLimits = new HashMap<String, Long>();
private static final String TAG = WearUtil.class.getName(); private static final String TAG = WearUtil.class.getName();
@ -33,7 +39,7 @@ public class WearUtil {
// Time related util methods // Time related util methods
//============================================================================================== //==============================================================================================
public static String dateTimeText(long timeInMs) { public String dateTimeText(long timeInMs) {
Date d = new Date(timeInMs); Date d = new Date(timeInMs);
return "" + d.getDay() + "." + d.getMonth() + "." + d.getYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds(); return "" + d.getDay() + "." + d.getMonth() + "." + d.getYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
} }

View file

@ -10,7 +10,8 @@ import android.view.animation.RotateAnimation;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interaction.menus.MainMenuActivity; import info.nightscout.androidaps.interaction.menus.MainMenuActivity;
import info.nightscout.androidaps.interaction.utils.SafeParse; import info.nightscout.shared.SafeParse;
/** /**
* Created by andrew-warrington on 01/12/2017. * Created by andrew-warrington on 01/12/2017.
*/ */

View file

@ -1,7 +1,7 @@
package info.nightscout.androidaps.testing.mockers; package info.nightscout.androidaps.testing.mockers;
import info.nightscout.androidaps.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
import info.nightscout.androidaps.interaction.utils.SafeParse; import info.nightscout.shared.SafeParse;
import static info.nightscout.androidaps.testing.mockers.WearUtilMocker.backInTime; import static info.nightscout.androidaps.testing.mockers.WearUtilMocker.backInTime;