diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml index 310a05b9be..55d8d23c8d 100644 --- a/.github/workflows/unit_test.yml +++ b/.github/workflows/unit_test.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: - java-version: [ 8, 11 ] + java-version: [ 11 ] steps: - uses: actions/checkout@v2 diff --git a/Documentation/Quick_Start.md b/Documentation/Quick_Start.md new file mode 100644 index 0000000000..5776afaa5e --- /dev/null +++ b/Documentation/Quick_Start.md @@ -0,0 +1,20 @@ +# Quick Start + +### Currently Recommended IDE + +Android Studio Giraffe | 2022.3.1 Patch 3 + + +### Lombok Plugin + +Until we are using Android Studio Iguana (where the lombok regression is believed to be corrected) you will need to manually install the lombok plugin jar from the etc source tree folder. + +To install it you go to Settings -> Plugins -> Cog icon -> Install plugin from disk -> select the lombok-giraffe.jar file + +### Android Studio Bugs and Regressions + +Be aware that each new version of Android Studio introduces more regressions and bugs. There are still uncorrected bugs which were introduced back in version 3.6! Also each IDE version is tightly coupled with various versions of gradle which are also tightly coupled with various versions of the Android framework tools. + +What this means, is that even though the command line compilation always works fine, any single version of Android Studio is unable to compile the entire xDrip source tree history and is likely to break in misleading and confusing ways based on simple dependency changes as there is such poor support in Android Studio for forward or backwards compatibility. + +Expect to have to run multiple different versions of Android Studio over time or where in the commit history you may be working from and for each new version to potentially introduce new and unpredictable issues. Expect to have to clear cache and restart to avoid being misled about the source of errors. \ No newline at end of file diff --git a/Documentation/technical/Incoming_Glucose_Broadcast.md b/Documentation/technical/Incoming_Glucose_Broadcast.md new file mode 100644 index 0000000000..8c9c14d754 --- /dev/null +++ b/Documentation/technical/Incoming_Glucose_Broadcast.md @@ -0,0 +1,57 @@ + +# Integration with xDrip+ via Broadcast Intent + +## Overview +This documentation provides guidance on how to send a broadcast intent from a third-party Android application to insert a glucose sensor record into the xDrip application. There are a few different broadcast receivers but this documents the Nightscout Emulation receiver just for glucose records. + +## Sending a Broadcast Intent +To insert a glucose sensor record into xDrip, construct and send a broadcast intent with specific parameters as described below. + +### Intent Action +Use the following intent action when constructing the intent: +```java +Intent intent = new Intent("com.eveningoutpost.dexdrip.NS_EMULATOR"); +``` + +### Intent Package +To ensure the intent is received only by xDrip and to be allowed on Android 8+, specify the package name: +```java +intent.setPackage("com.eveningoutpost.dexdrip"); +``` + +### Extra Parameters +Add extra parameters to the intent for the data collection and JSON payload containing the sensor readings. + +- Collection: Indicate the type of data collection using the key `"collection"` with the value `"entries"`. +- Data: Provide the glucose sensor readings in a JSON array format with the key `"data"`. + +### JSON Payload Structure +Construct the JSON payload with the glucose sensor readings as follows: +- Each reading should be a JSON object with the following attributes: + - `"type"`: Set to `"sgv"` for sensor glucose value record. + - `"date"`: The timestamp of the reading in milliseconds since epoch. + - `"sgv"`: The glucose value in mg/dL. + - `"direction"`: The rate of change of the glucose value, represented by a string such as `"SingleUp"`. Refer to `BgReading.slopeFromName()` for possible values. + +Here is an example JSON payload with a single reading: +```java +final JSONArray sgv_array = new JSONArray(); +final JSONObject sgv_object = new JSONObject(); +sgv_object.put("type", "sgv"); +sgv_object.put("date", 1526817691000.0); +sgv_object.put("sgv", 158); +sgv_object.put("direction", "SingleUp"); +sgv_array.put(sgv_object); +intent.putExtra("data", sgv_array.toString()); +``` + +A code example of this is in the unit test source tree in `NSEmulatorReceiverTest.bgReadingExampleBroadcast()` + +### Sending the Intent +After constructing the intent, use `sendBroadcast()` to send it: +```java +context.sendBroadcast(intent); +``` + +## Testing the Integration +For testing purposes, make sure you set xDrip `Hardware Data Source` to `640G / Eversense` to enable the receiver. diff --git a/Documentation/technical/Kotlin_Policy.md b/Documentation/technical/Kotlin_Policy.md new file mode 100644 index 0000000000..c96e713b79 --- /dev/null +++ b/Documentation/technical/Kotlin_Policy.md @@ -0,0 +1,9 @@ +### Kotlin Policy + +xDrip supports both Java and Kotlin source files. + +New class files in Java or Kotlin are accepted but there is no intention to convert existing Java files to Kotlin. + +Kotlin classes should be mindful to maintain as much java compatibility as possible where they may need to interact with existing classes. + +Overhead in terms of additional libraries and any performance related issues (such as threading and component lifecycle) should be carefully monitored. \ No newline at end of file diff --git a/README.md b/README.md index 764b4663b3..4edc49df13 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ xDrip+ is an unofficial and independent Android app which works as data hub and processor between many different devices. -It supports wireless connections to G4, G5, G6, Medtrum A6, Libre via NFC and Bluetooth, 630G, 640G, 670G pumps and Eversense CGM via companion apps. Bluetooth Glucose Meters such as the Contour Next One, AccuChek Guide, Verio Flex & Diamond Mini as well as devices like the Pendiq 2.0 Insulin Pen. +It supports wireless connections to G4, G5, G6, G7, Medtrum A6, Libre via NFC and Bluetooth, 630G, 640G, 670G pumps, CareSens Air and Eversense CGM via companion apps. Bluetooth Glucose Meters such as the Contour Next One, AccuChek Guide, Verio Flex & Diamond Mini as well as devices like the Pendiq 2.0 Insulin Pen. Heart-rate and step counter data is processed from Android Wear, Garmin, Fitbit and Pebble smart-watches and watch-faces for those that show glucose values and graphs. diff --git a/aidex_text.png b/aidex_text.png deleted file mode 100644 index f6d9ba1f9a..0000000000 Binary files a/aidex_text.png and /dev/null differ diff --git a/app/build.gradle b/app/build.gradle index 7aab5ff96e..419807d515 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,9 @@ buildscript { } } apply plugin: 'com.android.application' -apply from: 'token-replace.gradle' +//apply from: 'token-replace.gradle' apply from: '../common.gradle' +apply plugin: 'kotlin-android' if (project.file('local.gradle').exists()) { apply from: 'local.gradle' @@ -34,7 +35,7 @@ repositories { url "https://jitpack.io" } flatDir { - dirs 'libs' + dirs project(':app').file('libs'), project(':wear').file('libs') } } @@ -68,11 +69,8 @@ def getLocalProperty(String propertyName) { } android { - compileSdkVersion 29 + compileSdk 34 - dexOptions { - javaMaxHeapSize "3g" - } configurations.all { resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9' @@ -82,7 +80,7 @@ android { // changes to databinding libraries can apparently result in nasty bugs on some handsets // the following checks that databinding dependencies are not changed from the tested configuration // 2.3.0 and 1.3.1 are from me.tatarka.bindingcollectionadapter2 - if (!["3.1.4", "2.3.0", "1.3.1", "3.4.3"].contains(details.target.version)) { + if (!["3.1.4", "2.3.0", "1.3.1", "3.4.3", "3.6.4", "7.4.2"].contains(details.target.version)) { throw new GradleException("Untested databinding version: " + details.requested.group + " " + details.requested.name + "- " + details.requested.version + " - " + details.target.version) } } @@ -91,10 +89,10 @@ android { defaultConfig { applicationId "com.eveningoutpost.dexdrip" - minSdkVersion 21 + minSdkVersion 24 // increasing target SDK version can cause compatibility issues with Android 7+ //noinspection ExpiredTargetSdkVersion - targetSdkVersion 23 + targetSdkVersion 24 // change versionCode only when downgrade should be prevented // eg, when data structures are incompatible versionCode 1603091400 @@ -104,12 +102,14 @@ android { buildConfigField "long", "buildTimestamp", generateTimestamp() buildConfigField "int", "targetSDK", targetSdkVersion.mApiLevel.toString() //vectorDrawables.useSupportLibrary = true // broken in newer gradle versions - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - multiDexEnabled true + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' + multiDexEnabled false // To get a Google Maps API key, follow this link, follow the directions and press "Create" at the end: // https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=7C:1E:BB:15:CE:A1:92:30:47:9D:D0:3D:89:F6:C6:51:7D:3C:1B:DD%3Bcom.eveningoutpost.dexdrip - manifestPlaceholders = [google_maps_key:getLocalProperty('google_maps_key')] + manifestPlaceholders = [google_maps_key:getLocalProperty('google_maps_key'), + 'appAuthRedirectScheme': 'xdrip' + ] } // The defaultConfig values above are fixed, so your incremental builds don't @@ -134,6 +134,7 @@ android { } lintOptions { + checkReleaseBuilds false disable 'MissingTranslation' disable 'ExtraTranslation' } @@ -145,6 +146,7 @@ android { } } + packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/INDEX.LIST' @@ -156,7 +158,13 @@ android { exclude 'META-INF/NOTICE' exclude 'org/apache/http/version.properties' exclude 'org/apache/http/client/version.properties' + //exclude 'META-INF/androidx.core_core.version' + exclude 'META-INF/com.android.tools/proguard/coroutines.pro' exclude 'META-INF/ASL2.0' + exclude 'META-INF/androidx.interpolator_interpolator.version' + exclude 'META-INF/androidx.core_core.version' + pickFirst 'org/bouncycastle/x509/CertPathReviewerMessages.properties' + pickFirst 'org/bouncycastle/x509/CertPathReviewerMessages_de.properties' } compileOptions { @@ -190,7 +198,6 @@ android { dev { minifyEnabled false shrinkResources false - useProguard false ext.enableCrashlytics = false ext.alwaysUpdateBuildId = false versionNameSuffix "-debug" @@ -209,7 +216,7 @@ android { // set minSdkVersion to 21 or higher. When using Android Studio 2.3 or higher, // the build automatically avoids legacy multidex when deploying to a device running // API level 21 or higher—regardless of what you set as your minSdkVersion. - minSdkVersion 21 + minSdkVersion 24 versionNameSuffix "-dev" buildConfigField "int", "buildVersion", "2021010100" buildConfigField "String", "buildUUID", "\"0f79a60a-5616-99be-8eb1-a430edcfd9fd\"" @@ -229,7 +236,7 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.android.support.constraint:constraint-layout:1.1.3' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' wearApp project(':wear') //weapApp files('../wear/build/outputs/apk/wear_release.apk') //testimplementation 'com.squareup.okhttp:mockwebserver:2.5.0' @@ -238,6 +245,7 @@ dependencies { } implementation project(':localeapi') + implementation project(':libkeks') // add missing JAXB dependencies for JDK 9+ if (JavaVersion.current().ordinal() >= JavaVersion.VERSION_1_9.ordinal()) { @@ -245,12 +253,27 @@ dependencies { annotationProcessor 'org.glassfish.jaxb:jaxb-runtime:2.3.5' } - implementation 'com.android.support:appcompat-v7:26.1.0' - implementation 'com.android.support:design:26.1.0' - implementation 'com.android.support:support-v13:26.1.0' - implementation 'com.android.support:recyclerview-v7:26.1.0' - implementation 'com.android.support:cardview-v7:26.1.0' - implementation 'com.android.support:preference-v7:26.1.0' + // app auth implementation + //implementation(name: 'core-1.1.0', ext: 'aar') + implementation(name: 'appauth-release', ext: 'aar') { + exclude group: 'androidx.core', module: 'core' // fix INotificationSideChannel // android.support.v4.app + } + implementation("androidx.browser:browser:1.3.0") { + exclude group: 'androidx.core', module: 'core' // fix INotificationSideChannel // android.support.v4.app + } + + api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1" + implementation(name: 'ns-sdk-full-release', ext: 'aar') + + //implementation 'androidx.core:core-ktx:1.9.0' + implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.8.22' + + implementation ('androidx.appcompat:appcompat:1.0.0') + implementation ('com.google.android.material:material:1.1.0') + implementation ('androidx.legacy:legacy-support-v13:1.0.0') + implementation ('androidx.recyclerview:recyclerview:1.0.0') + implementation ('androidx.cardview:cardview:1.0.0') + implementation ('androidx.preference:preference:1.0.0') implementation ('com.google.apis:google-api-services-drive:v3-rev20220815-2.0.0') { exclude group: 'org.apache.httpcomponents' @@ -279,6 +302,9 @@ dependencies { implementation 'com.google.code.gson:gson:2.8.6' implementation 'com.squareup.retrofit:converter-gson:2.0.0-beta2' implementation 'com.getpebble:pebblekit:3.1.0' + implementation ("androidx.health.connect:connect-client:1.1.0-alpha06") { + exclude group: 'androidx.core', module: 'core' + } implementation 'com.github.jamorham:amazfitcommunication:master-SNAPSHOT' implementation 'io.reactivex:rxjava:1.3.3' implementation "com.polidea.rxandroidble2:rxandroidble:1.12.1" @@ -286,7 +312,7 @@ dependencies { implementation 'com.embarkmobile:zxing-android-minimal:2.0.0@aar' implementation 'com.embarkmobile:zxing-android-integration:2.0.0@aar' //implementation 'com.embarkmobile:zxing-android-legacy:2.0.0@aar' - implementation 'com.google.zxing:core:3.1.0' + implementation 'com.google.zxing:core:3.5.1' implementation 'net.tribe7.seeds:seeds-functional:16.0.1' implementation 'net.tribe7.seeds:seeds-primitives:16.0.1' implementation 'me.tatarka.bindingcollectionadapter2:bindingcollectionadapter:2.2.0' @@ -309,19 +335,27 @@ dependencies { implementation 'org.apache.commons:commons-text:1.3' implementation 'com.google.dagger:dagger:2.25.4' implementation "com.evernote:android-job:1.2.6" - implementation 'com.android.support:multidex:1.0.3' + //implementation 'com.android.support:multidex:1.0.3' //implementation 'com.google.dagger:dagger-android-support:2.x' // if you use the support libraries annotationProcessor 'com.google.dagger:dagger-compiler:2.25.4' implementation 'net.danlew:android.joda:2.10.6.1' + implementation 'org.bouncycastle:bcpkix-jdk15to18:1.68' + + def appCenterSdkVersion = '4.4.5' + implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}" + implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}" + testImplementation 'joda-time:joda-time:2.10.7' testImplementation 'junit:junit:4.13.2' testImplementation 'org.objenesis:objenesis:2.5.1' testImplementation 'org.hamcrest:hamcrest-library:1.3' - testImplementation "org.robolectric:robolectric:4.2.1" + testImplementation "org.robolectric:robolectric:4.11.1" testImplementation "com.google.truth:truth:1.1.3" - testImplementation 'org.mockito:mockito-core:2.4.0' + testImplementation 'org.mockito:mockito-inline:2.13.0' + testImplementation 'org.mockito:mockito-core:4.11.0' + testImplementation 'org.powermock:powermock-core:1.7.1' testImplementation 'org.powermock:powermock-module-junit4:1.7.1' testImplementation 'org.powermock:powermock-module-junit4-rule:1.7.1' @@ -332,13 +366,13 @@ dependencies { exclude group: 'com.android.support' } // espresso, workarounds needed for correct functioning - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1', { + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0', { exclude group: 'com.android.support', module: 'support-annotations' } - androidTestImplementation 'com.android.support.test:runner:1.0.2', { + androidTestImplementation 'androidx.test.ext:junit:1.1.1', { exclude group: 'com.android.support', module: 'support-annotations' } - androidTestImplementation 'com.android.support.test.espresso:espresso-idling-resource:3.0.1' + androidTestImplementation 'androidx.test.espresso:espresso-idling-resource:3.1.0' // add this for intent mocking support //androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.1' // add this for webview testing support diff --git a/app/libs/appauth-release.aar b/app/libs/appauth-release.aar new file mode 100644 index 0000000000..66ae29747e Binary files /dev/null and b/app/libs/appauth-release.aar differ diff --git a/app/libs/hellocharts-library-release.aar b/app/libs/hellocharts-library-release.aar index 539b24ee91..30e44c1a67 100644 Binary files a/app/libs/hellocharts-library-release.aar and b/app/libs/hellocharts-library-release.aar differ diff --git a/app/libs/ns-sdk-full-release.aar b/app/libs/ns-sdk-full-release.aar new file mode 100644 index 0000000000..b1eb2082fd Binary files /dev/null and b/app/libs/ns-sdk-full-release.aar differ diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 7bf26d5069..ebbec48de7 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -56,13 +56,13 @@ -keep class org.slf4j.** { *; } -keep class rx.internal.util.** { *; } -keep class sun.misc.Unsafe { *; } --keep class com.eveningoutpost.dexdrip.Models.** { *; } -keep class com.eveningoutpost.dexdrip.models.** { *; } --keep class com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.** { *; } +-keep class com.eveningoutpost.dexdrip.models.** { *; } +-keep class com.eveningoutpost.dexdrip.importedlibraries.usbserial.** { *; } -keep class com.eveningoutpost.dexdrip.importedlibraries.usbserial.** { *; } -keep class ar.com.hjg.pngj.** { *; } -keep class android.support.v7.widget.SearchView { *; } - +-keep class kotlinx.serialization.Serializable { *; } -dontwarn java.util.concurrent.** diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index dc602e0bcf..73df543f1f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,9 +4,11 @@ package="com.eveningoutpost.dexdrip" android:installLocation="internalOnly" tools:ignore="InnerclassSeparator"> + + - - + + + + @@ -58,6 +62,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:exported="false" + android:label="Cloud Backup" /> + android:value="com.eveningoutpost.dexdrip.models.ActiveBgAlert,com.eveningoutpost.dexdrip.models.ActiveBluetoothDevice,com.eveningoutpost.dexdrip.models.AlertType,com.eveningoutpost.dexdrip.models.BgReading,com.eveningoutpost.dexdrip.models.BgReadingArchive,com.eveningoutpost.dexdrip.models.BgReading,com.eveningoutpost.dexdrip.models.Calibration,com.eveningoutpost.dexdrip.models.Calibration,com.eveningoutpost.dexdrip.models.CalibrationRequest,com.eveningoutpost.dexdrip.models.Sensor,com.eveningoutpost.dexdrip.models.TransmitterData,com.eveningoutpost.dexdrip.models.Treatments,com.eveningoutpost.dexdrip.models.UserError,com.eveningoutpost.dexdrip.models.UserNotification,com.eveningoutpost.dexdrip.sharemodels.models,com.eveningoutpost.dexdrip.utilitymodels.BgSendQueue,com.eveningoutpost.dexdrip.utilitymodels.CalibrationSendQueue,com.eveningoutpost.dexdrip.utilitymodels.SensorSendQueue,com.eveningoutpost.dexdrip.models.HeartRate,com.eveningoutpost.dexdrip.models.StepCounter,com.eveningoutpost.dexdrip.utilitymodels.UploaderQueue,com.eveningoutpost.dexdrip.models.BloodTest,com.eveningoutpost.dexdrip.models.Accuracy,com.eveningoutpost.dexdrip.models.Reminder,com.eveningoutpost.dexdrip.models.LibreData,com.eveningoutpost.dexdrip.models.LibreBlock,com.eveningoutpost.dexdrip.models.APStatus,com.eveningoutpost.dexdrip.models.Prediction,com.eveningoutpost.dexdrip.models.DesertSync,com.eveningoutpost.dexdrip.models.PenData,com.eveningoutpost.dexdrip.models.Libre2RawValue,com.eveningoutpost.dexdrip.models.Libre2Sensor" /> @@ -96,6 +150,12 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" /> + + + + + + + + + + + - - + + --> @@ -287,6 +360,10 @@ + + + + + + + + + + + + + @@ -524,7 +610,7 @@ - + @@ -536,7 +622,7 @@ - + @@ -559,7 +645,7 @@ @@ -570,7 +656,7 @@ android:resource="@xml/accessibility_service" /> @@ -646,7 +733,7 @@ android:screenOrientation="landscape" /> @@ -734,7 +821,7 @@ android:name="com.sec.android.multiwindow.MINIMUM_SIZE_H" android:value="598.0dip" /> - + + + - + \ No newline at end of file diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ActivityWithRecycler.java b/app/src/main/java/com/eveningoutpost/dexdrip/ActivityWithRecycler.java index 1c67b33376..156042ec57 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ActivityWithRecycler.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ActivityWithRecycler.java @@ -4,16 +4,17 @@ import android.graphics.Color; import android.graphics.PointF; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.LinearSmoothScroller; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.helper.ItemTouchHelper; + import android.util.AttributeSet; import android.util.DisplayMetrics; import android.view.View; import android.view.ViewGroup; +import androidx.recyclerview.widget.ItemTouchHelper; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.LinearSmoothScroller; +import androidx.recyclerview.widget.RecyclerView; + /** * Created by jamorham on 01/02/2017. */ diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/AddCalibration.java b/app/src/main/java/com/eveningoutpost/dexdrip/AddCalibration.java index 1435550b3f..cc49ab624f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/AddCalibration.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/AddCalibration.java @@ -3,31 +3,33 @@ import android.content.Intent; import android.os.Bundle; import android.os.PowerManager; -import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.AppCompatActivity; + import android.text.TextUtils; import android.view.View; import android.widget.Button; import android.widget.EditText; -import com.eveningoutpost.dexdrip.G5Model.FirmwareCapability; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.UndoRedo; +import com.eveningoutpost.dexdrip.g5model.FirmwareCapability; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.UndoRedo; import com.eveningoutpost.dexdrip.calibrations.NativeCalibrationPipe; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import java.util.UUID; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.getTransmitterID; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.getTransmitterID; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.drawerlayout.widget.DrawerLayout; public class AddCalibration extends AppCompatActivity implements NavigationDrawerFragment.NavigationDrawerCallbacks { // Unit used diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Agreement.java b/app/src/main/java/com/eveningoutpost/dexdrip/Agreement.java index c43e932f07..3c0bccab2c 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Agreement.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/Agreement.java @@ -4,12 +4,11 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.CheckBox; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; public class Agreement extends BaseAppCompatActivity { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/AlertList.java b/app/src/main/java/com/eveningoutpost/dexdrip/AlertList.java index 5c7ba6910b..0225247530 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/AlertList.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/AlertList.java @@ -8,14 +8,11 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.graphics.Paint; -import android.media.Ringtone; -import android.media.RingtoneManager; -import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; @@ -25,10 +22,10 @@ import android.widget.SimpleAdapter; import android.widget.TextView; -import com.eveningoutpost.dexdrip.Models.AlertType; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; +import com.eveningoutpost.dexdrip.models.AlertType; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; import com.eveningoutpost.dexdrip.utils.ActivityWithMenu; import java.text.ParseException; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/AutoStart.java b/app/src/main/java/com/eveningoutpost/dexdrip/AutoStart.java index 22c8f92db1..d915a63c29 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/AutoStart.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/AutoStart.java @@ -4,11 +4,11 @@ import android.content.Context; import android.content.Intent; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Services.PlusSyncService; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.services.PlusSyncService; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/BGHistory.java b/app/src/main/java/com/eveningoutpost/dexdrip/BGHistory.java index 3b20da0ad5..f0edae7b1f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/BGHistory.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/BGHistory.java @@ -16,8 +16,8 @@ import android.widget.TextView; import android.widget.Toast; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.stats.StatsResult; import com.eveningoutpost.dexdrip.utils.ActivityWithMenu; @@ -50,6 +50,8 @@ public class BGHistory extends ActivityWithMenu { private int noDays = 1; private SharedPreferences prefs; private TextView statisticsTextView; + private static final int SAMPLE_PERIOD = 1; // In minutes - The time between two consecutive readings - The lowest period we currently support: 1 minute + private static final int GRACE_READINGS_PER_DAY = 2; // When switching from one source to another, there may be a misalignment in sample timing resulting in more readings per day @Override protected void onCreate(Bundle savedInstanceState) { @@ -148,7 +150,7 @@ private void setupCharts() { Calendar endDate = (GregorianCalendar) date1.clone(); endDate.add(Calendar.DATE, noDays); - int numValues = noDays * (60 / 2) * 24; // LimiTTer sample rate 1 per 2 minutes + int numValues = noDays * (24 * (60 / SAMPLE_PERIOD) + GRACE_READINGS_PER_DAY); // The highest sample rate we currently support BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(this, date1.getTimeInMillis(), endDate.getTimeInMillis(), numValues, false); chart = (LineChartView) findViewById(R.id.chart); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/BaseAppCompatActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/BaseAppCompatActivity.java index 29540989e4..d0873fce01 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/BaseAppCompatActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/BaseAppCompatActivity.java @@ -3,7 +3,9 @@ // jamorham import android.content.Context; -import android.support.v7.app.AppCompatActivity; + +import androidx.appcompat.app.AppCompatActivity; + public abstract class BaseAppCompatActivity extends AppCompatActivity { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/BestGlucose.java b/app/src/main/java/com/eveningoutpost/dexdrip/BestGlucose.java index 1ccf3150d5..9e391da2ca 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/BestGlucose.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/BestGlucose.java @@ -1,26 +1,25 @@ package com.eveningoutpost.dexdrip; import android.content.SharedPreferences; -import android.graphics.Color; import android.preference.PreferenceManager; import android.text.SpannableString; import android.text.style.ForegroundColorSpan; import android.text.style.StrikethroughSpan; import android.util.Log; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.SensorSanity; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.ColorCache; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.SensorSanity; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.ColorCache; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.calibrations.CalibrationAbstract; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import java.util.List; -import static com.eveningoutpost.dexdrip.UtilityModels.ColorCache.getCol; +import static com.eveningoutpost.dexdrip.utilitymodels.ColorCache.getCol; import static com.eveningoutpost.dexdrip.calibrations.PluggableCalibration.getCalibrationPluginFromPreferences; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/BindingAdapterUtils.java b/app/src/main/java/com/eveningoutpost/dexdrip/BindingAdapterUtils.java index 4e6c393f29..9b9f36651a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/BindingAdapterUtils.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/BindingAdapterUtils.java @@ -3,9 +3,9 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; -import android.databinding.BindingAdapter; +import androidx.databinding.BindingAdapter; import android.graphics.Typeface; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import android.view.View; import android.widget.Button; import android.widget.CompoundButton; @@ -13,9 +13,9 @@ import android.widget.LinearLayout; import android.widget.TextView; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.FINAL_VISIBILITY_ID; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.FINAL_VISIBILITY_ID; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/BluetoothScan.java b/app/src/main/java/com/eveningoutpost/dexdrip/BluetoothScan.java index 0cf16881fd..1fb60afbf5 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/BluetoothScan.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/BluetoothScan.java @@ -31,14 +31,14 @@ import android.widget.Toast; import com.activeandroid.query.Select; -import com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.Blukon; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.ActiveBluetoothDevice; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Blukon; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.cgm.medtrum.Medtrum; import com.eveningoutpost.dexdrip.utils.AndroidBarcode; import com.eveningoutpost.dexdrip.utils.ListActivityWithMenu; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/CalibrationCheckInActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/CalibrationCheckInActivity.java index 1f667ef6b9..aed7569460 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/CalibrationCheckInActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/CalibrationCheckInActivity.java @@ -3,14 +3,14 @@ import android.content.Intent; import android.os.Bundle; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; import android.view.View; import android.widget.Button; import android.widget.Toast; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.SyncingService; -import com.eveningoutpost.dexdrip.Models.Sensor; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.SyncingService; +import com.eveningoutpost.dexdrip.models.Sensor; import com.eveningoutpost.dexdrip.utils.ActivityWithMenu; public class CalibrationCheckInActivity extends ActivityWithMenu { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/CalibrationGraph.java b/app/src/main/java/com/eveningoutpost/dexdrip/CalibrationGraph.java index e11599a789..021e867ff8 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/CalibrationGraph.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/CalibrationGraph.java @@ -3,8 +3,9 @@ import android.content.DialogInterface; import android.graphics.Color; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v7.app.AlertDialog; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; + import android.text.InputType; import android.text.TextUtils; import android.view.Menu; @@ -12,11 +13,11 @@ import android.widget.EditText; import android.widget.TextView; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.CalibrationSendQueue; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.CalibrationSendQueue; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.calibrations.CalibrationAbstract; import com.eveningoutpost.dexdrip.utils.ActivityWithMenu; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/CalibrationOverride.java b/app/src/main/java/com/eveningoutpost/dexdrip/CalibrationOverride.java index b18481343d..f4a41808e8 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/CalibrationOverride.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/CalibrationOverride.java @@ -4,22 +4,21 @@ import android.os.Bundle; import android.text.TextUtils; -import com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.UserError.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.UndoRedo; -import com.eveningoutpost.dexdrip.UtilityModels.CalibrationSendQueue; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.UndoRedo; +import com.eveningoutpost.dexdrip.utilitymodels.CalibrationSendQueue; import com.eveningoutpost.dexdrip.calibrations.NativeCalibrationPipe; import com.eveningoutpost.dexdrip.utils.ActivityWithMenu; -import com.eveningoutpost.dexdrip.wearintegration.WatchUpdaterService; + import static com.eveningoutpost.dexdrip.Home.startWatchUpdaterService; import static com.eveningoutpost.dexdrip.xdrip.gs; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/DoubleCalibrationActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/DoubleCalibrationActivity.java index 61b8ec73f5..aed990e54a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/DoubleCalibrationActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/DoubleCalibrationActivity.java @@ -6,20 +6,20 @@ import android.os.Bundle; import android.text.TextUtils; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.UserError.Log; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.PrefsViewImpl; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.PrefsViewImpl; import com.eveningoutpost.dexdrip.databinding.ActivityDoubleCalibrationBinding; import com.eveningoutpost.dexdrip.utils.ActivityWithMenu; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/EditAlertActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/EditAlertActivity.java index ea7776b4e2..5551f78785 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/EditAlertActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/EditAlertActivity.java @@ -17,9 +17,9 @@ import android.os.Bundle; import android.preference.PreferenceManager; import android.provider.MediaStore; -import android.support.annotation.NonNull; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; +import androidx.annotation.NonNull; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; import android.text.InputType; import android.text.format.DateFormat; import android.text.method.DigitsKeyListener; @@ -37,13 +37,14 @@ import android.widget.TimePicker; import android.widget.Toast; -import com.eveningoutpost.dexdrip.Models.AlertType; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.AlertType; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.ui.dialog.GenericConfirmDialog; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.ActivityWithMenu; import com.eveningoutpost.dexdrip.watch.thinjam.BlueJayEntry; import com.eveningoutpost.dexdrip.wearintegration.WatchUpdaterService; @@ -272,7 +273,7 @@ protected void onCreate(Bundle savedInstanceState) { audioPath = getExtra(savedInstanceState, "audioPath" ,alertType.mp3_file); alertMp3File.setText(shortPath(audioPath)); - status = "editing " + (above ? "high" : "low") + " alert"; + status = getString(R.string.editing)+" " + (above ? getString(R.string.high) : getString(R.string.low)) + " "+getString(R.string.alert); startHour = AlertType.time2Hours(alertType.start_time_minutes); startMinute = AlertType.time2Minutes(alertType.start_time_minutes); endHour = AlertType.time2Hours(alertType.end_time_minutes); @@ -565,19 +566,20 @@ public void onClick(View v) { buttonRemove.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { - - - if (uuid == null) { - Log.wtf(TAG, "Error remove pressed, while we were adding an alert"); - } else { - AlertType.remove_alert(uuid); - startWatchUpdaterService(mContext, WatchUpdaterService.ACTION_SYNC_ALERTTYPE, TAG); - } - Intent returnIntent = new Intent(); - setResult(RESULT_OK,returnIntent); - finish(); + GenericConfirmDialog.show(EditAlertActivity.this, gs(R.string.are_you_sure), gs(R.string.you_cannot_undo_delete_alert), + () -> { // This, which deletes the alert, will only be executed after confirmation + if (uuid == null) { + Log.wtf(TAG, "Error remove pressed, while we were adding an alert"); + } else { + AlertType.remove_alert(uuid); + startWatchUpdaterService(mContext, WatchUpdaterService.ACTION_SYNC_ALERTTYPE, TAG); + } + Intent returnIntent = new Intent(); + setResult(RESULT_OK, returnIntent); + finish(); + } + ); } - }); buttonTest.setOnClickListener(new View.OnClickListener() { @@ -941,8 +943,8 @@ public void testAlert() { if (Pref.getBooleanDefaultFalse("start_snoozed")) { JoH.static_toast_long("Start Snoozed setting means alert would normally start silent"); - } else if (Pref.getStringDefaultBlank("bg_alert_profile").equals("ascending")) { - JoH.static_toast_long("Ascending Volume Profile means it will start silent"); + } else if (Pref.getStringDefaultBlank("bg_alert_profile").equals("ascending") && Pref.getBoolean("delay_ascending_3min", true)) { + JoH.static_toast_long("Ascending Volume Profile + delayed ascending means it will start silent"); } else if (Pref.getStringDefaultBlank("bg_alert_profile").equals("Silent")) { JoH.static_toast_long("Volume Profile is set to silent!"); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ErrorListAdapter.java b/app/src/main/java/com/eveningoutpost/dexdrip/ErrorListAdapter.java index a67773011f..83cdfa8cfa 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ErrorListAdapter.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ErrorListAdapter.java @@ -9,7 +9,7 @@ import android.widget.LinearLayout; import android.widget.TextView; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import java.text.DateFormat; import java.util.Date; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ErrorsActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/ErrorsActivity.java index 22b7fba622..cdecd4fe29 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ErrorsActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ErrorsActivity.java @@ -13,10 +13,10 @@ import android.widget.Switch; import android.widget.Toast; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.SendFeedBack; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.SendFeedBack; import com.eveningoutpost.dexdrip.utils.ActivityWithMenu; import com.eveningoutpost.dexdrip.wearintegration.WatchUpdaterService; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/EventLogActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/EventLogActivity.java index 4e5b092f7a..3fba4b8de2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/EventLogActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/EventLogActivity.java @@ -1,17 +1,19 @@ package com.eveningoutpost.dexdrip; import android.content.Intent; -import android.databinding.ObservableArrayList; -import android.databinding.ObservableBoolean; -import android.databinding.ObservableList; -import android.databinding.ViewDataBinding; + +import androidx.appcompat.widget.SearchView; +import androidx.databinding.ObservableArrayList; +import androidx.databinding.ObservableBoolean; +import androidx.databinding.ObservableList; +import androidx.databinding.ViewDataBinding; import android.graphics.Color; import android.os.Bundle; -import android.support.annotation.LayoutRes; -import android.support.v4.view.MenuItemCompat; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.SearchView; +import androidx.annotation.LayoutRes; +import androidx.core.view.MenuItemCompat; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import android.util.SparseBooleanArray; import android.util.TypedValue; import android.view.LayoutInflater; @@ -26,12 +28,12 @@ import android.widget.CompoundButton; import android.widget.TextView; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.SendFeedBack; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.SendFeedBack; import com.eveningoutpost.dexdrip.databinding.ActivityEventLogBinding; import com.eveningoutpost.dexdrip.ui.helpers.BitmapUtil; import com.eveningoutpost.dexdrip.utils.ExtensionMethods; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/FakeNumbers.java b/app/src/main/java/com/eveningoutpost/dexdrip/FakeNumbers.java index d56eb1ca2a..74be094b58 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/FakeNumbers.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/FakeNumbers.java @@ -2,24 +2,19 @@ import java.util.Date; -import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.DatePicker; import android.widget.EditText; import android.widget.TimePicker; -import com.eveningoutpost.dexdrip.Models.ActiveBgAlert; -import com.eveningoutpost.dexdrip.Models.AlertType; -import com.eveningoutpost.dexdrip.Models.BgReading; +import com.eveningoutpost.dexdrip.models.ActiveBgAlert; +import com.eveningoutpost.dexdrip.models.AlertType; +import com.eveningoutpost.dexdrip.models.BgReading; import com.eveningoutpost.dexdrip.utils.ActivityWithMenu; -import java.util.Date; - public class FakeNumbers extends ActivityWithMenu { public static String menu_name = "Fake Numbers"; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/FauxActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/FauxActivity.java index 808001b76a..4dd4bafa9a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/FauxActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/FauxActivity.java @@ -3,8 +3,8 @@ import android.content.Intent; import android.os.Bundle; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; /** * Created by jamorham on 09/01/2017. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/FollowerListAdapter.java b/app/src/main/java/com/eveningoutpost/dexdrip/FollowerListAdapter.java index 95eb85a877..0698c4887a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/FollowerListAdapter.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/FollowerListAdapter.java @@ -9,8 +9,8 @@ import android.widget.TextView; import android.widget.Toast; -import com.eveningoutpost.dexdrip.ShareModels.Models.ExistingFollower; -import com.eveningoutpost.dexdrip.ShareModels.ShareRest; +import com.eveningoutpost.dexdrip.sharemodels.models.ExistingFollower; +import com.eveningoutpost.dexdrip.sharemodels.ShareRest; import com.squareup.okhttp.ResponseBody; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/FollowerManagementActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/FollowerManagementActivity.java index f22b609137..d396d40df7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/FollowerManagementActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/FollowerManagementActivity.java @@ -12,9 +12,9 @@ import android.widget.ListView; import android.widget.Toast; -import com.eveningoutpost.dexdrip.ShareModels.Models.ExistingFollower; -import com.eveningoutpost.dexdrip.ShareModels.Models.InvitationPayload; -import com.eveningoutpost.dexdrip.ShareModels.ShareRest; +import com.eveningoutpost.dexdrip.sharemodels.models.ExistingFollower; +import com.eveningoutpost.dexdrip.sharemodels.models.InvitationPayload; +import com.eveningoutpost.dexdrip.sharemodels.ShareRest; import com.eveningoutpost.dexdrip.utils.ActivityWithMenu; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/GcmActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/GcmActivity.java index 51a1e89bad..447dfef44f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/GcmActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/GcmActivity.java @@ -13,27 +13,28 @@ import android.os.Handler; import android.os.PowerManager; import android.preference.PreferenceManager; -import android.support.v4.content.LocalBroadcastManager; + import android.widget.Toast; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.DesertSync; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.RollCall; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.Services.PlusSyncService; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.InstalledApps; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.DesertSync; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.RollCall; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.services.PlusSyncService; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.InstalledApps; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.CipherUtils; import com.eveningoutpost.dexdrip.utils.DisplayQRCode; import com.eveningoutpost.dexdrip.utils.SdcardImportExport; +import com.eveningoutpost.dexdrip.watch.thinjam.BlueJayEntry; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GoogleApiAvailability; import com.google.android.gms.gcm.GoogleCloudMessaging; @@ -52,9 +53,11 @@ import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -import static com.eveningoutpost.dexdrip.Models.JoH.isOldVersion; +import static com.eveningoutpost.dexdrip.models.JoH.isOldVersion; import static com.eveningoutpost.dexdrip.xdrip.gs; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; + /** * Created by jamorham on 11/01/16. */ @@ -862,9 +865,11 @@ public void onReceive(Context context, Intent intent) { xdrip.getAppContext().startService(intent); } else { cease_all_activity = true; - final String msg = "ERROR: Connecting to Google Services - check google login or reboot?"; - JoH.static_toast_long(msg); - Home.toaststaticnext(msg); + if (!BlueJayEntry.isNative()) { + final String msg = "ERROR: Connecting to Google Services - check google login or reboot?"; + JoH.static_toast_long(msg); + Home.toaststaticnext(msg); + } } } @@ -996,6 +1001,7 @@ static Boolean checkPlayServices(Context context, Activity activity) { if (resultCode != ConnectionResult.SUCCESS) { try { if (apiAvailability.isUserResolvableError(resultCode)) { + if (resultCode == 3 && BlueJayEntry.isNative()) return false; if (activity != null) { apiAvailability.getErrorDialog(activity, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST) .show(); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/GcmListenerSvc.java b/app/src/main/java/com/eveningoutpost/dexdrip/GcmListenerSvc.java index a99dc18d12..0e2211199d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/GcmListenerSvc.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/GcmListenerSvc.java @@ -1,7 +1,5 @@ package com.eveningoutpost.dexdrip; -import android.R.integer; - /** * Created by jamorham on 11/01/16. */ @@ -18,28 +16,28 @@ import android.os.PowerManager; import android.util.Base64; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.DesertSync; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.LibreBlock; -import com.eveningoutpost.dexdrip.Models.RollCall; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.SensorSanity; -import com.eveningoutpost.dexdrip.Models.TransmitterData; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.Services.ActivityRecognizedService; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.NanoStatus; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.PumpStatus; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; -import com.eveningoutpost.dexdrip.UtilityModels.WholeHouse; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.DesertSync; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.LibreBlock; +import com.eveningoutpost.dexdrip.models.RollCall; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.SensorSanity; +import com.eveningoutpost.dexdrip.models.TransmitterData; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.services.ActivityRecognizedService; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.NanoStatus; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.PumpStatus; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; +import com.eveningoutpost.dexdrip.utilitymodels.WholeHouse; import com.eveningoutpost.dexdrip.utils.CheckBridgeBattery; import com.eveningoutpost.dexdrip.utils.CipherUtils; import com.eveningoutpost.dexdrip.utils.Preferences; @@ -56,9 +54,8 @@ import java.util.List; import java.util.Map; -import static android.support.v4.content.WakefulBroadcastReceiver.completeWakefulIntent; -import static com.eveningoutpost.dexdrip.Models.JoH.isAnyNetworkConnected; -import static com.eveningoutpost.dexdrip.Models.JoH.showNotification; +import static com.eveningoutpost.dexdrip.models.JoH.isAnyNetworkConnected; +import static com.eveningoutpost.dexdrip.models.JoH.showNotification; public class GcmListenerSvc extends JamListenerSvc { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/GoogleDriveInterface.java b/app/src/main/java/com/eveningoutpost/dexdrip/GoogleDriveInterface.java index 8b077fbe4d..1b1f034690 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/GoogleDriveInterface.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/GoogleDriveInterface.java @@ -9,7 +9,7 @@ import android.preference.PreferenceManager; import android.util.Log; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.utils.CipherUtils; import com.google.android.gms.common.api.GoogleApiClient; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/HealthPrivacy.java b/app/src/main/java/com/eveningoutpost/dexdrip/HealthPrivacy.java new file mode 100644 index 0000000000..6374750d66 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/HealthPrivacy.java @@ -0,0 +1,25 @@ +package com.eveningoutpost.dexdrip; + + +import android.os.Bundle; +import android.view.View; + +import androidx.appcompat.app.AppCompatActivity; + +import com.eveningoutpost.dexdrip.models.JoH; + +// jamorham + +public class HealthPrivacy extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_health_privacy); + JoH.fixActionBar(this); + } + + public void healthPrivacyClose(View view) { + finish(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/HelpActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/HelpActivity.java index df0ec8c0db..b10fd1519f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/HelpActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/HelpActivity.java @@ -1,10 +1,9 @@ package com.eveningoutpost.dexdrip; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; import android.webkit.WebView; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; public class HelpActivity extends BaseAppCompatActivity { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Home.java b/app/src/main/java/com/eveningoutpost/dexdrip/Home.java index 26c45508bc..75ec69b26e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Home.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/Home.java @@ -1,15 +1,17 @@ package com.eveningoutpost.dexdrip; import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.Models.JoH.quietratelimit; -import static com.eveningoutpost.dexdrip.Models.JoH.tsl; -import static com.eveningoutpost.dexdrip.UtilityModels.ColorCache.X; -import static com.eveningoutpost.dexdrip.UtilityModels.ColorCache.getCol; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.DAY_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.HOUR_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.MINUTE_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.SECOND_IN_MS; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.shortTxId; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.quietratelimit; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.getTransmitterID; +import static com.eveningoutpost.dexdrip.utilitymodels.ColorCache.X; +import static com.eveningoutpost.dexdrip.utilitymodels.ColorCache.getCol; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.DAY_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.HOUR_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.SECOND_IN_MS; import static com.eveningoutpost.dexdrip.xdrip.gs; import android.Manifest; @@ -29,7 +31,6 @@ import android.graphics.Paint; import android.graphics.Point; import android.graphics.Typeface; -import android.graphics.drawable.ColorDrawable; import android.media.AudioManager; import android.net.Uri; import android.os.AsyncTask; @@ -39,14 +40,15 @@ import android.preference.PreferenceManager; import android.provider.Settings; import android.speech.RecognizerIntent; -import android.support.annotation.NonNull; -import android.support.annotation.RequiresApi; -import android.support.design.widget.Snackbar; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; -import android.support.v4.content.LocalBroadcastManager; -import android.support.v4.widget.DrawerLayout; -import android.support.v7.widget.Toolbar; +import androidx.annotation.NonNull; +import androidx.annotation.RequiresApi; + +import androidx.appcompat.widget.Toolbar; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import androidx.drawerlayout.widget.DrawerLayout; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; + import android.text.InputType; import android.util.DisplayMetrics; import android.util.Log; @@ -68,51 +70,53 @@ import android.widget.TextView; import android.widget.Toast; -import com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine; -import com.eveningoutpost.dexdrip.G5Model.SensorDays; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.ActiveBgAlert; -import com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.HeartRate; -import com.eveningoutpost.dexdrip.Models.InsulinInjection; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.LibreBlock; -import com.eveningoutpost.dexdrip.Models.ProcessInitialDataQuality; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.StepCounter; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Services.ActivityRecognizedService; -import com.eveningoutpost.dexdrip.Services.DexCollectionService; -import com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService; -import com.eveningoutpost.dexdrip.Services.PlusSyncService; -import com.eveningoutpost.dexdrip.Services.WixelReader; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.ColorCache; -import com.eveningoutpost.dexdrip.UtilityModels.CompatibleApps; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Experience; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Intents; -import com.eveningoutpost.dexdrip.UtilityModels.JamorhamShowcaseDrawer; -import com.eveningoutpost.dexdrip.UtilityModels.NanoStatus; -import com.eveningoutpost.dexdrip.UtilityModels.NightscoutUploader; -import com.eveningoutpost.dexdrip.UtilityModels.Notifications; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.PrefsViewImpl; -import com.eveningoutpost.dexdrip.UtilityModels.SendFeedBack; -import com.eveningoutpost.dexdrip.UtilityModels.ShotStateStore; -import com.eveningoutpost.dexdrip.UtilityModels.SourceWizard; -import com.eveningoutpost.dexdrip.UtilityModels.StatusLine; -import com.eveningoutpost.dexdrip.UtilityModels.UndoRedo; -import com.eveningoutpost.dexdrip.UtilityModels.UpdateActivity; -import com.eveningoutpost.dexdrip.UtilityModels.VoiceCommands; +import com.eveningoutpost.dexdrip.g5model.DexTimeKeeper; +import com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine; +import com.eveningoutpost.dexdrip.g5model.SensorDays; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.ActiveBgAlert; +import com.eveningoutpost.dexdrip.models.ActiveBluetoothDevice; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.HeartRate; +import com.eveningoutpost.dexdrip.models.InsulinInjection; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.LibreBlock; +import com.eveningoutpost.dexdrip.models.ProcessInitialDataQuality; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.StepCounter; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.services.ActivityRecognizedService; +import com.eveningoutpost.dexdrip.services.DexCollectionService; +import com.eveningoutpost.dexdrip.services.Ob1G5CollectionService; +import com.eveningoutpost.dexdrip.services.PlusSyncService; +import com.eveningoutpost.dexdrip.services.WixelReader; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.ColorCache; +import com.eveningoutpost.dexdrip.utilitymodels.CompatibleApps; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Experience; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Intents; +import com.eveningoutpost.dexdrip.utilitymodels.JamorhamShowcaseDrawer; +import com.eveningoutpost.dexdrip.utilitymodels.MockDataSource; +import com.eveningoutpost.dexdrip.utilitymodels.NanoStatus; +import com.eveningoutpost.dexdrip.utilitymodels.NightscoutUploader; +import com.eveningoutpost.dexdrip.utilitymodels.Notifications; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.PrefsViewImpl; +import com.eveningoutpost.dexdrip.utilitymodels.SendFeedBack; +import com.eveningoutpost.dexdrip.utilitymodels.ShotStateStore; +import com.eveningoutpost.dexdrip.utilitymodels.SourceWizard; +import com.eveningoutpost.dexdrip.utilitymodels.StatusLine; +import com.eveningoutpost.dexdrip.utilitymodels.UndoRedo; +import com.eveningoutpost.dexdrip.utilitymodels.UpdateActivity; +import com.eveningoutpost.dexdrip.utilitymodels.VoiceCommands; import com.eveningoutpost.dexdrip.calibrations.NativeCalibrationPipe; import com.eveningoutpost.dexdrip.calibrations.PluggableCalibration; import com.eveningoutpost.dexdrip.cloud.backup.BackupActivity; @@ -154,9 +158,11 @@ import com.github.amlcurran.showcaseview.ShowcaseView; import com.github.amlcurran.showcaseview.targets.Target; import com.github.amlcurran.showcaseview.targets.ViewTarget; +import com.google.android.material.snackbar.Snackbar; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.internal.bind.DateTypeAdapter; +import static com.eveningoutpost.dexdrip.utils.DexCollectionType.DexcomG5; import java.io.ByteArrayOutputStream; import java.io.File; @@ -330,8 +336,8 @@ public class Home extends ActivityWithMenu implements ActivityCompat.OnRequestPe private static Activity mActivity; @Getter - private static String statusIOB = ""; - private static String statusBWP = ""; + private volatile static String statusIOB = ""; + private volatile static String statusBWP = ""; @SuppressLint("ObsoleteSdkInt") @@ -673,7 +679,7 @@ public void run() { private void refreshStatusLine() { try { - String status = ((statusIOB.length() > 0) ? ("IoB: " + statusIOB) : "") + final String status = ((statusIOB.length() > 0) ? ("IoB: " + statusIOB) : "") + ((statusBWP.length() > 0) ? (" " + statusBWP) : ""); Log.d(TAG, "Refresh Status Line: " + status); //if (status.length() > 0) { @@ -1123,7 +1129,7 @@ public void cloudBackup(MenuItem x) { } public void crowdTranslate(MenuItem x) { - // startActivity(new Intent(this, LanguageEditor.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); + // startActivity(new Intent(this, LanguageEditor.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://crowdin.com/project/xdrip")).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } @@ -1822,7 +1828,9 @@ public static void staticRefreshBGCharts(boolean override) { reset_viewport = true; if (activityVisible || override) { Intent updateIntent = new Intent(Intents.ACTION_NEW_BG_ESTIMATE_NO_DATA); - mActivity.sendBroadcast(updateIntent); + if (mActivity != null) { + mActivity.sendBroadcast(updateIntent); + } } } @@ -1928,33 +1936,35 @@ public void onReceive(Context ctx, Intent intent) { } private void checkWifiSleepPolicy() { - if (!JoH.getWifiSleepPolicyNever()) { - if (JoH.ratelimit("policy-never", 3600)) { - if (Pref.getLong("wifi_warning_never", 0) == 0) { - if (!JoH.isMobileDataOrEthernetConnected()) { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(gs(R.string.wifi_sleep_policy_issue)); - builder.setMessage(gs(R.string.your_wifi_is_set_to_sleep_when_the_phone_screen_is_off__this_may_cause_problems_if_you_dont_have_cellular_data_or_have_devices_on_your_local_network__would_you_like_to_go_to_the_settings_page_to_set__always_keep_wifi_on_during_sleep)); - - builder.setNeutralButton(gs(R.string.maybe_later), (dialog, which) -> dialog.dismiss()); - - builder.setPositiveButton(gs(R.string.yes_do_it), (dialog, which) -> { - dialog.dismiss(); - toast(gs(R.string.recommend_that_you_change_wifi_to_always_be_on_during_sleep)); - try { - startActivity(new Intent(Settings.ACTION_WIFI_IP_SETTINGS)); - } catch (ActivityNotFoundException e) { - JoH.static_toast_long(gs(R.string.ooops_this_device_doesnt_seem_to_have_a_wifi_settings_page)); - } - }); + if (Build.VERSION.SDK_INT < 33) { // setting removed after android 12 + if (!JoH.getWifiSleepPolicyNever()) { + if (JoH.ratelimit("policy-never", 3600)) { + if (Pref.getLong("wifi_warning_never", 0) == 0) { + if (!JoH.isMobileDataOrEthernetConnected()) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(gs(R.string.wifi_sleep_policy_issue)); + builder.setMessage(gs(R.string.your_wifi_is_set_to_sleep_when_the_phone_screen_is_off__this_may_cause_problems_if_you_dont_have_cellular_data_or_have_devices_on_your_local_network__would_you_like_to_go_to_the_settings_page_to_set__always_keep_wifi_on_during_sleep)); + + builder.setNeutralButton(gs(R.string.maybe_later), (dialog, which) -> dialog.dismiss()); + + builder.setPositiveButton(gs(R.string.yes_do_it), (dialog, which) -> { + dialog.dismiss(); + toast(gs(R.string.recommend_that_you_change_wifi_to_always_be_on_during_sleep)); + try { + startActivity(new Intent(Settings.ACTION_WIFI_IP_SETTINGS)); + } catch (ActivityNotFoundException e) { + JoH.static_toast_long(gs(R.string.ooops_this_device_doesnt_seem_to_have_a_wifi_settings_page)); + } + }); - builder.setNegativeButton(R.string.no_never, (dialog, which) -> { - dialog.dismiss(); - Pref.setLong("wifi_warning_never", (long) JoH.ts()); - }); + builder.setNegativeButton(R.string.no_never, (dialog, which) -> { + dialog.dismiss(); + Pref.setLong("wifi_warning_never", (long) JoH.ts()); + }); - AlertDialog alert = builder.create(); - alert.show(); + AlertDialog alert = builder.create(); + alert.show(); + } } } } @@ -2170,7 +2180,7 @@ public static boolean hasLibreblock() { if (!has_libreblock_set) setHasLibreblock(); return has_libreblock; } - + public static boolean get_is_libre_whole_house_collector() { return Pref.getBooleanDefaultFalse("libre_whole_house_collector"); } @@ -2242,7 +2252,7 @@ public void toggleStepsVisibility(View v) { } public void sourceWizardButtonClick(View v) { - SourceWizard.start(this, true); + SourceWizard.start(Home.this, true); } private long whichTimeLocked() { @@ -2286,22 +2296,32 @@ private void setHoursViewPort(final String source) { break; } - float ideal_hours_to_show = DEFAULT_CHART_HOURS + bgGraphBuilder.getPredictivehours(); - // always show at least the ideal number of hours if locked or auto + // always show at least the ideal number of hours + float ideal_hours_to_show = DEFAULT_CHART_HOURS; + // ... and rescale to accommodate predictions if not locked + if (! homeShelf.get("time_locked_always")) { + ideal_hours_to_show += bgGraphBuilder.getPredictivehours(); + } float hours_to_show = exactHoursSpecified ? hours : Math.max(hours, ideal_hours_to_show); UserError.Log.d(TAG, "VIEWPORT " + source + " moveviewport in setHours: asked " + hours + " vs auto " + ideal_hours_to_show + " = " + hours_to_show + " full chart width: " + bgGraphBuilder.hoursShownOnChart()); - float hour_width = maxViewPort.width() / bgGraphBuilder.hoursShownOnChart(); + double hour_width = maxViewPort.width() / bgGraphBuilder.hoursShownOnChart(); holdViewport.left = maxViewPort.right - hour_width * hours_to_show; holdViewport.right = maxViewPort.right; holdViewport.top = maxViewPort.top; holdViewport.bottom = maxViewPort.bottom; - if (d) { - UserError.Log.d(TAG, "HOLD VIEWPORT " + holdViewport); - UserError.Log.d(TAG, "MAX VIEWPORT " + maxViewPort); - } + // if locked, center display on current bg values, not predictions + if (homeShelf.get("time_locked_always")) { + holdViewport.left -= hour_width * bgGraphBuilder.getPredictivehours(); + holdViewport.right -= hour_width * bgGraphBuilder.getPredictivehours(); + } + + if (d) { + UserError.Log.d(TAG, "HOLD VIEWPORT " + holdViewport); + UserError.Log.d(TAG, "MAX VIEWPORT " + maxViewPort); + } chart.setCurrentViewport(holdViewport); @@ -2354,7 +2374,7 @@ private void updateHealthInfo(String caller) { final StepCounter pm = StepCounter.last(); final boolean use_pebble_health = Pref.getBoolean("use_pebble_health", true); if ((use_pebble_health) && (pm != null)) { - stepsButton.setText(Integer.toString(pm.metric)); + stepsButton.setText(Integer.toString(StepCounter.getDailyTotal())); stepsButton.setVisibility(View.VISIBLE); // TODO this can be done with PrefsView binding stepsButton.setAlpha(Pref.getBoolean("show_pebble_movement_line", true) ? 1.0f : 0.3f); @@ -2382,8 +2402,8 @@ private void updateCurrentBgInfo(final String source) { } if (reset_viewport) { reset_viewport = false; - // holdViewport.set(0, 0, 0, 0); - // if (chart != null) chart.setZoomType(ZoomType.HORIZONTAL); + // holdViewport.set(0, 0, 0, 0); + // if (chart != null) chart.setZoomType(ZoomType.HORIZONTAL); // TODO above reset viewport thing seems defunct now } setupCharts(source); @@ -2459,6 +2479,12 @@ private void updateCurrentBgInfo(final String source) { } } else if (collector.equals(DexCollectionType.Mock)) { notificationText.append("\n USING FAKE DATA SOURCE !!!"); + if (MockDataSource.divisor_scale == 1500000) { + notificationText.append(" F"); + } + if (MockDataSource.amplify_cnst == 330000) { + notificationText.append(" Amp"); + } } if (Pref.getLong("alerts_disabled_until", 0) > new Date().getTime()) { notificationText.append("\n " + getString(R.string.all_alerts_currently_disabled)); @@ -2604,7 +2630,13 @@ private void updateCurrentBgInfoCommon(DexCollectionType collector, TextView not } if (!isSensorActive) { - notificationText.setText(R.string.now_start_your_sensor); + // Define a variable (notConnectedToG6Yet) that is only true if Native G6 is chosen, but, transmitter days is unknown. + boolean notConnectedToG6Yet = DexCollectionType.getDexCollectionType() == DexcomG5 && Pref.getBooleanDefaultFalse("ob1_g5_use_transmitter_alg") && Pref.getBooleanDefaultFalse("using_g6") && DexTimeKeeper.getTransmitterAgeInDays(getTransmitterID()) == -1; + if (notConnectedToG6Yet || shortTxId()) { // Only if G6 has been selected and transmitter days is unknown, or if G7 has been selected. + notificationText.setText(R.string.wait_to_connect); + } else { // Only if G6 is not selected or G6 transmitter days is known. + notificationText.setText(R.string.now_start_your_sensor); + } if ((dialog == null) || (!dialog.isShowing())) { if (!Experience.gotData() && Experience.backupAvailable() && JoH.ratelimit("restore-backup-prompt", 10)) { @@ -2620,11 +2652,12 @@ private void updateCurrentBgInfoCommon(DexCollectionType collector, TextView not dialog = builder.create(); dialog.show(); } else { - if (!Experience.gotData() && !QuickSettingsDialogs.isDialogShowing() && JoH.ratelimit("start-sensor_prompt", 20)) { + if (!Experience.gotData() && !QuickSettingsDialogs.isDialogShowing() && !notConnectedToG6Yet && JoH.ratelimit("start-sensor_prompt", 20)) { + // Show the dialog only if there is no data, and there is no dialog, and G6 is not selected or G6 is connected, and the rate limit is satisfied. final AlertDialog.Builder builder = new AlertDialog.Builder(this); final Context context = this; builder.setTitle(getString(R.string.start_sensor) + "?"); - builder.setMessage(String.format(gs(R.string.start_sensor_confirmation), DexCollectionType.getDexCollectionType().toString())); + builder.setMessage(String.format(gs(R.string.start_sensor_confirmation), DexCollectionType.getBestCollectorHardwareName())); builder.setNegativeButton(gs(R.string.change_settings), (dialog, which) -> { dialog.dismiss(); startActivity(new Intent(context, Preferences.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); @@ -2670,7 +2703,7 @@ private void updateCurrentBgInfoCommon(DexCollectionType collector, TextView not // TODO this logic needed a rework even a year ago, now its a lot more confused with the additional complexity of native mode if (Ob1G5CollectionService.isG5ActiveButUnknownState() && Calibration.latestValid(2).size() < 2) { // TODO use format string - notificationText.setText(String.format(gs(R.string.state_not_currently_known), (Ob1G5StateMachine.usingG6() ? "G6" : "G5"))); + notificationText.setText(String.format(gs(R.string.state_not_currently_known), (Ob1G5StateMachine.usingG6() ? (shortTxId() ? "G7" : "G6") : "G5"))); showUncalibratedSlope(); } else { @@ -3304,6 +3337,95 @@ public void shareMyConfig(MenuItem myitem) { startActivity(new Intent(getApplicationContext(), DisplayQRCode.class)); } + public void exportDatabase(MenuItem myitem) { + new AsyncTask() { + @Override + protected String doInBackground(Void... params) { + int permissionCheck = ContextCompat.checkSelfPermission(Home.this, + Manifest.permission.READ_EXTERNAL_STORAGE); + if (permissionCheck != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(Home.this, + new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, + 0); + return null; + } else { + return DatabaseUtil.saveSql(getBaseContext()); + } + + } + + @Override + protected void onPostExecute(String filename) { + super.onPostExecute(filename); + if (filename != null) { + + snackBar(R.string.share, getString(R.string.exported_to) + filename, makeSnackBarUriLauncher(Uri.fromFile(new File(filename)), getString(R.string.share_database)), Home.this); + startActivity(new Intent(xdrip.getAppContext(), SdcardImportExport.class).putExtra("backup", "now").setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); + /* SnackbarManager.show( + Snackbar.with(Home.this) + .type(SnackbarType.MULTI_LINE) + .duration(4000) + .text(getString(R.string.exported_to) + filename) // text to display + .actionLabel("Share") // action button label + .actionListener(new SnackbarUriListener(Uri.fromFile(new File(filename)))), + Home.this);*/ + } else { + Toast.makeText(Home.this, R.string.could_not_export_database, Toast.LENGTH_LONG).show(); + } + } + }.execute(); + } + + public void restoreDatabase(MenuItem myitem) { + startActivity(new Intent(this, ImportDatabaseActivity.class)); + } + + public void exportCSVasSiDiary(MenuItem myitem) { + long from = Pref.getLong("sidiary_last_exportdate", 0); + final GregorianCalendar date = new GregorianCalendar(); + final DatePickerFragment datePickerFragment = new DatePickerFragment(); + if (from > 0) datePickerFragment.setInitiallySelectedDate(from); + datePickerFragment.setAllowFuture(false); + datePickerFragment.setTitle(getString(R.string.sidiary_date_title)); + datePickerFragment.setDateCallback(new ProfileAdapter.DatePickerCallbacks() { + @Override + public void onDateSet(int year, int month, int day) { + date.set(year, month, day); + date.set(Calendar.HOUR_OF_DAY, 0); + date.set(Calendar.MINUTE, 0); + date.set(Calendar.SECOND, 0); + date.set(Calendar.MILLISECOND, 0); + new AsyncTask() { + @Override + protected String doInBackground(Void... params) { + int permissionCheck = ContextCompat.checkSelfPermission(Home.this, + Manifest.permission.READ_EXTERNAL_STORAGE); + if (permissionCheck != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(Home.this, + new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, + 0); + return null; + } else { + return DatabaseUtil.saveCSV(getBaseContext(), date.getTimeInMillis()); + } + } + + @Override + protected void onPostExecute(String filename) { + super.onPostExecute(filename); + if (filename != null) { + Pref.setLong("sidiary_last_exportdate", System.currentTimeMillis()); + snackBar(R.string.share, getString(R.string.exported_to) + filename, makeSnackBarUriLauncher(Uri.fromFile(new File(filename)), getString(R.string.share_database)), Home.this); + } else { + Toast.makeText(Home.this, gs(R.string.could_not_export_csv_), Toast.LENGTH_LONG).show(); + } + } + }.execute(); + } + }); + datePickerFragment.show(getFragmentManager(), "DatePicker"); + } + public void settingsSDcardExport(MenuItem myitem) { startActivity(new Intent(getApplicationContext(), SdcardImportExport.class)); } @@ -3340,6 +3462,21 @@ public void parakeetSetupMode(MenuItem myitem) { alertDialog.show(); } + public void resendGlucoseToWatch(MenuItem myitem) { + WatchUpdaterService.startServiceAndResendData(0); + if (Pref.getBooleanDefaultFalse("pref_amazfit_enable_key")) { + Amazfitservice.start("xDrip_synced_SGV_data"); + } + } + + public void openSettingsOnWatch(MenuItem myitem) { + startService(new Intent(this, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_OPEN_SETTINGS)); + } + + public void resetWearDb(MenuItem myitem) { + startService(new Intent(this, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_RESET_DB)); + } + public void undoButtonClick(View myitem) { if (UndoRedo.undoNextItem()) staticRefreshBGCharts(); } @@ -3436,7 +3573,15 @@ public void checkForUpdate(MenuItem myitem) { if (JoH.ratelimit("manual-update-check", 5)) { toast(getString(R.string.checking_for_update)); UpdateActivity.last_check_time = -1; - UpdateActivity.checkForAnUpdate(getApplicationContext()); + UpdateActivity.checkForAnUpdate(getApplicationContext(), true); + } + } + + public void toggleSpeakReadings(MenuItem myitem) { + Pref.toggleBoolean("bg_to_speech"); + invalidateOptionsMenu(); + if (Pref.getBooleanDefaultFalse("bg_to_speech")) { + BgToSpeech.testSpeech(); } } @@ -3472,133 +3617,12 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { @Override public boolean onOptionsItemSelected(MenuItem item) { - - switch (item.getItemId()) { - case R.id.action_resend_last_bg: - WatchUpdaterService.startServiceAndResendData(0); - if (Pref.getBooleanDefaultFalse("pref_amazfit_enable_key")) { - Amazfitservice.start("xDrip_synced_SGV_data"); - } - break; - case R.id.action_open_watch_settings: - startService(new Intent(this, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_OPEN_SETTINGS)); - break; - case R.id.action_sync_watch_db: - startService(new Intent(this, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_RESET_DB)); - break; - } - - if (item.getItemId() == R.id.action_export_database) { - new AsyncTask() { - @Override - protected String doInBackground(Void... params) { - int permissionCheck = ContextCompat.checkSelfPermission(Home.this, - Manifest.permission.READ_EXTERNAL_STORAGE); - if (permissionCheck != PackageManager.PERMISSION_GRANTED) { - ActivityCompat.requestPermissions(Home.this, - new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, - 0); - return null; - } else { - return DatabaseUtil.saveSql(getBaseContext()); - } - - } - - @Override - protected void onPostExecute(String filename) { - super.onPostExecute(filename); - if (filename != null) { - - snackBar(R.string.share, getString(R.string.exported_to) + filename, makeSnackBarUriLauncher(Uri.fromFile(new File(filename)), getString(R.string.share_database)), Home.this); - startActivity(new Intent(xdrip.getAppContext(), SdcardImportExport.class).putExtra("backup", "now").setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); - /* SnackbarManager.show( - Snackbar.with(Home.this) - .type(SnackbarType.MULTI_LINE) - .duration(4000) - .text(getString(R.string.exported_to) + filename) // text to display - .actionLabel("Share") // action button label - .actionListener(new SnackbarUriListener(Uri.fromFile(new File(filename)))), - Home.this);*/ - } else { - Toast.makeText(Home.this, R.string.could_not_export_database, Toast.LENGTH_LONG).show(); - } - } - }.execute(); - - return true; - } - - if (item.getItemId() == R.id.action_import_db) { - startActivity(new Intent(this, ImportDatabaseActivity.class)); - return true; - } - - /* // jamorham additions + /*// jamorham additions if (item.getItemId() == R.id.synctreatments) { startActivity(new Intent(this, GoogleDriveInterface.class)); return true; }*/ - /// - - if (item.getItemId() == R.id.action_export_csv_sidiary) { - - long from = Pref.getLong("sidiary_last_exportdate", 0); - final GregorianCalendar date = new GregorianCalendar(); - final DatePickerFragment datePickerFragment = new DatePickerFragment(); - if (from > 0) datePickerFragment.setInitiallySelectedDate(from); - datePickerFragment.setAllowFuture(false); - datePickerFragment.setTitle(getString(R.string.sidiary_date_title)); - datePickerFragment.setDateCallback(new ProfileAdapter.DatePickerCallbacks() { - @Override - public void onDateSet(int year, int month, int day) { - date.set(year, month, day); - date.set(Calendar.HOUR_OF_DAY, 0); - date.set(Calendar.MINUTE, 0); - date.set(Calendar.SECOND, 0); - date.set(Calendar.MILLISECOND, 0); - new AsyncTask() { - @Override - protected String doInBackground(Void... params) { - int permissionCheck = ContextCompat.checkSelfPermission(Home.this, - Manifest.permission.READ_EXTERNAL_STORAGE); - if (permissionCheck != PackageManager.PERMISSION_GRANTED) { - ActivityCompat.requestPermissions(Home.this, - new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, - 0); - return null; - } else { - return DatabaseUtil.saveCSV(getBaseContext(), date.getTimeInMillis()); - } - } - - @Override - protected void onPostExecute(String filename) { - super.onPostExecute(filename); - if (filename != null) { - Pref.setLong("sidiary_last_exportdate", System.currentTimeMillis()); - snackBar(R.string.share, getString(R.string.exported_to) + filename, makeSnackBarUriLauncher(Uri.fromFile(new File(filename)), getString(R.string.share_database)), Home.this); - } else { - Toast.makeText(Home.this, gs(R.string.could_not_export_csv_), Toast.LENGTH_LONG).show(); - } - } - }.execute(); - } - }); - datePickerFragment.show(getFragmentManager(), "DatePicker"); - return true; - } - - if (item.getItemId() == R.id.action_toggle_speakreadings) { - Pref.toggleBoolean("bg_to_speech"); - invalidateOptionsMenu(); - if (Pref.getBooleanDefaultFalse("bg_to_speech")) { - BgToSpeech.testSpeech(); - } - return true; - } - return super.onOptionsItemSelected(item); } @@ -3617,7 +3641,7 @@ public void initializeGraphicTrendArrow() { public static double convertToMgDlIfMmol(double value) { if (!Pref.getString("units", "mgdl").equals("mgdl")) { - return value * com.eveningoutpost.dexdrip.UtilityModels.Constants.MMOLL_TO_MGDL; + return value * com.eveningoutpost.dexdrip.utilitymodels.Constants.MMOLL_TO_MGDL; } else { return value; // no conversion needed } @@ -3625,7 +3649,7 @@ public static double convertToMgDlIfMmol(double value) { public static void snackBar(int buttonString, String message, View.OnClickListener mOnClickListener, Activity activity) { - android.support.design.widget.Snackbar.make( + Snackbar.make( activity.findViewById(android.R.id.content), message, Snackbar.LENGTH_LONG) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportDatabaseActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/ImportDatabaseActivity.java index 3916af40b6..7794283b53 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportDatabaseActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ImportDatabaseActivity.java @@ -12,17 +12,17 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; -import android.support.annotation.NonNull; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; +import androidx.annotation.NonNull; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; import com.eveningoutpost.dexdrip.utils.DatabaseUtil; import com.eveningoutpost.dexdrip.utils.FileUtils; import com.eveningoutpost.dexdrip.utils.ListActivityWithMenu; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/LibreAlarmReceiver.java b/app/src/main/java/com/eveningoutpost/dexdrip/LibreAlarmReceiver.java index a9c64fcec0..68d2253eb2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/LibreAlarmReceiver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/LibreAlarmReceiver.java @@ -9,19 +9,18 @@ import android.os.PowerManager; import android.preference.PreferenceManager; -import com.eveningoutpost.dexdrip.Models.SensorSanity; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.Forecast; -import com.eveningoutpost.dexdrip.Models.GlucoseData; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.LibreBlock; -import com.eveningoutpost.dexdrip.Models.LibreOOPAlgorithm; -import com.eveningoutpost.dexdrip.Models.ReadingData; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Intents; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.SensorSanity; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.Forecast; +import com.eveningoutpost.dexdrip.models.GlucoseData; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.LibreBlock; +import com.eveningoutpost.dexdrip.models.ReadingData; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Intents; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.CheckBridgeBattery; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.utils.LibreTrendUtil; @@ -36,8 +35,7 @@ import java.util.Collections; import java.util.List; -import static com.eveningoutpost.dexdrip.Models.JoH.tsl; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.LIBRE_MULTIPLIER; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.LIBRE_MULTIPLIER; import static com.eveningoutpost.dexdrip.xdrip.gs; import lombok.val; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/LibreReceiver.java b/app/src/main/java/com/eveningoutpost/dexdrip/LibreReceiver.java index 4cb2df9935..49cd1c1974 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/LibreReceiver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/LibreReceiver.java @@ -1,27 +1,29 @@ package com.eveningoutpost.dexdrip; import static com.eveningoutpost.dexdrip.Home.get_engineering_mode; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; -import static com.eveningoutpost.dexdrip.Models.Libre2Sensor.Libre2Sensors; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.Libre2Sensor.Libre2Sensors; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.os.PowerManager; +import android.preference.PreferenceManager; import android.text.format.DateFormat; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.GlucoseData; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Libre2RawValue; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.Intents; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; -import com.eveningoutpost.dexdrip.UtilityModels.Unitized; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.GlucoseData; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Libre2RawValue; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Intents; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; +import com.eveningoutpost.dexdrip.utilitymodels.Unitized; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import java.text.DecimalFormat; @@ -137,9 +139,15 @@ public void run() { Log.v(TAG, "got bg reading: from sensor:" + currentRawValue.serial + " rawValue:" + currentRawValue.glucose + " at:" + currentRawValue.timestamp); // period of 4.5 minutes to collect 5 readings if (!BgReading.last_within_millis(DexCollectionType.getCurrentDeduplicationPeriod())) { - List smoothingValues = Libre2RawValue.last20Minutes(); + long smoothing_minutes = Pref.getStringToInt("libre_filter_length", 25); + long dataFetchInterval; + if ( smoothing_minutes == 25L ) + dataFetchInterval = 20L; + else + dataFetchInterval = smoothing_minutes; + List smoothingValues = Libre2RawValue.weightedAverageInterval(dataFetchInterval); smoothingValues.add(currentRawValue); - processValues(currentRawValue, smoothingValues, context); + processValues(currentRawValue, smoothingValues, smoothing_minutes, context); } currentRawValue.save(); clearNFCsensorAge(); @@ -193,13 +201,13 @@ private static Libre2RawValue processIntent(Intent intent) { return rawValue; } - private static void processValues(Libre2RawValue currentValue, List smoothingValues, Context context) { + private static void processValues(Libre2RawValue currentValue, List smoothingValues, long smoothing_minutes, Context context) { if (Sensor.currentSensor() == null) { Sensor.create(currentValue.timestamp, currentValue.serial); } - double value = calculateWeightedAverage(smoothingValues, currentValue.timestamp); + double value = calculateWeightedAverage(smoothingValues, currentValue.timestamp, TimeUnit.MINUTES.toMillis(smoothing_minutes)); BgReading.bgReadingInsertLibre2(value, currentValue.timestamp, currentValue.glucose); } @@ -221,17 +229,14 @@ private static void saveSensorStartTime(Bundle sensor, String serial) { } } - private static long SMOOTHING_DURATION = TimeUnit.MINUTES.toMillis(25); - - - private static double calculateWeightedAverage(List rawValues, long now) { + private static double calculateWeightedAverage(List rawValues, long now, long smoothing_duration) { double sum = 0; double weightSum = 0; DecimalFormat longformat = new DecimalFormat("#,###,###,##0.00"); libre_calc_doku = ""; for (Libre2RawValue rawValue : rawValues) { - double weight = 1 - ((now - rawValue.timestamp) / (double) SMOOTHING_DURATION); + double weight = 1 - ((now - rawValue.timestamp) / (double) smoothing_duration); sum += rawValue.glucose * weight; weightSum += weight; libre_calc_doku += DateFormat.format("kk:mm:ss :", rawValue.timestamp) + " w:" + longformat.format(weight) + " raw: " + rawValue.glucose + "\n"; @@ -239,7 +244,6 @@ private static double calculateWeightedAverage(List rawValues, l return Math.round(sum / weightSum); } - public static List megaStatus() { final List l = new ArrayList<>(); final Sensor sensor = Sensor.currentSensor(); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/LicenseAgreementActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/LicenseAgreementActivity.java index 06661a8bb8..c7c25fb491 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/LicenseAgreementActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/LicenseAgreementActivity.java @@ -8,7 +8,7 @@ import android.widget.Button; import android.widget.CheckBox; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.google.android.gms.oss.licenses.OssLicensesMenuActivity; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/MapsActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/MapsActivity.java index 30cfd2a1f2..767539cd56 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/MapsActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/MapsActivity.java @@ -3,15 +3,13 @@ // jamorham import android.app.Activity; -import android.content.Intent; -import android.graphics.Color; import android.os.Bundle; -import android.support.v4.app.FragmentActivity; -import android.util.Log; + import android.view.WindowManager; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import androidx.fragment.app.FragmentActivity; + +import com.eveningoutpost.dexdrip.models.JoH; //import com.google.android.gms.maps.CameraUpdateFactory; //import com.google.android.gms.maps.GoogleMap; //import com.google.android.gms.maps.OnMapReadyCallback; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/MegaStatus.java b/app/src/main/java/com/eveningoutpost/dexdrip/MegaStatus.java index 2ef9954d17..de93a3a4cc 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/MegaStatus.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/MegaStatus.java @@ -12,10 +12,10 @@ import static com.eveningoutpost.dexdrip.utils.DexCollectionType.NSFollow; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.SHFollow; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.WebFollow; +import static com.eveningoutpost.dexdrip.utils.DexCollectionType.CLFollow; import android.app.Activity; -import android.app.Fragment; -import android.app.FragmentManager; + import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; @@ -23,9 +23,13 @@ import android.content.IntentFilter; import android.graphics.Color; import android.os.Bundle; -import android.support.v13.app.FragmentStatePagerAdapter; -import android.support.v4.content.LocalBroadcastManager; -import android.support.v4.view.ViewPager; + +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentStatePagerAdapter; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; +import androidx.viewpager.widget.ViewPager; + import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; @@ -38,25 +42,26 @@ import android.widget.ListView; import android.widget.TextView; -import com.eveningoutpost.dexdrip.Models.DesertSync; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.RollCall; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Services.DexCollectionService; -import com.eveningoutpost.dexdrip.Services.DoNothingService; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; -import com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService; -import com.eveningoutpost.dexdrip.Services.WifiCollectionService; -import com.eveningoutpost.dexdrip.UtilityModels.JamorhamShowcaseDrawer; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.ShotStateStore; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; -import com.eveningoutpost.dexdrip.UtilityModels.UploaderQueue; +import com.eveningoutpost.dexdrip.models.DesertSync; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.RollCall; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.services.DexCollectionService; +import com.eveningoutpost.dexdrip.services.DoNothingService; +import com.eveningoutpost.dexdrip.services.G5CollectionService; +import com.eveningoutpost.dexdrip.services.Ob1G5CollectionService; +import com.eveningoutpost.dexdrip.services.WifiCollectionService; +import com.eveningoutpost.dexdrip.utilitymodels.JamorhamShowcaseDrawer; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.ShotStateStore; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; +import com.eveningoutpost.dexdrip.utilitymodels.UploaderQueue; import com.eveningoutpost.dexdrip.cgm.medtrum.MedtrumCollectionService; import com.eveningoutpost.dexdrip.cgm.nsfollow.NightscoutFollowService; import com.eveningoutpost.dexdrip.cgm.sharefollow.ShareFollowService; import com.eveningoutpost.dexdrip.cgm.webfollow.WebFollowService; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.CareLinkFollowService; import com.eveningoutpost.dexdrip.insulin.inpen.InPenEntry; import com.eveningoutpost.dexdrip.insulin.inpen.InPenService; import com.eveningoutpost.dexdrip.utils.ActivityWithMenu; @@ -114,7 +119,7 @@ private void addAsection(String section, String title) { } private static final String G4_STATUS = "BT Device"; - public static final String G5_STATUS = "G5/G6 Status"; + public static final String G5_STATUS = "G5/G6/G7 Status"; private static final String MEDTRUM_STATUS = "Medtrum Status"; private static final String IP_COLLECTOR = "IP Collector"; private static final String XDRIP_PLUS_SYNC = "Followers"; @@ -126,6 +131,7 @@ private void addAsection(String section, String title) { private static final String NIGHTSCOUT_FOLLOW = "Nightscout Follow"; private static final String SHARE_FOLLOW = "Dex Share Follow"; private static final String WEB_FOLLOW = "Web Follower"; + private static final String CARELINK_FOLLOW = "CareLink Follow"; private static final String XDRIP_LIBRE2 = "Libre2"; static { @@ -162,7 +168,7 @@ private void populateSectionList() { } if (dexCollectionType.equals(DexcomG5)) { if (Pref.getBooleanDefaultFalse(Ob1G5CollectionService.OB1G5_PREFS)) { - addAsection(G5_STATUS, "OB1 G5/G6 Collector and Transmitter Status"); + addAsection(G5_STATUS, "OB1 G5/G6/G7 Collector and Transmitter Status"); } else { addAsection(G5_STATUS, "G5 Collector and Transmitter Status"); } @@ -173,7 +179,7 @@ private void populateSectionList() { addAsection(BLUEJAY_STATUS, "BlueJay Watch Status"); } if (DexCollectionType.getDexCollectionType() == DexCollectionType.LibreReceiver) { - addAsection(XDRIP_LIBRE2, "Libre 2 Patched App Status"); + addAsection(XDRIP_LIBRE2, "Libre Patched App Status"); } if (DexCollectionType.hasWifi()) { addAsection(IP_COLLECTOR, dexCollectionType == DexCollectionType.Mock ? "FAKE / MOCK DATA SOURCE" : "Wifi Wixel / Parakeet Status"); @@ -205,6 +211,9 @@ private void populateSectionList() { if(dexCollectionType.equals(WebFollow)) { addAsection(WEB_FOLLOW, "Web Follower Status"); } + if(dexCollectionType.equals(CLFollow)) { + addAsection(CARELINK_FOLLOW, "CareLink Follow Status"); + } //addAsection("Misc", "Currently Empty"); @@ -268,6 +277,9 @@ private static void populate(MegaStatusListAdapter la, String section) { case WEB_FOLLOW: la.addRows(WebFollowService.megaStatus()); break; + case CARELINK_FOLLOW: + la.addRows(CareLinkFollowService.megaStatus()); + break; case XDRIP_LIBRE2: la.addRows(LibreReceiver.megaStatus()); break; @@ -292,7 +304,7 @@ protected void onCreate(Bundle savedInstanceState) { sectionTitles.clear(); populateSectionList(); - mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); + mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/MissedReadingActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/MissedReadingActivity.java index aec2b76055..2026095bbd 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/MissedReadingActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/MissedReadingActivity.java @@ -3,7 +3,6 @@ import android.app.AlertDialog; import android.app.TimePickerDialog; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; @@ -16,8 +15,8 @@ import android.widget.TextView; import android.widget.TimePicker; -import com.eveningoutpost.dexdrip.Models.AlertType; -import com.eveningoutpost.dexdrip.Services.MissedReadingService; +import com.eveningoutpost.dexdrip.models.AlertType; +import com.eveningoutpost.dexdrip.services.MissedReadingService; import com.eveningoutpost.dexdrip.utils.ActivityWithMenu; @@ -197,7 +196,7 @@ public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinut setTimeRanges(); } }, startHour, startMinute, DateFormat.is24HourFormat(mContext)); - mTimePicker.setTitle("Select start time"); + mTimePicker.setTitle(getString(R.string.select_start_time)); mTimePicker.show(); } @@ -215,7 +214,7 @@ public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinut setTimeRanges(); } }, endHour, endMinute, DateFormat.is24HourFormat(mContext)); - mTimePicker.setTitle("Select end time"); + mTimePicker.setTitle(getString(R.string.select_end_time)); mTimePicker.show(); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/NFCReaderX.java b/app/src/main/java/com/eveningoutpost/dexdrip/NFCReaderX.java index a3fd25f7fe..a30671c2ab 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/NFCReaderX.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/NFCReaderX.java @@ -27,25 +27,25 @@ import android.widget.Button; import android.widget.CheckBox; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice; -import com.eveningoutpost.dexdrip.Models.GlucoseData; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Libre2SensorData; -import com.eveningoutpost.dexdrip.Models.LibreBlock; -import com.eveningoutpost.dexdrip.Models.LibreOOPAlgorithm; -import com.eveningoutpost.dexdrip.Models.ReadingData; -import com.eveningoutpost.dexdrip.Models.SensorSanity; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.LibreUtils; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.ActiveBluetoothDevice; +import com.eveningoutpost.dexdrip.models.GlucoseData; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Libre2SensorData; +import com.eveningoutpost.dexdrip.models.LibreBlock; +import com.eveningoutpost.dexdrip.models.LibreOOPAlgorithm; +import com.eveningoutpost.dexdrip.models.ReadingData; +import com.eveningoutpost.dexdrip.models.SensorSanity; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.LibreUtils; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.DexCollectionType; -import com.eveningoutpost.dexdrip.Models.LibreOOPAlgorithm.SensorType; +import com.eveningoutpost.dexdrip.models.LibreOOPAlgorithm.SensorType; import com.eveningoutpost.dexdrip.utils.LibreTrendUtil; @@ -611,7 +611,7 @@ protected Tag doInBackground(Tag... params) { try { replyBlock = nfcvTag.transceive(diag); break; - } catch (IOException e) { + } catch (IOException | SecurityException e) { if ((System.currentTimeMillis() > time + 2000)) { Log.e(TAG, "tag diagnostic read timeout"); JoH.static_toast_short(gs(R.string.nfc_diag_timeout)); @@ -644,7 +644,7 @@ protected Tag doInBackground(Tag... params) { patchInfo = Arrays.copyOfRange(patchInfo, 1, patchInfo.length); } break; - } catch (IOException e) { + } catch (IOException | SecurityException e) { if ((System.currentTimeMillis() > time_patch + 2000)) { Log.e(TAG, "patchInfo tag read timeout"); JoH.static_toast_short(gs(R.string.nfc_read_timeout)); @@ -699,7 +699,7 @@ protected Tag doInBackground(Tag... params) { try { replyBlock = nfcvTag.transceive(cmd); break; - } catch (IOException e) { + } catch (IOException | SecurityException e) { if ((System.currentTimeMillis() > time + 2000)) { Log.e(TAG, "tag read timeout"); JoH.static_toast_short(gs(R.string.nfc_read_timeout)); @@ -760,7 +760,7 @@ protected Tag doInBackground(Tag... params) { Log.e(TAG, "sending command " + HexDump.toHexString(cmd)); oneBlock = nfcvTag.transceive(cmd); break; - } catch (IOException e) { + } catch (IOException | SecurityException e) { if ((System.currentTimeMillis() > time + 2000)) { Log.e(TAG, "tag read timeout"); JoH.static_toast_short(gs(R.string.nfc_read_timeout)); @@ -790,7 +790,7 @@ protected Tag doInBackground(Tag... params) { JoH.static_toast_short(gs(R.string.scanned_ok)); PersistentStore.setLongZeroIfSet("nfc-address-failures"); - } catch (IOException e) { + } catch (IOException | SecurityException e) { JoH.static_toast_short(gs(R.string.nfc_io_error)); vibrate(context, 3); } catch (Exception e) { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/NSClientReceiver.java b/app/src/main/java/com/eveningoutpost/dexdrip/NSClientReceiver.java index c6761e6e09..4c752d84a8 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/NSClientReceiver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/NSClientReceiver.java @@ -1,5 +1,6 @@ package com.eveningoutpost.dexdrip; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; import static com.eveningoutpost.dexdrip.xdrip.gs; import android.content.BroadcastReceiver; @@ -10,13 +11,14 @@ import android.preference.PreferenceManager; import android.util.Log; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Intents; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.insulin.aaps.AAPSStatusHandler; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Intents; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.profileeditor.ImportAapsProfile; import org.json.JSONArray; @@ -57,6 +59,26 @@ public void onReceive(Context context, Intent intent) { if (action == null) return; switch (action) { + case Intents.ACTION_NEW_DEVICESTATUS: + case Intents.ACTION_NS_BRIDGE: + if (bundle == null) break; + if (prefs.getBoolean("accept_nsclient_treatments", true)) { + + final String device_status_json = bundle.getString("devicestatus", ""); + if (!emptyString(device_status_json)) { + try { + AAPSStatusHandler.processDeviceStatus(device_status_json); + } catch (Exception e) { + Log.e(TAG, "Exception processing device status in NS_BRIDGE action: " + e); + } + } else { + Log.e(TAG, "Empty device status received via NS_BRIDGE action"); + } + } else { + Log.e(TAG, "Cannot accept device status as preference setting prevents it"); + } + break; + case Intents.ACTION_NEW_SGV: if (Home.get_follower() && prefs.getBoolean("accept_nsclient_sgv", true)) { if (bundle == null) break; @@ -80,6 +102,7 @@ public void onReceive(Context context, Intent intent) { } break; + case Intents.ACTION_NEW_FOOD: // action changed unexpectedly case Intents.ACTION_NEW_TREATMENT: if (bundle == null) break; if (prefs.getBoolean("accept_nsclient_treatments", true)) { @@ -257,7 +280,12 @@ private String toTreatmentJSON(HashMap trt_map) { try { // jsonObject.put("uuid", UUID.fromString(trt_map.get("_id").toString()).toString()); - jsonObject.put("timestamp", trt_map.get("mills")); + Object ts = trt_map.get("mills"); + if (ts == null) { + ts = trt_map.get("date"); // identifier changed at some point + } + + jsonObject.put("timestamp", ts); jsonObject.put("eventType", trt_map.get("eventType")); jsonObject.put("enteredBy", trt_map.get("enteredBy")); if (trt_map.containsKey("carbs")) { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/NSEmulatorReceiver.java b/app/src/main/java/com/eveningoutpost/dexdrip/NSEmulatorReceiver.java index b1fc9c0aaa..9b35cc9cf2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/NSEmulatorReceiver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/NSEmulatorReceiver.java @@ -10,15 +10,15 @@ import android.preference.PreferenceManager; import android.util.Base64; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.LibreOOPAlgorithm; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.Intents; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.PumpStatus; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.LibreOOPAlgorithm; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Intents; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.PumpStatus; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import org.json.JSONArray; @@ -28,7 +28,7 @@ import java.util.ArrayList; import java.util.UUID; -import static com.eveningoutpost.dexdrip.Models.BgReading.bgReadingInsertFromJson; +import static com.eveningoutpost.dexdrip.models.BgReading.bgReadingInsertFromJson; import static com.eveningoutpost.dexdrip.xdrip.gs; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/NavDrawerBuilder.java b/app/src/main/java/com/eveningoutpost/dexdrip/NavDrawerBuilder.java index 6a7ec9a63c..f8fcca76d7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/NavDrawerBuilder.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/NavDrawerBuilder.java @@ -6,25 +6,27 @@ import android.os.Build; import android.preference.PreferenceManager; -import com.eveningoutpost.dexdrip.G5Model.FirmwareCapability; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService; +import com.eveningoutpost.dexdrip.g5model.FirmwareCapability; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.services.Ob1G5CollectionService; import com.eveningoutpost.dexdrip.tables.BgReadingTable; import com.eveningoutpost.dexdrip.tables.CalibrationDataTable; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Experience; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Experience; import com.eveningoutpost.dexdrip.stats.StatsActivity; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.utils.Preferences; import java.util.ArrayList; import java.util.List; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.getTransmitterID; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.getTransmitterID; +import static com.eveningoutpost.dexdrip.utils.DexCollectionType.getBestCollectorHardwareName; /** * Created by Emma Black on 11/5/14. @@ -90,7 +92,7 @@ public NavDrawerBuilder(final Context context) { } } else { //If there haven't been two initial calibrations if (BgReading.isDataSuitableForDoubleCalibration() || Ob1G5CollectionService.isG5WantingInitialCalibration()) { - if (FirmwareCapability.isTransmitterRawIncapable(getTransmitterID()) && last_two_bgReadings.size() > 1) { //A Firefly G6 after third reading + if ((FirmwareCapability.isTransmitterRawIncapable(getTransmitterID()) && last_two_bgReadings.size() > 1) || FirmwareCapability.isDeviceG7(getTransmitterID()) ) { //A Firefly G6 after third reading or a G7 this.nav_drawer_options.add(context.getString(R.string.add_calibration)); this.nav_drawer_intents.add(new Intent(context, AddCalibration.class)); } else { //G5 or non-Firefly G6 or Firefly G6 in no-code mode, after warm-up before initial calibration @@ -101,8 +103,10 @@ public NavDrawerBuilder(final Context context) { } } } - this.nav_drawer_options.add(context.getString(R.string.stop_sensor)); - this.nav_drawer_intents.add(new Intent(context, StopSensor.class)); + if (!getBestCollectorHardwareName().equals("G7") || Pref.getBooleanDefaultFalse("engineering_mode")) { // If we are using G7, offer the stop sensor option in engineering mode only + this.nav_drawer_options.add(context.getString(R.string.stop_sensor)); + this.nav_drawer_intents.add(new Intent(context, StopSensor.class)); + } } else { this.nav_drawer_options.add(context.getString(R.string.start_sensor)); this.nav_drawer_intents.add(new Intent(context, StartNewSensor.class)); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/NavigationDrawerFragment.java b/app/src/main/java/com/eveningoutpost/dexdrip/NavigationDrawerFragment.java index 00aa3f75d0..d679764077 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/NavigationDrawerFragment.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/NavigationDrawerFragment.java @@ -1,6 +1,7 @@ package com.eveningoutpost.dexdrip; + import android.app.Activity; import android.app.Fragment; import android.content.Context; @@ -9,10 +10,7 @@ import android.content.res.Configuration; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.ActionBar; -import android.support.v7.app.ActionBarDrawerToggle; -import android.support.v7.app.AppCompatActivity; + import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; @@ -24,6 +22,11 @@ import android.widget.ArrayAdapter; import android.widget.ListView; +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.ActionBarDrawerToggle; +import androidx.appcompat.app.AppCompatActivity; +import androidx.drawerlayout.widget.DrawerLayout; + import java.util.List; public class NavigationDrawerFragment extends Fragment { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/NewDataObserver.java b/app/src/main/java/com/eveningoutpost/dexdrip/NewDataObserver.java index 4354f13359..86cef53f33 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/NewDataObserver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/NewDataObserver.java @@ -1,17 +1,20 @@ package com.eveningoutpost.dexdrip; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.LibreBlock; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.ShareModels.BgUploader; -import com.eveningoutpost.dexdrip.ShareModels.Models.ShareUploadPayload; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Notifications; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.VehicleMode; -import com.eveningoutpost.dexdrip.UtilityModels.pebble.PebbleUtil; -import com.eveningoutpost.dexdrip.UtilityModels.pebble.PebbleWatchSync; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.LibreBlock; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.receiver.InfoContentProvider; +import com.eveningoutpost.dexdrip.sharemodels.BgUploader; +import com.eveningoutpost.dexdrip.sharemodels.models.ShareUploadPayload; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Notifications; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.VehicleMode; +import com.eveningoutpost.dexdrip.utilitymodels.pebble.PebbleUtil; +import com.eveningoutpost.dexdrip.utilitymodels.pebble.PebbleWatchSync; +import com.eveningoutpost.dexdrip.healthconnect.HealthGamut; +import com.eveningoutpost.dexdrip.healthconnect.HealthConnectEntry; import com.eveningoutpost.dexdrip.tidepool.TidepoolEntry; import com.eveningoutpost.dexdrip.ui.LockScreenWallPaper; import com.eveningoutpost.dexdrip.utils.BgToSpeech; @@ -24,11 +27,13 @@ import com.eveningoutpost.dexdrip.watch.thinjam.BlueJayRemote; import com.eveningoutpost.dexdrip.wearintegration.Amazfitservice; import com.eveningoutpost.dexdrip.wearintegration.ExternalStatusService; -import com.eveningoutpost.dexdrip.Services.broadcastservice.BroadcastEntry; +import com.eveningoutpost.dexdrip.services.broadcastservice.BroadcastEntry; import com.eveningoutpost.dexdrip.wearintegration.WatchUpdaterService; import static com.eveningoutpost.dexdrip.Home.startWatchUpdaterService; +import android.os.Build; + /** * Created by jamorham on 01/01/2018. * @@ -54,10 +59,12 @@ public static void newBgReading(BgReading bgReading, boolean is_follower) { sendToBlueJay(); sendToRemoteBlueJay(); Notifications.start(); + InfoContentProvider.ping("bg"); uploadToShare(bgReading, is_follower); textToSpeech(bgReading, null); LibreBlock.UpdateBgVal(bgReading.timestamp, bgReading.calculated_value); LockScreenWallPaper.setIfEnabled(); + sendToHealthConnect(bgReading); TidepoolEntry.newData(); } @@ -82,6 +89,7 @@ public static void newExternalStatus(boolean receivedLocally) { GcmActivity.push_external_status_update(JoH.tsl(), statusLine); } + InfoContentProvider.ping("status"); } } @@ -134,6 +142,14 @@ private static void sendToRemoteBlueJay() { } } + private static void sendToHealthConnect(final BgReading bgReading) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (HealthConnectEntry.sendEnabled()) { + HealthGamut.sendGlucoseStatic(bgReading); + } + } + } + // send to wear // data is already synced via UploaderQueue but this will send the display glucose private static void sendToWear() { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/NewSensorLocation.java b/app/src/main/java/com/eveningoutpost/dexdrip/NewSensorLocation.java index 46b92bbedf..aeca18aa4e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/NewSensorLocation.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/NewSensorLocation.java @@ -15,7 +15,7 @@ import android.widget.RadioGroup.OnCheckedChangeListener; import android.widget.Toast; -import com.eveningoutpost.dexdrip.Models.Sensor; +import com.eveningoutpost.dexdrip.models.Sensor; import com.eveningoutpost.dexdrip.utils.ActivityWithMenu; import java.util.LinkedList; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/NightscoutBackfillActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/NightscoutBackfillActivity.java index 964405ac3d..a07d3d64e7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/NightscoutBackfillActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/NightscoutBackfillActivity.java @@ -2,19 +2,18 @@ import android.os.Bundle; import android.os.PowerManager; -import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.AppCompatActivity; + import android.view.View; import android.widget.Button; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Services.SyncService; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.UploaderTask; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.UploaderQueue; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.services.SyncService; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.UploaderTask; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.UploaderQueue; import com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment; import com.eveningoutpost.dexdrip.profileeditor.ProfileAdapter; @@ -23,6 +22,9 @@ import java.util.List; import static com.eveningoutpost.dexdrip.xdrip.gs; +import androidx.appcompat.app.AppCompatActivity; +import androidx.drawerlayout.widget.DrawerLayout; + /** * Created by jamorham on 23/05/2017. *

diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/NoteSearch.java b/app/src/main/java/com/eveningoutpost/dexdrip/NoteSearch.java index b5f72307b7..0e22dfe783 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/NoteSearch.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/NoteSearch.java @@ -30,8 +30,7 @@ import com.activeandroid.Cache; import com.activeandroid.util.SQLiteUtils; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.utils.ListActivityWithMenu; import java.text.DateFormat; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ParakeetHelper.java b/app/src/main/java/com/eveningoutpost/dexdrip/ParakeetHelper.java index ff32f366ba..c66e5a1bc4 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ParakeetHelper.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ParakeetHelper.java @@ -8,15 +8,15 @@ import android.media.RingtoneManager; import android.net.Uri; import android.preference.PreferenceManager; -import android.support.v4.app.NotificationCompat; +import androidx.core.app.NotificationCompat; import android.util.Log; import android.widget.Toast; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.NotificationChannels; -import com.eveningoutpost.dexdrip.UtilityModels.Notifications; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.XdripNotificationCompat; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.NotificationChannels; +import com.eveningoutpost.dexdrip.utilitymodels.Notifications; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.XdripNotificationCompat; import com.eveningoutpost.dexdrip.utils.PowerStateReceiver; import com.eveningoutpost.dexdrip.utils.Preferences; import com.eveningoutpost.dexdrip.utils.WebAppHelper; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/PhoneKeypadInputActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/PhoneKeypadInputActivity.java index d875208cd6..832942e7fb 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/PhoneKeypadInputActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/PhoneKeypadInputActivity.java @@ -13,8 +13,8 @@ import android.widget.LinearLayout; import android.widget.TextView; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.insulin.Insulin; import com.eveningoutpost.dexdrip.insulin.InsulinManager; import com.eveningoutpost.dexdrip.insulin.MultipleInsulins; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/RegistrationIntentService.java b/app/src/main/java/com/eveningoutpost/dexdrip/RegistrationIntentService.java index c1f88fc940..5e4885b163 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/RegistrationIntentService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/RegistrationIntentService.java @@ -9,11 +9,13 @@ import android.content.SharedPreferences; import android.os.PowerManager; import android.preference.PreferenceManager; -import android.support.v4.content.LocalBroadcastManager; + import android.util.Log; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Services.PlusSyncService; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; + +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.services.PlusSyncService; import com.google.android.gms.gcm.GcmNetworkManager; import com.google.android.gms.gcm.PeriodicTask; import com.google.android.gms.gcm.Task; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Reminders.java b/app/src/main/java/com/eveningoutpost/dexdrip/Reminders.java index c40ae651d6..6e89c46f93 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Reminders.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/Reminders.java @@ -6,11 +6,11 @@ import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; import static com.eveningoutpost.dexdrip.Home.SHOWCASE_REMINDER3; -import static com.eveningoutpost.dexdrip.Models.JoH.dateTimeText; -import static com.eveningoutpost.dexdrip.Models.JoH.hourMinuteString; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.Models.JoH.niceTimeScalarNatural; -import static com.eveningoutpost.dexdrip.Models.JoH.tsl; +import static com.eveningoutpost.dexdrip.models.JoH.dateTimeText; +import static com.eveningoutpost.dexdrip.models.JoH.hourMinuteString; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.niceTimeScalarNatural; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; import static lecho.lib.hellocharts.animation.ChartDataAnimator.DEFAULT_ANIMATION_DURATION; import android.animation.ValueAnimator; @@ -32,12 +32,13 @@ import android.os.Build; import android.os.Bundle; import android.os.PowerManager; -import android.support.annotation.NonNull; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.CardView; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.helper.ItemTouchHelper; +import androidx.annotation.NonNull; +import androidx.cardview.widget.CardView; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.ItemTouchHelper; +import androidx.recyclerview.widget.RecyclerView; + import android.text.Editable; import android.text.InputType; import android.text.TextWatcher; @@ -65,17 +66,17 @@ import android.widget.RelativeLayout; import android.widget.TextView; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Reminder; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.JamorhamShowcaseDrawer; -import com.eveningoutpost.dexdrip.UtilityModels.NotificationChannels; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.ShotStateStore; -import com.eveningoutpost.dexdrip.UtilityModels.SpeechUtil; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Reminder; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.JamorhamShowcaseDrawer; +import com.eveningoutpost.dexdrip.utilitymodels.NotificationChannels; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.ShotStateStore; +import com.eveningoutpost.dexdrip.utilitymodels.SpeechUtil; import com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment; import com.eveningoutpost.dexdrip.profileeditor.ProfileAdapter; import com.eveningoutpost.dexdrip.profileeditor.TimePickerFragment; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ShareTest.java b/app/src/main/java/com/eveningoutpost/dexdrip/ShareTest.java index aa818b16df..7b198db8a0 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ShareTest.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ShareTest.java @@ -1,6 +1,5 @@ package com.eveningoutpost.dexdrip; -import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothGatt; @@ -23,17 +22,17 @@ import android.widget.Toast; import com.activeandroid.query.Select; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.ReadDataShare; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.CalRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.EGVRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.SensorRecord; -import com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.DexShareAttributes; -import com.eveningoutpost.dexdrip.UtilityModels.ForegroundServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.HM10Attributes; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.ReadDataShare; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.CalRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.EGVRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.SensorRecord; +import com.eveningoutpost.dexdrip.models.ActiveBluetoothDevice; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.DexShareAttributes; +import com.eveningoutpost.dexdrip.utilitymodels.ForegroundServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.HM10Attributes; import java.nio.charset.StandardCharsets; import java.util.Date; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/SimpleItemTouchHelperCallback.java b/app/src/main/java/com/eveningoutpost/dexdrip/SimpleItemTouchHelperCallback.java index e9d1af9b89..0cb187a7d5 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/SimpleItemTouchHelperCallback.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/SimpleItemTouchHelperCallback.java @@ -16,10 +16,10 @@ */ import android.graphics.Canvas; -import android.support.v4.view.ViewCompat; -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.helper.ItemTouchHelper; +import androidx.core.view.ViewCompat; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.ItemTouchHelper; +import androidx.recyclerview.widget.RecyclerView; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/SnoozeActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/SnoozeActivity.java index 99423fc514..a0d9b63e8a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/SnoozeActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/SnoozeActivity.java @@ -9,8 +9,8 @@ import android.os.Bundle; import android.preference.PreferenceManager; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; import android.util.TypedValue; import android.view.View; @@ -18,13 +18,13 @@ import android.widget.NumberPicker; import android.widget.TextView; -import com.eveningoutpost.dexdrip.Models.ActiveBgAlert; -import com.eveningoutpost.dexdrip.Models.AlertType; -import com.eveningoutpost.dexdrip.Services.MissedReadingService; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.Notifications; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.ActiveBgAlert; +import com.eveningoutpost.dexdrip.models.AlertType; +import com.eveningoutpost.dexdrip.services.MissedReadingService; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.Notifications; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.ActivityWithMenu; import static com.eveningoutpost.dexdrip.xdrip.gs; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/StartNewSensor.java b/app/src/main/java/com/eveningoutpost/dexdrip/StartNewSensor.java index 7ceaf3f5df..c01bb1791b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/StartNewSensor.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/StartNewSensor.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip; import static com.eveningoutpost.dexdrip.Home.startWatchUpdaterService; -import static com.eveningoutpost.dexdrip.Models.BgReading.AGE_ADJUSTMENT_TIME; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.getTransmitterID; +import static com.eveningoutpost.dexdrip.models.BgReading.AGE_ADJUSTMENT_TIME; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.getTransmitterID; import static com.eveningoutpost.dexdrip.xdrip.gs; import android.app.Activity; @@ -12,24 +12,24 @@ import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import android.view.View; import android.widget.Button; import android.widget.Toast; -import com.eveningoutpost.dexdrip.G5Model.DexSyncKeeper; -import com.eveningoutpost.dexdrip.G5Model.DexTimeKeeper; -import com.eveningoutpost.dexdrip.G5Model.FirmwareCapability; -import com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Experience; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.g5model.DexSyncKeeper; +import com.eveningoutpost.dexdrip.g5model.DexTimeKeeper; +import com.eveningoutpost.dexdrip.g5model.FirmwareCapability; +import com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.services.Ob1G5CollectionService; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Experience; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment; import com.eveningoutpost.dexdrip.profileeditor.ProfileAdapter; import com.eveningoutpost.dexdrip.profileeditor.TimePickerFragment; @@ -54,21 +54,29 @@ public class StartNewSensor extends ActivityWithMenu { // private TimePicker tp; final Activity activity = this; Calendar ucalendar = Calendar.getInstance(); + private int transmitterAgeInDays() { // Transmitter days reported by the transmitter; 0 on day 1; -1 if unknown due to no connectivity. + return DexTimeKeeper.getTransmitterAgeInDays(getTransmitterID()); + } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (!Sensor.isActive()) { - JoH.fixActionBar(this); - setContentView(R.layout.activity_start_new_sensor); - button = (Button) findViewById(R.id.startNewSensor); - //dp = (DatePicker)findViewById(R.id.datePicker); - //tp = (TimePicker)findViewById(R.id.timePicker); - addListenerOnButton(); - } else { - Intent intent = new Intent(this, StopSensor.class); - startActivity(intent); + if (DexCollectionType.getBestCollectorHardwareName().equals("G7")) { + JoH.static_toast_long(getString(R.string.g7_should_start_automatically)); finish(); + } else { + if (!Sensor.isActive()) { + JoH.fixActionBar(this); + setContentView(R.layout.activity_start_new_sensor); + button = (Button) findViewById(R.id.startNewSensor); + //dp = (DatePicker)findViewById(R.id.datePicker); + //tp = (TimePicker)findViewById(R.id.timePicker); + addListenerOnButton(); + } else { + Intent intent = new Intent(this, StopSensor.class); + startActivity(intent); + finish(); + } } } @@ -101,8 +109,9 @@ private void sensorButtonClick() { ucalendar = Calendar.getInstance(); if (Ob1G5CollectionService.usingNativeMode()) { - if (!DexSyncKeeper.isReady(Pref.getString("dex_txid", "NULL"))) { - JoH.static_toast_long("Need to connect to transmitter once before we can start sensor"); + if (!DexSyncKeeper.isReady(Pref.getString("dex_txid", "NULL")) || transmitterAgeInDays() == -1) { + JoH.static_toast_long("Need to connect to transmitter before we can start sensor"); + UserError.Log.e(TAG, "Need to connect to transmitter before we can start sensor"); MegaStatus.startStatus(MegaStatus.G5_STATUS); } else { startSensorOrAskForG6Code(); // If we're using native mode, don't bother asking about insertion time @@ -175,11 +184,15 @@ public void onTimeUpdated(int newmins) { private static final int MONTH_WARNING_DAYS = 30; private void startSensorOrAskForG6Code() { + if (getTransmitterID().length() == 4) { + Sensor.createDefaultIfMissing(); + finish(); + } final int cap = 20; if (Ob1G5CollectionService.usingCollector() && Ob1G5StateMachine.usingG6()) { if (JoH.pratelimit("dex-stop-start", cap)) { JoH.clearRatelimit("dex-stop-start"); - val transmitterAgeInDays = DexTimeKeeper.getTransmitterAgeInDays(getTransmitterID()); + val transmitterAgeInDays = transmitterAgeInDays(); val modified = FirmwareCapability.isTransmitterModified(getTransmitterID()); val endOfLife = transmitterAgeInDays >= ABSOLUTE_MAX_AGE_DAYS || (!modified && transmitterAgeInDays >= MAX_AGE_DAYS); if (transmitterAgeInDays < MAX_AGE_DAYS - MONTH_WARNING_DAYS @@ -234,7 +247,7 @@ public static void startSensorForTime(long startTime) { LibreAlarmReceiver.clearSensorStats(); // TODO this is just a timer and could be confusing - consider removing this notification - // JoH.scheduleNotification(xdrip.getAppContext(), "Sensor should be ready", xdrip.getAppContext().getString(R.string.please_enter_two_calibrations_to_get_started), 60 * 130, Home.SENSOR_READY_ID); + // JoH.scheduleNotification(xdrip.getAppContext(), "Sensor should be ready", xdrip.getAppContext().getString(R.string.please_enter_two_calibrations_to_get_started), 60 * 130, Home.SENSOR_READY_ID); // Add treatment entry in db Treatments.sensorStart(startTime, "Started by xDrip"); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/StopSensor.java b/app/src/main/java/com/eveningoutpost/dexdrip/StopSensor.java index 7d43667a7a..9f15f352cc 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/StopSensor.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/StopSensor.java @@ -7,25 +7,31 @@ import android.view.View; import android.widget.Button; -import com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.NanoStatus; +import com.eveningoutpost.dexdrip.databinding.ActivityEventLogBinding; +import com.eveningoutpost.dexdrip.databinding.ActivityStopSensorBinding; +import com.eveningoutpost.dexdrip.g5model.FirmwareCapability; +import com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.NanoStatus; import com.eveningoutpost.dexdrip.calibrations.PluggableCalibration; import com.eveningoutpost.dexdrip.ui.dialog.GenericConfirmDialog; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.ActivityWithMenu; +import com.eveningoutpost.dexdrip.utils.DexCollectionType; import lombok.val; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.shortTxId; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.getTransmitterID; import static com.eveningoutpost.dexdrip.xdrip.gs; public class StopSensor extends ActivityWithMenu { - public Button button; @Override protected void onCreate(Bundle savedInstanceState) { @@ -36,9 +42,10 @@ protected void onCreate(Bundle savedInstanceState) { finish(); } else { JoH.fixActionBar(this); - setContentView(R.layout.activity_stop_sensor); - button = (Button)findViewById(R.id.stop_sensor); - addListenerOnButton(); + + val binding = ActivityStopSensorBinding.inflate(getLayoutInflater()); + binding.setModel(new ViewModel()); + setContentView(binding.getRoot()); } } @@ -47,16 +54,6 @@ public String getMenuName() { return getString(R.string.stop_sensor); } - public void addListenerOnButton() { - button = (Button)findViewById(R.id.stop_sensor); - val activity = this; - button.setOnClickListener(v -> GenericConfirmDialog.show(activity, gs(R.string.are_you_sure), gs(R.string.sensor_stop_confirm), () -> { - stop(); - JoH.startActivity(Home.class); - finish(); - })); - } - public synchronized static void stop() { Sensor.stopSensor(); Inevitable.task("stop-sensor",1000, Sensor::stopSensor); @@ -85,23 +82,42 @@ public void resetAllCalibrations(View v) { builder.setTitle(gs(R.string.are_you_sure)); builder.setMessage(gs(R.string.do_you_want_to_delete_and_reset_the_calibrations_for_this_sensor)); - builder.setNegativeButton(gs(R.string.no), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); + builder.setNegativeButton(gs(R.string.no), (dialog, which) -> dialog.dismiss()); - } - }); - - builder.setPositiveButton(gs(R.string.yes), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - Calibration.invalidateAllForSensor(); - dialog.dismiss(); - finish(); - } + builder.setPositiveButton(gs(R.string.yes), (dialog, which) -> { + Calibration.invalidateAllForSensor(); + dialog.dismiss(); + finish(); }); builder.create().show(); + } + + public class ViewModel { + // This is false only for Dexcom G6 Firefly and G7 as of December 2023. + // These devices have two common characteristics: + // 1- xDrip does not maintain a calibration graph for them. Therefore, resetting calibrations has no impact. + // 2- They cannot be restarted easily or they cannot be restarted at all. + // TODO this could be moved to another utility class if the same logic is used elsewhere + public boolean resettableCals() { // Used on the stop sensor menu. + return DexCollectionType.getDexCollectionType() != DexCollectionType.DexcomG5 + || !Pref.getBooleanDefaultFalse("using_g6") + || !FirmwareCapability.isTransmitterRawIncapable(getTransmitterID()); + } + public void stopSensorClick() { + String confirm = gs(R.string.are_you_sure); + if (!resettableCals()) { // Dexcom G6 Firefly or G7 + confirm = gs(R.string.sensor_stop_confirm_norestart); + if (shortTxId()) { // Dexcom G7 + confirm = gs(R.string.sensor_stop_confirm_really_norestart); + } + } + GenericConfirmDialog.show(StopSensor.this, gs(R.string.are_you_sure), confirm, () -> { + stop(); + JoH.startActivity(Home.class); + finish(); + }); + } } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/SystemStatusFragment.java b/app/src/main/java/com/eveningoutpost/dexdrip/SystemStatusFragment.java index 8c200440f7..e67cc9aba3 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/SystemStatusFragment.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/SystemStatusFragment.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip; -import android.app.Fragment; + import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothManager; @@ -11,14 +11,17 @@ import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageManager; -import android.databinding.DataBindingUtil; +import androidx.databinding.DataBindingUtil; +import androidx.fragment.app.Fragment; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; + import android.graphics.Point; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.PowerManager; import android.preference.PreferenceManager; -import android.support.v4.content.LocalBroadcastManager; + import android.view.Display; import android.view.LayoutInflater; import android.view.View; @@ -28,21 +31,20 @@ import android.widget.LinearLayout; import android.widget.TextView; -import com.eveningoutpost.dexdrip.G5Model.Extensions; -import com.eveningoutpost.dexdrip.G5Model.Transmitter; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants; -import com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.TransmitterData; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.Services.DexCollectionService; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.SensorStatus; +import com.eveningoutpost.dexdrip.g5model.Extensions; +import com.eveningoutpost.dexdrip.g5model.Transmitter; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants; +import com.eveningoutpost.dexdrip.models.ActiveBluetoothDevice; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.TransmitterData; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.services.DexCollectionService; +import com.eveningoutpost.dexdrip.services.G5CollectionService; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.SensorStatus; import com.eveningoutpost.dexdrip.databinding.ActivitySystemStatusBinding; import com.eveningoutpost.dexdrip.ui.MicroStatus; import com.eveningoutpost.dexdrip.ui.MicroStatusImpl; @@ -51,9 +53,6 @@ import com.google.android.gms.wearable.DataMap; import java.lang.reflect.Method; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.List; import java.util.Set; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/TaskService.java b/app/src/main/java/com/eveningoutpost/dexdrip/TaskService.java index a2c05cec69..10bae9dca4 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/TaskService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/TaskService.java @@ -7,8 +7,8 @@ import android.content.Intent; import android.util.Log; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.UpdateActivity; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.UpdateActivity; import com.google.android.gms.gcm.GcmNetworkManager; import com.google.android.gms.gcm.GcmTaskService; import com.google.android.gms.gcm.TaskParams; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UsbConnectedActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/UsbConnectedActivity.java index 92cfa705ec..a23f426c36 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UsbConnectedActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/UsbConnectedActivity.java @@ -1,10 +1,9 @@ package com.eveningoutpost.dexdrip; -import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.SyncingService; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.SyncingService; public class UsbConnectedActivity extends BaseActivity { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/HPointValue.java b/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/HPointValue.java deleted file mode 100644 index 5f174f1fff..0000000000 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/HPointValue.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.eveningoutpost.dexdrip.UtilityModels; - -import static com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder.FUZZER; - -import com.eveningoutpost.dexdrip.BuildConfig; - -import lecho.lib.hellocharts.model.PointValue; -import lombok.AllArgsConstructor; - -/** - * JamOrHam - *

- * Due to range issues with float we need to wrap around a friendly origin timestamp expressing - * but storing real value in a bigger primitive type while maintaining compatibility with libraries - */ - -@AllArgsConstructor -public class HPointValue extends PointValue { - - private static final long OFFSET = (BuildConfig.buildTimestamp - Constants.MONTH_IN_MS) / FUZZER; - - private double x; - private float y; - - @Override - public float getX() { - return convert(this.x); - } - - @Override - public float getY() { - return this.y; - } - - public HPointValue set(double x, float y) { - this.x = x; - this.y = y; - return this; - } - - public long getTimeStamp() { - return (long) (x * FUZZER); - } - - public static float convert(final double x) { - return (float) (x - OFFSET); - } - - public static double unconvert(final float x) { - return x + OFFSET; - } - -} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PrefsViewImpl.java b/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PrefsViewImpl.java deleted file mode 100644 index 6ced916a1e..0000000000 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PrefsViewImpl.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.eveningoutpost.dexdrip.UtilityModels; - -import android.support.annotation.NonNull; - -import com.eveningoutpost.dexdrip.adapters.ObservableArrayMapNoNotify; - -/** - * Created by jamorham on 05/10/2017. - * - * Implementation of PrefsView - */ - -public class PrefsViewImpl extends ObservableArrayMapNoNotify implements PrefsView { - - private Runnable runnable; - - public boolean getbool(String name) { - return Pref.getBooleanDefaultFalse(name); - } - - public void setbool(String name, boolean value) { - Pref.setBoolean(name, value); - super.put(name, value); - doRunnable(); - } - - public void togglebool(String name) { - setbool(name, !getbool(name)); - } - - public PrefsViewImpl setRefresh(final Runnable runnable) { - this.runnable = runnable; - return this; - } - - private void doRunnable() { - if (runnable != null) { - runnable.run(); - } - } - - @NonNull - @Override - public Boolean get(Object key) { - Boolean value = super.get(key); - if (value == null) { - value = getbool((String) key); - super.putNoNotify((String) key, value); - } - return value; - } - - @Override - public Boolean put(String key, Boolean value) { - if (!(super.get(key).equals(value))) { - Pref.setBoolean(key, value); - super.put(key, value); - doRunnable(); - } - return value; - } - - public void put(Object key, boolean value) { - if (!(super.get(key).equals(value))) { - super.put((String) key, value); - } - } - -} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/WidgetUpdateService.java b/app/src/main/java/com/eveningoutpost/dexdrip/WidgetUpdateService.java index 595d1abb45..a0b830a0b8 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/WidgetUpdateService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/WidgetUpdateService.java @@ -11,8 +11,8 @@ import android.os.IBinder; import android.os.PowerManager; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; public class WidgetUpdateService extends Service { private static final String TAG = "WidgetUpdateService"; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/adapters/CheckBoxBindingAdapterUtils.java b/app/src/main/java/com/eveningoutpost/dexdrip/adapters/CheckBoxBindingAdapterUtils.java index e6f79ff6cd..c4c3c2ca34 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/adapters/CheckBoxBindingAdapterUtils.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/adapters/CheckBoxBindingAdapterUtils.java @@ -1,10 +1,10 @@ package com.eveningoutpost.dexdrip.adapters; -import android.databinding.BindingAdapter; -import android.databinding.InverseBindingAdapter; -import android.databinding.InverseBindingListener; -import android.databinding.InverseBindingMethod; -import android.databinding.InverseBindingMethods; +import androidx.databinding.BindingAdapter; +import androidx.databinding.InverseBindingAdapter; +import androidx.databinding.InverseBindingListener; +import androidx.databinding.InverseBindingMethod; +import androidx.databinding.InverseBindingMethods; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/adapters/ObservableArrayMapNoNotify.java b/app/src/main/java/com/eveningoutpost/dexdrip/adapters/ObservableArrayMapNoNotify.java index 8b809ba720..238733c905 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/adapters/ObservableArrayMapNoNotify.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/adapters/ObservableArrayMapNoNotify.java @@ -15,9 +15,10 @@ * limitations under the License. */ -import android.databinding.MapChangeRegistry; -import android.databinding.ObservableMap; -import android.support.v4.util.ArrayMap; +import androidx.collection.ArrayMap; +import androidx.databinding.MapChangeRegistry; +import androidx.databinding.ObservableMap; + import java.util.Collection; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/adapters/ObservableBackground.java b/app/src/main/java/com/eveningoutpost/dexdrip/adapters/ObservableBackground.java index 537a6ff8bd..f20a163924 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/adapters/ObservableBackground.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/adapters/ObservableBackground.java @@ -1,14 +1,14 @@ package com.eveningoutpost.dexdrip.adapters; -import android.databinding.BaseObservable; -import android.databinding.BindingAdapter; +import androidx.databinding.BaseObservable; +import androidx.databinding.BindingAdapter; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; -import android.support.annotation.ColorRes; -import android.support.annotation.DrawableRes; -import android.support.annotation.Nullable; -import android.support.v4.content.ContextCompat; +import androidx.annotation.ColorRes; +import androidx.annotation.DrawableRes; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; import android.view.View; import lombok.Getter; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/adapters/ObservableLinkedList.java b/app/src/main/java/com/eveningoutpost/dexdrip/adapters/ObservableLinkedList.java index f604b569a3..af7024d587 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/adapters/ObservableLinkedList.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/adapters/ObservableLinkedList.java @@ -16,8 +16,8 @@ * limitations under the License. */ -import android.databinding.ListChangeRegistry; -import android.databinding.ObservableList; +import androidx.databinding.ListChangeRegistry; +import androidx.databinding.ObservableList; import java.util.Collection; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/adapters/SeekBarBindingAdapterUtils.java b/app/src/main/java/com/eveningoutpost/dexdrip/adapters/SeekBarBindingAdapterUtils.java index 431864d089..15da08f00b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/adapters/SeekBarBindingAdapterUtils.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/adapters/SeekBarBindingAdapterUtils.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip.adapters; -import android.databinding.BindingAdapter; -import android.databinding.InverseBindingAdapter; -import android.databinding.InverseBindingListener; +import androidx.databinding.BindingAdapter; +import androidx.databinding.InverseBindingAdapter; +import androidx.databinding.InverseBindingListener; import android.widget.SeekBar; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/alert/Action.java b/app/src/main/java/com/eveningoutpost/dexdrip/alert/Action.java new file mode 100644 index 0000000000..d537f9f889 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/alert/Action.java @@ -0,0 +1,11 @@ +package com.eveningoutpost.dexdrip.alert; + +/** + * JamOrHam + * + * Alert action interface + */ + +public interface Action { + boolean activate(); +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/alert/BaseAlert.java b/app/src/main/java/com/eveningoutpost/dexdrip/alert/BaseAlert.java new file mode 100644 index 0000000000..e4975e58e2 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/alert/BaseAlert.java @@ -0,0 +1,73 @@ +package com.eveningoutpost.dexdrip.alert; + +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.google.gson.annotations.Expose; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import lombok.Getter; +import lombok.val; + +/** + * JamOrHam + * + * BaseAlert abstract helper class + */ + +public abstract class BaseAlert implements Condition, Action, Pollable { + + @Expose + @Getter + private final String name; + @Expose + @Getter + private final List when = new ArrayList<>(); + + @Expose + private boolean oneShot; + + + protected When lastEvent; + + public BaseAlert(final String name, final When... when) { + this.name = name; + this.when.addAll(Arrays.asList(when)); + } + + public BaseAlert setOneShot(final boolean oneShot) { + this.oneShot = oneShot; + return this; + } + + private void log(final String msg) { + Log.uel("Alert:" + name, msg); // TODO i18n ? + } + + @Override + public PollResult poll(final When event) { + val ret = new PollResult(); + if (when.contains(event)) { + lastEvent = event; + if (isMet()) { + val result = activate(); + ret.triggered = true; + log("Activated: " + result); // TODO i18n? + ret.remove = oneShot; + } + } + return ret; + } + + @Override + public String group() { + return name; + } + + @Override + public int sortPos() { + return 0; + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/alert/Condition.java b/app/src/main/java/com/eveningoutpost/dexdrip/alert/Condition.java new file mode 100644 index 0000000000..427dd51365 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/alert/Condition.java @@ -0,0 +1,11 @@ +package com.eveningoutpost.dexdrip.alert; + +/** + * JamOrHam + * + * Alert condition interface + */ + +public interface Condition { + boolean isMet(); +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/alert/Persist.java b/app/src/main/java/com/eveningoutpost/dexdrip/alert/Persist.java new file mode 100644 index 0000000000..2d022821cc --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/alert/Persist.java @@ -0,0 +1,135 @@ +package com.eveningoutpost.dexdrip.alert; + +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; +import static com.eveningoutpost.dexdrip.utilitymodels.PersistentStore.getDouble; +import static com.eveningoutpost.dexdrip.utilitymodels.PersistentStore.getLong; +import static com.eveningoutpost.dexdrip.utilitymodels.PersistentStore.getString; +import static com.eveningoutpost.dexdrip.utilitymodels.PersistentStore.setDouble; +import static com.eveningoutpost.dexdrip.utilitymodels.PersistentStore.setLong; +import static com.eveningoutpost.dexdrip.utilitymodels.PersistentStore.setString; + +import java.security.InvalidParameterException; + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +/** + * JamOrHam + *

+ * Generic persistence property helper class + */ + +public class Persist { + + private static final java.lang.String PREF_TIMEOUT = "TIMEOUT__"; + + @RequiredArgsConstructor + public static class String { + private final java.lang.String pref; + + public java.lang.String get() { + return getString(pref); + } + + public void set(final java.lang.String value) { + setString(pref, value); + } + } + + @RequiredArgsConstructor + public static class Long { + private final java.lang.String pref; + + public long get() { + return getLong(pref); + } + + public void set(final long value) { + setLong(pref, value); + } + } + + @RequiredArgsConstructor + public static class Double { + private final java.lang.String pref; + + public java.lang.Double get() { + return getDouble(pref); + } + + public void set(final double value) { + setDouble(pref, value); + } + } + + public static class LongTimeout extends Long { + + private final long millis; + + public LongTimeout(final java.lang.String pref, final long millis) { + super(pref); + this.millis = millis; + } + + public void set() { + set(tsl()); + } + + public boolean expired() { + return msSince(get()) > millis; + } + } + + public static class DoubleTimeout extends Double { + + private final LongTimeout timeout; + + public DoubleTimeout(final java.lang.String pref, final long millis) { + super(pref); + timeout = new LongTimeout(PREF_TIMEOUT + pref, millis); + } + + @Override + public void set(final double value) { + super.set(value); + timeout.set(); + } + + @Override + public java.lang.Double get() { + return !timeout.expired() ? super.get() : null; + } + + public void set(@NonNull final java.lang.Double value) { + if (value == null) { + throw new InvalidParameterException("Sorry null not permitted here"); + } + set((double)value); + } + + } + + public static class StringTimeout extends String { + + private final LongTimeout timeout; + + public StringTimeout(final java.lang.String pref, final long millis) { + super(pref); + timeout = new LongTimeout(PREF_TIMEOUT + pref, millis); + } + + @Override + public void set(final java.lang.String value) { + super.set(value); + timeout.set(); + } + + @Override + public java.lang.String get() { + return !timeout.expired() ? super.get() : null; + } + + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/alert/PollResult.java b/app/src/main/java/com/eveningoutpost/dexdrip/alert/PollResult.java new file mode 100644 index 0000000000..ce2edf9976 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/alert/PollResult.java @@ -0,0 +1,19 @@ +package com.eveningoutpost.dexdrip.alert; + +/** + * JamOrHam + *

+ * Data class for returning poll results to caller + */ + +public class PollResult { + + boolean remove; + boolean triggered; + + public void reset() { + remove = false; + triggered = false; + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/alert/Pollable.java b/app/src/main/java/com/eveningoutpost/dexdrip/alert/Pollable.java new file mode 100644 index 0000000000..c6db7b6fd5 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/alert/Pollable.java @@ -0,0 +1,27 @@ +package com.eveningoutpost.dexdrip.alert; + +/** + * JamOrHam + * + * Alert polling interface + */ + +public interface Pollable { + + enum When { + Reading, + Hour, + ScreenOn, + ChargeChange, + } + + // main polling method + PollResult poll(When event); + + // grouping identifier + String group(); + + // relative sorting position + int sortPos(); + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/alert/Poller.java b/app/src/main/java/com/eveningoutpost/dexdrip/alert/Poller.java new file mode 100644 index 0000000000..e4fc17f44a --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/alert/Poller.java @@ -0,0 +1,98 @@ +package com.eveningoutpost.dexdrip.alert; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; + +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.xdrip; + +import java.util.LinkedList; + +import lombok.val; + +/** + * JamOrHam + *

+ * Encapsulated poller providing external methods for trigger events + *

+ * Handles its own trigger for screen on events + */ + +public class Poller { + + private static final String TAG = "AlertSchedule"; + + public static void chargerConnectedDisconnected() { + poll(Pollable.When.ChargeChange); + } + + public static void screenOn() { + poll(Pollable.When.ScreenOn); + } + + public static void reading() { + poll(Pollable.When.Reading); + } + + public static void hour() { + poll(Pollable.When.Hour); + } + + // call from application start + public static void init() { + try { + val intentFilter = new IntentFilter(); + intentFilter.addAction(Intent.ACTION_SCREEN_ON); + + try { + xdrip.getAppContext().unregisterReceiver(screenReceiver); + } catch (Exception e) { + // + } + xdrip.getAppContext().registerReceiver(screenReceiver, intentFilter); + } catch (Exception e) { + Log.wtf(TAG, "Exception in init: " + e); + } + } + + private static void poll(final Pollable.When event) { + Log.d(TAG, "DEBUG POLL: " + event); + val remove = new LinkedList(); + val triggeredGroups = new LinkedList(); + val registry = Registry.getRegistry(); + for (val alert : registry) { + if (triggeredGroups.contains(alert.group())) { + Log.d(TAG, "Skipping due to group match: " + alert.group()); + continue; + } + val result = alert.poll(event); + if (result.remove) { + remove.add(alert); // this one asked to be removed + } + if (result.triggered) { + triggeredGroups.add(alert.group()); + } + } + for (val alert : remove) { + Registry.remove(alert); + } + } + + private static final BroadcastReceiver screenReceiver = new BroadcastReceiver() { + + @Override + public void onReceive(final Context context, final Intent intent) { + final String action = intent.getAction(); + if (action == null) return; + switch (action) { + case Intent.ACTION_SCREEN_ON: + Inevitable.task("screen-on-poll", 6000, () -> screenOn()); + break; + } + } + }; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/alert/Registry.java b/app/src/main/java/com/eveningoutpost/dexdrip/alert/Registry.java new file mode 100644 index 0000000000..e457d8d178 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/alert/Registry.java @@ -0,0 +1,79 @@ +package com.eveningoutpost.dexdrip.alert; + +import android.content.SharedPreferences; + +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; + +import java.util.ArrayList; +import java.util.List; + +import lombok.Getter; + +/** + * JamOrHam + *

+ * Registry for Pollable alert objects + */ + +public class Registry { + + private static final String TAG = "AlertRegistry"; + + @Getter + private static final List registry = new ArrayList<>(); + + // TODO allow for adjusting list and available vs enabled lists + // TODO add sorting of registry + + static { + refresh(); + } + + public static void refresh() { + synchronized (registry) { + registry.clear(); + if (Pref.getBooleanDefaultFalse("alert_raise_for_sensor_expiry")) { + registry.add(new SensorExpiry()); + } + // addGlucoseAlerts(); + // sort(); + } + } + + public static void remove(final Pollable alert) { + synchronized (registry) { + Log.d(TAG, "Removing " + alert); + registry.remove(alert); + } + } + + private static void clear() { + synchronized (registry) { + registry.clear(); + } + } + + /*private static void addGlucoseAlerts() { + synchronized (registry) { + registry.add(new CustomAlert("Ultra Low") + .setHighAlert(false) + .setSmoothedRate(false) + .setRateOfChange(0d) + .setThreshold(100)); + registry.add(new CustomAlert("Ultra High") + .setHighAlert(true) + .setSmoothedRate(false) + .setRateOfChange(0d) + .setThreshold(300)); + } + }*/ + + public static SharedPreferences.OnSharedPreferenceChangeListener prefListener = (prefs, key) -> { + if (key.startsWith("alert_")) { + Log.d(TAG, "Refreshing due to settings change"); + refresh(); + } + }; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/alert/SensorExpiry.java b/app/src/main/java/com/eveningoutpost/dexdrip/alert/SensorExpiry.java new file mode 100644 index 0000000000..dcd1f455d0 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/alert/SensorExpiry.java @@ -0,0 +1,87 @@ +package com.eveningoutpost.dexdrip.alert; + +import static com.eveningoutpost.dexdrip.models.JoH.cancelNotification; +import static com.eveningoutpost.dexdrip.models.JoH.niceTimeScalar; +import static com.eveningoutpost.dexdrip.models.JoH.niceTimeScalarNatural; +import static com.eveningoutpost.dexdrip.models.JoH.showNotification; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.SENSORY_EXPIRY_NOTIFICATION_ID; + +import com.eveningoutpost.dexdrip.g5model.SensorDays; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; + +import lombok.val; + +/** + * JamOrHam + * + * Sensor Expiry alert. Triggers when passing threshold times when user should be able to notice + */ + +public class SensorExpiry extends BaseAlert { + + private static final String TAG = SensorExpiry.class.getSimpleName(); + private static final long NOT_ALERTED = Long.MAX_VALUE; + private static final long[] THRESHOLDS = { + // need to be in ascending order so first hit is first applicable to avoid multiple triggers + Constants.HOUR_IN_MS * 2, + Constants.HOUR_IN_MS * 6, + Constants.HOUR_IN_MS * 12, + Constants.HOUR_IN_MS * 24, + }; + + private static final Persist.Long remaining = new Persist.Long("PREF_SENSOR_EXPIRE_ALERT"); + private static final Persist.Long alerted = new Persist.Long("PREF_SENSOR_EXPIRE_ALERTED"); + + public SensorExpiry() { + super("Sensor Expiry", When.ChargeChange, When.ScreenOn); + } + + @Override + public boolean activate() { + val expiry = niceTimeScalarNatural(SensorDays.get().getRemainingSensorPeriodInMs()); + val notificationId = SENSORY_EXPIRY_NOTIFICATION_ID; + cancelNotification(notificationId); + val expireMsg = String.format("Sensor will expire in %s", expiry); // TODO i18n and format string + showNotification("Sensor expiring", expireMsg, null, notificationId, null, true, true, null, null, null, true); + Treatments.create_note("Warning: " + expireMsg, tsl()); // TODO i18n but note classifier also needs updating for that + return true; + } + + @Override + public boolean isMet() { + val sd = SensorDays.get(); + if (sd.isValid()) { + val now = sd.getRemainingSensorPeriodInMs(); + val last = remaining.get(); + + try { + if (now > (last + Constants.HOUR_IN_MS)) { + Log.d(TAG, "Period rewound to: " + niceTimeScalar(now) + " was " + niceTimeScalar(last)); + alerted.set(NOT_ALERTED); + } else if (last > now) { + Log.d(TAG, "Period reduced to: " + niceTimeScalar(now) + " was " + niceTimeScalar(last)); + val lastAlerted = alerted.get(); + for (val threshold : THRESHOLDS) { + if (now <= threshold && threshold < lastAlerted) { + alerted.set(threshold); + return true; + } + } + } else { + Log.d(TAG, "Now and last identical: " + niceTimeScalar(now)); + } + + } finally { + remaining.set(now); + } + + } else { + Log.d(TAG, "Cannot evaluate as sensor days invalid"); + } + return false; + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/buffer/MyByteBuffer.java b/app/src/main/java/com/eveningoutpost/dexdrip/buffer/MyByteBuffer.java index b05dd5d8db..48e63d68e2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/buffer/MyByteBuffer.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/buffer/MyByteBuffer.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.buffer; -import static com.eveningoutpost.dexdrip.Models.JoH.reverseBytes; +import static com.eveningoutpost.dexdrip.models.JoH.reverseBytes; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/CalibrationAbstract.java b/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/CalibrationAbstract.java index 0c2ba6a41d..514de804de 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/CalibrationAbstract.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/CalibrationAbstract.java @@ -1,10 +1,10 @@ package com.eveningoutpost.dexdrip.calibrations; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.annotations.Expose; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/Datricsae.java b/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/Datricsae.java index e73f6e6254..494b8df163 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/Datricsae.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/Datricsae.java @@ -2,12 +2,11 @@ import android.util.Log; -import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.Forecast; -import com.eveningoutpost.dexdrip.Models.Forecast.PolyTrendLine; -import com.eveningoutpost.dexdrip.Models.Forecast.TrendLine; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.Forecast; +import com.eveningoutpost.dexdrip.models.Forecast.PolyTrendLine; +import com.eveningoutpost.dexdrip.models.Forecast.TrendLine; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import java.util.ArrayList; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/LastSevenUnweightedA.java b/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/LastSevenUnweightedA.java index f2d07a8626..4b3ba387d3 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/LastSevenUnweightedA.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/LastSevenUnweightedA.java @@ -2,9 +2,9 @@ import android.util.Log; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.Forecast.PolyTrendLine; -import com.eveningoutpost.dexdrip.Models.Forecast.TrendLine; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.Forecast.PolyTrendLine; +import com.eveningoutpost.dexdrip.models.Forecast.TrendLine; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import java.util.ArrayList; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/NativeCalibrationPipe.java b/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/NativeCalibrationPipe.java index 3ea5ba3a8d..349872a161 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/NativeCalibrationPipe.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/NativeCalibrationPipe.java @@ -1,15 +1,15 @@ package com.eveningoutpost.dexdrip.calibrations; -import com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Unitized; +import com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Unitized; import com.eveningoutpost.dexdrip.cgm.medtrum.Medtrum; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.HOUR_IN_MS; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.HOUR_IN_MS; /** * diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/PluggableCalibration.java b/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/PluggableCalibration.java index 785c08e798..bdd8f95e4f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/PluggableCalibration.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/PluggableCalibration.java @@ -3,9 +3,9 @@ import android.preference.ListPreference; import android.util.Log; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import java.util.HashMap; import java.util.Map; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/XDripOriginal.java b/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/XDripOriginal.java index 21f683eb8c..a65a1aa0e7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/XDripOriginal.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/calibrations/XDripOriginal.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.calibrations; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.UserError; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/CareLinkDataProcessor.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/CareLinkDataProcessor.java new file mode 100644 index 0000000000..8e0d593e65 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/CareLinkDataProcessor.java @@ -0,0 +1,342 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow; + +import com.eveningoutpost.dexdrip.Home; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.DateUtil; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.PumpStatus; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.ActiveNotification; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.Alarm; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.ClearedNotification; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.Marker; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.RecentData; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.SensorGlucose; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.TextMap; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +import static com.eveningoutpost.dexdrip.models.BgReading.SPECIAL_FOLLOWER_PLACEHOLDER; +import static com.eveningoutpost.dexdrip.models.Treatments.pushTreatmentSyncToWatch; + + +/** + * Medtronic CareLink Data Processor + * - process CareLink data and convert to xDrip internal data + * - update xDrip internal data + */ +public class CareLinkDataProcessor { + + + private static final String TAG = "CareLinkFollowDP"; + private static final boolean D = false; + + private static final String SOURCE_CARELINK_FOLLOW = "CareLink Follow"; + + + static synchronized void processData(final RecentData recentData, final boolean live) { + + List filteredSgList; + List filteredMarkerList; + + UserError.Log.d(TAG, "Start processsing data..."); + + //SKIP ALL IF EMPTY!!! + if (recentData == null) { + UserError.Log.e(TAG, "Recent data is null, processing stopped!"); + return; + } + + if (recentData.sgs == null) UserError.Log.d(TAG, "SGs is null!"); + + //SKIP DATA processing if NO PUMP CONNECTION (time shift seems to be different in this case, needs further analysis) + if (recentData.isNGP() && !recentData.pumpCommunicationState) { + UserError.Log.d(TAG, "Not connected to pump => time can be wrong, leave processing!"); + return; + } + + //SENSOR GLUCOSE (if available) + if (recentData.sgs != null) { + + final BgReading lastBg = BgReading.lastNoSenssor(); + final long lastBgTimestamp = lastBg != null ? lastBg.timestamp : 0; + + //create filtered sortable SG list + filteredSgList = new ArrayList<>(); + for (SensorGlucose sg : recentData.sgs) { + //SG DateTime is null (sensor expired?) + if (sg != null && sg.datetimeAsDate != null) { + filteredSgList.add(sg); + } + } + + if (filteredSgList.size() > 0) { + + final Sensor sensor = Sensor.createDefaultIfMissing(); + sensor.save(); + + // place in order of oldest first + Collections.sort(filteredSgList, (o1, o2) -> o1.datetimeAsDate.compareTo(o2.datetimeAsDate)); + + for (final SensorGlucose sg : filteredSgList) { + + //Not EPOCH 0 (warmup?) + if (sg.datetimeAsDate.getTime() > 1) { + + //Not in the future + if (sg.datetimeAsDate.getTime() < new Date().getTime() + 300_000) { + + //Not 0 SG (not calibrated?) + if (sg.sg > 0) { + + //newer than last BG + if (sg.datetimeAsDate.getTime() > lastBgTimestamp) { + + if (sg.datetimeAsDate.getTime() > 0) { + + //New entry + if (BgReading.getForPreciseTimestamp(sg.datetimeAsDate.getTime(), 10_000) == null) { + UserError.Log.d(TAG, "NEW NEW NEW New entry: " + sg.toS()); + + if (live) { + final BgReading bg = new BgReading(); + bg.timestamp = sg.datetimeAsDate.getTime(); + bg.calculated_value = (double) sg.sg; + bg.raw_data = SPECIAL_FOLLOWER_PLACEHOLDER; + bg.filtered_data = (double) sg.sg; + bg.noise = ""; + bg.uuid = UUID.randomUUID().toString(); + bg.calculated_value_slope = 0; + bg.sensor = sensor; + bg.sensor_uuid = sensor.uuid; + bg.source_info = SOURCE_CARELINK_FOLLOW; + bg.save(); + bg.find_slope(); + Inevitable.task("entry-proc-post-pr", 500, () -> bg.postProcess(false)); + } + } + } else { + UserError.Log.e(TAG, "Could not parse a timestamp from: " + sg.toS()); + } + } + + } else { + UserError.Log.d(TAG, "SG is 0 (calibration missed?)"); + } + + } else { + UserError.Log.d(TAG, "SG DateTime is 0 (warmup phase?)"); + } + } else { + UserError.Log.d(TAG, "SG DateTime in future: " + sg.datetime); + } + } + } + } + + + //MARKERS (if available) + if (recentData.markers != null) { + + //Filter markers + filteredMarkerList = new ArrayList<>(); + for (Marker marker : recentData.markers) { + if (marker != null && marker.type != null && marker.dateTime != null) { + filteredMarkerList.add(marker); + } + } + + if (filteredMarkerList.size() > 0) { + //sort markers by time + Collections.sort(filteredMarkerList, (o1, o2) -> o1.dateTime.compareTo(o2.dateTime)); + + //process markers one-by-one + for (Marker marker : filteredMarkerList) { + + //FINGER BG + if (marker.isBloodGlucose() && Pref.getBooleanDefaultFalse("clfollow_download_finger_bgs")) { + //check required values + if (marker.value != null && !marker.value.equals(0)) { + //new blood test + if (BloodTest.getForPreciseTimestamp(marker.dateTime.getTime(), 10000) == null) { + BloodTest.create(marker.dateTime.getTime(), marker.value, SOURCE_CARELINK_FOLLOW); + } + } + + //INSULIN, MEAL => Treatment + } else if ((marker.type.equals(Marker.MARKER_TYPE_INSULIN) && Pref.getBooleanDefaultFalse("clfollow_download_boluses")) + || (marker.type.equals(Marker.MARKER_TYPE_MEAL) && Pref.getBooleanDefaultFalse("clfollow_download_meals"))) { + + //insulin, meal only for pumps (not value in case of GC) + if (recentData.isNGP()) { + + final Treatments t; + double carbs = 0; + double insulin = 0; + + //Extract treament infos (carbs, insulin) + //Insulin + if (marker.type.equals(Marker.MARKER_TYPE_INSULIN)) { + carbs = 0; + if (marker.deliveredExtendedAmount != null && marker.deliveredFastAmount != null) { + insulin = marker.deliveredExtendedAmount + marker.deliveredFastAmount; + } + //SKIP if insulin = 0 + if (insulin == 0) continue; + //Carbs + } else if (marker.type.equals(Marker.MARKER_TYPE_MEAL)) { + if (marker.amount != null) { + carbs = marker.amount; + } + insulin = 0; + //SKIP if carbs = 0 + if (carbs == 0) continue; + } + + //new Treatment + if (newTreatment(carbs, insulin, marker.dateTime.getTime())) { + t = Treatments.create(carbs, insulin, marker.dateTime.getTime()); + if (t != null) { + t.enteredBy = SOURCE_CARELINK_FOLLOW; + t.save(); + if (Home.get_show_wear_treatments()) + pushTreatmentSyncToWatch(t, true); + } + } + } + + } + + } + } + } + + //PUMP INFO (Pump Status) + if (recentData.isNGP()) { + PumpStatus.setReservoir(recentData.reservoirRemainingUnits); + PumpStatus.setBattery(recentData.medicalDeviceBatteryLevelPercent); + if (recentData.activeInsulin != null) + PumpStatus.setBolusIoB(recentData.activeInsulin.amount); + PumpStatus.syncUpdate(); + } + + // LAST ALARM -> NOTE (only for GC) + if (Pref.getBooleanDefaultFalse("clfollow_download_notifications")) { + + // Only Guardian Connect, NGP has all in notifications + if (recentData.isGM() && recentData.lastAlarm != null) { + //Add notification from alarm + if (recentData.lastAlarm.datetimeAsDate != null && recentData.lastAlarm.kind != null) + addNotification(recentData.lastAlarm.datetimeAsDate, recentData.getDeviceFamily(), recentData.lastAlarm); + } + } + + + //NOTIFICATIONS -> NOTE + if (Pref.getBooleanDefaultFalse("clfollow_download_notifications")) { + if (recentData.notificationHistory != null) { + //Active Notifications + if (recentData.notificationHistory.activeNotifications != null) { + for (ActiveNotification activeNotification : recentData.notificationHistory.activeNotifications) { + addNotification(activeNotification.dateTime, recentData.getDeviceFamily(), activeNotification.messageId, activeNotification.faultId); + } + } + //Cleared Notifications + if (recentData.notificationHistory.clearedNotifications != null) { + for (ClearedNotification clearedNotification : recentData.notificationHistory.clearedNotifications) { + addNotification(clearedNotification.triggeredDateTime, recentData.getDeviceFamily(), clearedNotification.messageId, clearedNotification.faultId); + } + } + } + } + + } + + //Check if treatment is new (no identical entry (timestamp, carbs, insulin) exists) + protected static boolean newTreatment(double carbs, double insulin, long timestamp) { + + List treatmentsList; + //Treatment with same timestamp and carbs + insulin exists? + treatmentsList = Treatments.listByTimestamp(timestamp); + if (treatmentsList != null) { + for (Treatments treatments : treatmentsList) { + if (treatments.carbs == carbs && treatments.insulin == insulin) + return false; + } + } + return true; + } + + + //Create notification from CareLink messageId + protected static boolean addNotification(Date date, String deviceFamily, String messageId, int faultId) { + + if (deviceFamily != null && messageId != null) + return addNotification(date, TextMap.getNotificationMessage(deviceFamily, messageId, faultId)); + else + return false; + + } + + //Create notification from CareLink Alarm + protected static boolean addNotification(Date date, String deviceFamily, Alarm alarm) { + + if (deviceFamily != null && alarm != null && alarm.kind != null) + return addNotification(date, TextMap.getAlarmMessage(deviceFamily, alarm)); + else + return false; + + } + + //Create notification from CareLink note info + protected static boolean addNotification(Date date, String noteText) { + + //Valid date + if (date != null && noteText != null) { + //New note + if (newNote(noteText, date.getTime())) { + //create_note in Treatment is not good, because of automatic link to other treatments in 5 mins range + Treatments note = new Treatments(); + note.notes = noteText; + note.timestamp = date.getTime(); + note.created_at = DateUtil.toISOString(note.timestamp); + note.uuid = UUID.randomUUID().toString(); + note.enteredBy = SOURCE_CARELINK_FOLLOW; + note.save(); + if (Home.get_show_wear_treatments()) + pushTreatmentSyncToWatch(note, true); + return true; + } + } + + return false; + + } + + + //Check note is new + protected static boolean newNote(String note, long timestamp) { + + List treatmentsList; + //Treatment with same timestamp and note text exists? + treatmentsList = Treatments.listByTimestamp(timestamp); + if (treatmentsList != null) { + for (Treatments treatments : treatmentsList) { + if (treatments.notes.contains(note)) + return false; + } + } + + return true; + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/CareLinkFollowDownloader.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/CareLinkFollowDownloader.java new file mode 100644 index 0000000000..a7bf88176c --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/CareLinkFollowDownloader.java @@ -0,0 +1,220 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow; + +import android.os.PowerManager; + +import com.eveningoutpost.dexdrip.R; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth.CareLinkAuthenticator; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth.CareLinkCredentialStore; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.client.CareLinkClient; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.RecentData; +import com.eveningoutpost.dexdrip.xdrip; + +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; + +/** + * CareLink Downloader + * - download data from CareLink + * - execute data conversion and update xDrip data + */ +public class CareLinkFollowDownloader { + + private static final String TAG = "CareLinkFollowDL"; + private static final boolean D = false; + + private String carelinkUsername; + private String carelinkPassword; + private String carelinkCountry; + private String carelinkPatient; + + private CareLinkClient careLinkClient; + + private boolean loginDataLooksOkay; + + private static PowerManager.WakeLock wl; + + private String status; + + private int lastResponseCode = 0; + + public String getStatus() { + return status; + } + + CareLinkFollowDownloader(String carelinkUsername, String carelinkPassword, String carelinkCountry, String carelinkPatient) { + this.carelinkUsername = carelinkUsername; + this.carelinkPassword = carelinkPassword; + this.carelinkCountry = carelinkCountry; + this.carelinkPatient = carelinkPatient; + loginDataLooksOkay = !emptyString(carelinkUsername) && !emptyString(carelinkPassword) && carelinkCountry != null && !emptyString(carelinkCountry); + loginDataLooksOkay = true; + } + + public static void resetInstance() { + UserError.Log.d(TAG, "Instance reset"); + CollectionServiceStarter.restartCollectionServiceBackground(); + } + + public void doEverything(boolean refreshToken, boolean downloadData) { + if (refreshToken) + this.refreshToken(); + if (downloadData) + this.downloadData(); + } + + private void downloadData() { + msg(xdrip.gs(R.string.carelink_download_start)); + if (checkCredentials(true, true, true)) { + try { + if (getCareLinkClient() != null) { + extendWakeLock(30_000); + backgroundProcessConnectData(); + } else { + UserError.Log.d(TAG, "Cannot get data as CareLinkClient is null"); + msg(xdrip.gs(R.string.carelink_download_failed)); + } + } catch (Exception e) { + UserError.Log.e(TAG, "Got exception in getData() " + e); + releaseWakeLock(); + msg(xdrip.gs(R.string.carelink_download_failed)); + } + } + } + + private void refreshToken() { + msg(xdrip.gs(R.string.carelink_refresh_token_start)); + if (checkCredentials(true, false, true)) { + try { + if (new CareLinkAuthenticator(CareLinkCredentialStore.getInstance().getCredential().country, CareLinkCredentialStore.getInstance()).refreshToken()) { + UserError.Log.d(TAG, "Access renewed!"); + msg(null); + } else { + UserError.Log.e(TAG, "Error renewing access token!"); + msg(xdrip.gs(R.string.carelink_refresh_token_failed)); + } + } catch (Exception e) { + UserError.Log.e(TAG, "Error renewing access token: " + e.getMessage()); + msg(xdrip.gs(R.string.carelink_refresh_token_failed)); + } + } + } + + private boolean checkCredentials(boolean checkAuthenticated, boolean checkAccessExpired, boolean checkRefreshExpired) { + // Not authenticated + if (checkAuthenticated && CareLinkCredentialStore.getInstance().getAuthStatus() != CareLinkCredentialStore.AUTHENTICATED) { + msg(xdrip.gs(R.string.carelink_credential_status_not_authenticated)); + return false; + } + if (checkAccessExpired && CareLinkCredentialStore.getInstance().getAccessExpiresIn() <= 0) { + msg(xdrip.gs(R.string.carelink_credential_status_access_expired)); + return false; + } + if (checkRefreshExpired && CareLinkCredentialStore.getInstance().getRefreshExpiresIn() <= 0) { + msg(xdrip.gs(R.string.carelink_credential_status_refresh_expired)); + return false; + } + return true; + } + + private void msg(final String msg) { + status = msg != null ? JoH.hourMinuteString() + ": " + msg : null; + if (msg != null) UserError.Log.d(TAG, "Setting message: " + status); + } + + public void invalidateSession() { + this.careLinkClient = null; + } + + private void backgroundProcessConnectData() { + Inevitable.task("proc-carelink-follow", 100, this::processConnectData); + releaseWakeLock(); // handover to inevitable + } + + // don't call this directly unless you are also handling the wakelock release + private void processConnectData() { + + RecentData recentData = null; + CareLinkClient carelinkClient = null; + + + //Get client + carelinkClient = getCareLinkClient(); + //Get RecentData from CareLink client + if (carelinkClient != null) { + //Get data + try { + if (JoH.emptyString(this.carelinkPatient)) + recentData = getCareLinkClient().getRecentData(); + else + recentData = getCareLinkClient().getRecentData(this.carelinkPatient); + lastResponseCode = carelinkClient.getLastResponseCode(); + } catch (Exception e) { + UserError.Log.e(TAG, "Exception in CareLink data download: " + e); + } + + //Process data + if (recentData != null) { + UserError.Log.d(TAG, "Success get data!"); + try { + UserError.Log.d(TAG, "Start process data"); + //Process CareLink data (conversion and update xDrip data) + CareLinkDataProcessor.processData(recentData, true); + UserError.Log.d(TAG, "ProcessData finished!"); + //Update Service status + CareLinkFollowService.updateBgReceiveDelay(); + msg(null); + } catch (Exception e) { + UserError.Log.e(TAG, "Exception in data processing: " + e); + msg("Data processing error!"); + } + //Data receive error + } else { + if (carelinkClient.getLastResponseCode() == 401) { + UserError.Log.e(TAG, "CareLink login error! Response code: " + carelinkClient.getLastResponseCode()); + msg("Login error!"); + //login error + } else { + UserError.Log.e(TAG, "CareLink download error! Response code: " + carelinkClient.getLastResponseCode()); + UserError.Log.e(TAG, "Error message: " + getCareLinkClient().getLastErrorMessage()); + msg("Download data failed!"); + } + } + } + + } + + + private CareLinkClient getCareLinkClient() { + if (careLinkClient == null) { + try { + UserError.Log.d(TAG, "Creating CareLinkClient"); + if (CareLinkCredentialStore.getInstance().getAuthStatus() == CareLinkCredentialStore.AUTHENTICATED) + careLinkClient = new CareLinkClient(CareLinkCredentialStore.getInstance()); + } catch (Exception e) { + UserError.Log.e(TAG, "Error creating CareLinkClient", e); + } + } + return careLinkClient; + } + + + private static synchronized void extendWakeLock(final long ms) { + if (wl == null) { + if (D) UserError.Log.d(TAG, "Creating wakelock"); + wl = JoH.getWakeLock("CLFollow-download", (int) ms); + } else { + JoH.releaseWakeLock(wl); // lets not get too messy + wl.acquire(ms); + if (D) UserError.Log.d(TAG, "Extending wakelock"); + } + } + + protected static synchronized void releaseWakeLock() { + if (D) UserError.Log.d(TAG, "Releasing wakelock"); + JoH.releaseWakeLock(wl); + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/CareLinkFollowService.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/CareLinkFollowService.java new file mode 100644 index 0000000000..1a991f1e37 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/CareLinkFollowService.java @@ -0,0 +1,395 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow; + +import android.content.Intent; +import android.os.IBinder; +import android.os.PowerManager; +import androidx.annotation.Nullable; +import android.text.SpannableString; + +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth.CareLinkCredentialStore; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; +import com.eveningoutpost.dexdrip.utils.DexCollectionType; +import com.eveningoutpost.dexdrip.utils.framework.BuggySamsung; +import com.eveningoutpost.dexdrip.utils.framework.ForegroundService; +import com.eveningoutpost.dexdrip.utils.framework.WakeLockTrampoline; +import com.eveningoutpost.dexdrip.xdrip; + +import java.util.ArrayList; +import java.util.List; + +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder.DEXCOM_PERIOD; + +/** + * CareLink Follow Service + * - main service class for managing CareLink Connect data retrieval + * - start/stop data retrieval + * - provide status infos of follower service + */ + +public class CareLinkFollowService extends ForegroundService { + + private static final String TAG = "CareLinkFollow"; + private static final long SAMPLE_PERIOD = DEXCOM_PERIOD; + private static final int RATE_LIMIT_SECONDS = 20; + private static final String RATE_LIMIT_NAME = "last-carelink-follow-poll"; + private static final int RATE_LIMIT_SAFETY = 10; + + protected static volatile String lastState = ""; + + private static BuggySamsung buggySamsung; + private static volatile long wakeup_time = 0; + private static volatile long last_wakeup = 0; + private static volatile long lastPoll = 0; + private static volatile BgReading lastBg; + private static volatile long bgReceiveDelay; + private static volatile long lastBgTime; + + private static CareLinkFollowDownloader downloader; + private static volatile int gracePeriod = 0; + private static volatile int missedPollInterval = 0; + private static volatile int renewBefore = 0; + private static volatile int renewInterval = 0; + + + @Override + public void onCreate() { + super.onCreate(); + resetInstance(); // manage static reference life cycle + } + + + /** + * Update observedDelay if new bg reading is available + */ + static void updateBgReceiveDelay() { + lastBg = BgReading.lastNoSenssor(); + if (lastBg != null && lastBgTime != lastBg.timestamp) { + bgReceiveDelay = JoH.msSince(lastBg.timestamp); + lastBgTime = lastBg.timestamp; + } + } + + public synchronized static void resetInstanceAndInvalidateSession() { + try { + if (downloader != null) { + downloader.invalidateSession(); + } + } catch (Exception e) { + // concurrency related + } + resetInstance(); + } + + public static void resetInstance() { + downloader = null; + gracePeriod = 0; + missedPollInterval = 0; + renewBefore = 0; + renewInterval = 0; + } + + private static boolean shouldServiceRun() { + return DexCollectionType.getDexCollectionType() == DexCollectionType.CLFollow; + } + + private static long getGraceMillis() { + return Constants.SECOND_IN_MS * gracePeriod; + } + + private static long getMissedIntervalMillis() { + if (missedPollInterval == 0) + return SAMPLE_PERIOD; + else + return Constants.MINUTE_IN_MS * missedPollInterval; + } + + private static long getRenewBeforeMillis() { + return Constants.MINUTE_IN_MS * renewBefore; + } + + private static long getRenewIntervalMillis() { + return Constants.MINUTE_IN_MS * renewInterval; + } + + static void scheduleWakeUp() { + + String scheduleReason; + long next; + + final BgReading lastBg = BgReading.lastNoSenssor(); + final long last = lastBg != null ? lastBg.timestamp : 0; + + final long nextTokenRefresh = anticipateNextTokenRefresh(JoH.tsl(), CareLinkCredentialStore.getInstance().getAccessExpiresOn(), getRenewBeforeMillis(), getRenewIntervalMillis()); + final long nextDataPoll = anticipateNextDataPoll(JoH.tsl(), last, SAMPLE_PERIOD, getGraceMillis(), getMissedIntervalMillis()); + + // Token needs to refreshed sooner + if (nextTokenRefresh <= nextDataPoll) { + next = nextTokenRefresh; + scheduleReason = " as access expires: "; + // Data is required sooner + } else { + next = nextDataPoll; + scheduleReason = " as last BG timestamp: "; + } + + if (JoH.msTill(next) < (RATE_LIMIT_SECONDS * Constants.SECOND_IN_MS)) + next = JoH.tsl() + (RATE_LIMIT_SECONDS * Constants.SECOND_IN_MS); + + wakeup_time = next; + UserError.Log.d(TAG, "Anticipate next: " + JoH.dateTimeText(next) + scheduleReason + JoH.dateTimeText(last)); + + JoH.wakeUpIntent(xdrip.getAppContext(), JoH.msTill(next), WakeLockTrampoline.getPendingIntent(CareLinkFollowService.class, Constants.CARELINK_SERVICE_FAILOVER_ID)); + } + + private static long anticipateNextTokenRefresh(long now, final long expiry, final long before, final long interval) { + + long next; + + // refresh should happen before expiration + next = expiry - before; + // add retry interval until future + while (next <= now) { + next += interval; + } + + return next; + + } + + public static long anticipateNextDataPoll(long now, final long last, final long period, final long grace, final long missedInterval) { + + long next; + + //recent reading (less then data period) => last + period + grace + if ((now - last) < period) { + next = last + period + grace; + } + //old reading => anticipated next + grace + else { + //last expected + next = now + ((last - now) % period); + //add missed poll interval until future time is reached + while (next <= now) { + next += missedInterval; + } + //add grace + next += grace; + } + + return next; + + } + + private static CareLinkFollowDownloader getDownloader() { + if (downloader == null) { + downloader = new CareLinkFollowDownloader( + Pref.getString("clfollow_user", ""), + Pref.getString("clfollow_pass", ""), + Pref.getString("clfollow_country", "").toLowerCase(), + Pref.getString("clfollow_patient", "") + ); + } + return downloader; + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + final PowerManager.WakeLock wl = JoH.getWakeLock("CareLinkFollow-osc", 60000); + try { + + UserError.Log.d(TAG, "WAKE UP WAKE UP WAKE UP"); + + // Check service should be running + if (!shouldServiceRun()) { + UserError.Log.d(TAG, "Stopping service due to shouldServiceRun() result"); + msg("Stopping"); + stopSelf(); + return START_NOT_STICKY; + } + buggySamsungCheck(); + + last_wakeup = JoH.tsl(); + + // Check current + if (gracePeriod == 0) + gracePeriod = Pref.getStringToInt("clfollow_grace_period", 30); + if (missedPollInterval == 0) + missedPollInterval = Pref.getStringToInt("clfollow_missed_poll_interval", 5); + if (renewBefore == 0) + renewBefore = 10; + if (renewInterval == 0) + renewInterval = 1; + lastBg = BgReading.lastNoSenssor(); + if (lastBg != null) { + lastBgTime = lastBg.timestamp; + } + // Check if downloader needs to be started (last BG old or token needs to be renewed) + final boolean refreshToken = (JoH.msTill(CareLinkCredentialStore.getInstance().getAccessExpiresOn()) < getRenewBeforeMillis()) ? true : false; + final boolean downloadData = (lastBg == null || msSince(lastBg.timestamp) > SAMPLE_PERIOD + getGraceMillis()) ? true : false; + if (refreshToken || downloadData) { + //Only start if rate limit is not exceeded + if (JoH.ratelimit(RATE_LIMIT_NAME, RATE_LIMIT_SAFETY)) { + Inevitable.task("CareLink-Follow-Work", 200, () -> { + try { + getDownloader().doEverything(refreshToken, downloadData); + } catch (NullPointerException e) { + UserError.Log.e(TAG, "Caught concurrency exception when trying to run doeverything"); + } + }); + lastPoll = JoH.tsl(); + } + } else { + UserError.Log.d(TAG, "Already have recent reading: " + msSince(lastBg.timestamp)); + } + scheduleWakeUp(); + } finally { + JoH.releaseWakeLock(wl); + } + return START_STICKY; + } + + /** + * MegaStatus for Connect Follower + */ + public static List megaStatus() { + final BgReading lastBg = BgReading.lastNoSenssor(); + + long hightlightGrace = Constants.SECOND_IN_MS * getGraceMillis() + Constants.SECOND_IN_MS * 10; //garce + 20 seconds for processing + + // Status for BG receive delay (time from bg was recorded till received in xdrip) + String ageOfBgLastPoll = "n/a"; + StatusItem.Highlight ageOfLastBgPollHighlight = StatusItem.Highlight.NORMAL; + if (bgReceiveDelay > 0) { + ageOfBgLastPoll = JoH.niceTimeScalar(bgReceiveDelay); + if (bgReceiveDelay > SAMPLE_PERIOD / 2) { + ageOfLastBgPollHighlight = StatusItem.Highlight.BAD; + } + if (bgReceiveDelay > SAMPLE_PERIOD * 2) { + ageOfLastBgPollHighlight = StatusItem.Highlight.CRITICAL; + } + } + + // Status for time since latest BG + String ageLastBg = "n/a"; + StatusItem.Highlight bgAgeHighlight = StatusItem.Highlight.NORMAL; + if (lastBg != null) { + long age = JoH.msSince(lastBg.timestamp); + ageLastBg = JoH.niceTimeScalar(age); + if (age > SAMPLE_PERIOD + hightlightGrace) { + bgAgeHighlight = StatusItem.Highlight.BAD; + } + } + + // Status of authentication + String authStatus = null; + StatusItem.Highlight authHighlight = null; + switch (CareLinkCredentialStore.getInstance().getAuthStatus()) { + case CareLinkCredentialStore.NOT_AUTHENTICATED: + authStatus = "NOT AUTHENTICATED"; + authHighlight = StatusItem.Highlight.CRITICAL; + break; + case CareLinkCredentialStore.AUTHENTICATED: + authHighlight = StatusItem.Highlight.GOOD; + authStatus = "AUTHENTICATED"; + break; + case CareLinkCredentialStore.ACCESS_EXPIRED: + authHighlight = StatusItem.Highlight.NOTICE; + authStatus = "ACCESS EXPIRED"; + break; + case CareLinkCredentialStore.REFRESH_EXPIRED: + authHighlight = StatusItem.Highlight.BAD; + authStatus = "REFRESH EXPIRED"; + break; + } + + //Client type + String clientType = "Unkown"; + try { + switch (CareLinkCredentialStore.getInstance().getCredential().authType) { + case Browser: + clientType = "Browser"; + break; + case MobileApp: + clientType = "CarePartner app"; + break; + } + } catch (Exception ex) { + } + + //Build status screeen + List megaStatus = new ArrayList<>(); + megaStatus.add(new StatusItem("Client type", clientType)); + megaStatus.add(new StatusItem("Authentication status", authStatus, authHighlight)); + megaStatus.add(new StatusItem("Access expires in", JoH.niceTimeScalar(CareLinkCredentialStore.getInstance().getAccessExpiresIn()))); + megaStatus.add(new StatusItem("Login expires in", JoH.niceTimeScalar(CareLinkCredentialStore.getInstance().getRefreshExpiresIn()))); + megaStatus.add(new StatusItem()); + megaStatus.add(new StatusItem("Latest BG", ageLastBg + (lastBg != null ? " ago" : ""), bgAgeHighlight)); + megaStatus.add(new StatusItem("BG receive delay", ageOfBgLastPoll, ageOfLastBgPollHighlight)); + megaStatus.add(new StatusItem("Data period:", JoH.niceTimeScalar(SAMPLE_PERIOD))); + megaStatus.add(new StatusItem("Grace period:", JoH.niceTimeScalar(getGraceMillis()))); + megaStatus.add(new StatusItem("Missed poll interval:", JoH.niceTimeScalar(getMissedIntervalMillis()))); + megaStatus.add(new StatusItem()); + megaStatus.add(new StatusItem("Last poll", lastPoll > 0 ? JoH.niceTimeScalar(JoH.msSince(lastPoll)) + " ago" : "n/a")); + megaStatus.add(new StatusItem("Last wakeup", last_wakeup > 0 ? JoH.niceTimeScalar(JoH.msSince(last_wakeup)) + " ago" : "n/a")); + megaStatus.add(new StatusItem("Next poll in", JoH.niceTimeScalar(wakeup_time - JoH.tsl()))); + if (lastBg != null) { + megaStatus.add(new StatusItem("Last BG time", JoH.dateTimeText(lastBg.timestamp))); + } + megaStatus.add(new StatusItem("Last poll time", lastPoll > 0 ? JoH.dateTimeText(lastPoll) : "n/a")); + megaStatus.add(new StatusItem("Next poll time", JoH.dateTimeText(wakeup_time))); + megaStatus.add(new StatusItem()); + megaStatus.add(new StatusItem("Buggy handset", JoH.buggy_samsung ? "Yes" : "No")); + + return megaStatus; + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } + + @Override + public void onDestroy() { + super.onDestroy(); + resetInstance(); // manage static reference life cycle + } + + private void buggySamsungCheck() { + if (buggySamsung == null) { + buggySamsung = new BuggySamsung(TAG); + } + buggySamsung.evaluate(wakeup_time); + wakeup_time = 0; + } + + private static void msg(final String msg) { + lastState = msg; + } + + private static String getBestStatusMessage() { + // service state overrides downloader state reply + if (emptyString(lastState)) { + if (downloader != null) { + return downloader.getStatus(); + } + } else { + return lastState; + } + return null; + } + + public static SpannableString nanoStatus() { + final String current_state = getBestStatusMessage(); + return emptyString(current_state) ? null : new SpannableString(current_state); + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CareLinkAuthType.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CareLinkAuthType.java new file mode 100644 index 0000000000..b4f09a6176 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CareLinkAuthType.java @@ -0,0 +1,6 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth; + +public enum CareLinkAuthType { + Browser, + MobileApp +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CareLinkAuthentication.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CareLinkAuthentication.java new file mode 100644 index 0000000000..d7d87e1fb3 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CareLinkAuthentication.java @@ -0,0 +1,20 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth; + +import okhttp3.Headers; + +public class CareLinkAuthentication { + + public CareLinkAuthType authType; + private Headers.Builder builder; + + public CareLinkAuthentication(Headers headers, CareLinkAuthType authType) { + this.builder = new Headers.Builder(); + this.builder.addAll(headers); + this.authType = authType; + } + + public Headers getHeaders() { + return builder.build(); + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CareLinkAuthenticator.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CareLinkAuthenticator.java new file mode 100644 index 0000000000..a53ec08f68 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CareLinkAuthenticator.java @@ -0,0 +1,861 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth; + +import android.app.Activity; +import android.app.Dialog; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.graphics.Bitmap; +import android.net.UrlQuerySanitizer; +import android.os.Handler; +import android.os.Looper; + +import android.view.ViewGroup; +import android.webkit.CookieManager; +import android.webkit.WebResourceError; +import android.webkit.WebResourceRequest; +import android.webkit.WebView; +import android.webkit.WebViewClient; + +import com.eveningoutpost.dexdrip.R; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.xdrip; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +import java.io.IOException; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.security.KeyPairGenerator; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.security.KeyPair; +import java.security.SecureRandom; +import java.text.SimpleDateFormat; +import java.util.ArrayList; + +import android.util.Base64; +import android.widget.LinearLayout; +import android.widget.ProgressBar; + +import androidx.appcompat.widget.LinearLayoutCompat; + +import org.bouncycastle.openssl.jcajce.JcaPEMWriter; +import org.bouncycastle.operator.ContentSigner; +import org.bouncycastle.operator.OperatorCreationException; +import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; +import org.bouncycastle.pkcs.PKCS10CertificationRequest; +import org.bouncycastle.pkcs.PKCS10CertificationRequestBuilder; +import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequestBuilder; + +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.Random; +import java.util.UUID; +import java.util.concurrent.Semaphore; + +import javax.security.auth.x500.X500Principal; + +import okhttp3.ConnectionPool; +import okhttp3.Cookie; +import okhttp3.FormBody; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class CareLinkAuthenticator { + + private static final String TAG = "CareLinkAuthenticator"; + + protected static final String CAREPARTNER_APP_DISCO_URL = "https://clcloud.minimed.com/connect/carepartner/v6/discover/android/3.1"; + protected static final String CARELINK_CONNECT_SERVER_EU = "carelink.minimed.eu"; + protected static final String CARELINK_CONNECT_SERVER_US = "carelink.minimed.com"; + protected static final String CARELINK_LANGUAGE_EN = "en"; + protected static final String CARELINK_AUTH_TOKEN_COOKIE_NAME = "auth_tmp_token"; + protected static final String CARELINK_TOKEN_VALIDTO_COOKIE_NAME = "c_token_valid_to"; + + protected static final String[] ANDROID_MODELS = { + "SM-G973F", + "SM-G988U1", + "SM-G981W", + "SM-G9600" + }; + + protected static final SimpleDateFormat[] VALIDTO_DATE_FORMATS = { + new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy", Locale.ENGLISH), + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.ENGLISH), + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz", Locale.ENGLISH), + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.ENGLISH), + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH), + //new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX", Locale.ENGLISH), + //new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX", Locale.ENGLISH), + new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy"), + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"), + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz"), + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"), + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"), + //new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX"), + //new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX") + }; + + private static final int PKCE_BASE64_ENCODE_SETTINGS = + Base64.NO_WRAP | Base64.NO_PADDING | Base64.URL_SAFE; + + + private final Semaphore available = new Semaphore(0, true); + private AlertDialog progressDialog; + private String carelinkCountry; + private CareLinkCredentialStore credentialStore; + private CarePartnerAppConfig carepartnerAppConfig; + private String authCode = null; + private OkHttpClient httpClient = null; + private boolean authWebViewCancelled = false; + private boolean carelinkCommunicationError = false; + + + public CareLinkAuthenticator(String carelinkCountry, CareLinkCredentialStore credentialStore) { + this.carelinkCountry = carelinkCountry; + this.credentialStore = credentialStore; + } + + public boolean authenticate(Activity context, CareLinkAuthType authType) throws InterruptedException { + + if (Looper.myLooper() == Looper.getMainLooper()) + throw new RuntimeException("don't call authenticate() from the main thread."); + + //Execute authentication method of authentication type + switch (authType) { + case Browser: + this.authenticateAsBrowser(context); + break; + case MobileApp: + this.authenticateAsCpApp(context); + break; + } + + //Return: is authenticated + return (credentialStore.getAuthStatus() == CareLinkCredentialStore.AUTHENTICATED); + } + + public boolean refreshToken() { + //Have credential, authType is known, already authenticated + if (credentialStore.getCredential() != null && credentialStore.getCredential().authType != null && credentialStore.getAuthStatus() != CareLinkCredentialStore.NOT_AUTHENTICATED) { + switch (credentialStore.getCredential().authType) { + case Browser: + return this.refreshBrowserToken(); + case MobileApp: + return this.refreshCpAppToken(); + default: + return false; + } + } else { + return false; + } + } + + private void authenticateAsCpApp(Activity context) { + + String deviceId; + String androidModel; + String clientId; + String clientSecret; + String magIdentifier; + JsonObject clientCredential; + String codeVerifier; + String authUrl; + String idToken; + String idTokenType; + + try { + + carelinkCommunicationError = false; + + //Show progress dialog while preparing for login page + this.showProgressDialog(context); + + //Generate ID, models + deviceId = generateDeviceId(); + androidModel = this.generateAndroidModel(); + + //Load application config + this.loadAppConfig(); + + //Create client credential + clientCredential = this.createClientCredential(deviceId); + clientId = clientCredential.get("client_id").getAsString(); + clientSecret = clientCredential.get("client_secret").getAsString(); + + //Prepare authentication + UserError.Log.d(TAG, "Prepare authentication"); + codeVerifier = generateRandomDataBase64url(32); + authUrl = this.prepareAuth(clientId, codeVerifier); + + //Hide progress dialog + this.hideProgressDialog(); + + //Authenticate in browser + UserError.Log.d(TAG, "Start browser login"); + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + CareLinkAuthenticator.this.showCpAppAuthPage(context, authUrl); + } + }); + available.acquire(); + + //Continue if not cancelled and no error + if (!this.authWebViewCancelled && !carelinkCommunicationError) { + //Show progress dialog while completing authentication + this.showProgressDialog(context); + + //Register device + UserError.Log.d(TAG, "Register device"); + Response registerResp = this.registerDevice(deviceId, androidModel, clientId, clientSecret, authCode, codeVerifier); + magIdentifier = registerResp.header("mag-identifier"); + idToken = registerResp.header("id-token"); + idTokenType = registerResp.header("id-token-type"); + + //Get access token + UserError.Log.d(TAG, "Get access token"); + JsonObject tokenObject = this.getAccessToken(clientId, clientSecret, magIdentifier, idToken, idTokenType); + + //Store credentials + UserError.Log.d(TAG, "Store credentials"); + this.credentialStore.setMobileAppCredential(this.carelinkCountry, + deviceId, androidModel, clientId, clientSecret, magIdentifier, + tokenObject.get("access_token").getAsString(), tokenObject.get("refresh_token").getAsString(), + //new Date(Calendar.getInstance().getTime().getTime() + 15 * 60000), + //new Date(Calendar.getInstance().getTime().getTime() + 30 * 60000)); + new Date(Calendar.getInstance().getTime().getTime() + (tokenObject.get("expires_in").getAsInt() * 1000)), + new Date(Calendar.getInstance().getTime().getTime() + (this.carepartnerAppConfig.getRefreshLifetimeSec() * 1000))); + + //Hide progress dialog + this.hideProgressDialog(); + } + + } catch (Exception ex) { + UserError.Log.e(TAG, "Error authenticating as CpApp. Details: \r\n " + ex.getMessage()); + carelinkCommunicationError = true; + this.hideProgressDialog(); + } + + //Show communication error + if (carelinkCommunicationError) { + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + new AlertDialog.Builder(context) + .setTitle("Communication error!") + .setMessage("Error communicating with CareLink Server! Please try again later!") + .setCancelable(true) + .setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + dialogInterface.cancel(); + } + }) + .show(); + } + }); + } + + } + + private void authenticateAsBrowser(Activity context) throws InterruptedException { + + //Authenticate in browser + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + CareLinkAuthenticator.this.showBrowserAuthPage(context, ""); + } + }); + available.acquire(); + } + + private OkHttpClient getHttpClient() { + if (this.httpClient == null) + this.httpClient = new OkHttpClient(); + return this.httpClient; + } + + private boolean loadAppConfig() throws IOException { + if (carepartnerAppConfig == null) { + carepartnerAppConfig = new CarePartnerAppConfig(); + UserError.Log.d(TAG, "Get region config"); + carepartnerAppConfig.regionConfig = this.getCpAppRegionConfig(); + UserError.Log.d(TAG, "Get SSO config"); + carepartnerAppConfig.ssoConfig = this.getCpAppSSOConfig(carepartnerAppConfig.getSSOConfigUrl()); + } + return true; + } + + private JsonObject getAccessToken(String clientId, String clientSecret, String magIdentifier, String idToken, String idTokenType) throws IOException { + return this.getToken(clientId, clientSecret, magIdentifier, idToken, idTokenType, null); + } + + private JsonObject refreshToken(String clientId, String clientSecret, String magIdentifier, String refreshToken) throws IOException { + return this.getToken(clientId, clientSecret, magIdentifier, null, null, refreshToken); + } + + private JsonObject getToken(String clientId, String clientSecret, String magIdentifier, String idToken, String idTokenType, String refreshToken) throws IOException { + + Request.Builder requestBuilder; + FormBody.Builder form; + + //Common token request params + form = new FormBody.Builder() + .add("client_id", clientId) + .add("client_secret", clientSecret); + //Authentication token request params + if (idToken != null) { + form.add("assertion", idToken) + .add("grant_type", idTokenType) + .add("scope", this.carepartnerAppConfig.getOAuthScope()); + //Refresh token request params + } else { + form.add("refresh_token", refreshToken) + .add("grant_type", "refresh_token"); + } + + requestBuilder = new Request.Builder() + .post(form.build()) + .addHeader("mag-identifier", magIdentifier) + .header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); + + return this.callSsoRestApi(requestBuilder, carepartnerAppConfig.getOAuthTokenEndpoint(), null); + + } + + private Response registerDevice(String deviceId, String androidModel, String clientId, String clientSecret, String authCode, String codeVerifier) throws IOException { + + String trimmedCsr = null; + + //Create RSA2048 keypair and CSR + try { + KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA"); + keygen.initialize(2048); + KeyPair keypair = keygen.genKeyPair(); + trimmedCsr = createTrimmedCsr(keypair, "SHA256withRSA", "socialLogin", deviceId, androidModel, "Medtronic"); + } catch (Exception e) { + UserError.Log.e(TAG, "Error creating CSR! Details: \r\n" + e.getMessage()); + } + + //Register device and get certificate for CSR + RequestBody body; + Request.Builder requestBuilder; + + body = RequestBody.create(null, trimmedCsr); + + requestBuilder = new Request.Builder() + .post(body) + .addHeader("device-id", Base64.encodeToString(deviceId.getBytes(StandardCharsets.UTF_8), Base64.NO_WRAP)) + .addHeader("device-name", Base64.encodeToString(androidModel.getBytes(StandardCharsets.UTF_8), Base64.NO_WRAP)) + .addHeader("authorization", "Bearer " + authCode) + .addHeader("client-authorization", "Basic " + Base64.encodeToString((clientId + ":" + clientSecret).getBytes(StandardCharsets.UTF_8), Base64.NO_WRAP)) + .addHeader("cert-format", "pem") + .addHeader("create-session", "true") + .addHeader("code-verifier", codeVerifier) + .addHeader("redirect-uri", carepartnerAppConfig.getOAuthRedirectUri()); + + return this.callSsoApi(requestBuilder, carepartnerAppConfig.getMagDeviceRegisterEndpoint(), null); + + } + + private String createTrimmedCsr(KeyPair keypair, String signAlgo, String cn, String ou, String dc, String o) throws IOException, OperatorCreationException { + + PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder( + new X500Principal( + "CN=" + cn + + ", OU=" + ou + + ", DC=" + dc + + ", O=" + o), keypair.getPublic()); + JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder(signAlgo); + ContentSigner signer = csBuilder.build(keypair.getPrivate()); + PKCS10CertificationRequest csr = p10Builder.build(signer); + StringWriter writer = new StringWriter(); + JcaPEMWriter jcaPEMWriter = new JcaPEMWriter(writer); + jcaPEMWriter.writeObject(csr); + jcaPEMWriter.close(); + + return writer.toString().replaceAll("-----.*-----", "").replaceAll("\\r", "").replaceAll("\\n", ""); + + } + + private String prepareAuth(String clientId, String codeVerifier) throws IOException { + + Request.Builder requestBuilder; + Map queryParams; + String codeChallenge = null; + JsonObject providers; + + //Generate SHA-256 code challenge + try { + codeChallenge = Base64.encodeToString( + MessageDigest.getInstance("SHA-256").digest(codeVerifier.getBytes("ISO_8859_1")), + PKCE_BASE64_ENCODE_SETTINGS); + } catch (Exception ex) { + } + + //Set params + queryParams = new HashMap(); + queryParams.put("client_id", clientId); + queryParams.put("response_type", "code"); + queryParams.put("display", "social_login"); + queryParams.put("scope", this.carepartnerAppConfig.getOAuthScope()); + queryParams.put("code_challenge", codeChallenge); + queryParams.put("code_challenge_method", "S256"); + queryParams.put("redirect_uri", this.carepartnerAppConfig.getOAuthRedirectUri()); + queryParams.put("state", generateRandomDataBase64url(32)); + + requestBuilder = new Request.Builder() + .get(); + + providers = this.callSsoRestApi(requestBuilder, carepartnerAppConfig.getOAuthAuthEndpoint(), queryParams); + + //Get auth url of enterprise login provider + for (JsonElement provider : providers.get("providers").getAsJsonArray()) { + if (provider.getAsJsonObject().get("provider").getAsJsonObject().get("id").getAsString().contentEquals("enterprise")) + return (provider.getAsJsonObject().get("provider").getAsJsonObject().get("auth_url").getAsString()); + } + + return null; + + } + + private JsonObject createClientCredential(String deviceId) throws IOException { + + RequestBody form; + Request.Builder requestBuilder; + + form = new FormBody.Builder() + .add("client_id", carepartnerAppConfig.getClientId()) + .add("nonce", UUID.randomUUID().toString()) + .build(); + + requestBuilder = new Request.Builder() + .post(form) + .addHeader("device-id", Base64.encodeToString(deviceId.getBytes(StandardCharsets.UTF_8), Base64.NO_WRAP | Base64.URL_SAFE)); + + return this.callSsoRestApi(requestBuilder, carepartnerAppConfig.getMagCredentialInitEndpoint(), null); + + } + + private String generateDeviceId() { + + try { + byte[] bytes = MessageDigest.getInstance("SHA-256").digest(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8)); + StringBuilder stringBuilder = new StringBuilder(bytes.length); + for (byte byteChar : bytes) + stringBuilder.append(String.format("%02x", byteChar)); + return stringBuilder.toString(); + } catch (NoSuchAlgorithmException e) { + UserError.Log.e(TAG, "Error generating deviceId! Details: \r\n" + e.getMessage()); + } + + return null; + + } + + private String generateAndroidModel() { + return ANDROID_MODELS[new Random().nextInt(ANDROID_MODELS.length)]; + } + + private String generateRandomDataBase64url(int length) { + SecureRandom secureRandom = new SecureRandom(); + byte[] codeVerifier = new byte[length]; + secureRandom.nextBytes(codeVerifier); + return Base64.encodeToString(codeVerifier, PKCE_BASE64_ENCODE_SETTINGS); + } + + private JsonObject callSsoRestApi(Request.Builder requestBuilder, String endpoint, Map queryParams) throws IOException { + + Response response = this.callSsoApi(requestBuilder, endpoint, queryParams); + if (response.isSuccessful()) { + return JsonParser.parseString(response.body().string()).getAsJsonObject(); + } else { + return null; + } + + } + + private Response callSsoApi(Request.Builder requestBuilder, String endpoint, Map queryParams) throws IOException { + + HttpUrl.Builder url = null; + + //Build URL + url = new HttpUrl.Builder() + .scheme("https") + .host(carepartnerAppConfig.getSSOServerHost()) + .addPathSegments(carepartnerAppConfig.getSSOServerPrefix()) + .addPathSegments(endpoint); + //Add query params + if (queryParams != null) { + for (Map.Entry param : queryParams.entrySet()) { + url.addQueryParameter(param.getKey(), param.getValue()); + } + } + requestBuilder.url(url.build()); + //Send request + return this.getHttpClient().newCall(requestBuilder.build()).execute(); + + } + + private boolean refreshCpAppToken() { + JsonObject tokenRefreshResult; + + try { + //Get config + this.loadAppConfig(); + //Refresh token + tokenRefreshResult = this.refreshToken( + credentialStore.getCredential().clientId, credentialStore.getCredential().clientSecret, + credentialStore.getCredential().magIdentifier, credentialStore.getCredential().refreshToken); + //Save token + credentialStore.updateMobileAppCredential( + tokenRefreshResult.get("access_token").getAsString(), + //new Date(Calendar.getInstance().getTime().getTime() + 15 * 60000), + //new Date(Calendar.getInstance().getTime().getTime() + 30 * 60000), + new Date(Calendar.getInstance().getTime().getTime() + (tokenRefreshResult.get("expires_in").getAsInt() * 1000)), + new Date(Calendar.getInstance().getTime().getTime() + (this.carepartnerAppConfig.getRefreshLifetimeSec() * 1000)), + tokenRefreshResult.get("refresh_token").getAsString()); + //Completed successfully + return true; + } catch (Exception ex) { + UserError.Log.e(TAG, "Error refreshing CpApp token! Details: \r\n" + ex.getMessage()); + return false; + } + } + + private boolean refreshBrowserToken() { + + //If not authenticated => unable to refresh + if (credentialStore.getAuthStatus() == CareLinkCredentialStore.NOT_AUTHENTICATED) + return false; + + HttpUrl url; + OkHttpClient httpClient; + Request.Builder requestBuilder; + Response response; + EditableCookieJar cookieJar; + + + //Build client with cookies from CredentialStore + cookieJar = new EditableCookieJar(); + httpClient = new OkHttpClient.Builder() + .cookieJar(cookieJar) + .build(); + cookieJar.AddCookies(credentialStore.getCredential().cookies); + + //Build request + url = new HttpUrl.Builder() + .scheme("https") + .host(this.careLinkServer()) + .addPathSegments("patient/sso/reauth") + .build(); + requestBuilder = new Request.Builder() + .url(url) + .post(RequestBody.create(null, new byte[0])) + .addHeader("Accept", "application/json, text/plain, */*") + .addHeader("Accept-Language", "en;q=0.9, *;q=0.8") + .addHeader("Connection", "keep-alive") + .addHeader("Authorization", credentialStore.getCredential().getAuthorizationFieldValue()) + .addHeader("User-Agent", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36") + .addHeader("Sec-Ch-Ua", "\"Google Chrome\";v=\"117\", \"Not;A=Brand\";v=\"8\", \"Chromium\";v=\"117\""); + + //Send request to refresh token + try { + response = httpClient.newCall(requestBuilder.build()).execute(); + //successful response + if (response.isSuccessful()) { + //New authentication cookies found + if (cookieJar.contains(CARELINK_AUTH_TOKEN_COOKIE_NAME) && cookieJar.contains(CARELINK_TOKEN_VALIDTO_COOKIE_NAME)) { + //Update credentials + this.credentialStore.updateBrowserCredential( + cookieJar.getCookies(CARELINK_AUTH_TOKEN_COOKIE_NAME).get(0).value(), + this.parseValidTo(cookieJar.getCookies(CARELINK_TOKEN_VALIDTO_COOKIE_NAME).get(0).value()), + this.parseValidTo(cookieJar.getCookies(CARELINK_TOKEN_VALIDTO_COOKIE_NAME).get(0).value()), + cookieJar.getAllCookies().toArray(new Cookie[0])); + } else { + return false; + } + } + //error in response + else { + return false; + } + response.close(); + } catch (IOException e) { + return false; + } finally { + + } + + return (credentialStore.getAuthStatus() == CareLinkCredentialStore.AUTHENTICATED); + } + + private void showProgressDialog(Activity context) { + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + CareLinkAuthenticator.this.getProgressDialog(context).show(); + } + }); + } + + private void hideProgressDialog() { + if (this.progressDialog != null && this.progressDialog.isShowing()) { + this.progressDialog.dismiss(); + } + } + + private AlertDialog getProgressDialog(Activity context) { + if (this.progressDialog == null) { + AlertDialog.Builder builder; + builder = new AlertDialog.Builder(context); + builder.setTitle(xdrip.gs(R.string.carelink_auth_login_in_progress)); + final ProgressBar progressBar = new ProgressBar(context); + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.WRAP_CONTENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + progressBar.setLayoutParams(lp); + builder.setView(progressBar); + this.progressDialog = builder.create(); + } + //return builder; + return this.progressDialog; + } + + private void showBrowserAuthPage(Activity context, String url) { + final Dialog authDialog = new Dialog(context); + this.showAuthWebView(authDialog, url, new WebViewClient() { + @Override + public void onPageStarted(WebView view, String url, Bitmap favicon) { + if (CareLinkAuthenticator.this.extractBrowserLoginCookies(url)) + authDialog.dismiss(); + } + }); + } + + private void showCpAppAuthPage(Activity context, String url) { + + //CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build(); + //customTabsIntent.launchUrl( + // context, Uri.parse(url)); + + final Dialog authDialog = new Dialog(context); + this.showAuthWebView(authDialog, url, new WebViewClient() { + @Override + public void onPageStarted(WebView view, String url, Bitmap favicon) { + if (CareLinkAuthenticator.this.extractCpAppAuthCode(url)) + //close browser dialog + authDialog.dismiss(); + } + + @Override + public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { + //Connection error + if (error.getErrorCode() == WebViewClient.ERROR_CONNECT) { + carelinkCommunicationError = true; + authDialog.dismiss(); + } + } + }); + } + + private void showAuthWebView(Dialog authDialog, String url, WebViewClient webViewClient) { + + this.authWebViewCancelled = false; + + LinearLayoutCompat layout = new LinearLayoutCompat(authDialog.getContext()); + WebView webView = new WebView(authDialog.getContext()); + webView.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + layout.addView(webView); + authDialog.setContentView(layout); + + authDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + unlock(); + } + }); + authDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { + @Override + public void onCancel(DialogInterface dialogInterface) { + authWebViewCancelled = true; + } + }); + + //Configure Webview + webView.getSettings().setJavaScriptEnabled(true); + webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36"); + webView.loadUrl(url); + webView.setWebViewClient(webViewClient); + + //Set dialog display params and show it + authDialog.setCancelable(true); + authDialog.getWindow().setLayout(LinearLayoutCompat.LayoutParams.MATCH_PARENT, LinearLayoutCompat.LayoutParams.MATCH_PARENT); + authDialog.show(); + + } + + private boolean extractCpAppAuthCode(String url) { + + //Redirect url => extract code, completed + if (url.contains(this.carepartnerAppConfig.getOAuthRedirectUri())) { + try { + UrlQuerySanitizer sanitizer = new UrlQuerySanitizer(); + sanitizer.setAllowUnregisteredParamaters(true); + sanitizer.parseUrl(url); + authCode = sanitizer.getValue("code"); + } catch (Exception ex) { + UserError.Log.e(TAG, "Error extracting authCode! Details: \r\n" + ex.getMessage()); + } + return true; + //Other url => authentication not completed yet + } else + return false; + + } + + private JsonObject getCpAppRegionConfig() throws IOException { + + + //Get CarePartner app discover + JsonObject endpointConfig = this.getConfigJson(CAREPARTNER_APP_DISCO_URL); + //Extract region config of selected country + JsonArray countries = endpointConfig.getAsJsonArray("supportedCountries"); + JsonArray regions = endpointConfig.getAsJsonArray("CP"); + for (JsonElement country : countries) { + if (country.getAsJsonObject().has(this.carelinkCountry.toUpperCase(Locale.ROOT))) { + String regionCode = country.getAsJsonObject().get(this.carelinkCountry.toUpperCase(Locale.ROOT)).getAsJsonObject().get("region").getAsString(); + for (JsonElement region : regions) { + if (region.getAsJsonObject().get("region").getAsString().contentEquals(regionCode)) { + return region.getAsJsonObject(); + } + } + } + } + + return null; + + } + + private JsonObject getCpAppSSOConfig(String url) throws IOException { + return this.getConfigJson(url); + } + + private JsonObject getConfigJson(String url) throws IOException { + + Request request; + + request = new Request.Builder() + .url(url) + .get() + .build(); + Response response = this.getHttpClient().newCall(request).execute(); + return JsonParser.parseString(response.body().string()).getAsJsonObject(); + + } + + private String getWebAppLoginUrl() { + + HttpUrl url = null; + + url = new HttpUrl.Builder() + .scheme("https") + .host(this.careLinkServer()) + .addPathSegments("patient/sso/login") + .addQueryParameter("country", this.carelinkCountry) + .addQueryParameter("lang", CARELINK_LANGUAGE_EN) + .build(); + + return url.toString(); + + } + + private String careLinkServer() { + if (this.carelinkCountry.equals("us")) + return CARELINK_CONNECT_SERVER_US; + else + return CARELINK_CONNECT_SERVER_EU; + } + + private Boolean extractBrowserLoginCookies(String url) { + + String cookies = null; + String authToken = null; + String host = null; + Date validToDate = null; + ArrayList cookieList; + + + cookies = CookieManager.getInstance().getCookie(url); + + //Authentication cookies are present + if (cookies != null && cookies.contains(CARELINK_AUTH_TOKEN_COOKIE_NAME) && cookies.contains(CARELINK_TOKEN_VALIDTO_COOKIE_NAME)) { + + //Build cookies + host = HttpUrl.parse(url).host(); + cookieList = new ArrayList(); + + for (String cookie : cookies.split("; ")) { + + String[] cookieParts = cookie.split("="); + + Cookie.Builder cookieBuilder = new Cookie.Builder() + .name(cookieParts[0]) + .value(cookieParts[1]) + .path("/") + .domain(host); + + if (cookieParts[0].contains(CARELINK_AUTH_TOKEN_COOKIE_NAME)) { + cookieBuilder.secure(); + authToken = cookieParts[1]; + } + + if (cookieParts[0].contains(CARELINK_TOKEN_VALIDTO_COOKIE_NAME)) { + validToDate = this.parseValidTo(cookieParts[1]); + cookieBuilder.secure(); + } + + cookieList.add(cookieBuilder.build()); + + } + + //Skip cookies if authentication already expired (existing old cookies found) + if (validToDate.getTime() < System.currentTimeMillis()) + return false; + + //Update credentials + this.credentialStore.setBrowserCredential(this.carelinkCountry, authToken, validToDate, validToDate, cookieList.toArray(new Cookie[0])); + //success + return true; + } else + //error + return false; + } + + private void unlock() { + if (available.availablePermits() <= 0) + available.release(); + } + + private Date parseValidTo(String validToDateString) { + for (SimpleDateFormat zonedFormat : VALIDTO_DATE_FORMATS) { + //try until translate is successful + try { + return zonedFormat.parse(validToDateString); + } catch (Exception ex) { + } + } + return null; + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CareLinkCredential.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CareLinkCredential.java new file mode 100644 index 0000000000..89705d1bcb --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CareLinkCredential.java @@ -0,0 +1,59 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth; + +import java.util.Calendar; +import java.util.Date; + +import okhttp3.Cookie; +import okhttp3.Headers; + +public class CareLinkCredential { + + + public String country = null; + public String accessToken = null; + public Cookie[] cookies = null; + public Date accessValidTo = null; + public Date refreshValidTo = null; + public CareLinkAuthType authType = null; + public String androidModel = null; + public String deviceId = null; + public String clientId = null; + public String clientSecret = null; + public String magIdentifier = null; + public String refreshToken = null; + + + public CareLinkAuthentication getAuthentication() { + + //Not authenticated + if (this.authType == null || this.getAuthorizationFieldValue() == null) + return null; + + //Build authentication + Headers.Builder headers = new Headers.Builder(); + headers.add("Authorization", this.getAuthorizationFieldValue()); + if (this.authType == CareLinkAuthType.MobileApp) + headers.add("mag-identifier", this.magIdentifier); + return new CareLinkAuthentication(headers.build(), this.authType); + + } + + public String getToken() { + return accessToken; + } + + public String getAuthorizationFieldValue() { + if (this.getToken() == null) + return null; + else + return "Bearer " + this.getToken(); + } + + public long getAccessExpiresIn() { + if (this.accessValidTo == null) + return -1; + else + return this.accessValidTo.getTime() - Calendar.getInstance().getTime().getTime(); + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CareLinkCredentialStore.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CareLinkCredentialStore.java new file mode 100644 index 0000000000..62cf74b7d5 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CareLinkCredentialStore.java @@ -0,0 +1,152 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth; + + +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.google.gson.GsonBuilder; + +import java.util.Calendar; +import java.util.Date; + +import okhttp3.Cookie; + +public class CareLinkCredentialStore { + + private static final String TAG = "CareLinkCredentialStore"; + + public final static int NOT_AUTHENTICATED = 0; + public final static int ACCESS_EXPIRED = 1; + public final static int AUTHENTICATED = 2; + public final static int REFRESH_EXPIRED = 3; + + private CareLinkCredential credential = null; + private static CareLinkCredentialStore instance = null; + private final static String PREF_CARELINK_CREDENTIAL = "carelink_credential"; + + private int authStatus = NOT_AUTHENTICATED; + + + private CareLinkCredentialStore() { + + } + + public static CareLinkCredentialStore getInstance() { + if (instance == null) { + instance = new CareLinkCredentialStore(); + UserError.Log.d(TAG, "Trying to restore saved Credential"); + String credJson = PersistentStore.getString(PREF_CARELINK_CREDENTIAL, ""); + if (!credJson.equals("")) { + try { + CareLinkCredential savedCred = new GsonBuilder().create().fromJson(credJson, CareLinkCredential.class); + instance.setCredential(savedCred.country, savedCred.authType, savedCred.accessToken, savedCred.accessValidTo, savedCred.refreshValidTo, savedCred.cookies, + savedCred.androidModel, savedCred.deviceId, savedCred.clientId, savedCred.clientSecret, savedCred.magIdentifier, savedCred.refreshToken, false); + } catch (Exception e) { + UserError.Log.d(TAG, "Error when restoring saved Credential: " + e.getMessage()); + } + } else { + UserError.Log.d(TAG, "No saved Credential found!"); + } + + } + return instance; + } + + synchronized void setMobileAppCredential(String country, String deviceId, String androidModel, String clientId, String clientSecret, String magIdentifier, String accessToken, String refreshToken, Date accessValidTo, Date refreshValidTo) { + this.setCredential(country, CareLinkAuthType.MobileApp, accessToken, accessValidTo, refreshValidTo, null, androidModel, deviceId, clientId, clientSecret, magIdentifier, refreshToken, true); + } + + synchronized void updateMobileAppCredential(String accessToken, Date accessValidTo, Date refreshValidTo, String refreshToken) { + this.setCredential(credential.country, CareLinkAuthType.MobileApp, accessToken, accessValidTo, refreshValidTo, null, credential.androidModel, credential.deviceId, credential.clientId, credential.clientSecret, credential.magIdentifier, refreshToken, true); + } + + synchronized void updateBrowserCredential(String accessToken, Date accessValidTo, Date refreshValidTo, Cookie[] cookies) { + this.setCredential(credential.country, CareLinkAuthType.Browser, accessToken, accessValidTo, refreshValidTo, cookies, null, null, null, null, null, null, true); + } + + synchronized void setBrowserCredential(String country, String accessToken, Date accessValidTo, Date refreshValidTo, Cookie[] cookies) { + this.setCredential(country, CareLinkAuthType.Browser, accessToken, accessValidTo, refreshValidTo, cookies, null, null, null, null, null, null, true); + } + + protected synchronized void setCredential(String country, CareLinkAuthType authType, String accessToken, Date accessValidTo, Date refreshValidTo, Cookie[] cookies, String androidModel, String deviceId, String clientId, String clientSecret, String magIdentifier, String refreshToken, boolean save) { + + credential = new CareLinkCredential(); + credential.authType = authType; + credential.country = country; + credential.accessToken = accessToken; + credential.accessValidTo = accessValidTo; + credential.cookies = cookies; + credential.androidModel = androidModel; + credential.deviceId = deviceId; + credential.clientId = clientId; + credential.clientSecret = clientSecret; + credential.magIdentifier = magIdentifier; + credential.refreshToken = refreshToken; + credential.refreshValidTo = refreshValidTo; + if (credential.accessToken == null || credential.accessValidTo == null) + authStatus = NOT_AUTHENTICATED; + else + evaluateExpiration(); + UserError.Log.d(TAG, "Credential updated!"); + if (save) { + try { + PersistentStore.setString(PREF_CARELINK_CREDENTIAL, new GsonBuilder().create().toJson(credential)); + UserError.Log.d(TAG, "Credential saved!"); + } catch (Exception e) { + UserError.Log.d(TAG, "Error saving Credential: " + e.getMessage()); + } + } + } + + public CareLinkCredential getCredential() { + return credential; + } + + public int getAuthStatus() { + return authStatus; + } + + public long getAccessExpiresIn() { + if (credential == null || credential.accessValidTo == null) + return -1; + else + return credential.accessValidTo.getTime() - Calendar.getInstance().getTime().getTime(); + } + + public long getAccessExpiresOn() { + if (credential == null || credential.accessValidTo == null) + return -1; + else + return credential.accessValidTo.getTime(); + } + + public long getRefreshExpiresIn() { + if (credential == null || credential.refreshValidTo == null) + return -1; + else + return credential.refreshValidTo.getTime() - Calendar.getInstance().getTime().getTime(); + } + + public long getRefreshExpiresOn() { + if (credential == null || credential.refreshValidTo == null) + return -1; + else + return credential.refreshValidTo.getTime(); + } + + synchronized void clear() { + this.credential = null; + PersistentStore.setString(PREF_CARELINK_CREDENTIAL, ""); + UserError.Log.d(TAG, "Credential cleared"); + authStatus = NOT_AUTHENTICATED; + } + + protected void evaluateExpiration() { + if (this.getRefreshExpiresIn() < 0) + authStatus = REFRESH_EXPIRED; + else if (this.getAccessExpiresIn() < 0) + authStatus = ACCESS_EXPIRED; + else + authStatus = AUTHENTICATED; + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CarePartnerAppConfig.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CarePartnerAppConfig.java new file mode 100644 index 0000000000..939594da5b --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/CarePartnerAppConfig.java @@ -0,0 +1,92 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +public class CarePartnerAppConfig { + + public JsonObject regionConfig = null; + public JsonObject ssoConfig = null; + + public String getRegion() { + return regionConfig.get("region").getAsString(); + } + + public String getSSOConfigUrl() { + return regionConfig.get("SSOConfiguration").getAsString(); + } + + public String getCloudBaseUrl() { + return regionConfig.get("baseUrlCumulus").getAsString(); + } + + public String getCareLinkBaseUrl() { + return regionConfig.get("baseUrlCareLink").getAsString(); + } + + public String getSSOServerHost() { + return this.getChildJsonString(ssoConfig, "server.hostname"); + } + + public String getSSOServerPrefix() { + return this.getChildJsonString(ssoConfig, "server.prefix"); + } + + public int getSSOServerPort() { + return this.getChildJsonElement(ssoConfig, "server.port").getAsInt(); + } + + public String getOAuthAuthEndpoint() { + return this.getChildJsonString(ssoConfig, "oauth.system_endpoints.authorization_endpoint_path").substring(1); + } + + public String getOAuthTokenEndpoint() { + return this.getChildJsonString(ssoConfig, "oauth.system_endpoints.token_endpoint_path").substring(1); + } + + public String getMagCredentialInitEndpoint() { + return this.getChildJsonString(ssoConfig, "mag.system_endpoints.client_credential_init_endpoint_path").substring(1); + } + + public String getMagDeviceRegisterEndpoint() { + return this.getChildJsonString(ssoConfig, "mag.system_endpoints.device_register_endpoint_path").substring(1); + } + + public String getClientId() { + return getClientMemberString("client_id"); + } + + public String getOAuthScope() { + return getClientMemberString("scope"); + } + + public String getOAuthRedirectUri() { + return getClientMemberString("redirect_uri"); + } + + public int getRefreshLifetimeSec() { + return Integer.parseInt(getClientMemberString("client_key_custom.lifetimes.oauth2_refresh_token_lifetime_sec")); + } + + private String getClientMemberString(String clientMember) { + return this.getChildJsonString(this.getChildJsonElement(ssoConfig, "oauth.client.client_ids").getAsJsonArray().get(0) + .getAsJsonObject(), clientMember); + } + + private String getChildJsonString(JsonObject parent, String path) { + return getChildJsonElement(parent, path).getAsString(); + } + + private JsonElement getChildJsonElement(JsonObject parent, String path) { + + JsonElement obj = parent; + + for (String member : path.split("\\.")) { + obj = obj.getAsJsonObject().get(member); + } + + return obj; + + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/EditableCookieJar.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/EditableCookieJar.java new file mode 100644 index 0000000000..5f06c6548b --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/auth/EditableCookieJar.java @@ -0,0 +1,100 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import okhttp3.Cookie; +import okhttp3.CookieJar; +import okhttp3.HttpUrl; + +public class EditableCookieJar implements CookieJar { + + private List storage = new ArrayList<>(); + + @Override + public void saveFromResponse(HttpUrl url, List cookies) { + //add cookies, delete cookie with same name before add + for (Cookie cookie : cookies) { + if (this.contains(cookie.name())) + this.deleteCookie(cookie.name()); + this.storage.add(cookie); + } + } + + @Override + public List loadForRequest(HttpUrl url) { + + List cookies = new ArrayList<>(); + + // Remove expired Cookies + //removeExpiredCookies(); + + // Only return matching Cookies + for (Cookie cookie : storage) { + if (cookie.matches(url)) { + cookies.add(cookie); + } + } + + return cookies; + } + + public List getCookies(String name) { + + List cookies = new ArrayList<>(); + + // Remove expired Cookies + //removeExpiredCookies(); + + // Only return matching Cookies + for (Cookie cookie : storage) { + if (cookie.name().equals(name)) { + cookies.add(cookie); + } + } + + return cookies; + + } + + public List getAllCookies() { + return storage; + } + + public void AddCookie(Cookie cookie) { + storage.add(cookie); + } + + public void AddCookies(Cookie[] cookies) { + storage.addAll(Arrays.asList(cookies)); + } + + public boolean contains(String name) { + return (getCookies(name).size() > 0); + } + + public void deleteCookie(String name) { + for (int i = 0; i < storage.size(); i++) { + if (storage.get(i).name().contains(name)) { + storage.remove(i); + } + } + } + + public void deleteAllCookies() { + storage.clear(); + } + + /* + private void removeExpiredCookies() { + for (int i = 0; i < storage.size(); i++) { + if (storage.get(i).expiresAt() < System.currentTimeMillis()) { + storage.remove(i); + } + } + } + + */ + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CareLinkClient.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CareLinkClient.java new file mode 100644 index 0000000000..8703b07c90 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CareLinkClient.java @@ -0,0 +1,922 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.client; + +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth.CareLinkAuthType; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth.CareLinkAuthentication; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth.CareLinkCredentialStore; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth.EditableCookieJar; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.ActiveNotification; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.ClearedNotification; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.CountrySettings; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.DataUpload; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.Marker; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.MonitorData; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.Profile; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.Patient; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.M2MEnabled; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.RecentData; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.RecentUploads; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.SensorGlucose; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.User; +import com.eveningoutpost.dexdrip.models.JoH; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; + +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import okhttp3.ConnectionPool; +import okhttp3.FormBody; +import okhttp3.Headers; +import okhttp3.HttpUrl; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + + +/** + * CareLink Follower Client + * - API client for communication with CareLink + */ +public class CareLinkClient { + protected String carelinkUsername; + protected String carelinkPassword; + protected String carelinkCountry; + protected static final String CARELINK_CONNECT_SERVER_EU = "carelink.minimed.eu"; + protected static final String CARELINK_CONNECT_SERVER_US = "carelink.minimed.com"; + protected static final String CARELINK_LANGUAGE_EN = "en"; + protected static final String CARELINK_AUTH_TOKEN_COOKIE_NAME = "auth_tmp_token"; + protected static final String CARELINK_TOKEN_VALIDTO_COOKIE_NAME = "c_token_valid_to"; + protected static final int AUTH_EXPIRE_DEADLINE_MINUTES = 1; + + protected static final SimpleDateFormat[] ZONED_DATE_FORMATS = { + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"), + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz"), + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"), + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"), + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX"), + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX") + }; + + //Communication info + protected OkHttpClient httpClient = null; + protected boolean loginInProcess = false; + protected boolean collectingSessionInfos = false; + protected int lastResponseCode; + + public int getLastResponseCode() { + return lastResponseCode; + } + + private boolean lastLoginSuccess; + + public boolean getLastLoginSuccess() { + return lastLoginSuccess; + } + + private boolean lastDataSuccess; + + public boolean getLastDataSuccess() { + return lastDataSuccess; + } + + private String lastErrorMessage; + + public String getLastErrorMessage() { + return lastErrorMessage; + } + + private String lastStackTraceString; + + public String getLastStackTraceString() { + return lastStackTraceString; + } + + //Credentials + protected CareLinkCredentialStore credentialStore; + + //Session info + protected boolean sessionInfosLoaded = false; + protected User sessionUser; + + public User getSessionUser() { + return sessionUser; + } + + protected Profile sessionProfile; + + public Profile getSessionProfile() { + return sessionProfile; + } + + protected CountrySettings sessionCountrySettings; + + public CountrySettings getSessionCountrySettings() { + return sessionCountrySettings; + } + protected RecentUploads sessionRecentUploads; + public RecentUploads getSessionRecentUploads() { + return sessionRecentUploads; + } + protected Boolean sessionDeviceIsBle; + public Boolean getSessionDeviceIsBle() { + return sessionDeviceIsBle; + } + protected Boolean sessionM2MEnabled; + public boolean getSessionM2MEnabled(){ + return sessionM2MEnabled; + } + protected Patient[] sessionPatients; + public Patient[] getSessionPatients(){ + return sessionPatients; + } + + protected MonitorData sessionMonitorData; + + public MonitorData getSessionMonitorData() { + return sessionMonitorData; + } + + protected enum RequestType { + HtmlGet(), + HtmlPost(), + Json() + } + + public CareLinkClient(String carelinkUsername, String carelinkPassword, String carelinkCountry) { + + this.carelinkUsername = carelinkUsername; + this.carelinkPassword = carelinkPassword; + this.carelinkCountry = carelinkCountry; + + lastLoginSuccess = false; + lastDataSuccess = false; + + //Create main http client with CookieJar + this.httpClient = new OkHttpClient.Builder() + .cookieJar(new SimpleOkHttpCookieJar()) + .build(); + + } + + public CareLinkClient(CareLinkCredentialStore credentialStore) { + this.carelinkCountry = credentialStore.getCredential().country; + this.credentialStore = credentialStore; + this.createHttpClient(); + } + + private void createHttpClient(){ + + EditableCookieJar cookieJar = null; + + cookieJar = new EditableCookieJar(); + //Add cookies if there are any + if(this.credentialStore.getCredential().cookies != null && this.credentialStore.getCredential().cookies.length > 0) { + cookieJar.AddCookies(this.credentialStore.getCredential().cookies); + } + + this.httpClient = new OkHttpClient.Builder() + .cookieJar(cookieJar) + .connectionPool(new ConnectionPool(5, 10, TimeUnit.MINUTES)) + .build(); + } + + protected String careLinkServer() { + if (this.carelinkCountry.equals("us")) + return CARELINK_CONNECT_SERVER_US; + else + return CARELINK_CONNECT_SERVER_EU; + } + + + //Wrapper for common request of recent data (last 24 hours) + public RecentData getRecentData() { + + //Use default patient username if not provided + return this.getRecentData(this.getDefaultPatientUsername()); + + } + + //Get recent data of patient + public RecentData getRecentData(String patientUsername) { + + // Force login to get basic info + if (getAuthentication() == null) + return null; + + // 7xxG + if (this.isBleDevice(patientUsername)) + return this.getConnectDisplayMessage(this.sessionProfile.username, this.sessionUser.getUserRole(), patientUsername, + sessionCountrySettings.blePereodicDataEndpoint); + // Guardian + multi + else if (this.sessionM2MEnabled) + return this.getM2MPatientData(patientUsername); + // Guardian + single + else + return this.getLast24Hours(); + + } + + //Determine default patient + public String getDefaultPatientUsername() { + + // Force login to get basic info + if (getAuthentication() == null) + return null; + + // Care Partner + multi follow => first patient + if (this.sessionUser.isCarePartner() && this.sessionM2MEnabled) + if (this.sessionPatients != null && this.sessionPatients.length > 0) + return this.sessionPatients[0].username; + else + return null; + // Not care partner or no multi follow => username from session profile + else if (this.sessionProfile.username != null) + return this.sessionProfile.username; + else + return null; + } + + public boolean isBleDevice(String patientUsername){ + + Boolean recentUploadBle; + + // Session device already determined + if(sessionDeviceIsBle != null) + return sessionDeviceIsBle; + + // Force login to get basic info + if(getAuthentication() == null) + return false; + + // Patient: device from recent uploads if possible + if(!this.sessionUser.isCarePartner()){ + recentUploadBle = this.isRecentUploadBle(); + if(recentUploadBle != null){ + this.sessionDeviceIsBle = recentUploadBle; + return sessionDeviceIsBle; + } + } + + // Care partner (+M2M): device from patient list + if(this.sessionM2MEnabled && this.sessionUser.isCarePartner()) + if(patientUsername == null || this.sessionPatients == null) + return false; + else { + for (int i = 0; i < this.sessionPatients.length; i++) { + if (sessionPatients[i].username.equals(patientUsername)) + return sessionPatients[i].isBle(); + } + return false; + } + // Other: classic method (session monitor data) + else + return this.sessionMonitorData.isBle(); + + } + + public Boolean isRecentUploadBle(){ + + if(this.sessionRecentUploads == null) + return null; + + for(DataUpload upload : this.sessionRecentUploads.recentUploads){ + if(upload.device.toUpperCase().contains("MINIMED")) + return true; + else if(upload.device.toUpperCase().contains("GUARDIAN")) + return false; + } + return null; + } + + //Authentication methods + protected boolean executeLoginProcedure() { + + Response loginSessionResponse = null; + Response doLoginResponse = null; + Response consentResponse = null; + + + lastLoginSuccess = false; + loginInProcess = true; + lastErrorMessage = ""; + + try { + //Clear session + this.clearSessionInfos(); + + //Open login (get SessionId and SessionData) + loginSessionResponse = this.getLoginSession(); + this.lastResponseCode = loginSessionResponse.code(); + + //Login + doLoginResponse = this.doLogin(loginSessionResponse); + this.lastResponseCode = doLoginResponse.code(); + loginSessionResponse.close(); + + //Consent + consentResponse = this.doConsent(doLoginResponse); + doLoginResponse.close(); + this.lastResponseCode = consentResponse.code(); + consentResponse.close(); + + // Get required sessions infos + if(this.getSessionInfos()) + lastLoginSuccess = true; + + } catch (Exception e) { + lastErrorMessage = e.getClass().getSimpleName() + ":" + e.getMessage(); + // lastStackTraceString = Log.getStackTraceString(e); + } finally { + loginInProcess = false; + } + + return lastLoginSuccess; + + } + + protected boolean getSessionInfos(){ + + collectingSessionInfos = true; + + try { + this.clearSessionInfos(); + // User + this.sessionUser = this.getMyUser(); + // Profile + this.sessionProfile = this.getMyProfile(); + // Country settings + this.sessionCountrySettings = this.getMyCountrySettings(); + // Recent uploads (only for patients) + if (!this.sessionUser.isCarePartner()) + this.sessionRecentUploads = this.getRecentUploads(30); + this.sessionM2MEnabled = this.getM2MEnabled().value; + // Multi follow + Care Partner => patients + if (this.sessionM2MEnabled && this.sessionUser.isCarePartner()) + this.sessionPatients = this.getM2MPatients(); + // Single follow and/or Patient => monitor data + else + this.sessionMonitorData = this.getMonitorData(); + + if (this.sessionUser != null && this.sessionProfile != null && this.sessionCountrySettings != null && this.sessionM2MEnabled != null && + (((!this.sessionM2MEnabled || !this.sessionUser.isCarePartner()) && this.sessionMonitorData != null) || + (this.sessionM2MEnabled && this.sessionUser.isCarePartner() && this.sessionPatients != null))) + this.sessionInfosLoaded = true; + else { + this.clearSessionInfos(); + } + } catch (Exception ex) { + + } finally { + collectingSessionInfos = false; + } + + + return this.sessionInfosLoaded; + + } + + protected void clearSessionInfos() + { + //((SimpleOkHttpCookieJar) this.httpClient.cookieJar()).deleteAllCookies(); + this.sessionUser = null; + this.sessionProfile = null; + this.sessionCountrySettings = null; + this.sessionMonitorData = null; + this.sessionPatients = null; + this.sessionInfosLoaded = false; + } + + protected Response getLoginSession() throws IOException { + + HttpUrl url = null; + Request.Builder requestBuilder = null; + + + url = new HttpUrl.Builder() + .scheme("https") + .host(this.careLinkServer()) + .addPathSegments("patient/sso/login") + .addQueryParameter("country", this.carelinkCountry) + .addQueryParameter("lang", CARELINK_LANGUAGE_EN) + .build(); + + requestBuilder = new Request.Builder() + .url(url); + + this.addHttpHeaders(requestBuilder, RequestType.HtmlGet, true); + + return this.httpClient.newCall(requestBuilder.build()).execute(); + + } + + protected Response doLogin(Response loginSessionResponse) throws IOException { + + HttpUrl url = null; + Request.Builder requestBuilder = null; + RequestBody form = null; + + form = new FormBody.Builder() + .add("sessionID", loginSessionResponse.request().url().queryParameter("sessionID")) + .add("sessionData", loginSessionResponse.request().url().queryParameter("sessionData")) + .add("locale", loginSessionResponse.request().url().queryParameter("locale")) + .add("action", "login") + .add("username", this.carelinkUsername) + .add("password", this.carelinkPassword) + .add("actionButton", "Log in") + .build(); + + url = new HttpUrl.Builder() + .scheme(loginSessionResponse.request().url().scheme()) + .host(loginSessionResponse.request().url().host()) + .addPathSegments(loginSessionResponse.request().url().encodedPath().substring(1)) + .addQueryParameter("locale", loginSessionResponse.request().url().queryParameter("locale")) + .addQueryParameter("country", loginSessionResponse.request().url().queryParameter("countrycode")) + .build(); + + requestBuilder = new Request.Builder() + .url(url) + .post(form); + + this.addHttpHeaders(requestBuilder, RequestType.HtmlGet, true); + + return this.httpClient.newCall(requestBuilder.build()).execute(); + + } + + protected Response doConsent(Response doLoginResponse) throws IOException { + + Request.Builder requestBuilder = null; + RequestBody form = null; + String doLoginRespBody = null; + + doLoginRespBody = doLoginResponse.body().string(); + + //Extract data for consent + String consentUrl = this.extractResponseData(doLoginRespBody, "(form action=\")(.*)(\" method=\"POST\")", 2); + String consentSessionData = this.extractResponseData(doLoginRespBody, "()", 2); + String consentSessionId = this.extractResponseData(doLoginRespBody, "()", 2); + + //Send consent + form = new FormBody.Builder() + .add("action", "consent") + .add("sessionID", consentSessionId) + .add("sessionData", consentSessionData) + .add("response_type", "code") + .add("response_mode", "query") + .build(); + + requestBuilder = new Request.Builder() + .url(consentUrl) + .post(form); + + this.addHttpHeaders(requestBuilder, RequestType.HtmlPost, true); + + return this.httpClient.newCall(requestBuilder.build()).execute(); + + } + + // Response parsing + protected String extractResponseData(String respBody, String groupRegex, int groupIndex) { + + String responseData = null; + Matcher responseDataMatcher = null; + + responseDataMatcher = Pattern.compile(groupRegex).matcher(respBody); + if (responseDataMatcher.find()) { + responseData = responseDataMatcher.group(groupIndex); + } + + return responseData; + + } + + protected CareLinkAuthentication getAuthentication() { + + // CredentialStore is used + if(this.credentialStore != null){ + if(!this.sessionInfosLoaded && this.credentialStore.getAuthStatus() == CareLinkCredentialStore.AUTHENTICATED && !this.collectingSessionInfos) + { + this.getSessionInfos(); + } + if(!this.collectingSessionInfos && !this.sessionInfosLoaded) + return null; + else + return this.credentialStore.getCredential().getAuthentication(); + // New token is needed: + // a) no token or about to expire => execute authentication + // b) last response 401 + } else { + if (!((SimpleOkHttpCookieJar) httpClient.cookieJar()).contains(CARELINK_AUTH_TOKEN_COOKIE_NAME) + || !((SimpleOkHttpCookieJar) httpClient.cookieJar()).contains(CARELINK_TOKEN_VALIDTO_COOKIE_NAME) + || !((new Date(Date.parse(((SimpleOkHttpCookieJar) httpClient.cookieJar()) + .getCookies(CARELINK_TOKEN_VALIDTO_COOKIE_NAME).get(0).value()))) + .after(new Date(new Date(System.currentTimeMillis()).getTime() + + AUTH_EXPIRE_DEADLINE_MINUTES * 60000))) + || this.lastResponseCode == 401 + || (!loginInProcess && !this.lastLoginSuccess) + ) { + //execute new login process + if (this.loginInProcess || !this.executeLoginProcedure()) + return null; + } + + //there can be only one auth cookie + return new CareLinkAuthentication( + new Headers.Builder().add("Authorization", "Bearer" + " " + ((SimpleOkHttpCookieJar) httpClient.cookieJar()).getCookies(CARELINK_AUTH_TOKEN_COOKIE_NAME).get(0).value()).build(), + CareLinkAuthType.Browser); + //return "Bearer" + " " + ((SimpleOkHttpCookieJar) httpClient.cookieJar()).getCookies(CARELINK_AUTH_TOKEN_COOKIE_NAME).get(0).value(); + } + + + } + + + //CareLink data APIs + + // My user + public User getMyUser() { + return this.getData(this.careLinkServer(), "patient/users/me", null, null, User.class); + } + + // My profile + public Profile getMyProfile() { + return this.getData(this.careLinkServer(), "patient/users/me/profile", null, null, Profile.class); + } + + // Recent uploads + public RecentUploads getRecentUploads(int numOfUploads) { + + Map queryParams = null; + + queryParams = new HashMap(); + queryParams.put("numUploads", String.valueOf(numOfUploads)); + + return this.getData(this.careLinkServer(), "patient/dataUpload/recentUploads", queryParams, null, RecentUploads.class); + } + + // Monitoring data + public MonitorData getMonitorData() { + return this.getData(this.careLinkServer(), "patient/monitor/data", null, null, MonitorData.class); + } + + // Country settings + public CountrySettings getMyCountrySettings() { + + Map queryParams = null; + + queryParams = new HashMap(); + queryParams.put("countryCode", this.carelinkCountry); + queryParams.put("language", CARELINK_LANGUAGE_EN); + + return this.getData(this.careLinkServer(), "patient/countries/settings", queryParams, null, + CountrySettings.class); + + } + + // M2M Enabled + public M2MEnabled getM2MEnabled() { + return this.getData(this.careLinkServer(), "patient/configuration/system/personal.cp.m2m.enabled", null, null, M2MEnabled.class); + } + + // M2M Patients + public Patient[] getM2MPatients() { + return this.getData(this.careLinkServer(), "patient/m2m/links/patients", null, null, Patient[].class); + } + + // Classic last24hours webapp data + public RecentData getLast24Hours() { + + Map queryParams = null; + RecentData recentData = null; + + queryParams = new HashMap(); + queryParams.put("cpSerialNumber", "NONE"); + queryParams.put("msgType", "last24hours"); + queryParams.put("requestTime", String.valueOf(System.currentTimeMillis())); + + try { + recentData = this.getData(this.careLinkServer(), "patient/connect/data", queryParams, null, RecentData.class); + if (recentData != null) + correctTimeInRecentData(recentData); + } catch (Exception e) { + lastErrorMessage = e.getClass().getSimpleName() + ":" + e.getMessage(); + } + + return recentData; + + } + + // Periodic data from CareLink Cloud + public RecentData getConnectDisplayMessage(String username, String role, String patientUsername, String endpointUrl) { + + RequestBody requestBody = null; + Gson gson = null; + JsonObject userJson = null; + RecentData recentData = null; + + // Build user json for request + userJson = new JsonObject(); + userJson.addProperty("username", username); + userJson.addProperty("role", role); + if(!JoH.emptyString(patientUsername)) + userJson.addProperty("patientId", patientUsername); + + gson = new GsonBuilder().create(); + + requestBody = RequestBody.create(MediaType.get("application/json; charset=utf-8"), gson.toJson(userJson)); + + try { + recentData = this.getData(HttpUrl.parse(endpointUrl), requestBody, RecentData.class); + if (recentData != null) + correctTimeInRecentData(recentData); + } catch (Exception e) { + lastErrorMessage = e.getClass().getSimpleName() + ":" + e.getMessage(); + } + return recentData; + + } + + // New M2M last24hours webapp data + public RecentData getM2MPatientData(String patientUsername) { + + Map queryParams = null; + + //Patient username is mandantory! + if(patientUsername == null || patientUsername.isEmpty()) + return null; + + queryParams = new HashMap(); + queryParams.put("cpSerialNumber", "NONE"); + queryParams.put("msgType", "last24hours"); + queryParams.put("requestTime", String.valueOf(System.currentTimeMillis())); + + RecentData recentData = this.getData(this.careLinkServer(), "/patient/m2m/connect/data/gc/patients/" + patientUsername, queryParams, null, RecentData.class); + if (recentData != null) + correctTimeInRecentData(recentData); + return recentData; + + } + + // General data request for API calls + protected T getData(HttpUrl url, RequestBody requestBody, Class dataClass) { + + Request.Builder requestBuilder = null; + HttpUrl.Builder urlBuilder = null; + CareLinkAuthentication authentication = null; + String responseString = null; + Response response = null; + Object data = null; + boolean isBrowserClient = true; + + this.lastDataSuccess = false; + this.lastErrorMessage = ""; + + // Get authentication + authentication = this.getAuthentication(); + + if (authentication != null) { + + // Create request for URL with authToken + //requestBuilder = new Request.Builder().url(url).addHeader("Authorization", authToken); + requestBuilder = new Request.Builder().url(url).headers(authentication.getHeaders()); + + // Add additional headers + if (requestBody == null) { + this.addHttpHeaders(requestBuilder, RequestType.Json, authentication.authType == CareLinkAuthType.Browser); + } else { + requestBuilder.post(requestBody); + this.addHttpHeaders(requestBuilder, RequestType.HtmlPost, authentication.authType == CareLinkAuthType.Browser); + } + + // Send request + try { + response = this.httpClient.newCall(requestBuilder.build()).execute(); + this.lastResponseCode = response.code(); + if (response.isSuccessful()) { + try { + responseString = response.body().string(); + data = new GsonBuilder().create().fromJson(responseString, dataClass); + this.lastDataSuccess = true; + } catch (Exception e) { + lastErrorMessage = e.getClass().getSimpleName() + ":" + e.getMessage(); + } + } + response.close(); + } catch (Exception e) { + lastErrorMessage = e.getClass().getSimpleName() + ":" + e.getMessage(); + } + + } + + //Return result + if (data != null) + return dataClass.cast(data); + else + return null; + + } + + protected T getData(String host, String path, Map queryParams, RequestBody requestBody, + Class dataClass) { + + HttpUrl.Builder urlBuilder = null; + HttpUrl url = null; + + // Build url + urlBuilder = new HttpUrl.Builder().scheme("https").host(host).addPathSegments(path); + if (queryParams != null) { + for (Map.Entry param : queryParams.entrySet()) { + urlBuilder.addQueryParameter(param.getKey(), param.getValue()); + } + } + + url = urlBuilder.build(); + + return this.getData(url, requestBody, dataClass); + + } + + // Http header builder for requests + protected void addHttpHeaders(Request.Builder requestBuilder, RequestType type, boolean isBrowserClient) { + + //Add common browser headers + if(isBrowserClient) { + requestBuilder + .addHeader("Accept-Language", "en;q=0.9, *;q=0.8") + .addHeader("Connection", "keep-alive") + .addHeader("Sec-Ch-Ua", "\"Google Chrome\";v=\"117\", \"Not;A=Brand\";v=\"8\", \"Chromium\";v=\"117\"") + .addHeader("User-Agent", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36"); + } + + //Set media type based on request type + switch (type) { + case Json: + requestBuilder.addHeader("Accept", "application/json, text/plain, */*"); + requestBuilder.addHeader("Content-Type", "application/json; charset=utf-8"); + break; + case HtmlGet: + requestBuilder.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"); + case HtmlPost: + requestBuilder.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"); + requestBuilder.addHeader("Content-Type", "application/x-www-form-urlencoded"); + break; + } + + } + + protected void correctTimeInRecentData(RecentData recentData) { + + boolean timezoneMissing = false; + String offsetString = null; + + if (recentData.sMedicalDeviceTime != null && !recentData.sMedicalDeviceTime.isEmpty() && recentData.lastMedicalDeviceDataUpdateServerTime > 1) { + + //MedicalDeviceTime string has no timezone information + if (parseDateString(recentData.sMedicalDeviceTime) == null) { + + timezoneMissing = true; + + //Try get TZ offset string: lastSG or lastAlarm + if(recentData.lastSG != null && recentData.lastSG.datetime != null) + offsetString = this.getZoneOffset(recentData.lastSG.datetime); + else + offsetString = this.getZoneOffset(recentData.lastAlarm.datetime); + + //Set last alarm datetimeAsDate + if(recentData.lastAlarm != null && recentData.lastAlarm.datetime != null) + recentData.lastAlarm.datetimeAsDate = parseDateString(recentData.lastAlarm.datetime); + //Build correct dates with timezone + recentData.sMedicalDeviceTime = recentData.sMedicalDeviceTime + offsetString; + recentData.medicalDeviceTimeAsString = recentData.medicalDeviceTimeAsString + offsetString; + recentData.sLastSensorTime = recentData.sLastSensorTime + offsetString; + recentData.lastSensorTSAsString = recentData.lastSensorTSAsString + offsetString; + + } else { + timezoneMissing = false; + } + + //Parse dates + recentData.dMedicalDeviceTime = parseDateString(recentData.sMedicalDeviceTime); + recentData.medicalDeviceTimeAsDate = parseDateString(recentData.medicalDeviceTimeAsString); + recentData.dLastSensorTime = parseDateString(recentData.sLastSensorTime); + recentData.lastSensorTSAsDate = parseDateString(recentData.lastSensorTSAsString); + + //Sensor + if (recentData.sgs != null) { + for (SensorGlucose sg : recentData.sgs) { + sg.datetimeAsDate = parseDateString(sg.datetime); + } + } + + //Timezone was present => check if time needs correction + if (!timezoneMissing) { + + //Calc time diff between event time and actual local time + int diffInHour = (int) Math.round(((recentData.lastMedicalDeviceDataUpdateServerTime - recentData.dMedicalDeviceTime.getTime()) / 3600000D)); + + //Correct times if server <> device > 26 mins => possibly different time zones + if (diffInHour != 0 && diffInHour < 26) { + + + recentData.medicalDeviceTimeAsDate = shiftDateByHours(recentData.medicalDeviceTimeAsDate, diffInHour); + recentData.dMedicalDeviceTime = shiftDateByHours(recentData.dMedicalDeviceTime, diffInHour); + recentData.lastConduitDateTime = shiftDateByHours(recentData.lastConduitDateTime, diffInHour); + recentData.lastSensorTSAsDate = shiftDateByHours(recentData.lastSensorTSAsDate, diffInHour); + recentData.dLastSensorTime = shiftDateByHours(recentData.dLastSensorTime, diffInHour); + //Sensor + if (recentData.sgs != null) { + for (SensorGlucose sg : recentData.sgs) { + sg.datetimeAsDate = shiftDateByHours(sg.datetimeAsDate, diffInHour); + } + } + //Markers + if (recentData.markers != null) { + for (Marker marker : recentData.markers) { + marker.dateTime = shiftDateByHours(marker.dateTime, diffInHour); + } + } + //Notifications + if (recentData.notificationHistory != null) { + if (recentData.notificationHistory.clearedNotifications != null) { + for (ClearedNotification notification : recentData.notificationHistory.clearedNotifications) { + notification.dateTime = shiftDateByHours(notification.dateTime, diffInHour); + notification.triggeredDateTime = shiftDateByHours(notification.triggeredDateTime, diffInHour); + } + } + if (recentData.notificationHistory.activeNotifications != null) { + for (ActiveNotification notification : recentData.notificationHistory.activeNotifications) { + notification.dateTime = shiftDateByHours(notification.dateTime, diffInHour); + } + } + } + } + } + + } + + //Set dateTime of Markers using index if dateTime is missing (Guardian Connect) + if (recentData.dLastSensorTime != null && recentData.markers != null) { + for (Marker marker : recentData.markers) { + if (marker != null && marker.dateTime == null) { + try { + marker.dateTime = calcTimeByIndex(recentData.dLastSensorTime, marker.index, true); + } catch (Exception ex) { + continue; + } + } + } + } + + } + + protected String getZoneOffset(String dateString) { + Matcher offsetDataMatcher = Pattern.compile(("(.*)([\\+|-].*)")).matcher(dateString); + if (offsetDataMatcher.find()) + return offsetDataMatcher.group(2); + else + return null; + } + + protected Date parseDateString(String dateString) { + for (SimpleDateFormat zonedFormat : ZONED_DATE_FORMATS) { + try { + return zonedFormat.parse(dateString); + } catch (Exception ex) { + } + } + return null; + } + + protected Date shiftDateByHours(Date date, int hours) { + if (date != null) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + calendar.add(Calendar.HOUR_OF_DAY, hours); + return calendar.getTime(); + } else { + return null; + } + } + + //Calculate DateTime using graph index (1 index = 5 minute) + protected static Date calcTimeByIndex(Date lastSensorTime, int index, boolean round) { + if (lastSensorTime == null) + return null; + else if (round) + //round to 10 minutes + return new Date((Math.round((calcTimeByIndex(lastSensorTime, index, false).getTime()) / 600_000D) * 600_000L)); + else + return new Date((lastSensorTime.getTime() - ((287 - index) * 300_000L))); + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CountryUtils.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CountryUtils.java new file mode 100644 index 0000000000..d7672e175d --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CountryUtils.java @@ -0,0 +1,142 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.client; + +import java.util.Arrays; + +public class CountryUtils { + + public static final String[] supportedCountryCodes = { + "al", + "dz", + "ad", + "ar", + "am", + "aw", + "au", + "at", + "az", + "bs", + "bh", + "bd", + "bb", + "by", + "be", + "bm", + "bo", + "ba", + "bw", + "br", + "bg", + "kh", + "ca", + "ky", + "cl", + "cn", + "co", + "cr", + "hr", + "cw", + "cy", + "cz", + "dk", + "do", + "ec", + "eg", + "sv", + "ee", + "fi", + "fr", + "pf", + "ge", + "de", + "gr", + "gt", + "hn", + "hk", + "hu", + "is", + "in", + "id", + "ir", + "iq", + "ie", + "il", + "it", + "jm", + "jp", + "jo", + "kz", + "ke", + "xk", + "kw", + "lv", + "lb", + "ly", + "li", + "lt", + "lu", + "mo", + "mk", + "my", + "mv", + "mt", + "mu", + "yt", + "mx", + "md", + "me", + "ma", + "na", + "nl", + "nc", + "nz", + "ni", + "ng", + "no", + "om", + "pk", + "pa", + "py", + "pe", + "ph", + "pl", + "pt", + "pr", + "qa", + "ro", + "ru", + "sa", + "rs", + "sg", + "sk", + "si", + "za", + "kr", + "es", + "mf", + "sd", + "se", + "ch", + "tw", + "th", + "tt", + "tn", + "tr", + "ua", + "ae", + "gb", + "us", + "uy", + "uz", + "ve", + "vn" + }; + + public static boolean isSupportedCountry(String countryCode) { + return Arrays.asList(supportedCountryCodes).contains(countryCode); + } + + public static boolean isUS(String countryCode) { + return countryCode.equals("us"); + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/SimpleOkHttpCookieJar.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/SimpleOkHttpCookieJar.java new file mode 100644 index 0000000000..89ab7b939f --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/SimpleOkHttpCookieJar.java @@ -0,0 +1,80 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.client; + +import java.util.ArrayList; +import java.util.List; + +import okhttp3.Cookie; +import okhttp3.CookieJar; +import okhttp3.HttpUrl; + +public class SimpleOkHttpCookieJar implements CookieJar { + + private List storage = new ArrayList<>(); + + @Override + public void saveFromResponse(HttpUrl url, List cookies) { + if (cookies != null && cookies.size() > 0) + storage.addAll(cookies); + } + + @Override + public List loadForRequest(HttpUrl url) { + + List cookies = new ArrayList<>(); + + // Remove expired Cookies + removeExpiredCookies(); + + // Only return matching Cookies + for (Cookie cookie : storage) { + if (cookie.matches(url)) { + cookies.add(cookie); + } + } + + return cookies; + } + + public List getCookies(String name) { + + List cookies = new ArrayList<>(); + + // Remove expired Cookies + removeExpiredCookies(); + + // Only return matching Cookies + for (Cookie cookie : storage) { + if (cookie.name().equals(name)) { + cookies.add(cookie); + } + } + + return cookies; + + } + + public boolean contains(String name) { + return (getCookies(name).size() > 0); + } + + public void deleteCookie(String name) { + for (int i = 0; i < storage.size(); i++) { + if (storage.get(i).name() == name) { + storage.remove(i); + } + } + } + + public void deleteAllCookies() { + storage.clear(); + } + + private void removeExpiredCookies() { + for (int i = 0; i < storage.size(); i++) { + if (storage.get(i).expiresAt() < System.currentTimeMillis()) { + storage.remove(i); + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ActiveInsulin.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ActiveInsulin.java new file mode 100644 index 0000000000..731998a1b3 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ActiveInsulin.java @@ -0,0 +1,17 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +import java.util.Date; + +/** + * CareLink ActiveInsulin data + */ +public class ActiveInsulin { + + public Integer code; + public Date datetime; + public long version; + public Double amount; + public String precision; + public String kind; + +} \ No newline at end of file diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ActiveNotification.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ActiveNotification.java new file mode 100644 index 0000000000..5f9810fec9 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ActiveNotification.java @@ -0,0 +1,18 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +import java.util.Date; + +public class ActiveNotification { + + public String GUID; + public Date dateTime; + public String type; + public int faultId; + public int instanceId; + public String messageId; + public String pumpDeliverySuspendState; + public String pnpId; + public int relativeOffset; + public Boolean alertSilenced; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Alarm.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Alarm.java new file mode 100644 index 0000000000..71c385f824 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Alarm.java @@ -0,0 +1,27 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +import java.util.Date; + +/** + * CareLink Alarm data + */ +public class Alarm { + + public String getMessageAlarmCode() { + return null; + } + + public int code; + public String datetime; + public Date datetimeAsDate; + public String type; + public boolean flash; + public String kind; + public long version; + public Integer instanceId; + public String messageId; + public Integer sg; + public Boolean pumpDeliverySuspendState; + public String referenceGUID; + +} \ No newline at end of file diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Basal.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Basal.java new file mode 100644 index 0000000000..3fb91c9794 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Basal.java @@ -0,0 +1,8 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +public class Basal { + + public String activeBasalPattern; + public Double basalRate; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ClearedNotification.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ClearedNotification.java new file mode 100644 index 0000000000..53228a83ad --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ClearedNotification.java @@ -0,0 +1,18 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +import java.util.Date; + +public class ClearedNotification { + + public String referenceGUID; + public Date dateTime; + public String type; + public int faultId; + public int instanceId; + public String messageId; + public String pumpDeliverySuspendState; + public String pnpId; + public int relativeOffset; + public Date triggeredDateTime; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ConnectData.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ConnectData.java new file mode 100644 index 0000000000..0c7d6b6c38 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ConnectData.java @@ -0,0 +1,55 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +import java.util.List; + +/** + * CareLink ConnectData message + */ +public class ConnectData { + + public String lastSensorTSAsString; + public String medicalDeviceTimeAsString; + public String bgunits; + public long lastSensorTS; + public String kind; + public long version; + public long currentServerTime; + public long lastConduitTime; + public long lastConduitUpdateServerTime; + public long lastMedicalDeviceDataUpdateServerTime; + public String firstName; + public String lastName; + public String conduitSerialNumber; + public int conduitBatteryLevel; + public String conduitBatteryStatus; + public boolean conduitInRange; + public boolean conduitMedicalDeviceInRange; + public boolean conduitSensorInRange; + public String medicalDeviceFamily; + public String sensorState; + public String medicalDeviceSerialNumber; + public long medicalDeviceTime; + public String sMedicalDeviceTime; + public int reservoirLevelPercent; + public long reservoirAmount; + public int medicalDeviceBatteryLevelPercent; + public int sensorDurationHours; + public int timeToNextCalibHours; + public String calibStatus; + public String bgUnits; + public String timeFormat; + public int lastSensorTime; + public String sLastSensorTime; + public boolean medicalDeviceSuspended; + public String lastSGTrend; + public SensorGlucose lastSG; + public Alarm lastAlarm; + public ActiveInsulin activeInsulin; + public List sgs; + public List markers; + + public ConnectData() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ConnectDataResult.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ConnectDataResult.java new file mode 100644 index 0000000000..c55628885b --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ConnectDataResult.java @@ -0,0 +1,10 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +/** + * CareLink ConnectData result + */ +public class ConnectDataResult extends Result { + + public ConnectData connectData; + +} \ No newline at end of file diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Country.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Country.java new file mode 100644 index 0000000000..74ff44126e --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Country.java @@ -0,0 +1,10 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +public class Country { + + public String countryCode; + public String countryName; + public String dialCode; + public String defaultCountryName; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/CountrySettings.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/CountrySettings.java new file mode 100644 index 0000000000..91ff0cbce6 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/CountrySettings.java @@ -0,0 +1,40 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +import java.util.List; + +public class CountrySettings { + + public String name; + public List languages; + public String defaultLanguage; + public String defaultCountryName; + public String defaultDevice; + public String dialCode; + public boolean cpMobileAppAvailable; + public boolean uploaderAllowed; + public String techSupport; + public String techDays; + public String firstDayOfWeek; + public String techHours; + public Integer legalAge; + public String shortDateFormat; + public String shortTimeFormat; + public String mediaHost; + public String blePereodicDataEndpoint; + public String region; + public String carbDefaultUnit; + public String bgUnits; + public String timeFormat; + public String timeUnitsDefault; + public String recordSeparator; + public String glucoseUnitsDefault; + public String carbohydrateUnitsDefault; + public Long carbExchangeRatioDefault; + public ReportDateFormat reportDateFormat; + public MfaRules mfa; + public List supportedReports; + public boolean smsSendingAllowed; + public PostalInfo postal; + public NumberFormat numberFormat; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/DataUpload.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/DataUpload.java new file mode 100644 index 0000000000..258c9a27da --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/DataUpload.java @@ -0,0 +1,11 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +public class DataUpload { + + public long date; + public boolean mobileUploaded; + public String status; + public String device; + public String serialNumber; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Language.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Language.java new file mode 100644 index 0000000000..6134b34129 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Language.java @@ -0,0 +1,8 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +public class Language { + + public String name; + public String code; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Limit.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Limit.java new file mode 100644 index 0000000000..f4410c50c2 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Limit.java @@ -0,0 +1,11 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +public class Limit { + + public int index; + public int highLimit; + public int lowLimit; + public String kind; + public int version; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/M2MEnabled.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/M2MEnabled.java new file mode 100644 index 0000000000..5faa49f4a9 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/M2MEnabled.java @@ -0,0 +1,7 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +public class M2MEnabled { + + public boolean value; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Marker.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Marker.java new file mode 100644 index 0000000000..7ea335aab1 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Marker.java @@ -0,0 +1,46 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +import java.util.Date; + +/** + * CareLink Marker data + */ +public class Marker { + + public static final String MARKER_TYPE_MEAL = "MEAL"; + public static final String MARKER_TYPE_CALIBRATION = "CALIBRATION"; + public static final String MARKER_TYPE_BG_READING = "BG_READING"; + public static final String MARKER_TYPE_BG = "BG"; + public static final String MARKER_TYPE_INSULIN = "INSULIN"; + public static final String MARKER_TYPE_AUTO_BASAL = "AUTO_BASAL_DELIVERY"; + public static final String MARKER_TYPE_AUTO_MODE_STATUS = "AUTO_MODE_STATUS"; + + public boolean isBloodGlucose() { + if (type == null) + return false; + else + return (type.equals(MARKER_TYPE_BG_READING) || type.equals(MARKER_TYPE_CALIBRATION) || type.equals(MARKER_TYPE_BG)); + } + + public String type; + public int index; + public Double value; + public String kind; + public int version; + public Date dateTime; + public Integer relativeOffset; + public Boolean calibrationSuccess; + public Double amount; + public Float programmedExtendedAmount; + public String activationType; + public Float deliveredExtendedAmount; + public Float programmedFastAmount; + public Integer programmedDuration; + public Float deliveredFastAmount; + public Integer effectiveDuration; + public Boolean completed; + public String bolusType; + public Boolean autoModeOn; + public Float bolusAmount; + +} \ No newline at end of file diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/MfaRules.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/MfaRules.java new file mode 100644 index 0000000000..bc3cc442c7 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/MfaRules.java @@ -0,0 +1,12 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +public class MfaRules { + + public String status; + public String fromDate; + public int gracePeriod; + public int codeValidityDuration; + public int maxAttempts; + public int rememberPeriod; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/MonitorData.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/MonitorData.java new file mode 100644 index 0000000000..6f4d73f3f4 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/MonitorData.java @@ -0,0 +1,11 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +public class MonitorData { + + public String deviceFamily; + + public boolean isBle() { + return deviceFamily.contains("BLE"); + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/NotificationHistory.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/NotificationHistory.java new file mode 100644 index 0000000000..dc2dd34cea --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/NotificationHistory.java @@ -0,0 +1,10 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +import java.util.List; + +public class NotificationHistory { + + public List activeNotifications; + public List clearedNotifications; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/NumberFormat.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/NumberFormat.java new file mode 100644 index 0000000000..2f19f9847a --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/NumberFormat.java @@ -0,0 +1,8 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +public class NumberFormat { + + public String decimalSeparator; + public String groupsSeparator; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Patient.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Patient.java new file mode 100644 index 0000000000..b80ac5e749 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Patient.java @@ -0,0 +1,18 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +public class Patient { + + public String firstName; + public String lastName; + public String status; + public String username; + public boolean notificationsAllowed; + public String nickname; + public String lastDeviceFamily; + public boolean patientUsesConnect; + + public boolean isBle() { + return lastDeviceFamily.contains("BLE"); + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/PostalInfo.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/PostalInfo.java new file mode 100644 index 0000000000..f9ab20468b --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/PostalInfo.java @@ -0,0 +1,8 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +public class PostalInfo { + + public String[] postalFormat; + public String regExpStr; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Profile.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Profile.java new file mode 100644 index 0000000000..83796575dd --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Profile.java @@ -0,0 +1,31 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +public class Profile { + + public String username; + public String firstName; + public String middleName; + public String lastName; + public boolean guardianParent; + public String parentFirstName; + public String parentMiddleName; + public String parentLastName; + public String address; + public String city; + public String stateProvince; + public String postalCode; + public String country; + public String dateOfBirth; + public String phone; + public String phoneLegacy; + public String email; + public String gender; + public String diabetesType; + public String therapyType; + public String ageRange; + public String insulinType; + public String patientNickname; + public String textNotification; + public String a1C; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/PumpBannerState.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/PumpBannerState.java new file mode 100644 index 0000000000..117cc5b446 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/PumpBannerState.java @@ -0,0 +1,22 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +public class PumpBannerState { + + public static final String STATE_DUAL_BOLUS = "DUAL_BOLUS"; + public static final String STATE_SQUARE_BOLUS = "SQUARE_BOLUS"; + public static final String STATE_LOAD_RESERVOIR = "LOAD_RESERVOIR"; + public static final String STATE_SUSPENDED_ON_LOW = "SUSPENDED_ON_LOW"; + public static final String STATE_SUSPENDED_BEFORE_LOW = "SUSPENDED_BEFORE_LOW"; + public static final String STATE_DELIVERY_SUSPEND = "DELIVERY_SUSPEND"; + public static final String STATE_BG_REQUIRED = "BG_REQUIRED"; + public static final String STATE_PROCESSING_BG = "PROCESSING_BG"; + public static final String STATE_WAIT_TO_ENTER_BG = "WAIT_TO_ENTER_BG"; + public static final String STATE_TEMP_TARGET = "TEMP_TARGET"; + public static final String STATE_TEMP_BASAL = "TEMP_BASAL"; + public static final String STATE_NO_DELIVERY = "NO_DELIVERY"; + public static final String STATE_CALIBRATION_REQUIRED = "CALIBRATION_REQUIRED"; + + public String type; + public int timeRemaining; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/RecentData.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/RecentData.java new file mode 100644 index 0000000000..528020f9ee --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/RecentData.java @@ -0,0 +1,127 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +import java.util.Date; +import java.util.List; + +public class RecentData { + + public static final String DEVICE_FAMILY_GUARDIAN = "GUARDIAN"; + public static final String DEVICE_FAMILY_NGP = "NGP"; + + //sensorState + public static final String SENSOR_STATE_CALIBRATION_REQUIRED = "CALIBRATION_REQUIRED"; + public static final String SENSOR_STATE_NO_DATA_FROM_PUMP = "NO_DATA_FROM_PUMP"; + public static final String SENSOR_STATE_WAIT_TO_CALIBRATE = "WAIT_TO_CALIBRATE"; + public static final String SENSOR_STATE_DO_NOT_CALIBRATE = "DO_NOT_CALIBRATE"; + public static final String SENSOR_STATE_CALIBRATING = "CALIBRATING"; + public static final String SENSOR_STATE_NO_ERROR_MESSAGE = "NO_ERROR_MESSAGE"; + public static final String SENSOR_STATE_WARM_UP = "WARM_UP"; + public static final String SENSOR_STATE_CHANGE_SENSOR = "CHANGE_SENSOR"; + public static final String SENSOR_STATE_NORMAL = "NORMAL"; + public static final String SENSOR_STATE_UNKNOWN = "UNKNOWN"; + + //systemStatusMessage + public static final String SYSTEM_STATUS_BLUETOOTH_OFF = "BLUETOOTH_OFF"; + public static final String SYSTEM_STATUS_UPDATING = "UPDATING"; + public static final String SYSTEM_STATUS_RECONNECTING_TO_PUMP = "RECONNECTING_TO_PUMP"; + public static final String SYSTEM_STATUS_PUMP_PAIRING_LOST = "PUMP_PAIRING_LOST"; + public static final String SYSTEM_STATUS_LOST_PUMP_SIGNAL = "LOST_PUMP_SIGNAL"; + public static final String SYSTEM_STATUS_PUMP_NOT_PAIRED = "PUMP_NOT_PAIRED"; + public static final String SYSTEM_STATUS_SENSOR_OFF = "SENSOR_OFF"; + public static final String SYSTEM_STATUS_NO_ERROR_MESSAGE = "NO_ERROR_MESSAGE"; + public static final String SYSTEM_STATUS_CALIBRATION_REQUIRED = "CALIBRATION_REQUIRED"; + + //autoModeShieldState + public static final String AUTOMODE_SHIELD_AUTO_BASAL = "AUTO_BASAL"; + public static final String AUTOMODE_SHIELD_FEATURE_OFF = "FEATURE_OFF"; + + //autoModeReadinessState + public static final String AUTOMODE_READINESS_NO_ACTION_REQUIRED = "NO_ACTION_REQUIRED"; + + //plgmLgsState + public static final String LGS_STATE_FEATURE_OFF = "FEATURE_OFF"; + public static final String LGS_STATE_MONITORING = "MONITORING"; + + + public String getDeviceFamily() { + return medicalDeviceFamily; + } + + public boolean isGM() { + return getDeviceFamily().equals(DEVICE_FAMILY_GUARDIAN); + } + + public boolean isNGP() { + return getDeviceFamily().equals(DEVICE_FAMILY_NGP); + } + + public long lastSensorTS; + public String medicalDeviceTimeAsString; + public Date medicalDeviceTimeAsDate; + public String lastSensorTSAsString; + public Date lastSensorTSAsDate; + public String kind; + public int version; + public String pumpModelNumber; + public long currentServerTime; + public long lastConduitTime; + public long lastConduitUpdateServerTime; + public long lastMedicalDeviceDataUpdateServerTime; + public String firstName; + public String lastName; + public String conduitSerialNumber; + public int conduitBatteryLevel; + public String conduitBatteryStatus; + public Boolean conduitInRange; + public Boolean conduitMedicalDeviceInRange; + public Boolean conduitSensorInRange; + public String medicalDeviceFamily; + public String sensorState; + public String medicalDeviceSerialNumber; + public long medicalDeviceTime; + public String sMedicalDeviceTime; + public Date dMedicalDeviceTime; + public int reservoirLevelPercent; + public int reservoirAmount; + public float reservoirRemainingUnits; + public int medicalDeviceBatteryLevelPercent; + public int sensorDurationHours; + public int timeToNextCalibHours; + public String calibStatus; + public String bgUnits; + public String timeFormat; + public long lastSensorTime; + public String sLastSensorTime; + public Date dLastSensorTime; + public boolean medicalDeviceSuspended; + public String lastSGTrend; + public SensorGlucose lastSG; + public Alarm lastAlarm; + public ActiveInsulin activeInsulin; + public List sgs; + public List limits; + public List markers; + public NotificationHistory notificationHistory; + public TherapyAlgorithmState therapyAlgorithmState; + public List pumpBannerState; + public Basal basal; + public String systemStatusMessage; + public int averageSG; + public int belowHypoLimit; + public int aboveHyperLimit; + public int timeInRange; + public Boolean pumpCommunicationState; + public Boolean gstCommunicationState; + public int gstBatteryLevel; + public Date lastConduitDateTime; + public float maxAutoBasalRate; + public float maxBolusAmount; + public int sensorDurationMinutes; + public int timeToNextCalibrationMinutes; + public String clientTimeZoneName; + public int sgBelowLimit; + public float averageSGFloat; + public Boolean calFreeSensor; + public Boolean finalCalibration; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/RecentUploads.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/RecentUploads.java new file mode 100644 index 0000000000..6c79d8ae6c --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/RecentUploads.java @@ -0,0 +1,9 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +import java.util.List; + +public class RecentUploads { + + public List recentUploads; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ReportDataProvider.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ReportDataProvider.java new file mode 100644 index 0000000000..f97fa6e689 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ReportDataProvider.java @@ -0,0 +1,10 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +import java.util.List; + +public class ReportDataProvider { + + public String category; + public List segments; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ReportDateFormat.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ReportDateFormat.java new file mode 100644 index 0000000000..fdd0760fde --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ReportDateFormat.java @@ -0,0 +1,13 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +public class ReportDateFormat { + + public String longTimePattern12; + public String longTimePattern24; + public String shortTimePattern12; + public String shortTimePattern24; + public String shortDatePattern; + public String dateSeparator; + public String timeSeparator; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ReportSnapshotTimelinesForCalendar.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ReportSnapshotTimelinesForCalendar.java new file mode 100644 index 0000000000..f14a6b4f17 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ReportSnapshotTimelinesForCalendar.java @@ -0,0 +1,9 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +import java.util.List; + +public class ReportSnapshotTimelinesForCalendar { + + public List dataProvider; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ReportTimelinesRange.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ReportTimelinesRange.java new file mode 100644 index 0000000000..4914e4e823 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/ReportTimelinesRange.java @@ -0,0 +1,8 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +public class ReportTimelinesRange { + + public String start; + public String end; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Result.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Result.java new file mode 100644 index 0000000000..1bbbf98666 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Result.java @@ -0,0 +1,11 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +/** + * CareLink communication result base + */ +public class Result { + + public boolean success; + public int responseCode; + +} \ No newline at end of file diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/SensorGlucose.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/SensorGlucose.java new file mode 100644 index 0000000000..d04efbc11c --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/SensorGlucose.java @@ -0,0 +1,32 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +import java.util.Date; + +/** + * CareLink SensorGlucose message with helper methods for processing + */ +public class SensorGlucose { + + public Integer sg; + public String datetime; + public Date datetimeAsDate; + public boolean timeChange; + public String kind; + public int version; + public String sensorState; + public int relativeOffset; + + public long timestamp = -1; + public Date date = null; + + public String toS() { + String dt; + if (datetime == null) { + dt = ""; + } else { + dt = datetime; + } + return dt + " " + sg; + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/SupportedReport.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/SupportedReport.java new file mode 100644 index 0000000000..ce9cde5f9d --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/SupportedReport.java @@ -0,0 +1,9 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +public class SupportedReport { + + public String report; + public String[] onlyFor; + public String[] notFor; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/TextMap.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/TextMap.java new file mode 100644 index 0000000000..bf0522528c --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/TextMap.java @@ -0,0 +1,344 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +import java.util.HashMap; + +public class TextMap { + + + public static final String ERROR_TEXT_PREFIX_GUARDIAN = "GM_"; + public static final String ERROR_TEXT_PREFIX_NGP = "N"; + + private static HashMap errorTextMap; + private static HashMap errorCodeMap; + + static { + + errorTextMap = new HashMap<>(); + errorTextMap.put("", ""); + errorTextMap.put("3", "Battery out limit"); + errorTextMap.put("4", "Delivery stopped. Check BG"); + errorTextMap.put("5", "Pump battery depleted. Insulin delivery stopped"); + errorTextMap.put("6", "Auto Off. Insulin delivery stopped"); + errorTextMap.put("16", "Pump reset. Insulin delivery stopped"); + errorTextMap.put("43", "Pump motor error. Insulin delivery stopped"); + errorTextMap.put("50", "Bolus stopped"); + errorTextMap.put("51", "Delivery limit exceeded. Check BG"); + errorTextMap.put("55", "Pump battery failed. Replace battery"); + errorTextMap.put("59", "Button error"); + errorTextMap.put("61", "Check settings. Insulin delivery stopped"); + errorTextMap.put("62", "Empty reservoir"); + errorTextMap.put("66", "No reservoir"); + errorTextMap.put("74", "Finish loading"); + errorTextMap.put("81", "Replace pump battery now"); + errorTextMap.put("82", "Low Reservoir"); + errorTextMap.put("83", "Check BG"); + errorTextMap.put("84", "Alarm clock"); + errorTextMap.put("85", "Max fill reached"); + errorTextMap.put("86", "Weak battery detected"); + errorTextMap.put("87", "Missed bolus"); + errorTextMap.put("88", "Silenced sensor alert. Check alarm history"); + errorTextMap.put("101", "High SG. CHECK BG"); + errorTextMap.put("102", "Low SG"); + errorTextMap.put("103", "Threshold Suspend"); + errorTextMap.put("104", "Meter BG now"); + errorTextMap.put("105", "Calibration Reminder"); + errorTextMap.put("106", "Calibration error"); + errorTextMap.put("107", "Sensor expired"); + errorTextMap.put("108", "Change sensor"); + errorTextMap.put("109", "Sensor error"); + errorTextMap.put("110", "Recharge transmitter"); + errorTextMap.put("111", "Transmitter battery low"); + errorTextMap.put("112", "Weak signal"); + errorTextMap.put("113", "Lost sensor"); + errorTextMap.put("114", "Sensor glucose approaching high limit"); + errorTextMap.put("115", "Sensor glucose approaching low limit"); + errorTextMap.put("116", "Sensor glucose rising rapidly"); + errorTextMap.put("117", "Sensor glucose falling rapidly"); + errorTextMap.put("Axx", "Pump error Anull"); + errorTextMap.put("Exx", "Pump error Enull"); + errorTextMap.put("N002", "Pump Error. Delivery Stopped"); + errorTextMap.put("N006", "Pump Battery Out Limit"); + errorTextMap.put("N007", "Delivery Stopped. Check BG"); + errorTextMap.put("N011", "Replace Pump Battery Now"); + errorTextMap.put("N012", "Auto Suspend Limit Reached. Delivery Stopped"); + errorTextMap.put("N024", "Critical Pump Error. Stop Pump Use. Use Other Treatment"); + errorTextMap.put("N025", "Pump Power Error. Record Settings"); + errorTextMap.put("N029", "Pump Restarted. Delivery Stopped"); + errorTextMap.put("N037", "Pump Motor Error. Delivery Stopped"); + errorTextMap.put("N051", "Bolus Stopped"); + errorTextMap.put("N052", "Delivery Limit Exceeded. Check BG"); + errorTextMap.put("N057", "Pump Battery Not Compatible"); + errorTextMap.put("N058", "Insert A New AA Battery"); + errorTextMap.put("N061", "Pump Button Error. Delivery Stopped"); + errorTextMap.put("N062", "New Notification Received From Pump"); + errorTextMap.put("N066", "No Reservoir Detected During Infusion Set Change"); + errorTextMap.put("N069", "Loading Incomplete During Infusion Set Change"); + errorTextMap.put("N073", "Replace Pump Battery Now"); + errorTextMap.put("N077", "Pump Settings Error. Delivery Stopped"); + errorTextMap.put("N084", "Pump Battery Removed. Replace Battery"); + errorTextMap.put("N100", "Bolus Entry Timed Out Before Delivery"); + errorTextMap.put("N103", "BG Check Reminder"); + errorTextMap.put("N104", "Replace Pump Battery Soon"); + errorTextMap.put("N105", "Reservoir Low. Change Reservoir Soon"); + errorTextMap.put("N107", "Missed Meal Bolus Reminder"); + errorTextMap.put("N109", "Set Change Reminder"); + errorTextMap.put("N110", "Silenced Sensor Alert. Check Alarm History"); + errorTextMap.put("N113", "Reservoir Empty. Change Reservoir Now"); + errorTextMap.put("N117", "Active Insulin Cleared"); + errorTextMap.put("N130", "Rewind Required. Delivery Stopped"); + errorTextMap.put("N140", "Delivery Suspended. Connect Infusion Set"); + errorTextMap.put("N775", "Calibrate Now"); + errorTextMap.put("N776", "Calibration Error"); + errorTextMap.put("N777", "Change Sensor"); + errorTextMap.put("N779", "Recharge Transmitter Now"); + errorTextMap.put("N780", "Lost Sensor Signal"); + errorTextMap.put("N784", "SG Rising Rapidly"); + errorTextMap.put("N794", "Sensor Expired. Change Sensor"); + errorTextMap.put("N795", "Lost Sensor Signal. Check Transmitter"); + errorTextMap.put("N796", "No Sensor Signal"); + errorTextMap.put("N797", "Sensor Connected"); + errorTextMap.put("N801", "Do Not Calibrate. Wait Up To 3 Hours"); + errorTextMap.put("N802", "Low Sensor Glucose"); + errorTextMap.put("N803", "Low Sensor Glucose. Check BG"); + errorTextMap.put("N805", "Alert Before Low. Check BG"); + errorTextMap.put("N807", "Basal Delivery Resumed. Check BG"); + errorTextMap.put("N809", "Suspend On Low. Delivery Stopped. Check BG"); + errorTextMap.put("N810", "Suspend Before Low. Delivery Stopped. Check BG"); + errorTextMap.put("N812", "Call Emergency Assistance"); + errorTextMap.put("N814", "Basal Resumed. SG Still Under Low Limit. Check BG"); + errorTextMap.put("N815", "Low Limit Changed. Basal Manually Resumed. Check BG"); + errorTextMap.put("N816", "High Sensor Glucose"); + errorTextMap.put("N817", "Alert Before High. Check BG"); + errorTextMap.put("N819", "Auto Mode Exit. Basal Delivery Started. BG Required"); + errorTextMap.put("N821", "Minimum Delivery Timeout. BG Required"); + errorTextMap.put("N822", "Maximum Delivery Timeout. BG Required"); + errorTextMap.put("N823", "High Sensor Glucose For Over 1 Hour"); + errorTextMap.put("N827", "Urgent Low Sensor Glucose. Check BG"); + errorTextMap.put("N829", "BG Required"); + errorTextMap.put("N832", "Calibration Required"); + errorTextMap.put("N833", "Correction Bolus Recommended"); + errorTextMap.put("N869", "Calibration Reminder"); + errorTextMap.put("N870", "Recharge Transmitter Soon"); + errorTextMap.put("Nnodata1", "Reconnecting To Pump"); + errorTextMap.put("Nnodata2", "Lost Signal. Check Mobile Application"); + errorTextMap.put("GM_alert.sg.threshold.low.urgent", "Urgent Low Sensor Glucose"); + errorTextMap.put("GM_alert.sg.threshold.low", "Low Sensor Glucose"); + errorTextMap.put("GM_alert.sg.predictive.low", "Low Predicted"); + errorTextMap.put("GM_alert.sg.rate.falling", "Fall Alert"); + errorTextMap.put("GM_alert.sg.threshold.high", "High Sensor Glucose"); + errorTextMap.put("GM_alert.sg.predictive.high", "High Predicted"); + errorTextMap.put("GM_alert.sg.rate.rising", "Rise Alert"); + errorTextMap.put("GM_alert.transmitter.battery", "Transmitter Battery Empty"); + errorTextMap.put("GM_alert.sensor.replace.calibrationError", "Change Sensor"); + errorTextMap.put("GM_alert.sensor.replace.sensorError", "Change Sensor"); + errorTextMap.put("GM_alert.sensor.replace.lifetime", "Sensor End of Life"); + errorTextMap.put("GM_alert.transmitter.signal", "Lost Sensor Communication"); + errorTextMap.put("GM_alert.sensor.connection", "Sensor Connected"); + errorTextMap.put("GM_alert.sensor.calibration.rejected", "Calibration Not Accepted"); + errorTextMap.put("GM_alert.sensor.calibration.calibrate_now", "Calibrate Now"); + errorTextMap.put("GM_alert.sensor.error", "Sensor Glucose Not Available"); + errorTextMap.put("GM_alert.calibration.reminder", "Calibration Reminder"); + errorTextMap.put("GM_alert.transmitter.error", "Transmitter Error"); + errorTextMap.put("GM_alert.receiver.battery.low", "Mobile Device Battery Low"); + errorTextMap.put("Nalert.sg.threshold.low.urgent", "Urgent Low Sensor Glucose"); + errorTextMap.put("Nalert.sg.threshold.low", "Low Sensor Glucose"); + errorTextMap.put("Nalert.sg.predictive.low", "Low Predicted"); + errorTextMap.put("Nalert.sg.rate.falling", "Fall Alert"); + errorTextMap.put("Nalert.sg.threshold.high", "High Sensor Glucose"); + errorTextMap.put("Nalert.sg.predictive.high", "High Predicted"); + errorTextMap.put("Nalert.sg.rate.rising", "Rise Alert"); + errorTextMap.put("Nalert.transmitter.battery", "Transmitter Battery Empty"); + errorTextMap.put("Nalert.sensor.replace.calibrationError", "Change Sensor"); + errorTextMap.put("Nalert.sensor.replace.sensorError", "Change Sensor"); + errorTextMap.put("Nalert.sensor.replace.lifetime", "Sensor End of Life"); + errorTextMap.put("Nalert.transmitter.signal", "Lost Sensor Communication"); + errorTextMap.put("Nalert.sensor.connection", "Sensor Connected"); + errorTextMap.put("Nalert.sensor.calibration.rejected", "Calibration Not Accepted"); + errorTextMap.put("Nalert.sensor.calibration.calibrate_now", "Calibrate Now"); + errorTextMap.put("Nalert.sensor.error", "Sensor Glucose Not Available"); + errorTextMap.put("Nalert.calibration.reminder", "Calibration Reminder"); + errorTextMap.put("Nalert.transmitter.error", "Transmitter Error"); + errorTextMap.put("Nalert.receiver.battery.low", "Mobile Device Battery Low"); + + errorCodeMap = new HashMap<>(); + errorCodeMap.put("002", "002"); + errorCodeMap.put("003", "002"); + errorCodeMap.put("004", "002"); + errorCodeMap.put("013", "002"); + errorCodeMap.put("014", "002"); + errorCodeMap.put("015", "002"); + errorCodeMap.put("016", "002"); + errorCodeMap.put("017", "002"); + errorCodeMap.put("018", "002"); + errorCodeMap.put("019", "002"); + errorCodeMap.put("020", "002"); + errorCodeMap.put("022", "002"); + errorCodeMap.put("023", "002"); + errorCodeMap.put("026", "002"); + errorCodeMap.put("027", "002"); + errorCodeMap.put("028", "002"); + errorCodeMap.put("030", "002"); + errorCodeMap.put("031", "002"); + errorCodeMap.put("033", "002"); + errorCodeMap.put("034", "002"); + errorCodeMap.put("044", "002"); + errorCodeMap.put("045", "002"); + errorCodeMap.put("046", "002"); + errorCodeMap.put("049", "002"); + errorCodeMap.put("053", "002"); + errorCodeMap.put("054", "002"); + errorCodeMap.put("060", "002"); + errorCodeMap.put("063", "002"); + errorCodeMap.put("064", "002"); + errorCodeMap.put("065", "002"); + errorCodeMap.put("067", "002"); + errorCodeMap.put("068", "002"); + errorCodeMap.put("074", "002"); + errorCodeMap.put("075", "002"); + errorCodeMap.put("076", "002"); + errorCodeMap.put("079", "002"); + errorCodeMap.put("080", "002"); + errorCodeMap.put("081", "002"); + errorCodeMap.put("082", "002"); + errorCodeMap.put("117", "117"); + errorCodeMap.put("817", "817"); + errorCodeMap.put("805", "805"); + errorCodeMap.put("819", "819"); + errorCodeMap.put("820", "819"); + errorCodeMap.put("012", "012"); + errorCodeMap.put("807", "807"); + errorCodeMap.put("808", "807"); + errorCodeMap.put("814", "814"); + errorCodeMap.put("103", "103"); + errorCodeMap.put("829", "829"); + errorCodeMap.put("830", "829"); + errorCodeMap.put("831", "829"); + errorCodeMap.put("100", "100"); + errorCodeMap.put("051", "051"); + errorCodeMap.put("775", "775"); + errorCodeMap.put("776", "776"); + errorCodeMap.put("869", "869"); + errorCodeMap.put("832", "832"); + errorCodeMap.put("812", "812"); + errorCodeMap.put("777", "777"); + errorCodeMap.put("778", "777"); + errorCodeMap.put("789", "777"); + errorCodeMap.put("833", "833"); + errorCodeMap.put("024", "024"); + errorCodeMap.put("035", "024"); + errorCodeMap.put("040", "024"); + errorCodeMap.put("047", "024"); + errorCodeMap.put("048", "024"); + errorCodeMap.put("050", "024"); + errorCodeMap.put("055", "024"); + errorCodeMap.put("131", "024"); + errorCodeMap.put("052", "052"); + errorCodeMap.put("007", "007"); + errorCodeMap.put("008", "007"); + errorCodeMap.put("140", "140"); + errorCodeMap.put("801", "801"); + errorCodeMap.put("816", "816"); + errorCodeMap.put("823", "823"); + errorCodeMap.put("824", "823"); + errorCodeMap.put("058", "058"); + errorCodeMap.put("069", "069"); + errorCodeMap.put("780", "780"); + errorCodeMap.put("781", "780"); + errorCodeMap.put("795", "795"); + errorCodeMap.put("815", "815"); + errorCodeMap.put("802", "802"); + errorCodeMap.put("803", "803"); + errorCodeMap.put("822", "822"); + errorCodeMap.put("821", "821"); + errorCodeMap.put("107", "107"); + errorCodeMap.put("066", "066"); + errorCodeMap.put("796", "796"); + errorCodeMap.put("057", "057"); + errorCodeMap.put("006", "006"); + errorCodeMap.put("084", "084"); + errorCodeMap.put("061", "061"); + errorCodeMap.put("037", "037"); + errorCodeMap.put("038", "037"); + errorCodeMap.put("039", "037"); + errorCodeMap.put("041", "037"); + errorCodeMap.put("042", "037"); + errorCodeMap.put("043", "037"); + errorCodeMap.put("025", "025"); + errorCodeMap.put("029", "029"); + errorCodeMap.put("077", "077"); + errorCodeMap.put("779", "779"); + errorCodeMap.put("870", "870"); + errorCodeMap.put("011", "011"); + errorCodeMap.put("073", "011"); + errorCodeMap.put("104", "104"); + errorCodeMap.put("113", "113"); + errorCodeMap.put("105", "105"); + errorCodeMap.put("106", "105"); + errorCodeMap.put("130", "130"); + errorCodeMap.put("797", "797"); + errorCodeMap.put("798", "797"); + errorCodeMap.put("794", "794"); + errorCodeMap.put("109", "109"); + errorCodeMap.put("784", "784"); + errorCodeMap.put("110", "110"); + errorCodeMap.put("810", "810"); + errorCodeMap.put("811", "810"); + errorCodeMap.put("809", "809"); + errorCodeMap.put("062", "062"); + errorCodeMap.put("070", "062"); + errorCodeMap.put("071", "062"); + errorCodeMap.put("072", "062"); + errorCodeMap.put("108", "062"); + errorCodeMap.put("114", "062"); + errorCodeMap.put("786", "062"); + errorCodeMap.put("787", "062"); + errorCodeMap.put("788", "062"); + errorCodeMap.put("799", "062"); + errorCodeMap.put("806", "062"); + errorCodeMap.put("825", "062"); + errorCodeMap.put("828", "062"); + errorCodeMap.put("827", "827"); + + } + + public static String getAlarmMessage(String deviceFamily, Alarm alarm) { + + return getErrorMessage(deviceFamily, alarm.kind, alarm.code); + + } + + public static String getNotificationMessage(String deviceFamily, ClearedNotification notification) { + return getErrorMessage(deviceFamily, notification.messageId, notification.faultId); + } + + public static String getNotificationMessage(String deviceFamily, String messageId, int faultId) { + return getErrorMessage(deviceFamily, messageId, faultId); + } + + public static String getErrorMessage(String deviceFamily, String guardianErrorCode, int ngpErrorCode) { + String errorTextId; + String internalEC; + + if (deviceFamily.equals(RecentData.DEVICE_FAMILY_GUARDIAN)) { + if (guardianErrorCode != null) + errorTextId = ERROR_TEXT_PREFIX_GUARDIAN + guardianErrorCode; + else + errorTextId = null; + } else if (deviceFamily.equals(RecentData.DEVICE_FAMILY_NGP)) { + String formattedEC = String.format("%03d", ngpErrorCode); + if (errorCodeMap.containsKey(formattedEC)) + internalEC = errorCodeMap.get(formattedEC); + else + internalEC = formattedEC; + errorTextId = ERROR_TEXT_PREFIX_NGP + internalEC; + } else { + errorTextId = null; + } + + if (errorTextId != null && errorTextMap.containsKey(errorTextId)) + return errorTextMap.get(errorTextId); + else + return null; + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/TherapyAlgorithmState.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/TherapyAlgorithmState.java new file mode 100644 index 0000000000..d63b5571d6 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/TherapyAlgorithmState.java @@ -0,0 +1,11 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +public class TherapyAlgorithmState { + + public String autoModeShieldState; + public String autoModeReadinessState; + public String plgmLgsState; + public int safeBasalDuration; + public int waitToCalibrateDuration; + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/User.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/User.java new file mode 100644 index 0000000000..2aedecc850 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/User.java @@ -0,0 +1,39 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +import java.util.Date; + +public class User { + + public static final String ROLE_CARE_PARTNER_US = "CARE_PARTNER"; + public static final String ROLE_CARE_PARTNER_OUS = "CARE_PARTNER_OUS"; + public static final String ROLE_CARE_PATIENT_US = "CARE_PARTNER"; + public static final String ROLE_CARE_PATIENT_OUS = "CARE_PARTNER_OUS"; + public static final String USER_ROLE_CARE_PARTNER = "carepartner"; + public static final String USER_ROLE_PATIENT = "patient"; + + public Date loginDateUTC; + public String id; + public String country; + public String language; + public String lastName; + public String firstName; + public Integer accountId; + public String role; + public String cpRegistrationStatus; + public String accountSuspended; + public boolean needToReconsent; + public boolean mfaRequired; + public boolean mfaEnabled; + + public boolean isCarePartner() { + return (this.role.equals(ROLE_CARE_PARTNER_US) || this.role.equals(ROLE_CARE_PARTNER_OUS)); + } + + public String getUserRole() { + if (isCarePartner()) + return USER_ROLE_CARE_PARTNER; + else + return USER_ROLE_PATIENT; + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/dex/BlueTails.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/dex/BlueTails.java index a454537994..9e4adb46f1 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/dex/BlueTails.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/dex/BlueTails.java @@ -1,9 +1,11 @@ package com.eveningoutpost.dexdrip.cgm.dex; -import static com.eveningoutpost.dexdrip.G5Model.BluetoothServices.Control; -import static com.eveningoutpost.dexdrip.G5Model.BluetoothServices.ProbablyBackfill; +import static com.eveningoutpost.dexdrip.g5model.BluetoothServices.Control; +import static com.eveningoutpost.dexdrip.g5model.BluetoothServices.ProbablyBackfill; import static com.eveningoutpost.dexdrip.cgm.dex.ClassifierAction.BACKFILL; +import static com.eveningoutpost.dexdrip.cgm.dex.ClassifierAction.CONNECT; import static com.eveningoutpost.dexdrip.cgm.dex.ClassifierAction.CONTROL; +import static com.eveningoutpost.dexdrip.cgm.dex.ClassifierAction.action; import static com.eveningoutpost.dexdrip.cgm.dex.ClassifierAction.lastReadingTimestamp; import android.bluetooth.BluetoothAdapter; @@ -15,9 +17,9 @@ import android.content.Context; import android.os.Bundle; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.bt.BtCallBack3; import com.eveningoutpost.dexdrip.utils.bt.ConnectReceiver; import com.eveningoutpost.dexdrip.xdrip; @@ -44,7 +46,7 @@ public class BlueTails extends BluetoothGattCallback implements BtCallBack3 { private BluetoothManager mBluetoothManager; private BluetoothAdapter mBluetoothAdapter; - + private final byte[] EMPTY_PAYLOAD = new byte[1]; private final HashMap characteristics = new HashMap<>(); { @@ -102,6 +104,7 @@ public void onConnectionStateChange(final BluetoothGatt gatt, final int status, if (newState == STATE_CONNECTED) { gatt.discoverServices(); + action(CONNECT, EMPTY_PAYLOAD); } if (newState == STATE_DISCONNECTED) { gatt.close(); @@ -139,7 +142,7 @@ public synchronized void onCharacteristicChanged(final BluetoothGatt gatt, final val achar = characteristics.get(characteristic.getUuid()); if (achar != null) { - ClassifierAction.action(achar.action, bytes); + action(achar.action, bytes); } else { UserError.Log.wtf(TAG, "Got onCharacteristicChanged for something we don't know about: " + characteristic.getUuid()); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/dex/ClassifierAction.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/dex/ClassifierAction.java index e06b32531a..ff380e2bc7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/dex/ClassifierAction.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/dex/ClassifierAction.java @@ -1,18 +1,18 @@ package com.eveningoutpost.dexdrip.cgm.dex; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.HOUR_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.HOUR_IN_MS; -import com.eveningoutpost.dexdrip.G5Model.BackFillRxMessage; -import com.eveningoutpost.dexdrip.G5Model.BackFillStream; -import com.eveningoutpost.dexdrip.G5Model.BaseGlucoseRxMessage; -import com.eveningoutpost.dexdrip.G5Model.DexTimeKeeper; -import com.eveningoutpost.dexdrip.G5Model.GlucoseRxMessage; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; +import com.eveningoutpost.dexdrip.g5model.BackFillRxMessage; +import com.eveningoutpost.dexdrip.g5model.BackFillStream; +import com.eveningoutpost.dexdrip.g5model.BaseGlucoseRxMessage; +import com.eveningoutpost.dexdrip.g5model.DexTimeKeeper; +import com.eveningoutpost.dexdrip.g5model.GlucoseRxMessage; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; import com.eveningoutpost.dexdrip.cgm.dex.g7.BackfillControlRx; import com.eveningoutpost.dexdrip.cgm.dex.g7.EGlucoseRxMessage; import com.eveningoutpost.dexdrip.utils.DexCollectionType; @@ -26,6 +26,7 @@ public class ClassifierAction { private static final String TAG = ClassifierAction.class.getSimpleName(); + static final String CONNECT = "connect"; static final String BACKFILL = "backfill"; static final String CONTROL = "control"; static final String TXID = "UIUIUI"; @@ -35,8 +36,14 @@ public class ClassifierAction { public static void action(final String type, final byte[] data) { if (data == null || data.length == 0) return; - + UserError.Log.d(TAG, "Type: " + type + " hex: " + JoH.bytesToHex(data)); switch (type) { + + case CONNECT: + UserError.Log.d(TAG, "Connect"); + stream.reset(); + break; + case BACKFILL: stream.pushNew(data); UserError.Log.d(TAG, "Added backfill cache: " + JoH.bytesToHex(data)); @@ -46,7 +53,6 @@ public static void action(final String type, final byte[] data) { val g7EGlucose = new EGlucoseRxMessage(data); if (g7EGlucose.isValid()) { DexTimeKeeper.updateAge(TXID, (int) g7EGlucose.clock); - stream.reset(); UserError.Log.d(TAG, "Got valid glucose: " + g7EGlucose); if (g7EGlucose.usable()) { lastReadingTimestamp = g7EGlucose.timestamp; @@ -80,11 +86,11 @@ public static void action(final String type, final byte[] data) { } else { BaseGlucoseRxMessage glucose = new GlucoseRxMessage(data); if (!glucose.usable()) { - glucose = new com.eveningoutpost.dexdrip.G5Model.EGlucoseRxMessage(data); + glucose = new com.eveningoutpost.dexdrip.g5model.EGlucoseRxMessage(data); } if (glucose.usable()) { + UserError.Log.d(TAG, "Updating age from timestamp: " + glucose.timestamp); DexTimeKeeper.updateAge(TXID, glucose.timestamp); - stream.reset(); val ts = DexTimeKeeper.fromDexTime(TXID, glucose.timestamp); lastReadingTimestamp = ts; if (BgReading.getForPreciseTimestamp(ts, DexCollectionType.getCurrentDeduplicationPeriod(), false) == null) { @@ -112,6 +118,7 @@ public static void action(final String type, final byte[] data) { private static void processBackfill() { UserError.Log.d(TAG, "Processing backfill"); val decoded = stream.decode(); + stream.reset(); for (BackFillStream.Backsie backsie : decoded) { UserError.Log.d(TAG, "Backsie: " + backsie.getDextime()); val time = DexTimeKeeper.fromDexTime(TXID, backsie.getDextime()); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/dex/g7/EGlucoseRxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/dex/g7/EGlucoseRxMessage.java index 105900456d..12d50c31cb 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/dex/g7/EGlucoseRxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/dex/g7/EGlucoseRxMessage.java @@ -1,9 +1,9 @@ package com.eveningoutpost.dexdrip.cgm.dex.g7; -import com.eveningoutpost.dexdrip.G5Model.CalibrationState; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.g5model.CalibrationState; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/BackfillAssessor.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/BackfillAssessor.java index f36d88ab98..a38170b097 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/BackfillAssessor.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/BackfillAssessor.java @@ -2,18 +2,18 @@ import android.util.Pair; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import java.util.List; import lombok.Setter; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder.DEXCOM_PERIOD; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.HOUR_IN_MS; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder.DEXCOM_PERIOD; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.HOUR_IN_MS; /** * jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/Medtrum.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/Medtrum.java index b63a93f32b..389194880c 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/Medtrum.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/Medtrum.java @@ -8,12 +8,12 @@ import android.util.Pair; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.cgm.medtrum.messages.AdvertRx; import com.eveningoutpost.dexdrip.cgm.medtrum.messages.AnnexARx; import com.eveningoutpost.dexdrip.utils.DexCollectionType; @@ -22,7 +22,7 @@ import lombok.Getter; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; import static com.eveningoutpost.dexdrip.cgm.medtrum.Const.MANUFACTURER_ID; import static com.eveningoutpost.dexdrip.cgm.medtrum.Const.SUPPORTED_DEVICES; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/MedtrumCollectionService.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/MedtrumCollectionService.java index fa01b94249..95ef929401 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/MedtrumCollectionService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/MedtrumCollectionService.java @@ -9,22 +9,22 @@ import android.util.Pair; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Prediction; -import com.eveningoutpost.dexdrip.Models.TransmitterData; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.ActiveBluetoothDevice; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Prediction; +import com.eveningoutpost.dexdrip.models.TransmitterData; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.JamBaseBluetoothService; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.RxBleProvider; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; +import com.eveningoutpost.dexdrip.services.JamBaseBluetoothService; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.RxBleProvider; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; import com.eveningoutpost.dexdrip.cgm.medtrum.messages.AnnexARx; import com.eveningoutpost.dexdrip.cgm.medtrum.messages.AuthRx; import com.eveningoutpost.dexdrip.cgm.medtrum.messages.AuthTx; @@ -59,24 +59,21 @@ //import rx.Subscription; //import rx.schedulers.Schedulers; -import io.reactivex.Observable; -import io.reactivex.Scheduler; -import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; -import static com.eveningoutpost.dexdrip.Models.BgReading.bgReadingInsertMedtrum; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.Models.JoH.msTill; -import static com.eveningoutpost.dexdrip.Models.JoH.quietratelimit; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.HOUR_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.MEDTRUM_SERVICE_FAILOVER_ID; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.MEDTRUM_SERVICE_RETRY_ID; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.MINUTE_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.BAD; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.CRITICAL; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.GOOD; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.NORMAL; +import static com.eveningoutpost.dexdrip.models.BgReading.bgReadingInsertMedtrum; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.msTill; +import static com.eveningoutpost.dexdrip.models.JoH.quietratelimit; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.HOUR_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MEDTRUM_SERVICE_FAILOVER_ID; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MEDTRUM_SERVICE_RETRY_ID; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.BAD; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.CRITICAL; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.GOOD; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.NORMAL; import static com.eveningoutpost.dexdrip.cgm.medtrum.Const.CGM_CHARACTERISTIC_INDICATE; import static com.eveningoutpost.dexdrip.cgm.medtrum.Const.OPCODE_AUTH_REPLY; import static com.eveningoutpost.dexdrip.cgm.medtrum.Const.OPCODE_BACK_REPLY; @@ -884,7 +881,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { if (wakeup_jitter > 1000) { UserError.Log.d(TAG, "Wake up, time jitter: " + JoH.niceTimeScalar(wakeup_jitter)); if ((wakeup_jitter > TOLERABLE_JITTER) && (!JoH.buggy_samsung) && JoH.isSamsung()) { - UserError.Log.wtf(TAG, "Enabled Buggy Samsung workaround due to jitter of: " + JoH.niceTimeScalar(wakeup_jitter)); + UserError.Log.wtf(TAG, "Enabled wake workaround due to jitter of: " + JoH.niceTimeScalar(wakeup_jitter)); JoH.buggy_samsung = true; PersistentStore.incrementLong(BUGGY_SAMSUNG_ENABLED); max_wakeup_jitter = 0; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/Scanner.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/Scanner.java index 328eece401..c99c5a4664 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/Scanner.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/Scanner.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.cgm.medtrum; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.utils.bt.ScanMeister; import com.polidea.rxandroidble2.scan.ScanResult; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/TimeKeeper.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/TimeKeeper.java index 7d8ca3edd9..08776d8fe8 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/TimeKeeper.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/TimeKeeper.java @@ -1,10 +1,10 @@ package com.eveningoutpost.dexdrip.cgm.medtrum; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.MINUTE_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS; /** * JamOrHam diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/AdvertRx.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/AdvertRx.java index 1265c311e1..8b1aed41d8 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/AdvertRx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/AdvertRx.java @@ -2,8 +2,8 @@ // jamorham -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.cgm.medtrum.Crypt; import com.eveningoutpost.dexdrip.cgm.medtrum.DeviceType; import com.eveningoutpost.dexdrip.cgm.medtrum.Medtrum; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/AnnexARx.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/AnnexARx.java index 35dec1e10f..d71340c32d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/AnnexARx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/AnnexARx.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip.cgm.medtrum.messages; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import com.eveningoutpost.dexdrip.cgm.medtrum.SensorState; import com.eveningoutpost.dexdrip.cgm.medtrum.TimeKeeper; import com.google.gson.annotations.Expose; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/AuthTx.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/AuthTx.java index 99f65666c9..c91fe1d911 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/AuthTx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/AuthTx.java @@ -1,10 +1,10 @@ package com.eveningoutpost.dexdrip.cgm.medtrum.messages; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.cgm.medtrum.Crypt; import com.eveningoutpost.dexdrip.cgm.medtrum.Medtrum; -import static com.eveningoutpost.dexdrip.Models.JoH.tolerantHexStringToByteArray; +import static com.eveningoutpost.dexdrip.models.JoH.tolerantHexStringToByteArray; import static com.eveningoutpost.dexdrip.cgm.medtrum.Const.OPCODE_AUTH_REQST; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/BackFillRx.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/BackFillRx.java index 4afc5e86e2..b162a1dd9a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/BackFillRx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/BackFillRx.java @@ -2,7 +2,7 @@ // jamorham -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.google.gson.annotations.Expose; import java.nio.BufferUnderflowException; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/BaseMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/BaseMessage.java index 9abde55fbd..7458550a10 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/BaseMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/BaseMessage.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.cgm.medtrum.messages; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.cgm.medtrum.Const; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/InboundStream.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/InboundStream.java index dc186cb75e..c5ccda7479 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/InboundStream.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/InboundStream.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.cgm.medtrum.messages; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/TimeTx.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/TimeTx.java index e6fe1ce56f..02fb2a833b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/TimeTx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/medtrum/messages/TimeTx.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.cgm.medtrum.messages; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import java.util.Calendar; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/BaseCallback.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/BaseCallback.java index 4e883516fd..e932b4a6cf 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/BaseCallback.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/BaseCallback.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.cgm.nsfollow; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.store.FastStore; import lombok.RequiredArgsConstructor; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/EntryProcessor.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/EntryProcessor.java index 2acb4f5a53..0ed4374d3d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/EntryProcessor.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/EntryProcessor.java @@ -1,16 +1,16 @@ package com.eveningoutpost.dexdrip.cgm.nsfollow; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Unitized; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Unitized; import com.eveningoutpost.dexdrip.cgm.nsfollow.messages.Entry; import java.util.List; import java.util.UUID; -import static com.eveningoutpost.dexdrip.Models.BgReading.SPECIAL_FOLLOWER_PLACEHOLDER; +import static com.eveningoutpost.dexdrip.models.BgReading.SPECIAL_FOLLOWER_PLACEHOLDER; /** * jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/NightscoutFollow.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/NightscoutFollow.java index 0dba1ab025..eb3944db37 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/NightscoutFollow.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/NightscoutFollow.java @@ -1,12 +1,12 @@ package com.eveningoutpost.dexdrip.cgm.nsfollow; import com.eveningoutpost.dexdrip.BuildConfig; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.NightscoutTreatments; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.NightscoutTreatments; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.cgm.nsfollow.messages.Entry; import com.eveningoutpost.dexdrip.cgm.nsfollow.utils.NightscoutUrl; import com.eveningoutpost.dexdrip.evaluators.MissedReadingsEstimator; @@ -35,9 +35,9 @@ import retrofit2.http.Headers; import retrofit2.http.Query; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; -import static com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder.DEXCOM_PERIOD; -import static com.eveningoutpost.dexdrip.UtilityModels.OkHttpWrapper.enableTls12OnPreLollipop; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder.DEXCOM_PERIOD; +import static com.eveningoutpost.dexdrip.utilitymodels.OkHttpWrapper.enableTls12OnPreLollipop; import static com.eveningoutpost.dexdrip.cgm.nsfollow.NightscoutFollowService.msg; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/NightscoutFollowService.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/NightscoutFollowService.java index fa13801558..720182618b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/NightscoutFollowService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/NightscoutFollowService.java @@ -3,18 +3,19 @@ import android.content.Intent; import android.os.IBinder; import android.os.PowerManager; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import android.text.SpannableString; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight; import com.eveningoutpost.dexdrip.cgm.nsfollow.utils.Anticipate; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.utils.framework.BuggySamsung; @@ -27,7 +28,7 @@ import java.util.ArrayList; import java.util.List; -import static com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder.DEXCOM_PERIOD; +import static com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder.DEXCOM_PERIOD; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.NSFollow; import static com.eveningoutpost.dexdrip.xdrip.gs; @@ -146,6 +147,7 @@ private static boolean shouldServiceRun() { */ public static List megaStatus() { final BgReading lastBg = BgReading.lastNoSenssor(); + final long lag = Constants.SECOND_IN_MS * Pref.getStringToInt("nsfollow_lag", 0); // Wake delay selected by user String lastPollText = "n/a"; if (lastPoll > 0) { @@ -159,10 +161,10 @@ public static List megaStatus() { Highlight ageOfLastBgPollHighlight = Highlight.NORMAL; if (bgReceiveDelay > 0) { ageOfBgLastPoll = JoH.niceTimeScalar(bgReceiveDelay); - if (bgReceiveDelay > SAMPLE_PERIOD / 2) { + if (bgReceiveDelay - lag > SAMPLE_PERIOD / 2) { ageOfLastBgPollHighlight = Highlight.BAD; } - if (bgReceiveDelay > SAMPLE_PERIOD * 2) { + if (bgReceiveDelay - lag > SAMPLE_PERIOD * 2) { ageOfLastBgPollHighlight = Highlight.CRITICAL; } } @@ -173,7 +175,7 @@ public static List megaStatus() { if (lastBg != null) { long age = JoH.msSince(lastBg.timestamp); ageLastBg = JoH.niceTimeScalar(age); - if (age > SAMPLE_PERIOD + hightlightGrace) { + if (age > SAMPLE_PERIOD + hightlightGrace + lag) { bgAgeHighlight = Highlight.BAD; } } @@ -207,7 +209,7 @@ public static List megaStatus() { } statuses.add(new StatusItem("Next poll time", JoH.dateTimeText(wakeup_time))); statuses.add(new StatusItem()); - statuses.add(new StatusItem("Buggy Samsung", JoH.buggy_samsung ? gs(R.string.yes) : gs(R.string.no))); + statuses.add(new StatusItem("Buggy handset", JoH.buggy_samsung ? gs(R.string.yes) : gs(R.string.no))); statuses.add(new StatusItem("Download treatments", NightscoutFollow.treatmentDownloadEnabled() ? gs(R.string.yes) : gs(R.string.no))); if (StringUtils.isNotBlank(lastState)) { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/messages/BaseMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/messages/BaseMessage.java index 8970092d82..213ab6c2ae 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/messages/BaseMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/messages/BaseMessage.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.cgm.nsfollow.messages; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import okhttp3.MediaType; import okhttp3.RequestBody; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/messages/Entry.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/messages/Entry.java index ff44e6c43b..c509bc0b59 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/messages/Entry.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/messages/Entry.java @@ -4,7 +4,7 @@ // Nightscout Entry data item -import com.eveningoutpost.dexdrip.Models.DateUtil; +import com.eveningoutpost.dexdrip.models.DateUtil; import com.google.gson.annotations.Expose; import java.util.Date; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/utils/Anticipate.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/utils/Anticipate.java index 7a94d455b5..426bf0c629 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/utils/Anticipate.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/utils/Anticipate.java @@ -1,5 +1,8 @@ package com.eveningoutpost.dexdrip.cgm.nsfollow.utils; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; + /** * Choose optimum anticipation times for re-attempting data collection to minimize * number of requests to nightscout but at the same time reduce latency from new @@ -16,7 +19,10 @@ public class Anticipate { * If last + period and a bit < now, ask again after grace * If last + period and a bit >= now, ask again after last + period and grace */ - public static long next(long now, final long last, final long period, final long grace) { + + public static long next(long now, final long lastTimeStamp, final long period, final long grace) { + final long lag = Constants.SECOND_IN_MS * Pref.getStringToInt("nsfollow_lag", 0); // User can choose a wake delay with a 0 default. + final long last = lastTimeStamp + lag; // We delay the source timestamp and use it as the time we received the reading to account for any source delay. final long since = now - last; if (since <= (grace * 2)) { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/utils/NightscoutUrl.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/utils/NightscoutUrl.java index 31e28883f4..15b4fac717 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/utils/NightscoutUrl.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/nsfollow/utils/NightscoutUrl.java @@ -8,7 +8,7 @@ import lombok.RequiredArgsConstructor; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; /** * jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/EntryProcessor.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/EntryProcessor.java index 161de75ff1..264456f3df 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/EntryProcessor.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/EntryProcessor.java @@ -1,15 +1,15 @@ package com.eveningoutpost.dexdrip.cgm.sharefollow; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; import java.util.Collections; import java.util.List; import java.util.UUID; -import static com.eveningoutpost.dexdrip.Models.BgReading.SPECIAL_FOLLOWER_PLACEHOLDER; +import static com.eveningoutpost.dexdrip.models.BgReading.SPECIAL_FOLLOWER_PLACEHOLDER; /** * jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/RetrofitBase.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/RetrofitBase.java index 0bdd80d647..b8b4345a01 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/RetrofitBase.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/RetrofitBase.java @@ -1,9 +1,9 @@ package com.eveningoutpost.dexdrip.cgm.sharefollow; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.cgm.nsfollow.GzipRequestInterceptor; import com.eveningoutpost.dexdrip.tidepool.InfoInterceptor; import com.google.gson.Gson; @@ -20,8 +20,8 @@ import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; -import static com.eveningoutpost.dexdrip.UtilityModels.OkHttpWrapper.enableTls12OnPreLollipop; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.utilitymodels.OkHttpWrapper.enableTls12OnPreLollipop; /** * jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/Session.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/Session.java index eaef11db88..d3bce73211 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/Session.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/Session.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip.cgm.sharefollow; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; import java.io.IOException; import java.util.List; @@ -12,7 +12,7 @@ import lombok.Setter; import okhttp3.ResponseBody; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; import static com.eveningoutpost.dexdrip.cgm.sharefollow.ShareConstants.SESSION_ID_VALIDITY_TIME; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareErrorResponse.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareErrorResponse.java index 441b2e4d76..883c583010 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareErrorResponse.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareErrorResponse.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.cgm.sharefollow; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.xdrip; import com.google.gson.annotations.Expose; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareFollowDownload.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareFollowDownload.java index e33a8d1126..7b67c7a300 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareFollowDownload.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareFollowDownload.java @@ -2,11 +2,11 @@ import android.os.PowerManager; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; import com.eveningoutpost.dexdrip.evaluators.MissedReadingsEstimator; import com.eveningoutpost.dexdrip.xdrip; @@ -16,7 +16,7 @@ import lombok.Getter; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; import static com.eveningoutpost.dexdrip.cgm.sharefollow.ShareConstants.MAX_RECORDS_TO_ASK_FOR; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareFollowService.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareFollowService.java index dcc2845779..53bc57a08b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareFollowService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareFollowService.java @@ -3,17 +3,17 @@ import android.content.Intent; import android.os.IBinder; import android.os.PowerManager; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import android.text.SpannableString; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; import com.eveningoutpost.dexdrip.cgm.nsfollow.utils.Anticipate; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.utils.framework.BuggySamsung; @@ -24,9 +24,9 @@ import java.util.ArrayList; import java.util.List; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder.DEXCOM_PERIOD; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder.DEXCOM_PERIOD; import static com.eveningoutpost.dexdrip.cgm.sharefollow.ShareConstants.MAX_RECORDS_TO_ASK_FOR; import static com.eveningoutpost.dexdrip.cgm.sharefollow.ShareConstants.NON_US_SHARE_BASE_URL; import static com.eveningoutpost.dexdrip.cgm.sharefollow.ShareConstants.US_SHARE_BASE_URL; @@ -215,7 +215,7 @@ public static List megaStatus() { megaStatus.add(new StatusItem("Last BG time", JoH.dateTimeText(lastBg.timestamp))); } megaStatus.add(new StatusItem("Next poll time", JoH.dateTimeText(wakeup_time))); - megaStatus.add(new StatusItem("Buggy Samsung", JoH.buggy_samsung ? gs(R.string.yes) : gs(R.string.no))); + megaStatus.add(new StatusItem("Buggy handset", JoH.buggy_samsung ? gs(R.string.yes) : gs(R.string.no))); return megaStatus; } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareGlucoseRecord.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareGlucoseRecord.java index 5476810600..8c143e43dc 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareGlucoseRecord.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareGlucoseRecord.java @@ -1,9 +1,9 @@ package com.eveningoutpost.dexdrip.cgm.sharefollow; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Unitized; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Unitized; import com.google.gson.annotations.Expose; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareTrendDeserializer.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareTrendDeserializer.java index ae31f6fb26..2a157ca73b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareTrendDeserializer.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/sharefollow/ShareTrendDeserializer.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.cgm.sharefollow; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Cmd.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Cmd.java index 2aff12319b..ad85d086a3 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Cmd.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Cmd.java @@ -1,10 +1,10 @@ package com.eveningoutpost.dexdrip.cgm.webfollow; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; import static com.eveningoutpost.dexdrip.cgm.webfollow.Agent.get; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.cgm.medtrum.BackfillAssessor; import com.eveningoutpost.dexdrip.utils.DexCollectionType; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Cpref.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Cpref.java index a221eaaa7a..27d3d25082 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Cpref.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Cpref.java @@ -2,9 +2,9 @@ import android.content.SharedPreferences; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import lombok.val; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/MContext.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/MContext.java index 08af5df003..b12e5edc47 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/MContext.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/MContext.java @@ -1,9 +1,9 @@ package com.eveningoutpost.dexdrip.cgm.webfollow; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.xdrip; import com.google.gson.Gson; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/ResponseGetterImpl.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/ResponseGetterImpl.java index ee9730c6f3..e5d2e728ee 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/ResponseGetterImpl.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/ResponseGetterImpl.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.cgm.webfollow; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import java.io.IOException; import java.net.InetSocketAddress; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Template.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Template.java index be6a8b20fb..5c607d00a7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Template.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Template.java @@ -3,8 +3,8 @@ import static com.eveningoutpost.dexdrip.utils.DexCollectionType.Disabled; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.setDexCollectionType; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.google.common.primitives.Bytes; import java.io.IOException; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Verify.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Verify.java index 71583fec5c..506f4e4086 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Verify.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Verify.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip.cgm.webfollow; -import static com.eveningoutpost.dexdrip.Models.JoH.hexStringToByteArray; +import static com.eveningoutpost.dexdrip.models.JoH.hexStringToByteArray; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import java.security.KeyFactory; import java.security.PublicKey; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/WebFollowService.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/WebFollowService.java index fd7ca29237..e24e262401 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/WebFollowService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/WebFollowService.java @@ -1,25 +1,25 @@ package com.eveningoutpost.dexdrip.cgm.webfollow; -import static com.eveningoutpost.dexdrip.Models.JoH.clearRatelimit; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.clearRatelimit; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.WebFollow; import static com.eveningoutpost.dexdrip.xdrip.gs; import android.content.Intent; import android.os.IBinder; import android.os.PowerManager; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import android.text.SpannableString; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; import com.eveningoutpost.dexdrip.cgm.nsfollow.utils.Anticipate; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.utils.framework.BuggySamsung; @@ -232,7 +232,7 @@ public static List megaStatus() { megaStatus.add(new StatusItem("Next poll time", JoH.dateTimeText(wakeup_time))); if (JoH.buggy_samsung) { - megaStatus.add(new StatusItem("Buggy Samsung", JoH.buggy_samsung ? gs(R.string.yes) : gs(R.string.no))); + megaStatus.add(new StatusItem("Buggy handset", JoH.buggy_samsung ? gs(R.string.yes) : gs(R.string.no))); } if (lastErrorTime != 0L && (msSince(lastErrorTime) < Constants.HOUR_IN_MS)) { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/Backup.java b/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/Backup.java index ab0f55e814..e274021687 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/Backup.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/Backup.java @@ -3,11 +3,11 @@ import static android.provider.OpenableColumns.DISPLAY_NAME; import static android.provider.OpenableColumns.SIZE; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; -import static com.eveningoutpost.dexdrip.Models.JoH.getFieldFromURI; -import static com.eveningoutpost.dexdrip.Models.JoH.getLocalBluetoothName; -import static com.eveningoutpost.dexdrip.Models.JoH.hexStringToByteArray; -import static com.eveningoutpost.dexdrip.Models.JoH.readLine; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.getFieldFromURI; +import static com.eveningoutpost.dexdrip.models.JoH.getLocalBluetoothName; +import static com.eveningoutpost.dexdrip.models.JoH.hexStringToByteArray; +import static com.eveningoutpost.dexdrip.models.JoH.readLine; import static com.eveningoutpost.dexdrip.utils.SdcardImportExport.PREFERENCES_FILE; import static java.nio.file.StandardCopyOption.ATOMIC_MOVE; @@ -16,12 +16,12 @@ import android.util.Pair; import com.activeandroid.Configuration; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.CipherUtils; import com.eveningoutpost.dexdrip.utils.SdcardImportExport; import com.eveningoutpost.dexdrip.xdrip; @@ -62,6 +62,7 @@ public class Backup { private static final String TAG = "xDrip-Backup"; private static final String PREF_BACKUP_URI = "backup-document-uri"; public static final String PREF_AUTO_BACKUP = "backup-automatic-enabled"; + public static final String PREF_AUTO_BACKUP_MOBILE = "backup-automatic-mobile"; private static final String XDRIP_CONTENT_TYPE = "xDripBackup://"; private static final String[] dbSuffix = {"-journal", "-shm", "-wal"}; @@ -298,7 +299,7 @@ public static boolean isBackupSuitableForAutomatic() { public static void doCompleteBackupIfEnabled() { if (Pref.getBooleanDefaultFalse(PREF_AUTO_BACKUP) - && isBackupSuitableForAutomatic()) { + && isBackupSuitableForAutomatic() && ((Pref.getBoolean(PREF_AUTO_BACKUP_MOBILE, true)) || (JoH.isLANConnected()))) { UserError.Log.e(TAG, "Attempting automatic backup"); val success = doCompleteBackup(new LogStatus()); if (!success) { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/BackupActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/BackupActivity.java index 3e85124b6a..d648465277 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/BackupActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/BackupActivity.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.cloud.backup; -import static com.eveningoutpost.dexdrip.Models.JoH.showNotification; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.BACKUP_ACTIVITY_ID; +import static com.eveningoutpost.dexdrip.models.JoH.showNotification; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.BACKUP_ACTIVITY_ID; import static com.eveningoutpost.dexdrip.cloud.backup.Backup.cleanPhoneName; import static com.eveningoutpost.dexdrip.cloud.backup.Backup.isBackupSuitableForAutomatic; import static com.eveningoutpost.dexdrip.cloud.backup.DriveManager.BINARY_FILE_TYPE; @@ -9,16 +9,17 @@ import android.app.AlertDialog; import android.app.PendingIntent; import android.content.Intent; -import android.databinding.ObservableArrayMap; -import android.databinding.ObservableField; +import androidx.databinding.ObservableArrayMap; +import androidx.databinding.ObservableField; import android.net.Uri; import android.os.Bundle; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PrefsViewImpl; +import com.eveningoutpost.dexdrip.receiver.InfoContentProvider; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PrefsViewImpl; import com.eveningoutpost.dexdrip.databinding.ActivityBackupPickerBinding; import com.eveningoutpost.dexdrip.ui.dialog.GenericConfirmDialog; import com.eveningoutpost.dexdrip.xdrip; @@ -193,7 +194,7 @@ public synchronized void restoreNow() { status(getString(R.string.nothing_to_restore_please_select)); } else { Runnable restoreRunnable = () -> GenericConfirmDialog.show(BackupActivity.this, getString(R.string.are_you_really_sure_question), getString(R.string.restoring_backup_will_erase_warning), () -> restoreNowReal()); - if (metaData.sourceDevice.equals(cleanPhoneName())) { + if (metaData.sourceDevice != null && metaData.sourceDevice.equals(cleanPhoneName())) { restoreRunnable.run(); } else { GenericConfirmDialog.show(BackupActivity.this, getString(R.string.backup_source_confirm), getString(R.string.this_backup_looks_like_came_from_different_format_string, metaData.sourceDevice), restoreRunnable); @@ -212,6 +213,7 @@ private synchronized void restoreNowReal() { if (metaData.exception != null) { status(getString(R.string.error_exclamation) + " " + metaData.exception); } + InfoContentProvider.ping("pref"); } finally { idle.set(true); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/BackupBaseActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/BackupBaseActivity.java index a83be65848..ca0f1a546c 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/BackupBaseActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/BackupBaseActivity.java @@ -2,10 +2,12 @@ import android.content.Intent; -import android.support.v7.app.AppCompatActivity; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; + +import androidx.appcompat.app.AppCompatActivity; + +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; import com.google.android.gms.auth.api.signin.GoogleSignIn; import com.google.android.gms.auth.api.signin.GoogleSignInClient; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/BackupMetaData.java b/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/BackupMetaData.java index f75a5a2e1d..56f68beec1 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/BackupMetaData.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/BackupMetaData.java @@ -1,11 +1,11 @@ package com.eveningoutpost.dexdrip.cloud.backup; -import static com.eveningoutpost.dexdrip.Models.JoH.readLine; -import static com.eveningoutpost.dexdrip.Models.JoH.roundDouble; +import static com.eveningoutpost.dexdrip.models.JoH.readLine; +import static com.eveningoutpost.dexdrip.models.JoH.roundDouble; import static com.eveningoutpost.dexdrip.xdrip.gs; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; import java.io.IOException; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/DriveManager.java b/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/DriveManager.java index 5907e2d273..76b360b20e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/DriveManager.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/DriveManager.java @@ -1,9 +1,9 @@ package com.eveningoutpost.dexdrip.cloud.backup; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.xdrip; import com.google.android.gms.auth.api.signin.GoogleSignIn; import com.google.android.gms.common.Scopes; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/LogStatus.java b/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/LogStatus.java index f066838f31..86bf495bcb 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/LogStatus.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cloud/backup/LogStatus.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.cloud.backup; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; public class LogStatus implements BackupStatus { private static final String TAG = "Backup"; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/deposit/DepositActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/deposit/DepositActivity.java index 068e520305..90e9416374 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/deposit/DepositActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/deposit/DepositActivity.java @@ -1,23 +1,23 @@ package com.eveningoutpost.dexdrip.deposit; import android.app.Activity; -import android.databinding.Observable; -import android.databinding.ObservableField; +import androidx.databinding.Observable; +import androidx.databinding.ObservableField; import android.os.Build; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatActivity; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.PrefsViewImpl; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.PrefsViewImpl; import com.eveningoutpost.dexdrip.databinding.ActivityDepositActivityBinding; import com.eveningoutpost.dexdrip.ui.dialog.GenericConfirmDialog; -import android.support.annotation.RequiresApi; +import androidx.annotation.RequiresApi; import lombok.RequiredArgsConstructor; -import static com.eveningoutpost.dexdrip.Models.JoH.tsl; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; import static com.eveningoutpost.dexdrip.deposit.WebDeposit.getSerialInfo; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/deposit/DepositCallback.java b/app/src/main/java/com/eveningoutpost/dexdrip/deposit/DepositCallback.java index dff669a9c4..abb8b292fa 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/deposit/DepositCallback.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/deposit/DepositCallback.java @@ -2,10 +2,10 @@ import android.os.Build; -import android.support.annotation.NonNull; -import android.support.annotation.RequiresApi; +import androidx.annotation.NonNull; +import androidx.annotation.RequiresApi; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import lombok.RequiredArgsConstructor; import lombok.var; @@ -43,7 +43,7 @@ DepositCallback setOnStatus(final F runnable) { @Override public void onResponse(@NonNull Call call, Response response) { if (response.isSuccessful() && response.body() != null) { - var msg = "Error"; + String msg = "Error"; if (response.body() instanceof DepositReply1) { msg = ((DepositReply1) response.body()).result; } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/deposit/DepositReply1.java b/app/src/main/java/com/eveningoutpost/dexdrip/deposit/DepositReply1.java index b71aa94e7c..9fc12ef64f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/deposit/DepositReply1.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/deposit/DepositReply1.java @@ -2,7 +2,7 @@ // jamorham -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/deposit/F.java b/app/src/main/java/com/eveningoutpost/dexdrip/deposit/F.java index 4c57e59526..f0ee4e1679 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/deposit/F.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/deposit/F.java @@ -4,7 +4,7 @@ import java.util.function.Consumer; -import android.support.annotation.RequiresApi; +import androidx.annotation.RequiresApi; @RequiresApi(api = Build.VERSION_CODES.N) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/deposit/ReadingsToJson.java b/app/src/main/java/com/eveningoutpost/dexdrip/deposit/ReadingsToJson.java index 2b5383fe8c..cb346b1266 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/deposit/ReadingsToJson.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/deposit/ReadingsToJson.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.deposit; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.UserError; import org.json.JSONArray; import org.json.JSONException; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/deposit/TreatmentsToJson.java b/app/src/main/java/com/eveningoutpost/dexdrip/deposit/TreatmentsToJson.java index 61e45dccc1..cf12221542 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/deposit/TreatmentsToJson.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/deposit/TreatmentsToJson.java @@ -1,9 +1,9 @@ package com.eveningoutpost.dexdrip.deposit; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.profileeditor.BasalProfile; import org.json.JSONArray; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/deposit/WebDeposit.java b/app/src/main/java/com/eveningoutpost/dexdrip/deposit/WebDeposit.java index 87a417a78a..05e036de54 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/deposit/WebDeposit.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/deposit/WebDeposit.java @@ -5,16 +5,16 @@ import android.os.PowerManager; import com.eveningoutpost.dexdrip.BuildConfig; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.tidepool.InfoInterceptor; import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeUnit; -import android.support.annotation.RequiresApi; +import androidx.annotation.RequiresApi; import org.json.JSONArray; import lombok.val; import okhttp3.MediaType; @@ -30,7 +30,7 @@ import retrofit2.http.POST; import retrofit2.http.Path; -import static com.eveningoutpost.dexdrip.UtilityModels.OkHttpWrapper.enableTls12OnPreLollipop; +import static com.eveningoutpost.dexdrip.utilitymodels.OkHttpWrapper.enableTls12OnPreLollipop; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/eassist/AlertTracker.java b/app/src/main/java/com/eveningoutpost/dexdrip/eassist/AlertTracker.java index 89e7eef11b..5e8c1e1eff 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/eassist/AlertTracker.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/eassist/AlertTracker.java @@ -1,9 +1,16 @@ package com.eveningoutpost.dexdrip.eassist; +import static com.eveningoutpost.dexdrip.eassist.EmergencyAssist.Reason.DID_NOT_ACKNOWLEDGE_HIGH_ALERT; +import static com.eveningoutpost.dexdrip.eassist.EmergencyAssist.Reason.DID_NOT_ACKNOWLEDGE_LOWEST_ALERT; +import static com.eveningoutpost.dexdrip.eassist.EmergencyAssist.Reason.DID_NOT_ACKNOWLEDGE_LOW_ALERT; + import com.eveningoutpost.dexdrip.BestGlucose; -import com.eveningoutpost.dexdrip.Models.ActiveBgAlert; -import com.eveningoutpost.dexdrip.Models.AlertType; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.ActiveBgAlert; +import com.eveningoutpost.dexdrip.models.AlertType; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; + +import lombok.val; // jamorham @@ -29,10 +36,18 @@ public static void evaluate() { // } if (!type.above) { - EmergencyAssist.checkAndActivate(EmergencyAssist.Reason.DID_NOT_ACKNOWLEDGE_LOW_ALERT, - since, summary); + // Determine if is lowest alert + val lowest = AlertType.getLowestAlert(); + val thisAlertType = ActiveBgAlert.alertTypegetOnly(activeBgAlert); + if (lowest == null || thisAlertType == null + || lowest.threshold == thisAlertType.threshold) { + // Always flag as lowest unless we know it isn't + EmergencyAssist.checkAndActivate(DID_NOT_ACKNOWLEDGE_LOWEST_ALERT, since, summary); + } + + EmergencyAssist.checkAndActivate(DID_NOT_ACKNOWLEDGE_LOW_ALERT, since, summary); } else { - EmergencyAssist.checkAndActivate(EmergencyAssist.Reason.DID_NOT_ACKNOWLEDGE_HIGH_ALERT, + EmergencyAssist.checkAndActivate(DID_NOT_ACKNOWLEDGE_HIGH_ALERT, since, summary); } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/eassist/EmergencyAssist.java b/app/src/main/java/com/eveningoutpost/dexdrip/eassist/EmergencyAssist.java index c92ae88eed..4edcd8385b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/eassist/EmergencyAssist.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/eassist/EmergencyAssist.java @@ -1,14 +1,14 @@ package com.eveningoutpost.dexdrip.eassist; -import android.databinding.ObservableField; +import androidx.databinding.ObservableField; import android.os.PowerManager; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.SMS; import com.eveningoutpost.dexdrip.xdrip; @@ -28,6 +28,7 @@ public class EmergencyAssist { public static final String EMERGENCY_ASSIST_PREF = "emergency_assist_enabled"; public static final String EMERGENCY_LOW_MINS_PREF = "emergency_assist_low_alert_minutes"; + public static final String EMERGENCY_LOWEST_MINS_PREF = "emergency_assist_lowest_alert_minutes"; public static final String EMERGENCY_HIGH_MINS_PREF = "emergency_assist_high_alert_minutes"; private static final String TAG = EmergencyAssist.class.getSimpleName(); @@ -78,7 +79,8 @@ public static boolean isEnabled() { public static boolean isEnabled(Reason reason) { if (!isEnabled()) return false; switch (reason) { - + case DID_NOT_ACKNOWLEDGE_LOWEST_ALERT: + return Pref.getBooleanDefaultFalse("emergency_assist_lowest_alert"); case DID_NOT_ACKNOWLEDGE_LOW_ALERT: return Pref.getBooleanDefaultFalse("emergency_assist_low_alert"); case DID_NOT_ACKNOWLEDGE_HIGH_ALERT: @@ -110,6 +112,7 @@ public void setUsername(String value) { private static String getReasonText(Reason reason) { switch (reason) { + case DID_NOT_ACKNOWLEDGE_LOWEST_ALERT: case DID_NOT_ACKNOWLEDGE_LOW_ALERT: return getString(R.string.did_not_acknowledge_a_low_glucose_alert); case DID_NOT_ACKNOWLEDGE_HIGH_ALERT: @@ -137,6 +140,8 @@ private static long minutesToMs(String mins) { private static long timeThreshold(Reason reason) { switch (reason) { + case DID_NOT_ACKNOWLEDGE_LOWEST_ALERT: + return minutesToMs(Pref.getString(EMERGENCY_LOWEST_MINS_PREF, "60")); case DID_NOT_ACKNOWLEDGE_LOW_ALERT: return minutesToMs(Pref.getString(EMERGENCY_LOW_MINS_PREF, "60")); case DID_NOT_ACKNOWLEDGE_HIGH_ALERT: @@ -231,6 +236,7 @@ private static String getString(int id) { } public enum Reason { + DID_NOT_ACKNOWLEDGE_LOWEST_ALERT, DID_NOT_ACKNOWLEDGE_LOW_ALERT, DID_NOT_ACKNOWLEDGE_HIGH_ALERT, EXTENDED_MISSED_READINGS, diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/eassist/EmergencyAssistActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/eassist/EmergencyAssistActivity.java index cdc0af8179..977c855651 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/eassist/EmergencyAssistActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/eassist/EmergencyAssistActivity.java @@ -6,26 +6,26 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.database.Cursor; -import android.databinding.ObservableArrayList; -import android.databinding.ObservableList; +import androidx.databinding.ObservableArrayList; +import androidx.databinding.ObservableList; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.provider.ContactsContract; -import android.support.annotation.NonNull; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; +import androidx.annotation.NonNull; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; import android.view.View; import com.eveningoutpost.dexdrip.BR; import com.eveningoutpost.dexdrip.BaseAppCompatActivity; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PrefsViewImpl; -import com.eveningoutpost.dexdrip.UtilityModels.PrefsViewString; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PrefsViewImpl; +import com.eveningoutpost.dexdrip.utilitymodels.PrefsViewString; import com.eveningoutpost.dexdrip.databinding.ActivityEmergencyAssistBinding; import com.eveningoutpost.dexdrip.ui.dialog.GenericConfirmDialog; import com.eveningoutpost.dexdrip.utils.LocationHelper; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/eassist/EmergencyContact.java b/app/src/main/java/com/eveningoutpost/dexdrip/eassist/EmergencyContact.java index b900493206..fcabeb8edd 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/eassist/EmergencyContact.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/eassist/EmergencyContact.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.eassist; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.google.gson.annotations.Expose; import com.google.gson.reflect.TypeToken; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/eassist/GetLocation.java b/app/src/main/java/com/eveningoutpost/dexdrip/eassist/GetLocation.java index ccac535cb0..2b59e66f32 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/eassist/GetLocation.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/eassist/GetLocation.java @@ -8,11 +8,11 @@ import android.location.Geocoder; import android.location.Location; import android.os.Looper; -import android.support.v4.app.ActivityCompat; +import androidx.core.app.ActivityCompat; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; import com.eveningoutpost.dexdrip.xdrip; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.location.LocationCallback; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/evaluators/MissedReadingsEstimator.java b/app/src/main/java/com/eveningoutpost/dexdrip/evaluators/MissedReadingsEstimator.java index ee8a8aa0aa..c6a04ea41b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/evaluators/MissedReadingsEstimator.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/evaluators/MissedReadingsEstimator.java @@ -2,11 +2,11 @@ // jamorham -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; -import static com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder.DEXCOM_PERIOD; +import static com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder.DEXCOM_PERIOD; public class MissedReadingsEstimator { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/evaluators/PersistentHigh.java b/app/src/main/java/com/eveningoutpost/dexdrip/evaluators/PersistentHigh.java index 624eae47d2..0bc4ab48e5 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/evaluators/PersistentHigh.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/evaluators/PersistentHigh.java @@ -9,22 +9,22 @@ */ import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Notifications; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Notifications; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.xdrip; import java.util.Date; import java.util.List; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.Models.JoH.niceTimeScalar; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.MINUTE_IN_MS; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.niceTimeScalar; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS; public class PersistentHigh { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/g5model/AdvMatcher.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/AdvMatcher.java new file mode 100644 index 0000000000..39b6a0a70a --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/AdvMatcher.java @@ -0,0 +1,30 @@ +package com.eveningoutpost.dexdrip.g5model; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + + +/** + * JamOrHam + */ + +public class AdvMatcher extends BaseMessage { + + public byte[] check = new byte[2]; + public byte diu; + public byte ver; + + public boolean valid; + + public AdvMatcher(final byte[] packet) { + if (packet != null && packet.length >= 6) { + if (packet.length >= 19) { + data = ByteBuffer.wrap(packet).order(ByteOrder.LITTLE_ENDIAN); + data.get(check); + data.get(diu); + data.get(ver); + valid = true; + } + } + } +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/AuthChallengeRxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/AuthChallengeRxMessage.java similarity index 73% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/AuthChallengeRxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/AuthChallengeRxMessage.java index 952979352e..a23907c6a6 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/AuthChallengeRxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/AuthChallengeRxMessage.java @@ -1,10 +1,9 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.services.G5CollectionService; -import java.nio.ByteOrder; import java.util.Arrays; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/AuthChallengeTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/AuthChallengeTxMessage.java similarity index 63% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/AuthChallengeTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/AuthChallengeTxMessage.java index 846d06d738..a65da32dc3 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/AuthChallengeTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/AuthChallengeTxMessage.java @@ -1,11 +1,8 @@ -package com.eveningoutpost.dexdrip.G5Model; -import com.eveningoutpost.dexdrip.G5Model.TransmitterMessage; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; +package com.eveningoutpost.dexdrip.g5model; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import java.nio.ByteBuffer; -import java.nio.ByteOrder; /** * Created by joeginley on 3/16/16. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/AuthRequestTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/AuthRequestTxMessage.java similarity index 88% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/AuthRequestTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/AuthRequestTxMessage.java index cbfc88295a..d3bf1f2885 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/AuthRequestTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/AuthRequestTxMessage.java @@ -1,7 +1,7 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/AuthStatusRxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/AuthStatusRxMessage.java similarity index 83% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/AuthStatusRxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/AuthStatusRxMessage.java index f8116de8b4..9c24870228 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/AuthStatusRxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/AuthStatusRxMessage.java @@ -1,8 +1,7 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; +import com.eveningoutpost.dexdrip.models.UserError; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BackFillControlRxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BackFillControlRxMessage.java new file mode 100644 index 0000000000..1cd7d01554 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BackFillControlRxMessage.java @@ -0,0 +1,27 @@ +package com.eveningoutpost.dexdrip.g5model; + + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import lombok.Getter; + +/** + * JamOrHam + */ + +public class BackFillControlRxMessage extends BaseMessage { + + public static final byte opcode = 0x59; + @Getter + private boolean valid; + + public BackFillControlRxMessage(final byte[] packet) { + data = ByteBuffer.wrap(packet).order(ByteOrder.LITTLE_ENDIAN); + if ((data.get() == opcode)) { + valid = true; + // TODO more to parse here + } + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BackFillRxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BackFillRxMessage.java similarity index 94% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BackFillRxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/BackFillRxMessage.java index ecf13e83e5..dbfbca004d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BackFillRxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BackFillRxMessage.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BackFillStream.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BackFillStream.java similarity index 83% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BackFillStream.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/BackFillStream.java index 9846cd8393..6b07390f72 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BackFillStream.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BackFillStream.java @@ -1,12 +1,12 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; // created by jamorham -import static com.eveningoutpost.dexdrip.G5Model.DexTimeKeeper.fromDexTimeCached; +import static com.eveningoutpost.dexdrip.g5model.DexTimeKeeper.fromDexTimeCached; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; @@ -20,10 +20,10 @@ public class BackFillStream extends BaseMessage { private volatile int last_sequence = 0; - + private volatile boolean locked = false; public BackFillStream() { - data = ByteBuffer.allocate(1000); + data = ByteBuffer.allocate(2800); data.order(ByteOrder.LITTLE_ENDIAN); } @@ -48,10 +48,23 @@ public synchronized void push(byte[] packet) { public synchronized void pushNew(final byte[] packet) { if (packet == null) return; + if (locked) { + UserError.Log.d(TAG, "Locked stream so ignoring"); + return; + } if (packet.length == 9) { last_sequence = -1; data.put(packet); } else { + if (last_sequence == 0) { + if (packet.length > 17) { + if (packet[5] != 0x00 || packet[9] != 0x00 || packet[17] != 0x00) { + UserError.Log.d(TAG, "Non backfill data received - locking stream"); + locked = true; + return; + } + } + } push(packet); } } @@ -59,6 +72,7 @@ public synchronized void pushNew(final byte[] packet) { public void reset() { data.clear(); last_sequence = 0; + locked = false; } diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/BackFillTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BackFillTxMessage.java similarity index 82% rename from wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/BackFillTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/BackFillTxMessage.java index ceee90794e..69eee55a40 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/BackFillTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BackFillTxMessage.java @@ -1,9 +1,9 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; -import static com.eveningoutpost.dexdrip.G5Model.DexTimeKeeper.getDexTime; +import static com.eveningoutpost.dexdrip.g5model.DexTimeKeeper.getDexTime; // created by jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BackFillTxMessage2.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BackFillTxMessage2.java new file mode 100644 index 0000000000..f2894eb8e1 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BackFillTxMessage2.java @@ -0,0 +1,35 @@ +package com.eveningoutpost.dexdrip.g5model; + +import static com.eveningoutpost.dexdrip.g5model.DexTimeKeeper.getDexTime; + +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; + +/** + * JamOrHam + */ + +public class BackFillTxMessage2 extends BaseMessage { + + final byte opcode = 0x59; + final int length = 9; + + public BackFillTxMessage2(final int startDexTime, final int endDexTime) { + init(opcode, length); + data.putInt(startDexTime); + data.putInt(endDexTime); + getByteSequence(); + UserError.Log.d(TAG, "BackfillTxMessage2 dbg: " + JoH.bytesToHex(byteSequence)); + } + + public static BackFillTxMessage2 get(final String id, final long startTime, final long endTime) { + final int dexStart = getDexTime(id, startTime); + final int dexEnd = getDexTime(id, endTime); + if (dexStart < 1 || dexEnd < 1) { + UserError.Log.e(TAG, "Unable to calculate start or end time for BackFillTxMessage2"); + return null; + } + return new BackFillTxMessage2(dexStart, dexEnd); + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BaseAuthChallengeTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BaseAuthChallengeTxMessage.java similarity index 71% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BaseAuthChallengeTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/BaseAuthChallengeTxMessage.java index 7b7112e3d4..010745aa54 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BaseAuthChallengeTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BaseAuthChallengeTxMessage.java @@ -1,7 +1,7 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BaseGlucoseRxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BaseGlucoseRxMessage.java similarity index 81% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BaseGlucoseRxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/BaseGlucoseRxMessage.java index eaedf7dc3b..b39e37f42e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BaseGlucoseRxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BaseGlucoseRxMessage.java @@ -1,6 +1,7 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.services.G5CollectionService; import lombok.NoArgsConstructor; @@ -50,4 +51,9 @@ public Integer getPredictedGlucose() { return null; // stub } + public long getRealTimestamp() { + return JoH.tsl(); // default behavior is received now + } + + } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BaseMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BaseMessage.java similarity index 80% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BaseMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/BaseMessage.java index 498e588314..68d2d3283f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BaseMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BaseMessage.java @@ -1,7 +1,7 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.services.G5CollectionService; import com.google.gson.annotations.Expose; import java.nio.ByteBuffer; @@ -21,7 +21,7 @@ public class BaseMessage { public volatile ByteBuffer data; - void init(final byte opcode, final int length) { + protected void init(final byte opcode, final int length) { data = ByteBuffer.allocate(length).order(ByteOrder.LITTLE_ENDIAN); data.put(opcode); if (length == 1) { @@ -74,6 +74,16 @@ static String dottedStringFromData(ByteBuffer data, int length) { return sb.toString(); } + static long longFromData(final ByteBuffer data, final int length) { + long result = 0; + int shift = 0; + for (int i = 0; i < length; i++) { + result += (((long) getUnsignedByte(data)) << shift); + shift += 8; + } + return result; + } + static int getUnixTime() { return (int) (JoH.tsl() / 1000); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BatteryInfoRxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BatteryInfoRxMessage.java similarity index 84% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BatteryInfoRxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/BatteryInfoRxMessage.java index 51ff9bc455..edafbb956f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BatteryInfoRxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BatteryInfoRxMessage.java @@ -1,12 +1,14 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.services.G5CollectionService; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.Locale; +import lombok.val; + /** * Created by jamorham on 25/11/2016. */ @@ -17,6 +19,7 @@ public class BatteryInfoRxMessage extends BaseMessage { private final static String TAG = G5CollectionService.TAG; // meh public static final byte opcode = 0x23; + public static final byte opcode2 = 0x22; public int status; public int voltagea; @@ -28,7 +31,8 @@ public class BatteryInfoRxMessage extends BaseMessage { public BatteryInfoRxMessage(byte[] packet) { if (packet.length >= 10) { data = ByteBuffer.wrap(packet).order(ByteOrder.LITTLE_ENDIAN); - if (data.get() == opcode) { + val oc = data.get(); + if (oc == opcode || oc == opcode2) { status = data.get(); voltagea = getUnsignedShort(data); voltageb = getUnsignedShort(data); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BatteryInfoTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BatteryInfoTxMessage.java similarity index 64% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BatteryInfoTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/BatteryInfoTxMessage.java index ad325c374c..1bf4be19c7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BatteryInfoTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BatteryInfoTxMessage.java @@ -1,8 +1,8 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.services.G5CollectionService; /** * Created by jamorham on 25/11/2016. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BluetoothServices.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BluetoothServices.java similarity index 90% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BluetoothServices.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/BluetoothServices.java index 1e77980c28..00fbfc1415 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BluetoothServices.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BluetoothServices.java @@ -1,6 +1,5 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import android.util.SparseArray; import java.util.HashMap; import java.util.UUID; @@ -25,6 +24,7 @@ public class BluetoothServices { public static final UUID Control = UUID.fromString("F8083534-849E-531C-C594-30F1F86A4EA5"); public static final UUID Authentication = UUID.fromString("F8083535-849E-531C-C594-30F1F86A4EA5"); public static final UUID ProbablyBackfill = UUID.fromString("F8083536-849E-531C-C594-30F1F86A4EA5"); + public static final UUID ExtraData = UUID.fromString("F8083538-849E-531C-C594-30F1F86A4EA5"); //ServiceBCharacteristicUUID public static final UUID CharacteristicE = UUID.fromString("F8084533-849E-531C-C594-30F1F86A4EA5"); @@ -33,6 +33,8 @@ public class BluetoothServices { //CharacteristicDescriptorUUID public static final UUID CharacteristicUpdateNotification = UUID.fromString("00002902-0000-1000-8000-00805F9B34FB"); + public static final UUID Mask16 = UUID.fromString("0000FFFF-0000-0000-0000-000000000000"); + private static final HashMap mapToName = new HashMap<>(); @@ -45,6 +47,7 @@ public class BluetoothServices { mapToName.put(Communication, "Communication"); mapToName.put(Control, "Control"); mapToName.put(Authentication, "Authentication"); + mapToName.put(ExtraData, "Extra Data"); mapToName.put(ProbablyBackfill, "ProbablyBackfill"); mapToName.put(CharacteristicE, "CharacteristicE"); mapToName.put(CharacteristicF, "CharacteristicF"); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BondRequestTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BondRequestTxMessage.java similarity index 80% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BondRequestTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/BondRequestTxMessage.java index 34c735f7bd..40d004d48b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/BondRequestTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/BondRequestTxMessage.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; // jamorham diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/CRC.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/CRC.java similarity index 85% rename from wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/CRC.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/CRC.java index b4eadfedb0..c928ae3d30 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/CRC.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/CRC.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.CRC16; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.CRC16; /** * Created by jcostik1 on 3/24/16. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/CalibrateRxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/CalibrateRxMessage.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/CalibrateRxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/CalibrateRxMessage.java index 96981546fa..fef1aa5e08 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/CalibrateRxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/CalibrateRxMessage.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; import com.eveningoutpost.dexdrip.R; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/CalibrateTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/CalibrateTxMessage.java similarity index 77% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/CalibrateTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/CalibrateTxMessage.java index f2abded7b9..be9a885715 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/CalibrateTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/CalibrateTxMessage.java @@ -1,10 +1,10 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; // created by jamorham -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; public class CalibrateTxMessage extends BaseMessage { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/CalibrationState.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/CalibrationState.java similarity index 89% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/CalibrationState.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/CalibrationState.java index 1887010a23..fb5a960f5b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/CalibrationState.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/CalibrationState.java @@ -1,15 +1,15 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; // created by jamorham import android.util.SparseArray; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.google.common.collect.ImmutableSet; import lombok.Getter; -import static com.eveningoutpost.dexdrip.Services.G5CollectionService.TAG; +import static com.eveningoutpost.dexdrip.services.G5CollectionService.TAG; public enum CalibrationState { @@ -38,6 +38,14 @@ public enum CalibrationState { SensorFailed5(0x14, "Sensor Failed 5"), SensorFailed6(0x15, "Sensor Failed 6"), SensorFailedStart(0x16, "Sensor Failed Start"), + SensorFailedStart2(0x17, "Sensor Failed Start 2"), + SensorExpired(0x18, "Sensor Expired"), + SensorFailed7(0x19, "Sensor Failed 7"), + SensorStopped2(0x1A, "Sensor Stopped 2"), + SensorFailed8(0x1B, "Sensor Failed 8"), + SensorFailed9(0x1C, "Sensor Failed 9"), + SensorFailed10(0x1D, "Sensor Failed 10"), + SensorFailed11(0x1E, "Sensor Failed 11"), SensorStarted(0xC1, "Sensor Started"), SensorStopped(0xC2, "Sensor Stopped"), CalibrationSent(0xC3, "Calibration Sent"); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/DexResetHelper.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/DexResetHelper.java similarity index 69% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/DexResetHelper.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/DexResetHelper.java index 690a0d5348..31c1189daa 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/DexResetHelper.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/DexResetHelper.java @@ -1,13 +1,13 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.CompatibleApps; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.CompatibleApps; -import static com.eveningoutpost.dexdrip.UtilityModels.CompatibleApps.createActionIntent; -import static com.eveningoutpost.dexdrip.UtilityModels.CompatibleApps.createChoiceIntent; -import static com.eveningoutpost.dexdrip.UtilityModels.CompatibleApps.showNotification; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.DEX_BASE_ID; +import static com.eveningoutpost.dexdrip.utilitymodels.CompatibleApps.createActionIntent; +import static com.eveningoutpost.dexdrip.utilitymodels.CompatibleApps.createChoiceIntent; +import static com.eveningoutpost.dexdrip.utilitymodels.CompatibleApps.showNotification; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.DEX_BASE_ID; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/DexSessionKeeper.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/DexSessionKeeper.java similarity index 80% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/DexSessionKeeper.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/DexSessionKeeper.java index c582850970..7d4a071d12 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/DexSessionKeeper.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/DexSessionKeeper.java @@ -1,8 +1,7 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; // jamorham @@ -20,11 +19,17 @@ public static long getWarmupPeriod() { return SensorDays.get().getWarmupMs(); // allow for variable warm up period } - public static void setStart(long when) { + public static void setStart(final long when) { // TODO sanity check PersistentStore.setLong(PREF_SESSION_START, when); } + public static void setStart(final Long when) { + if (when != null) { + setStart((long) when); + } + } + public static long getStart() { // value 0 == not started return PersistentStore.getLong(PREF_SESSION_START); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/DexSyncKeeper.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/DexSyncKeeper.java similarity index 73% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/DexSyncKeeper.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/DexSyncKeeper.java index 4f0f19780b..31e0c28b75 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/DexSyncKeeper.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/DexSyncKeeper.java @@ -1,13 +1,13 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; // jamorham -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; -import static com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder.DEXCOM_PERIOD; +import static com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder.DEXCOM_PERIOD; public class DexSyncKeeper { @@ -26,7 +26,7 @@ public static void store(final String transmitterId) { // store sync time public static void store(final String transmitterId, final long when) { - if ((transmitterId == null) || (transmitterId.length() != 6)) { + if ((transmitterId == null) || (transmitterId.length() < 4)) { UserError.Log.e(TAG, "Invalid dex transmitter in store: " + transmitterId); return; } @@ -36,10 +36,21 @@ public static void store(final String transmitterId, final long when) { return; } + PersistentStore.cleanupOld(DEX_SYNC_STORE); PersistentStore.setLong(DEX_SYNC_STORE + transmitterId, when); UserError.Log.d(TAG, "Sync time updated to: " + JoH.dateTimeText(when)); } + public static void store(final String transmitterId, final long when, final long last_conection_time, final long last_glucose_processed) { + final long latency = (last_glucose_processed - last_conection_time); + UserError.Log.d(TAG, "Update time from glucose rx glucose: " + JoH.dateTimeText(when) + " latency:" + latency + " ms"); + if (latency < 8000) { // roughly half preempt + store(transmitterId, when); + } else { + UserError.Log.e(TAG, "Refusing to update stored timestamp due to excessive processing latency: " + latency + "ms"); + } + } + public static void clear(final String transmitterId) { if (PersistentStore.getLong(DEX_SYNC_STORE + transmitterId) > 0) { UserError.Log.e(TAG, "Clearing stored timing sync information for: " + transmitterId); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/DexTimeKeeper.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/DexTimeKeeper.java similarity index 85% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/DexTimeKeeper.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/DexTimeKeeper.java index 4bef6b45b9..f45ff132f0 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/DexTimeKeeper.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/DexTimeKeeper.java @@ -1,10 +1,10 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.getTransmitterID; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.getTransmitterID; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; import lombok.val; @@ -29,17 +29,17 @@ public static void updateAge(final String transmitterId, final int dexTimeStamp) // update the activation time stored for a transmitter public static void updateAge(final String transmitterId, final int dexTimeStamp, final boolean absolute) { - if ((transmitterId == null) || (transmitterId.length() != 6 && transmitterId.length() != 17)) { + if ((transmitterId == null) || (transmitterId.length() != 6 && transmitterId.length() != 17 && transmitterId.length() != 4)) { UserError.Log.e(TAG, "Invalid dex transmitter in updateAge: " + transmitterId); return; } if (dexTimeStamp < 1) { UserError.Log.e(TAG, "Invalid dex timestamp in updateAge: " + dexTimeStamp); if (dexTimeStamp == 0 && absolute) { - if (FirmwareCapability.isTransmitterRawIncapable(getTransmitterID())) { // Firefly, which cannot be hard reset - UserError.Log.e(TAG, "Your transmitter clock has stopped or never started."); - } else { + if (FirmwareCapability.isTransmitterG5(getTransmitterID()) || FirmwareCapability.isTransmitterTimeTravelCapable(getTransmitterID()) || FirmwareCapability.isTransmitterModified(getTransmitterID())) { // Devices that can be hard reset only DexResetHelper.offer("Your transmitter clock has stopped or never started. Do you want to hard reset it?"); + } else { // Everything else - future devices will be here. If a future device can be hard reset, they should be added to the true (other) side. + UserError.Log.e(TAG, "Your transmitter clock has stopped or never started."); } } return; @@ -59,7 +59,7 @@ public static void updateAge(final String transmitterId, final int dexTimeStamp, public static int getDexTime(String transmitterId, long timestamp) { - if ((transmitterId == null) || (transmitterId.length() != 6 && transmitterId.length() != 17)) { + if ((transmitterId == null) || (transmitterId.length() != 6 && transmitterId.length() != 4 && transmitterId.length() != 17)) { UserError.Log.e(TAG, "Invalid dex transmitter in getDexTime: " + transmitterId); return -3; } @@ -86,13 +86,16 @@ public static int getDexTime(String transmitterId, long timestamp) { return (int) (ms_since / 1000L); } + public static long getTxStartTimestamp(String transmitterId) { + return PersistentStore.getLong(DEX_XMIT_START + transmitterId); + } + public static long fromDexTimeCached(int dexTimeStamp) { return fromDexTime(lastTransmitterId, dexTimeStamp); } - public static long fromDexTime(String transmitterId, int dexTimeStamp) { - if ((transmitterId == null) || (transmitterId.length() != 6)) { + if ((transmitterId == null) || (transmitterId.length() != 6 && transmitterId.length() != 4)) { UserError.Log.e(TAG, "Invalid dex transmitter in fromDexTime: " + transmitterId); return -3; } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/DisconnectTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/DisconnectTxMessage.java similarity index 68% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/DisconnectTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/DisconnectTxMessage.java index 8916813304..87296e21b1 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/DisconnectTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/DisconnectTxMessage.java @@ -1,8 +1,8 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.services.G5CollectionService; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/EGlucoseRxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/EGlucoseRxMessage.java similarity index 93% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/EGlucoseRxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/EGlucoseRxMessage.java index cf480f5fa1..e3f4465662 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/EGlucoseRxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/EGlucoseRxMessage.java @@ -1,8 +1,8 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/g5model/EGlucoseRxMessage2.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/EGlucoseRxMessage2.java new file mode 100644 index 0000000000..358b0766cb --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/EGlucoseRxMessage2.java @@ -0,0 +1,115 @@ +package com.eveningoutpost.dexdrip.g5model; + +import static com.eveningoutpost.dexdrip.models.JoH.tsl; + +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import lombok.Getter; +import lombok.val; + + +public class EGlucoseRxMessage2 extends BaseGlucoseRxMessage { + + private static final String TAG = EGlucoseRxMessage2.class.getSimpleName(); + public static final byte opcode = 0x4e; + + private Integer predicted_glucose; + + public int age; + public int info; + + @Getter + public boolean valid; + + /** + * JamOrHam + * + * @param packet + */ + + public EGlucoseRxMessage2(final byte[] packet) { + UserError.Log.d(TAG, "EGlucoseRX2 dbg: " + JoH.bytesToHex(packet)); + if (packet.length >= 19) { + data = ByteBuffer.wrap(packet).order(ByteOrder.LITTLE_ENDIAN); + if ((data.get() == opcode)) { + + status_raw = data.get(); + timestamp = (int) getUnsignedInt(data); + sequence = getUnsignedShort(data); + val bogus = getUnsignedShort(data); + + age = getUnsignedShort(data); + + //timestamp = JoH.tsl() - (age * Constants.SECOND_IN_MS); // TODO assumes processed now + + int glucoseBytes = data.getShort(); // check signed vs unsigned!! + glucoseIsDisplayOnly = (glucoseBytes & 0xf000) > 0; + glucose = glucoseBytes & 0xfff; + + state = data.get(); + trend = data.get(); + + if (glucose > 13) { + unfiltered = glucose * 1000; + filtered = glucose * 1000; + } else { + filtered = glucose; + unfiltered = glucose; + } + + predicted_glucose = data.getShort() & 0x03ff; // needs mask??? // remaining bits?? + if (predicted_glucose == 0x3FF) { + predicted_glucose = -1; // invalid + } + + info = getUnsignedByte(data); + + valid = true; // TODO + + UserError.Log.d(TAG, toString()); + + } + } else { + UserError.Log.d(TAG, "GlucoseRxMessage packet length received wrong: " + packet.length); + } + + } + + public Integer getPredictedGlucose() { + return predicted_glucose; + } + + public Long getRealSessionStartTime() { + if (calibrationState().sensorStarted() && timestamp > 0) { + return tsl() - (timestamp * Constants.SECOND_IN_MS); + } + return null; + } + + @Override + public long getRealTimestamp() { + return JoH.tsl() - (age * Constants.SECOND_IN_MS); + } + + public String getRealSessionStartTimeString() { + val t = getRealSessionStartTime(); + if (t != null) { + return JoH.dateTimeText(t); + } else { + return "N/A"; + } + } + + @Override + public String toString() { + return "EGlucoseRX2: seq:" + sequence + " ts:" + JoH.niceTimeScalar(timestamp * Constants.SECOND_IN_MS, 2) + " sg:" + glucose + " psg: " + predicted_glucose + " do:" + glucoseIsDisplayOnly + " sr:" + status_raw + " st:" + calibrationState() + " info:" + info + " tr:" + getTrend() + " age:" + age + " Start: " + getRealSessionStartTimeString(); + + } + +} + diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/g5model/EGlucoseTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/EGlucoseTxMessage.java new file mode 100644 index 0000000000..5e8ce2ee61 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/EGlucoseTxMessage.java @@ -0,0 +1,20 @@ +package com.eveningoutpost.dexdrip.g5model; + +/** + * JamOrHam + */ + + +public class EGlucoseTxMessage extends BaseMessage { + + final byte opcode = 0x4e; + + public EGlucoseTxMessage(final boolean small) { + init(opcode, small ? 1 : 3); + } + + public EGlucoseTxMessage() { + this(false); + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/ExtensionTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/ExtensionTxMessage.java similarity index 93% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/ExtensionTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/ExtensionTxMessage.java index f45bd2cd22..9a7333b8bb 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/ExtensionTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/ExtensionTxMessage.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; // jamorham diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/Extensions.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/Extensions.java similarity index 95% rename from wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/Extensions.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/Extensions.java index a5cfddca45..3fc84461f8 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/Extensions.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/Extensions.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; /** * Created by joeginley on 3/19/16. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/g5model/ExtraState.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/ExtraState.java new file mode 100644 index 0000000000..40743aa4d6 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/ExtraState.java @@ -0,0 +1,34 @@ +package com.eveningoutpost.dexdrip.g5model; + +import lombok.val; + +/** + * JamOrHam + */ + +public class ExtraState { + + boolean p; + boolean t; + boolean l; + boolean h; + boolean s; + boolean error; + + public static ExtraState parse(byte state) { + + val es = new ExtraState(); + es.p = (state & 0x01) != 0; + es.t = (state & 0x02) != 0; + es.l = (state & 0x04) != 0; + es.h = (state & 0x08) != 0; + es.s = (state & 0x10) != 0; + es.error = (state & 0x80) != 0; + return es; + } + + public static ExtraState parse(int state) { + return parse((byte) state); + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/F2DUnknownRxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/F2DUnknownRxMessage.java similarity index 81% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/F2DUnknownRxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/F2DUnknownRxMessage.java index 3d6b6e20d9..9336d3a64d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/F2DUnknownRxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/F2DUnknownRxMessage.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/FastCRC16.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/FastCRC16.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/FastCRC16.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/FastCRC16.java index ff5193f46d..fbd5514863 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/FastCRC16.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/FastCRC16.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/FirmwareCapability.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/FirmwareCapability.java similarity index 80% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/FirmwareCapability.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/FirmwareCapability.java index cde0eac37e..ad1c5efe22 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/FirmwareCapability.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/FirmwareCapability.java @@ -1,12 +1,12 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; // jamorham -import static com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine.getFirmwareXDetails; -import static com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine.getRawFirmwareVersionString; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.getFirmwareXDetails; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.getRawFirmwareVersionString; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import com.google.common.collect.ImmutableSet; import lombok.val; @@ -18,6 +18,8 @@ public class FirmwareCapability { private static final ImmutableSet KNOWN_G6_REV2_FIRMWARES = ImmutableSet.of("2.18.2.67", "2.18.2.88", "2.18.2.98", "2.24.2.88", "2.27.2.98", "2.27.2.103"); private static final ImmutableSet KNOWN_G6_REV2_RAW_FIRMWARES = ImmutableSet.of("2.18.2.67"); private static final ImmutableSet KNOWN_G6_PLUS_FIRMWARES = ImmutableSet.of("2.4.2.88"); + private static final ImmutableSet KNOWN_ONE_FIRMWARES = ImmutableSet.of("30.192.103.34"); + private static final ImmutableSet KNOWN_ALT_FIRMWARES = ImmutableSet.of("29.192.104.59", "32.192.104.82", "32.192.104.109", "32.192.105.64", "32.192.106.0", "44.192.105.72"); private static final ImmutableSet KNOWN_TIME_TRAVEL_TESTED = ImmutableSet.of("1.6.5.25"); // new G6 firmware versions will need to be added here / above @@ -29,7 +31,12 @@ static boolean isG6Firmware(final String version) { || version.startsWith("2.18.") || version.startsWith("2.24.") || version.startsWith("2.27.") - || version.startsWith("2.4.")); + || version.startsWith("2.4.") + || isDex1Firmware(version)); + } + + static boolean isDex1Firmware(final String version) { + return version.startsWith("30."); } public static boolean isG6Rev2(final String version) { @@ -72,6 +79,10 @@ static boolean isFirmwarePreemptiveRestartCapable(final String version) { return isFirmwareRawCapable(version); // hang off this for now as they are currently the same } + static boolean isG7Firmware(final String version) { + return KNOWN_ALT_FIRMWARES.contains(version); + } + public static boolean isTransmitterPredictiveCapable(final String tx_id) { return isG6Firmware(getRawFirmwareVersionString(tx_id)); } @@ -84,6 +95,17 @@ public static boolean isTransmitterModified(final String tx_id) { return false; } + public static boolean isTransmitterStandardFirefly(final String tx_id) { // Firefly that has not been modified + if (!isTransmitterModified(tx_id) && isTransmitterRawIncapable(tx_id)) { + return true; + } + return false; + } + + public static boolean isDeviceG7(final String tx_id) { + return isG7Firmware(getRawFirmwareVersionString(tx_id)); + } + public static boolean isTransmitterG5(final String tx_id) { return isG5Firmware(getRawFirmwareVersionString(tx_id)); } @@ -123,6 +145,8 @@ public static boolean isKnownFirmware(final String version) { return (version == null || version.equals("") || KNOWN_G5_FIRMWARES.contains(version) || KNOWN_G6_FIRMWARES.contains(version) + || KNOWN_ONE_FIRMWARES.contains(version) + || KNOWN_ALT_FIRMWARES.contains(version) || KNOWN_G6_REV2_FIRMWARES.contains(version) || KNOWN_G6_PLUS_FIRMWARES.contains(version)); } diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/G6CalibrationParameters.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/G6CalibrationParameters.java similarity index 96% rename from wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/G6CalibrationParameters.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/G6CalibrationParameters.java index 17a2584e65..d82914f8b1 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/G6CalibrationParameters.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/G6CalibrationParameters.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; import lombok.Getter; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/GlucoseRxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/GlucoseRxMessage.java similarity index 90% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/GlucoseRxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/GlucoseRxMessage.java index 23ee8fb4d8..d0f2800b8d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/GlucoseRxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/GlucoseRxMessage.java @@ -1,8 +1,8 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.services.G5CollectionService; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/GlucoseTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/GlucoseTxMessage.java similarity index 63% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/GlucoseTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/GlucoseTxMessage.java index 57e6eb988f..f2fc51ffae 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/GlucoseTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/GlucoseTxMessage.java @@ -1,8 +1,8 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.services.G5CollectionService; /** * Created by jamorham on 25/11/2016. diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/InvalidRxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/InvalidRxMessage.java similarity index 90% rename from wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/InvalidRxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/InvalidRxMessage.java index 70de647e1f..15c4deba8a 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/InvalidRxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/InvalidRxMessage.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/KeepAliveTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/KeepAliveTxMessage.java similarity index 75% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/KeepAliveTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/KeepAliveTxMessage.java index f56f30d383..0c293268c2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/KeepAliveTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/KeepAliveTxMessage.java @@ -1,8 +1,8 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.services.G5CollectionService; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/Ob1DexTransmitterBattery.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/Ob1DexTransmitterBattery.java similarity index 85% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/Ob1DexTransmitterBattery.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/Ob1DexTransmitterBattery.java index 638d54880b..59f5b33c60 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/Ob1DexTransmitterBattery.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/Ob1DexTransmitterBattery.java @@ -1,12 +1,14 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Services.G5BaseService; -import com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.shortTxId; + +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.services.G5BaseService; +import com.eveningoutpost.dexdrip.services.Ob1G5CollectionService; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; /** @@ -61,7 +63,7 @@ public String daysEstimate() { StringBuilder b = new StringBuilder(); - if (battery.runtime > -1) { + if (battery.runtime > -1 && !shortTxId()) { // Excluding G7 b.append(battery.runtime); } @@ -93,6 +95,9 @@ public boolean voltageAWarning() { } public boolean voltageBWarning() { + if (shortTxId()) { // G7 only + return voltageB() < (G5BaseService.LOW_BATTERY_WARNING_LEVEL - 25); + } return voltageB() < (G5BaseService.LOW_BATTERY_WARNING_LEVEL - 10); }; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/Ob1G5StateMachine.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/Ob1G5StateMachine.java similarity index 81% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/Ob1G5StateMachine.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/Ob1G5StateMachine.java index 2e7a4beb08..1488d74b7c 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/Ob1G5StateMachine.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/Ob1G5StateMachine.java @@ -1,32 +1,33 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; import android.annotation.SuppressLint; import android.bluetooth.BluetoothGatt; +import android.bluetooth.BluetoothGattCharacteristic; import android.os.Build; import android.os.PowerManager; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Prediction; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.SensorSanity; -import com.eveningoutpost.dexdrip.Models.TransmitterData; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Prediction; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.SensorSanity; +import com.eveningoutpost.dexdrip.models.TransmitterData; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.BroadcastGlucose; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.NotificationChannels; -import com.eveningoutpost.dexdrip.UtilityModels.Notifications; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.WholeHouse; +import com.eveningoutpost.dexdrip.services.Ob1G5CollectionService; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.BroadcastGlucose; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.NotificationChannels; +import com.eveningoutpost.dexdrip.utilitymodels.Notifications; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.WholeHouse; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.utils.PowerStateReceiver; import com.eveningoutpost.dexdrip.utils.bt.Mimeograph; @@ -41,6 +42,7 @@ import java.io.UnsupportedEncodingException; import java.lang.reflect.Type; import java.security.InvalidKeyException; +import java.security.InvalidParameterException; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Arrays; @@ -57,29 +59,39 @@ import javax.crypto.spec.SecretKeySpec; import io.reactivex.schedulers.Schedulers; - -import static com.eveningoutpost.dexdrip.G5Model.BluetoothServices.Authentication; -import static com.eveningoutpost.dexdrip.G5Model.BluetoothServices.Control; -import static com.eveningoutpost.dexdrip.G5Model.BluetoothServices.ProbablyBackfill; -import static com.eveningoutpost.dexdrip.G5Model.FirmwareCapability.isTransmitterG6Rev2; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.Models.JoH.pratelimit; -import static com.eveningoutpost.dexdrip.Models.JoH.tsl; -import static com.eveningoutpost.dexdrip.Services.G5BaseService.G5_BATTERY_FROM_MARKER; -import static com.eveningoutpost.dexdrip.Services.G5BaseService.G5_BATTERY_LEVEL_MARKER; -import static com.eveningoutpost.dexdrip.Services.G5BaseService.G5_BATTERY_MARKER; -import static com.eveningoutpost.dexdrip.Services.G5BaseService.G5_BATTERY_WEARABLE_SEND; -import static com.eveningoutpost.dexdrip.Services.G5BaseService.G5_FIRMWARE_MARKER; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.android_wear; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.getTransmitterID; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.onlyUsingNativeMode; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.resetSomeInternalState; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.wear_broadcast; -import static com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder.DEXCOM_PERIOD; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.DAY_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.HOUR_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.MINUTE_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.SECOND_IN_MS; +import lombok.val; + +import static com.eveningoutpost.dexdrip.g5model.BluetoothServices.Authentication; +import static com.eveningoutpost.dexdrip.g5model.BluetoothServices.Control; +import static com.eveningoutpost.dexdrip.g5model.BluetoothServices.ExtraData; +import static com.eveningoutpost.dexdrip.g5model.BluetoothServices.ProbablyBackfill; +import static com.eveningoutpost.dexdrip.g5model.FirmwareCapability.isTransmitterG6Rev2; +import static com.eveningoutpost.dexdrip.models.JoH.bytesToHex; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.pratelimit; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; +import static com.eveningoutpost.dexdrip.services.G5BaseService.G5_BATTERY_FROM_MARKER; +import static com.eveningoutpost.dexdrip.services.G5BaseService.G5_BATTERY_LEVEL_MARKER; +import static com.eveningoutpost.dexdrip.services.G5BaseService.G5_BATTERY_MARKER; +import static com.eveningoutpost.dexdrip.services.G5BaseService.G5_BATTERY_WEARABLE_SEND; +import static com.eveningoutpost.dexdrip.services.G5BaseService.G5_FIRMWARE_MARKER; +import static com.eveningoutpost.dexdrip.services.G5BaseService.ALT_LOW_BATTERY_WARNING_DEFAULT; +import static com.eveningoutpost.dexdrip.services.G5BaseService.setG6Defaults; +import static com.eveningoutpost.dexdrip.services.G5BaseService.unBondAndStop; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.STATE.GET_DATA; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.STATE.SCAN; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.android_wear; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.getTransmitterID; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.ignoreBonding; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.immediateBonding; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.onlyUsingNativeMode; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.resetSomeInternalState; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.wear_broadcast; +import static com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder.DEXCOM_PERIOD; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.DAY_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.HOUR_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.SECOND_IN_MS; import static com.eveningoutpost.dexdrip.utils.bt.Helper.getStatusName; @@ -98,11 +110,11 @@ public class Ob1G5StateMachine { public static final String PREF_QUEUE_DRAINED = "OB1-QUEUE-DRAINED"; public static final String CLOSED_OK_TEXT = "Closed OK"; - private static final int LOW_BATTERY_WARNING_LEVEL = Pref.getStringToInt("g5-battery-warning-level", 300); // voltage a < this value raises warnings; + private static int LOW_BATTERY_WARNING_LEVEL = Pref.getStringToInt("g5-battery-warning-level", 300); // voltage a < this value raises warnings; private static final long BATTERY_READ_PERIOD_MS = HOUR_IN_MS * 12; // how often to poll battery data (12 hours) private static final long MAX_BACKFILL_PERIOD_MS = HOUR_IN_MS * 3; // how far back to request backfill data + private static final long MAX_BACKFILL_PERIOD_MS2 = HOUR_IN_MS * 24; // A larger backfill option private static final int BACKFILL_CHECK_SMALL = 3; - private static final int BACKFILL_CHECK_LARGE = (int) (MAX_BACKFILL_PERIOD_MS / DEXCOM_PERIOD); private static final boolean getVersionDetails = true; // try to load firmware version details private static final boolean getBatteryDetails = true; // try to load battery info details @@ -120,6 +132,21 @@ public class Ob1G5StateMachine { private static volatile BgReading lastGlucoseBgReading; private static volatile AuthRequestTxMessage lastAuthPacket; private static volatile boolean backup_loaded = false; + private static final int OLDEST_RAW = 300 * 24 * 60 * 60; // 300 days + + public static long maxBackfillPeriod_MS = 0; + + public static long maxBackfillPeriod_MS() { + maxBackfillPeriod_MS = MAX_BACKFILL_PERIOD_MS; + if (shortTxId()) { // If using G7 + maxBackfillPeriod_MS = MAX_BACKFILL_PERIOD_MS2; + } + return maxBackfillPeriod_MS; + } + + public static int backfillCheckLarge() { + return (int) (maxBackfillPeriod_MS() / DEXCOM_PERIOD); + } // Auth Check + Request @SuppressLint("CheckResult") @@ -144,7 +171,7 @@ public static boolean doCheckAuth(final Ob1G5CollectionService parent, final RxB .subscribe(bytes -> { // incoming indications lastAuthenticationStream = tsl(); - UserError.Log.d(TAG, "Received Authentication indication bytes: " + JoH.bytesToHex(bytes)); + UserError.Log.d(TAG, "Received Authentication indication bytes: " + bytesToHex(bytes)); authenticationProcessor(parent, connection, bytes); }, throwable -> handleAuthenticationThrowable(throwable, parent)); } else { @@ -159,27 +186,157 @@ public static boolean doCheckAuth(final Ob1G5CollectionService parent, final RxB .subscribe(bytes -> { // incoming notifications lastAuthenticationStream = tsl(); - UserError.Log.d(TAG, "Received Authentication notification bytes: " + JoH.bytesToHex(bytes)); + UserError.Log.d(TAG, "Received Authentication notification bytes: " + bytesToHex(bytes)); authenticationProcessor(parent, connection, bytes); }, throwable -> handleAuthenticationThrowable(throwable, parent)); } return true; } + + private static void doNext(final Ob1G5CollectionService parent, final RxBleConnection connection) { + try { + val p = parent.plugin.aNext(); + if (p == null) { + UserError.Log.d(TAG, "Null value returned via plugin"); + if (shortTxId()) { + UserError.Log.d(TAG, "Attempting state reset"); + parent.resetSomeInternalState(); + } + return; + } + val cmd = p[0]; + + if (p.length == 2) { + val data = p[1]; + if (data != null) { + connection.getCharacteristic(ExtraData) + .blockingGet().setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE); + val len = data.length; + for (int i = 0; i < len; i = i + 20) { + val size = Math.min(20, len - i); + val buf = new byte[size]; + System.arraycopy(data, i, buf, 0, size); + UserError.Log.d(TAG, "Sending auth data: " + bytesToHex(buf)); + connection.writeCharacteristic(ExtraData, nn(buf)).subscribe(); + threadSleep(40); + } + // TODO wait for completion? + threadSleep(500); + } + if (cmd != null) { + UserError.Log.d(TAG, "Sending auth command: " + HexDump.dumpHexString(cmd)); + connection.getCharacteristic(Authentication) + .blockingGet().setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT); + connection.writeCharacteristic(Authentication, nn(cmd)).subscribe(); + } + } else if (p.length == 1) { + if (cmd != null) { + parent.changeState(GET_DATA); + } + } else if (p.length == 3) { + parent.savePersist(); + if (parent.isDeviceLocallyBonded()) { + parent.changeState(Ob1G5CollectionService.STATE.UNBOND); + } else { + UserError.Log.d(TAG, "Device does not appear to be bonded?"); + } + } + } catch (Exception e) { + UserError.Log.wtf(TAG, "Got exception in doNext() " + e); + } + } + + @SuppressLint("CheckResult") + public static boolean doCheckAuth2(final Ob1G5CollectionService parent, final RxBleConnection connection) { + if (connection == null) return false; + parent.msg("Authorizing 2"); + + if (!usingG6()) { + setG6Defaults(); + } + + if (shortTxId()) { + LOW_BATTERY_WARNING_LEVEL = ALT_LOW_BATTERY_WARNING_DEFAULT; + Pref.setString("g5-battery-warning-level", "" + ALT_LOW_BATTERY_WARNING_DEFAULT); + parent.updateBatteryWarningLevel(); + } + + if (parent.android_wear) { + speakSlowly = true; + UserError.Log.d(TAG, "Setting speak slowly to true"); // WARN should be reactive or on named devices + } + + try { + parent.plugin.amConnected(); + } catch (Exception e) { + UserError.Log.e(TAG, "Got exception in plugin: " + e); + e.printStackTrace(); + } + connection.setupNotification(ExtraData) + .timeout(15, TimeUnit.SECONDS) // WARN + .doOnNext(notificationObservable -> { + UserError.Log.d(TAG, "Extra data notifications enabled"); + connection.setupIndication(Authentication) + .timeout(15, TimeUnit.SECONDS) // WARN + .doOnNext(notificationObservable2 -> doNext(parent, connection)) + .flatMap(notificationObservable2 -> notificationObservable2) + .subscribe(bytes -> { + lastAuthenticationStream = tsl(); + UserError.Log.d(TAG, "Received Authentication 2 indication bytes: " + bytesToHex(bytes)); + try { + if (parent.plugin.bondNow(bytes)) { + UserError.Log.d(TAG, "Creating bond!!"); + parent.changeState(Ob1G5CollectionService.STATE.BOND); + } + if (parent.plugin.receivedResponse(bytes)) { + doNext(parent, connection); + } + } catch (Exception e) { + UserError.Log.e(TAG, "Got exception in plugin: " + e); + parent.lastSensorStatus = e.getMessage(); + if (e instanceof InvalidParameterException) { + parent.resetSomeInternalState(); + } else if (e instanceof SecurityException) { + parent.logFailure(); + parent.clearPersistStore(); + parent.changeState(SCAN); + } else { + e.printStackTrace(); + } + } + }, throwable -> handleAuthenticationThrowable(throwable, parent)); + }) + .flatMap(notificationObservable -> notificationObservable) + .subscribe(bytes -> { + lastAuthenticationStream = tsl(); + UserError.Log.d(TAG, "Received extra data indication bytes: " + bytesToHex(bytes)); + try { + if (parent.plugin.receivedData(bytes)) { + doNext(parent, connection); + } + } catch (Exception e) { + UserError.Log.e(TAG, "Got exception in plugin: " + e); + e.printStackTrace(); + } + }, throwable -> handleAuthenticationThrowable(throwable, parent)); + return true; + } + @SuppressLint("CheckResult") private static void handleAuthenticationWrite(final Ob1G5CollectionService parent, final RxBleConnection connection) { final int specifiedSlot = Pref.getBooleanDefaultFalse("engineering_mode") ? Pref.getStringToInt("dex_specified_slot", -1) : -1; final AuthRequestTxMessage authRequest = (specifiedSlot == -1) ? new AuthRequestTxMessage(getTokenSize(), usingAlt()) - : new AuthRequestTxMessage(getTokenSize(), specifiedSlot); + : new AuthRequestTxMessage(getTokenSize(), specifiedSlot); lastAuthPacket = authRequest; - UserError.Log.i(TAG, "AuthRequestTX: " + JoH.bytesToHex(authRequest.byteSequence)); + UserError.Log.i(TAG, "AuthRequestTX: " + bytesToHex(authRequest.byteSequence)); connection.writeCharacteristic(Authentication, nn(authRequest.byteSequence)) .subscribe( characteristicValue -> { // Characteristic value confirmed. if (d) - UserError.Log.d(TAG, "Wrote authrequest, got: " + JoH.bytesToHex(characteristicValue)); + UserError.Log.d(TAG, "Wrote authrequest, got: " + bytesToHex(characteristicValue)); speakSlowly(); if ((msSince(lastAuthenticationStream) > 500) && !isTransmitterG6Rev2(getTransmitterID())) { connection.readCharacteristic(Authentication).subscribe( @@ -212,12 +369,12 @@ private static void handleAuthenticationThrowable(final Throwable throwable, fin // parent.reset_bond(true); // parent.unBond(); // WARN } else { - UserError.Log.e(TAG, "authentication notification throwable: (" + parent.getState() + ") " + throwable + " " + JoH.dateTimeText(tsl())); + UserError.Log.d(TAG, "authentication notification throwable: (" + parent.getState() + ") " + throwable + " " + JoH.dateTimeText(tsl())); parent.incrementErrors(); if (throwable instanceof BleCannotSetCharacteristicNotificationException || throwable instanceof BleGattCharacteristicException) { parent.tryGattRefresh(); - parent.changeState(Ob1G5CollectionService.STATE.SCAN); + parent.changeState(SCAN); } } if ((throwable instanceof BleDisconnectedException) || (throwable instanceof TimeoutException)) { @@ -228,7 +385,7 @@ private static void handleAuthenticationThrowable(final Throwable throwable, fin threadSleep(15000); } UserError.Log.d(TAG, "REQUESTING RECONNECT"); - parent.changeState(Ob1G5CollectionService.STATE.SCAN); + parent.changeState(SCAN); } } } @@ -237,7 +394,7 @@ private static void handleAuthenticationThrowable(final Throwable throwable, fin @SuppressLint("CheckResult") private static void authenticationProcessor(final Ob1G5CollectionService parent, final RxBleConnection connection, final byte[] readValue) { PacketShop pkt = classifyPacket(readValue); - UserError.Log.d(TAG, "Read from auth request: " + pkt.type + " " + JoH.bytesToHex(readValue)); + UserError.Log.d(TAG, "Read from auth request: " + pkt.type + " " + bytesToHex(readValue)); switch (pkt.type) { case AuthChallengeRxMessage: @@ -266,7 +423,7 @@ private static void authenticationProcessor(final Ob1G5CollectionService parent, if (throwable instanceof OperationSuccess) { UserError.Log.d(TAG, "Stopping auth challenge listener due to success"); } else { - UserError.Log.e(TAG, "Could not read reply to auth challenge: " + throwable); + UserError.Log.d(TAG, "Could not read reply to auth challenge: " + throwable); parent.incrementErrors(); speakSlowly = true; } @@ -309,7 +466,7 @@ private static void authenticationProcessor(final Ob1G5CollectionService parent, if (status.isBonded()) { parent.msg("Authenticated"); parent.authResult(true); - parent.changeState(Ob1G5CollectionService.STATE.GET_DATA); + parent.changeState(GET_DATA); throw new OperationSuccess("Authenticated"); } else { //parent.unBond(); // bond must be invalid or not existing // WARN @@ -342,7 +499,7 @@ private static void authenticationProcessor(final Ob1G5CollectionService parent, break; default: - UserError.Log.e(TAG, "Unhandled packet type in reply: " + pkt.type + " " + JoH.bytesToHex(readValue)); + UserError.Log.e(TAG, "Unhandled packet type in reply: " + pkt.type + " " + bytesToHex(readValue)); parent.incrementErrors(); // TODO what to do here? break; @@ -412,14 +569,14 @@ public synchronized static boolean doKeepAliveAndBondRequest(Ob1G5CollectionServ connection.writeCharacteristic(Authentication, nn(new BondRequestTxMessage().byteSequence)) .subscribe( bondRequestValue -> { - UserError.Log.d(TAG, "Wrote bond request value: " + JoH.bytesToHex(bondRequestValue)); + UserError.Log.d(TAG, "Wrote bond request value: " + bytesToHex(bondRequestValue)); speakSlowly(); connection.readCharacteristic(Authentication) .observeOn(Schedulers.io()) .timeout(10, TimeUnit.SECONDS) .subscribe( status_value -> { - UserError.Log.d(TAG, "Got status read after keepalive " + JoH.bytesToHex(status_value)); + UserError.Log.d(TAG, "Got status read after keepalive " + bytesToHex(status_value)); authenticationProcessor(parent, connection, status_value); throw new OperationSuccess("Bond requested"); }, throwable -> { @@ -459,7 +616,11 @@ private static void localUnbondAndStop(final Ob1G5CollectionService parent, RxBl public static boolean doUnBond(final Ob1G5CollectionService parent, RxBleConnection connection) { if (connection == null) return false; parent.msg("Unbond Transmitter a:" + usingAlt()); - localUnbondAndStop(parent, connection); + if (unBondAndStop) { + localUnbondAndStop(parent, connection); + } else { + parent.unBond(); + } return true; } @@ -511,12 +672,14 @@ public static boolean doGetData(Ob1G5CollectionService parent, RxBleConnection c if (connection == null) return false; // TODO switch modes depending on conditions as to whether we are using internal final boolean use_g5_internal_alg = Pref.getBooleanDefaultFalse("ob1_g5_use_transmitter_alg"); - UserError.Log.d(TAG, use_g5_internal_alg ? ("Requesting Glucose Data " + (usingG6() ? "G6" : "G5")) : "Requesting Sensor Data"); + UserError.Log.d(TAG, use_g5_internal_alg ? ("Requesting Glucose Data " + (usingG6() ? (shortTxId() ? "G7" : "G6") : "G5")) : "Requesting Sensor Data"); if (!use_g5_internal_alg) { parent.lastSensorStatus = null; // not applicable parent.lastUsableGlucosePacketTime = 0; } + connection.getCharacteristic(Control) + .blockingGet().setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT); connection.setupIndication(Control) @@ -525,7 +688,7 @@ public static boolean doGetData(Ob1G5CollectionService parent, RxBleConnection c if (d) UserError.Log.d(TAG, "Notifications enabled"); speakSlowly(); - connection.writeCharacteristic(Control, nn(use_g5_internal_alg ? (getEGlucose() ? new EGlucoseTxMessage().byteSequence : new GlucoseTxMessage().byteSequence) : new SensorTxMessage().byteSequence)) + connection.writeCharacteristic(Control, nn(use_g5_internal_alg ? (getEGlucose(parent) ? new EGlucoseTxMessage(shortTxId()).byteSequence : new GlucoseTxMessage().byteSequence) : new SensorTxMessage().byteSequence)) .subscribe( characteristicValue -> { if (d) @@ -547,7 +710,7 @@ public static boolean doGetData(Ob1G5CollectionService parent, RxBleConnection c .timeout(6, TimeUnit.SECONDS) .subscribe(bytes -> { // incoming data notifications - UserError.Log.d(TAG, "Received indication bytes: " + JoH.bytesToHex(bytes)); + UserError.Log.d(TAG, "Received indication bytes: " + bytesToHex(bytes)); final PacketShop data_packet = classifyPacket(bytes); switch (data_packet.type) { case SensorRxMessage: @@ -566,7 +729,7 @@ public static boolean doGetData(Ob1G5CollectionService parent, RxBleConnection c if (!setStoredFirmwareBytes(getTransmitterID(), 1, bytes, true)) { UserError.Log.e(TAG, "Could not save out firmware version!"); } - nextBackFillCheckSize = BACKFILL_CHECK_LARGE; + nextBackFillCheckSize = backfillCheckLarge(); if (JoH.ratelimit("g6-evaluate", 600)) { Inevitable.task("evaluteG6Settings", 10000, () -> evaluateG6Settings()); } @@ -576,7 +739,7 @@ public static boolean doGetData(Ob1G5CollectionService parent, RxBleConnection c if (!setStoredFirmwareBytes(getTransmitterID(), 0, bytes, true)) { UserError.Log.e(TAG, "Could not save out firmware version!"); } - nextBackFillCheckSize = BACKFILL_CHECK_LARGE; + nextBackFillCheckSize = backfillCheckLarge(); if (JoH.ratelimit("g6-evaluate", 600)) { Inevitable.task("evaluteG6Settings", 10000, () -> evaluateG6Settings()); } @@ -588,7 +751,7 @@ public static boolean doGetData(Ob1G5CollectionService parent, RxBleConnection c UserError.Log.e(TAG, "Could not save out firmware version!"); } SensorDays.clearCache(); - nextBackFillCheckSize = BACKFILL_CHECK_LARGE; + nextBackFillCheckSize = backfillCheckLarge(); if (JoH.ratelimit("g6-evaluate", 600)) { Inevitable.task("evaluteG6Settings", 10000, () -> evaluateG6Settings()); } @@ -602,7 +765,7 @@ public static boolean doGetData(Ob1G5CollectionService parent, RxBleConnection c PersistentStore.setBoolean(G5_BATTERY_WEARABLE_SEND, true); } } - nextBackFillCheckSize = BACKFILL_CHECK_LARGE; + nextBackFillCheckSize = backfillCheckLarge(); break; case SessionStartRxMessage: @@ -624,7 +787,7 @@ public static boolean doGetData(Ob1G5CollectionService parent, RxBleConnection c if (session_start.isFubar()) { final long tk = DexTimeKeeper.getDexTime(getTransmitterID(), tsl()); if (tk > 0) { - if (FirmwareCapability.isTransmitterRawIncapable(getTransmitterID())) {// Firefly, which cannot be hard reset + if (FirmwareCapability.isTransmitterStandardFirefly(getTransmitterID())) {// Firefly, which cannot be hard reset UserError.Log.e(TAG, "Unusual session start failure"); } else { DexResetHelper.offer("Unusual session start failure, is transmitter crashed? Try Hard Reset?"); @@ -706,6 +869,25 @@ public static boolean doGetData(Ob1G5CollectionService parent, RxBleConnection c glucoseRxCommon(eglucose, parent, connection); break; + case EGlucoseRxMessage2: + val eglucose2 = (EGlucoseRxMessage2) data_packet.msg; + UserError.Log.d(TAG, "EG2 Debug: " + eglucose2); + if (eglucose2.isValid()) { + parent.processCalibrationState(eglucose2.calibrationState()); + DexTimeKeeper.updateAge(getTransmitterID(), (int) eglucose2.timestamp); + DexSessionKeeper.setStart(eglucose2.getRealSessionStartTime()); + if (eglucose2.usable()) { + parent.msg("Got glucose"); + } else { + parent.msg("Got data"); + } + glucoseRxCommon(eglucose2, parent, connection); + parent.saveTransmitterMac(); + } else { + parent.msg("Invalid Glucose"); + } + break; + case CalibrateRxMessage: final CalibrateRxMessage calibrate = (CalibrateRxMessage) data_packet.msg; @@ -731,6 +913,15 @@ public static boolean doGetData(Ob1G5CollectionService parent, RxBleConnection c } break; + case BackFillControlRxMessage: + final BackFillControlRxMessage backfill2 = (BackFillControlRxMessage) data_packet.msg; + if (backfill2.isValid()) { + UserError.Log.d(TAG, "Backfill2 request confirmed"); + } else { + UserError.Log.wtf(TAG, "Backfill2 request corrupted!"); + } + break; + case TransmitterTimeRxMessage: // This message is received every 120-125m final TransmitterTimeRxMessage txtime = (TransmitterTimeRxMessage) data_packet.msg; @@ -761,7 +952,16 @@ public static boolean doGetData(Ob1G5CollectionService parent, RxBleConnection c break; default: - UserError.Log.e(TAG, "Got unknown packet rx: " + JoH.bytesToHex(bytes)); + val hex = bytesToHex(bytes); + UserError.Log.e(TAG, "Got unknown packet rx: " + hex); + + switch (hex) { + case "2E01": + UserError.Log.e(TAG, "Invalid settings, attempting to restore Dex defaults, Native mode, no plugin"); + setG6Defaults(); + break; + } + break; } if (!queued(parent, connection)) { @@ -809,7 +1009,9 @@ private static void glucoseRxCommon(final BaseGlucoseRxMessage glucose, final Ob || glucose.calibrationState().warmingUp() || !DexSessionKeeper.isStarted()) { if (JoH.ratelimit("g5-tx-time-governer", 30)) { - enqueueUniqueCommand(new TimeTxMessage(), "Periodic Query Time"); + if (getTransmitterID().length() > 4) { + enqueueUniqueCommand(new TimeTxMessage(), "Periodic Query Time"); + } } } @@ -870,7 +1072,7 @@ private static void backFillIfNeeded(Ob1G5CollectionService parent, RxBleConnect UserError.Log.d(TAG, "Checking " + check_readings + " for backfill requirement"); final List lastReadings = BgReading.latest_by_size(check_readings); boolean ask_for_backfill = false; - long earliest_timestamp = tsl() - MAX_BACKFILL_PERIOD_MS; + long earliest_timestamp = tsl() - maxBackfillPeriod_MS(); long latest_timestamp = tsl(); if ((lastReadings == null) || (lastReadings.size() != check_readings)) { ask_for_backfill = true; @@ -879,7 +1081,7 @@ private static void backFillIfNeeded(Ob1G5CollectionService parent, RxBleConnect final BgReading reading = lastReadings.get(i); if ((reading == null) || (msSince(reading.timestamp) > ((DEXCOM_PERIOD * i) + Constants.MINUTE_IN_MS * 7))) { ask_for_backfill = true; - if ((reading != null) && (msSince(reading.timestamp) <= MAX_BACKFILL_PERIOD_MS)) { + if ((reading != null) && (msSince(reading.timestamp) <= maxBackfillPeriod_MS())) { earliest_timestamp = reading.timestamp; } if (reading != null) { @@ -896,10 +1098,12 @@ private static void backFillIfNeeded(Ob1G5CollectionService parent, RxBleConnect } if (ask_for_backfill) { - nextBackFillCheckSize = BACKFILL_CHECK_LARGE; + nextBackFillCheckSize = backfillCheckLarge(); monitorBackFill(parent, connection); - final long startTime = Math.max(earliest_timestamp - (Constants.MINUTE_IN_MS * 5), sensor.started_at); - final long endTime = latest_timestamp + (Constants.MINUTE_IN_MS * 5); + + final long txStartTime = DexTimeKeeper.getTxStartTimestamp(getTransmitterID()); // the time the transmitter reports as starting or 0 if we don't know + final long startTime = Math.max(earliest_timestamp - DEXCOM_PERIOD, Math.max(txStartTime + DEXCOM_PERIOD, sensor.started_at)); + final long endTime = latest_timestamp + DEXCOM_PERIOD; if (startTime >= endTime) { UserError.Log.e(TAG, "Cannot process backfill request where start time would be after end time"); @@ -907,14 +1111,26 @@ private static void backFillIfNeeded(Ob1G5CollectionService parent, RxBleConnect } UserError.Log.d(TAG, "Requesting backfill between: " + JoH.dateTimeText(startTime) + " " + JoH.dateTimeText(endTime)); - enqueueUniqueCommand( - BackFillTxMessage.get(getTransmitterID(), startTime, endTime), - "Get backfill since: " + JoH.hourMinuteString(startTime)); + + if (!shortTxId()) { + enqueueUniqueCommand( + BackFillTxMessage.get(getTransmitterID(), startTime, endTime), + "Get backfill since: " + JoH.hourMinuteString(startTime)); + } else { + enqueueUniqueCommand( + BackFillTxMessage2.get(getTransmitterID(), startTime, endTime), + "Get backfill2 since: " + JoH.hourMinuteString(startTime)); + } } else { nextBackFillCheckSize = BACKFILL_CHECK_SMALL; } } + public static boolean shortTxId() { + return getTransmitterID().length() < 6; + } + + private static Ob1Work enqueueCommand(BaseMessage tm, String msg) { if (tm != null) { final Ob1Work item = new Ob1Work(tm, msg); @@ -1333,13 +1549,30 @@ private static void processQueueCommand(Ob1G5CollectionService parent, RxBleConn if (changed) saveQueue(); } + private static void checkAndActivateSensor() { + // automagically start an xDrip sensor session if transmitter already has active sensor + if (!Sensor.isActive() && Ob1G5CollectionService.isG5SensorStarted() && (!Sensor.stoppedRecently() || shortTxId())) { + JoH.static_toast_long(xdrip.gs(R.string.auto_starting_sensor)); + // TODO possibly here we want to look at last sensor stop time and not backtrack before that + Sensor.create(tsl() - HOUR_IN_MS * 3); + if (shortTxId()) { // If we are using G7 + Sensor.create(tsl() - HOUR_IN_MS * 24); + } + } + } + private static void processGlucoseRxMessage(Ob1G5CollectionService parent, final BaseGlucoseRxMessage glucose) { if (glucose == null) return; lastGlucosePacket = tsl(); DexTimeKeeper.updateAge(getTransmitterID(), glucose.timestamp); + if (glucose.calibrationState().warmingUp()) { + checkAndActivateSensor(); + } if (glucose.usable() || (glucose.insufficient() && Pref.getBoolean("ob1_g5_use_insufficiently_calibrated", true))) { - UserError.Log.d(TAG, "Got usable glucose data from G5!!"); - final long rxtimestamp = tsl(); + UserError.Log.d(TAG, "Got usable glucose data from transmitter!!"); + final long rxtimestamp = glucose.getRealTimestamp(); + checkAndActivateSensor(); + DexSyncKeeper.store(getTransmitterID(), rxtimestamp, parent.static_last_connected, lastGlucosePacket); final BgReading bgReading = BgReading.bgReadingInsertFromG5(glucose.glucose, rxtimestamp); if (bgReading != null) { try { @@ -1365,7 +1598,7 @@ private static void processGlucoseRxMessage(Ob1G5CollectionService parent, final if (glucose.getPredictedGlucose() != null) { // not really supported on wear yet if (!android_wear) { - Prediction.create(tsl(), glucose.getPredictedGlucose(), "EGlucoseRx").save(); + Prediction.create(rxtimestamp, glucose.getPredictedGlucose(), "EGlucoseRx").save(); } } @@ -1403,8 +1636,13 @@ private static void processSensorRxMessage(SensorRxMessage sensorRx) { } UserError.Log.d(TAG, "SUCCESS!! unfiltered: " + sensorRx.unfiltered + " filtered: " + sensorRx.filtered + " timestamp: " + sensorRx.timestamp + " " + JoH.qs((double) sensorRx.timestamp / 86400, 1) + " days :: (" + sensorRx.status + ")"); - DexTimeKeeper.updateAge(getTransmitterID(), sensorRx.timestamp); - Ob1G5CollectionService.setLast_transmitter_timestamp(sensorRx.timestamp); + if (FirmwareCapability.isTransmitterModified(getTransmitterID()) && sensorRx.timestamp > OLDEST_RAW) { // Raw timestamp reported by a mod TX is incorrect until after sensor start. + UserError.Log.d(TAG, "Will not update age since raw timestamp is incorrect."); + Ob1G5CollectionService.setLast_transmitter_timestamp(0); + } else { // Update age, based on the raw timestamp, only if the raw timestamp is correct. + DexTimeKeeper.updateAge(getTransmitterID(), sensorRx.timestamp); + Ob1G5CollectionService.setLast_transmitter_timestamp(sensorRx.timestamp); + } if (sensorRx.unfiltered == 0) { UserError.Log.e(TAG, "Transmitter sent raw sensor value of 0 !! This isn't good. " + JoH.hourMinuteString()); } else { @@ -1479,29 +1717,32 @@ public static void evaluateG6Settings() { if (haveFirmwareDetails()) { if (FirmwareCapability.isTransmitterG6(getTransmitterID())) { if (!usingG6()) { - Ob1G5CollectionService.setG6Defaults(); - JoH.showNotification("Enabled G6", "G6 Features and default settings automatically enabled", null, Constants.G6_DEFAULTS_MESSAGE, false, true, false); + setG6Defaults(); + JoH.showNotification("Enabled defaults", "Default settings automatically enabled", null, Constants.G6_DEFAULTS_MESSAGE, false, true, false); } else if (!onlyUsingNativeMode() && !Home.get_engineering_mode()) { // TODO revisit this now that there is scaling - Ob1G5CollectionService.setG6Defaults(); - JoH.showNotification("Enabled G6", "G6 Native mode enabled", null, Constants.G6_DEFAULTS_MESSAGE, false, true, false); + setG6Defaults(); + UserError.Log.uel(TAG, "Dex Native mode enabled. For your device, non-native mode is either not possible or not recommended."); + JoH.showNotification("Enabled Native", "Native mode enabled", null, Constants.G6_DEFAULTS_MESSAGE, false, true, false); } } } } private static boolean haveFirmwareDetails() { - return getTransmitterID().length() == 6 && getStoredFirmwareBytes(getTransmitterID()).length >= 10; + return getTransmitterID().length() >= 4 && getStoredFirmwareBytes(getTransmitterID()).length >= 10; } private static int requiredNextFirmwareDetailsType() { final String txid = getTransmitterID(); - if (txid.length() == 6) { + if (txid.length() > 3) { final byte[] v1b = getStoredFirmwareBytes(txid, 1); if (v1b.length < 10) return 1; - final byte[] v0b = getStoredFirmwareBytes(txid, 0); - if (v0b.length < 10) return 0; + if (txid.length() == 6) { + final byte[] v0b = getStoredFirmwareBytes(txid, 0); + if (v0b.length < 10) return 0; + } if (FirmwareCapability.isTransmitterG6Rev2(txid)) { final byte[] v3b = getStoredFirmwareBytes(txid, 3); if (v3b.length < 9) return 3; @@ -1514,7 +1755,7 @@ private static int requiredNextFirmwareDetailsType() { private static boolean haveCurrentBatteryStatus() { - return getTransmitterID().length() == 6 && (msSince(PersistentStore.getLong(G5_BATTERY_FROM_MARKER + getTransmitterID())) < BATTERY_READ_PERIOD_MS); + return getTransmitterID().length() >= 4 && (msSince(PersistentStore.getLong(G5_BATTERY_FROM_MARKER + getTransmitterID())) < BATTERY_READ_PERIOD_MS); } private static byte[] getStoredFirmwareBytes(final String transmitterId) { @@ -1522,7 +1763,7 @@ private static byte[] getStoredFirmwareBytes(final String transmitterId) { } private static byte[] getStoredFirmwareBytes(final String transmitterId, final int type) { - if (transmitterId.length() != 6) return new byte[0]; + if (transmitterId.length() < 4) return new byte[0]; return PersistentStore.getBytes(G5_FIRMWARE_MARKER + transmitterId + "-" + type); } @@ -1536,8 +1777,8 @@ public static boolean setStoredFirmwareBytes(String transmitterId, byte[] data, } public static boolean setStoredFirmwareBytes(String transmitterId, int type, byte[] data, boolean from_bluetooth) { - if (from_bluetooth) UserError.Log.e(TAG, "Store: VersionRX dbg: " + JoH.bytesToHex(data)); - if (transmitterId.length() != 6) return false; + if (from_bluetooth) UserError.Log.e(TAG, "Store: VersionRX dbg: " + bytesToHex(data)); + if (transmitterId.length() < 4) return false; if (data.length < 9) return false; if (JoH.ratelimit("store-firmware-bytes" + type, 60)) { PersistentStore.setBytes(G5_FIRMWARE_MARKER + transmitterId + "-" + type, data); @@ -1552,11 +1793,13 @@ public static void clearStoredFirmwareBytes(String transmitterId) { } public synchronized static boolean setStoredBatteryBytes(String transmitterId, byte[] data) { - UserError.Log.e(TAG, "Store: BatteryRX dbg: " + JoH.bytesToHex(data)); - if (transmitterId.length() != 6) return false; + UserError.Log.e(TAG, "Store: BatteryRX dbg: " + bytesToHex(data)); + if (transmitterId.length() < 4) return false; if (data.length < 10) return false; final BatteryInfoRxMessage batteryInfoRxMessage = new BatteryInfoRxMessage(data); UserError.Log.uel(TAG, "Saving battery data: " + batteryInfoRxMessage.toString()); + PersistentStore.cleanupOld(G5_BATTERY_MARKER); + PersistentStore.cleanupOld(G5_BATTERY_FROM_MARKER); PersistentStore.setBytes(G5_BATTERY_MARKER + transmitterId, data); PersistentStore.setLong(G5_BATTERY_FROM_MARKER + transmitterId, tsl()); @@ -1566,10 +1809,11 @@ public synchronized static boolean setStoredBatteryBytes(String transmitterId, b if (batteryInfoRxMessage.voltagea < LOW_BATTERY_WARNING_LEVEL) { if (JoH.pratelimit("g5-low-battery-warning", 40000)) { final boolean loud = !PowerStateReceiver.is_power_connected(); - JoH.showNotification("G5 Battery Low", "G5 Transmitter battery has dropped to: " + batteryInfoRxMessage.voltagea + " it may fail soon", + JoH.showNotification("Battery Low", "Transmitter battery has dropped to: " + batteryInfoRxMessage.voltagea + " it may fail soon", null, 770, NotificationChannels.LOW_TRANSMITTER_BATTERY_CHANNEL, loud, loud, null, null, null); } } + PersistentStore.cleanupOld(G5_BATTERY_LEVEL_MARKER); PersistentStore.setLong(G5_BATTERY_LEVEL_MARKER + transmitterId, batteryInfoRxMessage.voltagea); } return true; @@ -1642,7 +1886,7 @@ public static String getRawFirmwareVersionString(final String tx_id) { } return vr.firmware_version_string; } else { - return ""; + return tx_id.length() > 4 ? "" : "N/A"; } } @@ -1651,7 +1895,7 @@ private static void updateStreamedTillTimeForBackfill() { if (JoH.areWeRunningOnAndroidWear()) { final String pref_last_send_previous = "last_send_previous"; final long last_send_previous = PersistentStore.getLong(pref_last_send_previous); - PersistentStore.setLong(pref_last_send_previous, Math.min(last_send_previous, tsl() - MAX_BACKFILL_PERIOD_MS)); + PersistentStore.setLong(pref_last_send_previous, Math.min(last_send_previous, tsl() - maxBackfillPeriod_MS())); } } @@ -1661,7 +1905,7 @@ private static void processBacksies(List backsies) { final long time = DexTimeKeeper.fromDexTime(getTransmitterID(), backsie.getDextime()); final long since = JoH.msSince(time); - if ((since > HOUR_IN_MS * 6) || (since < 0)) { + if ((!shortTxId() && since > HOUR_IN_MS * 6) || (since > HOUR_IN_MS * 25) || (since < 0)) { UserError.Log.wtf(TAG, "Backfill timestamp unrealistic: " + JoH.dateTimeText(time) + " (ignored)"); } else { if (BgReading.getForPreciseTimestamp(time, Constants.MINUTE_IN_MS * 4) == null) { @@ -1675,6 +1919,7 @@ private static void processBacksies(List backsies) { } if (changed) { updateStreamedTillTimeForBackfill(); + Home.staticRefreshBGChartsOnIdle(); } } @@ -1688,8 +1933,8 @@ private static void monitorBackFill(Ob1G5CollectionService parent, RxBleConnecti .observeOn(Schedulers.newThread()) .flatMap(notificationObservable -> notificationObservable) .subscribe(bytes -> { - UserError.Log.d(TAG, "Received backfill notification bytes: " + JoH.bytesToHex(bytes)); - backfill.push(bytes); + UserError.Log.d(TAG, "Received backfill notification bytes: " + bytesToHex(bytes)); + backfill.pushNew(bytes); inevitableDisconnect(parent, connection); Inevitable.task("Process G5 backfill", 3000, () -> processBacksies(backfill.decode())); }, throwable -> { @@ -1744,7 +1989,8 @@ private static synchronized byte[] calculateChallengeHash(final byte[] challenge @SuppressLint("GetInstance") final Cipher aesCipher = Cipher.getInstance("AES/ECB/PKCS7Padding"); aesCipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); return Arrays.copyOfRange(aesCipher.doFinal(plainText, 0, plainText.length), 0, 8); - } catch (NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException | InvalidKeyException e) { + } catch (NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | + BadPaddingException | InvalidKeyException e) { UserError.Log.wtf(TAG, "System Encryption problem: " + e); return null; } @@ -1779,8 +2025,10 @@ private enum PACKET { SessionStopRxMessage, GlucoseRxMessage, EGlucoseRxMessage, + EGlucoseRxMessage2, CalibrateRxMessage, BackFillRxMessage, + BackFillControlRxMessage, TransmitterTimeRxMessage, BondRequestRxMessage, F2DUnknownRxMessage, @@ -1812,10 +2060,13 @@ private static PacketShop classifyPacket(byte[] packet) { case VersionRequestRxMessage.opcode: return new PacketShop(PACKET.VersionRequestRxMessage, new VersionRequestRxMessage(packet)); case VersionRequest1RxMessage.opcode: + case VersionRequest1RxMessage.opcode2: return new PacketShop(PACKET.VersionRequest1RxMessage, new VersionRequest1RxMessage(packet)); case VersionRequest2RxMessage.opcode: + case VersionRequest2RxMessage.opcode2: return new PacketShop(PACKET.VersionRequest2RxMessage, new VersionRequest2RxMessage(packet)); case BatteryInfoRxMessage.opcode: + case BatteryInfoRxMessage.opcode2: return new PacketShop(PACKET.BatteryInfoRxMessage, new BatteryInfoRxMessage(packet)); case SessionStartRxMessage.opcode: return new PacketShop(PACKET.SessionStartRxMessage, new SessionStartRxMessage(packet, getTransmitterID())); @@ -1829,10 +2080,14 @@ private static PacketShop classifyPacket(byte[] packet) { return new PacketShop(PACKET.CalibrateRxMessage, new CalibrateRxMessage(packet)); case BackFillRxMessage.opcode: return new PacketShop(PACKET.BackFillRxMessage, new BackFillRxMessage(packet)); + case BackFillControlRxMessage.opcode: + return new PacketShop(PACKET.BackFillControlRxMessage, new BackFillControlRxMessage(packet)); case TransmitterTimeRxMessage.opcode: return new PacketShop(PACKET.TransmitterTimeRxMessage, new TransmitterTimeRxMessage(packet)); case BondRequestTxMessage.opcode: return new PacketShop(PACKET.BondRequestRxMessage, null); + case EGlucoseRxMessage2.opcode: + return new PacketShop(PACKET.EGlucoseRxMessage2, new EGlucoseRxMessage2(packet)); case F2DUnknownRxMessage.opcode: return new PacketShop(PACKET.F2DUnknownRxMessage, new F2DUnknownRxMessage(packet)); case InvalidRxMessage.opcode: @@ -1850,9 +2105,9 @@ public static boolean usingG6() { return Pref.getBooleanDefaultFalse("using_g6"); } - private static boolean getEGlucose() { + private static boolean getEGlucose(final Ob1G5CollectionService parent) { // if (android_wear) { - return usingG6() && Pref.getBooleanDefaultFalse("show_g_prediction"); + return usingG6() && Pref.getBooleanDefaultFalse("show_g_prediction") || parent.plugin != null; // } else { // return usingG6(); // } @@ -1860,7 +2115,7 @@ private static boolean getEGlucose() { public static boolean usingAlt() { return (android_wear && !Pref.getBooleanDefaultFalse("only_ever_use_wear_collector")) - || WholeHouse.isLive(); + || (immediateBonding() && !ignoreBonding()) || WholeHouse.isLive(); } private static class OperationSuccess extends RuntimeException { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/Ob1Work.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/Ob1Work.java similarity index 94% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/Ob1Work.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/Ob1Work.java index ca7b899e1e..fbdb9788c7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/Ob1Work.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/Ob1Work.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.google.common.collect.ImmutableSet; import com.google.gson.annotations.Expose; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/RawScaling.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/RawScaling.java similarity index 89% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/RawScaling.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/RawScaling.java index 45bc18df74..01fa18de2e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/RawScaling.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/RawScaling.java @@ -1,8 +1,8 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; // jamorham -import static com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine.usingG6; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.usingG6; public class RawScaling { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/ResetTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/ResetTxMessage.java similarity index 61% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/ResetTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/ResetTxMessage.java index 063a432fb2..718c759752 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/ResetTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/ResetTxMessage.java @@ -1,7 +1,7 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SensorDays.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/SensorDays.java similarity index 82% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SensorDays.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/SensorDays.java index 490aeab4e6..6edcd8250f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SensorDays.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/SensorDays.java @@ -1,14 +1,13 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; import android.text.SpannableString; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.Sensor; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight; import com.eveningoutpost.dexdrip.ui.helpers.Span; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.xdrip; @@ -21,17 +20,18 @@ import lombok.Getter; import lombok.val; -import static com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine.getFirmwareXDetails; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.Models.JoH.roundDouble; -import static com.eveningoutpost.dexdrip.Models.JoH.tsl; -import static com.eveningoutpost.dexdrip.Services.G5BaseService.usingG6; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.getTransmitterID; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.usingNativeMode; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.DAY_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.HOUR_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.MINUTE_IN_MS; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.getFirmwareXDetails; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.roundDouble; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; +import static com.eveningoutpost.dexdrip.services.G5BaseService.usingG6; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.getTransmitterID; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.usingNativeMode; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.DAY_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.HOUR_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.None; +import static com.eveningoutpost.dexdrip.utils.DexCollectionType.getBestCollectorHardwareName; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.getDexCollectionType; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.hasDexcomRaw; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.hasLibre; @@ -103,6 +103,11 @@ public static SensorDays get(DexCollectionType type, final String tx_id) { ths.warmupMs = 2 * HOUR_IN_MS; } + if (getBestCollectorHardwareName().equals("G7")) { // If using a G7 + ths.period = DAY_IN_MS * 10 + HOUR_IN_MS * 12; // The device lasts 10.5 days. + ths.warmupMs = 30 * MINUTE_IN_MS; // The warmup time is 30 minutes. + } + } else { // unknown type } @@ -161,7 +166,7 @@ private boolean isStarted() { } // returns 0 if invalid - long getRemainingSensorPeriodInMs() { + public long getRemainingSensorPeriodInMs() { //UserError.Log.d(TAG, "Get start debug returns: " + JoH.dateTimeText(getStart())); if (isValid()) { val elapsed = msSince(getStart()); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SensorRxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/SensorRxMessage.java similarity index 81% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SensorRxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/SensorRxMessage.java index 6c6c4ec8d0..c5a674a192 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SensorRxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/SensorRxMessage.java @@ -1,8 +1,8 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.services.G5CollectionService; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SensorTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/SensorTxMessage.java similarity index 65% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SensorTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/SensorTxMessage.java index 570370415d..3a83363e6d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SensorTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/SensorTxMessage.java @@ -1,11 +1,9 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import java.nio.ByteBuffer; -import java.nio.ByteOrder; /** * Created by jcostik1 on 3/26/16. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SessionStartRxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/SessionStartRxMessage.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SessionStartRxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/SessionStartRxMessage.java index b0250bf083..3cfc7cb49a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SessionStartRxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/SessionStartRxMessage.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SessionStartTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/SessionStartTxMessage.java similarity index 92% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SessionStartTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/SessionStartTxMessage.java index 90d557b722..098721587f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SessionStartTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/SessionStartTxMessage.java @@ -1,7 +1,7 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SessionStopRxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/SessionStopRxMessage.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SessionStopRxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/SessionStopRxMessage.java index f8ae444e12..2867be169d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/SessionStopRxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/SessionStopRxMessage.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/SessionStopTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/SessionStopTxMessage.java similarity index 85% rename from wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/SessionStopTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/SessionStopTxMessage.java index 9fd46c0c5c..492e0447a7 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/SessionStopTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/SessionStopTxMessage.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; // created by jamorham diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/TimeTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/TimeTxMessage.java similarity index 78% rename from wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/TimeTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/TimeTxMessage.java index ff6f374240..e30054546d 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/TimeTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/TimeTxMessage.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/Transmitter.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/Transmitter.java similarity index 83% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/Transmitter.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/Transmitter.java index f7b47c16b6..ab05035a55 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/Transmitter.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/Transmitter.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; /** * Created by joeginley on 3/19/16. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/TransmitterMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/TransmitterMessage.java similarity index 90% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/TransmitterMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/TransmitterMessage.java index 211cbf2f9b..8e5f5e78d6 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/TransmitterMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/TransmitterMessage.java @@ -1,7 +1,7 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.services.G5CollectionService; import com.google.gson.annotations.Expose; import java.nio.ByteBuffer; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/TransmitterStatus.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/TransmitterStatus.java similarity index 91% rename from wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/TransmitterStatus.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/TransmitterStatus.java index 0272d86a86..e2ff9b931d 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/TransmitterStatus.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/TransmitterStatus.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; /** * Created by joeginley on 3/28/16. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/TransmitterTimeRxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/TransmitterTimeRxMessage.java similarity index 94% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/TransmitterTimeRxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/TransmitterTimeRxMessage.java index 38fe2bde3d..98614d27f5 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/TransmitterTimeRxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/TransmitterTimeRxMessage.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/TransmitterTimeTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/TransmitterTimeTxMessage.java similarity index 90% rename from wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/TransmitterTimeTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/TransmitterTimeTxMessage.java index 9f11c37ddf..72c009bbd7 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/TransmitterTimeTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/TransmitterTimeTxMessage.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; import java.nio.ByteBuffer; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/UnbondRequestTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/UnbondRequestTxMessage.java similarity index 87% rename from wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/UnbondRequestTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/UnbondRequestTxMessage.java index e7470a8c4d..15f7562352 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/UnbondRequestTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/UnbondRequestTxMessage.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; import java.nio.ByteBuffer; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/VersionRequest1RxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/VersionRequest1RxMessage.java similarity index 72% rename from wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/VersionRequest1RxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/VersionRequest1RxMessage.java index 48c2bbf322..b751c78641 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/G5Model/VersionRequest1RxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/VersionRequest1RxMessage.java @@ -1,9 +1,11 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.Locale; +import lombok.val; + /** * Created by jamorham on 25/11/2016. */ @@ -11,22 +13,25 @@ public class VersionRequest1RxMessage extends BaseMessage { public static final byte opcode = 0x4B; + public static final byte opcode2 = 0x4A; public int status; public String firmware_version_string; public long build_version; - public int version_code; + public long version_code; public int inactive_days; public int max_inactive_days; public int max_runtime_days; + public long serial; public VersionRequest1RxMessage(byte[] packet) { if (packet.length >= 18) { // TODO check CRC?? data = ByteBuffer.wrap(packet).order(ByteOrder.LITTLE_ENDIAN); - if (data.get() == opcode) { - status = data.get(); + val op = data.get(); + status = data.get(); + if (op == opcode) { firmware_version_string = dottedStringFromData(data, 4); build_version = getUnsignedInt(data); inactive_days = getUnsignedShort(data); @@ -35,6 +40,12 @@ public VersionRequest1RxMessage(byte[] packet) { max_inactive_days = getUnsignedShort(data); // crc } + if (op == opcode2) { + firmware_version_string = dottedStringFromData(data, 4); + build_version = getUnsignedInt(data); + version_code = getUnsignedInt(data); + serial = longFromData(data, 6); + } } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/VersionRequest2RxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/VersionRequest2RxMessage.java similarity index 64% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/VersionRequest2RxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/VersionRequest2RxMessage.java index d62115ccfb..42f4e38028 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/VersionRequest2RxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/VersionRequest2RxMessage.java @@ -1,10 +1,11 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.Locale; import lombok.Getter; +import lombok.val; /** * Created by jamorham on 25/11/2016. @@ -14,11 +15,15 @@ public class VersionRequest2RxMessage extends BaseMessage { public static final byte opcode = 0x53; + public static final byte opcode2 = 0x52; public int status; public int typicalSensorDays; public int featureBits; + public long lifeSeconds; public int warmupSeconds; + public int version1; + public int version2; @Getter public boolean type2; @@ -28,14 +33,22 @@ public VersionRequest2RxMessage(byte[] packet) { if (packet.length >= 9) { // TODO check CRC?? data = ByteBuffer.wrap(packet).order(ByteOrder.LITTLE_ENDIAN); - if (data.get() == opcode) { - status = data.get(); + val op = data.get(); + status = data.get(); + if (op == opcode) { typicalSensorDays = getUnsignedByte(data); featureBits = getUnsignedShort(data); warmupSeconds = getUnsignedShort(data); // only valid in type 2 // 12 more bytes of unknown data // crc } + if (op == opcode2) { + lifeSeconds = getUnsignedInt(data); + warmupSeconds = getUnsignedShort(data); + version1 = (int) getUnsignedInt(data); + version2 = getUnsignedByte(data); + typicalSensorDays = (int) Math.min(getUnsignedShort(data), lifeSeconds / 86400); + } } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/VersionRequestRxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/VersionRequestRxMessage.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/VersionRequestRxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/VersionRequestRxMessage.java index 30f7ecd3ca..dcbc5672db 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/VersionRequestRxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/VersionRequestRxMessage.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/VersionRequestTxMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/VersionRequestTxMessage.java similarity index 88% rename from app/src/main/java/com/eveningoutpost/dexdrip/G5Model/VersionRequestTxMessage.java rename to app/src/main/java/com/eveningoutpost/dexdrip/g5model/VersionRequestTxMessage.java index a1952ee037..57447f9c5a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/G5Model/VersionRequestTxMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/g5model/VersionRequestTxMessage.java @@ -1,7 +1,7 @@ -package com.eveningoutpost.dexdrip.G5Model; +package com.eveningoutpost.dexdrip.g5model; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; /** * Created by jamorham on 25/11/2016. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/BTGlucoseMeterActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/BTGlucoseMeterActivity.java index c3ced337fd..62e6fe5e43 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/BTGlucoseMeterActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/BTGlucoseMeterActivity.java @@ -13,7 +13,7 @@ import android.graphics.Color; import android.os.Build; import android.os.Bundle; -import android.support.v4.content.LocalBroadcastManager; + import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -25,17 +25,19 @@ import android.widget.TextView; import android.widget.Toast; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.BluetoothGlucoseMeter; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.services.BluetoothGlucoseMeter; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.ListActivityWithMenu; import com.eveningoutpost.dexdrip.utils.LocationHelper; import java.util.ArrayList; -import static com.eveningoutpost.dexdrip.Services.BluetoothGlucoseMeter.start_forget; +import static com.eveningoutpost.dexdrip.services.BluetoothGlucoseMeter.start_forget; + +import androidx.localbroadcastmanager.content.LocalBroadcastManager; /** * Created by jamorham on 09/12/2016. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/CurrentTimeRx.java b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/CurrentTimeRx.java index 70aff52367..cedf201d52 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/CurrentTimeRx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/CurrentTimeRx.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.glucosemeter; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/GlucoseReadingRx.java b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/GlucoseReadingRx.java index 108f51c0d2..c5cdeeb963 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/GlucoseReadingRx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/GlucoseReadingRx.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.glucosemeter; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/VerioHelper.java b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/VerioHelper.java index 40e24923a6..455c3954fc 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/VerioHelper.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/VerioHelper.java @@ -1,17 +1,17 @@ package com.eveningoutpost.dexdrip.glucosemeter; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Services.BluetoothGlucoseMeter; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.services.BluetoothGlucoseMeter; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.UUID; -import static com.eveningoutpost.dexdrip.Services.BluetoothGlucoseMeter.mBluetoothDeviceAddress; -import static com.eveningoutpost.dexdrip.Services.BluetoothGlucoseMeter.statusUpdate; +import static com.eveningoutpost.dexdrip.services.BluetoothGlucoseMeter.mBluetoothDeviceAddress; +import static com.eveningoutpost.dexdrip.services.BluetoothGlucoseMeter.statusUpdate; import static com.eveningoutpost.dexdrip.utils.CRC16ccitt.crc16ccitt; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/GlucoMen.java b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/GlucoMen.java index d2276c90a4..a2b42d0a59 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/GlucoMen.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/GlucoMen.java @@ -3,7 +3,7 @@ import android.nfc.Tag; import com.eveningoutpost.dexdrip.glucosemeter.glucomen.devices.Identify; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; /** * JamOrHam diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/GlucoMenNfc.java b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/GlucoMenNfc.java index 523e37b432..e9b987806e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/GlucoMenNfc.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/GlucoMenNfc.java @@ -14,9 +14,9 @@ import com.eveningoutpost.dexdrip.glucosemeter.glucomen.devices.Identify; import com.eveningoutpost.dexdrip.glucosemeter.glucomen.st.T5StRead; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.utils.jobs.BackgroundQueue; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/blocks/RecordBlock.java b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/blocks/RecordBlock.java index e434841d01..317d86c76c 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/blocks/RecordBlock.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/blocks/RecordBlock.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip.glucosemeter.glucomen.blocks; -import static com.eveningoutpost.dexdrip.Models.JoH.roundDouble; +import static com.eveningoutpost.dexdrip.models.JoH.roundDouble; -import com.eveningoutpost.dexdrip.UtilityModels.Unitized; +import com.eveningoutpost.dexdrip.utilitymodels.Unitized; import com.eveningoutpost.dexdrip.buffer.MyByteBuffer; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/blocks/SerialBlock.java b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/blocks/SerialBlock.java index 784abffb5d..547c5eba5c 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/blocks/SerialBlock.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/blocks/SerialBlock.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.glucosemeter.glucomen.blocks; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.buffer.MyByteBuffer; import lombok.AllArgsConstructor; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/data/ProcessingThread.java b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/data/ProcessingThread.java index 9129ed701f..6a3ae1f4fc 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/data/ProcessingThread.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/data/ProcessingThread.java @@ -2,19 +2,19 @@ import static com.eveningoutpost.dexdrip.glucosemeter.glucomen.GlucoMen.playSounds; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.Models.JoH.tsl; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.SECOND_IN_MS; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.SECOND_IN_MS; import com.eveningoutpost.dexdrip.glucosemeter.glucomen.GlucoMenNfc; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.LowPriorityThread; -import com.eveningoutpost.dexdrip.UtilityModels.Unitized; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.LowPriorityThread; +import com.eveningoutpost.dexdrip.utilitymodels.Unitized; import com.eveningoutpost.dexdrip.utils.jobs.BackgroundQueue; import lombok.Getter; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/devices/Identify.java b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/devices/Identify.java index e39f6edadc..b93aae2727 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/devices/Identify.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/glucosemeter/glucomen/devices/Identify.java @@ -2,8 +2,8 @@ import android.nfc.Tag; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.UserError; import lombok.val; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/healthconnect/Coroutines.kt b/app/src/main/java/com/eveningoutpost/dexdrip/healthconnect/Coroutines.kt new file mode 100644 index 0000000000..e9a5c6623f --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/healthconnect/Coroutines.kt @@ -0,0 +1,67 @@ +package com.eveningoutpost.dexdrip.healthconnect + +import android.annotation.TargetApi + +import android.os.Build +import androidx.annotation.RequiresApi +import androidx.health.connect.client.HealthConnectClient +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.DelicateCoroutinesApi +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking +import java.lang.RuntimeException +import java.util.function.BiConsumer +import kotlin.coroutines.Continuation +import kotlin.coroutines.CoroutineContext + +// jamorham + +object Coroutines { + @JvmOverloads + fun getContinuation( + onFinished: BiConsumer, + dispatcher: CoroutineDispatcher = Dispatchers.IO + ): Continuation { + return object : Continuation { + override val context: CoroutineContext + get() = dispatcher + + @TargetApi(Build.VERSION_CODES.N) + override fun resumeWith(result: Result) { + onFinished.accept(result.getOrNull(), result.exceptionOrNull()) + } + } + } + + fun interface FunctionWrapperWithBiConsumer { + fun apply(t: T, resultHandler: BiConsumer?) + } + + @OptIn(DelicateCoroutinesApi::class) + @RequiresApi(Build.VERSION_CODES.N) + @JvmStatic + // Note: the fact that this anti-pattern is needed shows the imprecision of kotlin and lack of interoperability + fun suspendFunction(fn: (T) -> R): FunctionWrapperWithBiConsumer { + return FunctionWrapperWithBiConsumer { t, resultHandler -> + if (resultHandler == null) throw RuntimeException("result handler was null!") + GlobalScope.launch(Dispatchers.IO) { + try { + val result = fn(t) + resultHandler.accept(result, null) + } catch (e: Throwable) { + resultHandler.accept(null, e) + } + } + } + } + + @JvmStatic + fun getGrantedPermissions(healthConnectClient: HealthConnectClient): Set { + return runBlocking { + return@runBlocking healthConnectClient.permissionController.getGrantedPermissions() + } + } +} + diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/healthconnect/DataReply.java b/app/src/main/java/com/eveningoutpost/dexdrip/healthconnect/DataReply.java new file mode 100644 index 0000000000..2dbce2ebbe --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/healthconnect/DataReply.java @@ -0,0 +1,25 @@ +package com.eveningoutpost.dexdrip.healthconnect; + +import static com.eveningoutpost.dexdrip.models.JoH.defaultGsonInstance; + +import androidx.health.connect.client.records.HeartRateRecord; +import androidx.health.connect.client.records.StepsRecord; + +import com.google.gson.annotations.Expose; + +import java.util.List; + +// jamorham + +public class DataReply { + @Expose + public List stepsRecords; + @Expose + public List heartRateRecords; + + public static DataReply fromJson(final String json) { + return defaultGsonInstance().fromJson(json, DataReply.class); + } + +} + diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/healthconnect/HealthConnectEntry.java b/app/src/main/java/com/eveningoutpost/dexdrip/healthconnect/HealthConnectEntry.java new file mode 100644 index 0000000000..5901dae4ce --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/healthconnect/HealthConnectEntry.java @@ -0,0 +1,34 @@ +package com.eveningoutpost.dexdrip.healthconnect; + +import android.os.Build; + +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; + +// jamorham + +public class HealthConnectEntry { + + public static boolean enabled() { + return Pref.getBooleanDefaultFalse("health_connect_enable"); + } + + public static boolean sendEnabled() { + return enabled() && Pref.getBooleanDefaultFalse("health_connect_send"); + } + + public static boolean receiveEnabled() { + return enabled() && Pref.getBooleanDefaultFalse("health_connect_receive"); + } + + public static void ping() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (receiveEnabled()) { + if (JoH.ratelimit("health-connect-read", 290)) { + HealthGamut.ping(); + } + } + } + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/healthconnect/HealthGamut.java b/app/src/main/java/com/eveningoutpost/dexdrip/healthconnect/HealthGamut.java new file mode 100644 index 0000000000..722ca53a73 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/healthconnect/HealthGamut.java @@ -0,0 +1,379 @@ +package com.eveningoutpost.dexdrip.healthconnect; + +import static com.eveningoutpost.dexdrip.healthconnect.Coroutines.suspendFunction; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.HEALTH_CONNECT_RESPONSE_ID; +import static kotlin.jvm.internal.Reflection.createKotlinClass; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.os.Build; +import androidx.core.app.ActivityCompat; + +import androidx.annotation.RequiresApi; +import androidx.health.connect.client.HealthConnectClient; +import androidx.health.connect.client.PermissionController; +import androidx.health.connect.client.changes.Change; +import androidx.health.connect.client.changes.UpsertionChange; +import androidx.health.connect.client.permission.HealthPermission; +import androidx.health.connect.client.records.BloodGlucoseRecord; +import androidx.health.connect.client.records.DistanceRecord; +import androidx.health.connect.client.records.ElevationGainedRecord; +import androidx.health.connect.client.records.ExerciseSessionRecord; +import androidx.health.connect.client.records.FloorsClimbedRecord; +import androidx.health.connect.client.records.HeartRateRecord; +import androidx.health.connect.client.records.HeartRateVariabilityRmssdRecord; +import androidx.health.connect.client.records.HeightRecord; +import androidx.health.connect.client.records.HydrationRecord; +import androidx.health.connect.client.records.MealType; +import androidx.health.connect.client.records.NutritionRecord; +import androidx.health.connect.client.records.PowerRecord; +import androidx.health.connect.client.records.Record; +import androidx.health.connect.client.records.RestingHeartRateRecord; +import androidx.health.connect.client.records.SleepSessionRecord; +import androidx.health.connect.client.records.SpeedRecord; +import androidx.health.connect.client.records.StepsRecord; +import androidx.health.connect.client.records.TotalCaloriesBurnedRecord; +import androidx.health.connect.client.records.WeightRecord; +import androidx.health.connect.client.records.WheelchairPushesRecord; +import androidx.health.connect.client.records.metadata.Metadata; +import androidx.health.connect.client.request.ChangesTokenRequest; +import androidx.health.connect.client.request.ReadRecordsRequest; +import androidx.health.connect.client.time.TimeRangeFilter; +import androidx.health.connect.client.units.BloodGlucose; + +import com.eveningoutpost.dexdrip.BuildConfig; +import com.eveningoutpost.dexdrip.R; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.xdrip; + +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import java.util.Set; + + +import kotlin.reflect.KClass; +import lombok.RequiredArgsConstructor; +import lombok.val; + +// jamorham + +@RequiredArgsConstructor +@RequiresApi(api = Build.VERSION_CODES.O) +@SuppressWarnings("unchecked") +public class HealthGamut { + + private static final String TAG = HealthGamut.class.getSimpleName(); + + private static final String[] fullPermissionList = { + HealthPermission.getReadPermission(createKotlinClass(ExerciseSessionRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(SleepSessionRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(StepsRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(SpeedRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(DistanceRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(TotalCaloriesBurnedRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(HeartRateRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(HeartRateVariabilityRmssdRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(RestingHeartRateRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(ElevationGainedRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(FloorsClimbedRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(HeightRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(WeightRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(WheelchairPushesRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(PowerRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(BloodGlucoseRecord.class)), + HealthPermission.getWritePermission(createKotlinClass(BloodGlucoseRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(HydrationRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(NutritionRecord.class)), + HealthPermission.getWritePermission(createKotlinClass(NutritionRecord.class)) + }; + + private static final String[] minimalPermissionList = { + HealthPermission.getReadPermission(createKotlinClass(StepsRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(HeartRateRecord.class)), + HealthPermission.getReadPermission(createKotlinClass(BloodGlucoseRecord.class)), + HealthPermission.getWritePermission(createKotlinClass(BloodGlucoseRecord.class)) + }; + private static final List> recordList = new LinkedList<>(); + + static { + recordList.add(createKotlinClass(StepsRecord.class)); + recordList.add(createKotlinClass(HeartRateRecord.class)); + } + + private static final Set permissions = new HashSet<>(Arrays.asList(fullPermissionList)); + private static final Set minimalPermissions = new HashSet<>(Arrays.asList(minimalPermissionList)); + private static final Set> records = new HashSet<>(recordList); + + private static volatile String token = null; + + private final Context context; + private HealthConnectClient client; + + private final Coroutines coroutines = Coroutines.INSTANCE; + + @RequiresApi(api = Build.VERSION_CODES.O) + public boolean init() { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + Log.e(TAG, "Needs above android 8"); + return false; + } + + if (HealthConnectClient.getSdkStatus(context) == HealthConnectClient.SDK_AVAILABLE) { + client = HealthConnectClient.getOrCreate(context); + try { + suspendFunction(Coroutines::getGrantedPermissions).apply(client, (result, throwable) -> { + try { + if (throwable != null) { + throw new RuntimeException(throwable); + } + + if (!result.containsAll(minimalPermissions)) { + Log.d(TAG, "Need permissions!"); + + if (Build.VERSION.SDK_INT >= 34) { + askPermsNew(); + } else { + askPermsOld(); + } + + } else { + Log.d(TAG, "Got permissions!"); + getAllDataIfEnabled(); + } + } catch (Exception e) { + Log.e(TAG, "Failed to get permissions: " + e); + } + }); + } catch (Exception e) { + Log.d(TAG, "got exception in permissions get granted: " + e); + } + return true; + } else { + Log.e(TAG, "Companion app not available - asking for installation"); + + val url = Uri.parse("market://details") + .buildUpon() + .appendQueryParameter("id", "com.google.android.apps.healthdata") + .appendQueryParameter("url", "healthconnect://onboarding") + .build(); + val intent = new Intent(Intent.ACTION_VIEW, url); + + JoH.runOnUiThread(() -> { + if (context instanceof Activity) { + ((Activity) context).startActivityForResult(intent, HEALTH_CONNECT_RESPONSE_ID); + } else { + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + } + + }); + } + return false; + } + + private void askPermsNew() { + val permsIntent = PermissionController.createRequestPermissionResultContract().createIntent(context, permissions); + JoH.runOnUiThread(() -> { + try { + if (context instanceof Activity) { + ActivityCompat.requestPermissions((Activity) context, + Objects.requireNonNull(permsIntent.getStringArrayExtra("androidx.activity.result.contract.extra.PERMISSIONS")), HEALTH_CONNECT_RESPONSE_ID); + } else { + JoH.static_toast_long(xdrip.gs(R.string.google_health_connect_needs_perms)); + } + } catch (Exception e) { + Log.e(TAG, "Cannot start permissions request: " + e); + } + }); + } + + private void askPermsOld() { + val permsIntent = PermissionController.createRequestPermissionResultContract().createIntent(context, permissions); + JoH.runOnUiThread(() -> { + try { + if (context instanceof Activity) { + ((Activity) context).startActivityForResult(permsIntent, HEALTH_CONNECT_RESPONSE_ID); + } else { + JoH.static_toast_long(xdrip.gs(R.string.google_health_connect_needs_perms)); + } + } catch (Exception e) { + Log.e(TAG, "Cannot start permissions request: " + e); + } + }); + } + + public void openPermissionManager() { + JoH.runOnUiThread(() -> { + try { + if (context instanceof Activity) { + if (Build.VERSION.SDK_INT >= 34) { + val intent = + new Intent("android.health.connect.action.MANAGE_HEALTH_PERMISSIONS") + .putExtra(Intent.EXTRA_PACKAGE_NAME, BuildConfig.APPLICATION_ID); + ((Activity) context).startActivity(intent); + } else { + val intent = new Intent("androidx.health.ACTION_HEALTH_CONNECT_SETTINGS"); + ((Activity) context).startActivity(intent); + } + + } else { + JoH.static_toast_long(xdrip.gs(R.string.google_health_connect_needs_perms)); + } + } catch (Exception e) { + Log.e(TAG, "Cannot start permissions request: " + e); + } + }); + } + + public static HealthGamut init(Activity activity) { + val instance = new HealthGamut(activity); + instance.init(); + return instance; + } + + public static void ping() { + new HealthGamut(xdrip.getAppContext()).init(); + } + + public static void sendGlucoseStatic(final BgReading bg) { + new HealthGamut(xdrip.getAppContext()).sendGlucose(bg); + } + + public void getAllDataIfEnabled() { + if (HealthConnectEntry.receiveEnabled()) { + getAllData(); + } + } + + @RequiresApi(api = Build.VERSION_CODES.O) + public synchronized void getAllData() { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return; + val startTime = Instant.now().minus(1, ChronoUnit.DAYS); + val endTime = Instant.now(); + val reply = new DataReply(); + + try { + if (token != null) { + if (JoH.ratelimit("health-connect-use-token", 1)) { + client.getChanges(token, coroutines.getContinuation((result, throwable) -> { + token = null; + if (throwable != null) { + Log.e(TAG, "Got exception during changes: " + throwable); + return; + } + try { + token = result.getNextChangesToken(); + reply.stepsRecords = new LinkedList<>(); + reply.heartRateRecords = new LinkedList<>(); + int ups = 0; + for (Change change : result.getChanges()) { + if (change instanceof UpsertionChange) { + ups++; + UpsertionChange cu = (UpsertionChange) change; + val record = cu.getRecord(); + if (record instanceof StepsRecord) { + reply.stepsRecords.add((StepsRecord) record); + } + if (record instanceof HeartRateRecord) { + reply.heartRateRecords.add((HeartRateRecord) record); + } + } else { + Log.d(TAG, "Unhandled change record of type: " + change.getClass().getSimpleName()); + } + } + Log.d(TAG, "Processed changes of count: " + ups); + if (ups > 0) { + ReadReplyProcessor.process(reply); + } + } catch (Exception e) { + Log.e(TAG, "Exception processing changes: " + e); + } + })); + } + return; + } + } catch (Exception e) { + Log.e(TAG, "Exception trying to get changes: " + e); + } + + client.readRecords(new ReadRecordsRequest(createKotlinClass(StepsRecord.class), + TimeRangeFilter.between(startTime, endTime), + Collections.emptySet(), + false, + 1000, + null), coroutines.getContinuation((result, throwable) -> { + + try { + if (throwable != null) { + throw new RuntimeException(throwable); + } + reply.stepsRecords = result.getRecords(); + + client.readRecords(new ReadRecordsRequest(createKotlinClass(HeartRateRecord.class), + TimeRangeFilter.between(startTime, endTime), + Collections.emptySet(), + false, + 1000, + null), coroutines.getContinuation((result2, throwable2) -> { + + try { + if (throwable2 != null) { + throw new RuntimeException(throwable2); + } + reply.heartRateRecords = result2.getRecords(); + + } catch (Exception e) { + Log.e(TAG, "Failed to read hr records: " + e); + } + })); + + ReadReplyProcessor.process(reply); + + client.getChangesToken(new ChangesTokenRequest(records, new HashSet<>()), + coroutines.getContinuation((tokenResult, throwable3) -> { + if (throwable3 != null) { + throw new RuntimeException(throwable3); + } + + Log.d(TAG, "Changes token: " + tokenResult); + token = tokenResult; + })); + + + } catch (Exception e) { + Log.e(TAG, "Failed to read records: " + e); + } + })); + } + + public void sendGlucose(final BgReading bg) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return; + if (init()) { + val list = new LinkedList(); + val record = new BloodGlucoseRecord(Instant.ofEpochMilli(bg.timestamp), + null, BloodGlucose.milligramsPerDeciliter(bg.calculated_value), + BloodGlucoseRecord.SPECIMEN_SOURCE_INTERSTITIAL_FLUID, + MealType.MEAL_TYPE_UNKNOWN, BloodGlucoseRecord.RELATION_TO_MEAL_UNKNOWN, new Metadata()); + list.add(record); + client.insertRecords(list, coroutines.getContinuation((result, throwable) -> { + try { + Log.d(TAG, "Insert result: " + result.getRecordIdsList().size()); + } catch (Exception e) { + Log.e(TAG, "Got exception on insert: " + e); + } + })); + } else { + Log.e(TAG, "Could not send Glucose"); + } + } +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/healthconnect/ReadReplyProcessor.java b/app/src/main/java/com/eveningoutpost/dexdrip/healthconnect/ReadReplyProcessor.java new file mode 100644 index 0000000000..e91ae7c5b3 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/healthconnect/ReadReplyProcessor.java @@ -0,0 +1,44 @@ +package com.eveningoutpost.dexdrip.healthconnect; + +import android.os.Build; + +import androidx.annotation.RequiresApi; + +import com.eveningoutpost.dexdrip.models.HeartRate; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.StepCounter; +import com.eveningoutpost.dexdrip.models.UserError; + +import lombok.val; + +// jamorham + +@RequiresApi(api = Build.VERSION_CODES.O) +public class ReadReplyProcessor { + + private static final String TAG = ReadReplyProcessor.class.getSimpleName(); + + public static void process(final DataReply dataReply) { + if (dataReply == null) { + UserError.Log.d(TAG, "Null reply"); + return; + } + + if (dataReply.stepsRecords != null) { + for (val item : dataReply.stepsRecords) { + StepCounter.createUniqueRecord(item.getStartTime().toEpochMilli() + ((item.getEndTime().toEpochMilli() - item.getStartTime().toEpochMilli()) / 2), + (int) item.getCount(), + true); + } + } + + if (dataReply.heartRateRecords != null) { + for (val item : dataReply.heartRateRecords) { + for (val i : item.getSamples()) { + UserError.Log.d(TAG, "heart rate: " + JoH.dateTimeText(i.getTime().toEpochMilli()) + " bpm:" + i.getBeatsPerMinute()); + HeartRate.create(i.getTime().toEpochMilli(), (int) i.getBeatsPerMinute(), 1); + } + } + } + } +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/CRC16.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/CRC16.java similarity index 92% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/CRC16.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/CRC16.java index ec5092c6ac..c184aab4a6 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/CRC16.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/CRC16.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom; // This code and this particular library are from the NightScout android uploader // Check them out here: https://github.com/nightscout/android-uploader diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/CRCFailRuntimeException.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/CRCFailRuntimeException.java similarity index 85% rename from wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/CRCFailRuntimeException.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/CRCFailRuntimeException.java index 9f7fdb1a7b..7ceed1baaa 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/CRCFailRuntimeException.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/CRCFailRuntimeException.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom; // This code and this particular library are from the NightScout android uploader // Check them out here: https://github.com/nightscout/android-uploader diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/Dex_Constants.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/Dex_Constants.java similarity index 99% rename from wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/Dex_Constants.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/Dex_Constants.java index a66bbef27f..af6471cb3d 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/Dex_Constants.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/Dex_Constants.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom; // This code and this particular library are from the NightScout android uploader // Check them out here: https://github.com/nightscout/android-uploader diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/PacketBuilder.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/PacketBuilder.java similarity index 97% rename from wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/PacketBuilder.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/PacketBuilder.java index 72134cfa62..2c38898ef8 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/PacketBuilder.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/PacketBuilder.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/ReadData.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/ReadData.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/ReadData.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/ReadData.java index c49e6b212b..e102e09aae 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/ReadData.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/ReadData.java @@ -1,16 +1,16 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbDeviceConnection; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.CalRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.EGVRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.GenericXMLRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.MeterRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.PageHeader; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.SensorRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.driver.UsbSerialDriver; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.CalRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.EGVRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.GenericXMLRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.MeterRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.PageHeader; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.SensorRecord; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver.UsbSerialDriver; +import com.eveningoutpost.dexdrip.models.UserError.Log; import org.w3c.dom.Element; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/ReadDataShare.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/ReadDataShare.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/ReadDataShare.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/ReadDataShare.java index 2305645d9e..85c638b1a2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/ReadDataShare.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/ReadDataShare.java @@ -1,14 +1,14 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.CalRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.EGVRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.GenericXMLRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.MeterRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.PageHeader; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.SensorRecord; -import com.eveningoutpost.dexdrip.Services.DexShareCollectionService; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.CalRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.EGVRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.GenericXMLRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.MeterRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.PageHeader; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.SensorRecord; +import com.eveningoutpost.dexdrip.services.DexShareCollectionService; import com.eveningoutpost.dexdrip.ShareTest; import org.w3c.dom.Element; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/ReadPacket.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/ReadPacket.java similarity index 95% rename from wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/ReadPacket.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/ReadPacket.java index f84f20c61f..949aa8d8a0 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/ReadPacket.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/ReadPacket.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom; import java.util.Arrays; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/SyncingService.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/SyncingService.java similarity index 94% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/SyncingService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/SyncingService.java index c06b48aedb..35c00c0e69 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/SyncingService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/SyncingService.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom; import android.app.IntentService; import android.content.Context; @@ -10,19 +10,19 @@ import android.os.PowerManager; import android.preference.PreferenceManager; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.CalRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.EGVRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.GlucoseDataSet; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.MeterRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.SensorRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.driver.CdcAcmSerialDriver; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.driver.ProbeTable; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.driver.UsbSerialDriver; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.driver.UsbSerialProber; -import com.eveningoutpost.dexdrip.Models.Calibration; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.CalRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.EGVRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.GlucoseDataSet; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.MeterRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.SensorRecord; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver.CdcAcmSerialDriver; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver.ProbeTable; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver.UsbSerialDriver; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver.UsbSerialProber; +import com.eveningoutpost.dexdrip.models.Calibration; import org.json.JSONArray; @@ -44,11 +44,11 @@ public class SyncingService extends IntentService { // Action for intent - private static final String ACTION_SYNC = "com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.action.SYNC"; + private static final String ACTION_SYNC = "com.eveningoutpost.dexdrip.importedlibraries.dexcom.action.SYNC"; private static final String ACTION_CALIBRATION_CHECKIN = "com.eveningoutpost.dexdrip.CalibrationCheckInActivity"; // Parameters for intent - private static final String SYNC_PERIOD = "com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.extra.SYNC_PERIOD"; + private static final String SYNC_PERIOD = "com.eveningoutpost.dexdrip.importedlibraries.dexcom.extra.SYNC_PERIOD"; // Response to broadcast to activity public static final String RESPONSE_SGV = "mySGV"; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/Utils.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/Utils.java similarity index 91% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/Utils.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/Utils.java index ca698538dc..81e76dca6a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/Utils.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/Utils.java @@ -1,8 +1,8 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.EGVRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.GlucoseDataSet; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.SensorRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.EGVRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.GlucoseDataSet; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.SensorRecord; import java.util.Date; import java.util.TimeZone; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/CalRecord.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/CalRecord.java similarity index 94% rename from wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/CalRecord.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/CalRecord.java index 8353cea430..bff6cd027b 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/CalRecord.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/CalRecord.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom.records; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/CalSubrecord.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/CalSubrecord.java similarity index 88% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/CalSubrecord.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/CalSubrecord.java index be2f954223..3b85f054e0 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/CalSubrecord.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/CalSubrecord.java @@ -1,8 +1,6 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom.records; -import com.eveningoutpost.dexdrip.Models.UserError.Log; - -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Utils; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.Utils; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/EGVRecord.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/EGVRecord.java similarity index 93% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/EGVRecord.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/EGVRecord.java index 6d2c378e55..9f276023b1 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/EGVRecord.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/EGVRecord.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom.records; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants; import org.json.JSONException; import org.json.JSONObject; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/GenericTimestampRecord.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/GenericTimestampRecord.java similarity index 91% rename from wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/GenericTimestampRecord.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/GenericTimestampRecord.java index d1b09d4c42..da4fa39c43 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/GenericTimestampRecord.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/GenericTimestampRecord.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom.records; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Utils; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.Utils; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/GenericXMLRecord.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/GenericXMLRecord.java similarity index 91% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/GenericXMLRecord.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/GenericXMLRecord.java index 73137ac4ae..67729f72e0 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/GenericXMLRecord.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/GenericXMLRecord.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom.records; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -8,7 +8,7 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import java.io.Serializable; + import java.io.StringReader; import java.util.Arrays; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/GlucoseDataSet.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/GlucoseDataSet.java similarity index 92% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/GlucoseDataSet.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/GlucoseDataSet.java index 13bbbb3999..8e665241ca 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/GlucoseDataSet.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/GlucoseDataSet.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom.records; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants; import java.util.Date; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/MeterRecord.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/MeterRecord.java similarity index 92% rename from wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/MeterRecord.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/MeterRecord.java index 3187923883..2a313808d0 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/MeterRecord.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/MeterRecord.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom.records; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/PageHeader.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/PageHeader.java similarity index 88% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/PageHeader.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/PageHeader.java index a831d4edf4..9db81c6b10 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/PageHeader.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/PageHeader.java @@ -1,11 +1,11 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom.records; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.CRC16; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.CRCFailRuntimeException; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Utils; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.CRC16; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.CRCFailRuntimeException; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.Utils; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/SensorRecord.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/SensorRecord.java similarity index 91% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/SensorRecord.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/SensorRecord.java index 033ad6f53f..9750d62c31 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/dexcom/records/SensorRecord.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/dexcom/records/SensorRecord.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records; +package com.eveningoutpost.dexdrip.importedlibraries.dexcom.records; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/BuildInfo.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/BuildInfo.java similarity index 87% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/BuildInfo.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/BuildInfo.java index 012c47b981..d4a75c0315 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/BuildInfo.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/BuildInfo.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.ImportedLibraries.usbserial; +package com.eveningoutpost.dexdrip.importedlibraries.usbserial; /** * Static container of information about this library. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/CdcAcmSerialDriver.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/CdcAcmSerialDriver.java similarity index 99% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/CdcAcmSerialDriver.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/CdcAcmSerialDriver.java index 2aadb1d3b2..c5f837e384 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/CdcAcmSerialDriver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/CdcAcmSerialDriver.java @@ -19,7 +19,7 @@ * Project home page: https://github.com/mik3y/usb-serial-for-android */ -package com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.driver; +package com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver; import android.hardware.usb.UsbConstants; import android.hardware.usb.UsbDevice; @@ -28,7 +28,7 @@ import android.hardware.usb.UsbInterface; import android.hardware.usb.UsbRequest; import android.os.Build; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; import java.io.IOException; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/CommonUsbSerialPort.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/CommonUsbSerialPort.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/CommonUsbSerialPort.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/CommonUsbSerialPort.java index eb0adf28f2..88800fcda0 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/CommonUsbSerialPort.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/CommonUsbSerialPort.java @@ -19,7 +19,7 @@ * Project home page: https://github.com/mik3y/usb-serial-for-android */ -package com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.driver; +package com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbDeviceConnection; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/Cp21xxSerialDriver.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/Cp21xxSerialDriver.java similarity index 99% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/Cp21xxSerialDriver.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/Cp21xxSerialDriver.java index 535e18bfa5..ef99bff178 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/Cp21xxSerialDriver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/Cp21xxSerialDriver.java @@ -19,7 +19,7 @@ * Project home page: https://github.com/mik3y/usb-serial-for-android */ -package com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.driver; +package com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver; import android.hardware.usb.UsbConstants; import android.hardware.usb.UsbDevice; @@ -27,7 +27,7 @@ import android.hardware.usb.UsbEndpoint; import android.hardware.usb.UsbInterface; import android.hardware.usb.UsbRequest; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; import java.io.IOException; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/FtdiSerialDriver.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/FtdiSerialDriver.java similarity index 99% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/FtdiSerialDriver.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/FtdiSerialDriver.java index 7506629cd4..611ee35cd8 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/FtdiSerialDriver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/FtdiSerialDriver.java @@ -19,16 +19,16 @@ * Project home page: https://github.com/mik3y/usb-serial-for-android */ -package com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.driver; +package com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver; import android.hardware.usb.UsbConstants; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbDeviceConnection; import android.hardware.usb.UsbEndpoint; import android.hardware.usb.UsbRequest; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; import java.io.IOException; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/ProbeTable.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/ProbeTable.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/ProbeTable.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/ProbeTable.java index 001943dfcf..30e4100d67 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/ProbeTable.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/ProbeTable.java @@ -19,7 +19,7 @@ * Project home page: https://github.com/mik3y/usb-serial-for-android */ -package com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.driver; +package com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver; import android.util.Pair; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/ProlificSerialDriver.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/ProlificSerialDriver.java similarity index 99% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/ProlificSerialDriver.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/ProlificSerialDriver.java index d666d185eb..947cbd640a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/ProlificSerialDriver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/ProlificSerialDriver.java @@ -25,7 +25,7 @@ * See https://github.com/eblot/pyftdi */ -package com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.driver; +package com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver; import android.hardware.usb.UsbConstants; import android.hardware.usb.UsbDevice; @@ -33,7 +33,7 @@ import android.hardware.usb.UsbEndpoint; import android.hardware.usb.UsbInterface; import android.hardware.usb.UsbRequest; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; import java.io.IOException; import java.lang.reflect.Method; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/UsbId.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/UsbId.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/UsbId.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/UsbId.java index c2467b1b45..ae1a1a34e7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/UsbId.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/UsbId.java @@ -19,7 +19,7 @@ * Project home page: https://github.com/mik3y/usb-serial-for-android */ -package com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.driver; +package com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver; /** * Registry of USB vendor/product ID constants. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/UsbSerialDriver.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/UsbSerialDriver.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/UsbSerialDriver.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/UsbSerialDriver.java index 08ac5e57fe..908a6185a9 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/UsbSerialDriver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/UsbSerialDriver.java @@ -19,7 +19,7 @@ * Project home page: https://github.com/mik3y/usb-serial-for-android */ -package com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.driver; +package com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver; import android.hardware.usb.UsbDevice; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/UsbSerialPort.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/UsbSerialPort.java similarity index 99% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/UsbSerialPort.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/UsbSerialPort.java index 8131baa8fc..1b4d3116a6 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/UsbSerialPort.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/UsbSerialPort.java @@ -19,7 +19,7 @@ * Project home page: https://github.com/mik3y/usb-serial-for-android */ -package com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.driver; +package com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver; import android.hardware.usb.UsbDeviceConnection; import android.hardware.usb.UsbManager; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/UsbSerialProber.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/UsbSerialProber.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/UsbSerialProber.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/UsbSerialProber.java index 54507ce080..97e4133462 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/UsbSerialProber.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/UsbSerialProber.java @@ -19,12 +19,12 @@ * Project home page: https://github.com/mik3y/usb-serial-for-android */ -package com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.driver; +package com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbManager; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/UsbSerialRuntimeException.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/UsbSerialRuntimeException.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/UsbSerialRuntimeException.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/UsbSerialRuntimeException.java index e4e971090b..853c6522ca 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/driver/UsbSerialRuntimeException.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/driver/UsbSerialRuntimeException.java @@ -17,7 +17,7 @@ * USA. */ -package com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.driver; +package com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver; /** * Generic unchecked exception for the usbserial package. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/util/HexDump.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/util/HexDump.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/util/HexDump.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/util/HexDump.java index 023e41a80c..cb456e54a9 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/util/HexDump.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/util/HexDump.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util; +package com.eveningoutpost.dexdrip.importedlibraries.usbserial.util; /** * Clone of Android's HexDump class, for use in debugging. Cosmetic changes diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/util/SerialInputOutputManager.java b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/util/SerialInputOutputManager.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/util/SerialInputOutputManager.java rename to app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/util/SerialInputOutputManager.java index 8267c48159..8ddfe8aa1d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ImportedLibraries/usbserial/util/SerialInputOutputManager.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/importedlibraries/usbserial/util/SerialInputOutputManager.java @@ -19,12 +19,12 @@ * Project home page: https://github.com/mik3y/usb-serial-for-android */ -package com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util; +package com.eveningoutpost.dexdrip.importedlibraries.usbserial.util; import android.hardware.usb.UsbRequest; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.driver.UsbSerialPort; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver.UsbSerialPort; import java.io.IOException; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/InfluxDB/InfluxDBUploader.java b/app/src/main/java/com/eveningoutpost/dexdrip/influxdb/InfluxDBUploader.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/InfluxDB/InfluxDBUploader.java rename to app/src/main/java/com/eveningoutpost/dexdrip/influxdb/InfluxDBUploader.java index d714a1f32c..0feb5f1c6e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/InfluxDB/InfluxDBUploader.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/influxdb/InfluxDBUploader.java @@ -4,15 +4,15 @@ */ -package com.eveningoutpost.dexdrip.InfluxDB; +package com.eveningoutpost.dexdrip.influxdb; import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.UserError.Log; import org.influxdb.InfluxDB; import org.influxdb.InfluxDBFactory; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/InsulinManager.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/InsulinManager.java index 46ae64856f..8e2d3aae8e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/InsulinManager.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/InsulinManager.java @@ -2,13 +2,15 @@ import android.util.Log; +import androidx.annotation.Keep; + import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.xdrip; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import com.google.gson.annotations.Expose; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -20,7 +22,9 @@ public class InsulinManager { private static ArrayList profiles; private static volatile Insulin basalProfile, bolusProfile; + @Keep class insulinDataWrapper { + @Expose public ArrayList profiles; insulinDataWrapper() { @@ -53,24 +57,33 @@ private Boolean checkUniquenessPPN() { for (insulinData d : profiles) for (String ppn : d.PPN) if (PPNs.contains(ppn)) { - Log.d(TAG, "pharmacy product number dupplicated " + ppn + ". that's not allowed!"); + Log.d(TAG, "pharmacy product number duplicated " + ppn + ". That's not allowed!"); return false; } else PPNs.add(ppn); - Log.d(TAG, "pharmacy product numbers uniquee"); + Log.d(TAG, "pharmacy product numbers unique"); return true; } } + @Keep class insulinCurve { + @Expose public String type; + @Expose public JsonObject data; } + @Keep class insulinData { + @Expose public String displayName; + @Expose public String name; + @Expose public ArrayList PPN; + @Expose public String concentration; + @Expose public insulinCurve Curve; } @@ -97,6 +110,7 @@ private static void initializeInsulinManager(InputStream in_s) { insulinDataWrapper iDW; try { String input = readTextFile(in_s); + Log.d(TAG,"read text bytes: " + input.length()); Gson gson = new Gson(); iDW = gson.fromJson(input, insulinDataWrapper.class); profiles = iDW.getInsulinProfiles(); @@ -145,6 +159,9 @@ public static void setBolusProfile(Insulin p) { } public static ArrayList getAllProfiles() { + if (profiles == null) { + InsulinManager.getDefaultInstance(); // this entire feature needs a serious rework + } return profiles; } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/InsulinProfileEditor.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/InsulinProfileEditor.java index 92789b895e..a5722af830 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/InsulinProfileEditor.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/InsulinProfileEditor.java @@ -11,10 +11,13 @@ import com.eveningoutpost.dexdrip.BaseAppCompatActivity; import com.eveningoutpost.dexdrip.R; +import com.eveningoutpost.dexdrip.models.JoH; import java.util.ArrayList; import java.util.HashMap; +import lombok.val; + /** * Created by gruoner on 28/07/2019. */ @@ -50,7 +53,13 @@ protected void onCreate(Bundle savedInstanceState) { basalSpinner = (Spinner) findViewById(R.id.basalSpinner); bolusSpinner = (Spinner) findViewById(R.id.bolusSpinner); - for (Insulin i : InsulinManager.getAllProfiles()) { + val iprofiles = InsulinManager.getAllProfiles(); + if (iprofiles == null) { + JoH.static_toast_long("Can't initialize insulin profiles"); + finish(); + return; + } + for (Insulin i : iprofiles) { LinearLayout v = new LinearLayout(this); v.setOrientation(LinearLayout.HORIZONTAL); CheckBox cb = new CheckBox(this); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/MultipleInsulins.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/MultipleInsulins.java index 89cf2714b0..77e542c0bf 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/MultipleInsulins.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/MultipleInsulins.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.insulin; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; public class MultipleInsulins { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/aaps/AAPSStatusHandler.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/aaps/AAPSStatusHandler.java new file mode 100644 index 0000000000..65fefbf46d --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/aaps/AAPSStatusHandler.java @@ -0,0 +1,75 @@ +package com.eveningoutpost.dexdrip.insulin.aaps; + +import com.eveningoutpost.dexdrip.alert.Persist; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.PumpStatus; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import info.nightscout.sdk.localmodel.devicestatus.NSDeviceStatus; +import lombok.val; + +/** + * JamOrHam + *

+ * Handle processing of AAPS device status updates + */ + +public class AAPSStatusHandler { + + private static final String TAG = AAPSStatusHandler.class.getSimpleName(); + private static final Gson gson = new GsonBuilder().create(); + private static final Persist.StringTimeout store = + new Persist.StringTimeout("AAPS_DEVICE_STATUS", Constants.MINUTE_IN_MS * 21); + private static volatile NSDeviceStatus last; + + // process and store received json in to object and maintain persistent time limited cache + public static void processDeviceStatus(final String json) { + synchronized (AAPSStatusHandler.class) { + try { + last = gson.fromJson(json, NSDeviceStatus.class); + Log.d(TAG, "DEBUG: got device status: " + last.toString()); + if (last != null) { + store.set(json); + val pump = last.getPump(); + if (pump != null) { + val r = pump.getReservoir(); + if (r != null) { + PumpStatus.setReservoir(r); + } + val b = pump.getBattery(); + if (b != null) { + val pc = b.getPercent(); + if (pc != null) { + PumpStatus.setBattery(pc); + } + } + } + } + } catch (Exception e) { + Log.e(TAG, "Error processing device status: " + e); + } + } + } + + // get instance either from cache or persistent store if still valid + public static NSDeviceStatus get() { + synchronized (AAPSStatusHandler.class) { + val json = store.get(); // local copy + if (json != null) { + if (last == null) { + // needs reconstructing + try { + last = gson.fromJson(json, NSDeviceStatus.class); + } catch (Exception e) { + Log.wtf(TAG, "Unusual problem reconstructing device status: " + e); + } + } + return last; + } + return null; + } + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/FindNearby.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/FindNearby.java index 899172e368..a9abee6e9b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/FindNearby.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/FindNearby.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.insulin.inpen; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.utils.BtCallBack; import com.eveningoutpost.dexdrip.utils.bt.ScanMeister; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/InPen.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/InPen.java index 88f3299c56..50b220e679 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/InPen.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/InPen.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.insulin.inpen; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; /** * jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/InPenEntry.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/InPenEntry.java index beb01412ea..522e600747 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/InPenEntry.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/InPenEntry.java @@ -1,9 +1,9 @@ package com.eveningoutpost.dexdrip.insulin.inpen; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; /** * jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/InPenScanMeister.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/InPenScanMeister.java index 9bdd11c7cd..0d77477460 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/InPenScanMeister.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/InPenScanMeister.java @@ -2,11 +2,11 @@ import android.os.ParcelUuid; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; import com.eveningoutpost.dexdrip.utils.bt.ScanMeister; import com.eveningoutpost.dexdrip.utils.bt.Subscription; import com.polidea.rxandroidble2.scan.ScanFilter; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/InPenService.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/InPenService.java index 1363efea41..fe7394cf22 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/InPenService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/InPenService.java @@ -9,16 +9,16 @@ import android.os.Build; import android.os.PowerManager; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.PenData; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.PenData; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; +import com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; import com.eveningoutpost.dexdrip.insulin.inpen.messages.AdvertRx; import com.eveningoutpost.dexdrip.insulin.inpen.messages.BatteryRx; import com.eveningoutpost.dexdrip.insulin.inpen.messages.BondTx; @@ -52,30 +52,27 @@ //import rx.schedulers.Schedulers; -import io.reactivex.Observable; -import io.reactivex.Scheduler; -import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; import static android.bluetooth.BluetoothDevice.BOND_BONDED; import static android.bluetooth.BluetoothDevice.BOND_NONE; -import static com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump.dumpHexString; -import static com.eveningoutpost.dexdrip.Models.JoH.bytesToHex; -import static com.eveningoutpost.dexdrip.Models.JoH.dateTimeText; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; -import static com.eveningoutpost.dexdrip.Models.JoH.hourMinuteString; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.Models.JoH.quietratelimit; -import static com.eveningoutpost.dexdrip.Models.JoH.ratelimit; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.CLOSE; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.INIT; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.INPEN_SERVICE_FAILOVER_ID; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.MINUTE_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.SECOND_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.BAD; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.GOOD; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.NORMAL; +import static com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump.dumpHexString; +import static com.eveningoutpost.dexdrip.models.JoH.bytesToHex; +import static com.eveningoutpost.dexdrip.models.JoH.dateTimeText; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.hourMinuteString; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.quietratelimit; +import static com.eveningoutpost.dexdrip.models.JoH.ratelimit; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.CLOSE; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.INIT; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.INPEN_SERVICE_FAILOVER_ID; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.SECOND_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.BAD; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.GOOD; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.NORMAL; import static com.eveningoutpost.dexdrip.insulin.inpen.Constants.AUTHENTICATION; import static com.eveningoutpost.dexdrip.insulin.inpen.Constants.BATTERY; import static com.eveningoutpost.dexdrip.insulin.inpen.Constants.BONDCONTROL; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/BaseRx.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/BaseRx.java index 882541dc51..42d1ab9ad6 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/BaseRx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/BaseRx.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.insulin.inpen.messages; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.utils.math.SkeletonCRC16; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/BaseTx.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/BaseTx.java index 3c19cab9d1..fb47ba1bac 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/BaseTx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/BaseTx.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.insulin.inpen.messages; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; import com.eveningoutpost.dexdrip.insulin.inpen.Constants; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/BondTx.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/BondTx.java index 09eb4ccb2e..a125bc10a0 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/BondTx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/BondTx.java @@ -2,7 +2,7 @@ import android.annotation.SuppressLint; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.insulin.inpen.Constants; import java.security.SecureRandom; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/RecordRx.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/RecordRx.java index e719bcb1e4..f21bc8ab8d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/RecordRx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/RecordRx.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.insulin.inpen.messages; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import com.google.gson.annotations.Expose; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/TimeRx.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/TimeRx.java index ef32c2f966..95d9907d8d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/TimeRx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/inpen/messages/TimeRx.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.insulin.inpen.messages; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import com.google.gson.annotations.Expose; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/BaseMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/BaseMessage.java index 1a528eef41..cae331376a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/BaseMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/BaseMessage.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.insulin.opennov; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.buffer.MyByteBuffer; import com.eveningoutpost.dexdrip.xdrip; import com.google.gson.GsonBuilder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/Machine.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/Machine.java index 57908379a9..5279fa28fd 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/Machine.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/Machine.java @@ -3,9 +3,9 @@ import static com.eveningoutpost.dexdrip.insulin.opennov.BaseMessage.d; import static com.eveningoutpost.dexdrip.insulin.opennov.FSA.Action.WRITE_READ; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; import com.eveningoutpost.dexdrip.insulin.opennov.data.ICompleted; import lombok.RequiredArgsConstructor; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/Message.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/Message.java index bffba26a65..9eb7d6cb4d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/Message.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/Message.java @@ -7,8 +7,8 @@ import static com.eveningoutpost.dexdrip.insulin.opennov.mt.EventReport.MDC_NOTI_CONFIG; import static com.eveningoutpost.dexdrip.insulin.opennov.mt.EventReport.MDC_NOTI_SEGMENT_DATA; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.insulin.opennov.mt.ARequest; import com.eveningoutpost.dexdrip.insulin.opennov.mt.AResponse; import com.eveningoutpost.dexdrip.insulin.opennov.mt.Apdu; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/OpenNov.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/OpenNov.java index fc6946a9b2..550a4d08e8 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/OpenNov.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/OpenNov.java @@ -11,9 +11,9 @@ import androidx.annotation.RequiresApi; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.buffer.MyByteBuffer; import com.eveningoutpost.dexdrip.insulin.opennov.data.ICompleted; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/Options.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/Options.java index a8629708a9..e718cd5c8c 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/Options.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/Options.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.insulin.opennov; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; /** * JamOrHam diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/data/Pens.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/data/Pens.java index d71e4fe281..be60ec00a2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/data/Pens.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/data/Pens.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip.insulin.opennov.data; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/data/SaveCompleted.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/data/SaveCompleted.java index 8ea95546d5..5093b397e3 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/data/SaveCompleted.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/data/SaveCompleted.java @@ -1,17 +1,17 @@ package com.eveningoutpost.dexdrip.insulin.opennov.data; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.Models.JoH.tsl; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; import static com.eveningoutpost.dexdrip.insulin.opennov.Options.playSounds; import static com.eveningoutpost.dexdrip.insulin.opennov.Options.removePrimingDoses; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.InsulinInjection; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.InsulinInjection; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import com.eveningoutpost.dexdrip.insulin.MultipleInsulins; import com.eveningoutpost.dexdrip.insulin.opennov.Machine; import com.eveningoutpost.dexdrip.insulin.opennov.Message; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/ll/PHDllHelper.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/ll/PHDllHelper.java index d84377fea6..1e30934fce 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/ll/PHDllHelper.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/ll/PHDllHelper.java @@ -1,11 +1,11 @@ package com.eveningoutpost.dexdrip.insulin.opennov.ll; -import static com.eveningoutpost.dexdrip.Models.JoH.tolerantHexStringToByteArray; +import static com.eveningoutpost.dexdrip.models.JoH.tolerantHexStringToByteArray; import static com.eveningoutpost.dexdrip.insulin.opennov.BaseMessage.d; import static com.eveningoutpost.dexdrip.insulin.opennov.BaseMessage.log; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.UserError; import lombok.RequiredArgsConstructor; import lombok.val; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/ll/T4Select.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/ll/T4Select.java index 3fc71129e8..190a587727 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/ll/T4Select.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/ll/T4Select.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.insulin.opennov.ll; -import static com.eveningoutpost.dexdrip.Models.JoH.tolerantHexStringToByteArray; +import static com.eveningoutpost.dexdrip.models.JoH.tolerantHexStringToByteArray; import com.eveningoutpost.dexdrip.insulin.opennov.BaseMessage; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/ll/T4Transceiver.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/ll/T4Transceiver.java index 4334fbc85c..bb7fef4d4e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/ll/T4Transceiver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/ll/T4Transceiver.java @@ -6,9 +6,9 @@ import android.nfc.TagLostException; import android.nfc.tech.IsoDep; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.buffer.MyByteBuffer; import java.io.IOException; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/ARequest.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/ARequest.java index c46b395e8e..f64b3fb125 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/ARequest.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/ARequest.java @@ -2,7 +2,7 @@ import static com.eveningoutpost.dexdrip.insulin.opennov.mt.ApoepElement.APOEP; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; import com.eveningoutpost.dexdrip.insulin.opennov.BaseMessage; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/AResponse.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/AResponse.java index 9beeeb557b..e54847d9a9 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/AResponse.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/AResponse.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.insulin.opennov.mt; -import static com.eveningoutpost.dexdrip.Models.JoH.cloneObject; +import static com.eveningoutpost.dexdrip.models.JoH.cloneObject; import static com.eveningoutpost.dexdrip.insulin.opennov.mt.ApoepElement.APOEP; import static com.eveningoutpost.dexdrip.insulin.opennov.mt.ApoepElement.SYS_TYPE_MANAGER; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/Attribute.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/Attribute.java index 73d4cedfd9..fc45a6a677 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/Attribute.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/Attribute.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.insulin.opennov.mt; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; import com.eveningoutpost.dexdrip.insulin.opennov.BaseMessage; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/InsulinDose.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/InsulinDose.java index d30c9df273..d6d0a5a948 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/InsulinDose.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/InsulinDose.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip.insulin.opennov.mt; -import static com.eveningoutpost.dexdrip.Models.JoH.tsl; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import com.eveningoutpost.dexdrip.insulin.opennov.BaseMessage; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/RelativeTime.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/RelativeTime.java index d761164188..a2e5ca6bed 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/RelativeTime.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/mt/RelativeTime.java @@ -1,8 +1,7 @@ package com.eveningoutpost.dexdrip.insulin.opennov.mt; -import static com.eveningoutpost.dexdrip.Models.JoH.tsl; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; -import com.eveningoutpost.dexdrip.Models.JoH; import com.eveningoutpost.dexdrip.insulin.opennov.BaseMessage; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/nfc/TagDispatcher.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/nfc/TagDispatcher.java index 1fd12a80b6..9f9499a799 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/nfc/TagDispatcher.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/opennov/nfc/TagDispatcher.java @@ -5,8 +5,8 @@ import android.nfc.NfcAdapter; import android.nfc.Tag; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.insulin.opennov.OpenNov; import com.eveningoutpost.dexdrip.insulin.opennov.data.ICompleted; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/Pendiq.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/Pendiq.java index d10979f67e..ce0cdef3ee 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/Pendiq.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/Pendiq.java @@ -6,9 +6,9 @@ import android.content.Intent; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.xdrip; import static com.eveningoutpost.dexdrip.insulin.pendiq.Const.MINIMUM_DOSE; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/PendiqService.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/PendiqService.java index 5eef095ad7..365000e8ea 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/PendiqService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/PendiqService.java @@ -5,15 +5,15 @@ import android.os.PowerManager; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.JamBaseBluetoothService; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.RxBleProvider; +import com.eveningoutpost.dexdrip.services.JamBaseBluetoothService; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.RxBleProvider; import com.eveningoutpost.dexdrip.insulin.pendiq.messages.InjectionStatusTx; import com.eveningoutpost.dexdrip.insulin.pendiq.messages.InsulinLogRx; import com.eveningoutpost.dexdrip.insulin.pendiq.messages.InsulinLogTx; @@ -45,13 +45,10 @@ import rx.Subscription; import rx.schedulers.Schedulers; */ -import io.reactivex.Observable; -import io.reactivex.Scheduler; -import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.Models.JoH.ratelimit; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.ratelimit; import static com.eveningoutpost.dexdrip.insulin.pendiq.Const.INCOMING_CHAR; import static com.eveningoutpost.dexdrip.insulin.pendiq.Const.INSULIN_CLASSIFIER; import static com.eveningoutpost.dexdrip.insulin.pendiq.Const.OUTGOING_CHAR; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/SequenceCounter.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/SequenceCounter.java index 0d1553aada..c0c72bfdfd 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/SequenceCounter.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/SequenceCounter.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip.insulin.pendiq; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; import java.util.concurrent.atomic.AtomicInteger; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/messages/BaseMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/messages/BaseMessage.java index d24797cb2d..d647354431 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/messages/BaseMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/messages/BaseMessage.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip.insulin.pendiq.messages; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import com.eveningoutpost.dexdrip.utils.CRC16ccitt; import com.google.gson.annotations.Expose; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/messages/InsulinLogRx.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/messages/InsulinLogRx.java index 58f79aa38c..0779df9ffe 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/messages/InsulinLogRx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/messages/InsulinLogRx.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.insulin.pendiq.messages; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.google.gson.annotations.Expose; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/messages/SetTimeTx.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/messages/SetTimeTx.java index 6ad108c5fd..60bd353e04 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/messages/SetTimeTx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/messages/SetTimeTx.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.insulin.pendiq.messages; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.insulin.pendiq.Const; import static com.eveningoutpost.dexdrip.insulin.pendiq.SequenceCounter.getNext; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/messages/StatusRx.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/messages/StatusRx.java index 21bbf4d263..becf9916ff 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/messages/StatusRx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/pendiq/messages/StatusRx.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.insulin.pendiq.messages; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.google.gson.annotations.Expose; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/shared/PrimeDetection.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/shared/PrimeDetection.java index ce8514dee4..9598eb8eec 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/shared/PrimeDetection.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/shared/PrimeDetection.java @@ -1,15 +1,15 @@ package com.eveningoutpost.dexdrip.insulin.shared; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.PenData; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.PenData; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import java.util.ArrayList; import java.util.List; -import static com.eveningoutpost.dexdrip.Models.JoH.roundDouble; +import static com.eveningoutpost.dexdrip.models.JoH.roundDouble; import static com.eveningoutpost.dexdrip.insulin.inpen.InPenEntry.ID_INPEN; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/shared/ProcessPenData.java b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/shared/ProcessPenData.java index e185fdb96f..dd3826eef4 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/insulin/shared/ProcessPenData.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/insulin/shared/ProcessPenData.java @@ -1,11 +1,11 @@ package com.eveningoutpost.dexdrip.insulin.shared; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.PenData; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.PenData; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/languageeditor/LanguageAdapter.java b/app/src/main/java/com/eveningoutpost/dexdrip/languageeditor/LanguageAdapter.java index 35d34ee075..924b01971f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/languageeditor/LanguageAdapter.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/languageeditor/LanguageAdapter.java @@ -3,7 +3,7 @@ import android.app.Activity; import android.content.Context; import android.graphics.Color; -import android.support.v7.widget.RecyclerView; + import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -15,10 +15,12 @@ import android.widget.RelativeLayout; import android.widget.TextView; -import com.eveningoutpost.dexdrip.Models.JoH; +import androidx.recyclerview.widget.RecyclerView; + +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.JamorhamShowcaseDrawer; -import com.eveningoutpost.dexdrip.UtilityModels.ShotStateStore; +import com.eveningoutpost.dexdrip.utilitymodels.JamorhamShowcaseDrawer; +import com.eveningoutpost.dexdrip.utilitymodels.ShotStateStore; import com.github.amlcurran.showcaseview.ShowcaseView; import com.github.amlcurran.showcaseview.targets.ViewTarget; @@ -28,7 +30,8 @@ * Created by jamorham on 04/07/2016. */ - +// TODO Due for deletion - will no longer function +@Deprecated public class LanguageAdapter extends RecyclerView.Adapter { private static final String TAG = "jamorhamlang"; @@ -143,78 +146,7 @@ public void afterTextChanged(Editable s) { @Override public void onBindViewHolder(final MyViewHolder holder, int position) { - final LanguageItem languageItem = languageList.get(position); - holder.position = position; - - - holder.english_text.setText(languageItem.english_text); - - - holder.local_text.setText(languageItem.local_text.replace("\n", " ^ ")); - holder.id_text.setText(languageItem.item_name); - - - if (languageItem.customized) { - holder.local_text.setTextColor(Color.parseColor("#d6a5a7")); - holder.elementUndo.setVisibility(View.VISIBLE); - - // optimize with flag - if (!showcased_undo) { - if (JoH.ratelimit("language-showcase", 2)) { - if (!ShotStateStore.hasShot(LanguageEditor.SHOWCASE_LANGUAGE_ELEMENT_UNDO)) { - ShowcaseView myShowcase = new ShowcaseView.Builder((Activity) context) - - .setTarget(new ViewTarget(holder.elementUndo)) - .setStyle(R.style.CustomShowcaseTheme2) - .setContentTitle("Item Undo Button") // always in english - .setContentText("\n" + "You can Undo a single change by Long-pressing the Undo button.") // always in english - .setShowcaseDrawer(new JamorhamShowcaseDrawer(context.getResources(), context.getTheme(), 90, 14)) - .singleShot(LanguageEditor.oneshot ? LanguageEditor.SHOWCASE_LANGUAGE_ELEMENT_UNDO : -1) - .build(); - myShowcase.setBackgroundColor(Color.TRANSPARENT); - myShowcase.show(); - showcased_undo = true; - } else { - showcased_undo = true; - } - } - } - - } else { - holder.local_text.setTextColor(Color.parseColor("#a5d6a7")); - holder.elementUndo.setVisibility(View.INVISIBLE); - } - - if (languageItem.english_text.equals(languageItem.local_text)) { - holder.id_text.setText(holder.id_text.getText() + " NEW"); - } - - if (!showcased_newline) { - if (LanguageEditor.last_filter.length()==0) { - if (holder.local_text.getText().toString().contains(" ^ ")) { - if (JoH.ratelimit("language-showcase", 2)) { - if (!ShotStateStore.hasShot(LanguageEditor.SHOWCASE_LANGUAGE_ELEMENT_NEWLINE)) { - ShowcaseView myShowcase = new ShowcaseView.Builder((Activity) context) - - .setTarget(new ViewTarget(holder.local_text)) - .setStyle(R.style.CustomShowcaseTheme2) - .setContentTitle("Line break and other Symbols") // always in english - .setContentText("\n" + "Symbols like ^ are used internally for advancing to a new line.\n\nPlease be careful to preserve these exactly and also respect other symbols you find like : which may affect the user interface if removed.") // always in english - .setShowcaseDrawer(new JamorhamShowcaseDrawer(context.getResources(), context.getTheme(), 90, 50)) - .singleShot(LanguageEditor.oneshot ? LanguageEditor.SHOWCASE_LANGUAGE_ELEMENT_NEWLINE : -1) - .build(); - - myShowcase.setBackgroundColor(Color.TRANSPARENT); - myShowcase.show(); - showcased_newline = true; - } else { - showcased_newline = true; - } - } - } - } - } } @Override diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/languageeditor/LanguageEditor.java b/app/src/main/java/com/eveningoutpost/dexdrip/languageeditor/LanguageEditor.java index 97eabdd56e..47cc3cb58e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/languageeditor/LanguageEditor.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/languageeditor/LanguageEditor.java @@ -10,15 +10,9 @@ import android.graphics.Point; import android.os.Bundle; import android.os.Handler; -import android.support.annotation.IdRes; -import android.support.v4.view.MenuItemCompat; -import android.support.v7.app.AlertDialog; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.SearchView; -import android.support.v7.widget.Toolbar; +import androidx.annotation.IdRes; +import androidx.core.view.MenuItemCompat; + import android.text.InputType; import android.util.Log; import android.view.Menu; @@ -29,12 +23,12 @@ import android.widget.Toast; import com.eveningoutpost.dexdrip.BaseAppCompatActivity; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.JamorhamShowcaseDrawer; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.SendFeedBack; -import com.eveningoutpost.dexdrip.UtilityModels.ShotStateStore; +import com.eveningoutpost.dexdrip.utilitymodels.JamorhamShowcaseDrawer; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.SendFeedBack; +import com.eveningoutpost.dexdrip.utilitymodels.ShotStateStore; import com.github.amlcurran.showcaseview.ShowcaseView; import com.github.amlcurran.showcaseview.targets.Target; import com.github.amlcurran.showcaseview.targets.ViewTarget; @@ -60,623 +54,10 @@ * Created by jamorham on 04/07/2016. */ - +// TODO no longer in use or functional - for deletion +@Deprecated public class LanguageEditor extends BaseAppCompatActivity { - private static final String TAG = "jamorhamlanguage"; - private static final String EMAIL_KEY = "___EMAIL_KEY:"; - private static final String NAME_KEY = "___NAME_KEY:"; - private static final String CONSENT_KEY = "___CONSENT_KEY"; - private final List languageItemList = new ArrayList<>(); - private final List languageItemListBackup = new ArrayList<>(); - private RecyclerView recyclerView; - private LanguageAdapter mAdapter; - // private static Button cancelBtn; - private static Button saveBtn; - private static Button undoBtn; - - private boolean show_only_customized = false; - private boolean show_only_untranslated = false; - protected static String last_filter = ""; - - private static Map user_edits = new HashMap<>(); - - protected static final boolean oneshot = true; - private static ShowcaseView myShowcase; - - private static final int SHOWCASE_LANGUAGE_INTRO = 601; - protected static final int SHOWCASE_LANGUAGE_ELEMENT_UNDO = 602; - protected static final int SHOWCASE_LANGUAGE_ELEMENT_NEWLINE = 603; - - private Context mContext; - private Toolbar toolbar; - - - private String getStringFromLocale(int id, Locale desired_locale) { - final Resources my_resources = getResources(); - final Configuration cfg = my_resources.getConfiguration(); - final Locale savedLocale = cfg.locale; - cfg.setLocale(desired_locale); - my_resources.updateConfiguration(cfg, null); - final String result = my_resources.getString(id); - cfg.setLocale(savedLocale); - my_resources.updateConfiguration(cfg, null); - return result; - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - mContext = this; - super.onCreate(savedInstanceState); - setTheme(R.style.AppThemeToolBarLite); // for toolbar mode - setContentView(R.layout.activity_language_editor); - - toolbar = (Toolbar) findViewById(R.id.language_toolbar); - setSupportActionBar(toolbar); - - undoBtn = (Button) findViewById(R.id.languageUndoBtn); - saveBtn = (Button) findViewById(R.id.languageSaveBtn); - // cancelBtn = (Button) findViewById(R.id.languageCancelBtn); - JoH.fixActionBar(this); - forceReload(); - - recyclerView = (RecyclerView) findViewById(R.id.language_recycler_view); - - mAdapter = new LanguageAdapter(this, languageItemList); - RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext()); - recyclerView.setLayoutManager(mLayoutManager); - recyclerView.setItemAnimator(new DefaultItemAnimator()); - - mAdapter.registerAdapterDataObserver( - // handle incoming messages from the adapater - new RecyclerView.AdapterDataObserver() { - - @Override - public void onChanged() { - super.onChanged(); - // Log.d(TAG, "onChanged"); - } - - @Override - public void onItemRangeChanged(final int positionStart, int itemCount, Object payload) { - super.onItemRangeChanged(positionStart, itemCount, payload); - - Log.d(TAG, "onItemRangeChanged: pos:" + positionStart + " cnt:" + itemCount + " p: " + payload.toString()); - - try { - - final LanguageItem updated_element = (LanguageItem) payload; - final LanguageItem current_item = languageItemList.get(positionStart); - if (!current_item.original_text.equals(updated_element.local_text)) { - user_edits.put(updated_element.item_name, (LanguageItem) payload); // on change - - if (languageItemList.get(positionStart).item_name.equals(updated_element.item_name)) { - languageItemList.get(positionStart).local_text = updated_element.local_text; - languageItemList.get(positionStart).customized = true; - - } else { - Log.e(TAG, "Error item at position during update does not match!"); - } - saveBtn.setVisibility(View.VISIBLE); - undoBtn.setVisibility(View.VISIBLE); - forceRefresh(); - } else { - Log.d(TAG, "Updated element is same as original - ignoring"); - } - } catch (ClassCastException e) { - if (payload.toString().equals("undo")) { - languageItemList.get(positionStart).local_text = languageItemList.get(positionStart).original_text; - languageItemList.get(positionStart).customized = false; - forceRefresh(); - } else { - Log.e(TAG, "Could not cast item-change payload to LanguageItem: " + e.toString()); - } - } - } - }); - - - DefaultItemAnimator animator = new DefaultItemAnimator() { - @Override - public boolean canReuseUpdatedViewHolder(RecyclerView.ViewHolder viewHolder) { - return true; - } - }; - - recyclerView.setItemAnimator(animator); - recyclerView.setAdapter(mAdapter); - applyFilter(last_filter); - forceRefresh(); - - // handle case where we don't know about any translations for current language - if (languageItemList.size() == 0 || Locale.getDefault().toString().startsWith("en")) { - if (Locale.getDefault().toString().startsWith("en")) { - android.app.AlertDialog.Builder alertDialogBuilder = new android.app.AlertDialog.Builder(this); - - if (!Pref.getBoolean("force_english", false)) { - alertDialogBuilder.setMessage("To access translation features your phone or tablet must be set to a language other than English.\n\nTo achieve this, use the phone's system settings to change Language."); // don't extract/translate this string - } else { - alertDialogBuilder.setMessage("To access translation features your phone or tablet must be set to a language other than English.\n\nTo achieve this, disable the Force English option within xDrip+ display settings."); // don't extract/translate this string - } - alertDialogBuilder.setNegativeButton(getString(R.string.ok), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - finish(); - } - }); - alertDialogBuilder.show(); - - } else { - android.app.AlertDialog.Builder alertDialogBuilder = new android.app.AlertDialog.Builder(this); - alertDialogBuilder.setMessage("xDrip+ does not yet have the capability to translate for: " + Locale.getDefault().toString() + "\n\n" + "But we can add this if you request it!"); // don't extract/translate this string - alertDialogBuilder.setNegativeButton("No, don't request my language", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - finish(); - } - }); - alertDialogBuilder.setPositiveButton("Yes, please support my language", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - // fire off a request! - startActivity(new Intent(getApplicationContext(), SendFeedBack.class).putExtra("request_translation", Locale.getDefault().toString())); - finish(); - } - }); - alertDialogBuilder.show(); - } - } - } - - @Override - public void onStart() { - super.onStart(); - if ((languageItemList.size() > 0) && (!Locale.getDefault().toString().startsWith("en"))) { - showcasemenu(SHOWCASE_LANGUAGE_INTRO); - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_language, menu); - - MenuItem searchItem = menu.findItem(R.id.action_language_search); - SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); - - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - - @Override - public boolean onQueryTextSubmit(String s) { - applyFilter(s); - return false; - } - - @Override - public boolean onQueryTextChange(String s) { - applyFilter(s); - return false; - } - }); - return true; - } - - public void languageResetEverything(MenuItem v) { - android.app.AlertDialog.Builder alertDialogBuilder = new android.app.AlertDialog.Builder(this); - alertDialogBuilder.setMessage("Are you sure you want to reset all edited language data?"); // don't extract/translate this string - alertDialogBuilder.setNegativeButton("No, keep my data", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - } - }); - alertDialogBuilder.setPositiveButton("Delete all language edits", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - LanguageStore.resetEverything(); - user_edits.clear(); - forceReload(); - applyFilter(last_filter); - forceRefresh(); - } - }); - alertDialogBuilder.show(); - } - - public void languageShowOnlyCustomized(MenuItem v) { - v.setChecked(!v.isChecked()); - show_only_customized = v.isChecked(); - applyFilter(last_filter); - forceRefresh(); - } - - public void languageShowOnlyUntranslated(MenuItem v) { - v.setChecked(!v.isChecked()); - show_only_untranslated = v.isChecked(); - applyFilter(last_filter); - forceRefresh(); - } - - private void applyFilter(String filter) { - last_filter = filter; - // create initial backup if no filter yet applied - if (languageItemListBackup.size() == 0) { - languageItemListBackup.addAll(languageItemList); - } else { - // restore before new filter - languageItemList.clear(); - languageItemList.addAll(languageItemListBackup); - } - - final List filteredItemList = new ArrayList<>(); - filter = filter.toLowerCase(); - for (LanguageItem item : languageItemList) { - if ((filter.length() == 0) - || item.original_text.toLowerCase().contains(filter) - || item.english_text.toLowerCase().contains(filter) - || item.local_text.toLowerCase().contains(filter) - || item.item_name.toLowerCase().contains(filter)) { - if ((!show_only_untranslated) || isUntranslated(item)) { - if ((!show_only_customized) || (item.customized)) filteredItemList.add(item); - } - } - } - languageItemList.clear(); - languageItemList.addAll(filteredItemList); - forceRefresh(); - } - - private boolean isUntranslated(LanguageItem item) { - return item.english_text.equals(item.local_text); - } - - private void getEmailAddress() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle("Email address?"); - builder.setMessage("To provide crowd-sourced translations for xDrip+ we request your email address so we can contact you with any questions. Your email address will not be disclosed or used for any other purpose."); - final EditText input = new EditText(this); - - input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); - builder.setView(input); - - builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - LanguageStore.putString(EMAIL_KEY, input.getText().toString()); - saveData(); - } - }); - builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.cancel(); - } - }); - - builder.show(); - } - - private void getThanksName() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle("Name for thanks page?"); - builder.setMessage("We also want to have a notice in xDrip+ thanking our translators. We don't use your email address for this.\n\nPlease tell us a Name or Alias we can use to put on the thanks page for you?"); - final EditText input = new EditText(this); - - input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); - builder.setView(input); - - builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - LanguageStore.putString(NAME_KEY, input.getText().toString()); - saveData(); - } - }); - builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.cancel(); - } - }); - - builder.show(); - } - - private void getConsent() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle("Copyright Disclaimer"); - builder.setMessage("If approved, your translations will be published as part of xDrip+\n\nTo ensure the stability of the project we must ask contributors to confirm that they assign the copyright of translations to the project so that we are allowed to redistribute the text."); - - builder.setPositiveButton("I ASSIGN COPYRIGHT TO THE PROJECT", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - LanguageStore.putString(CONSENT_KEY, "Agreed:" + JoH.ts()); - saveData(); - } - }); - builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.cancel(); - } - }); - - builder.show(); - } - - - private void toast(String msg) { - JoH.static_toast(mContext, msg, Toast.LENGTH_LONG); - } - - private void uploadData(String data) { - if (data.length() < 10) { - toast("No text entered - cannot send blank"); // don't translate - return; - } - - final String email = LanguageStore.getString(EMAIL_KEY); - final String name = LanguageStore.getString(NAME_KEY); - final String consent = LanguageStore.getString(CONSENT_KEY); - - if (email.length() == 0) { - toast("No email address stored - cannot send"); // don't translate - return; - } - - if (name.length() == 0) { - toast("No thanks name stored - cannot send"); // don't translate - return; - } - - if (consent.length() == 0) { - toast("No consent stored - cannot send"); // don't translate - return; - } - - - final OkHttpClient client = new OkHttpClient(); - final String send_url = mContext.getString(R.string.wserviceurl) + "/joh-langdata"; - - client.setConnectTimeout(20, TimeUnit.SECONDS); - client.setReadTimeout(30, TimeUnit.SECONDS); - client.setWriteTimeout(30, TimeUnit.SECONDS); - - toast("Sending.."); // don't translate - - try { - final RequestBody formBody = new FormEncodingBuilder() - .add("locale", Locale.getDefault().toString()) - .add("contact", email) - .add("name", name) - .add("consent", consent) - .add("data", data) - .build(); - new Thread(new Runnable() { - public void run() { - try { - final Request request = new Request.Builder() - .url(send_url) - .post(formBody) - .build(); - Log.i(TAG, "Sending language data"); - Response response = client.newCall(request).execute(); - if (response.isSuccessful()) { - toast("data sent successfully"); - ((Activity) mContext).runOnUiThread(new Runnable() { - @Override - public void run() { - try { - saveBtn.setVisibility(View.INVISIBLE); - undoBtn.setVisibility(View.INVISIBLE); - } catch (Exception e) { - // do nothing if its gone away - } - } - }); - } else { - toast("Error sending data: " + response.message()); - } - } catch (Exception e) { - Log.e(TAG, "Got exception in execute: " + e.toString()); - toast("Error with network connection"); // don't translate - } - } - }).start(); - } catch (Exception e) { - toast(e.getMessage()); - Log.e(TAG, "General exception: " + e.toString()); - } - } - - private void saveData() { - if (!LanguageStore.getString(EMAIL_KEY).equals("")) { - if (!LanguageStore.getString(NAME_KEY).equals("")) { - if (!LanguageStore.getString(CONSENT_KEY).equals("")) { - if (JoH.ratelimit("language-save", 5)) { - for (LanguageItem item : user_edits.values()) { - LanguageStore.putString(item.item_name, item.local_text); - } - final String data = getJsonToSave(); - Log.d(TAG, "Data to save: " + data); - uploadData(data); - } - } else { - getConsent(); - } - } else { - getThanksName(); - } - } else { - getEmailAddress(); - } - } - - private String getJsonToSave() { - - final Gson gson = new GsonBuilder() - .excludeFieldsWithoutExposeAnnotation() - //.registerTypeAdapter(Date.class, new DateTypeAdapter()) - .serializeSpecialFloatingPointValues() - .create(); - - return gson.toJson(user_edits.values()); - } - - - public void languageCancelButton(View myview) { - finish(); - } - - public void languageSaveButton(View myview) { - saveData(); - //finish(); - } - - public void languageUndoButton(View myview) { - - forceReload(); - applyFilter(last_filter); - forceRefresh(false); - - } - - private void forceReload() { - languageItemList.clear(); - languageItemListBackup.clear(); - user_edits.clear(); - // we must preserve the existing object reference used by the adapter - languageItemList.addAll(loadData(true)); - // TODO sanely repopulate user_edits with customized data?? - } - - private List loadData(boolean buttons) { - final List mylanguageItemList = new ArrayList<>(); - - // create string name hashset of things we want to be able to translate - final StringTokenizer tokenizer = new StringTokenizer(getString(R.string.internal_translatable_index), ","); - final List tokenizer_list = new ArrayList<>(); - while (tokenizer.hasMoreTokens()) { - tokenizer_list.add(tokenizer.nextToken()); - } - final ImmutableSet translatable_index_names = ImmutableSet.copyOf(tokenizer_list); - tokenizer_list.clear(); - - final Field[] fields = R.string.class.getFields(); - for (final Field field : fields) { - final String name = field.getName(); //name of string - - try { - int id = field.getInt(R.string.class); //id of string - final String local_text = getResources().getString(id); - final String english_text = getStringFromLocale(id, Locale.ENGLISH); - if ((!local_text.equals(english_text) || translatable_index_names.contains(name)) && !name.startsWith("abc_") && !name.startsWith("common_") && !name.startsWith("twofortyfouram_") && !name.startsWith("zxing_")) { - // Log.d(TAG, "name: " + name + " / reflect id:" + id + " english:" + english_text + " / local:" + local_text); - final String alternate_text = LanguageStore.getString(name); - final boolean customized = (alternate_text.length() > 0); - LanguageItem item = new LanguageItem(name, english_text, customized ? alternate_text : local_text, customized, local_text); - mylanguageItemList.add(item); - if (customized) { - user_edits.put(item.item_name, item); // refill edits list with anything previously saved - } - } - } catch (Exception e) { - //error - } - } - if (buttons) { - saveBtn.setVisibility(View.INVISIBLE); - undoBtn.setVisibility(View.INVISIBLE); - } - Log.d(TAG, "Loaded data"); - return mylanguageItemList; - } - - - private void forceRefresh() { - forceRefresh(true); - } - - private void forceRefresh(boolean save) { - mAdapter.first_run = languageItemList.size(); - recyclerView.invalidate(); - recyclerView.refreshDrawableState(); - mAdapter.notifyDataSetChanged(); - } - - - private synchronized void showcasemenu(final int option) { - if ((myShowcase != null) && (myShowcase.isShowing())) return; - if (ShotStateStore.hasShot(option)) return; - if (!JoH.ratelimit("language-showcase", 2)) return; - try { - - ToolbarActionItemTarget target = null; - ViewTarget viewtarget = null; - String title = ""; - String message = ""; - - switch (option) { - - case SHOWCASE_LANGUAGE_INTRO: - target = new ToolbarActionItemTarget(toolbar, R.id.action_language_search); - // these messages always appear in english only - title = "Search and Submit Translations"; - message = "You can help crowd-source better translations for xDrip+\n\nSimply find and edit the text, click ✔ or ➡ on your keyboard to save. Match as closely as possible the English version (including preserving punctuation symbols and capitalisation) and then use Save button to Upload your suggested changes.\n\nIt is not yet possible to preview your changes in the App, but if accepted they will appear in future updates."; - break; - - case SHOWCASE_LANGUAGE_ELEMENT_UNDO: - // done inside the adapter - break; - } - - // seems a bit excessive just to delay the lookup of the view to avoid it failing sometimes - final ToolbarActionItemTarget finaltarget = target; - final ViewTarget finalviewtarget = viewtarget; - final String finalmessage = message; - final String finaltitle = title; - final Activity finalactivity = this; - - final Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - @Override - public void run() { - - if ((finaltarget != null) || (finalviewtarget != null)) { - myShowcase = new ShowcaseView.Builder(finalactivity) - .setTarget((finaltarget != null) ? finaltarget : finalviewtarget) - .setStyle(R.style.CustomShowcaseTheme2) - .setContentTitle(finaltitle) - .setContentText("\n" + finalmessage) - .setShowcaseDrawer(new JamorhamShowcaseDrawer(getResources(), getTheme(), 90, 14)) - .singleShot(oneshot ? option : -1) - .build(); - - myShowcase.setBackgroundColor(Color.TRANSPARENT); - myShowcase.show(); - } - } - }, 100); - - } catch (Exception e) { - Log.e(TAG, "Exception in showcase: " + e.toString()); - } - } - - - class ToolbarActionItemTarget implements Target { - - private final Toolbar toolbar; - private final int menuItemId; - - public ToolbarActionItemTarget(Toolbar toolbar, @IdRes int itemId) { - this.toolbar = toolbar; - this.menuItemId = itemId; - } - - @Override - public Point getPoint() { - return new ViewTarget(toolbar.findViewById(menuItemId)).getPoint(); - } - } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/languageeditor/LanguageStore.java b/app/src/main/java/com/eveningoutpost/dexdrip/languageeditor/LanguageStore.java index 9ab33d9ee0..6cf779aa1d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/languageeditor/LanguageStore.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/languageeditor/LanguageStore.java @@ -2,7 +2,7 @@ import android.content.Context; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.xdrip; import java.util.Locale; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/localeTasker/receiver/FireReceiver.java b/app/src/main/java/com/eveningoutpost/dexdrip/localeTasker/receiver/FireReceiver.java index ed08b9e428..ca3528780b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/localeTasker/receiver/FireReceiver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/localeTasker/receiver/FireReceiver.java @@ -26,12 +26,12 @@ import android.util.Log; import android.widget.Toast; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.SnoozeActivity; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.localeTasker.Constants; import com.eveningoutpost.dexdrip.localeTasker.bundle.BundleScrubber; import com.eveningoutpost.dexdrip.localeTasker.bundle.PluginBundleManager; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/APStatus.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/APStatus.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/APStatus.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/APStatus.java index 8c8e766023..fd3779ebf4 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/APStatus.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/APStatus.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.provider.BaseColumns; @@ -6,7 +6,7 @@ import com.activeandroid.annotation.Table; import com.activeandroid.query.Delete; import com.activeandroid.query.Select; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import com.eveningoutpost.dexdrip.wearintegration.ExternalStatusService; import com.google.gson.annotations.Expose; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Accuracy.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/Accuracy.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/Accuracy.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/Accuracy.java index 84aa199463..47caae0462 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Accuracy.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/Accuracy.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; /** * Created by jamorham on 01/02/2017. @@ -11,8 +11,8 @@ import com.activeandroid.annotation.Table; import com.activeandroid.query.Select; import com.eveningoutpost.dexdrip.BestGlucose; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.google.gson.annotations.Expose; import java.util.ArrayList; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/ActiveBgAlert.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/ActiveBgAlert.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/ActiveBgAlert.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/ActiveBgAlert.java index f7a20e50b8..b4ba64c6cf 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/ActiveBgAlert.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/ActiveBgAlert.java @@ -1,15 +1,15 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.provider.BaseColumns; import com.activeandroid.util.SQLiteUtils; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.activeandroid.Model; import com.activeandroid.annotation.Column; import com.activeandroid.annotation.Table; import com.activeandroid.query.Select; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; import java.text.DateFormat; import java.util.Date; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/ActiveBluetoothDevice.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/ActiveBluetoothDevice.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/ActiveBluetoothDevice.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/ActiveBluetoothDevice.java index fcbc829edf..2dfeba9cab 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/ActiveBluetoothDevice.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/ActiveBluetoothDevice.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.provider.BaseColumns; @@ -6,8 +6,8 @@ import com.activeandroid.annotation.Column; import com.activeandroid.annotation.Table; import com.activeandroid.query.Select; -import com.eveningoutpost.dexdrip.UtilityModels.Blukon; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Blukon; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; /** * Created by Emma Black on 11/3/14. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/AlertType.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/AlertType.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/AlertType.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/AlertType.java index 14203b0844..2773783117 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/AlertType.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/AlertType.java @@ -1,35 +1,32 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; -import android.app.AlarmManager; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.provider.BaseColumns; import com.activeandroid.util.SQLiteUtils; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.activeandroid.Model; import com.activeandroid.annotation.Column; import com.activeandroid.annotation.Table; import com.activeandroid.query.Select; -import com.eveningoutpost.dexdrip.Services.ActivityRecognizedService; -import com.eveningoutpost.dexdrip.Services.MissedReadingService; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; -import com.eveningoutpost.dexdrip.UtilityModels.Notifications; +import com.eveningoutpost.dexdrip.services.ActivityRecognizedService; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.Notifications; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.UUID; -import java.util.concurrent.atomic.AtomicBoolean; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.annotations.Expose; import com.google.gson.internal.bind.DateTypeAdapter; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; + +import lombok.val; /** * Created by Emma Black on 1/14/15. @@ -447,6 +444,27 @@ public static boolean activeLowAlertExists() { return false; } + public static AlertType getMostExtremeAlert(boolean highAlerts) { + val alerts = getAll(highAlerts); + if (alerts == null) return null; + val filtered = new ArrayList(); + for (val alert : alerts) { + if (alert.active && alert.in_time_frame()) { // remove alerts which are not live now + filtered.add(alert); + } + } + if (filtered.size() == 0) return null; + return filtered.get(filtered.size()-1); // They are sorted with max last + } + + public static AlertType getLowestAlert() { + return getMostExtremeAlert(false); + } + + public static AlertType getHighestAlert() { + return getMostExtremeAlert(true); + } + // This function is used to make sure that we always have a static alert on 55 low. // This alert will not be editable/removable. public static void CreateStaticAlerts() { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/Atom.java similarity index 91% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/Atom.java index f6ccfa7361..ce4581b3b8 100755 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Atom.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/Atom.java @@ -1,17 +1,16 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.NFCReaderX; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.BridgeResponse; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.LibreUtils; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.BridgeResponse; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.LibreUtils; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import java.nio.ByteBuffer; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/BgReading.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/BgReading.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/BgReading.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/BgReading.java index 157ebcf6f2..cc1a2c7cd3 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/BgReading.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/BgReading.java @@ -1,7 +1,8 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; -import static com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants.TREND_ARROW_VALUES.NOT_COMPUTABLE; -import static com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants.TREND_ARROW_VALUES.getTrend; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.shortTxId; +import static com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants.TREND_ARROW_VALUES.NOT_COMPUTABLE; +import static com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants.TREND_ARROW_VALUES.getTrend; import static com.eveningoutpost.dexdrip.calibrations.PluggableCalibration.getCalibrationPluginFromPreferences; import static com.eveningoutpost.dexdrip.calibrations.PluggableCalibration.newCloseSensorData; @@ -21,21 +22,21 @@ import com.eveningoutpost.dexdrip.BestGlucose; import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.EGVRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.SensorRecord; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.EGVRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.SensorRecord; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService; -import com.eveningoutpost.dexdrip.Services.SyncService; -import com.eveningoutpost.dexdrip.ShareModels.ShareUploadableBg; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.BgSendQueue; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Notifications; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.UploaderQueue; -import com.eveningoutpost.dexdrip.UtilityModels.WholeHouse; +import com.eveningoutpost.dexdrip.services.Ob1G5CollectionService; +import com.eveningoutpost.dexdrip.services.SyncService; +import com.eveningoutpost.dexdrip.sharemodels.ShareUploadableBg; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.BgSendQueue; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Notifications; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.UploaderQueue; +import com.eveningoutpost.dexdrip.utilitymodels.WholeHouse; import com.eveningoutpost.dexdrip.calibrations.CalibrationAbstract; import com.eveningoutpost.dexdrip.messages.BgReadingMessage; import com.eveningoutpost.dexdrip.messages.BgReadingMultiMessage; @@ -610,7 +611,7 @@ public static BgReading createFromRawNoSave(Sensor sensor, Calibration calibrati Log.d(TAG, "USING CALIBRATION PLUGIN AS PRIMARY!!!"); if (plugin.isCalibrationSane(pcalibration)) { bgReading.calculated_value = (pcalibration.slope * bgReading.age_adjusted_raw_value) + pcalibration.intercept; - bgReading.filtered_calculated_value = (pcalibration.slope * bgReading.ageAdjustedFiltered()) + calibration.intercept; + bgReading.filtered_calculated_value = (pcalibration.slope * bgReading.ageAdjustedFiltered()) + pcalibration.intercept; } else { UserError.Log.wtf(TAG, "Calibration plugin failed intercept sanity check: " + pcalibration.toS()); Home.toaststaticnext("Calibration plugin failed intercept sanity check"); @@ -1122,7 +1123,11 @@ public static synchronized BgReading bgReadingInsertFromG5(double calculated_val bgr.calculated_value = calculated_value; bgr.raw_data = SPECIAL_G5_PLACEHOLDER; // placeholder if (Ob1G5CollectionService.usingG6()) { - bgr.appendSourceInfo("G6 Native"); + if (shortTxId()) { // If using G7 + bgr.appendSourceInfo("G7"); + } else { + bgr.appendSourceInfo("G6 Native"); + } } else { bgr.appendSourceInfo("G5 Native"); } @@ -2035,6 +2040,7 @@ public static boolean trendingToAlertEnd(Context context, boolean above) { return false; } + // TODO: Should we add documentation to address possible misbehavior in case of 1-minute readings? if(above == false) { // This is a low alert, we should be going up if((latest.get(0).calculated_value - latest.get(1).calculated_value > 4) || @@ -2044,8 +2050,8 @@ public static boolean trendingToAlertEnd(Context context, boolean above) { } } else { // This is a high alert we should be heading down - if((latest.get(1).calculated_value - latest.get(0).calculated_value > 4) || - (latest.get(2).calculated_value - latest.get(0).calculated_value > 10)) { + if((latest.get(1).calculated_value - latest.get(0).calculated_value > 1) || + (latest.get(2).calculated_value - latest.get(0).calculated_value > 2)) { Log.d(TAG_ALERT, "trendingToAlertEnd returning true for high alert"); return true; } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/BloodTest.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/BloodTest.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/BloodTest.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/BloodTest.java index 731a3818dc..f4cb478b56 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/BloodTest.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/BloodTest.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.provider.BaseColumns; import android.util.Log; @@ -12,12 +12,12 @@ import com.eveningoutpost.dexdrip.AddCalibration; import com.eveningoutpost.dexdrip.glucosemeter.GlucoseReadingRx; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Services.SyncService; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.UploaderQueue; +import com.eveningoutpost.dexdrip.services.SyncService; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.UploaderQueue; import com.eveningoutpost.dexdrip.calibrations.CalibrationAbstract; import com.eveningoutpost.dexdrip.calibrations.NativeCalibrationPipe; import com.eveningoutpost.dexdrip.calibrations.PluggableCalibration; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Bubble.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/Bubble.java similarity index 91% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/Bubble.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/Bubble.java index 1c3bd139ad..251534d0d3 100755 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Bubble.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/Bubble.java @@ -1,14 +1,14 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.NFCReaderX; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.BridgeResponse; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.LibreUtils; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.BridgeResponse; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.LibreUtils; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import java.nio.ByteBuffer; import java.text.SimpleDateFormat; @@ -44,7 +44,7 @@ public static BridgeResponse getBubbleResponse() { if (!Pref.getBooleanDefaultFalse("external_blukon_algorithm")) { if (patchInfo != null && patchInfo.length > 0) { int first = 0xff & patchInfo[0]; - if (first == 0x9D || first == 0xE5) {//Libre us and libre2 Libre pro + if (first == 0x9D || first == 0xE5 || first == 0xE6) {//Libre us and libre2 Libre pro if (fv >= 2.6) { ackMessage.put(0, (byte) 0x08); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Calibration.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/Calibration.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/Calibration.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/Calibration.java index 5d8546bc49..a2fd9e97d2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Calibration.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/Calibration.java @@ -1,10 +1,10 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.provider.BaseColumns; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import android.widget.Toast; import com.activeandroid.ActiveAndroid; @@ -14,16 +14,16 @@ import com.activeandroid.query.Select; import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.CalRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.CalSubrecord; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService; -import com.eveningoutpost.dexdrip.UtilityModels.BgSendQueue; -import com.eveningoutpost.dexdrip.UtilityModels.CalibrationSendQueue; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Notifications; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.CalRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.CalSubrecord; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.services.Ob1G5CollectionService; +import com.eveningoutpost.dexdrip.utilitymodels.BgSendQueue; +import com.eveningoutpost.dexdrip.utilitymodels.CalibrationSendQueue; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Notifications; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.calibrations.CalibrationAbstract; import com.eveningoutpost.dexdrip.calibrations.NativeCalibrationPipe; import com.eveningoutpost.dexdrip.calibrations.PluggableCalibration; @@ -39,7 +39,7 @@ import java.util.List; import java.util.UUID; -import static com.eveningoutpost.dexdrip.Models.BgReading.isDataSuitableForDoubleCalibration; +import static com.eveningoutpost.dexdrip.models.BgReading.isDataSuitableForDoubleCalibration; import static com.eveningoutpost.dexdrip.calibrations.PluggableCalibration.newFingerStickData; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/CalibrationRequest.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/CalibrationRequest.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/CalibrationRequest.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/CalibrationRequest.java index ea9d56888e..cb4b2b8e2f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/CalibrationRequest.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/CalibrationRequest.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.provider.BaseColumns; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/CobCalc.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/CobCalc.java similarity index 78% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/CobCalc.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/CobCalc.java index 0b37a795bc..ca4c5d226c 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/CobCalc.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/CobCalc.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; /** * Created by jamorham on 04/01/16. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/DateUtil.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/DateUtil.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/DateUtil.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/DateUtil.java index 07cb79050a..2db57a7e6b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/DateUtil.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/DateUtil.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import org.joda.time.DateTime; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/DesertSync.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/DesertSync.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/DesertSync.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/DesertSync.java index 84042d3e1c..8b82bd3180 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/DesertSync.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/DesertSync.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.os.Bundle; import android.provider.BaseColumns; @@ -12,13 +12,13 @@ import com.eveningoutpost.dexdrip.Home; import com.eveningoutpost.dexdrip.JamListenerSvc; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; -import com.eveningoutpost.dexdrip.UtilityModels.desertsync.DesertComms; -import com.eveningoutpost.dexdrip.UtilityModels.desertsync.RouteTools; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; +import com.eveningoutpost.dexdrip.utilitymodels.desertsync.DesertComms; +import com.eveningoutpost.dexdrip.utilitymodels.desertsync.RouteTools; import com.eveningoutpost.dexdrip.utils.CipherUtils; import com.eveningoutpost.dexdrip.webservices.XdripWebService; import com.eveningoutpost.dexdrip.xdrip; @@ -39,9 +39,9 @@ import lombok.NoArgsConstructor; import static com.eveningoutpost.dexdrip.GoogleDriveInterface.getDriveIdentityString; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; -import static com.eveningoutpost.dexdrip.UtilityModels.desertsync.RouteTools.getBestInterfaceAddress; -import static com.eveningoutpost.dexdrip.UtilityModels.desertsync.RouteTools.ip; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.utilitymodels.desertsync.RouteTools.getBestInterfaceAddress; +import static com.eveningoutpost.dexdrip.utilitymodels.desertsync.RouteTools.ip; // created by jamorham 18/08/2018 diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/models/FakeLibreData.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/FakeLibreData.java new file mode 100644 index 0000000000..d47c92a299 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/FakeLibreData.java @@ -0,0 +1,125 @@ +package com.eveningoutpost.dexdrip.models; + +import java.util.Vector; + +class FakeData { + byte[] data; + byte[] patchUid; + byte[] patchInfo; +} + + +public class FakeLibreData { + + private static FakeLibreData single_instance = null; + + public static FakeLibreData getInstance() + { + if (single_instance == null) + single_instance = new FakeLibreData(); + + return single_instance; + } + + + Vector fakeDataVector; + int VectorLocation; + + FakeLibreData() { + fakeDataVector = new Vector(); + VectorLocation = 0; + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000000C290F066807009496006907009496006907009096006C07009096006C07009096006F07009096006F07008C96007207008C96007507008C96007507008C96007907008C96007B07008C96007D07008C96007D07008C96008707080697006707009896000E0700CC9600F60700E49600DF07002C97007607005C9700690700A896007607008C96002E0500845A00000500709900DD0400B059001F0500B45900290500645A004905004C5A00810500309A00F90500645A00B00600E05A007C0700D05A00260800405A00380800745B003E08004C5A00B108002C99000509006459003009000C5900DC08001C9900340800C05A002C0700E859001D0600605A00D80400F05A007C0400805A00680500D897004B06002498004F0600209700CA0600D89600FF0501002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008430F"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000001A5B0108DF0600E098000707009459000607009C59000607009859000307009459000407009459000307007459000807007098000F0700209800150700F09700140700C89700130700F89700130700649800410700E89800170700C49800F90600D098000E0700CC9600F60700E49600DF07002C97007607005C9700690700A896007607008C96001607007859000A0700709800DD0400B059001F0500B45900290500645A004905004C5A00810500309A00F90500645A00B00600E05A007C0700D05A00260800405A00380800745B003E08004C5A00B108002C99000509006459003009000C5900DC08001C9900340800C05A002C0700E859001D0600605A00D80400F05A007C0400805A00680500D897004B06002498004F0600209700CA0600D89600220601002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008B808"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000605D0F05710300985900840300985900930300985900A50300A05900B803009C5900C30300BC5900DB0300C45900EF0300CC5900030400D859000C0400DC59001B0400E45900200400DC5900340400D859004C0400F05900570400CC59005F0300A45900830300505A00150300D45A00DC0200745A00280300E85900190400E459007607008C96001607007859000A07007098009906005459005506007898002306007898001306008C5900BF0500945A006C0500F49700160500049700D50400649700BD0400109700A30400289800A10400EC9600720400A89600420400989600130400889600D40300DC5800B70300885800C10300489700100400CC97007A0400EC9600C10400249700E70400449700870400A89600300400BC5700C00300CC5900D00701002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830082C0F"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000D3FA0805760400E859008D0400DC59009B0400205A00A50400205A00BA0400145A00CA0400205A00DB0400345A00E30400945A00030400D859000C0400DC59001B0400E45900200400DC5900340400D859004C0400F05900570400CC5900680408E65900830300505A00150300D45A00DC0200745A00280300E85900190400E459007607008C96001607007859000A07007098009906005459005506007898002306007898001306008C5900BF0500945A006C0500F49700160500049700D50400649700BD0400109700A30400289800A10400EC9600720400A89600420400989600130400889600D40300DC5800B70300885800C10300489700100400CC97007A0400EC9600C10400249700E70400449700870400A89600300400BC5700C00300CC5900D90701002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008A217"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000091950008A20500E85A00A80500D05A00B30500C05A00B90500A85A00C00500905A00C505008C5A00CD0500845A00DB05007C5A00E40500745A00EA05007C5A00EE0500745A00F005006C5A00F20500545A00F405005C5A00F005006C5A00F20500585A00830300505A00150300D45A00DC0200745A00280300E85900190400E45900EF0400E05A00660500605B00D805007C5A009906005459005506007898002306007898001306008C5900BF0500945A006C0500F49700160500049700D50400649700BD0400109700A30400289800A10400EC9600720400A89600420400989600130400889600D40300DC5800B70300885800C10300489700100400CC97007A0400EC9600C10400249700E70400449700870400A89600300400BC5700C00300CC5900010801002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830081F09"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000009DA707127604002C5A00730400305A00710400705A006E0400545A007304005C5A007B0400405A007C0400245A007B0400FC5900710400F85900760400F45900720400E459006F0400E059006F0400F85900740400085A00720400205A007504002C5A00830300505A00150300D45A00DC0200745A00280300E85900190400E45900EF0400E05A00660500605B00D805007C5A00FE0500545A002B0600805A00FA0500B85A00270600EC5A00D80600605A004C0700DC5A00330700545A00530600E059000B0500C05900710400085A00A10400EC9600720400A89600420400989600130400889600D40300DC5800B70300885800C10300489700100400CC97007A0400EC9600C10400249700E70400449700870400A89600300400BC5700C00300CC5900980801002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008081A"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000C9210B133C0400F85900400400D45900400400A059003E04008859003D04007C59003D04006459004304006059004804005459005004005459005304004059005B04002859004C0400BC5900450400C85900400400B85900370400BC59003E0400DC5900830300505A00150300D45A00DC0200745A00280300E85900190400E45900EF0400E05A00660500605B00D805007C5A00FE0500545A002B0600805A00FA0500B85A00270600EC5A00D80600605A004C0700DC5A00330700545A00530600E059000B0500C05900710400085A00450400C85900720400A89600420400989600130400889600D40300DC5800B70300885800C10300489700100400CC97007A0400EC9600C10400249700E70400449700870400A89600300400BC5700C00300CC5900AC0801002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830081B23"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000FD760C03470400BC5A004A0400B85A004904008C5A004E0400805A005D04003C5A00640400645A00660400685A006C0400885A006E0400B85A006A0400D45A00670400D45A00670400D85A00370400FC5A003A0400F85A00400400FC5A00450400DC5A00690300AC5A00C40300985B00340400FC5A00240500B09800B60500C49800E10500985900450600F09700780600AC9700380600985700960500045A005505008097003C05009897009D0500FC58009D0500489800960500F49600A00500705900700500089900610500005900F404000C9800A70400285900AD04006C1B80620400B45B00260400905900FC03009C9800B30300009800770300E497002B0300389700C90200DC9600880200A896009A02001497006B0200649700DB0200C85A005D0D01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830085B1B"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000074530904870400F45A00920400FC5A00A104000C5B00AC0400E85A00C40400DC5A00D30400EC5A00E50400F85A00F80400F45A00020500105B006A0400D45A00670400D45A00670400D85A00720408EA5A00700400D05A00770400F05A007F0400F45A00690300AC5A00C40300985B00340400FC5A006A0400D85A00B60500C49800E10500985900450600F09700780600AC9700380600985700960500045A005505008097003C05009897009D0500FC58009D0500489800960500F49600A00500705900700500089900610500005900F404000C9800A70400285900AD04006C1B80620400B45B00260400905900FC03009C9800B30300009800770300E497002B0300389700C90200DC9600880200A896009A02001497006B0200649700DB0200C85A006A0D01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830086902"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000E4110008D505003C5B00DB0500285B00DB0500005B00DC0500005B00E30500FC5A00E80500185B00E905002C5B00ED0500485B00F10500585B00EA0500405B00E40500285B00E70500245B00E00500345B00D20500145B00D80500285B00D305002C5B00690300AC5A00C40300985B00340400FC5A006A0400D85A00130500745B00940500DC5A00BE0500681B80EB0500485B00380600985700960500045A005505008097003C05009897009D0500FC58009D0500489800960500F49600A00500705900700500089900610500005900F404000C9800A70400285900AD04006C1B80620400B45B00260400905900FC03009C9800B30300009800770300E497002B0300389700C90200DC9600880200A896009A02001497006B0200649700DB0200C85A00A00D01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008B627"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000000637060CE30500685A00DE05005C5A00DD0500385A00D20500185A00CA05002C5A00C90500285A00FF0500CC5A00060600C85A00090600AC5A000E0600345B001A0600705B002906006C1B80170600945B000106003C5B00E70500C45A00DF0500885A00690300AC5A00C40300985B00340400FC5A006A0400D85A00130500745B00940500DC5A00BE0500681B80EB0500485B00D90500E85A00C605009C5A00F70500A05A00D30500185A009D0500FC58009D0500489800960500F49600A00500705900700500089900610500005900F404000C9800A70400285900AD04006C1B80620400B45B00260400905900FC03009C9800B30300009800770300E497002B0300389700C90200DC9600880200A896009A02001497006B0200649700DB0200C85A00D70D01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830080F1E"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000E9B60E10870700AC5A00940700D45A00AC0700FC5A00BF0700D85A00C90700C05A00D80700B05A00D807009C5A00E00700745A00F007008C5A00EF0700105B000A0800C45A00200800AC5A002C0808A65A003F08009C5A008E0700B05A00900700B45A00690300AC5A00C40300985B00340400FC5A006A0400D85A00130500745B00940500DC5A00BE0500681B80EB0500485B00D90500E85A00C605009C5A00F70500A05A00D30500185A00280600BC5A007D06006C5A00D10600AC5A008B0700B45A00700500089900610500005900F404000C9800A70400285900AD04006C1B80620400B45B00260400905900FC03009C9800B30300009800770300E497002B0300389700C90200DC9600880200A896009A02001497006B0200649700DB0200C85A001F0E01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830080506"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000001C220010870700AC5A00940700D45A00AC0700FC5A00BF0700D85A00C90700C05A00D80700B05A00D807009C5A00E00700745A00F007008C5A00EF0700105B000A0800C45A00200800AC5A002C0808A65A003F08009C5A00420808965A00480800105B00690300AC5A00C40300985B00340400FC5A006A0400D85A00130500745B00940500DC5A00BE0500681B80EB0500485B00D90500E85A00C605009C5A00F70500A05A00D30500185A00280600BC5A007D06006C5A00D10600AC5A008B0700B45A00700500089900610500005900F404000C9800A70400285900AD04006C1B80620400B45B00260400905900FC03009C9800B30300009800770300E497002B0300389700C90200DC9600880200A896009A02001497006B0200649700DB0200C85A00200E01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008BF25"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000036E20211530800B85A005E0800A85A00AC0700FC5A00BF0700D85A00C90700C05A00D80700B05A00D807009C5A00E00700745A00F007008C5A00EF0700105B000A0800C45A00200800AC5A002C0808A65A003F08009C5A00420808965A00480800105B00690300AC5A00C40300985B00340400FC5A006A0400D85A00130500745B00940500DC5A00BE0500681B80EB0500485B00D90500E85A00C605009C5A00F70500A05A00D30500185A00280600BC5A007D06006C5A00D10600AC5A008B0700B45A00480808965A00610500005900F404000C9800A70400285900AD04006C1B80620400B45B00260400905900FC03009C9800B30300009800770300E497002B0300389700C90200DC9600880200A896009A02001497006B0200649700DB0200C85A00230E01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830085B07"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000067F80E19470900D01B80420900C81B805A0900485B006309003C5A00560900FC59004B0900E059003B09007899003C09001C5900370900B059004E0900745A003909007C5A00130900F85A00F90800805A00D80800685A00230900A45B003B0900BC1B80690300AC5A00C40300985B00340400FC5A006A0400D85A00130500745B00940500DC5A00BE0500681B80EB0500485B00D90500E85A00C605009C5A00F70500A05A00D30500185A00280600BC5A007D06006C5A00D10600AC5A008B0700B45A00480808965A001D0900241B805E0900C85A008B0900805A001D0A00705A002E0A00CC5A00DC0900C45A00400900505B00430900789900770300E497002B0300389700C90200DC9600880200A896009A02001497006B0200649700DB0200C85A009F0E01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830086B12"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000095210E1A770800385A005608004C5A00380800805A00190800C45A00F20700D05A00C60700B85A008F0700AC5A005A0700745A003C07005C5A00210700845A001107006C5A00F30600A85A00DE0600C85A00C40600A45A00AF0808FA59008C0800EC5900690300AC5A00C40300985B00340400FC5A006A0400D85A00130500745B00940500DC5A00BE0500681B80EB0500485B00D90500E85A00C605009C5A00F70500A05A00D30500185A00280600BC5A007D06006C5A00D10600AC5A008B0700B45A00480808965A001D0900241B805E0900C85A008B0900805A001D0A00705A002E0A00CC5A00DC0900C45A00400900505B00430900789900BE0700B85A002B0300389700C90200DC9600880200A896009A02001497006B0200649700DB0200C85A00AF0E01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830084D12"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000057DA0217D30300285B00CC0300CC5B00F20300305A00F40300A45900F60300805A00F20300145B00E70300901B80DD0300945B00CC03004C5B00C203000C5B00C20300685B00C40300A85A00BF0300705A00D10300A05A00E10300F05A00DE0300F45A00E60200185A001C03000C5A007F0300E45900610400685900EB0400F05800B00400785B003E0400045B00AC03007C5B009F0300DC5A00880300685B00DE0200E45B006F0200285900990200085B00E80200841B80070300005B003E0300B059005D0300F45900A80300F45800EB0300F45A001D0300985A00060300689800E70300085A00D003004C5B00400900505B00430900789900BE0700B85A00FF0500005B00250400345A007D0200A89700CA02002058002803006859008B0300BC5A00621001002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830082E2C"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000008C9D0617D30300285B00CC0300CC5B00C50300585C00B60300481C80A50300405C00A20300605C00E70300901B80DD0300945B00CC03004C5B00C203000C5B00C20300685B00C40300A85A00BF0300705A00D10300A05A00E10300F05A00DE0300F45A00E60200185A001C03000C5A007F0300E45900610400685900EB0400F05800B00400785B003E0400045B00AC03007C5B009F0300DC5A00880300685B00DE0200E45B006F0200285900990200085B00E80200841B80070300005B003E0300B059005D0300F45900A80300F45800EB0300F45A001D0300985A00060300689800E70300085A00D003004C5B00400900505B00430900789900BE0700B85A00FF0500005B00250400345A007D0200A89700CA02002058002803006859008B0300BC5A00661001002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830084A34"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000002290B0DB40500205A00C80500245A00CC0500445A00CC0500245A00EE0500145A00010600185A00110600185A002206004C5A002D0600805A00480600785A006F0600B01A80730500485A008005004C5A00870500385A00A60500245A00B405002C5A00440300D85A003C0300DC5B00810300605B008E0300B05A00C40300C05A007C0400CC5A00EE0400745A00EE0400D45A00E50400045B00D90400C85A00CF0400385A00E50400305A00CD0500445A006C0400C85B00370400745900100400B09800D60300F85700E10300349700BD0300089700840300409700480300245800BB0300B497006904007497008F0400C896002B04004C9700D10300209700590300609700250300F09600200300B858000003000C9700FC02008096002903004859008B1301002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830084927"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000097220312390800F858002808005459001108002459005E0800FC59007608001C5A008D0800445A008E08008C5A009D0800DC1A80960800001B80860800281B80870800581B80770800F85A006B0800705A005E0800D05900550800605900470800105900440300D85A003C0300DC5B00810300605B008E0300B05A00C40300C05A007C0400CC5A00EE0400745A00EE0400D45A00E50400045B00D90400C85A00CF0400385A00E50400305A00CD0500445A00B10600185A00770700305A00240800745900630800A459005F0800D05900BD0300089700840300409700480300245800BB0300B497006904007497008F0400C896002B04004C9700D10300209700590300609700250300F09600200300B858000003000C9700FC0200809600290300485900D41301002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008B206"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000001FF00B1DDD04008C5900E10400A45900DC0400CC5900E30400E05900E20400D85900DC0400D45900DB0400905900D30400AC5900C40400A45900C70400745900C104007459001F0500185A000905001C5A00FE0400205A00EC0400E05900E20400A85900440300D85A003C0300DC5B00810300605B008E0300B05A00C40300C05A007C0400CC5A00EE0400745A00EE0400D45A00E50400045B00D90400C85A00CF0400385A00E50400305A00CD0500445A00B10600185A00770700305A00240800745900630800A459005F0800D05900970600585A00090500045A008F0400EC5A00720400C05A00A004009059005805005058000A0600889700790600EC5600CA0500585900D30500345A00DF0400CC59000003000C9700FC02008096002903004859007B1401002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830082426"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000F0E3041E270500E058003905000059005A0500005900680500105900E20400D85900DC0400D45900DB0400905900D30400AC5900C40400A45900C70400745900C10400745900C60400605900D804003C5900E80400145900FC0400EC9800120500CC5800440300D85A003C0300DC5B00810300605B008E0300B05A00C40300C05A007C0400CC5A00EE0400745A00EE0400D45A00E50400045B00D90400C85A00CF0400385A00E50400305A00CD0500445A00B10600185A00770700305A00240800745900630800A459005F0800D05900970600585A00090500045A008F0400EC5A00720400C05A00A004009059005805005058000A0600889700790600EC5600CA0500585900D30500345A00DF0400CC59003D0500005900FC0200809600290300485900841401002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008862B"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000005A78010C930500105900770400905800970400885800AC04009C5800AD0400985800B904009C5800D20400945800F20400785800240500AC5800610500C45800950500FC5800A50500105900AA0500205900A105001C5900A505002459009B0500305900AB0500DC5900E40500005A00DB0500905900B60500AC5900A50500E45900600500645700CD0400445800F20300E05700E402007059002B02003C59002B0300085900A004009C5800CD0500445A00B10600185A00770700305A00240800745900630800A459005F0800D05900970600585A00090500045A008F0400EC5A00720400C05A00A004009059005805005058000A0600889700790600EC5600CA0500585900D30500345A00DF0400CC59003D0500005900C605009C59000E0600EC5900611501002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830086734"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000052CF05002C0700A459000D07004C5900280700B859003B0700B458003F07007C98000D07006459002707009459001D07008059000907005C5900FD0600005900040700FC5800150700005900210700FC58002607006C5900210700A859002607009C5900AB0500DC5900E40500005A00DB0500905900B60500AC5900A50500E45900600500645700CD0400445800F20300E05700E402007059002B02003C59002B0300085900A004009C5800A60500145900A90500DC5800360500B058008E0400605900FC03003859004A03007459003E0300DC5900B40300945900C303002C5A005E0400385A002A0500281B80AE06005859002F0700245A00D40600F45900850600941A801D05009C5800890500FC5700480600B05800E406003C58002107009C5900851601002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008022A"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000B72C0411350400F85A00300400DC5A00370400005B00370400E45A006A0400885A00590400605A00610400A45A00670400B85A00690400745A00560400505A004E0400AC5A003E0400B05A003A0400A01A80370400A85A00380400D85A00350400185B00E30300385900820300C81A80690300DC1A80400300C05A00670300FC57006D0300B81980910300AC59009E0300285A00840300F85900BB0300B85A003B0400D85800450400DC58003904009C5900F90400045A00390500745900950400D05900370400D85A00190400F058005104004097003504007C97002A0400549700710400189700550400B09700B20400449700BA0400189700BE04004097009D0400109700A704001057007104002059003F0400EC9600FC0300B05800E103002C9800651901002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008D703"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000055BB0B18170800585A001B0800645A00010800401A80EB07003C5A00DE0700445A00C40700285A00A907000C5A008A0700005A006B0700EC59004B0700CC59002A0700D859004408004C5A00230800505A00220800385A000D0800405A001A0800405A00E30300385900820300C81A80690300DC1A80400300C05A00670300FC57006D0300B81980910300AC59009E0300285A00840300F85900BB0300B85A003B0400D85800450400DC58003904009C5900F90400045A00390500745900950400D05900370400D85A007F0400405A000E0500545800CA06001C5A003A08008C5900A408009C5800380800305A00890700005A00BA0400189700BE04004097009D0400109700A704001057007104002059003F0400EC9600FC0300B05800E103002C9800CC1901002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830080A1E"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000DA2D01182506001859001B0800645A00010800401A80EB07003C5A00DE0700445A00C40700285A00A907000C5A008A0700005A006B0700EC59004B0700CC59002A0700D85900090708BE5900E406002C59009E06005C59007706008C5900530600545900E30300385900820300C81A80690300DC1A80400300C05A00670300FC57006D0300B81980910300AC59009E0300285A00840300F85900BB0300B85A003B0400D85800450400DC58003904009C5900F90400045A00390500745900950400D05900370400D85A007F0400405A000E0500545800CA06001C5A003A08008C5900A408009C5800380800305A00890700005A00BA0400189700BE04004097009D0400109700A704001057007104002059003F0400EC9600FC0300B05800E103002C9800D11901002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830080627"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000E0F40E11A804002C5900A00400505900980400EC58009B0400FC58009E04000459009904004459008E04004059008204002C59008704006459008004005C59008204006859007804007C5900730400785900720400785900BF0400F45800B504004C59008D0800585900C30700285A00C50500FC19801F0500E05900840500801A80890500385A00428600DE5800DA06007C1A806F0700D01A80ED0700001B805D0800E85800770800B85A003B0600301A80A20500A059004F0500445900FA04002C5900B50400F458007F0400405A000E0500545800CA06001C5A003A08008C5900A408009C5800380800305A00890700005A009E0500DC58001F0500789700C204005C5800060500B05900C80500F896003406002058002B0700609700130800BC57004E1B01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830087932"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000079000E16EE0500E45900FB0500E45900FD05003C5A00FD0500385A00F705006C5A00080600645A000F0600645A001B0600585A003006005C5A002E0600585A00270600505A002206001C5A00340600145A00370600F05900FB0500F85900F80500E459008D0800585900C30700285A00C50500FC19801F0500E05900840500801A80890500385A00428600DE5800DA06007C1A806F0700D01A80ED0700001B805D0800E85800770800B85A003B0600301A80A20500A059004F0500445900FA04002C5900B50400F45800730400785900A10400845900510500A45900D30500A85900260600585A00380800305A00890700005A009E0500DC58001F0500789700C204005C5800060500B05900C80500F896003406002058002B0700609700130800BC57008F1B01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830083E18"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000B6F20C183B06005859003306005C5900430600E458004B06008458005906003C58006206001858006E0600E85700700600CC97007906000C58008E06005058009606001C5800860600F057001D06009859002D06007059003506005859004606006C59008D0800585900C30700285A00C50500FC19801F0500E05900840500801A80890500385A00428600DE5800DA06007C1A806F0700D01A80ED0700001B805D0800E85800770800B85A003B0600301A80A20500A059004F0500445900FA04002C5900B50400F45800730400785900A10400845900510500A45900D30500A85900260600585A00100600EC5900740600CC97009E0500DC58001F0500789700C204005C5800060500B05900C80500F896003406002058002B0700609700130800BC5700AC1B01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830088738"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000D52E0F197706004059007806006059006B06005059006C06005059006006004859005806004059005306006059006106006459007206007459007A0600A059007406007C59007F06007C59009306005059009606003459009B06005459008506000459008D0800585900C30700285A00C50500FC19801F0500E05900840500801A80890500385A00428600DE5800DA06007C1A806F0700D01A80ED0700001B805D0800E85800770800B85A003B0600301A80A20500A059004F0500445900FA04002C5900B50400F45800730400785900A10400845900510500A45900D30500A85900260600585A00100600EC5900740600CC97005F06006059001F0500789700C204005C5800060500B05900C80500F896003406002058002B0700609700130800BC5700BF1B01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008DE2C"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000CAB00A0AD80A00E05900DC0A00E85900E30A00D85900090B00E05900210B00B45900320B00BC59003D0B00D059003E0B00DC59003F0B00D459004C0B00DC59009A0A00B05900A90A00B85900A90A00A45900AE0A00E05900A60A00145A00BD0A00E859006703009C5A00BE0300081C80EB0300745C009C0300FC5B00130400205B003305004C5B00DF0600A05A00A50800F459001E0A008859002B0B00BC59008B0700C896002D0700B496002D07007496008A0700E45700CD0700889700CB07007497008707001C9700CF0700F89600000800D09600390800AC9600E90700409700B80700509700F906003C9700810600C05700DF0500BC97005C05005C5700D804001C9700940400F896003104008C9700C403001C97007603005C57003E03008059009B1E01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008B81D"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000097F1040F290A00DC5900120A002C5A00F00900305A00090A000C5A008F0A00B45900920A00B05900950A00C45900960A00E05900950A00F05900B60A00CC5900B40A00F059009F0A00EC59007E0A00E459006E0A00E059005C0A00DC5900440A00D459006703009C5A00BE0300081C80EB0300745C009C0300FC5B00130400205B003305004C5B00DF0600A05A00A50800F459001E0A008859002B0B00BC5900000B00A05A00D40A00E05900BE0A00D05900860A00585900280A00DC5900CB07007497008707001C9700CF0700F89600000800D09600390800AC9600E90700409700B80700509700F906003C9700810600C05700DF0500BC97005C05005C5700D804001C9700940400F896003104008C9700C403001C97007603005C57003E0300805900E51E01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830084B0F"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000008865010FA70900245A00120A002C5A00F00900305A00090A000C5A00FF0908225A00E10900405A00CC0900405A00C809001C5A00BA0900145A00BA0900F85900C70900E05900C30900E85900BE0900E85900A20900F459009109001C5A00890900145A006703009C5A00BE0300081C80EB0300745C009C0300FC5B00130400205B003305004C5B00DF0600A05A00A50800F459001E0A008859002B0B00BC5900000B00A05A00D40A00E05900BE0A00D05900860A00585900280A00DC5900CB07007497008707001C9700CF0700F89600000800D09600390800AC9600E90700409700B80700509700F906003C9700810600C05700DF0500BC97005C05005C5700D804001C9700940400F896003104008C9700C403001C97007603005C57003E0300805900F21E01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008B20A"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000039840214190600D45800080600F098004507003059002E0700205900120700FC5800FA0600F05800EB0600E45800E20600E45800CC0600E85800BF0600CC58009D0600E058007F0600AC58007A0600CC5800600600E858004C0600DC5800300600D858006703009C5A00BE0300081C80EB0300745C009C0300FC5B00130400205B003305004C5B00DF0600A05A00A50800F459001E0A008859002B0B00BC5900000B00A05A00D40A00E05900BE0A00D05900860A00585900280A00DC5900980900145A000909006C5A00E60800B85900A707004059008A0600AC5800E90700409700B80700509700F906003C9700810600C05700DF0500BC97005C05005C5700D804001C9700940400F896003104008C9700C403001C97007603005C57003E0300805900331F01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830087507"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000E6AE0C16820500B49800730500EC5800600500105900490500E058004D0500085900300500F05800270500F458002005002459001205001C59000D05003C5900E60400385900CB0400485900B00500EC5800B70500F45800A60500E05800940500CC58006703009C5A00BE0300081C80EB0300745C009C0300FC5B00130400205B003305004C5B00DF0600A05A00A50800F459001E0A008859002B0B00BC5900000B00A05A00D40A00E05900BE0A00D05900860A00585900280A00DC5900980900145A000909006C5A00E60800B85900A707004059008A0600AC5800CC0500EC5800FC04003C5900F906003C9700810600C05700DF0500BC97005C05005C5700D804001C9700940400F896003104008C9700C403001C97007603005C57003E03008059004D1F01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008900B"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000349D0509FA0300F45900080400D45900150400B45900140400805900F20300885900390400F458002D0400BC98002904000C59002504003059002B04006059002D04007059002304007C59000B0400C059000804009C5900080400BC5900F90300DC59008D0500F859003605000898008B0500549800F60500405900350600805900F80500545A00D30500A01B800A05008C5A00300400BC98002B0B00BC5900000B00A05A00D40A00E05900BE0A00D05900860A00585900280A00DC5900980900145A000909006C5A00E60800B85900A707004059008A0600AC5800CC0500EC5800FC04003C5900D00300C859004703009459009303008C5900F00300785A00D30400485A00E70500745900130700905900E207008459000A0800AC5900240700E85900752001002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830080630"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000AB360C0CC50300A45800D70300A45800D70300A05800C40300905800BF03007C5800B103005458009E03003C5800950300285800A103002C5800A90300105800A703000C5800A10300F05700EF0300DC5800D40300DC5800C40300985800D20300B458008D0500F859003605000898008B0500549800F60500405900350600805900F80500545A00D30500A01B800A05008C5A00300400BC9800F90300E45900D00300A85900C60300905800BE0A00D05900860A00585900280A00DC5900980900145A000909006C5A00E60800B85900A707004059008A0600AC5800CC0500EC5800FC04003C5900D00300C859004703009459009303008C5900F00300785A00D30400485A00E70500745900130700905900E207008459000A0800AC5900240700E859009C2001002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008462F"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000DAC808121C0300185A00140300145A00110300EC5900050300005A00FA0200045A00F302000C5A00E90200085A00E00200445A002F0300A459002B0300DC5900320300B859002E0300D85900270300F05900230300F45900240300FC59001E03000C5A008D0500F859003605000898008B0500549800F60500405900350600805900F80500545A00D30500A01B800A05008C5A00300400BC9800F90300E45900D00300A85900C60300905800BB0300F858000803005459001F0300D858003903002059003C0300405900250300F45900A707004059008A0600AC5800CC0500EC5800FC04003C5900D00300C859004703009459009303008C5900F00300785A00D30400485A00E70500745900130700905900E207008459000A0800AC5900240700E85900F92001002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830083015"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000008C830319AD0300FC5A00B103001C5B00A70300405B00790300485A007F03003C5A00830300EC1A808E0300AC5B008E0300545B00840300C05A00830300045A00870300EC59008D0300A459008E0300D059008E0300B459009B03003C5A00A70300685A008D0500F859003605000898008B0500549800F60500405900350600805900F80500545A00D30500A01B800A05008C5A00300400BC9800F90300E45900D00300A85900C60300905800BB0300F858000803005459001F0300D858003903002059003C0300405900250300F45900AF0200685A00A70200445A00DE0200CC5A00D70200805A00FD0200DC5A00360300C45900860300AC5B00F00300785A00D30400485A00E70500745900130700905900E207008459000A0800AC5900240700E85900642101002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008B411"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000E7EC080AD80500EC5900C00500D45900C30500D45900C60500B85900B40500CC5900B10500C85900B50500145A00C20500185A00E705001C9A00E00500485A00E405002C5A00E505001C5A00FB0500985900F20500605900D60500585900E60500C05900A00300C45A00770300245B00840300B45A00E103008C5A00150500345A00090600305A005A0600F85900540600945900FC0500505A00BA0500C859006E0400405800610400589700240400805800DA03006C5900050400DC58007A04008C97009304008457006E04004059006E0400A05900540400DC58005B04003C58002C0400F09600E30300585700F503004C97001F04001C5800BF04000458006C0500EC56003E05005C9600C704003096007904004496000C04006C5800D00300745B00392401002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008D617"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000F3F50F181705008C59001005005459001505005859000B05006C59000E0500885900250500705900220500605900100500705900F40400905900E50400909900DA0400689900E20400985900DA0400A05900D20400A85900CC0400D05900230500745900A00300C45A00770300245B00840300B45A00E103008C5A00150500345A00090600305A005A0600F85900540600945900FC0500505A00BA0500C85900290500205A007605007C59003F06004C5900330700B059004C0800E059005D0900EC5900AB0900385A008A0900D05900E708006C59000C0800B459002C0700A459006106007459007C05005C59000905007059001F04001C5800BF04000458006C0500EC56003E05005C9600C704003096007904004496000C04006C5800D00300745B00102501002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830080F19"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000009C4104043E0400E05900520400DC5900500400B05900610400A059003A0400AC59003F04009C59004304006459004704002859004904000C59006204004059006C04001C5900590400A459005204009859004504008859003B0400885900300400D85900DB0400345900B00400285900830400485900590400A45900150500345A00090600305A005A0600F85900540600945900FC0500505A00BA0500C85900290500205A007605007C59003F06004C5900330700B059004C0800E059005D0900EC5900AB0900385A008A0900D05900E708006C59000C0800B459002C0700A459006106007459007C05005C59000905007059005804004459002103002C59003C02000C59005902004C58005F0200085900460200A859008A0300A45900B204002C5900C52501002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008181D"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000DBDC000EDB06000C5A00DA8600125A00BB0600E05900A00600C05900A10600C85900870600285A00710600445A005D0600145A00580600EC5900560600E459005B0600F459004B0600CC5900520600B85900460600BC59004406008059005206007C5900DB0400345900B00400285900830400485900590400A45900880400985900CF0400705900020500BC5800360500B45800A00500605900EB0500FC58003F0600A459009C0600485900C40600245900C58600125A004C0800E059005D0900EC5900AB0900385A008A0900D05900E708006C59000C0800B459002C0700A459006106007459007C05005C59000905007059005804004459002103002C59003C02000C59005902004C58005F0200085900460200A859008A0300A45900B204002C5900612601002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008C416"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000EAE40F198005006C5900940500DC98009505009098009705006058009F0500349800AE0500445800B605005C5900CC0500D85900C80500205A00B80500985A00AA0500CC5A00A90500DC5A00A20500BC5A00AB0500E85A009D05000C5B005C0500545A00DB0400345900B00400285900830400485900590400A45900880400985900CF0400705900020500BC5800360500B45800A00500605900EB0500FC58003F0600A459009C0600485900C40600245900C58600125A00480608825900750600085900870600BC9800B80600AC5900020600605800A70500A45800B705004C59007A0500985900990500505A00080500F45C00B705005C59002103002C59003C02000C59005902004C58005F0200085900460200A859008A0300A45900B204002C5900002701002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008A61D"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000F9130E01570300BC5A004E0300BC5A004B0300885A00500300705A00490300645A00460300405A004F0300545A00530300705A004C0300705A00480300705A004603007C5A003E03006C5A00360300545A002D0300485A00680300E05A00610300DC5A00680300E05A00920400A496008A0400C89700730400C89700B40400A89700000500749700100500FC9600BA0400B09600580400505700E30300085900A503006C59009B0300885900CB03003C5A00540400E45800300400E057009304006897008E04002897006404000C9700420400109700400400E897000C04006099003E0400DC97008A0400AC9700870400A497003304008C9800E80300B09700E60300E49600EF0300A496004204000C9600AB04001896006A0400349800E803002459005F2901002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008DB1A"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000051830C01E50200E05700DC0200F49700D50200005800D00200DC9700CC0200A89700C00200F45700BB0200189800B00200309800B50200485800B20200489800AC0200449800A70200345800FF0200289700FD0200309700F60200749700F00200BC9700F40200749700310300485A00FB02009C5A006B0300045A00940400F459008D0500DC5900B20500EC5900CA0500885900D90500805900DB05009C5900FC0400345B00980400B45A00A10400B85A00180500145A00C805003C9900A30600785900230700A85900CE06002C5A00240600805A00C20500105A004C05004C5A00D10400905A007D0400DC5A00100500245B00240500E45A006D0500385A00910500CC5A006F0500A059004E04001859006C0300385900400300CC97004F03004C97003D2B01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830083117"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000A9130307760400145B00790400605B007D0400645B005B04007C5A00570400805A005C0400C45A00550400D85A00520400E05A006A0400D05A00760400845A00690400FC5A00700400DC5A00680400945A00680400F45A007404002C5B007504002C5B00D60400205A005A05002C5A003E0500EC5900C704009059008804009C5900460400505A00630400D05A000504002497002104009097004404003097002804001C9700AB03005C5A00640300645A00B30200A45A00180300545900510300005900A303002C98006104008497006B04004497005104009457001D0400189800A303002098009A0300D498002C0300289800960300D45800EE03002C5900E40300885800DA0300505900EB03005859003C04003459009B04001C5A005A0400F85A00542F01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830083315"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000695C030A810300905A00870300B05A00840300C05A001F0400F05A00160400FC5A00FE0300E05A00ED0300945A00E50300945A00DB0300905A00CF0300905A00CA0300B05A00BF0300AC5A00A50300985A008F0300A85A007D0300A45A00840300985A00D60400205A005A05002C5A003E0500EC5900C704009059008804009C5900460400505A00630400D05A00850400245B00A704008C5A00010400E05A002804001C9700AB03005C5A00640300645A00B30200A45A00180300545900510300005900A303002C98006104008497006B04004497005104009457001D0400189800A303002098009A0300D498002C0300289800960300D45800EE03002C5900E40300885800DA0300505900EB03005859003C04003459009B04001C5A005A0400F85A00832F01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008CA31"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000008810060C350300045A00330300385A003A0300045A002B0300105A00230300005A001A0300145A007B0300985A006A0300A45A00610300A05A005A0300985A00520300845A004A0300885A00450300A05A003A03007C5A003103005C5A003503001C5A00D60400205A005A05002C5A003E0500EC5900C704009059008804009C5900460400505A00630400D05A00850400245B00A704008C5A00010400E05A00880300AC5A002A0300105A00640300645A00B30200A45A00180300545900510300005900A303002C98006104008497006B04004497005104009457001D0400189800A303002098009A0300D498002C0300289800960300D45800EE03002C5900E40300885800DA0300505900EB03005859003C04003459009B04001C5A005A0400F85A00972F01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830083122"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000CB3E0B13F70200909900F10200909900F10200BC5900F50200005A00FE0200085A00090300285A000E0300305A00140300645A001A0300345A001E0300285A001F03002C5A00240300C459001F0300BC5900160300BC5900030300B85900FA0200AC5900D60400205A005A05002C5A003E0500EC5900C704009059008804009C5900460400505A00630400D05A00850400245B00A704008C5A00010400E05A00880300AC5A002A0300105A003C03003C5A00FC0300285A00300400985900ED0300B85900DF03008C9900750300B059001B0300BC59005104009457001D0400189800A303002098009A0300D498002C0300289800960300D45800EE03002C5900E40300885800DA0300505900EB03005859003C04003459009B04001C5A005A0400F85A000C3001002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830086308"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000086F10A1A310200B05A001D02008C5A001002008C5A000B0200985A00060200AC5A00020200585A000F0200645A00130200785A001A02006C5A00140200705A00830200DC5A00750200E45A00670200005B00580200FC5A00490200E45A003B0200E05A00D60400205A005A05002C5A003E0500EC5900C704009059008804009C5900460400505A00630400D05A00850400245B00A704008C5A00010400E05A00880300AC5A002A0300105A003C03003C5A00FC0300285A00300400985900ED0300B85900DF03008C9900750300B059001B0300BC59002003081A9A007F0300B85900B90300E09900A40300405A006C0300D05A00C70200E05A000A0200585A00E40300885800DA0300505900EB03005859003C04003459009B04001C5A005A0400F85A006B3001002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008EF0E"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000FEB4021E630200505A007D0200345A00EA0100645A00F30100585A00FD0100585A000702004C5A00100200585A001C0200645A00230200605A002C0200585A003302006C5A00370200685A00370200605A003C0200585A004502005C5A00530200485A00D60400205A005A05002C5A003E0500EC5900C704009059008804009C5900460400505A00630400D05A00850400245B00A704008C5A00010400E05A00880300AC5A002A0300105A003C03003C5A00FC0300285A00300400985900ED0300B85900DF03008C9900750300B059001B0300BC59002003081A9A007F0300B85900B90300E09900A40300405A006C0300D05A00C70200E05A000A0200585A00BE0200F85900E90200D498004E0200F05800E70100585A009B04001C5A005A0400F85A00B23001002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830085C38"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000A82E0505F70600E85A00FD0600BC5A000C0700DC5A00360700B45A00300700985A00F106003C5B00ED0600345B00EF06003C5B00E90600445B00E50600345B00F90600185B00F80600185B00FA0600005B00F80600E85A00FA0600C45A00FE0600F85A00100500645A00B40500E45900E50500185B00560600645B00F10600185B00460400505A00630400D05A00850400245B00A704008C5A00010400E05A00880300AC5A002A0300105A003C03003C5A00FC0300285A00300400985900ED0300B85900DF03008C9900750300B059001B0300BC59002003081A9A007F0300B85900B90300E09900A40300405A006C0300D05A00C70200E05A000A0200585A00BE0200F85900E90200D498004E0200F05800E70100585A005E0200505A00210400945A00153101002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008C934"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000A9100306130700805A000F0700885A00FF0600685A00360700B45A00300700985A00270700A45A001B0700A05A000C07009C5A00070700E05A00080700EC5A00070700B85A00080700CC5A00F90600AC5A00F80600845A00020700685A00110700685A00100500645A00B40500E45900E50500185B00560600645B00F10600185B00080700EC5A00630400D05A00850400245B00A704008C5A00010400E05A00880300AC5A002A0300105A003C03003C5A00FC0300285A00300400985900ED0300B85900DF03008C9900750300B059001B0300BC59002003081A9A007F0300B85900B90300E09900A40300405A006C0300D05A00C70200E05A000A0200585A00BE0200F85900E90200D498004E0200F05800E70100585A005E0200505A00210400945A00233101002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830083325"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000C949000C7E0600045A008B0600705900890600185A00B00600505A00CD0600F05A00C206007C5B00A10600885B00820600805B00620600B05B00340600D05B00360600C05B00220600C05B00120600A05B00300600D05B003906000C5C002906001C5C00100500645A00B40500E45900E50500185B00560600645B00F10600185B00080700EC5A00C50600B45A00810600945A00130600801E80ED0500241C80550600305B00AA0600505A003C03003C5A00FC0300285A00300400985900ED0300B85900DF03008C9900750300B059001B0300BC59002003081A9A007F0300B85900B90300E09900A40300405A006C0300D05A00C70200E05A000A0200585A00BE0200F85900E90200D498004E0200F05800E70100585A005E0200505A00210400945A00813101002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008D40D"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000003B820A13300400E05800390400E458003004000C5900350400E858003F0400D45800500400CC98004E0400889800590400AC5800740400C49800720400C498000E04003459001204000C5900170400145900210400F45800290400D85800290400D89800100500645A00B40500E45900E50500185B00560600645B00F10600185B00080700EC5A00C50600B45A00810600945A00130600801E80ED0500241C80550600305B00AA0600505A00E10500685C00320500EC5B00BA0400B01B80A70400DC5A006D0400645A000D0400EC59001904001459002003081A9A007F0300B85900B90300E09900A40300405A006C0300D05A00C70200E05A000A0200585A00BE0200F85900E90200D498004E0200F05800E70100585A005E0200505A00210400945A00EB3101002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830080B18"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000007DDF0700A50200F05800B70200105900B20200785900BD0200605900C802006C5900C00200605900AB02005859001103002C5900030300285900F60200485900F10200445900EE02004C5900E70200345900DD0200205900C002001C5900A60200F458007A0500685A00B606006C5A00410700305A00080700905A00330700E85A008F0700345B00DD0700C85A002B0800345A00BE0700BC5900690700385A00DF06001C5A00940600405A00070600745900AF05006C59003F0500D859009C0400585900050400F05900D903005C5A00230400DC5A002C0400C05A00D70400C05A00810500A85A00040600485A00E90500B89900FC04005899009A03006C59009C02007459009E02006C5900A60300385900FD0300D49800400300549900B90200F45800673601002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008DB25"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000675403017C0200D859005B0200C05900530200BC5900BD0200605900C802006C5900C00200605900AB0200585900A402005C59009D02009459008A0200B05900840200745900900200EC5900870200FC59008A0200C05900940200E85900900200F85900890200E85900B606006C5A00410700305A00080700905A00330700E85A008F0700345B00DD0700C85A002B0800345A00BE0700BC5900690700385A00DF06001C5A00940600405A00070600745900AF05006C59003F0500D859009C0400585900050400F05900D903005C5A00230400DC5A002C0400C05A00D70400C05A00810500A85A00040600485A00E90500B89900FC04005899009A03006C59009C02007459009E02006C5900A60300385900FD0300D49800400300549900B90200F45800743601002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008FD09"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000026DC0A05F70200DC9800000300A49800040300809800100300749800200300849800330300AC98003B0300D458003B0300A898004503009C98005303009C9800CA02002C9900CB0200109900D80200109900DF02000C9900E70200FC9800F00200EC9800890200E85900170200F059000A02000C9900180200489900CF02002C99008F0700345B00DD0700C85A002B0800345A00BE0700BC5900690700385A00DF06001C5A00940600405A00070600745900AF05006C59003F0500D859009C0400585900050400F05900D903005C5A00230400DC5A002C0400C05A00D70400C05A00810500A85A00040600485A00E90500B89900FC04005899009A03006C59009C02007459009E02006C5900A60300385900FD0300D49800400300549900B90200F45800BB3601002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008480E"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000047E4040FCF0300385900F00300285900E20300105900CC0300EC5800200400C45900000400C49900E30300A45900D803007C5900EB0300889900DF0300705900E60300885900EB0300A45900F70300D45900E103009C5900E703006C9900DD0300585900890200E85900170200F059000A02000C9900180200489900CF02002C99005103009C9800C50300F85800BF0400089800650600445900AB0600A49900BE0600BC59003306005499004A0500045C00260400185A00E103003859009C0400585900050400F05900D903005C5A00230400DC5A002C0400C05A00D70400C05A00810500A85A00040600485A00E90500B89900FC04005899009A03006C59009C02007459009E02006C5900A60300385900FD0300D49800400300549900B90200F45800443701002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830082234"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000008F7B0018640400C45900840400B45900970400B859009C04007C5900BE0400985900CA0400B45900E30400F45900FB0400C05900000500D05900160500205A00300500505A002B0500785A00310500845A00220500A05A005105005C5A00640500205A00890200E85900170200F059000A02000C9900180200489900CF02002C99005103009C9800C50300F85800BF0400089800650600445900AB0600A49900BE0600BC59003306005499004A0500045C00260400185A00E10300385900E803003C9800450300DC59002A0300FC5900010300C85900020300045A00040300745A001C0300705A00B10300245A00F20400C05900FC04005899009A03006C59009C02007459009E02006C5900A60300385900FD0300D49800400300549900B90200F45800D03701002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008CB33"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000461F031AEA0400BC5900DB0400E85900B90400845A00ED0500905900C40500E05900B50500585A00A60500045A00650500A459004F05004C5900450500E859004A0500B85900160500BC9800140500205900060500609800F104001059000B0500785900890200E85900170200F059000A02000C9900180200489900CF02002C99005103009C9800C50300F85800BF0400089800650600445900AB0600A49900BE0600BC59003306005499004A0500045C00260400185A00E10300385900E803003C9800450300DC59002A0300FC5900010300C85900020300045A00040300745A001C0300705A00B10300245A00F20400C05900CF0500389800B00500585A009C02007459009E02006C5900A60300385900FD0300D49800400300549900B90200F45800F43701002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008B301"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000007C690C03320500A85A002D0500945A00250500845A001F0500585A00330500985A004A0500D85A004105008C5A003E0500B45A004E0500745A00650500605A00810500605A007C0500645A000905007C5A000E0500AC5A00180500B45A00270500BC5A00690400EC5A00440500245B001205007C5A00CE0300E89600600400E09600CA0400F09600F40400109700F30400605A00430500EC5A00200500A05A00710500749800EA0500045A00220600305A003306007898002306009C9700F205004C97000506000C97002F0600CC9600800600689600E30600EC96007E06007096003E06005C9600F60500DC96009A05008C9600790500C89700800400849600A704000C96007F0400E895005A04003897005704008C96007304000C5900430400305A005D3A01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008D220"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000098F3080C150500D89800120500EC5800050500089900EE0400F05800E10400F45800DA0400BC9800D90400C45800E304000859003805004059003C05004459004105002059004505001C59003E05001859003805001459002F0500105900240500E05800690400EC5A00440500245B001205007C5A00730500645A005E0500785A00490500545A00850500B85A00820500885A006C05005C5A00580500285A00560500745900F30400F05800220600305A003306007898002306009C9700F205004C97000506000C97002F0600CC9600800600689600E30600EC96007E06007096003E06005C9600F60500DC96009A05008C9600790500C89700800400849600A704000C96007F0400E895005A04003897005704008C96007304000C5900430400305A00D93A01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830082F05"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000B582010CC00400F85800120500EC5800050500089900EE0400F05800E10400F45800DA0400BC9800D90400C45800E30400085900D50408DE5800CA0400E09800C70400049900B50400E45800A60400FC9800BA0400E89800B80400C85800BC0400C89800690400EC5A00440500245B001205007C5A00730500645A005E0500785A00490500545A00850500B85A00820500885A006C05005C5A00580500285A00560500745900F30400F05800220600305A003306007898002306009C9700F205004C97000506000C97002F0600CC9600800600689600E30600EC96007E06007096003E06005C9600F60500DC96009A05008C9600790500C89700800400849600A704000C96007F0400E895005A04003897005704008C96007304000C5900430400305A00E13A01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830087F27"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000003E33080DC00400F85800C50400BC9800C70400C49800D20400D45800DB0400D09800EA0400CC9800EA0400C49800F20400C49800D50408DE5800CA0400E09800C70400049900B50400E45800A60400FC9800BA0400E89800B80400C85800BC0400C89800690400EC5A00440500245B001205007C5A00730500645A005E0500785A00490500545A00850500B85A00820500885A006C05005C5A00580500285A00560500745900F30400F05800CB0400C498003306007898002306009C9700F205004C97000506000C97002F0600CC9600800600689600E30600EC96007E06007096003E06005C9600F60500DC96009A05008C9600790500C89700800400849600A704000C96007F0400E895005A04003897005704008C96007304000C5900430400305A00E93A01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008CE11"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000B158050E7205003858007205003498006C05004498006C0500049800640500EC9700EA0400CC9800EA0400C49800F20400C49800000508D258000D05009C58001605008898002305008098002905009C58003605004C98004A0500489800580500489800690400EC5A00440500245B001205007C5A00730500645A005E0500785A00490500545A00850500B85A00820500885A006C05005C5A00580500285A00560500745900F30400F05800CB0400C498006A05003498002306009C9700F205004C97000506000C97002F0600CC9600800600689600E30600EC96007E06007096003E06005C9600F60500DC96009A05008C9600790500C89700800400849600A704000C96007F0400E895005A04003897005704008C96007304000C5900430400305A00F63A01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830081119"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000006F1602100B0500909800F20400A49800790500049800750500009800720500F49700730500DC97007505001C9800720500E897006B0500E89700630500E097006C0500FC97006105002058005505004C58004605006898003B0500885800220500989800690400EC5A00440500245B001205007C5A00730500645A005E0500785A00490500545A00850500B85A00820500885A006C05005C5A00580500285A00560500745900F30400F05800CB0400C498006A05003498007905002098002005009898000506000C97002F0600CC9600800600689600E30600EC96007E06007096003E06005C9600F60500DC96009A05008C9600790500C89700800400849600A704000C96007F0400E895005A04003897005704008C96007304000C5900430400305A00123B01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830089A2C"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000F6D509100B0500909800F20400A49800DC0400949800CE0400945800C30400CC9800A00400BC58009004009098008B0400B098008D0400B85800630500E097006C0500FC97006105002058005505004C58004605006898003B0500885800220500989800690400EC5A00440500245B001205007C5A00730500645A005E0500785A00490500545A00850500B85A00820500885A006C05005C5A00580500285A00560500745900F30400F05800CB0400C498006A05003498007905002098002005009898000506000C97002F0600CC9600800600689600E30600EC96007E06007096003E06005C9600F60500DC96009A05008C9600790500C89700800400849600A704000C96007F0400E895005A04003897005704008C96007304000C5900430400305A00193B01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830081431"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000049140B12190300C49700020300609800E202008C9800D00200E49800B80200789800A90200D898009D02001C59008B02001859008D02003499008502006859007902006899009B0300B49700860300D897006B0300FC97005703000498003403001C9800690400EC5A00440500245B001205007C5A00730500645A005E0500785A00490500545A00850500B85A00820500885A006C05005C5A00580500285A00560500745900F30400F05800CB0400C498006A05003498007905002098002005009898002E0400C898006B0300FC9700800600689600E30600EC96007E06007096003E06005C9600F60500DC96009A05008C9600790500C89700800400849600A704000C96007F0400E895005A04003897005704008C96007304000C5900430400305A003C3B01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830088102"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000D9CB0617160400EC98002F04007498004004003098004F0400FC97006404008897005A04001C9800DE0300D45800E90300405900EE03007C5900E30300685900DA0300905900D70300AC5900E70300A85900EA0300B45900F60300A459000904009059003A04008C9700EA03005C9700A00300A89800AD03006097006D0300689700830300549700FB0300085A00750400745A00790400B45A004D0400845A00DF0300FC5A004E03008C5900FD0300545A00190500585A00450500C058000106007C5900B106005C5900DA0600E05800690600C45900C50500A859009604006459009D0300149800E303007C5900FF0300B896005D0400009800BA04001097009E04009C96007B04005C9600680400B85700970400289700C403001097002D0400E09700274101002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008241E"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000056120C114B04007859004704006059005404005459006704004459008A0400085900C00400FC5800B80400D09800A30400C09800B10400B45800CB0400AC5800FE0400BC5800200508DA58000D04009C9900250400C059003F0400B059005A0400945900130300DC5800A40200F45900580200A85A00860200E459005B0300945A00D90300485A00CA0300EC9700AA03003C9800100500709800260600989700C60600A058002D0500645900680400705900190400A45900040400C05900D80300E45900370400B05900DA0600E05800690600C45900C50500A859009604006459009D0300149800E303007C59004C0400EC5800900400D459009A0400A49600780400949800C70400649700DF04005458004C04006459000A04007097008803002C9800AC4201002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830084224"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000008BE502126D05005859007A05007459005404005459006704004459008A0400085900C00400FC5800B80400D09800A30400C09800B10400B45800CB0400AC5800FE0400BC5800200508DA58003305000C99004B05001459004C05002C59005D0500685900130300DC5800A40200F45900580200A85A00860200E459005B0300945A00D90300485A00CA0300EC9700AA03003C9800100500709800260600989700C60600A058002D0500645900680400705900190400A45900040400C05900D80300E45900370400B05900490500145900690600C45900C50500A859009604006459009D0300149800E303007C59004C0400EC5800900400D459009A0400A49600780400949800C70400649700DF04005458004C04006459000A04007097008803002C9800B34201002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830088519"); + parseOneFakeDataRaw("FC97501A03000000000000000000000000000000000000000CC00A16FC05007C5800E30500B45800DE0500C05800F60500DC9800060600F098001006000899002E06001C59006606005059007706006059005D0600745900F305005C9800F405005C9800E50500A45800DE0500BC5800E20500A85800E40500B09800130300DC5800A40200F45900580200A85A00860200E459005B0300945A00D90300485A00CA0300EC9700AA03003C9800100500709800260600989700C60600A058002D0500645900680400705900190400A45900040400C05900D80300E45900370400B05900490500145900CF05003C5900240600B85900EC0500C09800F30500409800E303007C59004C0400EC5800900400D459009A0400A49600780400949800C70400649700DF04005458004C04006459000A04007097008803002C9800FB4201002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830089C1B"); + parseOneFakeDataRaw("FC97501A0300000000000000000000000000000000000000C4EF0E02E70300749800E70300A89800E90300985800F10300B85800FA0300C05800FD03000459000B04000859001B0400FC58001D04000459002704000059001E04000859001D04000059001104003499000404083E5900200400585800F403003C9800C40400AC58001D0400505800890200705B008802003C9900660200885A00660200E059008502001C5A006E0200F05A00690200C85900390200E05A003802005C5A00700200B85A00BC0200CC5900AD0300245A00EA0400AC59006A05008C59005D0500785900DE05009059003F0600B45900EA05003C59008E0500D898001F0500C09800AD0400E898004604003C9800DB0300E858001D0400345900F20400EC98004E0500109900FA05009C9800E10500A89800A90500D098009405002898006E4701002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D0830085925"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000084A30710A80200305B00920200305B00920200405B008D0200F05A008F0200A45A00910200BC5A00880200E45A001E03008C5A000F03004C1B80F50200F85A00ED0200F05A00E60200F45A00D80200C05A00C602008C5A00BB0200685A00B00200EC5A00AB0400245A008C0400E85800BA0400D45900530400885A00360400B85800270400C898009F0300E858001E0400EC5900B40400485A00650400B05900B90300C45A00420300005B00D70200CC59002003003C5A000A0300345A00AF0200EC5A00A00300C49700200300385900F382002297004E03001899003A0300145A009603002C5A00C40300345900F20300545800F80300E85800D903007898007A0400B89700C40400F496006305009C9700320500349700830400105900340400C05900F84B01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008D313"); + parseOneFakeDataRaw("FC97501A030000000000000000000000000000000000000044D30817990200905A00940200BC5A00910200CC5A00980200045B009B02001C5B009F0200F45A00A902002C5B00AF0200505B00D40200A05A00C10200FC5A00AC0200485B009B02005C5B008E0200D05B00850200045C008E0200685B00A40200605A00AB0400245A008C0400E85800BA0400D45900530400885A00360400B85800270400C898009F0300E858001E0400EC5900B40400485A00650400B05900B90300C45A00420300005B00D70200CC59002003003C5A000A0300345A00AF0200EC5A002602008C5A00A70100605A00B101004459008601001C59001A0200C05800DA0200045A00CB0200A05A00F20300545800F80300E85800D903007898007A0400B89700C40400F496006305009C9700320500349700830400105900340400C05900694C01002B723008150D8351140396805A00CDA6065A1A000069886A", "EA53B60500A407E0", "9D083008F303"); + } + + private FakeData parseOneFakeDataRaw(String data, String patchUid, String patchInfo) { + FakeData fakeData = new FakeData(); + fakeData.data = JoH.tolerantHexStringToByteArray(data); + fakeData.patchUid = JoH.tolerantHexStringToByteArray(patchUid); + fakeData.patchInfo = JoH.tolerantHexStringToByteArray(patchInfo); + fakeDataVector.add(fakeData); + return fakeData; + } + + FakeData getFakeData() { + int loc = VectorLocation % fakeDataVector.size(); + VectorLocation++; + return fakeDataVector.get(loc); + } +} diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/Forecast.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/Forecast.java similarity index 99% rename from wear/src/main/java/com/eveningoutpost/dexdrip/Models/Forecast.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/Forecast.java index 1ea072c722..415f3a0c10 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/Forecast.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/Forecast.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.util.Log; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/GlucoseData.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/GlucoseData.java similarity index 94% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/GlucoseData.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/GlucoseData.java index 94cb4d2875..7003245174 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/GlucoseData.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/GlucoseData.java @@ -1,7 +1,7 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import java.text.DecimalFormat; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/HeartRate.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/HeartRate.java similarity index 95% rename from wear/src/main/java/com/eveningoutpost/dexdrip/Models/HeartRate.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/HeartRate.java index 82d2633e58..134e8d0a8d 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/HeartRate.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/HeartRate.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.provider.BaseColumns; @@ -8,6 +8,7 @@ import com.activeandroid.query.Delete; import com.activeandroid.query.Select; import com.activeandroid.util.SQLiteUtils; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.annotations.Expose; @@ -41,6 +42,7 @@ public static HeartRate last() { try { return new Select() .from(HeartRate.class) + .where("timestamp >= " + (JoH.tsl() - Constants.DAY_IN_MS)) .orderBy("timestamp desc") .executeSingle(); } catch (android.database.sqlite.SQLiteException e) { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/InsulinInjection.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/InsulinInjection.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/InsulinInjection.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/InsulinInjection.java index 0b2af23fd8..b216fa16b2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/InsulinInjection.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/InsulinInjection.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import com.eveningoutpost.dexdrip.insulin.Insulin; import com.eveningoutpost.dexdrip.insulin.InsulinManager; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Iob.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/Iob.java similarity index 86% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/Iob.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/Iob.java index 96e8906582..61517db253 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Iob.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/Iob.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; /** * Created by jamorham on 02/01/16. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/JoH.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/JoH.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/JoH.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/JoH.java index 8b57cd407d..584cea0e38 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/JoH.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/JoH.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import static android.bluetooth.BluetoothDevice.PAIRING_VARIANT_PIN; import static android.content.Context.ALARM_SERVICE; @@ -44,11 +44,13 @@ import android.os.PowerManager; import android.os.SystemClock; import android.provider.Settings; -import android.support.v4.app.NotificationCompat; -import android.support.v4.content.CursorLoader; -import android.support.v7.app.AlertDialog; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.view.ContextThemeWrapper; + +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.view.ContextThemeWrapper; +import androidx.core.app.NotificationCompat; +import androidx.loader.content.CursorLoader; + import android.text.InputType; import android.text.method.DigitsKeyListener; import android.util.Base64; @@ -62,12 +64,13 @@ import com.activeandroid.ActiveAndroid; import com.eveningoutpost.dexdrip.Home; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.XdripNotificationCompat; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.XdripNotificationCompat; import com.eveningoutpost.dexdrip.utils.BestGZIPOutputStream; import com.eveningoutpost.dexdrip.utils.CipherUtils; +import com.eveningoutpost.dexdrip.utils.framework.BuggySamsung; import com.eveningoutpost.dexdrip.xdrip; import com.google.common.primitives.Bytes; import com.google.common.primitives.UnsignedInts; @@ -439,7 +442,7 @@ public static String readLine(final InputStream stream) { } public static boolean isSamsung() { - return Build.MANUFACTURER.toLowerCase().contains("samsung"); + return BuggySamsung.isSamsung(); } private static final String BUGGY_SAMSUNG_ENABLED = "buggy-samsung-enabled"; @@ -447,7 +450,7 @@ public static void persistentBuggySamsungCheck() { if (!buggy_samsung) { if (JoH.isSamsung() && PersistentStore.getLong(BUGGY_SAMSUNG_ENABLED) > 4) { buggy_samsung = true; - UserError.Log.d(TAG,"Enabling buggy samsung mode due to historical pattern"); + UserError.Log.d(TAG,"Enabling wake workaround mode due to historical pattern"); } } } @@ -1500,6 +1503,10 @@ public static void showNotification(String title, String content, PendingIntent } public static void showNotification(String title, String content, PendingIntent intent, int notificationId, String channelId, boolean sound, boolean vibrate, PendingIntent deleteIntent, Uri sound_uri, String bigmsg) { + showNotification(title, content, intent, notificationId, channelId, sound, vibrate, deleteIntent, sound_uri, bigmsg, false); + } + + public static void showNotification(String title, String content, PendingIntent intent, int notificationId, String channelId, boolean sound, boolean vibrate, PendingIntent deleteIntent, Uri sound_uri, String bigmsg, boolean highPriority) { final NotificationCompat.Builder mBuilder = notificationBuilder(title, content, intent, channelId); final long[] vibratePattern = {0, 1000, 300, 1000, 300, 1000}; if (vibrate) mBuilder.setVibrate(vibratePattern); @@ -1514,6 +1521,10 @@ public static void showNotification(String title, String content, PendingIntent mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(bigmsg)); } + if (highPriority) { + mBuilder.setPriority(NotificationCompat.PRIORITY_MAX); + } + final NotificationManager mNotifyMgr = (NotificationManager) xdrip.getAppContext().getSystemService(Context.NOTIFICATION_SERVICE); // if (!onetime) mNotifyMgr.cancel(notificationId); @@ -1712,10 +1723,13 @@ public static boolean isBluetoothEnabled(final Context context) { public synchronized static void setBluetoothEnabled(Context context, boolean state) { try { - if (isAirplaneModeEnabled(context)) { + /* + // bluetooth is usually allowed on airplanes these days afaik + if (isAirplaneModeEnabled(context)) { UserError.Log.e(TAG, "Not setting bluetooth to state: " + state + " due to airplane mode being enabled"); return; } + */ if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) { @@ -1867,6 +1881,17 @@ public static byte[] splitBytes(final byte[] source, final int start, final int return newBytes; } + public static byte[] joinBytes(final byte[] first, final byte[] second) { + if (first == null || second == null) { + throw new IllegalArgumentException("Input arrays cannot be null"); + } + final int totalLength = first.length + second.length; + final byte[] result = new byte[totalLength]; + System.arraycopy(first, 0, result, 0, first.length); + System.arraycopy(second, 0, result, first.length, second.length); + return result; + } + public static long checksum(byte[] bytes) { if (bytes == null) return 0; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Libre2RawValue.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/Libre2RawValue.java similarity index 89% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/Libre2RawValue.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/Libre2RawValue.java index af25ac0ea3..ed0f10593a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Libre2RawValue.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/Libre2RawValue.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.provider.BaseColumns; @@ -7,7 +7,7 @@ import com.activeandroid.annotation.Table; import com.activeandroid.query.Delete; import com.activeandroid.query.Select; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import java.util.Date; import java.util.List; @@ -30,8 +30,8 @@ public class Libre2RawValue extends PlusModel { @Column(name = "glucose", index = false) public double glucose; - public static List last20Minutes() { - double timestamp = (new Date().getTime()) - (60000 * 20); + public static List weightedAverageInterval(long min) { + double timestamp = (new Date().getTime()) - (60000 * min); return new Select() .from(Libre2RawValue.class) .where("ts >= " + timestamp) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Libre2Sensor.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/Libre2Sensor.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/Libre2Sensor.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/Libre2Sensor.java index 3a761871dd..35dd962943 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Libre2Sensor.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/Libre2Sensor.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.provider.BaseColumns; import android.text.format.DateFormat; @@ -7,7 +7,6 @@ import com.activeandroid.annotation.Table; import com.activeandroid.query.Select; -import java.sql.SQLException; import java.util.List; @Table(name = "Libre2Sensors", id = BaseColumns._ID) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Libre2SensorData.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/Libre2SensorData.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/Libre2SensorData.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/Libre2SensorData.java index f6504d5bec..7d0e3d7f29 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Libre2SensorData.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/Libre2SensorData.java @@ -1,9 +1,9 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import com.google.gson.annotations.Expose; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.models.UserError.Log; import java.util.ArrayList; import java.util.HashMap; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/LibreBlock.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/LibreBlock.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/LibreBlock.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/LibreBlock.java index 1f62c985cb..ef0bc4e482 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/LibreBlock.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/LibreBlock.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; @@ -8,25 +8,18 @@ import com.activeandroid.annotation.Column; import com.activeandroid.annotation.Table; import com.activeandroid.query.Select; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.UploaderQueue; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.UploaderQueue; import com.eveningoutpost.dexdrip.utils.LibreTrendUtil; import com.google.gson.annotations.Expose; -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; -import java.text.DecimalFormat; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; import java.util.List; import java.util.UUID; -import org.json.JSONObject; /** * Created by jamorham on 19/10/2017. */ diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/LibreBluetooth.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/LibreBluetooth.java similarity index 88% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/LibreBluetooth.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/LibreBluetooth.java index 078f1e182d..e9c1f4e9b1 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/LibreBluetooth.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/LibreBluetooth.java @@ -1,18 +1,12 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.NFCReaderX; -import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Blukon; -import com.eveningoutpost.dexdrip.UtilityModels.BridgeResponse; -import com.eveningoutpost.dexdrip.UtilityModels.LibreUtils; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; - -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Arrays; +import com.eveningoutpost.dexdrip.utilitymodels.BridgeResponse; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; + import static com.eveningoutpost.dexdrip.xdrip.gs; /** * Created by Tzachi Dar on 7.3.2018. diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/LibreData.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/LibreData.java similarity index 97% rename from wear/src/main/java/com/eveningoutpost/dexdrip/Models/LibreData.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/LibreData.java index 46ee1f8622..1e0c0867ba 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/LibreData.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/LibreData.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.provider.BaseColumns; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/LibreOOPAlgorithm.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/LibreOOPAlgorithm.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/LibreOOPAlgorithm.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/LibreOOPAlgorithm.java index c643380831..c6ed86d0fa 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/LibreOOPAlgorithm.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/LibreOOPAlgorithm.java @@ -1,19 +1,19 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.content.Intent; import android.os.Bundle; import android.util.Pair; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; import com.eveningoutpost.dexdrip.LibreAlarmReceiver; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.NFCReaderX; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.CompatibleApps; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Intents; -import com.eveningoutpost.dexdrip.UtilityModels.LibreUtils; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.CompatibleApps; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Intents; +import com.eveningoutpost.dexdrip.utilitymodels.LibreUtils; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; import com.eveningoutpost.dexdrip.xdrip; import java.util.concurrent.ArrayBlockingQueue; @@ -299,8 +299,10 @@ public static SensorType getSensorType(byte[] SensorInfo) { case 0xa20800: return SensorType.Libre1New; case 0xe50003: + case 0xe60003: return SensorType.LibreUS14Day; case 0x9d0830: + case 0xc50930: return SensorType.Libre2; case 0x700010: return SensorType.LibreProH; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/NSClientChat.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/NSClientChat.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/NSClientChat.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/NSClientChat.java index 0749bc5b60..ebd4abf1a2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/NSClientChat.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/NSClientChat.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.content.Context; import android.content.Intent; @@ -6,7 +6,7 @@ import android.os.Bundle; import android.util.Log; -import com.eveningoutpost.dexdrip.UtilityModels.Intents; +import com.eveningoutpost.dexdrip.utilitymodels.Intents; import com.eveningoutpost.dexdrip.xdrip; import org.json.JSONException; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/Noise.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/Noise.java similarity index 83% rename from wear/src/main/java/com/eveningoutpost/dexdrip/Models/Noise.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/Noise.java index 38338fd442..9c09b3fd7d 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/Noise.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/Noise.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; /** * Created by jamorham on 04/03/2018. diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/OOPResultsContainer.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/OOPResultsContainer.java similarity index 91% rename from wear/src/main/java/com/eveningoutpost/dexdrip/Models/OOPResultsContainer.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/OOPResultsContainer.java index 62547279e7..8157ce0685 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/OOPResultsContainer.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/OOPResultsContainer.java @@ -1,11 +1,9 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import java.util.List; - class HistoricBg { public int quality; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/PenData.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/PenData.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/PenData.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/PenData.java index c5611f5d56..6e6e2e7b81 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/PenData.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/PenData.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.provider.BaseColumns; @@ -6,7 +6,7 @@ import com.activeandroid.annotation.Column; import com.activeandroid.annotation.Table; import com.activeandroid.query.Select; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import com.google.gson.annotations.Expose; import java.util.List; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/PlusModel.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/PlusModel.java similarity index 92% rename from wear/src/main/java/com/eveningoutpost/dexdrip/Models/PlusModel.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/PlusModel.java index 8c782d7abf..ba21ad60d6 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/PlusModel.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/PlusModel.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import com.activeandroid.Model; import com.activeandroid.util.SQLiteUtils; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/Prediction.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/Prediction.java similarity index 98% rename from wear/src/main/java/com/eveningoutpost/dexdrip/Models/Prediction.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/Prediction.java index 5bb639af2d..6023187e55 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/Prediction.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/Prediction.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.provider.BaseColumns; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/ProcessInitialDataQuality.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/ProcessInitialDataQuality.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/ProcessInitialDataQuality.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/ProcessInitialDataQuality.java index dae6a1844f..c0b9600e3a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/ProcessInitialDataQuality.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/ProcessInitialDataQuality.java @@ -1,14 +1,14 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; -import android.databinding.BaseObservable; +import androidx.databinding.BaseObservable; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.xdrip; import java.util.List; -import static com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder.DEXCOM_PERIOD; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.STALE_CALIBRATION_CUT_OFF; +import static com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder.DEXCOM_PERIOD; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.STALE_CALIBRATION_CUT_OFF; /** * Created by jamorham on 01/10/2017. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Profile.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/Profile.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/Profile.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/Profile.java index 3d3ae6eb3e..fad1ff4035 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Profile.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/Profile.java @@ -1,12 +1,12 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.util.Log; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.profileeditor.BasalRepository; import com.eveningoutpost.dexdrip.profileeditor.ProfileEditor; import com.eveningoutpost.dexdrip.profileeditor.ProfileItem; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/ReadingData.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/ReadingData.java similarity index 99% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/ReadingData.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/ReadingData.java index 456d33ffac..b9e71e97a7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/ReadingData.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/ReadingData.java @@ -1,8 +1,8 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; // class from LibreAlarm -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.utils.LibreTrendPoint; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Reminder.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/Reminder.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/Reminder.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/Reminder.java index c2fa3835c8..2096d0d80c 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Reminder.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/Reminder.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.content.Context; import android.provider.BaseColumns; @@ -8,10 +8,9 @@ import com.activeandroid.annotation.Table; import com.activeandroid.query.Select; import com.activeandroid.util.SQLiteUtils; -import com.eveningoutpost.dexdrip.Home; import com.eveningoutpost.dexdrip.Reminders; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.HomeWifi; import com.google.gson.annotations.Expose; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/RollCall.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/RollCall.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/RollCall.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/RollCall.java index fcd7bd9acf..9d7a74a35e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/RollCall.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/RollCall.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.content.Intent; import android.content.IntentFilter; @@ -7,10 +7,10 @@ import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.UtilityModels.BridgeBattery; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; -import com.eveningoutpost.dexdrip.UtilityModels.desertsync.RouteTools; +import com.eveningoutpost.dexdrip.utilitymodels.BridgeBattery; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; +import com.eveningoutpost.dexdrip.utilitymodels.desertsync.RouteTools; import com.eveningoutpost.dexdrip.utils.CipherUtils; import com.eveningoutpost.dexdrip.xdrip; import com.google.gson.Gson; @@ -24,7 +24,7 @@ import java.util.List; import java.util.Map; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; /** * Created by jamorham on 20/01/2017. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Sensor.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/Sensor.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/Sensor.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/Sensor.java index 1f7de31f55..04f6bfdb15 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Sensor.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/Sensor.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.provider.BaseColumns; @@ -8,9 +8,9 @@ import com.activeandroid.query.Select; import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.SensorSendQueue; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.SensorSendQueue; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.annotations.Expose; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/SensorSanity.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/SensorSanity.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/SensorSanity.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/SensorSanity.java index c6f8d5a181..6891c76048 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/SensorSanity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/SensorSanity.java @@ -1,9 +1,9 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.DexCollectionType; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/StepCounter.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/StepCounter.java similarity index 67% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/StepCounter.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/StepCounter.java index c9f6d7992d..b29d0b70a2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/StepCounter.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/StepCounter.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.provider.BaseColumns; @@ -8,6 +8,7 @@ import com.activeandroid.query.Delete; import com.activeandroid.query.Select; import com.activeandroid.util.SQLiteUtils; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.annotations.Expose; @@ -15,6 +16,8 @@ import java.util.ArrayList; import java.util.List; +import lombok.val; + /** * Created by jamorham on 01/11/2016. */ @@ -27,6 +30,8 @@ public class StepCounter extends Model { private final static String TAG = "StepCounter"; private final static boolean d = false; + private static final int ABSOLUTE_MASK = 1; + @Expose @Column(name = "timestamp", unique = true, onUniqueConflicts = Column.ConflictAction.IGNORE) public long timestamp; @@ -35,6 +40,10 @@ public class StepCounter extends Model { @Column(name = "metric") public int metric; + @Expose + @Column(name = "source") + public int source; + // patches and saves public Long saveit() { @@ -53,22 +62,49 @@ public String toS() { return gson.toJson(this); } + public boolean isAbsolute() { + return ((source & ABSOLUTE_MASK) != 0); + } // static methods - public static StepCounter createEfficientRecord(long timestamp_ms, int data) - { + public static StepCounter getForTimestamp(final long timestamp) { + return new Select() + .from(StepCounter.class) + .where("timestamp = ?", timestamp) + .executeSingle(); + } + + + public static synchronized StepCounter createUniqueRecord(final long timestamp_ms, final int data, final boolean absolute) { + if (getForTimestamp(timestamp_ms) == null) { + val pm = new StepCounter(); + pm.timestamp = timestamp_ms; + pm.metric = data; + if (absolute) { + pm.source |= ABSOLUTE_MASK; + } + pm.saveit(); + UserError.Log.d(TAG, "Created new record: " + pm.toS() + " " + JoH.dateTimeText(pm.timestamp)); + return pm; + } + return null; + } + + public static StepCounter createEfficientRecord(long timestamp_ms, int data) { StepCounter pm = last(); if ((pm == null) || (data < pm.metric) || ((timestamp_ms - pm.timestamp) > (1000 * 30 * 5))) { pm = new StepCounter(); pm.timestamp = timestamp_ms; - if (d) UserError.Log.d(TAG,"Creating new record for timestamp: "+JoH.dateTimeText(timestamp_ms)); + if (d) + UserError.Log.d(TAG, "Creating new record for timestamp: " + JoH.dateTimeText(timestamp_ms)); } else { - if (d) UserError.Log.d(TAG,"Merging pebble movement record: "+JoH.dateTimeText(timestamp_ms)+" vs old "+JoH.dateTimeText(pm.timestamp)); + if (d) + UserError.Log.d(TAG, "Merging pebble movement record: " + JoH.dateTimeText(timestamp_ms) + " vs old " + JoH.dateTimeText(pm.timestamp)); } pm.metric = (int) (long) data; - if(d) UserError.Log.d(TAG, "Saving Movement: " + pm.toS()); + if (d) UserError.Log.d(TAG, "Saving Movement: " + pm.toS()); pm.saveit(); return pm; } @@ -85,6 +121,26 @@ public static StepCounter last() { } } + public static int getDailyTotal() { + int accumulator = 0; + val list = latestForGraph(5000, JoH.tsl() - Constants.DAY_IN_MS, JoH.tsl()); // TODO since midnight vs 24 hours? + for (val item : list) { + if (item.isAbsolute()) { + accumulator += item.metric; + } + } + if (accumulator == 0) { + val last = last(); + if (last != null) { + return last.metric; + } else { + return 0; + } + } else { + return accumulator; // total from absolutes + } + } + public static List latestForGraph(int number, double startTime) { return latestForGraph(number, (long) startTime, Long.MAX_VALUE); } @@ -113,6 +169,7 @@ public static List deltaListFromMovementList(List mLis int last_metric = -1; int temp_metric = -1; for (StepCounter pm : mList) { + if (pm.isAbsolute()) continue; // first item in list if (last_metric == -1) { last_metric = pm.metric; @@ -146,6 +203,8 @@ private static void fixUpTable() { "CREATE TABLE PebbleMovement (_id INTEGER PRIMARY KEY AUTOINCREMENT);", "ALTER TABLE PebbleMovement ADD COLUMN timestamp INTEGER;", "ALTER TABLE PebbleMovement ADD COLUMN metric INTEGER;", + "ALTER TABLE PebbleMovement ADD COLUMN source INTEGER;", + "CREATE INDEX index_PebbleMovement_source on PebbleMovement(source);", "CREATE UNIQUE INDEX index_PebbleMovement_timestamp on PebbleMovement(timestamp);"}; for (String patch : patchup) { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Tomato.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/Tomato.java similarity index 92% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/Tomato.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/Tomato.java index d1f8e53fd1..4a28fdb9ce 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Tomato.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/Tomato.java @@ -1,15 +1,14 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.NFCReaderX; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Blukon; -import com.eveningoutpost.dexdrip.UtilityModels.BridgeResponse; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.LibreUtils; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.BridgeResponse; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.LibreUtils; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -181,7 +180,8 @@ static void AreWeDone() { byte []patchInfo = null; if(s_acumulatedSize >= extended_length) { patchUid = Arrays.copyOfRange(s_full_data, 5, 13); - patchInfo = Arrays.copyOfRange(s_full_data, TOMATO_HEADER_LENGTH+ Constants.LIBRE_1_2_FRAM_SIZE + 1 , TOMATO_HEADER_LENGTH + Constants.LIBRE_1_2_FRAM_SIZE + 1+ TOMATO_PATCH_INFO); + patchInfo = Arrays.copyOfRange(s_full_data, TOMATO_HEADER_LENGTH+ Constants.LIBRE_1_2_FRAM_SIZE + 1, + TOMATO_HEADER_LENGTH + Constants.LIBRE_1_2_FRAM_SIZE + 1+ TOMATO_PATCH_INFO); } Log.d(TAG, "patchUid = " + HexDump.dumpHexString(patchUid)); Log.d(TAG, "patchInfo = " + HexDump.dumpHexString(patchInfo)); @@ -189,6 +189,14 @@ static void AreWeDone() { Pref.setInt("bridge_battery", s_full_data[13]); // Set the time of the current reading PersistentStore.setLong("libre-reading-timestamp", JoH.tsl()); + + if(NFCReaderX.use_fake_de_data()) { + FakeData libreData = FakeLibreData.getInstance().getFakeData(); + data = libreData.data; + patchUid = libreData.patchUid; + patchInfo = libreData.patchInfo; + } + boolean checksum_ok = NFCReaderX.HandleGoodReading(SensorSn, data, now, true, patchUid, patchInfo); Log.e(TAG, "We have all the data that we need " + s_acumulatedSize + " checksum_ok = " + checksum_ok + HexDump.dumpHexString(data)); @@ -208,6 +216,7 @@ static void AreWeDone() { } + // This is the function that we should have once we are able to read all data realiably. static void AreWeDoneMax() { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/TransmitterData.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/TransmitterData.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/TransmitterData.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/TransmitterData.java index 9edd0ae68c..7620babe33 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/TransmitterData.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/TransmitterData.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.provider.BaseColumns; @@ -8,10 +8,10 @@ import com.activeandroid.query.Select; import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.CheckBridgeBattery; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.google.gson.annotations.Expose; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Treatments.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/Treatments.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/Treatments.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/Treatments.java index dfb3286562..fdcb7de632 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/Treatments.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/Treatments.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; /** * Created by jamorham on 31/12/15. @@ -18,13 +18,14 @@ import com.activeandroid.util.SQLiteUtils; import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.SyncService; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.UndoRedo; -import com.eveningoutpost.dexdrip.UtilityModels.UploaderQueue; +import com.eveningoutpost.dexdrip.services.SyncService; +import com.eveningoutpost.dexdrip.services.UiBasedCollector; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.UndoRedo; +import com.eveningoutpost.dexdrip.utilitymodels.UploaderQueue; import com.eveningoutpost.dexdrip.insulin.Insulin; import com.eveningoutpost.dexdrip.insulin.InsulinManager; import com.eveningoutpost.dexdrip.insulin.MultipleInsulins; @@ -54,11 +55,12 @@ import lombok.val; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.HOUR_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.MINUTE_IN_MS; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.HOUR_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import static java.lang.StrictMath.abs; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; // TODO Switchable Carb models // TODO Linear array timeline optimization @@ -247,13 +249,14 @@ public static synchronized Treatments create(final double carbs, final double in } public static synchronized Treatments create(final double carbs, final double insulinSum, final List insulin, long timestamp, String suggested_uuid) { - // if treatment more than 1 minutes in the future final long future_seconds = (timestamp - JoH.tsl()) / 1000; + // if treatment more than 1 hour in the future if (future_seconds > (60 * 60)) { JoH.static_toast_long("Refusing to create a treatement more than 1 hours in the future!"); return null; } - if ((future_seconds > 60) && (future_seconds < 86400) && ((carbs > 0) || (insulinSum > 0))) { + // if treatment more than 3 minutes in the future + if ((future_seconds > (3 * 60)) && (future_seconds < 86400) && ((carbs > 0) || (insulinSum > 0))) { final Context context = xdrip.getAppContext(); JoH.scheduleNotification(context, "Treatment Reminder", "@" + JoH.hourMinuteString(timestamp) + " : " + carbs + " g " + context.getString(R.string.carbs) + " / " @@ -584,6 +587,14 @@ public static Treatments byTimestamp(long timestamp, int plus_minus_millis) { .executeSingle(); } + public static List listByTimestamp(long timestamp) { + return new Select() + .from(Treatments.class) + .where("timestamp = ?", timestamp) + .orderBy("timestamp desc") + .execute(); + } + public static void delete_all() { delete_all(false); } @@ -686,6 +697,10 @@ public static synchronized boolean pushTreatmentFromJson(String json, boolean fr Log.d(TAG, "Skipping Temp Basal msg"); return false; } + if (mytreatment.timestamp < 1) { + Log.e(TAG, "Invalid treatment timestamp or 0 or less"); + return false; + } if (mytreatment.uuid == null) { try { @@ -966,7 +981,7 @@ private static void timesliceInsulinWriter(Map timeslices, Iob thisio } // NEW NEW NEW - public static List ioBForGraph_new(int number, long startTime) { + public static List ioBForGraph_new(long startTime) { // Log.d(TAG, "Processing iobforgraph2: main "); JoH.benchmark_method_start(); @@ -1279,6 +1294,37 @@ public static List ioBForGraph_old(int number, double startTime) { return responses; }*/ + public static Double getCurrentIoB() { + if (Pref.getBooleanDefaultFalse("fetch_iob_from_companion_app")) { + return getCurrentIoBFromCompanionApp(); + } else { + return getCurrentIoBFromGraphCalculation(); + } + } + + public static Double getCurrentIoBFromCompanionApp() { + Double iob = UiBasedCollector.getCurrentIoB(); + + return iob; + } + + public static Double getCurrentIoBFromGraphCalculation() { + long now = System.currentTimeMillis(); + + final List iobInfo = Treatments.ioBForGraph_new(now - 1 * Constants.DAY_IN_MS); + + if (iobInfo != null) { + for (Iob iob : iobInfo) { + // Find IoB sample close to the current timestamp. + if (iob.timestamp > now - 5 * MINUTE_IN_MS && iob.timestamp < now + 5 * MINUTE_IN_MS) { + return iob.iob; + } + } + } + + return null; + } + public String getBestShortText() { if (!eventType.equals(DEFAULT_EVENT_TYPE)) { return eventType; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/UserError.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/UserError.java similarity index 79% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/UserError.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/UserError.java index ed3b88b7d6..95bfbdc73a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/UserError.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/UserError.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.os.AsyncTask; import android.provider.BaseColumns; @@ -9,15 +9,15 @@ import com.activeandroid.annotation.Table; import com.activeandroid.query.Delete; import com.activeandroid.query.Select; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.receiver.InfoContentProvider; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.google.gson.annotations.Expose; import java.util.Date; import java.util.Hashtable; import java.util.List; -//import com.bugfender.sdk.Bugfender; /** * Created by Emma Black on 8/3/15. @@ -50,12 +50,12 @@ public class UserError extends Model { //todo: rather than include multiples of the same error, should we have a "Count" and just increase that on duplicates? //or rather, perhaps we should group up the errors - public String toString() - { - return severity+" ^ "+JoH.dateTimeText((long)timestamp)+" ^ "+shortError+" ^ "+message; + public String toString() { + return severity + " ^ " + JoH.dateTimeText((long) timestamp) + " ^ " + shortError + " ^ " + message; } - public UserError() {} + public UserError() { + } public UserError(int severity, String shortError, String message) { this.severity = severity; @@ -112,7 +112,7 @@ public String bestTime() { public static void cleanup() { - new Cleanup().execute(deletable()); + new Cleanup().execute(deletable()); } // used in unit testing @@ -159,13 +159,13 @@ public static List deletable() { List highErrors = new Select() .from(UserError.class) .where("severity = ?", 3) - .where("timestamp < ?", (new Date().getTime() - 1000*60*60*24*3)) + .where("timestamp < ?", (new Date().getTime() - 1000 * 60 * 60 * 24 * 3)) .orderBy("timestamp desc") .execute(); List events = new Select() .from(UserError.class) .where("severity > ?", 3) - .where("timestamp < ?", (new Date().getTime() - 1000*60*60*24*7)) + .where("timestamp < ?", (new Date().getTime() - 1000 * 60 * 60 * 24 * 7)) .orderBy("timestamp desc") .execute(); userErrors.addAll(highErrors); @@ -178,10 +178,10 @@ public static List bySeverity(Integer[] levels) { for (int level : levels) { levelsString += level + ","; } - Log.d("UserError", "severity in ("+levelsString.substring(0,levelsString.length() - 1)+")"); + Log.d("UserError", "severity in (" + levelsString.substring(0, levelsString.length() - 1) + ")"); return new Select() .from(UserError.class) - .where("severity in ("+levelsString.substring(0,levelsString.length() - 1)+")") + .where("severity in (" + levelsString.substring(0, levelsString.length() - 1) + ")") .orderBy("timestamp desc") .limit(10000)//too many data can kill akp .execute(); @@ -236,6 +236,15 @@ public static List bySeverityOlderThanID(long id, Integer[] levels, i } + public static UserError newestBySeverity(int level) { + return new Select() + .from(UserError.class) + .where("severity == "+level) + .orderBy("timestamp desc") + .limit(1) + .executeSingle(); + } + public static UserError getForTimestamp(UserError error) { try { return new Select() @@ -245,7 +254,7 @@ public static UserError getForTimestamp(UserError error) { .where("message = ?", error.message) .executeSingle(); } catch (Exception e) { - Log.e(TAG,"getForTimestamp() Got exception on Select : "+e.toString()); + Log.e(TAG, "getForTimestamp() Got exception on Select : " + e.toString()); return null; } } @@ -254,12 +263,12 @@ private static class Cleanup extends AsyncTask, Integer, Boolean @Override protected Boolean doInBackground(List... errors) { try { - for(UserError userError : errors[0]) { + for (UserError userError : errors[0]) { userError.delete(); //userError.save(); } return true; - } catch(Exception e) { + } catch (Exception e) { return false; } } @@ -268,21 +277,23 @@ protected Boolean doInBackground(List... errors) { public static List bySeverity(int level) { return bySeverity(new Integer[]{level}); } + public static List bySeverity(int level, int level2) { - return bySeverity(new Integer[]{ level, level2 }); + return bySeverity(new Integer[]{level, level2}); } + public static List bySeverity(int level, int level2, int level3) { - return bySeverity(new Integer[]{ level, level2, level3 }); + return bySeverity(new Integer[]{level, level2, level3}); } public static class Log { - public static void e(String a, String b){ + public static void e(String a, String b) { android.util.Log.e(a, b); new UserError(a, b); } - public static void e(String tag, String b, Exception e){ + public static void e(String tag, String b, Exception e) { android.util.Log.e(tag, b, e); StringBuilder sb = new StringBuilder(); sb.append(b); @@ -291,28 +302,32 @@ public static void e(String tag, String b, Exception e){ sb.append("\n"); StackTraceElement[] ste = e.getStackTrace(); for (StackTraceElement ee : ste) { - sb.append(" " + ee.toString() + "\n"); + sb.append(" " + ee.toString() + "\n"); } - new UserError(tag, sb.toString()) ; + new UserError(tag, sb.toString()); } - public static void w(String tag, String b){ + public static void w(String tag, String b) { android.util.Log.w(tag, b); UserError.UserErrorLow(tag, b); } - public static void w(String tag, String b, Exception e){ + + public static void w(String tag, String b, Exception e) { android.util.Log.w(tag, b, e); UserError.UserErrorLow(tag, b + "\n" + e.toString()); } - public static void wtf(String tag, String b){ + + public static void wtf(String tag, String b) { android.util.Log.wtf(tag, b); UserError.UserErrorHigh(tag, b); } - public static void wtf(String tag, String b, Exception e){ + + public static void wtf(String tag, String b, Exception e) { android.util.Log.wtf(tag, b, e); UserError.UserErrorHigh(tag, b + "\n" + e.toString()); } - public static void wtf(String tag, Exception e){ + + public static void wtf(String tag, Exception e) { android.util.Log.wtf(tag, e); UserError.UserErrorHigh(tag, e.toString()); } @@ -325,46 +340,58 @@ public static void uel(String tag, String b) { public static void ueh(String tag, String b) { android.util.Log.i(tag, b); UserError.UserEventHigh(tag, b); + InfoContentProvider.ping("info"); } - public static void d(String tag, String b){ + public static void d(String tag, String b) { android.util.Log.d(tag, b); - if(ExtraLogTags.shouldLogTag(tag, android.util.Log.DEBUG)) { + if (ExtraLogTags.shouldLogTag(tag, android.util.Log.DEBUG)) { UserErrorLow(tag, b); } } - public static void v(String tag, String b){ + public static void v(String tag, String b) { android.util.Log.v(tag, b); - if(ExtraLogTags.shouldLogTag(tag, android.util.Log.VERBOSE)) { + if (ExtraLogTags.shouldLogTag(tag, android.util.Log.VERBOSE)) { UserErrorLow(tag, b); - } + } } - public static void i(String tag, String b){ + public static void i(String tag, String b) { android.util.Log.i(tag, b); - if(ExtraLogTags.shouldLogTag(tag, android.util.Log.INFO)) { + if (ExtraLogTags.shouldLogTag(tag, android.util.Log.INFO)) { UserErrorLow(tag, b); } } - - static ExtraLogTags extraLogTags = new ExtraLogTags(); + } - + public static class ExtraLogTags { - static Hashtable extraTags; - ExtraLogTags () { - extraTags = new Hashtable (); - String extraLogs = Pref.getStringDefaultBlank("extra_tags_for_logging"); - readPreference(extraLogs); + private static final Hashtable extraTags = new Hashtable<>(); + + static { + init(); + } + + private static void init() { + try { + extraTags.clear(); + readPreference(Pref.getStringDefaultBlank("extra_tags_for_logging")); + } catch (Exception e) { + UserError.Log.wtf(TAG, "Error with extra log tags: " + e); + } + } + + ExtraLogTags() { + init(); } - + /* * This function reads a string representing tags that the user wants to log * Format of string is tag1:level1,tag2,level2 * Example of string is Alerts:i,BG:W - * + * */ public static void readPreference(String extraLogs) { extraLogs = extraLogs.trim(); @@ -379,44 +406,44 @@ public static void readPreference(String extraLogs) { if (tags.length == 0) { return; } - + // go over all tags and parse them - for(String tag : tags) { + for (String tag : tags) { if (tag.length() > 0) parseTag(tag); } } - + static void parseTag(String tag) { // Format is tag:level for example Alerts:i String[] tagAndLevel = tag.trim().split(":"); - if(tagAndLevel.length != 2) { + if (tagAndLevel.length != 2) { Log.e(TAG, "Failed to parse " + tag); return; } - String level = tagAndLevel[1]; - String tagName = tagAndLevel[0].toLowerCase(); + String level = tagAndLevel[1]; + String tagName = tagAndLevel[0].toLowerCase(); // TODO I would like to make this case sensitive for performance reasons if (level.compareTo("d") == 0) { extraTags.put(tagName, android.util.Log.DEBUG); - UserErrorLow(TAG, "Adding tag with DEBUG " + tagAndLevel[0] ); + UserErrorLow(TAG, "Adding tag with DEBUG " + tagAndLevel[0]); return; } if (level.compareTo("v") == 0) { extraTags.put(tagName, android.util.Log.VERBOSE); - UserErrorLow(TAG,"Adding tag with VERBOSE " + tagAndLevel[0] ); + UserErrorLow(TAG, "Adding tag with VERBOSE " + tagAndLevel[0]); return; } if (level.compareTo("i") == 0) { extraTags.put(tagName, android.util.Log.INFO); - UserErrorLow(TAG, "Adding tag with info " + tagAndLevel[0] ); + UserErrorLow(TAG, "Adding tag with info " + tagAndLevel[0]); return; } Log.e(TAG, "Unknown level for tag " + tag + " please use d v or i"); } - + public static boolean shouldLogTag(final String tag, final int level) { - final Integer levelForTag = extraTags.get(tag != null ? tag.toLowerCase() : ""); + final Integer levelForTag = extraTags.get(tag != null ? tag.toLowerCase() : ""); // TODO I would like to make this case sensitive for performance reasons return levelForTag != null && level >= levelForTag; } - + } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/UserNotification.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/UserNotification.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/Models/UserNotification.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/UserNotification.java index d7afbe04bb..a2c658587e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/UserNotification.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/UserNotification.java @@ -1,14 +1,13 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.provider.BaseColumns; -import com.activeandroid.Model; import com.activeandroid.annotation.Column; import com.activeandroid.annotation.Table; import com.activeandroid.query.Select; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; import java.util.Arrays; import java.util.Date; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/blueReader.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/blueReader.java similarity index 96% rename from wear/src/main/java/com/eveningoutpost/dexdrip/Models/blueReader.java rename to app/src/main/java/com/eveningoutpost/dexdrip/models/blueReader.java index d82c078531..83f5313b86 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/Models/blueReader.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/blueReader.java @@ -1,14 +1,14 @@ -package com.eveningoutpost.dexdrip.Models; +package com.eveningoutpost.dexdrip.models; import android.text.format.DateFormat; import com.eveningoutpost.dexdrip.Home; import java.nio.ByteBuffer; import java.util.Date; -import com.eveningoutpost.dexdrip.Services.DexCollectionService; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.Notifications; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.services.DexCollectionService; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Notifications; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.xdrip; import com.eveningoutpost.dexdrip.R; import java.io.BufferedWriter; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/nfc/NFControl.java b/app/src/main/java/com/eveningoutpost/dexdrip/nfc/NFControl.java index a7022a99df..68fc8db0ea 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/nfc/NFControl.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/nfc/NFControl.java @@ -7,8 +7,8 @@ import android.os.Bundle; import com.eveningoutpost.dexdrip.glucosemeter.glucomen.GlucoMen; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.NFCReaderX; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.insulin.opennov.Options; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/nfc/TagMultiplexer.java b/app/src/main/java/com/eveningoutpost/dexdrip/nfc/TagMultiplexer.java index d8ab12b990..04af2f9bcd 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/nfc/TagMultiplexer.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/nfc/TagMultiplexer.java @@ -6,7 +6,7 @@ import com.eveningoutpost.dexdrip.glucosemeter.glucomen.GlucoMen; import com.eveningoutpost.dexdrip.glucosemeter.glucomen.GlucoMenNfc; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.NFCReaderX; import com.eveningoutpost.dexdrip.insulin.opennov.nfc.TagDispatcher; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Cache.java b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Cache.java new file mode 100644 index 0000000000..15c5ac4e89 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Cache.java @@ -0,0 +1,98 @@ +package com.eveningoutpost.dexdrip.plugin; + +import static com.eveningoutpost.dexdrip.utils.FileUtils.readFromFile; + +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.xdrip; + +import java.io.File; + +import lombok.val; + +/** + * JamOrHam + * + * Manage local file system cache for plugins + */ + +public class Cache { + + private static final String TAG = "PluginCache"; + + public static synchronized void refresh(final PluginDef def) { + if (def.isFresh()) { + if (getPath(def) != null) { + Log.d(TAG, "Marking " + def.name + " as loaded"); + def.setLoaded(); + return; + } + def.setLoading(); + Inevitable.task("plugin-dload", 200, () -> Download.get(def)); + Log.d(TAG, "Trying to load " + def.name + ""); + } + if (def.loadingFailed()) { + def.reset(); + Log.e(TAG, "Download failed for: " + def.name); + } + } + + private static String checkPath(final String path, final PluginDef def, final boolean erase) { + try { + val f = new File(path, def.name + ".dex"); + if (f.exists()) { + if (erase) { + f.delete(); + return null; + } + val fs = new File(path, def.name + ".sig"); + if (fs.exists()) { + val fv = new File(path, def.name + ".ver"); + if (fv.exists()) { + val v1 = new String(readFromFile(TAG, fv)); + if (def.version.equals(v1)) { + val b1 = readFromFile(TAG, f); + val b2 = readFromFile(TAG, fs); + val ok = Verify.verify(b1, b2); + if (!ok) { + Log.e(TAG, "Failed local verification " + path + " " + def.name); + return null; + } + return f.getAbsolutePath(); + } else { + Log.d(TAG, "Version doesn't match " + v1 + " vs " + def.version); + } + } else { + Log.d(TAG, "Missing version for " + def.name); + } + } else { + Log.d(TAG, "Missing signature for " + def.name); + } + } + } catch (Exception e) { + Log.e(TAG, "checkPath exception: " + e); + } + return null; + } + + private static String[] getPaths() { + val appDir = xdrip.getAppContext().getFilesDir().getPath(); + return new String[]{appDir}; + } + + public static String getPath(final PluginDef def) { + for (val c : getPaths()) { + val r = checkPath(c, def, false); + if (r != null) return r; + } + return null; + } + + public static synchronized void erase(final PluginDef def) { + for (val c : getPaths()) { + val r = checkPath(c, def, true); + } + Loader.clear(); + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Consent.java b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Consent.java new file mode 100644 index 0000000000..1c3adaa7f6 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Consent.java @@ -0,0 +1,21 @@ +package com.eveningoutpost.dexdrip.plugin; + +import com.eveningoutpost.dexdrip.utilitymodels.Pref; + +/** + * JamOrHam + * + * Plugin consent data storage + */ + +public class Consent { + private static final String PREFIX = "plugin-consent-"; + + public static void setGiven(final PluginDef pluginDef) { + Pref.setBoolean(PREFIX + pluginDef.name, true); + } + + public static boolean isGiven(final PluginDef pluginDef) { + return Pref.getBooleanDefaultFalse(PREFIX + pluginDef.name); + } +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Dialog.java b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Dialog.java new file mode 100644 index 0000000000..51c98a2906 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Dialog.java @@ -0,0 +1,66 @@ +package com.eveningoutpost.dexdrip.plugin; + +import static com.eveningoutpost.dexdrip.plugin.Consent.setGiven; + +import android.app.Activity; +import android.app.AlertDialog; + +import com.eveningoutpost.dexdrip.R; + +/** + * JamOrHam + * + * Request plug-in use consent from user via a dialog. + */ + +public class Dialog { + + private static final String TAG = "PluginDialog"; + + public static void ask(final Activity activity, final PluginDef pluginDef, final String text, final Runnable success, final Runnable failure) { + + final AlertDialog.Builder builder = new AlertDialog.Builder(activity) + .setTitle(String.format("Download %s plugin?", pluginDef.name)) // TODO I18n + .setMessage(String.format("Download and use the %s plugin published by %s?\n\n%s", pluginDef.name, pluginDef.author, text)); + + builder.setPositiveButton(R.string.yes, (dialog, which) -> { + setGiven(pluginDef); + success.run(); + }); + builder.setNegativeButton(R.string.no, (dialog, which) -> failure.run()); + + final AlertDialog dialog = builder.create(); + // apparently possible dialog is already showing, probably due to hash code + try { + if (dialog.isShowing()) { + dialog.dismiss(); + } + } catch (Exception e) { + // + } + dialog.show(); + + } + + public static boolean txIdMatch(final String txId) { + return txId != null && txId.length() > 0 && (txId.length() == 4 || (Character.isLetter(txId.charAt(0)) && !txId.equals("ABCDEF"))); + } + + public static boolean askIfNeeded(final Activity activity, final String txId) { + /* + if (txIdMatch(txId)) { + val plugin = Registry.get("keks"); + if (!Consent.isGiven(plugin)) { + runOnUiThread(() -> ask(activity, plugin, "To use Dex ONE transmitters a plugin is needed.\n\nPlease select YES to download and use the plugin which is published by xDrip+ project lead JamOrHam", + () -> Loader.getInstance(plugin, ""), + () -> UserError.Log.wtf(TAG, "User declined to download plugin"))); + return true; + } else { + Loader.getInstance(plugin, ""); + } + } + */ + return false; + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Download.java b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Download.java new file mode 100644 index 0000000000..2463e3ad38 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Download.java @@ -0,0 +1,101 @@ +package com.eveningoutpost.dexdrip.plugin; + +import static com.eveningoutpost.dexdrip.models.JoH.decompressBytesToBytes; +import static com.eveningoutpost.dexdrip.utils.DexCollectionType.Disabled; +import static com.eveningoutpost.dexdrip.utils.DexCollectionType.setDexCollectionType; +import static com.eveningoutpost.dexdrip.utils.FileUtils.writeToFile; + +import com.eveningoutpost.dexdrip.Home; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.xdrip; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; + +import lombok.val; +import okhttp3.OkHttpClient; +import okhttp3.Request; + +/** + * JamOrHam + * + * Plugin downloader + */ + +public class Download { + + private static final String TAG = "PluginDownload"; + private static final String SCHEME = "https://"; + + private static byte[] getData(final PluginDef pluginDef) { + if (pluginDef == null) return null; + val url = getUrl(pluginDef); + val client = new OkHttpClient(); + val builder = new Request.Builder().url(url); + val request = builder.build(); + UserError.Log.d(TAG, "REQUEST URL: " + request.url()); + try { + val response = client.newCall(request).execute(); + if (response.code() == 410) { + UserError.Log.wtf(TAG, "Shutdown requested"); + setDexCollectionType(Disabled); + } + if (response.isSuccessful()) { + return response.body().bytes(); + } else { + throw new RuntimeException("Got failure response code: " + response.code() + "\n" + (response.body() != null ? response.body().string() : "")); + } + } catch (IOException e) { + UserError.Log.e(TAG, "Exception getting plugin: " + e); + JoH.static_toast_long("Problem downloading plugin!"); + e.printStackTrace(); + } + return null; + } + + private static byte[] getSizedBlock(final ByteBuffer bb) { + val b1size = bb.getInt(); + if (b1size < 0 || b1size > 10000000) return null; + val b1 = new byte[b1size]; + bb.get(b1); + return b1; + } + + public static boolean get(final PluginDef pluginDef) { + try { + val bytes = getData(pluginDef); + if (bytes == null) return false; + val bb = ByteBuffer.wrap(bytes); + val b1 = getSizedBlock(bb); + val b2 = getSizedBlock(bb); + val b3 = getSizedBlock(bb); + val ok = Verify.verify(b1, b2); + if (ok && b3 != null) { + val storagePath = xdrip.getAppContext().getFilesDir().getPath(); + val fileStruct = storagePath + "/" + pluginDef.name; + writeToFile(TAG, fileStruct + ".dex", decompressBytesToBytes(b1)); + writeToFile(TAG, fileStruct + ".sig", b3); + writeToFile(TAG, fileStruct + ".ver", pluginDef.version.getBytes(StandardCharsets.UTF_8)); + UserError.Log.ueh(TAG, pluginDef.canonical() + " plugin successfully downloaded"); + JoH.static_toast_long("Plugin successfully downloaded"); + Home.staticRefreshBGCharts(); + return true; + } else { + UserError.Log.e(TAG, "Invalid verification for " + pluginDef.name); + } + } catch (Exception e) { + UserError.Log.e(TAG, "Exception in get() " + e); + } finally { + pluginDef.reset(); // move out of loading state + } + + return false; + } + + private static String getUrl(final PluginDef pluginDef) { + return SCHEME + pluginDef.repository + "/" + pluginDef.canonical() + ".bin"; + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/plugin/IPluginDA.java b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/IPluginDA.java new file mode 100644 index 0000000000..d7fe9992f8 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/IPluginDA.java @@ -0,0 +1,41 @@ +package com.eveningoutpost.dexdrip.plugin; + +/** + * JamOrHam + * + * Simple plugin data exchange interface + */ + +public interface IPluginDA { + + byte[][] aNext(); + + byte[][] bNext(); + + byte[][] cNext(); + + void amConnected(); + + boolean bondNow(final byte[] data); + + boolean receivedResponse(final byte[] data); + + boolean receivedResponse2(final byte[] data); + + boolean receivedResponse3(final byte[] data); + + boolean receivedData(final byte[] data); + + boolean receivedData2(final byte[] data); + + boolean receivedData3(final byte[] data); + + byte[] getPersistence(final int channel); + + boolean setPersistence(final int channel, final byte[] data); + + String getStatus(); + + String getName(); + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Loader.java b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Loader.java new file mode 100644 index 0000000000..384bbd7387 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Loader.java @@ -0,0 +1,100 @@ +package com.eveningoutpost.dexdrip.plugin; + +import static com.eveningoutpost.dexdrip.plugin.Cache.getPath; + +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.xdrip; + +import java.lang.reflect.Method; +import java.util.HashMap; + +import dalvik.system.PathClassLoader; +import lombok.AllArgsConstructor; +import lombok.val; + +/** + * JamOrHam + * + * Plugin virtual environment cache loader + */ + +public class Loader { + + private static final String TAG = "Plugin"; + private static final HashMap loaderCache = new HashMap<>(); + + public static void clear() { + synchronized (loaderCache) { + loaderCache.clear(); + } + } + + public static void unload(final String name) { + synchronized (loaderCache) { + loaderCache.remove(name); + } + } + + @AllArgsConstructor + public static class Environ { + PathClassLoader virtualLoader; + Method getInstance; + + public Environ(PathClassLoader loader) { + this.virtualLoader = loader; + } + } + + public static synchronized IPluginDA getLocalInstance(final PluginDef def, final String parameter) { + switch (def.name) { + case "keks": + return jamorham.keks.Plugin.getInstance(parameter); + default: + throw new RuntimeException("Unknown local plugin " + def.name); + } + } + + public static synchronized IPluginDA getInstance(final PluginDef def, final String parameter) { + if (def == null) return null; + try { + if (!Consent.isGiven(def)) { + UserError.Log.wtf(TAG, "User has not yet consented to use of plugin: " + def.name); + return null; + } + + if (!def.isReady()) { + Cache.refresh(def); + if (!def.isReady()) { + return null; + } + } + Environ environ; + synchronized (loaderCache) { + if (!loaderCache.containsKey(def.name)) { + val loader = new PathClassLoader(getPath(def), xdrip.getAppContext().getClassLoader()); + loaderCache.put(def.name, new Environ(loader)); + } + environ = loaderCache.get(def.name); + } + if (environ == null) { + UserError.Log.e(TAG, "Cannot get loader"); + return null; + } + try { + if (environ.getInstance == null) { + val c = environ.virtualLoader.loadClass(def.pname() + TAG); + UserError.Log.d(TAG, "Loaded from file: " + c.getCanonicalName()); + environ.getInstance = c.getMethod("getInstance", String.class); + } + return (IPluginDA) environ.getInstance.invoke(null, parameter); + } catch (Exception e) { + UserError.Log.e(TAG, "Got load exception: " + e); + unload(def.name); + } + } catch (Exception e) { + UserError.Log.e(TAG, "Got exception in getInstance: " + e); + } + return null; + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/plugin/PluginDef.java b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/PluginDef.java new file mode 100644 index 0000000000..fcedb4a25d --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/PluginDef.java @@ -0,0 +1,71 @@ +package com.eveningoutpost.dexdrip.plugin; + +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS; +import static com.eveningoutpost.dexdrip.plugin.PluginDef.State.Fresh; +import static com.eveningoutpost.dexdrip.plugin.PluginDef.State.Loaded; +import static com.eveningoutpost.dexdrip.plugin.PluginDef.State.Loading; + +import lombok.RequiredArgsConstructor; + +/** + * JamOrHam + * + * Plugin meta-data and state handling + */ + +@RequiredArgsConstructor +public class PluginDef { + + final String name; + final String author; + final String version; + final String repository; + private volatile State state = Fresh; + private volatile long lastChange; + + public boolean isReady() { + return state == Loaded; + } + + public boolean isFresh() { + return state == Fresh; + } + + public boolean loadingFailed() { + return state == Loading && (msSince(lastChange) > MINUTE_IN_MS * 5); + } + + private void changeState(final State state) { + lastChange = tsl(); + this.state = state; + } + + public void setLoading() { + changeState(Loading); + } + + public void setLoaded() { + changeState(Loaded); + } + + public void reset() { + state = Fresh; + } + + public String canonical() { + return author + "-" + name + "-" + version; + } + + public String pname() { + return author + "." + name + "."; + } + + public enum State { + Fresh, + Loading, + Loaded, + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Registry.java b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Registry.java new file mode 100644 index 0000000000..d34c456bd5 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Registry.java @@ -0,0 +1,40 @@ +package com.eveningoutpost.dexdrip.plugin; + +import static com.eveningoutpost.dexdrip.plugin.Cache.erase; + +import java.util.HashMap; + +import lombok.val; + +/** + * JamOrHam + *

+ * Plugin registry with name, author, version and repository location + */ + +public class Registry { + + private static final HashMap registry = new HashMap<>(); + + static { + add(new PluginDef("zarquon", "jamorham", "2.1", "rgate1.local")); + add(new PluginDef("zarquot", "jamorham", "2.1", "rgate-staging.local")); + add(new PluginDef("keks", "jamorham", "1.3", "plugin1.beonlabs.net")); + } + + private static void add(final PluginDef pluginDef) { + registry.put(pluginDef.name, pluginDef); + } + + public static PluginDef get(final String name) { + return registry.get(name); + } + + public static synchronized void eraseAll() { + for (val p : registry.entrySet()) { + erase(p.getValue()); + p.getValue().reset(); + } + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Verify.java b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Verify.java new file mode 100644 index 0000000000..3603800b98 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/plugin/Verify.java @@ -0,0 +1,58 @@ +package com.eveningoutpost.dexdrip.plugin; + +import static com.eveningoutpost.dexdrip.models.JoH.hexStringToByteArray; + +import com.eveningoutpost.dexdrip.models.UserError; + +import java.security.KeyFactory; +import java.security.PublicKey; +import java.security.Signature; +import java.security.spec.X509EncodedKeySpec; + +import lombok.val; + +/** + * JamOrHam + */ + +public class Verify { + + private static final String VERIFY_KEY = "308201B73082012C06072A8648CE3804013082011F02818100FD7" + + "F53811D75122952DF4A9C2EECE4E7F611B7523CEF4400C31E3F80B6512669455D402251FB593D8D58FABFC" + + "5F5BA30F6CB9B556CD7813B801D346FF26660B76B9950A5A49F9FE8047B1022C24FBBA9D7FEB7C61BF83B5" + + "7E7C6A8A6150F04FB83F6D3C51EC3023554135A169132F675F3AE2B61D72AEFF22203199DD14801C702150" + + "09760508F15230BCCB292B982A2EB840BF0581CF502818100F7E1A085D69B3DDECBBCAB5C36B857B97994A" + + "FBBFA3AEA82F9574C0B3D0782675159578EBAD4594FE67107108180B449167123E84C281613B7CF09328CC" + + "8A6E13C167A8B547C8D28E0A3AE1E2BB3A675916EA37F0BFA213562F1FB627A01243BCCA4F1BEA8519089A" + + "883DFE15AE59F06928B665E807B552564014C3BFECF492A038184000281806180D810C8071501556C4E3B1" + + "D8AA842C78F5130B530BB1B9127CDE13760777E437604A5E3308C917B2AB7532857465929633206A4666D6" + + "EC01FB1663C81C579AAA72B83BC976B735AC50EC52D59E0D02F08F2A75A0C32F86F28517A20DD510B56481" + + "FEBB298C1F0ED00463DF69B00DF78C197176F68B44B4B3AC3F68B550AE3"; + + private static final boolean debug = false; + + private static final String TAG = Verify.class.getSimpleName(); + + private static PublicKey getPublicKey() { + try { + return KeyFactory.getInstance("DSA") + .generatePublic(new X509EncodedKeySpec(hexStringToByteArray(VERIFY_KEY))); + } catch (Exception e) { + UserError.Log.e(TAG, "Failed to get public key: " + e); + return null; + } + } + + public static boolean verify(final byte[] data, final byte[] signature) { + try { + val signCheck = Signature.getInstance("SHA256withDSA"); + signCheck.initVerify(getPublicKey()); + signCheck.update(data); + return signCheck.verify(signature) + || debug; + } catch (Exception e) { + UserError.Log.e(TAG, "Verification failed due to exception: " + e); + return debug; + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/processing/BaseSmoother.java b/app/src/main/java/com/eveningoutpost/dexdrip/processing/BaseSmoother.java index 415a231a65..dcb079016d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/processing/BaseSmoother.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/processing/BaseSmoother.java @@ -1,10 +1,10 @@ package com.eveningoutpost.dexdrip.processing; -import static com.eveningoutpost.dexdrip.Models.JoH.tolerantParseDouble; +import static com.eveningoutpost.dexdrip.models.JoH.tolerantParseDouble; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.Unitized; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Unitized; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/processing/GotoSmoother.java b/app/src/main/java/com/eveningoutpost/dexdrip/processing/GotoSmoother.java index fefe9d4fc7..cfadb4b996 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/processing/GotoSmoother.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/processing/GotoSmoother.java @@ -1,9 +1,9 @@ package com.eveningoutpost.dexdrip.processing; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import com.eveningoutpost.dexdrip.processing.sgfilter.ContinuousPadder; import com.eveningoutpost.dexdrip.processing.sgfilter.EnvelopeProcessor; import com.eveningoutpost.dexdrip.processing.sgfilter.LowPreserver; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/processing/JSmoother.java b/app/src/main/java/com/eveningoutpost/dexdrip/processing/JSmoother.java index 07ad2cbd87..cd27c9b10e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/processing/JSmoother.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/processing/JSmoother.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.processing; -import com.eveningoutpost.dexdrip.Models.BgReading; +import com.eveningoutpost.dexdrip.models.BgReading; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/processing/SmootherFactory.java b/app/src/main/java/com/eveningoutpost/dexdrip/processing/SmootherFactory.java index f1ab637e54..a87cbd3bcd 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/processing/SmootherFactory.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/processing/SmootherFactory.java @@ -1,9 +1,9 @@ package com.eveningoutpost.dexdrip.processing; -import static com.eveningoutpost.dexdrip.UtilityModels.Unitized.unit; -import static com.eveningoutpost.dexdrip.UtilityModels.Unitized.usingMgDl; +import static com.eveningoutpost.dexdrip.utilitymodels.Unitized.unit; +import static com.eveningoutpost.dexdrip.utilitymodels.Unitized.usingMgDl; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import java.util.HashMap; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/processing/sgfilter/LowPreserver.java b/app/src/main/java/com/eveningoutpost/dexdrip/processing/sgfilter/LowPreserver.java index f5e78af677..7f8290df96 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/processing/sgfilter/LowPreserver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/processing/sgfilter/LowPreserver.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.processing.sgfilter; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import java.security.InvalidParameterException; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/AapsProfile.java b/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/AapsProfile.java index 0254eebcd7..b4205d3c7e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/AapsProfile.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/AapsProfile.java @@ -22,7 +22,7 @@ public class AapsProfile { @Expose String timezone; - private List basalByMinute; + private List basalByMinute; private List profileByMinute; public boolean usingMgdl() { @@ -30,12 +30,12 @@ public boolean usingMgdl() { } // explode basal to per minute resolution - public List getBasalByMinute() { + public List getBasalByMinute() { if (basalByMinute == null) { if (basal != null) { - float current = 0f; + double current = 0d; int currentMinute = 0; - final List byMinute = new ArrayList<>(1440); + final List byMinute = new ArrayList<>(1440); for (int i = 0; i < 1440; i++) { byMinute.add(current); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/BasalProfile.java b/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/BasalProfile.java index 481d6f251b..fc555acadf 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/BasalProfile.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/BasalProfile.java @@ -1,9 +1,9 @@ package com.eveningoutpost.dexdrip.profileeditor; -import static com.eveningoutpost.dexdrip.Models.JoH.JsonStringToFloatList; +import static com.eveningoutpost.dexdrip.models.JoH.JsonStringToFloatList; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import org.json.JSONArray; import org.json.JSONException; @@ -26,7 +26,7 @@ private static String getPrefix(final String ref) { return BASAL_PREFIX + ref; } - public static void save(final String ref, final List segments) { + public static void save(final String ref, final List segments) { Pref.setString(getPrefix(ref), JoH.defaultGsonInstance().toJson(segments)); //android.util.Log.d("PROFILEXX", "Saved value:" + Pref.getString(getPrefix(ref), "null")); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/BasalProfileEditor.java b/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/BasalProfileEditor.java index a4facd6593..de0c5016e3 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/BasalProfileEditor.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/BasalProfileEditor.java @@ -3,8 +3,9 @@ import android.annotation.SuppressLint; import android.graphics.Rect; import android.os.Bundle; -import android.support.annotation.ColorInt; -import android.support.v7.app.AppCompatActivity; +import androidx.annotation.ColorInt; +import androidx.appcompat.app.AppCompatActivity; + import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.style.StyleSpan; @@ -19,11 +20,11 @@ import android.widget.Spinner; import android.widget.TextView; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.ColorCache; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.ColorCache; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; import com.eveningoutpost.dexdrip.ui.charts.BasalChart; import com.eveningoutpost.dexdrip.ui.dialog.GenericConfirmDialog; import com.eveningoutpost.dexdrip.ui.helpers.ColorUtil; @@ -41,7 +42,7 @@ import lecho.lib.hellocharts.view.ColumnChartView; import lombok.val; -import static com.eveningoutpost.dexdrip.UtilityModels.ColorCache.getCol; +import static com.eveningoutpost.dexdrip.utilitymodels.ColorCache.getCol; import static com.eveningoutpost.dexdrip.ui.helpers.UiHelper.convertDpToPixel; // jamorham @@ -495,11 +496,11 @@ private void setPlusMinusVisible(final boolean visible) { basalStepLabel.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); } - private List getListOfValues() { + private List getListOfValues() { final int columns = chart.getChartData().getColumns().size(); - final ArrayList values = new ArrayList<>(columns); + final ArrayList values = new ArrayList<>(columns); for (int col = 0; col < columns; col++) { - values.add(JoH.roundFloat(chart.getChartData().getColumns().get(col).getValues().get(0).getValue(), 2)); + values.add(JoH.roundDouble(chart.getChartData().getColumns().get(col).getValues().get(0).getValue(), 2)); } return values; } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/BasalRepository.java b/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/BasalRepository.java index 3f468d3f15..a6fdbae85e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/BasalRepository.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/BasalRepository.java @@ -1,11 +1,11 @@ package com.eveningoutpost.dexdrip.profileeditor; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.Models.JoH.roundDouble; -import static com.eveningoutpost.dexdrip.Models.JoH.tsl; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.roundDouble; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; import static com.eveningoutpost.dexdrip.profileeditor.BasalProfile.getActiveRateName; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/ImportAapsProfile.java b/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/ImportAapsProfile.java index 5e8ac36c18..fabc585c70 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/ImportAapsProfile.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/ImportAapsProfile.java @@ -2,11 +2,11 @@ import static com.eveningoutpost.dexdrip.profileeditor.BasalProfile.consolidate; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.Unitized; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Unitized; import com.eveningoutpost.dexdrip.utils.jobs.BackgroundQueue; import com.google.gson.GsonBuilder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/ProfileAdapter.java b/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/ProfileAdapter.java index 9e55b3d9c2..e8f43200ed 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/ProfileAdapter.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/ProfileAdapter.java @@ -3,7 +3,7 @@ import android.app.Activity; import android.content.Context; -import android.support.v7.widget.RecyclerView; + import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -15,7 +15,9 @@ import android.widget.SeekBar; import android.widget.TextView; -import com.eveningoutpost.dexdrip.Models.JoH; +import androidx.recyclerview.widget.RecyclerView; + +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/ProfileEditor.java b/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/ProfileEditor.java index 36aab04571..aaf7ff6746 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/ProfileEditor.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/ProfileEditor.java @@ -9,10 +9,7 @@ import android.graphics.Point; import android.os.Build; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; + import android.util.DisplayMetrics; import android.util.Log; import android.view.View; @@ -20,16 +17,20 @@ import android.widget.SeekBar; import android.widget.TextView; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import com.eveningoutpost.dexdrip.BaseAppCompatActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Profile; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Profile; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.JamorhamShowcaseDrawer; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.ShotStateStore; +import com.eveningoutpost.dexdrip.utilitymodels.JamorhamShowcaseDrawer; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.ShotStateStore; import com.eveningoutpost.dexdrip.utils.Preferences; import com.github.amlcurran.showcaseview.ShowcaseView; import com.github.amlcurran.showcaseview.targets.Target; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/receiver/InfoContentProvider.java b/app/src/main/java/com/eveningoutpost/dexdrip/receiver/InfoContentProvider.java new file mode 100644 index 0000000000..16205b28b4 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/receiver/InfoContentProvider.java @@ -0,0 +1,310 @@ +package com.eveningoutpost.dexdrip.receiver; + +import static com.eveningoutpost.dexdrip.utilitymodels.ColorCache.getCol; +import static com.eveningoutpost.dexdrip.utilitymodels.NanoStatus.nanoStatus; +import static com.eveningoutpost.dexdrip.utilitymodels.Pref.getBooleanDefaultFalse; +import static com.eveningoutpost.dexdrip.watch.thinjam.BlueJayEntry.isNative; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.database.Cursor; +import android.database.MatrixCursor; +import android.graphics.Bitmap; + +import android.net.Uri; +import android.os.Looper; +import android.util.Log; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.eveningoutpost.dexdrip.BestGlucose; +import com.eveningoutpost.dexdrip.BuildConfig; +import com.eveningoutpost.dexdrip.eassist.EmergencyAssist; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.BgSparklineBuilder; + +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.ColorCache; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utils.BlobCache; +import com.eveningoutpost.dexdrip.xdrip; + +import java.io.ByteArrayOutputStream; + +/** + * xDrip content provider + * JamOrHam + */ +public class InfoContentProvider extends ContentProvider { + + private static final String TAG = "jamorham-content"; + private static final BlobCache dgCache = new BlobCache(60_000); + private static final BlobCache graphCache = new BlobCache(60_000); + + { + xdrip.setContext(getContext()); + } + + @Override + public boolean onCreate() { + xdrip.setContext(getContext()); + return enabled(); + } + + @Nullable + @Override + public Cursor query(@NonNull Uri uri, String[] projection, String selection, + String[] selectionArgs, String sortOrder) { + if (!enabled()) return null; + try { + if (selection == null) return null; + + switch (selection) { + + case "ping": + return matrixRow( + "version", BuildConfig.VERSION_NAME, + "versioncode", BuildConfig.buildVersion); + + case "alarms": + if (selectionArgs.length > 0 && selectionArgs[0].equals("snooze")) { + AlertPlayer.getPlayer().OpportunisticSnooze(); + Log.d(TAG, "Opportunistic snooze"); + } + break; + + case "eassist": + if (enabledWrite()) { + EmergencyAssist.test(EmergencyAssist.Reason.REQUESTED_ASSISTANCE, Constants.MINUTE_IN_MS); + UserError.Log.ueh(TAG, "Emergency assist triggered remotely"); + } + break; + + case "bg": { + BestGlucose.DisplayGlucose dg = (BestGlucose.DisplayGlucose) dgCache.get(); + if (dg == null) { + dg = BestGlucose.getDisplayGlucose(); + dgCache.set(dg); + } + if (dg == null) return null; + + int chint = getCol(ColorCache.X.color_inrange_bg_values); + if (dg.isHigh()) { + chint = getCol(ColorCache.X.color_high_bg_values); + } else if (dg.isLow()) { + chint = getCol(ColorCache.X.color_low_bg_values); + } + return matrixRow( + "timestamp", dg.timestamp, + "mgdl", dg.mgdl, + "delta_mgdl", dg.delta_mgdl, + "delta_arrow", dg.delta_arrow, + "delta_name", dg.delta_name, + "mssince", dg.mssince, + "unitized", dg.unitized, + "unitized_delta", dg.unitized_delta, + "unitized_delta_no_units", dg.unitized_delta_no_units, + "chint", chint, + "humansummary", dg.humanSummary(), + "ishigh", boolInt(dg.isHigh()), + "islow", boolInt(dg.isLow()), + "isstale", boolInt(dg.isStale()), + "isreallystale", boolInt(dg.isReallyStale()) + ); + } + + case "status-line": { + } + break; + + case "nano-status": { + return matrixRow( + "collector", nanoStatus("collector"), + "sensor-expiry", nanoStatus("sensor-expiry") + ); + } + + case "info": + return matrixRow("last_ueh", UserError.newestBySeverity(6)); + + case "iob-info": { + } + break; + + case "graph": { + + if (Looper.myLooper() == null) { + Looper.prepare(); + } + + final int width = Math.min(1000, Integer.parseInt(selectionArgs[0])); + final int height = Math.min(1000, Integer.parseInt(selectionArgs[1])); + + byte[] blob = (byte[]) graphCache.get(width, height); + if (blob == null) { + String backgroundColor = "#80000000"; + if (selectionArgs.length >= 3) { + backgroundColor = selectionArgs[2]; + } + + final BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(xdrip.getAppContext()); + + final Bitmap bitmap = new BgSparklineBuilder(xdrip.getAppContext()) + .setBgGraphBuilder(bgGraphBuilder) + .setHeight(height) + .setDotSize(5) + .setWidth(width) + .showHighLine(true) + .showLowLine(true) + .build(); + blob = convertBitmapToPNGByteArray(bitmap); + bitmap.recycle(); + graphCache.set(blob, width, height); + } + + final String[] columnNames = {"blob"}; + final MatrixCursor cursor = new MatrixCursor(columnNames); + cursor.addRow(new Object[]{blob}); + return cursor; + } + + case "config": + if (enabledWrite()) { + try { + if (selectionArgs != null && projection != null + && selectionArgs.length == projection.length) { + for (int i = 0; i < projection.length; i++) { + final String item = projection[i]; + switch (sortOrder) { + case "String": + Pref.setString(item, selectionArgs[i]); + break; + case "Integer": + Pref.setInt(item, Integer.parseInt(selectionArgs[i])); + break; + case "Long": + Pref.setLong(item, Long.parseLong(selectionArgs[i])); + break; + case "Boolean": + Pref.setBoolean(item, Boolean.parseBoolean(selectionArgs[i])); + break; + case "NewString": + if (Pref.getString(item, "defaultvalue").equals("defaultvalue")) { + Pref.setString(item, selectionArgs[i]); + } + break; + case "NewInteger": + if (Pref.getInt(item, -1000) == -1000) { + Pref.setInt(item, Integer.parseInt(selectionArgs[i])); + } + break; + case "NewLong": + if (Pref.getLong(item, -1000) == -1000) { + Pref.setLong(item, Long.parseLong(selectionArgs[i])); + } + break; + case "NewBoolean": + if (Pref.isPreferenceSet(item)) { + Pref.setBoolean(item, Boolean.parseBoolean(selectionArgs[i])); + } + break; + case "Remove": + Pref.removeItem(item); + break; + } + } + CollectionServiceStarter.restartCollectionServiceBackground(); + return matrixRow("processed", projection.length); + } + } catch (Exception e) { + UserError.Log.e(TAG, "config error: " + e); + } + } + return null; + + } // end switch + } catch (Exception e) { + Log.d(TAG, "Got exception: " + e); + e.printStackTrace(); + } + return null; + } + + private static MatrixCursor matrixRow(Object... x) { + final String[] columnNames = new String[x.length / 2]; + final Object[] values = new Object[x.length / 2]; + for (int i = 0; i < x.length; i += 2) { + columnNames[i / 2] = (String) x[i]; + values[i / 2] = x[i + 1]; + } + try ( + MatrixCursor cursor = new MatrixCursor(columnNames)) { + cursor.addRow(values); + return cursor; + } catch (Exception e) { + Log.d(TAG, "Error with cursor: " + e); + } + return null; + } + + @Nullable + @Override + public String getType(@NonNull Uri uri) { + return null; + } + + @Nullable + @Override + public Uri insert(@NonNull Uri uri, @Nullable ContentValues contentValues) { + if (!enabled()) return null; + try { + getContext().getContentResolver().notifyChange(uri, null); + } catch (Exception e) { + Log.e(TAG, "Got exception during insert " + e); + } + return null; + } + + @Override + public int delete(@NonNull Uri uri, @Nullable String s, @Nullable String[] strings) { + return 0; + } + + @Override + public int update(@NonNull Uri uri, @Nullable ContentValues contentValues, @Nullable String s, @Nullable String[] strings) { + return 0; + } + + private int boolInt(final boolean bool) { + return bool ? 1 : 0; + } + + private static boolean enabled() { + return isNative() || xdrip.getAppContext() != null && getBooleanDefaultFalse("host_content_provider"); + } + + private static boolean enabledWrite() { + return enabled() && (isNative() || getBooleanDefaultFalse("content_provider_write")); + } + + public static void ping(String channel) { + if (enabled() && channel != null) { + if (channel.equals("bg")) { + dgCache.clear(); + graphCache.clear(); + } + xdrip.getAppContext().getContentResolver().insert(Uri.parse("content://" + BuildConfig.APPLICATION_ID + ".contentprovider/" + channel), null); + } + } + + public static byte[] convertBitmapToPNGByteArray(Bitmap bitmap) { + final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream); + return outputStream.toByteArray(); + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/receiver/ReminderReceiver.java b/app/src/main/java/com/eveningoutpost/dexdrip/receiver/ReminderReceiver.java index 909e67b1ee..c798130a6f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/receiver/ReminderReceiver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/receiver/ReminderReceiver.java @@ -6,7 +6,7 @@ import android.content.Intent; import android.os.Bundle; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.Reminders; public class ReminderReceiver extends BroadcastReceiver { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/receivers/aidex/AidexMessageType.java b/app/src/main/java/com/eveningoutpost/dexdrip/receivers/aidex/AidexMessageType.java index 0a96ee29da..a08dc61910 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/receivers/aidex/AidexMessageType.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/receivers/aidex/AidexMessageType.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.receivers.aidex; -import android.support.annotation.StringRes; +import androidx.annotation.StringRes; import com.eveningoutpost.dexdrip.R; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/receivers/aidex/AidexReceiver.java b/app/src/main/java/com/eveningoutpost/dexdrip/receivers/aidex/AidexReceiver.java index 2ec051785f..147a864c53 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/receivers/aidex/AidexReceiver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/receivers/aidex/AidexReceiver.java @@ -16,14 +16,14 @@ import android.util.Log; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.DexCollectionType; @@ -149,7 +149,7 @@ private void processNewBGEstimate(Bundle bundle) { checkIfCorrectSensorIsRunning(sensorId, timeStamp); UserError.Log.i(TAG, "Aidex Broadcast NewBGEstimate received: bg=" + bgValueMgDl + ", time=" + JoH.dateTimeText(timeStamp)); - BgReading.bgReadingInsertFromInt(bgValueMgDl, timeStamp, segmentation_timeslice, false); + BgReading.bgReadingInsertFromInt(bgValueMgDl, timeStamp, segmentation_timeslice, true); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/ActivityRecognizedService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/ActivityRecognizedService.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/ActivityRecognizedService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/ActivityRecognizedService.java index fac3b48f03..5e02dfb70e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/ActivityRecognizedService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/ActivityRecognizedService.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.app.IntentService; import android.app.PendingIntent; @@ -9,24 +9,23 @@ import android.net.Uri; import android.os.Bundle; import android.os.PowerManager; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.NotificationManagerCompat; -import android.support.v7.app.NotificationCompat; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.app.NotificationCompat; +import androidx.core.app.NotificationManagerCompat; import android.util.Log; import android.util.SparseArray; import com.eveningoutpost.dexdrip.ErrorsActivity; import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.ShotStateStore; -import com.eveningoutpost.dexdrip.UtilityModels.VehicleMode; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.ShotStateStore; +import com.eveningoutpost.dexdrip.utilitymodels.VehicleMode; import com.eveningoutpost.dexdrip.utils.PowerStateReceiver; -import com.eveningoutpost.dexdrip.utils.WebAppHelper; import com.eveningoutpost.dexdrip.xdrip; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/AlwaysOnDisplayService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/AlwaysOnDisplayService.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/AlwaysOnDisplayService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/AlwaysOnDisplayService.java index 5e37b65084..a33b707b05 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/AlwaysOnDisplayService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/AlwaysOnDisplayService.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.accessibilityservice.AccessibilityService; import android.content.BroadcastReceiver; @@ -18,9 +18,9 @@ import android.widget.FrameLayout; import android.widget.RemoteViews; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; import com.eveningoutpost.dexdrip.utils.math.BlockFinder; import com.eveningoutpost.dexdrip.xDripWidget; @@ -32,7 +32,7 @@ import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER; -import static com.eveningoutpost.dexdrip.Models.JoH.tsl; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; import static com.eveningoutpost.dexdrip.ui.helpers.UiHelper.convertDpToPixel; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/BluetoothGlucoseMeter.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/BluetoothGlucoseMeter.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/BluetoothGlucoseMeter.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/BluetoothGlucoseMeter.java index 1d15165656..84eb246a47 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/BluetoothGlucoseMeter.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/BluetoothGlucoseMeter.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.annotation.TargetApi; import android.app.Service; @@ -24,7 +24,7 @@ import android.os.IBinder; import android.os.ParcelUuid; import android.os.PowerManager; -import android.support.v4.content.LocalBroadcastManager; + import android.util.Log; import com.eveningoutpost.dexdrip.GcmActivity; @@ -35,16 +35,16 @@ import com.eveningoutpost.dexdrip.glucosemeter.caresens.ContextRx; import com.eveningoutpost.dexdrip.glucosemeter.caresens.TimeTx; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.xdrip; import java.lang.reflect.Method; @@ -57,8 +57,10 @@ import static com.eveningoutpost.dexdrip.glucosemeter.VerioHelper.VERIO_F7A1_SERVICE; import static com.eveningoutpost.dexdrip.glucosemeter.VerioHelper.VERIO_F7A2_WRITE; import static com.eveningoutpost.dexdrip.glucosemeter.VerioHelper.VERIO_F7A3_NOTIFICATION; -import static com.eveningoutpost.dexdrip.Models.CalibrationRequest.isSlopeFlatEnough; -import static com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder.unitized_string_with_units_static; +import static com.eveningoutpost.dexdrip.models.CalibrationRequest.isSlopeFlatEnough; +import static com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder.unitized_string_with_units_static; + +import androidx.localbroadcastmanager.content.LocalBroadcastManager; /** * Created by jamorham on 09/12/2016. @@ -483,12 +485,12 @@ protected static void waitFor(final int millis) { @Override public void onCreate() { super.onCreate(); - if (Build.VERSION.SDK_INT < 29) { + if (Build.VERSION.SDK_INT < 26) { final IntentFilter pairingRequestFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST); pairingRequestFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1); registerReceiver(mPairingRequestRecevier, pairingRequestFilter); } else { - UserError.Log.d(TAG, "Not registering pairing receiver on Android 10+"); + UserError.Log.d(TAG, "Not registering pairing receiver on Android 8+"); } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/CollectorStatus.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/CollectorStatus.java similarity index 79% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/CollectorStatus.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/CollectorStatus.java index 2ea6b9b2f3..e6f29b94af 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/CollectorStatus.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/CollectorStatus.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; /** * Created by jamorham on 19/01/2018. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/ComunicationHeader.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/ComunicationHeader.java similarity index 94% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/ComunicationHeader.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/ComunicationHeader.java index 56898f091c..d15932b040 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/ComunicationHeader.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/ComunicationHeader.java @@ -1,6 +1,5 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; -import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.annotations.Expose; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/DailyIntentService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/DailyIntentService.java similarity index 87% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/DailyIntentService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/DailyIntentService.java index ea089c8ff3..25906442e7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/DailyIntentService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/DailyIntentService.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.app.AlarmManager; import android.app.IntentService; @@ -8,29 +8,29 @@ import android.os.PowerManager; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.DesertSync; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Libre2RawValue; -import com.eveningoutpost.dexdrip.Models.RollCall; -import com.eveningoutpost.dexdrip.Models.StepCounter; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.BgSendQueue; -import com.eveningoutpost.dexdrip.UtilityModels.CalibrationSendQueue; -import com.eveningoutpost.dexdrip.UtilityModels.IncompatibleApps; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.UploaderQueue; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.DesertSync; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Libre2RawValue; +import com.eveningoutpost.dexdrip.models.RollCall; +import com.eveningoutpost.dexdrip.models.StepCounter; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.BgSendQueue; +import com.eveningoutpost.dexdrip.utilitymodels.CalibrationSendQueue; +import com.eveningoutpost.dexdrip.utilitymodels.IncompatibleApps; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.UploaderQueue; import com.eveningoutpost.dexdrip.cloud.backup.Backup; import com.eveningoutpost.dexdrip.utils.DatabaseUtil; import com.eveningoutpost.dexdrip.utils.Telemetry; import com.eveningoutpost.dexdrip.wearintegration.WatchUpdaterService; import com.eveningoutpost.dexdrip.xdrip; -import com.eveningoutpost.dexdrip.UtilityModels.SettingsValidation; +import com.eveningoutpost.dexdrip.utilitymodels.SettingsValidation; import static com.eveningoutpost.dexdrip.Home.startWatchUpdaterService; -import static com.eveningoutpost.dexdrip.UtilityModels.UpdateActivity.checkForAnUpdate; +import static com.eveningoutpost.dexdrip.utilitymodels.UpdateActivity.checkForAnUpdate; public class DailyIntentService extends IntentService { private final static String TAG = DailyIntentService.class.getSimpleName(); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/DexCollectionService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/DexCollectionService.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/DexCollectionService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/DexCollectionService.java index d11e260017..a9d137ae53 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/DexCollectionService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/DexCollectionService.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.annotation.SuppressLint; import android.annotation.TargetApi; @@ -40,31 +40,31 @@ import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice; -import com.eveningoutpost.dexdrip.Models.Atom; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.Bubble; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.LibreBluetooth; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.Tomato; -import com.eveningoutpost.dexdrip.Models.TransmitterData; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.Models.blueReader; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.ActiveBluetoothDevice; +import com.eveningoutpost.dexdrip.models.Atom; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.Bubble; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.LibreBluetooth; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.Tomato; +import com.eveningoutpost.dexdrip.models.TransmitterData; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.models.blueReader; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Blukon; -import com.eveningoutpost.dexdrip.UtilityModels.BridgeResponse; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.ForegroundServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.HM10Attributes; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; -import com.eveningoutpost.dexdrip.UtilityModels.XbridgePlus; +import com.eveningoutpost.dexdrip.utilitymodels.Blukon; +import com.eveningoutpost.dexdrip.utilitymodels.BridgeResponse; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.ForegroundServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.HM10Attributes; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; +import com.eveningoutpost.dexdrip.utilitymodels.XbridgePlus; import com.eveningoutpost.dexdrip.utils.BtCallBack; import com.eveningoutpost.dexdrip.utils.CheckBridgeBattery; import com.eveningoutpost.dexdrip.utils.DexCollectionType; @@ -85,8 +85,8 @@ import java.util.UUID; import static android.bluetooth.BluetoothDevice.TRANSPORT_LE; -import static com.eveningoutpost.dexdrip.Models.JoH.convertPinToBytes; -import static com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder.DEXCOM_PERIOD; +import static com.eveningoutpost.dexdrip.models.JoH.convertPinToBytes; +import static com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder.DEXCOM_PERIOD; import static com.eveningoutpost.dexdrip.utils.bt.Helper.getStatusName; import static com.eveningoutpost.dexdrip.xdrip.gs; @@ -1044,7 +1044,7 @@ public void run() { l.add(new StatusItem("Slowest wake up", JoH.niceTimeScalar(max_wakeup_jitter) + " late", max_wakeup_jitter > 61000 ? StatusItem.Highlight.CRITICAL : StatusItem.Highlight.NORMAL)); } if (JoH.buggy_samsung) { - l.add(new StatusItem("Buggy Samsung", "Using workaround", max_wakeup_jitter < TOLERABLE_JITTER ? StatusItem.Highlight.GOOD : StatusItem.Highlight.BAD)); + l.add(new StatusItem("Buggy handset", "Using workaround", max_wakeup_jitter < TOLERABLE_JITTER ? StatusItem.Highlight.GOOD : StatusItem.Highlight.BAD)); } if (retry_time > 0) l.add(new StatusItem("Next Retry", JoH.niceTimeTill(retry_time), JoH.msTill(retry_time) < -2 ? StatusItem.Highlight.CRITICAL : StatusItem.Highlight.NORMAL)); @@ -1165,10 +1165,13 @@ public void onCreate() { android.bluetooth.BluetoothDevice.class, android.bluetooth.BluetoothGattService.class ); - final IntentFilter pairingRequestFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST); pairingRequestFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1); - registerReceiver(mPairingRequestRecevier, pairingRequestFilter); + if (Build.VERSION.SDK_INT < 26) { + registerReceiver(mPairingRequestRecevier, pairingRequestFilter); + } else { + Log.d(TAG, "Not starting pairing request receiver on android 8+"); + } Log.i(TAG, "onCreate: STARTING SERVICE: pin code: " + DEFAULT_BT_PIN); Blukon.unBondIfBlukonAtInit(); @@ -1187,7 +1190,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { } JoH.persistentBuggySamsungCheck(); if ((wakeup_jitter > TOLERABLE_JITTER) && (!JoH.buggy_samsung) && (JoH.isSamsung())) { - UserError.Log.wtf(TAG, "Enabled Buggy Samsung workaround due to jitter of: " + JoH.niceTimeScalar(wakeup_jitter)); + UserError.Log.wtf(TAG, "Enabled wake workaround due to jitter of: " + JoH.niceTimeScalar(wakeup_jitter)); JoH.setBuggySamsungEnabled(); max_wakeup_jitter = 0; } else { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/DexShareCollectionService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/DexShareCollectionService.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/DexShareCollectionService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/DexShareCollectionService.java index e143a46a56..5e542e573f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/DexShareCollectionService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/DexShareCollectionService.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.annotation.TargetApi; import android.app.AlarmManager; @@ -24,20 +24,20 @@ import android.preference.PreferenceManager; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.ReadDataShare; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.CalRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.EGVRecord; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.SensorRecord; -import com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.DexShareAttributes; -import com.eveningoutpost.dexdrip.UtilityModels.ForegroundServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.HM10Attributes; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.ReadDataShare; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.CalRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.EGVRecord; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.records.SensorRecord; +import com.eveningoutpost.dexdrip.models.ActiveBluetoothDevice; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.DexShareAttributes; +import com.eveningoutpost.dexdrip.utilitymodels.ForegroundServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.HM10Attributes; import java.nio.charset.StandardCharsets; import java.util.Calendar; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/DoNothingService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/DoNothingService.java similarity index 73% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/DoNothingService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/DoNothingService.java index 06bc498f4a..0ec5789e67 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/DoNothingService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/DoNothingService.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.app.PendingIntent; import android.app.Service; @@ -6,37 +6,37 @@ import android.content.SharedPreferences; import android.os.Build; import android.os.IBinder; -import android.os.PowerManager; import android.preference.PreferenceManager; import android.text.SpannableString; import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.GcmListenerSvc; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.ForegroundServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.InstalledApps; -import com.eveningoutpost.dexdrip.UtilityModels.NanoStatus; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.ForegroundServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.InstalledApps; +import com.eveningoutpost.dexdrip.utilitymodels.NanoStatus; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; import com.eveningoutpost.dexdrip.ui.helpers.Span; import com.eveningoutpost.dexdrip.utils.framework.WakeLockTrampoline; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.xdrip; import java.util.ArrayList; -import java.util.Calendar; import java.util.List; import static com.eveningoutpost.dexdrip.GcmListenerSvc.lastMessageReceived; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.BAD; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.NOTICE; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.BAD; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.NOTICE; import static com.eveningoutpost.dexdrip.xdrip.gs; +import lombok.val; + public class DoNothingService extends Service { private final static String TAG = DoNothingService.class.getSimpleName(); private DoNothingService dexCollectionService; @@ -83,31 +83,32 @@ public void onCreate() { UserError.Log.i(TAG, "onCreate: STARTING SERVICE"); } - private static final long TOLERABLE_JITTER = 10000; + private static final long TOLERABLE_JITTER = 300000; @Override public int onStartCommand(Intent intent, int flags, int startId) { - final PowerManager.WakeLock wl = JoH.getWakeLock("donothing-follower", 60000); + val wl = JoH.getWakeLock("donothing-follower", 60000); lastState = "Trying to start " + JoH.hourMinuteString(); if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { + // TODO this block is never used due to min sdk stopSelf(); JoH.releaseWakeLock(wl); return START_NOT_STICKY; } - JoH.persistentBuggySamsungCheck(); + //JoH.persistentBuggySamsungCheck(); if (nextWakeUpTime > 0) { - wake_time_difference = Calendar.getInstance().getTimeInMillis() - nextWakeUpTime; + wake_time_difference = JoH.tsl() - nextWakeUpTime; if (wake_time_difference > TOLERABLE_JITTER) { UserError.Log.e(TAG, "Slow Wake up! time difference in ms: " + wake_time_difference); wakeUpErrors = wakeUpErrors + 3; max_wake_time_difference = Math.max(max_wake_time_difference, wake_time_difference); - if (!JoH.buggy_samsung && JoH.isSamsung()) { - UserError.Log.wtf(TAG, "Enabled Buggy Samsung workaround due to jitter of: " + JoH.niceTimeScalar(wake_time_difference)); - JoH.setBuggySamsungEnabled(); - } + // if (!JoH.buggy_samsung && JoH.isSamsung()) { + // UserError.Log.wtf(TAG, "Enabled wake workaround due to jitter of: " + JoH.niceTimeScalar(wake_time_difference)); + // JoH.setBuggySamsungEnabled(); + // } } else { if (wakeUpErrors > 0) wakeUpErrors--; @@ -116,34 +117,32 @@ public int onStartCommand(Intent intent, int flags, int startId) { if (CollectionServiceStarter.isFollower(getApplicationContext()) || CollectionServiceStarter.isLibre2App(getApplicationContext())) { - new Thread(new Runnable() { - public void run() { - final int minsago = GcmListenerSvc.lastMessageMinutesAgo(); - //Log.d(TAG, "Tick: minutes ago: " + minsago); - int sleep_time = 1000; - - if ((minsago > 60) && (minsago < 70)) { - if (JoH.ratelimit("slow-service-restart", 60)) { - UserError.Log.e(TAG, "Restarting collection service + full wakeup due to minsago: " + minsago + " !!!"); - Home.startHomeWithExtra(getApplicationContext(), Home.HOME_FULL_WAKEUP, "1"); - CollectionServiceStarter.restartCollectionService(getApplicationContext()); - } - } - - if (minsago > 6) { - if (Home.get_follower()) GcmActivity.requestPing(); - sleep_time = (minsago < 60) ? ((minsago / 6) * 1000) : 1000; // increase sleep time up to 10s for first hour or revert + new Thread(() -> { + final int minsago = GcmListenerSvc.lastMessageMinutesAgo(); + //Log.d(TAG, "Tick: minutes ago: " + minsago); + int sleep_time = 1000; + + if ((minsago > 60) && (minsago < 80)) { + if (JoH.ratelimit("slow-service-restart", 60)) { + UserError.Log.e(TAG, "Restarting collection service + full wakeup due to minsago: " + minsago + " !!!"); + Home.startHomeWithExtra(getApplicationContext(), Home.HOME_FULL_WAKEUP, "1"); + CollectionServiceStarter.restartCollectionService(getApplicationContext()); } + } - try { - Thread.sleep(sleep_time); - } catch (InterruptedException e) { - // - } + if (minsago > 6) { + if (Home.get_follower()) GcmActivity.requestPing(); + sleep_time = (minsago < 60) ? ((minsago / 6) * 1000) : 1000; // increase sleep time up to 10s for first hour or revert + } - setFailOverTimer(); - JoH.releaseWakeLock(wl); + try { + Thread.sleep(sleep_time); + } catch (InterruptedException e) { + // } + + setFailOverTimer(); + JoH.releaseWakeLock(wl); }).start(); } else { stopSelf(); @@ -166,8 +165,8 @@ public void onDestroy() { private void setFailOverTimer() { if (Home.get_follower()) { - final long retry_in = (5 * 60 * 1000); - UserError.Log.d(TAG, "setFailoverTimer: Restarting in: " + (retry_in / (60 * 1000)) + " minutes"); + final long retry_in = Constants.MINUTE_IN_MS * 10; + UserError.Log.d(TAG, "setFailoverTimer: Restarting in: " + (retry_in / Constants.MINUTE_IN_MS) + " minutes"); nextWakeUpTime = JoH.tsl() + retry_in; //final PendingIntent wakeIntent = PendingIntent.getService(this, 0, new Intent(this, this.getClass()), 0); final PendingIntent wakeIntent = WakeLockTrampoline.getPendingIntent(this.getClass()); @@ -211,7 +210,7 @@ public static List megaStatus() { } if (JoH.buggy_samsung) { - l.add(new StatusItem("Buggy Samsung", "Using workaround", max_wake_time_difference < TOLERABLE_JITTER ? StatusItem.Highlight.GOOD : BAD)); + l.add(new StatusItem("Buggy handset", "Using workaround", max_wake_time_difference < TOLERABLE_JITTER ? StatusItem.Highlight.GOOD : BAD)); } if (nextWakeUpTime != -1) { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/G5BaseService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/G5BaseService.java similarity index 93% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/G5BaseService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/G5BaseService.java index 5205f074f5..dcb78d3a62 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/G5BaseService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/G5BaseService.java @@ -1,16 +1,16 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.app.Service; import android.bluetooth.BluetoothDevice; import android.content.SharedPreferences; import android.os.PowerManager; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.ForegroundServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.ForegroundServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.google.android.gms.wearable.DataMap; /** @@ -35,6 +35,7 @@ public abstract class G5BaseService extends Service { protected static final int G5_LOW_BATTERY_WARNING_DEFAULT = 300; protected static final int G6_LOW_BATTERY_WARNING_DEFAULT = 290; + public static final int ALT_LOW_BATTERY_WARNING_DEFAULT = 280; // updated by updateBatteryWarningLevel(), accessed by Ob1DexTransmitterBattery public static int LOW_BATTERY_WARNING_LEVEL = G5_LOW_BATTERY_WARNING_DEFAULT; @@ -111,7 +112,7 @@ public static void resetTransmitterBatteryStatus() { PersistentStore.commit(); } - protected static void updateBatteryWarningLevel() { + public static void updateBatteryWarningLevel() { LOW_BATTERY_WARNING_LEVEL = Pref.getStringToInt("g5-battery-warning-level", G5_LOW_BATTERY_WARNING_DEFAULT); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/G5CollectionService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/G5CollectionService.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/G5CollectionService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/G5CollectionService.java index f994c842cc..dfd2ee67f9 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/G5CollectionService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/G5CollectionService.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; /** * Created by jcostik1 on 3/15/16. @@ -34,40 +34,40 @@ import android.os.PowerManager; import android.preference.PreferenceManager; -import com.eveningoutpost.dexdrip.G5Model.AuthChallengeRxMessage; -import com.eveningoutpost.dexdrip.G5Model.AuthChallengeTxMessage; -import com.eveningoutpost.dexdrip.G5Model.AuthRequestTxMessage; -import com.eveningoutpost.dexdrip.G5Model.AuthStatusRxMessage; -import com.eveningoutpost.dexdrip.G5Model.BatteryInfoRxMessage; -import com.eveningoutpost.dexdrip.G5Model.BatteryInfoTxMessage; -import com.eveningoutpost.dexdrip.G5Model.BluetoothServices; -import com.eveningoutpost.dexdrip.G5Model.BondRequestTxMessage; -import com.eveningoutpost.dexdrip.G5Model.DisconnectTxMessage; -import com.eveningoutpost.dexdrip.G5Model.Extensions; -import com.eveningoutpost.dexdrip.G5Model.FirmwareCapability; -import com.eveningoutpost.dexdrip.G5Model.GlucoseRxMessage; -import com.eveningoutpost.dexdrip.G5Model.GlucoseTxMessage; -import com.eveningoutpost.dexdrip.G5Model.KeepAliveTxMessage; -import com.eveningoutpost.dexdrip.G5Model.SensorRxMessage; -import com.eveningoutpost.dexdrip.G5Model.SensorTxMessage; -import com.eveningoutpost.dexdrip.G5Model.Transmitter; -import com.eveningoutpost.dexdrip.G5Model.TransmitterStatus; -import com.eveningoutpost.dexdrip.G5Model.VersionRequestRxMessage; -import com.eveningoutpost.dexdrip.G5Model.VersionRequestTxMessage; +import com.eveningoutpost.dexdrip.g5model.AuthChallengeRxMessage; +import com.eveningoutpost.dexdrip.g5model.AuthChallengeTxMessage; +import com.eveningoutpost.dexdrip.g5model.AuthRequestTxMessage; +import com.eveningoutpost.dexdrip.g5model.AuthStatusRxMessage; +import com.eveningoutpost.dexdrip.g5model.BatteryInfoRxMessage; +import com.eveningoutpost.dexdrip.g5model.BatteryInfoTxMessage; +import com.eveningoutpost.dexdrip.g5model.BluetoothServices; +import com.eveningoutpost.dexdrip.g5model.BondRequestTxMessage; +import com.eveningoutpost.dexdrip.g5model.DisconnectTxMessage; +import com.eveningoutpost.dexdrip.g5model.Extensions; +import com.eveningoutpost.dexdrip.g5model.FirmwareCapability; +import com.eveningoutpost.dexdrip.g5model.GlucoseRxMessage; +import com.eveningoutpost.dexdrip.g5model.GlucoseTxMessage; +import com.eveningoutpost.dexdrip.g5model.KeepAliveTxMessage; +import com.eveningoutpost.dexdrip.g5model.SensorRxMessage; +import com.eveningoutpost.dexdrip.g5model.SensorTxMessage; +import com.eveningoutpost.dexdrip.g5model.Transmitter; +import com.eveningoutpost.dexdrip.g5model.TransmitterStatus; +import com.eveningoutpost.dexdrip.g5model.VersionRequestRxMessage; +import com.eveningoutpost.dexdrip.g5model.VersionRequestTxMessage; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.TransmitterData; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.TransmitterData; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.NotificationChannels; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.NotificationChannels; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; import com.eveningoutpost.dexdrip.utils.PowerStateReceiver; import com.eveningoutpost.dexdrip.utils.bt.Helper; import com.eveningoutpost.dexdrip.xdrip; @@ -94,7 +94,7 @@ import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.SecretKeySpec; -import static com.eveningoutpost.dexdrip.G5Model.BluetoothServices.getUUIDName; +import static com.eveningoutpost.dexdrip.g5model.BluetoothServices.getUUIDName; import static com.eveningoutpost.dexdrip.utils.bt.Helper.getStatusName; import static com.eveningoutpost.dexdrip.xdrip.gs; @@ -208,7 +208,11 @@ public void onCreate() { final IntentFilter pairingRequestFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST); pairingRequestFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1); - registerReceiver(mPairingRequestRecevier, pairingRequestFilter); + if (Build.VERSION.SDK_INT < 26) { + registerReceiver(mPairingRequestRecevier, pairingRequestFilter); + } else { + UserError.Log.d(TAG, "Not registering pairing receiver on Android 8+"); + } } final BroadcastReceiver mPairReceiver = new BroadcastReceiver() { @@ -1960,7 +1964,9 @@ public void run() { l.add(new StatusItem("Transmitter Days", bt.runtime + ((last_transmitter_timestamp > 0) ? " / " + JoH.qs((double) last_transmitter_timestamp / 86400, 1) : ""))); l.add(new StatusItem("Voltage A", bt.voltagea, bt.voltagea < LOW_BATTERY_WARNING_LEVEL ? StatusItem.Highlight.BAD : StatusItem.Highlight.NORMAL)); l.add(new StatusItem("Voltage B", bt.voltageb, bt.voltageb < (LOW_BATTERY_WARNING_LEVEL - 10) ? StatusItem.Highlight.BAD : StatusItem.Highlight.NORMAL)); - l.add(new StatusItem("Resistance", bt.resist, bt.resist > 1400 ? StatusItem.Highlight.BAD : (bt.resist > 1000 ? StatusItem.Highlight.NOTICE : (bt.resist > 750 ? StatusItem.Highlight.NORMAL : StatusItem.Highlight.GOOD)))); + if (bt.resist != 0) { + l.add(new StatusItem("Resistance", bt.resist, bt.resist > 1400 ? StatusItem.Highlight.BAD : (bt.resist > 1000 ? StatusItem.Highlight.NOTICE : (bt.resist > 750 ? StatusItem.Highlight.NORMAL : StatusItem.Highlight.GOOD)))); + } l.add(new StatusItem("Temperature", bt.temperature + " \u2103")); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/JamBaseBluetoothSequencer.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/JamBaseBluetoothSequencer.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/JamBaseBluetoothSequencer.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/JamBaseBluetoothSequencer.java index 12b9a95b08..794d543431 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/JamBaseBluetoothSequencer.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/JamBaseBluetoothSequencer.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.annotation.SuppressLint; import android.app.PendingIntent; @@ -12,15 +12,15 @@ import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; -import android.support.v4.content.ContextCompat; +import androidx.core.content.ContextCompat; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.RxBleProvider; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.RxBleProvider; import com.eveningoutpost.dexdrip.utils.BtCallBack; import com.eveningoutpost.dexdrip.utils.BytesGenerator; import com.eveningoutpost.dexdrip.utils.DisconnectReceiver; @@ -57,14 +57,14 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.CLOSE; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.CLOSED; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.CONNECT_NOW; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.DISCOVER; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.INIT; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.SEND_QUEUE; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.SLEEP; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.CLOSE; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.CLOSED; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.CONNECT_NOW; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.DISCOVER; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.INIT; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.SEND_QUEUE; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.SLEEP; import static com.eveningoutpost.dexdrip.utils.bt.ScanMeister.SCAN_FOUND_CALLBACK; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/JamBaseBluetoothService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/JamBaseBluetoothService.java similarity index 92% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/JamBaseBluetoothService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/JamBaseBluetoothService.java index 312a5a9d6d..2e99d9cb3f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/JamBaseBluetoothService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/JamBaseBluetoothService.java @@ -1,18 +1,18 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.app.Service; import android.bluetooth.BluetoothGatt; import android.content.Intent; import android.os.IBinder; import android.os.PowerManager; -import android.support.annotation.NonNull; - -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.ForegroundServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import androidx.annotation.NonNull; + +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.ForegroundServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.bt.HandleBleScanException; import com.polidea.rxandroidble2.RxBleConnection; import com.polidea.rxandroidble2.RxBleCustomOperation; @@ -178,7 +178,7 @@ protected static byte[] nn(final byte[] array) { protected static void enableBuggySamsungIfNeeded(final String TAG) { if ((JoH.isSamsung() && PersistentStore.getLong(BUGGY_SAMSUNG_ENABLED) > 4)) { - UserError.Log.d(TAG, "Enabling buggy samsung due to persistent metric"); + UserError.Log.d(TAG, "Enabling wake workaround due to persistent metric"); JoH.buggy_samsung = true; } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/LibreWifiData.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/LibreWifiData.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/LibreWifiData.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/LibreWifiData.java index e9f312f064..2d34dc37dc 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/LibreWifiData.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/LibreWifiData.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import java.util.Arrays; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/LibreWifiReader.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/LibreWifiReader.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/LibreWifiReader.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/LibreWifiReader.java index b73bfbcf89..244ad5ce07 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/LibreWifiReader.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/LibreWifiReader.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.content.Context; import android.os.AsyncTask; @@ -10,20 +10,20 @@ import okhttp3.Response; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice; -import com.eveningoutpost.dexdrip.Models.LibreBluetooth; +import com.eveningoutpost.dexdrip.models.ActiveBluetoothDevice; +import com.eveningoutpost.dexdrip.models.LibreBluetooth; import com.eveningoutpost.dexdrip.NFCReaderX; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.LibreBlock; -import com.eveningoutpost.dexdrip.Models.SensorSanity; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.desertsync.RouteTools; -import com.eveningoutpost.dexdrip.UtilityModels.MockDataSource; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.LibreBlock; +import com.eveningoutpost.dexdrip.models.SensorSanity; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.desertsync.RouteTools; +import com.eveningoutpost.dexdrip.utilitymodels.MockDataSource; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.utils.Mdns; import com.google.gson.Gson; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/MissedReadingService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/MissedReadingService.java similarity index 88% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/MissedReadingService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/MissedReadingService.java index 22e1548709..b6ee1d0178 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/MissedReadingService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/MissedReadingService.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.app.IntentService; import android.app.PendingIntent; @@ -9,28 +9,29 @@ import android.preference.PreferenceManager; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.AlertType; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.DesertSync; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Reminder; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.Models.UserNotification; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.NanoStatus; -import com.eveningoutpost.dexdrip.UtilityModels.Notifications; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.pebble.PebbleUtil; -import com.eveningoutpost.dexdrip.UtilityModels.pebble.PebbleWatchSync; +import com.eveningoutpost.dexdrip.models.AlertType; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.DesertSync; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Reminder; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserNotification; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.NanoStatus; +import com.eveningoutpost.dexdrip.utilitymodels.Notifications; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.pebble.PebbleUtil; +import com.eveningoutpost.dexdrip.utilitymodels.pebble.PebbleWatchSync; +import com.eveningoutpost.dexdrip.healthconnect.HealthConnectEntry; import com.eveningoutpost.dexdrip.insulin.inpen.InPenEntry; import com.eveningoutpost.dexdrip.ui.LockScreenWallPaper; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.watch.lefun.LeFun; import com.eveningoutpost.dexdrip.watch.lefun.LeFunEntry; -import com.eveningoutpost.dexdrip.Services.broadcastservice.BroadcastEntry; +import com.eveningoutpost.dexdrip.services.broadcastservice.BroadcastEntry; import com.eveningoutpost.dexdrip.wearintegration.WatchUpdaterService; import com.eveningoutpost.dexdrip.webservices.XdripWebService; import com.eveningoutpost.dexdrip.xdrip; @@ -100,6 +101,7 @@ protected void onHandleIntent(Intent intent) { DesertSync.pullAsEnabled(); NanoStatus.keepFollowerUpdated(); LockScreenWallPaper.timerPoll(); + HealthConnectEntry.ping(); // TODO functionalize the actual checking bg_missed_alerts = Pref.getBoolean("bg_missed_alerts", false); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/MongoWrapper.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/MongoWrapper.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/MongoWrapper.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/MongoWrapper.java index b8ae28bd59..b098d75b91 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/MongoWrapper.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/MongoWrapper.java @@ -1,5 +1,5 @@ -package com.eveningoutpost.dexdrip.Services; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +package com.eveningoutpost.dexdrip.services; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.mongodb.BasicDBObject; import com.mongodb.DB; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/Ob1G5CollectionService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/Ob1G5CollectionService.java similarity index 79% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/Ob1G5CollectionService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/Ob1G5CollectionService.java index a6f47a3f7d..70a6702cd9 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/Ob1G5CollectionService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/Ob1G5CollectionService.java @@ -1,42 +1,59 @@ -package com.eveningoutpost.dexdrip.Services; - -import static com.eveningoutpost.dexdrip.G5Model.BluetoothServices.getUUIDName; -import static com.eveningoutpost.dexdrip.G5Model.CalibrationState.Ok; -import static com.eveningoutpost.dexdrip.G5Model.CalibrationState.Unknown; -import static com.eveningoutpost.dexdrip.G5Model.G6CalibrationParameters.getCurrentSensorCode; -import static com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine.CLOSED_OK_TEXT; -import static com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine.evaluateG6Settings; -import static com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine.pendingCalibration; -import static com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine.pendingStart; -import static com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine.pendingStop; -import static com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine.usingAlt; -import static com.eveningoutpost.dexdrip.Models.JoH.niceTimeScalar; -import static com.eveningoutpost.dexdrip.Models.JoH.tsl; -import static com.eveningoutpost.dexdrip.Models.JoH.upForAtLeastMins; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.STATE.BOND; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.STATE.CLOSE; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.STATE.CLOSED; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.STATE.CONNECT; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.STATE.CONNECT_NOW; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.STATE.DISCOVER; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.STATE.GET_DATA; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.STATE.INIT; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.STATE.PREBOND; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.STATE.SCAN; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.DAY_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.G5_CALIBRATION_REQUEST; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.G5_SENSOR_FAILED; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.G5_SENSOR_RESTARTED; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.G5_SENSOR_STARTED; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.HOUR_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.SECOND_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.BAD; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.CRITICAL; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.NORMAL; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.NOTICE; +package com.eveningoutpost.dexdrip.services; + +import static com.eveningoutpost.dexdrip.Home.get_engineering_mode; +import static com.eveningoutpost.dexdrip.g5model.BluetoothServices.Advertisement; +import static com.eveningoutpost.dexdrip.g5model.BluetoothServices.ExtraData; +import static com.eveningoutpost.dexdrip.g5model.BluetoothServices.Mask16; +import static com.eveningoutpost.dexdrip.g5model.BluetoothServices.getUUIDName; +import static com.eveningoutpost.dexdrip.g5model.CalibrationState.Ok; +import static com.eveningoutpost.dexdrip.g5model.CalibrationState.Unknown; +import static com.eveningoutpost.dexdrip.g5model.G6CalibrationParameters.getCurrentSensorCode; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.CLOSED_OK_TEXT; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.doKeepAlive; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.evaluateG6Settings; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.pendingCalibration; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.pendingStart; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.pendingStop; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.shortTxId; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.usingAlt; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.joinBytes; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.niceTimeScalar; +import static com.eveningoutpost.dexdrip.models.JoH.tolerantHexStringToByteArray; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; +import static com.eveningoutpost.dexdrip.models.JoH.upForAtLeastMins; +import static com.eveningoutpost.dexdrip.plugin.Dialog.txIdMatch; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.STATE.BOND; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.STATE.CLOSE; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.STATE.CLOSED; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.STATE.CONNECT; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.STATE.CONNECT_NOW; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.STATE.DISCOVER; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.STATE.GET_DATA; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.STATE.INIT; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.STATE.PREBOND; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.STATE.SCAN; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.DAY_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.G5_CALIBRATION_REQUEST; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.G5_SENSOR_FAILED; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.G5_SENSOR_RESTARTED; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.G5_SENSOR_STARTED; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.HOUR_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.SECOND_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.BAD; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.CRITICAL; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.NORMAL; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.NOTICE; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.DexcomG5; import static com.eveningoutpost.dexdrip.utils.bt.Subscription.addErrorHandler; +import static com.eveningoutpost.dexdrip.watch.thinjam.BlueJayEntry.isNative; import static com.eveningoutpost.dexdrip.xdrip.gs; +import static com.polidea.rxandroidble2.scan.ScanSettings.CALLBACK_TYPE_ALL_MATCHES; +import static com.polidea.rxandroidble2.scan.ScanSettings.CALLBACK_TYPE_FIRST_MATCH; +import static com.polidea.rxandroidble2.scan.ScanSettings.SCAN_MODE_BALANCED; +import static com.polidea.rxandroidble2.scan.ScanSettings.SCAN_MODE_LOW_LATENCY; import android.annotation.TargetApi; import android.app.PendingIntent; @@ -53,46 +70,52 @@ import android.media.AudioManager; import android.os.Build; import android.os.IBinder; +import android.os.ParcelUuid; import android.os.PowerManager; import android.preference.PreferenceManager; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; + import android.text.SpannableString; import android.text.SpannableStringBuilder; import com.eveningoutpost.dexdrip.AddCalibration; import com.eveningoutpost.dexdrip.DoubleCalibrationActivity; -import com.eveningoutpost.dexdrip.G5Model.BatteryInfoRxMessage; -import com.eveningoutpost.dexdrip.G5Model.BluetoothServices; -import com.eveningoutpost.dexdrip.G5Model.CalibrationState; -import com.eveningoutpost.dexdrip.G5Model.DexSyncKeeper; -import com.eveningoutpost.dexdrip.G5Model.DexTimeKeeper; -import com.eveningoutpost.dexdrip.G5Model.FirmwareCapability; -import com.eveningoutpost.dexdrip.G5Model.Ob1DexTransmitterBattery; -import com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine; -import com.eveningoutpost.dexdrip.G5Model.TransmitterStatus; -import com.eveningoutpost.dexdrip.G5Model.VersionRequest1RxMessage; -import com.eveningoutpost.dexdrip.G5Model.VersionRequest2RxMessage; -import com.eveningoutpost.dexdrip.G5Model.VersionRequestRxMessage; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.BroadcastGlucose; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.RxBleProvider; -import com.eveningoutpost.dexdrip.UtilityModels.SendFeedBack; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight; -import com.eveningoutpost.dexdrip.UtilityModels.UpdateActivity; -import com.eveningoutpost.dexdrip.UtilityModels.WholeHouse; +import com.eveningoutpost.dexdrip.g5model.BatteryInfoRxMessage; +import com.eveningoutpost.dexdrip.g5model.BluetoothServices; +import com.eveningoutpost.dexdrip.g5model.CalibrationState; +import com.eveningoutpost.dexdrip.g5model.DexSyncKeeper; +import com.eveningoutpost.dexdrip.g5model.DexTimeKeeper; +import com.eveningoutpost.dexdrip.g5model.FirmwareCapability; +import com.eveningoutpost.dexdrip.g5model.Ob1DexTransmitterBattery; +import com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine; +import com.eveningoutpost.dexdrip.g5model.TransmitterStatus; +import com.eveningoutpost.dexdrip.g5model.VersionRequest1RxMessage; +import com.eveningoutpost.dexdrip.g5model.VersionRequest2RxMessage; +import com.eveningoutpost.dexdrip.g5model.VersionRequestRxMessage; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.plugin.IPluginDA; +import com.eveningoutpost.dexdrip.plugin.Loader; +import com.eveningoutpost.dexdrip.plugin.Registry; import com.eveningoutpost.dexdrip.ui.helpers.Span; +import com.eveningoutpost.dexdrip.utilitymodels.BroadcastGlucose; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.RxBleProvider; +import com.eveningoutpost.dexdrip.utilitymodels.SendFeedBack; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight; +import com.eveningoutpost.dexdrip.utilitymodels.UpdateActivity; +import com.eveningoutpost.dexdrip.utilitymodels.WholeHouse; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.utils.bt.Subscription; import com.eveningoutpost.dexdrip.utils.framework.WakeLockTrampoline; @@ -116,6 +139,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Set; @@ -147,6 +171,8 @@ public class Ob1G5CollectionService extends G5BaseService { private static final int DEFAULT_AUTOMATA_DELAY = 100; private static final String BUGGY_SAMSUNG_ENABLED = "buggy-samsung-enabled"; private static final String STOP_SCAN_TASK_ID = "ob1-g5-scan-timeout_scan"; + private static final String KEKS = "keks"; + private static final String KEKS_ONE = "keks1_"; private static volatile STATE state = INIT; private static volatile STATE last_automata_state = CLOSED; @@ -164,7 +190,7 @@ public class Ob1G5CollectionService extends G5BaseService { public static volatile CalibrationState lastSensorState = null; public static volatile long lastUsableGlucosePacketTime = 0; private static volatile String static_connection_state = null; - private static volatile long static_last_connected = 0; + public static volatile long static_last_connected = 0; @Setter @Getter private static long last_transmitter_timestamp = 0; @@ -186,6 +212,7 @@ public class Ob1G5CollectionService extends G5BaseService { private Subscription discoverSubscription; private RxBleDevice bleDevice; private RxBleConnection connection; + public volatile IPluginDA plugin; private PowerManager.WakeLock connection_linger; private volatile PowerManager.WakeLock scanWakeLock; @@ -211,7 +238,8 @@ public class Ob1G5CollectionService extends G5BaseService { private static volatile int skippedConnects = 0; private static final boolean d = false; - private static boolean use_auto_connect = false; + private static volatile boolean allow_scan_by_mac = false; + private static volatile boolean use_auto_connect = false; private static volatile boolean minimize_scanning = false; // set by preference private static volatile boolean always_scan = false; private static volatile boolean scan_next_run = true; @@ -225,6 +253,7 @@ public class Ob1G5CollectionService extends G5BaseService { private static final List alwaysScanModelFamilies = Arrays.asList("SM-N910"); private static final Set alwaysConnectModels = Sets.newHashSet("G Watch"); private static final Set alwaysBuggyWakeupModels = Sets.newHashSet("Jelly-Pro", "SmartWatch 3"); + private static final HashMap failureTally = new HashMap<>(); // Internal process state tracking public enum STATE { @@ -286,10 +315,15 @@ public synchronized void background_automata(final int timeout) { }).start(); } - private boolean specialPairingWorkaround() { + private static boolean specialPairingWorkaround() { return Pref.getBooleanDefaultFalse("ob1_special_pairing_workaround"); } + private static boolean getTrustAutoConnect() { + return Pref.getBoolean("bluetooth_trust_autoconnect", true); + } + + private synchronized void automata() { if ((last_automata_state != state) || state == INIT || (JoH.ratelimit("jam-g5-dupe-auto", 2))) { @@ -303,7 +337,7 @@ private synchronized void automata() { break; case SCAN: // no connection? lets try a restart - if (JoH.msSince(static_last_connected) > 30 * 60 * 1000) { + if (msSince(static_last_connected) > 30 * 60 * 1000) { if (JoH.pratelimit("ob1-collector-restart", 1200)) { CollectionServiceStarter.restartCollectionServiceBackground(); break; @@ -333,7 +367,7 @@ private synchronized void automata() { } else { wasBonded = locallyBonded ? getTransmitterID() : ""; skippedConnects = 0; - connect_to_device(specialPairingWorkaround()); + connect_to_device(specialPairingWorkaround() && getTrustAutoConnect()); } } else { connect_to_device(false); @@ -343,7 +377,7 @@ private synchronized void automata() { connect_to_device(true); break; case DISCOVER: - if ((wear_broadcast && usingAlt()) || specialPairingWorkaround()){ + if ((wear_broadcast && usingAlt()) || specialPairingWorkaround()) { msg("Pausing"); UserError.Log.d(TAG, "Pausing for alt: "); JoH.threadSleep(1000); @@ -358,7 +392,15 @@ private synchronized void automata() { case CHECK_AUTH: if (do_auth) { final PowerManager.WakeLock linger_wl_connect = JoH.getWakeLock("jam-g5-check-linger", 6000); - if (!Ob1G5StateMachine.doCheckAuth(this, connection)) resetState(); + if (plugin != null) { + if (!Ob1G5StateMachine.doCheckAuth2(this, connection)) { + resetState(); + } + } else { + if (!Ob1G5StateMachine.doCheckAuth(this, connection)) { + resetState(); + } + } } else { UserError.Log.d(TAG, "Skipping authentication"); changeState(GET_DATA); @@ -383,8 +425,9 @@ private synchronized void automata() { create_bond(); break; case UNBOND: - UserError.Log.d(TAG, "Unbond state - not yet implemented"); - //Ob1G5StateMachine.doUnBond(this, connection); + UserError.Log.d(TAG, "Unbond state"); + Ob1G5StateMachine.doUnBond(this, connection); + Inevitable.task("unbond close", 10000, () -> changeState(Ob1G5CollectionService.STATE.CLOSE)); break; case RESET: @@ -446,7 +489,7 @@ private boolean useMinimizeScanningStrategy() { private void estimateAnticipateFromLinkedData() { final BgReading bg = BgReading.last(); - if (bg != null && bg.timestamp > static_last_connected && JoH.msSince(bg.timestamp) < HOUR_IN_MS * 3) { + if (bg != null && bg.timestamp > static_last_connected && msSince(bg.timestamp) < HOUR_IN_MS * 3) { final long ts = bg.timestamp - Constants.SECOND_IN_MS; UserError.Log.d(TAG, "Updating Sync Keeper with network learned timestamp: " + JoH.dateTimeText(ts)); DexSyncKeeper.store(transmitterID, ts); @@ -463,7 +506,12 @@ public STATE getState() { } public void changeState(STATE new_state) { - changeState(new_state, DEFAULT_AUTOMATA_DELAY); + if (shouldServiceRun()) { + changeState(new_state, DEFAULT_AUTOMATA_DELAY); + } else { + UserError.Log.d(TAG, "Stopping service due to having being disabled in preferences"); + stopSelf(); + } } public void changeState(STATE new_state, int timeout) { @@ -496,35 +544,45 @@ private synchronized void initialize() { } private static void init_tx_id() { - transmitterID = Pref.getString("dex_txid", "NULL"); + val TXID_PREF = "dex_txid"; + val txid = Pref.getString(TXID_PREF, "NULL"); + val txid_filtered = txid.trim(); + transmitterID = txid_filtered; + if (!txid.equals(txid_filtered)) { + Pref.setString(TXID_PREF, txid_filtered); + UserError.Log.wtf(TAG, "Had to fix invalid txid: :" + txid + ": -> :" + txid_filtered + ":"); + } } + private volatile boolean lastWasScanByMac = false; + private synchronized void scan_for_device() { if (state == SCAN) { msg(gs(R.string.scanning)); stopScan(); tryLoadingSavedMAC(); // did we already find it? + expireFailures(false); if (always_scan || scan_next_run || (transmitterMAC == null) || (!transmitterID.equals(transmitterIDmatchingMAC)) || (static_last_timestamp < 1)) { scan_next_run = false; // reset if set transmitterMAC = null; // reset if set last_scan_started = tsl(); - scanWakeLock = JoH.getWakeLock("xdrip-jam-g5-scan", (int) Constants.MINUTE_IN_MS * 7); + scanWakeLock = JoH.getWakeLock("xdrip-jam-g5-scan", (int) MINUTE_IN_MS * 7); historicalTransmitterMAC = PersistentStore.getString(OB1G5_MACSTORE + transmitterID); // "" if unset + boolean macFilter = false; ScanFilter filter; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && historicalTransmitterMAC.length() > 5 - && Build.VERSION.SDK_INT < 29) { - filter = new ScanFilter.Builder() - .setDeviceAddress(historicalTransmitterMAC) - .build(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && historicalTransmitterMAC.length() > 5 && allow_scan_by_mac) { + filter = new ScanFilter.Builder().setDeviceAddress(historicalTransmitterMAC).build(); + UserError.Log.d(TAG, "Using mac filter " + historicalTransmitterMAC); + macFilter = true; } else { final String localTransmitterID = transmitterID; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && localTransmitterID != null && localTransmitterID.length() > 4) { filter = new ScanFilter.Builder().setDeviceName(getTransmitterBluetoothName()).build(); } else { - filter = new ScanFilter.Builder().build(); + filter = new ScanFilter.Builder().setServiceUuid(new ParcelUuid(Advertisement), new ParcelUuid(Mask16)).build(); } } @@ -534,20 +592,21 @@ private synchronized void scan_for_device() { lastScanError = null; } + lastWasScanByMac = macFilter; scanSubscription = new Subscription(rxBleClient.scanBleDevices( - new ScanSettings.Builder() - //.setScanMode(static_last_timestamp < 1 ? ScanSettings.SCAN_MODE_LOW_LATENCY : ScanSettings.SCAN_MODE_BALANCED) - //.setCallbackType(ScanSettings.CALLBACK_TYPE_FIRST_MATCH) - .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) - .setScanMode(android_wear ? ScanSettings.SCAN_MODE_BALANCED : - historicalTransmitterMAC.length() <= 5 ? ScanSettings.SCAN_MODE_LOW_LATENCY : - minimize_scanning ? ScanSettings.SCAN_MODE_BALANCED : ScanSettings.SCAN_MODE_LOW_LATENCY) - // .setScanMode(ScanSettings.SCAN_MODE_BALANCED) - .build(), - - // scan filter doesn't work reliable on android sdk 23+ - filter - ) + new ScanSettings.Builder() + //.setScanMode(static_last_timestamp < 1 ? ScanSettings.SCAN_MODE_LOW_LATENCY : ScanSettings.SCAN_MODE_BALANCED) + //.setCallbackType(ScanSettings.CALLBACK_TYPE_FIRST_MATCH) + .setCallbackType(macFilter ? CALLBACK_TYPE_FIRST_MATCH : CALLBACK_TYPE_ALL_MATCHES) + .setScanMode(android_wear ? SCAN_MODE_BALANCED : + historicalTransmitterMAC.length() <= 5 ? SCAN_MODE_LOW_LATENCY : + minimize_scanning ? SCAN_MODE_BALANCED : SCAN_MODE_LOW_LATENCY) + // .setScanMode(ScanSettings.SCAN_MODE_BALANCED) + .build(), + + // scan filter doesn't work reliable on android sdk 23+ + filter + ) // observe on? // do unsubscribe? //.doOnUnsubscribe(this::clearSubscription) @@ -668,6 +727,7 @@ private synchronized void create_bond() { try { msg("Bonding"); do_create_bond(); + DexSyncKeeper.clear(getTransmitterID()); //state = STATE.CONNECT_NOW; //background_automata(15000); } catch (Exception e) { @@ -696,13 +756,12 @@ private synchronized void do_create_bond() { unbondIfAllowed(); changeState(CLOSE); } else { - try { - Ob1G5StateMachine.doKeepAlive(this, connection, () -> { - weInitiatedBondConfirmation = 1; - instantCreateBondIfAllowed(); - }); - + if (transmitterID.length() > 4) { + doKeepAlive(this, connection, this::startInitiateBondReal); + } else { + startInitiateBondReal(); + } //background_automata(10000); } catch (Exception e) { UserError.Log.wtf(TAG, "Got exception in do_create_bond() " + e); @@ -710,6 +769,15 @@ private synchronized void do_create_bond() { } } + private void startInitiateBondReal() { + try { + weInitiatedBondConfirmation = 1; + instantCreateBondIfAllowed(); + } catch (Exception e) { + UserError.Log.wtf(TAG, "Got exception in startInitiateBondReal() " + e); + } + } + private synchronized void send_reset_command() { hardResetTransmitterNow = false; getBatteryStatusNow = true; @@ -722,6 +790,7 @@ private synchronized void send_reset_command() { } private String getTransmitterBluetoothName() { + if (transmitterID == null || transmitterID.length() <= 4) return null; final String transmitterIdLastTwo = getLastTwoCharacters(transmitterID); // todo check for bad config return "Dexcom" + transmitterIdLastTwo; @@ -752,7 +821,6 @@ private void tryLoadingSavedMAC() { // should this service be running? Used to decide when to shut down private static boolean shouldServiceRun() { - if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return false; if (!Pref.getBooleanDefaultFalse(OB1G5_PREFS)) return false; if (!(DexCollectionType.getDexCollectionType() == DexcomG5)) return false; @@ -794,6 +862,27 @@ public static synchronized boolean isDeviceLocallyBonded() { return false; } + public static boolean immediateBonding() { + return Pref.getBooleanDefaultFalse("engineering_ob1_bonding_test") || isNative(); + } + + public static boolean ignoreBonding() { + return Pref.getBooleanDefaultFalse("engineering_ob1_ignore_bonding"); + } + + private byte[] fwChalCache(boolean prefix) { + final long chal = Pref.getLong("engineering_ob1_chal_cache" + (prefix ? "_1" : ""), 0); + if (chal != 0 && shortTxId()) { + final byte[] bytes = new byte[8]; + for (int i = 0; i < 8; i++) { + bytes[i] = (byte) (chal >> (8 - i - 1) * 8); + } + return bytes; + } else { + return new byte[0]; + } + } + private synchronized void checkAndEnableBT() { try { if (Pref.getBoolean("automatically_turn_bluetooth_on", true)) { @@ -891,6 +980,27 @@ private synchronized void prepareToWakeup() { stopConnect(); } + if (plugin != null) { + UserError.Log.d(TAG, "Saving persistent data for keks"); + savePersist(); + } + + } + + public synchronized void savePersist() { + if (plugin != null) { + PersistentStore.cleanupOld(KEKS_ONE); + PersistentStore.setBytes(KEKS_ONE + transmitterMAC, plugin.getPersistence(1)); + } + } + + public static void clearPersistStore() { + PersistentStore.removeItem(KEKS_ONE + transmitterMAC); + } + + public static void clearPersist() { + clearPersistStore(); + expireFailures(true); } private void scheduleWakeUp(long future, final String info) { @@ -928,7 +1038,7 @@ private void checkAlwaysScanModels() { UserError.Log.d(TAG, "Checking model: " + this_model); if ((JoH.isSamsung() && PersistentStore.getLong(BUGGY_SAMSUNG_ENABLED) > 4)) { - UserError.Log.d(TAG, "Enabling buggy samsung due to persistent metric"); + UserError.Log.d(TAG, "Enabling wake workaround due to persistent metric"); JoH.buggy_samsung = true; } @@ -1004,14 +1114,14 @@ public int onStartCommand(Intent intent, int flags, int startId) { UserError.Log.d(TAG, "WAKE UP WAKE UP WAKE UP WAKE UP @ " + JoH.dateTimeText(tsl())); msg("Wake up"); if (wakeup_time > 0) { - wakeup_jitter = JoH.msSince(wakeup_time); + wakeup_jitter = msSince(wakeup_time); if (wakeup_jitter < 0) { UserError.Log.d(TAG, "Woke up Early.."); } else { if (wakeup_jitter > 1000) { UserError.Log.d(TAG, "Wake up, time jitter: " + niceTimeScalar(wakeup_jitter)); if ((wakeup_jitter > TOLERABLE_JITTER) && (!JoH.buggy_samsung) && JoH.isSamsung()) { - UserError.Log.wtf(TAG, "Enabled Buggy Samsung workaround due to jitter of: " + niceTimeScalar(wakeup_jitter)); + UserError.Log.wtf(TAG, "Enabled wake workaround due to jitter of: " + niceTimeScalar(wakeup_jitter)); JoH.buggy_samsung = true; PersistentStore.incrementLong(BUGGY_SAMSUNG_ENABLED); max_wakeup_jitter = 0; @@ -1030,7 +1140,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { } - scheduleWakeUp(Constants.MINUTE_IN_MS * 6, "fail-over"); + scheduleWakeUp(MINUTE_IN_MS * 6, "fail-over"); if ((state == BOND) || (state == PREBOND) || (state == DISCOVER) || (state == CONNECT)) state = SCAN; @@ -1043,7 +1153,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { } minimize_scanning = Pref.getBooleanDefaultFalse("ob1_minimize_scanning"); - + // allow_scan_by_mac = Build.VERSION.SDK_INT >= 32 && shortTxId(); automata(); // sequence logic UserError.Log.d(TAG, "Releasing service start"); @@ -1120,6 +1230,10 @@ private synchronized void stopDiscover() { } private boolean isScanMatch(final String this_address, final String historical_address, final String this_name, final String search_name) { + if (search_name == null && (this_address.equalsIgnoreCase(historical_address) || this_name == null || (emptyString(historical_address) && this_name.startsWith("DXCM")) || (emptyString(historical_address) && this_name.startsWith("DX02")))) { + return !inFailureTally(this_address); + } + boolean result = this_address.equalsIgnoreCase(historical_address) || (this_name != null && this_name.equalsIgnoreCase(search_name)); if (result) { if (historical_address.length() == this_address.length() @@ -1138,13 +1252,13 @@ public static void clearScanError() { } // Successful result from our bluetooth scan - private synchronized void onScanResult(ScanResult bleScanResult) { + private synchronized void onScanResult(final ScanResult bleScanResult) { // TODO MIN RSSI final int this_rssi = bleScanResult.getRssi(); final String this_name = bleScanResult.getBleDevice().getName(); final String this_address = bleScanResult.getBleDevice().getMacAddress(); final String search_name = getTransmitterBluetoothName(); - + val mdata = bleScanResult.getScanRecord().getManufacturerSpecificData(0xD << 4); if (isScanMatch(this_address, historicalTransmitterMAC, this_name, search_name)) { stopScan(); // we got one! last_scan_started = 0; // clear scanning for time @@ -1152,7 +1266,9 @@ private synchronized void onScanResult(ScanResult bleScanResult) { UserError.Log.d(TAG, "Got scan result match: " + bleScanResult.getBleDevice().getName() + " " + this_address + " rssi: " + this_rssi); transmitterMAC = bleScanResult.getBleDevice().getMacAddress(); transmitterIDmatchingMAC = transmitterID; - PersistentStore.setString(OB1G5_MACSTORE + transmitterID, transmitterMAC); + if (search_name != null) { + saveTransmitterMac(); + } //if (JoH.ratelimit("ob1-g5-scan-to-connect-transition", 3)) { if (state == SCAN) { // if (always_scan) { @@ -1172,6 +1288,12 @@ private synchronized void onScanResult(ScanResult bleScanResult) { } } + public void saveTransmitterMac() { + UserError.Log.d(TAG, "Saving transmitter mac: " + transmitterID + " = " + transmitterMAC); + PersistentStore.cleanupOld(OB1G5_MACSTORE); + PersistentStore.setString(OB1G5_MACSTORE + transmitterID, transmitterMAC); + } + // Failed result from our bluetooth scan private synchronized void onScanFailure(Throwable throwable) { @@ -1181,7 +1303,24 @@ private synchronized void onScanFailure(Throwable throwable) { lastScanError = info; UserError.Log.d(TAG, info); - if (((BleScanException) throwable).getReason() == BleScanException.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED) { + final int reason = ((BleScanException) throwable).getReason(); + + if (reason == BleScanException.SCAN_FAILED_INTERNAL_ERROR) { + if (allow_scan_by_mac && lastWasScanByMac) { + allow_scan_by_mac = false; + UserError.Log.wtf(TAG, "Turning scan by by mac off"); + if (JoH.ratelimit("bluetooth-internal-error-register", 120)) { + if (Pref.getBooleanDefaultFalse("automatically_turn_bluetooth_on")) { + UserError.Log.wtf(TAG, "Android bluetooth appears broken with scan by mac - attempting to turn off and on"); + JoH.niceRestartBluetooth(xdrip.getAppContext()); + } else { + UserError.Log.e(TAG, "Cannot reset bluetooth due to preference being disabled"); + } + } + } + } + + if (reason == BleScanException.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED) { if (JoH.ratelimit("bluetooth-cannot-register", 120)) { if (Pref.getBooleanDefaultFalse("automatically_turn_bluetooth_on")) { UserError.Log.wtf(TAG, "Android bluetooth appears broken - attempting to turn off and on"); @@ -1192,7 +1331,7 @@ private synchronized void onScanFailure(Throwable throwable) { } } - if (((BleScanException) throwable).getReason() == BleScanException.BLUETOOTH_DISABLED) { + if (reason == BleScanException.BLUETOOTH_DISABLED) { // Attempt to turn bluetooth on if (JoH.ratelimit("bluetooth_toggle_on", 30)) { UserError.Log.d(TAG, "Pause before Turn Bluetooth on"); @@ -1273,7 +1412,7 @@ private void onConnectionFailure(final Throwable throwable) { UserError.Log.d(TAG, "Setting pre-scan failure marker enabled due to exception type"); preScanFailureMarker = true; } - } else if (JoH.msSince(last_connect_started) < Constants.SECOND_IN_MS) { + } else if (msSince(last_connect_started) < Constants.SECOND_IN_MS) { UserError.Log.d(TAG, "Setting pre-scan failure marker enabled due to exception timing"); preScanFailureMarker = true; } @@ -1327,27 +1466,33 @@ public void tryGattRefresh() { // We have connected to the device! private void onConnectionReceived(RxBleConnection this_connection) { msg("Connected"); - static_last_connected = tsl(); - lastConnectFailed = false; - preScanFailureMarker = false; - DexSyncKeeper.store(transmitterID, static_last_connected); - // TODO check connection already exists - close etc? - if (connection_linger != null) JoH.releaseWakeLock(connection_linger); - connection = this_connection; + if (shouldServiceRun()) { + static_last_connected = tsl(); + lastConnectFailed = false; + preScanFailureMarker = false; - if (state == CONNECT_NOW) { - connectNowFailures = -3; // mark good - } - if (state == CONNECT) { - connectFailures = -1; // mark good - } + DexSyncKeeper.store(transmitterID, static_last_connected); + // TODO check connection already exists - close etc? + if (connection_linger != null) JoH.releaseWakeLock(connection_linger); + connection = this_connection; - scanTimeouts = 0; // reset counter - clearRetries(); + if (state == CONNECT_NOW) { + connectNowFailures = -3; // mark good + } + if (state == CONNECT) { + connectFailures = -1; // mark good + } + + scanTimeouts = 0; // reset counter + clearRetries(); - if (JoH.ratelimit("g5-to-discover", 1)) { - changeState(DISCOVER); + if (JoH.ratelimit("g5-to-discover", 1)) { + changeState(DISCOVER); + } + } else { + msg("Shutdown"); + stopSelf(); } } @@ -1362,7 +1507,7 @@ private synchronized void onConnectionStateChange(RxBleConnection.RxBleConnectio connection_state = "Connected"; JoH.releaseWakeLock(floatingWakeLock); floatingWakeLock = JoH.getWakeLock("floating-connected", 40000); - final long since_connecting = JoH.msSince(connecting_time); + final long since_connecting = msSince(connecting_time); if ((connecting_time > static_last_timestamp) && (since_connecting > Constants.SECOND_IN_MS * 310) && (since_connecting < Constants.SECOND_IN_MS * 620)) { if (!always_scan) { UserError.Log.e(TAG, "Connection time shows missed reading, switching to always scan, metric: " + niceTimeScalar(since_connecting)); @@ -1413,8 +1558,35 @@ private void onServicesDiscovered(RxBleDeviceServices services) { do_discovery = false; } + if (txIdMatch(getTransmitterID()) && service.getCharacteristic(ExtraData) != null) { + try { + plugin = Loader.getLocalInstance(Registry.get(KEKS), getTransmitterID()); + if (plugin == null) { + val msg = "Unable to load keks plugin - please re-enter transmitter id"; + UserError.Log.wtf(TAG, msg); + JoH.static_toast_long(msg); + } else { + plugin.setPersistence(2, PersistentStore.getBytes(KEKS_ONE + transmitterMAC)); + if (immediateBonding()) + needsBonding(!isDeviceLocallyBonded() || ignoreBonding()); + try { + for (int i = 1; i < 4; i++) { + plugin.setPersistence(7 + i, tolerantHexStringToByteArray(Pref.getStringDefaultBlank(KEKS + "_p" + i))); + } + } catch (Exception e) { + UserError.Log.e(TAG, "Problem with persistence"); + } + } + } catch (Exception e) { + UserError.Log.e(TAG, "Exception getting instance: " + e); + e.printStackTrace(); + } + } else { + plugin = null; + } + if (specialPairingWorkaround()) { - UserError.Log.d(TAG,"Samsung additional delay"); + UserError.Log.d(TAG, "Samsung additional delay"); Inevitable.task("samsung delay", 1000, () -> changeState(STATE.CHECK_AUTH)); } else { changeState(STATE.CHECK_AUTH); @@ -1669,13 +1841,13 @@ public static void processCalibrationStateLite(final CalibrationState state, fin } } - public static boolean processCalibrationStateLite(final CalibrationState state) { + public static boolean processCalibrationStateLite(final CalibrationState state) { if (state == CalibrationState.Unknown) { UserError.Log.d(TAG, "Not processing push of unknown state as this is the unset state"); return false; } - if (JoH.msSince(lastProcessCalibrationState) < Constants.MINUTE_IN_MS) { + if (msSince(lastProcessCalibrationState) < MINUTE_IN_MS) { UserError.Log.d(TAG, "Ignoring duplicate processCalibration State"); return false; } @@ -1780,7 +1952,7 @@ private static void storeCalibrationState(final CalibrationState state) { } private static CalibrationState getStoredCalibrationState() { - if (JoH.msSince(PersistentStore.getLong(OB1G5_STATESTORE_TIME)) < HOUR_IN_MS * 2) { + if (msSince(PersistentStore.getLong(OB1G5_STATESTORE_TIME)) < HOUR_IN_MS * 2) { return CalibrationState.parse(PersistentStore.getByte(OB1G5_STATESTORE)); } return CalibrationState.Unknown; @@ -1851,7 +2023,13 @@ public static boolean usingNativeMode() { } public static boolean onlyUsingNativeMode() { - return usingNativeMode() && !fallbackToXdripAlgorithm(); + return (usingNativeMode() && !fallbackToXdripAlgorithm()) + || usingMockPreCalibrated(); + } + + public static boolean usingMockPreCalibrated() { + return Pref.getBooleanDefaultFalse("fake_data_pre_calibrated") + && DexCollectionType.getDexCollectionType() == DexCollectionType.Mock; } public static boolean isProvidingNativeGlucoseData() { @@ -1939,6 +2117,10 @@ void setPurdah(final long duration) { } } + void needsBonding(final boolean required) { + plugin.setPersistence(6, joinBytes(new byte[]{(byte) ((required ? 0 : 1) << 1)}, fwChalCache(required))); + } + private static void handleUnknownFirmwareClick() { UserError.Log.d(TAG, "handleUnknownFirmwareClick()"); if (UpdateActivity.testAndSetNightly(true)) { @@ -1965,10 +2147,10 @@ public static List megaStatus() { l.add(new StatusItem("Turn Sound On!", "You will not hear pairing request with volume set low or do not disturb enabled!", CRITICAL)); } - l.add(new StatusItem("Phone Service State", lastState + (BlueJayEntry.isPhoneCollectorDisabled() ? "\nDisabled by BlueJay option" : ""), JoH.msSince(lastStateUpdated) < 300000 ? (lastState.startsWith("Got data") ? Highlight.GOOD : NORMAL) : (isWatchRunning() ? Highlight.GOOD : CRITICAL))); + l.add(new StatusItem("Phone Service State", lastState + (BlueJayEntry.isPhoneCollectorDisabled() ? "\nDisabled by BlueJay option" : ""), msSince(lastStateUpdated) < 300000 ? (lastState.startsWith("Got data") ? Highlight.GOOD : NORMAL) : (isWatchRunning() ? Highlight.GOOD : CRITICAL))); if (last_scan_started > 0) { - final long scanning_time = JoH.msSince(last_scan_started); - l.add(new StatusItem("Time scanning", niceTimeScalar(scanning_time), scanning_time > Constants.MINUTE_IN_MS * 5 ? (scanning_time > Constants.MINUTE_IN_MS * 10 ? BAD : NOTICE) : NORMAL)); + final long scanning_time = msSince(last_scan_started); + l.add(new StatusItem("Time scanning", niceTimeScalar(scanning_time), scanning_time > MINUTE_IN_MS * 5 ? (scanning_time > MINUTE_IN_MS * 10 ? BAD : NOTICE) : NORMAL)); } if (lastScanError != null) { l.add(new StatusItem("Scan Error", lastScanError, BAD)); @@ -1982,7 +2164,7 @@ public static List megaStatus() { } if (transmitterID != null) { - l.add(new StatusItem("Transmitter ID", transmitterID + ((transmitterMAC != null && Home.get_engineering_mode()) ? "\n" + transmitterMAC : ""))); + l.add(new StatusItem("Transmitter ID", transmitterID + ((transmitterMAC != null && get_engineering_mode()) ? "\n" + transmitterMAC : ""))); } if (static_connection_state != null) { @@ -1990,14 +2172,14 @@ public static List megaStatus() { } if (static_last_connected > 0) { - l.add(new StatusItem("Last Connected", niceTimeScalar(JoH.msSince(static_last_connected)) + " ago")); + l.add(new StatusItem("Last Connected", niceTimeScalar(msSince(static_last_connected)) + " ago")); } if ((!lastState.startsWith("Service Stopped")) && (!lastState.startsWith("Not running"))) l.add(new StatusItem("Brain State", state.getString() + (error_count > 1 ? " Errors: " + error_count : ""), error_count > 1 ? NOTICE : error_count > 4 ? BAD : NORMAL)); if (lastUsableGlucosePacketTime != 0) { - if (JoH.msSince(lastUsableGlucosePacketTime) < Constants.MINUTE_IN_MS * 15) { + if (msSince(lastUsableGlucosePacketTime) < MINUTE_IN_MS * 15) { l.add(new StatusItem("Native Algorithm", "Data Received " + JoH.hourMinuteString(lastUsableGlucosePacketTime), Highlight.GOOD)); } } @@ -2012,7 +2194,7 @@ public static List megaStatus() { } if (JoH.buggy_samsung) { - l.add(new StatusItem("Buggy Samsung", "Using workaround", max_wakeup_jitter < TOLERABLE_JITTER ? Highlight.GOOD : BAD)); + l.add(new StatusItem("Buggy handset", "Using workaround", max_wakeup_jitter < TOLERABLE_JITTER ? Highlight.GOOD : BAD)); } final String tx_id = getTransmitterID(); @@ -2026,14 +2208,16 @@ public static List megaStatus() { } final String sensorCode = getCurrentSensorCode(); if (sensorCode != null) { - if (usingG6()) { + if (usingG6() && FirmwareCapability.isTransmitterG6(getTransmitterID())) { l.add(new StatusItem("Calibration Code", sensorCode)); } } - l.add(new StatusItem("Preemptive restarts", !FirmwareCapability.isTransmitterPreemptiveRestartCapable(getTransmitterID()) ? "Not capable" : - (Pref.getBooleanDefaultFalse("ob1_g5_preemptive_restart") ? "Enabled" : "Disabled") - + (Ob1G5StateMachine.useExtendedTimeTravel() ? " (extended)" : ""))); + if (get_engineering_mode() || FirmwareCapability.isTransmitterPreemptiveRestartCapable(getTransmitterID())) { + l.add(new StatusItem("Preemptive restarts", !FirmwareCapability.isTransmitterPreemptiveRestartCapable(getTransmitterID()) ? "Not capable" : + (Pref.getBooleanDefaultFalse("ob1_g5_preemptive_restart") ? "Enabled" : "Disabled") + + (Ob1G5StateMachine.useExtendedTimeTravel() ? " (extended)" : ""))); + } final VersionRequest1RxMessage vr1 = (VersionRequest1RxMessage) Ob1G5StateMachine.getFirmwareXDetails(tx_id, 1); final VersionRequest2RxMessage vr2 = (VersionRequest2RxMessage) Ob1G5StateMachine.getFirmwareXDetails(tx_id, 2); @@ -2045,12 +2229,17 @@ public static List megaStatus() { l.add(new StatusItem("Firmware Version", vr1.firmware_version_string + unknown, !known ? CRITICAL : NORMAL, !known ? "long-press" : null, !known ? (Runnable) Ob1G5CollectionService::handleUnknownFirmwareClick : null)); //l.add(new StatusItem("Build Version", "" + vr1.build_version)); - if (vr1.version_code != 3) { - l.add(new StatusItem("Compat Version", "" + vr1.version_code, Highlight.BAD)); + if (vr1.version_code != 3 && get_engineering_mode()) { + l.add(new StatusItem("Compat Version", "" + vr1.version_code, NORMAL)); } - if (vr1.max_runtime_days != 110 && vr1.max_runtime_days != 112) { + if (vr1.max_runtime_days != 110 && vr1.max_runtime_days != 112 && vr1.max_runtime_days != 0) { l.add(new StatusItem("Transmitter Life", "" + vr1.max_runtime_days + " " + gs(R.string.days))); } + + if (vr1.serial != 0 && get_engineering_mode()) { + l.add(new StatusItem("Serial", "" + vr1.serial)); + } + } } catch (Exception e) { // TODO add message? @@ -2061,6 +2250,23 @@ public static List megaStatus() { if (vr2.typicalSensorDays != 10 && vr2.typicalSensorDays != 7) { l.add(new StatusItem("Sensor Period", niceTimeScalar(vr2.typicalSensorDays * DAY_IN_MS), Highlight.NOTICE)); } + + if (get_engineering_mode()) { + if (vr2.lifeSeconds > 0) { + l.add(new StatusItem("Sensor Life", "" + niceTimeScalar(vr2.lifeSeconds * SECOND_IN_MS))); + } + if (vr2.version1 > 0) { + l.add(new StatusItem("Version 1", "" + vr2.version1)); + } + if (vr2.version2 > 0) { + l.add(new StatusItem("Version 2", "" + vr2.version2)); + } + } + + if (vr3 == null && vr2.version1 != 0 && vr2.warmupSeconds != 0 && vr2.warmupSeconds != 7200 && vr2.warmupSeconds != 1620) { + l.add(new StatusItem("Warm Up Time", niceTimeScalar(vr2.warmupSeconds * SECOND_IN_MS), Highlight.NOTICE)); + } + //l.add(new StatusItem("Feature mask", vr2.featureBits)); } } catch (Exception e) { @@ -2083,7 +2289,7 @@ public static List megaStatus() { try { if ((vr != null) && (vr.firmware_version_string.length() > 0)) { - if (Home.get_engineering_mode()) { + if (get_engineering_mode()) { if (vr1 != null && !vr.firmware_version_string.equals(vr1.firmware_version_string)) { l.add(new StatusItem("2nd Firmware Version", vr.firmware_version_string, FirmwareCapability.isG6Rev2(vr.firmware_version_string) ? NOTICE : NORMAL)); } @@ -2092,7 +2298,7 @@ public static List megaStatus() { } l.add(new StatusItem("Other Version", vr.other_firmware_version)); // l.add(new StatusItem("Hardware Version", vr.hardwarev)); - if (vr.asic != 61440 && vr.asic != 16705 && vr.asic != 243 && vr.asic != 74 && vr.asic != 226) + if (vr.asic != 61440 && vr.asic != 16705 && vr.asic != 243 && vr.asic != 74 && vr.asic != 226 && vr.asic != 0) l.add(new StatusItem("ASIC", vr.asic, NOTICE)); } } @@ -2117,7 +2323,7 @@ public void run() { updateBatteryWarningLevel(); } - if (vr1 != null && Home.get_engineering_mode()) { + if (vr1 != null && get_engineering_mode() && vr1.max_inactive_days > 0) { l.add(new StatusItem("Shelf Life", "" + vr1.inactive_days + " / " + vr1.max_inactive_days)); } @@ -2136,24 +2342,35 @@ public void run() { if (!battery_status.equals("OK")) l.add(new StatusItem("Transmitter Status", battery_status, BAD)); } - Highlight TX_dys_highlight; // Transmitter Days highlight + Highlight TX_dys_highlight = NORMAL; // Set the default transmitter days highlight to normal final int TX_dys = DexTimeKeeper.getTransmitterAgeInDays(tx_id); // Transmitter days - if (vr != null && (FirmwareCapability.isTransmitterRawCapable(getTransmitterID())) || TX_dys < 69) { - // Transmitter days < 69 or G5 or old G6 or modified Firefly - TX_dys_highlight = NORMAL; - } else if (TX_dys < 100) { // Unmodified Firefly with 68 < Transmitter days < 100 - TX_dys_highlight = NOTICE; - } else { // Unmodified Firefly with transmitter days > 99 - TX_dys_highlight = BAD; + if (vr != null) { + if (FirmwareCapability.isTransmitterModified(getTransmitterID())) { // Modified Firefly + if (TX_dys > 179) { // No more starts as transmitter days > 179 + TX_dys_highlight = BAD; + } else if (TX_dys > 148) { // Transmitter days approaching 180 - may be time to reset + TX_dys_highlight = NOTICE; + } + } else if (FirmwareCapability.isTransmitterRawIncapable(getTransmitterID())) { // Unmodified Firefly + if (TX_dys > 99) { // No more starts as transmitter days > 99 + TX_dys_highlight = BAD; + } else if (TX_dys > 68) { // Transmitter days approaching 100 - may be time to order a new one + TX_dys_highlight = NOTICE; + } + } } l.add(new StatusItem("Transmitter Days", parsedBattery.daysEstimate(), TX_dys_highlight)); l.add(new StatusItem("Voltage A", parsedBattery.voltageA(), parsedBattery.voltageAWarning() ? BAD : NORMAL)); l.add(new StatusItem("Voltage B", parsedBattery.voltageB(), parsedBattery.voltageBWarning() ? BAD : NORMAL)); if (vr != null && FirmwareCapability.isFirmwareResistanceCapable(vr.firmware_version_string)) { - l.add(new StatusItem("Resistance", parsedBattery.resistance(), parsedBattery.resistanceStatus().highlight)); + if (parsedBattery.resistance() != 0) { + l.add(new StatusItem("Resistance", parsedBattery.resistance(), parsedBattery.resistanceStatus().highlight)); + } } if (vr != null && FirmwareCapability.isFirmwareTemperatureCapable(vr.firmware_version_string)) { - l.add(new StatusItem("Temperature", parsedBattery.temperature() + " \u2103")); + if (parsedBattery.temperature() > 0) { + l.add(new StatusItem("Temperature", parsedBattery.temperature() + " \u2103")); + } } } else { l.add(new StatusItem("Battery Info Unavailable", "Click to trigger update", NORMAL, "long-press", @@ -2175,6 +2392,35 @@ public static void resetSomeInternalState() { scan_next_run = true; } + public synchronized void logFailure() { + val localMac = transmitterMAC; + if (localMac == null) { + UserError.Log.e(TAG, "Could not log failure as mac is null"); + return; + } + val tsl = tsl(); + failureTally.put(localMac, tsl); + UserError.Log.d(TAG, "Adding " + localMac + " to failure tally " + JoH.dateTimeText(tsl)); + resetSomeInternalState(); + } + + private static void expireFailures(final boolean all) { + val remove = new ArrayList(); + for (val entry : failureTally.entrySet()) { + if (all || msSince(entry.getValue()) > (MINUTE_IN_MS * 30)) { + remove.add(entry.getKey()); + } + } + for (val entry : remove) { + UserError.Log.d(TAG, "Removing " + entry + " from failure tally"); + failureTally.remove(entry); + } + } + + private static boolean inFailureTally(final String mac) { + if (mac == null) return false; + return (failureTally.containsKey(mac)); + } public void listenForChangeInSettings(boolean listen) { try { @@ -2198,7 +2444,7 @@ public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { // remember needs proguard exclusion due to access by reflection public static boolean isCollecting() { - return (state == CONNECT_NOW && JoH.msSince(static_last_timestamp) < Constants.MINUTE_IN_MS * 30) || JoH.msSince(static_last_timestamp) < Constants.MINUTE_IN_MS * 6; + return (state == CONNECT_NOW && msSince(static_last_timestamp) < MINUTE_IN_MS * 30) || msSince(static_last_timestamp) < MINUTE_IN_MS * 6; } public static boolean usingCollector() { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/PlusSyncService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/PlusSyncService.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/PlusSyncService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/PlusSyncService.java index 8aa900e4d1..c6e3497db9 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/PlusSyncService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/PlusSyncService.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.app.Service; import android.content.Context; @@ -12,7 +12,7 @@ import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.GoogleDriveInterface; -import com.eveningoutpost.dexdrip.UtilityModels.UpdateActivity; +import com.eveningoutpost.dexdrip.utilitymodels.UpdateActivity; import com.eveningoutpost.dexdrip.xdrip; import java.lang.ref.WeakReference; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/ProximitySensorService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/ProximitySensorService.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/ProximitySensorService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/ProximitySensorService.java index 0ebddeca52..0aed45113e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/ProximitySensorService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/ProximitySensorService.java @@ -1,5 +1,5 @@ /* -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.app.Service; import android.content.Context; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/SnoozeOnNotificationDismissService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/SnoozeOnNotificationDismissService.java similarity index 88% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/SnoozeOnNotificationDismissService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/SnoozeOnNotificationDismissService.java index a2614c1101..b3ceb478e8 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/SnoozeOnNotificationDismissService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/SnoozeOnNotificationDismissService.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.app.IntentService; import android.content.Intent; @@ -6,16 +6,16 @@ import android.preference.PreferenceManager; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.ActiveBgAlert; -import com.eveningoutpost.dexdrip.Models.AlertType; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.Models.UserNotification; +import com.eveningoutpost.dexdrip.models.ActiveBgAlert; +import com.eveningoutpost.dexdrip.models.AlertType; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserNotification; import com.eveningoutpost.dexdrip.SnoozeActivity; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.wearintegration.Amazfitservice; import com.eveningoutpost.dexdrip.xdrip; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/SyncService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/SyncService.java similarity index 81% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/SyncService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/SyncService.java index fd10c670f2..00d7323a2b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/SyncService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/SyncService.java @@ -1,17 +1,17 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.app.IntentService; import android.app.PendingIntent; import android.content.Intent; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.UploaderTask; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.UploaderTask; import com.eveningoutpost.dexdrip.xdrip; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.SYNC_QUEUE_RETRY_ID; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.SYNC_QUEUE_RETRY_ID; public class SyncService extends IntentService { private static final String TAG = "SyncService"; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/TransmitterRawData.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/TransmitterRawData.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/TransmitterRawData.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/TransmitterRawData.java index 719b38c8a6..d94624237d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/TransmitterRawData.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/TransmitterRawData.java @@ -1,7 +1,7 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import java.util.Date; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.google.gson.annotations.Expose; import com.mongodb.BasicDBObject; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/UiBasedCollector.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/UiBasedCollector.java similarity index 51% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/UiBasedCollector.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/UiBasedCollector.java index 3ff14795af..01383d195a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/UiBasedCollector.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/UiBasedCollector.java @@ -1,7 +1,7 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; import static com.eveningoutpost.dexdrip.cgm.dex.ClassifierAction.lastReadingTimestamp; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.UiBased; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.getDexCollectionType; import static com.eveningoutpost.dexdrip.xdrip.gs; @@ -26,20 +26,24 @@ import androidx.annotation.VisibleForTesting; import com.eveningoutpost.dexdrip.BestGlucose; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Unitized; +import com.eveningoutpost.dexdrip.alert.Persist; import com.eveningoutpost.dexdrip.cgm.dex.BlueTails; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Unitized; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.xdrip; import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import lombok.val; @@ -53,10 +57,17 @@ public class UiBasedCollector extends NotificationListenerService { private static final String TAG = UiBasedCollector.class.getSimpleName(); private static final String UI_BASED_STORE_LAST_VALUE = "UI_BASED_STORE_LAST_VALUE"; private static final String UI_BASED_STORE_LAST_REPEAT = "UI_BASED_STORE_LAST_REPEAT"; + private static final String COMPANION_APP_IOB_ENABLED_PREFERENCE_KEY = "fetch_iob_from_companion_app"; + private static final Persist.DoubleTimeout iob_store = + new Persist.DoubleTimeout("COMPANION_APP_IOB_VALUE", Constants.MINUTE_IN_MS * 5); private static final String ENABLED_NOTIFICATION_LISTENERS = "enabled_notification_listeners"; private static final String ACTION_NOTIFICATION_LISTENER_SETTINGS = "android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"; private static final HashSet coOptedPackages = new HashSet<>(); + private static final HashSet coOptedPackagesAll = new HashSet<>(); + private static final HashSet companionAppIoBPackages = new HashSet<>(); + private static final HashSet companionAppIoBRegexes = new HashSet<>(); + private static boolean debug = false; @VisibleForTesting String lastPackage; @@ -67,10 +78,32 @@ public class UiBasedCollector extends NotificationListenerService { coOptedPackages.add("com.dexcom.g6.region3.mgdl"); coOptedPackages.add("com.dexcom.dexcomone"); coOptedPackages.add("com.dexcom.g7"); + coOptedPackages.add("com.dexcom.d1plus"); coOptedPackages.add("com.camdiab.fx_alert.mmoll"); coOptedPackages.add("com.camdiab.fx_alert.mgdl"); coOptedPackages.add("com.camdiab.fx_alert.hx.mmoll"); coOptedPackages.add("com.camdiab.fx_alert.hx.mgdl"); + coOptedPackages.add("com.medtronic.diabetes.guardian"); + coOptedPackages.add("com.medtronic.diabetes.guardianconnect"); + coOptedPackages.add("com.medtronic.diabetes.guardianconnect.us"); + coOptedPackages.add("com.medtronic.diabetes.minimedmobile.eu"); + coOptedPackages.add("com.medtronic.diabetes.minimedmobile.us"); + coOptedPackages.add("com.medtronic.diabetes.simplera.eu"); + coOptedPackages.add("com.senseonics.gen12androidapp"); + coOptedPackages.add("com.senseonics.androidapp"); + + coOptedPackagesAll.add("com.dexcom.dexcomone"); + coOptedPackagesAll.add("com.dexcom.d1plus"); + coOptedPackagesAll.add("com.medtronic.diabetes.guardian"); + coOptedPackagesAll.add("com.medtronic.diabetes.simplera.eu"); + coOptedPackagesAll.add("com.senseonics.gen12androidapp"); + coOptedPackagesAll.add("com.senseonics.androidapp"); + + companionAppIoBPackages.add("com.insulet.myblue.pdm"); + + // The IoB value should be captured into the first match group. + // English localization of the Omnipod 5 App + companionAppIoBRegexes.add(Pattern.compile("IOB: ([\\d\\.,]+) U")); } @Override @@ -79,17 +112,79 @@ public void onNotificationPosted(final StatusBarNotification sbn) { if (coOptedPackages.contains(fromPackage)) { if (getDexCollectionType() == UiBased) { UserError.Log.d(TAG, "Notification from: " + fromPackage); - if (sbn.isOngoing()) { + if (sbn.isOngoing() || coOptedPackagesAll.contains(fromPackage)) { lastPackage = fromPackage; processNotification(sbn.getNotification()); BlueTails.immortality(); } } else { if (JoH.pratelimit("warn-notification-access", 7200)) { - UserError.Log.wtf(TAG, "Receiving notifications that we are not enabled to process"); + UserError.Log.wtf(TAG, "Receiving notifications that we are not enabled to process: " + fromPackage); } } } + + if (companionAppIoBPackages.contains(fromPackage)) { + processCompanionAppIoBNotification(sbn.getNotification()); + } + } + + private void processCompanionAppIoBNotification(final Notification notification) { + if (notification == null) { + UserError.Log.e(TAG, "Null notification"); + return; + } + if (notification.contentView != null) { + processCompanionAppIoBNotificationCV(notification.contentView); + } else { + UserError.Log.e(TAG, "Content is empty"); + } + } + + private void processCompanionAppIoBNotificationCV(final RemoteViews cview) { + if (cview == null) return; + val applied = cview.apply(this, null); + val root = (ViewGroup) applied.getRootView(); + val texts = new ArrayList(); + getTextViews(texts, root); + if (debug) UserError.Log.d(TAG, "Text views: " + texts.size()); + Double iob = null; + try { + for (val view : texts) { + val tv = (TextView) view; + String text = tv.getText() != null ? tv.getText().toString() : ""; + val desc = tv.getContentDescription() != null ? tv.getContentDescription().toString() : ""; + if (debug) UserError.Log.d(TAG, "Examining: >" + text + "< : >" + desc + "<"); + iob = parseIoB(text); + if (iob != null) { + break; + } + } + + if (iob != null) { + if (debug) UserError.Log.d(TAG, "Inserting new IoB value: " + iob); + iob_store.set(iob); + } + } catch (Exception e) { + UserError.Log.e(TAG, "exception in processCompanionAppIoBNotificationCV: " + e); + } + + texts.clear(); + } + Double parseIoB(final String value) { + for (Pattern pattern : companionAppIoBRegexes) { + Matcher matcher = pattern.matcher(value); + + if (matcher.find()) { + return JoH.tolerantParseDouble(matcher.group(1)); + } + } + + return null; + } + + public static Double getCurrentIoB() { + return iob_store.get(); } @Override @@ -124,10 +219,43 @@ String filterString(final String value) { if (lastPackage == null) return value; switch (lastPackage) { default: - return value - .replace("≤", "") - .replace("≥", ""); + return (basicFilterString(arrowFilterString(value))) + .trim(); + } + } + + String basicFilterString(final String value) { + return value + .replace("\u00a0"," ") + .replace("\u2060","") + .replace("\\","/") + .replace("mmol/L", "") + .replace("mmol/l", "") + .replace("mg/dL", "") + .replace("mg/dl", "") + .replace("≤", "") + .replace("≥", ""); + } + + String arrowFilterString(final String value) { + return filterUnicodeRange(filterUnicodeRange(filterUnicodeRange(filterUnicodeRange(value, + '\u2190', '\u21FF'), + '\u2700', '\u27BF'), + '\u2900', '\u297F'), + '\u2B00', '\u2BFF'); + } + + public String filterUnicodeRange(final String input, final char bottom, final char top) { + if (bottom > top) { + throw new RuntimeException("bottom and top of character range invalid"); + } + val filtered = new StringBuilder(input.length()); + for (final char c : input.toCharArray()) { + if (c < bottom || c > top) { + filtered.append(c); + } } + return filtered.toString(); } @SuppressWarnings("UnnecessaryLocalVariable") @@ -172,41 +300,61 @@ private void processRemote(final RemoteViews cview) { } else if (matches > 1) { UserError.Log.e(TAG, "Found too many matches: " + matches); } else { - Sensor.createDefaultIfMissing(); val timestamp = JoH.tsl(); - UserError.Log.d(TAG, "Found specific value: " + mgdl); - - if ((mgdl >= 40 && mgdl <= 405)) { - val grace = DexCollectionType.getCurrentSamplePeriod() * 4; - val recent = msSince(lastReadingTimestamp) < grace; - val period = recent ? grace : DexCollectionType.getCurrentDeduplicationPeriod(); - if (BgReading.getForPreciseTimestamp(timestamp, period, false) == null) { - if (isJammed(mgdl)) { - UserError.Log.wtf(TAG, "Apparently value is jammed at: " + mgdl); - } else { - UserError.Log.d(TAG, "Inserting new value"); - PersistentStore.setLong(UI_BASED_STORE_LAST_VALUE, mgdl); - val bgr = BgReading.bgReadingInsertFromG5(mgdl, timestamp); - if (bgr != null) { - bgr.find_slope(); - bgr.noRawWillBeAvailable(); - bgr.injectDisplayGlucose(BestGlucose.getDisplayGlucose()); - } - } + handleNewValue(timestamp, mgdl); + } + texts.clear(); + } + + boolean handleNewValue(final long timestamp, final int mgdl) { + Sensor.createDefaultIfMissing(); + + UserError.Log.d(TAG, "Found specific value: " + mgdl); + + if ((mgdl >= 40 && mgdl <= 405)) { + val grace = DexCollectionType.getCurrentSamplePeriod() * 4; + val recentbt = msSince(lastReadingTimestamp) < grace; + val dedupe = (!recentbt && isDifferentToLast(mgdl)) ? Constants.SECOND_IN_MS * 10 + : DexCollectionType.getCurrentDeduplicationPeriod(); + val period = recentbt ? grace : dedupe; + val existing = BgReading.getForPreciseTimestamp(timestamp, period, false); + if (existing == null) { + if (isJammed(mgdl)) { + UserError.Log.wtf(TAG, "Apparently value is jammed at: " + mgdl); } else { - UserError.Log.d(TAG, "Duplicate value"); + UserError.Log.d(TAG, "Inserting new value"); + PersistentStore.setLong(UI_BASED_STORE_LAST_VALUE, mgdl); + val bgr = BgReading.bgReadingInsertFromG5(mgdl, timestamp); + if (bgr != null) { + bgr.find_slope(); + bgr.noRawWillBeAvailable(); + bgr.injectDisplayGlucose(BestGlucose.getDisplayGlucose()); + return true; + } } } else { - UserError.Log.wtf(TAG, "Glucose value outside acceptable range: " + mgdl); + UserError.Log.d(TAG, "Duplicate value: "+existing.timeStamp()); } + } else { + UserError.Log.wtf(TAG, "Glucose value outside acceptable range: " + mgdl); } - texts.clear(); + return false; } static boolean isValidMmol(final String text) { return text.matches("[0-9]+[.,][0-9]+"); } + private boolean shouldAllowTimeOffsetChange(final int mgdl) { + return isDifferentToLast(mgdl); // TODO do we need to rate limit this or not? + } + // note this method only checks existing stored data + private boolean isDifferentToLast(final int mgdl) { + val previousValue = PersistentStore.getLong(UI_BASED_STORE_LAST_VALUE); + return previousValue != mgdl; + } + + // note this method actually updates the stored value private boolean isJammed(final int mgdl) { val previousValue = PersistentStore.getLong(UI_BASED_STORE_LAST_VALUE); if (previousValue == mgdl) { @@ -216,7 +364,14 @@ private boolean isJammed(final int mgdl) { } val lastRepeat = PersistentStore.getLong(UI_BASED_STORE_LAST_REPEAT); UserError.Log.d(TAG, "Last repeat: " + lastRepeat); - return lastRepeat > 3; + return lastRepeat > jamThreshold(); + } + + private int jamThreshold() { + if (lastPackage != null) { + if (lastPackage.startsWith("com.medtronic")) return 9; + } + return 6; } private void getTextViews(final List output, final ViewGroup parent) { @@ -249,12 +404,23 @@ public static SharedPreferences.OnSharedPreferenceChangeListener getListener(fin // } } + if (key.equals(COMPANION_APP_IOB_ENABLED_PREFERENCE_KEY)) { + try { + enableNotificationService(activity); + } catch (Exception e) { + UserError.Log.e(TAG, "Exception when enabling NotificationService: " + e); + } + } }; } public static void switchToAndEnable(final Activity activity) { DexCollectionType.setDexCollectionType(UiBased); Sensor.createDefaultIfMissing(); + enableNotificationService(activity); + } + + private static void enableNotificationService(final Activity activity) { if (!isNotificationServiceEnabled()) { JoH.show_ok_dialog(activity, gs(R.string.please_allow_permission), "Permission is needed to receive data from other applications. xDrip does not do anything beyond this scope. Please enable xDrip on the next screen", diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/WifiCollectionService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/WifiCollectionService.java similarity index 91% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/WifiCollectionService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/WifiCollectionService.java index d605a07b82..01378fbb6e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/WifiCollectionService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/WifiCollectionService.java @@ -1,7 +1,6 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.annotation.TargetApi; -import android.app.PendingIntent; import android.app.Service; import android.content.Context; import android.content.Intent; @@ -13,14 +12,14 @@ import android.preference.PreferenceManager; import android.text.SpannableString; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.ForegroundServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.ForegroundServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.utils.Mdns; import com.eveningoutpost.dexdrip.utils.framework.WakeLockTrampoline; @@ -75,7 +74,7 @@ public static List megaStatus(Context context) { l.add(new StatusItem("Wakeup jitter", JoH.niceTimeScalar(max_wakeup_jitter), max_wakeup_jitter > TOLERABLE_JITTER ? StatusItem.Highlight.BAD : StatusItem.Highlight.NORMAL)); } if (JoH.buggy_samsung) { - l.add(new StatusItem("Buggy Samsung", "Using workaround", max_wakeup_jitter < TOLERABLE_JITTER ? StatusItem.Highlight.GOOD : StatusItem.Highlight.BAD)); + l.add(new StatusItem("Buggy handset", "Using workaround", max_wakeup_jitter < TOLERABLE_JITTER ? StatusItem.Highlight.GOOD : StatusItem.Highlight.BAD)); } if(DexCollectionType.hasLibre()) { l.addAll(LibreWifiReader.megaStatus()); @@ -120,7 +119,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { Log.d(TAG, "Wake up jitter: " + JoH.niceTimeScalar(wakeup_jitter)); } if ((wakeup_jitter > TOLERABLE_JITTER) && (!JoH.buggy_samsung) && (JoH.isSamsung())) { - UserError.Log.wtf(TAG, "Enabled Buggy Samsung workaround due to jitter of: " + JoH.niceTimeScalar(wakeup_jitter)); + UserError.Log.wtf(TAG, "Enabled wake workaround due to jitter of: " + JoH.niceTimeScalar(wakeup_jitter)); JoH.setBuggySamsungEnabled(); max_wakeup_jitter = 0; } else { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/WixelReader.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/WixelReader.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/WixelReader.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/WixelReader.java index dc6709361f..9af3896892 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/WixelReader.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/WixelReader.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services; +package com.eveningoutpost.dexdrip.services; import android.content.Context; import android.os.AsyncTask; @@ -7,17 +7,17 @@ import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; import com.eveningoutpost.dexdrip.MapsActivity; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.TransmitterData; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.TransmitterData; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.ParakeetHelper; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.MockDataSource; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.MockDataSource; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; import com.eveningoutpost.dexdrip.utils.CheckBridgeBattery; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.utils.Mdns; @@ -137,6 +137,9 @@ private static List readFake() { trd.CaptureDateTime = System.currentTimeMillis() - trd.RelativeTime; final List l = new ArrayList<>(); l.add(trd); + if (Ob1G5CollectionService.usingMockPreCalibrated()) { + BgReading.bgReadingInsertFromG5(trd.RawValue / 1000.0, trd.getCaptureDateTime(), "Mock"); + } return l; } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastEntry.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastEntry.java similarity index 72% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastEntry.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastEntry.java index bfa888adb5..f3beec14b8 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastEntry.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastEntry.java @@ -1,8 +1,8 @@ -package com.eveningoutpost.dexdrip.Services.broadcastservice; +package com.eveningoutpost.dexdrip.services.broadcastservice; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; public class BroadcastEntry { //a tiny class created to make sure the service class would not be loaded if service disabled @@ -24,6 +24,12 @@ public static void sendLatestBG() { } } + public static void cancelAlert() { + if (isEnabled()) { + JoH.startService(BroadcastService.class, Const.INTENT_FUNCTION_KEY, Const.CMD_CANCEL_ALERT); + } + } + public static void sendAlert(String type, String message) { if (isEnabled()) { Inevitable.task("broadcast-service-send-alert", 100, () -> JoH.startService(BroadcastService.class, diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastService.java similarity index 90% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastService.java index abe69b9b73..c518b745c1 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastService.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services.broadcastservice; +package com.eveningoutpost.dexdrip.services.broadcastservice; import android.app.Service; import android.content.BroadcastReceiver; @@ -14,28 +14,30 @@ import android.preference.PreferenceManager; import com.eveningoutpost.dexdrip.BestGlucose; -import com.eveningoutpost.dexdrip.Models.Accuracy; -import com.eveningoutpost.dexdrip.Models.ActiveBgAlert; -import com.eveningoutpost.dexdrip.Models.AlertType; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.HeartRate; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.StepCounter; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserNotification; -import com.eveningoutpost.dexdrip.Services.MissedReadingService; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.PumpStatus; +import com.eveningoutpost.dexdrip.models.Accuracy; +import com.eveningoutpost.dexdrip.models.ActiveBgAlert; +import com.eveningoutpost.dexdrip.models.AlertType; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.HeartRate; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.StepCounter; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserNotification; +import com.eveningoutpost.dexdrip.services.MissedReadingService; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.PumpStatus; import com.eveningoutpost.dexdrip.stats.StatsResult; +import com.eveningoutpost.dexdrip.store.FastStore; +import com.eveningoutpost.dexdrip.store.KeyStore; import com.eveningoutpost.dexdrip.utils.PowerStateReceiver; -import com.eveningoutpost.dexdrip.Services.broadcastservice.models.BroadcastModel; -import com.eveningoutpost.dexdrip.Services.broadcastservice.models.GraphLine; -import com.eveningoutpost.dexdrip.Services.broadcastservice.models.Settings; +import com.eveningoutpost.dexdrip.services.broadcastservice.models.BroadcastModel; +import com.eveningoutpost.dexdrip.services.broadcastservice.models.GraphLine; +import com.eveningoutpost.dexdrip.services.broadcastservice.models.Settings; import com.eveningoutpost.dexdrip.xdrip; import java.util.HashMap; @@ -43,7 +45,11 @@ import lecho.lib.hellocharts.model.Line; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.DAY_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.DAY_IN_MS; + +// External status line from AAPS added +import static com.eveningoutpost.dexdrip.wearintegration.ExternalStatusService.getLastStatusLine; +import static com.eveningoutpost.dexdrip.wearintegration.ExternalStatusService.getLastStatusLineTime; /** * Broadcast API which provides common data like, bg values, graph info, statistic info. @@ -76,6 +82,8 @@ public class BroadcastService extends Service { protected String TAG = this.getClass().getSimpleName(); protected Map broadcastEntities; + protected KeyStore keyStore = FastStore.getInstance(); + /** * The receiver listening {@link ACTION_WATCH_COMMUNICATION_RECEIVER} action. * Every Receiver command requires {@link Const.INTENT_PACKAGE_KEY} @@ -91,7 +99,7 @@ public class BroadcastService extends Service { * If service received a command from not registered packageKey, this command would be skipped. * So it is necessary to "register" third-party applications with CMD_SET_SETTINGS or CMD_UPDATE_BG_FORCE at first. * {@link Settings} model is a {@link Parcelable} object. Please note since Settings model - * is located in package com.eveningoutpost.dexdrip.Services.broadcastservice.models and + * is located in package com.eveningoutpost.dexdrip.services.broadcastservice.models and * xdrip code replacing 'Services' package name to lowercase 'services' name after * apk compilation, the thirdparty application should use the following package * com.eveningoutpost.dexdrip.services.broadcastservice.models for the settings model. @@ -209,7 +217,6 @@ public void onReceive(Context context, Intent intent) { } }; - @Override public IBinder onBind(Intent intent) { return null; @@ -227,6 +234,7 @@ public void onCreate() { registerReceiver(broadcastReceiver, new IntentFilter(ACTION_WATCH_COMMUNICATION_RECEIVER)); JoH.startService(BroadcastService.class, Const.INTENT_FUNCTION_KEY, Const.CMD_START); + super.onCreate(); } @@ -294,6 +302,9 @@ private void handleCommand(String function, Intent intent) { bundle.putString("message", intent.getStringExtra("message")); sendBroadcast(function, receiver, bundle); break; + case Const.CMD_CANCEL_ALERT: + sendBroadcast(function, receiver, bundle); + break; } } @@ -318,6 +329,9 @@ private void handleCommand(String function, Intent intent) { broadcastModel = broadcastEntities.get(receiver); bundle = prepareBgBundle(broadcastModel); break; + case Const.CMD_CANCEL_ALERT: + receiver = null; //broadcast + break; case Const.CMD_SNOOZE_ALERT: String alertName = ""; String replyMsg = ""; @@ -513,7 +527,7 @@ protected Bundle prepareBgBundle(BroadcastModel broadcastModel) { bundle.putDouble("lowMark", JoH.tolerantParseDouble(prefs.getString("lowValue", "70"), 70)); BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(xdrip.getAppContext(), start, end); - bgGraphBuilder.defaultLines(true); // simple mode + bgGraphBuilder.defaultLines(false); // not simple mode in order to receive simulated data bundle.putParcelable("graph.lowLine", new GraphLine(bgGraphBuilder.lowLine())); bundle.putParcelable("graph.highLine", new GraphLine(bgGraphBuilder.highLine())); @@ -530,7 +544,25 @@ protected Bundle prepareBgBundle(BroadcastModel broadcastModel) { bundle.putParcelable("graph.cob", new GraphLine(treatments[6])); //cobValues bundle.putParcelable("graph.polyBg", new GraphLine(treatments[7])); //poly predict ; } + + String last_iob = keyStore.getS("last_iob"); + if ( last_iob != null){ + bundle.putString("predict.IOB", last_iob); + bundle.putLong("predict.IOB.timeStamp", keyStore.getL("last_iob_timestamp")); + } + + String last_bwp = keyStore.getS("last_bwp"); + if ( last_bwp != null){ + bundle.putString("predict.BWP", last_bwp); + bundle.putLong("predict.BWP.timeStamp", keyStore.getL("last_bwp_timestamp")); + } + + // External status line from AAPS added + bundle.putString("external.statusLine", getLastStatusLine()); + bundle.putLong("external.timeStamp", getLastStatusLineTime()); + } return bundle; } + } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/Const.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/Const.java similarity index 92% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/Const.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/Const.java index acc3cf91b2..81120aa647 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/Const.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/Const.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services.broadcastservice; +package com.eveningoutpost.dexdrip.services.broadcastservice; public class Const { public static final String BG_ALERT_TYPE = "BG_ALERT_TYPE"; @@ -19,6 +19,7 @@ public class Const { public static final String CMD_SET_SETTINGS = "set_settings"; public static final String CMD_UPDATE_BG_FORCE = "update_bg_force"; public static final String CMD_ALERT = "alarm"; + public static final String CMD_CANCEL_ALERT = "cancel_alarm"; public static final String CMD_SNOOZE_ALERT = "snooze_alarm"; public static final String CMD_ADD_STEPS = "add_steps"; public static final String CMD_ADD_HR = "add_hrs"; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/models/BroadcastModel.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/models/BroadcastModel.java similarity index 85% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/models/BroadcastModel.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/models/BroadcastModel.java index 85f3698d7c..104d8f6f9a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/models/BroadcastModel.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/models/BroadcastModel.java @@ -1,9 +1,9 @@ -package com.eveningoutpost.dexdrip.Services.broadcastservice.models; +package com.eveningoutpost.dexdrip.services.broadcastservice.models; import android.os.Bundle; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; public class BroadcastModel { private Settings settings; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/models/GraphLine.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/models/GraphLine.java similarity index 77% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/models/GraphLine.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/models/GraphLine.java index e183e85db6..6924752dfd 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/models/GraphLine.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/models/GraphLine.java @@ -1,10 +1,8 @@ -package com.eveningoutpost.dexdrip.Services.broadcastservice.models; +package com.eveningoutpost.dexdrip.services.broadcastservice.models; import android.os.Parcel; import android.os.Parcelable; -import com.eveningoutpost.dexdrip.UtilityModels.HPointValue; - import java.util.ArrayList; import java.util.List; @@ -42,11 +40,8 @@ public GraphLine(Line line) { values = new ArrayList<>(); line.update(0); for (PointValue pointValue : line.getValues()) { - float real_timestamp = pointValue.getX(); - if (pointValue instanceof HPointValue) { - real_timestamp = (float) HPointValue.unconvert(real_timestamp); - } - values.add(new GraphPoint(real_timestamp, pointValue.getY())); + double real_timestamp = pointValue.getX(); + values.add(new GraphPoint((float)real_timestamp, (float)pointValue.getY())); } color = line.getColor(); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/models/GraphPoint.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/models/GraphPoint.java similarity index 94% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/models/GraphPoint.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/models/GraphPoint.java index 1badf89108..d6742c7ca5 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/models/GraphPoint.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/models/GraphPoint.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services.broadcastservice.models; +package com.eveningoutpost.dexdrip.services.broadcastservice.models; import android.os.Parcel; import android.os.Parcelable; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/models/Settings.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/models/Settings.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/models/Settings.java rename to app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/models/Settings.java index 593a8cec95..7e0506408d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/models/Settings.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/models/Settings.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.Services.broadcastservice.models; +package com.eveningoutpost.dexdrip.services.broadcastservice.models; import android.os.Parcel; import android.os.Parcelable; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/BgUploader.java b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/BgUploader.java similarity index 89% rename from app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/BgUploader.java rename to app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/BgUploader.java index 08f5bc3b23..75cbe13f56 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/BgUploader.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/BgUploader.java @@ -1,8 +1,8 @@ -package com.eveningoutpost.dexdrip.ShareModels; +package com.eveningoutpost.dexdrip.sharemodels; import android.content.Context; -import com.eveningoutpost.dexdrip.ShareModels.Models.ShareUploadPayload; +import com.eveningoutpost.dexdrip.sharemodels.models.ShareUploadPayload; import com.squareup.okhttp.ResponseBody; import retrofit.Callback; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/DexcomShare.java b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/DexcomShare.java similarity index 94% rename from app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/DexcomShare.java rename to app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/DexcomShare.java index f3a4ce12c9..7e74a1f8c7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/DexcomShare.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/DexcomShare.java @@ -1,9 +1,9 @@ -package com.eveningoutpost.dexdrip.ShareModels; +package com.eveningoutpost.dexdrip.sharemodels; -import com.eveningoutpost.dexdrip.ShareModels.Models.ExistingFollower; -import com.eveningoutpost.dexdrip.ShareModels.Models.InvitationPayload; -import com.eveningoutpost.dexdrip.ShareModels.Models.ShareUploadPayload; -import com.eveningoutpost.dexdrip.ShareModels.UserAgentInfo.UserAgent; +import com.eveningoutpost.dexdrip.sharemodels.models.ExistingFollower; +import com.eveningoutpost.dexdrip.sharemodels.models.InvitationPayload; +import com.eveningoutpost.dexdrip.sharemodels.models.ShareUploadPayload; +import com.eveningoutpost.dexdrip.sharemodels.useragentinfo.UserAgent; import com.squareup.okhttp.ResponseBody; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/ShareRest.java b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/ShareRest.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/ShareRest.java rename to app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/ShareRest.java index 9ca96cf127..013389c395 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/ShareRest.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/ShareRest.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.ShareModels; +package com.eveningoutpost.dexdrip.sharemodels; import android.content.Context; import android.content.SharedPreferences; @@ -6,11 +6,11 @@ import android.preference.PreferenceManager; import android.util.Log; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.ShareModels.Models.ExistingFollower; -import com.eveningoutpost.dexdrip.ShareModels.Models.InvitationPayload; -import com.eveningoutpost.dexdrip.ShareModels.Models.ShareAuthenticationBody; -import com.eveningoutpost.dexdrip.ShareModels.Models.ShareUploadPayload; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.sharemodels.models.ExistingFollower; +import com.eveningoutpost.dexdrip.sharemodels.models.InvitationPayload; +import com.eveningoutpost.dexdrip.sharemodels.models.ShareAuthenticationBody; +import com.eveningoutpost.dexdrip.sharemodels.models.ShareUploadPayload; import com.eveningoutpost.dexdrip.xdrip; import com.google.gson.Gson; import com.google.gson.GsonBuilder; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/ShareModels/ShareUploadableBg.java b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/ShareUploadableBg.java similarity index 89% rename from wear/src/main/java/com/eveningoutpost/dexdrip/ShareModels/ShareUploadableBg.java rename to app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/ShareUploadableBg.java index 222f742b35..489432cace 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/ShareModels/ShareUploadableBg.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/ShareUploadableBg.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.ShareModels; +package com.eveningoutpost.dexdrip.sharemodels; /** * Created by Emma Black on 8/10/15. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/Egv.java b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/Egv.java similarity index 87% rename from app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/Egv.java rename to app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/Egv.java index c36c2e1de9..f8e06851e2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/Egv.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/Egv.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.ShareModels.Models; +package com.eveningoutpost.dexdrip.sharemodels.models; -import com.eveningoutpost.dexdrip.ShareModels.ShareUploadableBg; +import com.eveningoutpost.dexdrip.sharemodels.ShareUploadableBg; import com.google.gson.annotations.Expose; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/ExistingFollower.java b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/ExistingFollower.java similarity index 93% rename from app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/ExistingFollower.java rename to app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/ExistingFollower.java index e5c29b661e..d4027e8b01 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/ExistingFollower.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/ExistingFollower.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.ShareModels.Models; +package com.eveningoutpost.dexdrip.sharemodels.models; import com.google.gson.annotations.Expose; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/InvitationPayload.java b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/InvitationPayload.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/InvitationPayload.java rename to app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/InvitationPayload.java index 936b888c50..d47f59bf70 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/InvitationPayload.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/InvitationPayload.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.ShareModels.Models; +package com.eveningoutpost.dexdrip.sharemodels.models; import com.google.gson.annotations.Expose; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/ShareAuthenticationBody.java b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/ShareAuthenticationBody.java similarity index 93% rename from app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/ShareAuthenticationBody.java rename to app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/ShareAuthenticationBody.java index f6730e26ea..c2c91f1640 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/ShareAuthenticationBody.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/ShareAuthenticationBody.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.ShareModels.Models; +package com.eveningoutpost.dexdrip.sharemodels.models; import com.google.gson.annotations.Expose; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/ShareGlucose.java b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/ShareGlucose.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/ShareGlucose.java rename to app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/ShareGlucose.java index 9a5372795f..f9213640f9 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/ShareGlucose.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/ShareGlucose.java @@ -1,11 +1,11 @@ -package com.eveningoutpost.dexdrip.ShareModels.Models; +package com.eveningoutpost.dexdrip.sharemodels.models; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.BatteryManager; import android.provider.BaseColumns; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.activeandroid.Model; import com.activeandroid.annotation.Column; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/ShareUploadPayload.java b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/ShareUploadPayload.java similarity index 81% rename from app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/ShareUploadPayload.java rename to app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/ShareUploadPayload.java index b72b2b148b..5fc46fb3e2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/Models/ShareUploadPayload.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/models/ShareUploadPayload.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.ShareModels.Models; +package com.eveningoutpost.dexdrip.sharemodels.models; -import com.eveningoutpost.dexdrip.ShareModels.ShareUploadableBg; +import com.eveningoutpost.dexdrip.sharemodels.ShareUploadableBg; import com.google.gson.annotations.Expose; import java.util.ArrayList; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/UserAgentInfo/RuntimeInfo.java b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/useragentinfo/RuntimeInfo.java similarity index 89% rename from app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/UserAgentInfo/RuntimeInfo.java rename to app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/useragentinfo/RuntimeInfo.java index b36bd37031..2610b23e32 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/UserAgentInfo/RuntimeInfo.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/useragentinfo/RuntimeInfo.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.ShareModels.UserAgentInfo; +package com.eveningoutpost.dexdrip.sharemodels.useragentinfo; import com.google.gson.annotations.Expose; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/UserAgentInfo/UserAgent.java b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/useragentinfo/UserAgent.java similarity index 71% rename from app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/UserAgentInfo/UserAgent.java rename to app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/useragentinfo/UserAgent.java index 6a8d36248f..19a5ac8371 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ShareModels/UserAgentInfo/UserAgent.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/sharemodels/useragentinfo/UserAgent.java @@ -1,6 +1,5 @@ -package com.eveningoutpost.dexdrip.ShareModels.UserAgentInfo; +package com.eveningoutpost.dexdrip.sharemodels.useragentinfo; -import com.eveningoutpost.dexdrip.ShareModels.UserAgentInfo.RuntimeInfo; import com.google.gson.annotations.Expose; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/stats/ChartFragment.java b/app/src/main/java/com/eveningoutpost/dexdrip/stats/ChartFragment.java index 70ca9e6628..0a005f3cdc 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/stats/ChartFragment.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/stats/ChartFragment.java @@ -1,9 +1,10 @@ package com.eveningoutpost.dexdrip.stats; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +import com.eveningoutpost.dexdrip.models.UserError.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/stats/ChartView.java b/app/src/main/java/com/eveningoutpost/dexdrip/stats/ChartView.java index 6c37688215..6a324bea08 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/stats/ChartView.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/stats/ChartView.java @@ -7,7 +7,7 @@ import android.graphics.Paint; import android.graphics.RectF; import android.util.DisplayMetrics; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; import android.view.View; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/stats/DBSearchUtil.java b/app/src/main/java/com/eveningoutpost/dexdrip/stats/DBSearchUtil.java index 12ac99b24a..57b296c767 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/stats/DBSearchUtil.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/stats/DBSearchUtil.java @@ -6,13 +6,13 @@ import android.database.sqlite.SQLiteDatabase; import android.preference.PreferenceManager; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.activeandroid.Cache; import com.activeandroid.query.Select; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import java.util.Calendar; import java.util.GregorianCalendar; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/stats/FirstPageFragment.java b/app/src/main/java/com/eveningoutpost/dexdrip/stats/FirstPageFragment.java index 9e183c8762..b5a33d67f3 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/stats/FirstPageFragment.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/stats/FirstPageFragment.java @@ -1,19 +1,23 @@ package com.eveningoutpost.dexdrip.stats; +import static android.app.PendingIntent.getActivity; + + import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +import com.eveningoutpost.dexdrip.models.UserError.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants; import com.eveningoutpost.dexdrip.R; import java.text.DecimalFormat; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/stats/PercentileFragment.java b/app/src/main/java/com/eveningoutpost/dexdrip/stats/PercentileFragment.java index 85984b558e..363b6269c5 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/stats/PercentileFragment.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/stats/PercentileFragment.java @@ -1,9 +1,10 @@ package com.eveningoutpost.dexdrip.stats; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +import com.eveningoutpost.dexdrip.models.UserError.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/stats/PercentileView.java b/app/src/main/java/com/eveningoutpost/dexdrip/stats/PercentileView.java index df68e80665..26fd1c5211 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/stats/PercentileView.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/stats/PercentileView.java @@ -12,12 +12,12 @@ import android.preference.PreferenceManager; import android.util.DisplayMetrics; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; import android.view.View; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import java.util.Calendar; import java.util.Collections; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/stats/StatsActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/stats/StatsActivity.java index 9be4f2718a..e4d8e82f13 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/stats/StatsActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/stats/StatsActivity.java @@ -9,13 +9,15 @@ import android.os.Build; import android.os.Bundle; import android.os.Environment; -import android.support.annotation.NonNull; -import android.support.v4.app.ActivityCompat; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentStatePagerAdapter; -import android.support.v4.content.ContextCompat; -import android.support.v4.view.ViewPager; +import androidx.annotation.NonNull; +import androidx.core.app.ActivityCompat; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentPagerAdapter; +import androidx.core.content.ContextCompat; +import androidx.fragment.app.FragmentStatePagerAdapter; +import androidx.viewpager.widget.ViewPager; + import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -25,19 +27,19 @@ import android.widget.TextView; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.JamorhamShowcaseDrawer; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.ShotStateStore; +import com.eveningoutpost.dexdrip.utilitymodels.JamorhamShowcaseDrawer; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.ShotStateStore; import com.eveningoutpost.dexdrip.utils.ActivityWithMenu; import com.github.amlcurran.showcaseview.ShowcaseView; import com.github.amlcurran.showcaseview.targets.ViewTarget; import java.io.File; -import static com.eveningoutpost.dexdrip.Models.JoH.goFullScreen; +import static com.eveningoutpost.dexdrip.models.JoH.goFullScreen; import static com.eveningoutpost.dexdrip.R.id.pager; public class StatsActivity extends ActivityWithMenu { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/stats/StatsResult.java b/app/src/main/java/com/eveningoutpost/dexdrip/stats/StatsResult.java index cf825e639c..39de6d1b13 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/stats/StatsResult.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/stats/StatsResult.java @@ -5,10 +5,10 @@ import android.database.sqlite.SQLiteDatabase; import com.activeandroid.Cache; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import java.text.DecimalFormat; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/store/FastStore.java b/app/src/main/java/com/eveningoutpost/dexdrip/store/FastStore.java index 3cb4e15e88..621d2fed32 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/store/FastStore.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/store/FastStore.java @@ -1,6 +1,7 @@ package com.eveningoutpost.dexdrip.store; import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; /** * Created by jamorham on 08/11/2017. @@ -15,8 +16,8 @@ public class FastStore implements KeyStore { private static final FastStore mFastStore = new FastStore(); - private static final HashMap stringStore = new HashMap<>(); - private static final HashMap longStore = new HashMap<>(); + private static final ConcurrentHashMap stringStore = new ConcurrentHashMap<>(); + private static final ConcurrentHashMap longStore = new ConcurrentHashMap<>(); // we trade substitution flexibility at the expense of some object creation diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tables/BgReadingTable.java b/app/src/main/java/com/eveningoutpost/dexdrip/tables/BgReadingTable.java index c16bc2f659..a3ffaa759d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tables/BgReadingTable.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tables/BgReadingTable.java @@ -5,7 +5,9 @@ import android.content.DialogInterface; import android.graphics.Color; import android.os.Bundle; -import android.support.v4.widget.DrawerLayout; + +import androidx.drawerlayout.widget.DrawerLayout; + import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -14,19 +16,24 @@ import android.widget.TextView; import com.eveningoutpost.dexdrip.BaseListActivity; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.NavigationDrawerFragment; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utils.DexCollectionType; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Locale; import static com.eveningoutpost.dexdrip.xdrip.gs; +import lombok.val; + public class BgReadingTable extends BaseListActivity implements NavigationDrawerFragment.NavigationDrawerCallbacks { private String menu_name = "BG Data Table"; @@ -55,9 +62,39 @@ public void onNavigationDrawerItemSelected(int position) { private void getData() { final List latest = BgReading.latest(5000); + parseDataForStats(latest); ListAdapter adapter = new BgReadingAdapter(this, latest); - this.setListAdapter(adapter); + try { + if (total > 0) { + this.getActionBar().setSubtitle(String.format(Locale.getDefault(), "%d in 24h, bf:%d%% mis:%d", total, ((backfilled * 100) / total), missing)); + } + } catch (NullPointerException e) { + // + } + } + + private int missing; + private int backfilled; + private int total; + + private void parseDataForStats(List list) { + long cutoff = JoH.tsl() - Constants.DAY_IN_MS; + long oldest = 0; + for (val item : list) { + if (item.timestamp < cutoff) break; + oldest = item.timestamp; + total++; + if (item.source_info != null && item.source_info.contains("Backfill")) { + backfilled++; + } + } + + if (total > 0) { + val expectedReadings = (JoH.tsl() - oldest) / DexCollectionType.getCurrentSamplePeriod(); + missing = (int) (expectedReadings - total); + } + } public static class BgReadingCursorAdapterViewHolder { @@ -75,12 +112,12 @@ public BgReadingCursorAdapterViewHolder(View root) { } public static class BgReadingAdapter extends BaseAdapter { - private final Context context; + private final Context context; private final List readings; public BgReadingAdapter(Context context, List readings) { this.context = context; - if(readings == null) + if (readings == null) readings = new ArrayList<>(); this.readings = readings; @@ -119,19 +156,21 @@ public boolean onLongClick(View v) { DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - switch (which){ + switch (which) { case DialogInterface.BUTTON_POSITIVE: bgReading.ignoreForStats = true; bgReading.save(); notifyDataSetChanged(); - if (Pref.getBooleanDefaultFalse("wear_sync")) BgReading.pushBgReadingSyncToWatch(bgReading, false); + if (Pref.getBooleanDefaultFalse("wear_sync")) + BgReading.pushBgReadingSyncToWatch(bgReading, false); break; case DialogInterface.BUTTON_NEGATIVE: bgReading.ignoreForStats = false; bgReading.save(); notifyDataSetChanged(); - if (Pref.getBooleanDefaultFalse("wear_sync")) BgReading.pushBgReadingSyncToWatch(bgReading, false); + if (Pref.getBooleanDefaultFalse("wear_sync")) + BgReading.pushBgReadingSyncToWatch(bgReading, false); break; } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tables/CalibrationDataTable.java b/app/src/main/java/com/eveningoutpost/dexdrip/tables/CalibrationDataTable.java index 58bf4ddb49..972b6608c1 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tables/CalibrationDataTable.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tables/CalibrationDataTable.java @@ -5,7 +5,7 @@ import android.content.DialogInterface; import android.graphics.Color; import android.os.Bundle; -import android.support.v4.widget.DrawerLayout; + import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -13,17 +13,19 @@ import android.widget.TextView; import com.eveningoutpost.dexdrip.BaseListActivity; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.NavigationDrawerFragment; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; import java.util.ArrayList; import java.util.List; import static com.eveningoutpost.dexdrip.xdrip.gs; +import androidx.drawerlayout.widget.DrawerLayout; + public class CalibrationDataTable extends BaseListActivity implements NavigationDrawerFragment.NavigationDrawerCallbacks { private static final String menu_name = "Calibration Data Table"; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tables/SensorDataTable.java b/app/src/main/java/com/eveningoutpost/dexdrip/tables/SensorDataTable.java index 5c2ab240bc..5f04a5c919 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tables/SensorDataTable.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tables/SensorDataTable.java @@ -2,10 +2,13 @@ import android.database.Cursor; import android.os.Bundle; -import android.support.v4.widget.DrawerLayout; + + import android.view.View; import android.widget.SimpleCursorAdapter; +import androidx.drawerlayout.widget.DrawerLayout; + import com.activeandroid.Cache; import com.eveningoutpost.dexdrip.BaseListActivity; import com.eveningoutpost.dexdrip.NavigationDrawerFragment; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/AuthFlowIn.java b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/AuthFlowIn.java new file mode 100644 index 0000000000..9c34ca526c --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/AuthFlowIn.java @@ -0,0 +1,190 @@ +package com.eveningoutpost.dexdrip.tidepool; + +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.pratelimit; +import static com.eveningoutpost.dexdrip.tidepool.AuthFlowOut.eraseAuthState; + +import android.content.Intent; +import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; + +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; + +import net.openid.appauth.AppAuthConfiguration; +import net.openid.appauth.AuthorizationException; +import net.openid.appauth.AuthorizationResponse; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.atomic.AtomicReference; + +import lombok.val; +import okio.Okio; + +/** + * JamOrHam + *

+ * Handle inbound authentication events for Tidepool new authentication mechanism + */ + +public class AuthFlowIn extends AppCompatActivity { + + private static final String TAG = "TidePoolAuth"; + private static final String PREF_TIDEPOOL_USER_NAME = "tidepool_username"; + private static final String PREF_TIDEPOOL_SUB_NAME = "tidepool_subname"; + + final AtomicReference userInfo = new AtomicReference<>(); + + public void onCreate(final Bundle savedInstanceBundle) { + super.onCreate(savedInstanceBundle); + Log.d(TAG, "Got response"); + Inevitable.task("tidepool-process-auth", 10, () -> processIntent(getIntent())); + this.finish(); + } + + private void processIntent(final Intent intent) { + val authorizationResponse = AuthorizationResponse.fromIntent(intent); + val authorizationException = AuthorizationException.fromIntent(intent); + val state = AuthFlowOut.getAuthState(); + if (state == null) { + Log.wtf(TAG, "Could not get auth state"); + return; + } + state.update(authorizationResponse, authorizationException); + if (authorizationException != null) { + Log.d(TAG, "Got authorization error - resetting state: " + authorizationException); + eraseAuthState(); + } + if (authorizationResponse != null) { + // authorization completed + AuthFlowOut.saveAuthState(); + + val service = AuthFlowOut.getAuthService(); + service.performTokenRequest( + authorizationResponse.createTokenExchangeRequest(), + (tokenResponse, exception) -> { + state.update(tokenResponse, exception); + if (exception != null) { + Log.d(TAG, "Token request exception: " + exception); + eraseAuthState(); + } + if (tokenResponse != null) { + Log.d(TAG, "Got first token"); + AuthFlowOut.saveAuthState(); + + val configuration = state.getAuthorizationServiceConfiguration(); + if (configuration == null) { + Log.wtf(TAG, "Got null for authorization service configuration"); + return; + } + val discoveryDoc = configuration.discoveryDoc; + if (discoveryDoc == null) { + Log.wtf(TAG, "Got null for discoveryDoc"); + return; + } + val userInfoEndpoint = discoveryDoc.getUserinfoEndpoint(); + if (userInfoEndpoint == null) { + Log.wtf(TAG, "Got null for userInfoEndpoint"); + return; + } + + Inevitable.task("tidepool-get-userinfo", 100, () -> { + try { + val conn = AppAuthConfiguration.DEFAULT.getConnectionBuilder() + .openConnection(userInfoEndpoint); + // TODO should hardcoded Bearer be replaced by token type? + conn.setRequestProperty("Authorization", "Bearer " + tokenResponse.accessToken); + conn.setInstanceFollowRedirects(false); + val response = Okio.buffer(Okio.source(conn.getInputStream())) + .readString(StandardCharsets.UTF_8); + Log.d(TAG, "UserInfo: " + response); + userInfo.set(new JSONObject(response)); + + state.performActionWithFreshTokens(service, (accessToken, idToken, authorizationException1) -> { + if (authorizationException1 != null) { + Log.e(TAG, "Got fresh token exception: " + authorizationException1); + return; + } + val session = new Session(tokenResponse.tokenType, TidepoolUploader.getSESSION_TOKEN_HEADER()); + session.authReply = new MAuthReply(idToken); + session.token = accessToken; + try { + val email = userInfo.get().getString("email"); + if (!emptyString(email)) { + Log.d(TAG, "Setting username to: " + email); + Pref.setString(PREF_TIDEPOOL_USER_NAME, email); + } else { + Log.wtf(TAG, "Could not get userinfo email"); + } + session.authReply.userid = userInfo.get().getString("sub"); + if (!emptyString(session.authReply.userid)) { + Pref.setString(PREF_TIDEPOOL_SUB_NAME, session.authReply.userid); + TidepoolUploader.startSession(session, true); + } else { + Log.wtf(TAG, "Could not get 'sub' field - cannot proceed"); + } + } catch (JSONException e) { + Log.wtf(TAG, "Getting Access Token 1 Exception: " + e); + } + }); + + } catch (IOException ioException) { + Log.e(TAG, "Network error when querying userinfo endpoint", ioException); + } catch (JSONException jsonException) { + Log.e(TAG, "Failed to parse userinfo response"); + } + }); + + } else { + Log.e(TAG, "First token err: " + exception); + } + }); + + } else { + Log.e(TAG, "Got response failure " + authorizationException.toString()); + } + } + + public static void handleTokenLoginAndStartSession() { + val state = AuthFlowOut.getAuthState(); + if (state != null) { + val service = AuthFlowOut.getAuthService(); + state.performActionWithFreshTokens(service, (accessToken, idToken, tokenException) -> { + if (tokenException != null) { + Log.e(TAG, "Got exception token: " + tokenException); + } + if (accessToken != null) { + val lastReponse = state.getLastTokenResponse(); + if (lastReponse != null) { + val session = new Session(lastReponse.tokenType, TidepoolUploader.getSESSION_TOKEN_HEADER()); + session.authReply = new MAuthReply(idToken); + session.token = accessToken; + session.authReply.userid = Pref.getStringDefaultBlank(PREF_TIDEPOOL_SUB_NAME); + TidepoolUploader.startSession(session, false); + AuthFlowOut.saveAuthState(); + } else { + Log.e(TAG, "Failing to get response / token type - trying initial login again"); + retryInitialLogin(); + } + } else { + Log.e(TAG, "Failing to use access token - trying initial login again"); + retryInitialLogin(); + } + }); + } else { + Log.e(TAG, "Failing to get state - trying initial login"); + retryInitialLogin(); + } + } + + private static void retryInitialLogin() { + if (pratelimit("tidepool-retry-login", 600)) { + AuthFlowOut.doTidePoolInitialLogin(); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/AuthFlowOut.java b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/AuthFlowOut.java new file mode 100644 index 0000000000..533e51873e --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/AuthFlowOut.java @@ -0,0 +1,170 @@ +package com.eveningoutpost.dexdrip.tidepool; + +import android.annotation.SuppressLint; +import android.app.PendingIntent; +import android.content.Intent; +import android.net.Uri; +import android.util.Base64; +import android.util.Log; + +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utils.CipherUtils; +import com.eveningoutpost.dexdrip.xdrip; + +import net.openid.appauth.AppAuthConfiguration; +import net.openid.appauth.AuthState; +import net.openid.appauth.AuthorizationRequest; +import net.openid.appauth.AuthorizationService; +import net.openid.appauth.AuthorizationServiceConfiguration; +import net.openid.appauth.ResponseTypeValues; +import net.openid.appauth.browser.BrowserAllowList; +import net.openid.appauth.browser.VersionedBrowserMatcher; + +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import lombok.val; + +/** + * JamOrHam + *

+ * Handler for new style Tidepool openid auth + */ + +@SuppressLint("StaticFieldLeak") +public class AuthFlowOut { + + private static final String TAG = "TidePoolAuth"; + + private static final String MY_CLIENT_ID = "xdrip"; + private static final Uri MY_REDIRECT_URI = Uri.parse("xdrip://callback/tidepool"); + + private static volatile AuthState authState; + private static volatile AuthorizationService authService; + + private static final String INTEGRATION_BASE_URL = "https://auth.integration.tidepool.org/realms/integration"; + private static final String PRODUCTION_BASE_URL = "https://auth.tidepool.org/realms/tidepool"; + + private static final String PREF_TIDEPOOL_SERVICE_CONFIGURATON = "tidepool-service-configuration"; + private static final String PREF_TIDEPOOL_STATE_STORE = "tidepool-last-response"; + + public static AuthState getAuthState() { + if (authState == null) { + try { + authState = new AuthState(AuthorizationServiceConfiguration.fromJson(Pref.getStringDefaultBlank(PREF_TIDEPOOL_SERVICE_CONFIGURATON))); + authState = AuthState.jsonDeserialize(Pref.getStringDefaultBlank(PREF_TIDEPOOL_STATE_STORE)); + Log.d(TAG, "Auth state loaded with: " + authState.getAccessToken()); + } catch (Exception e) { + Log.d(TAG, "Error during getAuthState - could just be empty cache data: " + e); + } + } + return authState; + } + + public static void saveAuthState() { + val state = authState; + if (state != null) { + Pref.setString(PREF_TIDEPOOL_STATE_STORE, state.jsonSerializeString()); + } + } + + public static void eraseAuthState() { + Pref.setString(PREF_TIDEPOOL_STATE_STORE, ""); + } + + public static AuthorizationService getAuthService() { + if (authService == null) { + val appAuthConfig = new AppAuthConfiguration.Builder() + .setBrowserMatcher(new BrowserAllowList( + VersionedBrowserMatcher.CHROME_CUSTOM_TAB, + VersionedBrowserMatcher.FIREFOX_CUSTOM_TAB, + VersionedBrowserMatcher.SAMSUNG_CUSTOM_TAB)) + .build(); + + authService = new AuthorizationService(xdrip.getAppContext(), appAuthConfig); + } + return authService; + } + + private static synchronized void resetAll() { + authState = null; + authService = null; + getAuthService(); + getAuthState(); + } + + public static synchronized void clearAllSavedData() { + Pref.setString(PREF_TIDEPOOL_SERVICE_CONFIGURATON, ""); + eraseAuthState(); + resetAll(); + } + + public static void doTidePoolInitialLogin() { + doTidePoolInitialLogin(false); + } + + public static void doTidePoolInitialLogin(boolean full) { + + if (!Pref.getBooleanDefaultFalse("tidepool_new_auth")) { + Log.d(TAG, "Not using new authentication mechanism"); + return; + } + + val context = xdrip.getAppContext(); + JoH.static_toast_long("Connecting to Tidepool"); // TODO I18n + AuthorizationServiceConfiguration.fetchFromIssuer( + Uri.parse((Pref.getBooleanDefaultFalse("tidepool_dev_servers") + ? INTEGRATION_BASE_URL : PRODUCTION_BASE_URL)), + (serviceConfiguration, error) -> { + if (error != null || serviceConfiguration == null) { + Log.e(TAG, "failed to fetch configuration"); + return; + } + + Pref.setString(PREF_TIDEPOOL_SERVICE_CONFIGURATON, serviceConfiguration.toJsonString()); + resetAll(); + + val codeVerifierChallengeMethod = "S256"; + val messageDigestAlgorithm = "SHA-256"; + val encoding = Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP; + val challenge = CipherUtils.getRandomKey(64); + val codeVerifier = Base64.encodeToString(challenge, encoding); + MessageDigest digest; + try { + digest = MessageDigest.getInstance(messageDigestAlgorithm); + } catch (NoSuchAlgorithmException e) { + Log.wtf(TAG, "Failed to get message digest: " + e); + return; + } + val hash = digest.digest(codeVerifier.getBytes(StandardCharsets.UTF_8)); + val codeChallenge = Base64.encodeToString(hash, encoding); + + val authRequestBuilder = new AuthorizationRequest.Builder( + serviceConfiguration, // the authorization service configuration + MY_CLIENT_ID, // the client ID, typically pre-registered and static + ResponseTypeValues.CODE, // the response_type value: we want a code + MY_REDIRECT_URI); // the redirect URI to which the auth response is sent + + authRequestBuilder + .setScopes("openid", "offline_access") + .setLoginHint(Pref.getString("tidepool_username", "")) + .setCodeVerifier(codeVerifier, codeChallenge, codeVerifierChallengeMethod); + + if (full) { + // full relogin wanted + authRequestBuilder.setPrompt("login"); + } + + val authRequest = authRequestBuilder.build(); + + Log.d(TAG, "Firing off request"); + getAuthService().performAuthorizationRequest( + authRequest, + // TODO will need mutability flag in later target sdk versions + PendingIntent.getActivity(context, 0, new Intent(context, AuthFlowIn.class), 0), + PendingIntent.getActivity(context, 0, new Intent(context, AuthFlowIn.class), 0)); + }); + } +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/BaseMessage.java b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/BaseMessage.java index c96d3da1c4..1e3bb2bdf3 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/BaseMessage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/BaseMessage.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.tidepool; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import okhttp3.MediaType; import okhttp3.RequestBody; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/EBasal.java b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/EBasal.java index 96819ba31c..b8bf2bfdbc 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/EBasal.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/EBasal.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.tidepool; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.google.gson.annotations.Expose; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/EBloodGlucose.java b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/EBloodGlucose.java index 31242be0dc..3a696dda81 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/EBloodGlucose.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/EBloodGlucose.java @@ -2,9 +2,8 @@ // jamorham -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.UserError; import com.google.gson.annotations.Expose; import java.util.LinkedList; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/EBolus.java b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/EBolus.java index da60fe54bf..b72765de09 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/EBolus.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/EBolus.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.tidepool; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; import com.google.gson.annotations.Expose; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/ESensorGlucose.java b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/ESensorGlucose.java index c6b8f0bd84..8e0558d016 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/ESensorGlucose.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/ESensorGlucose.java @@ -2,8 +2,8 @@ // jamorham -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.UserError; import com.google.gson.annotations.Expose; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/EWizard.java b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/EWizard.java index aac37c8511..4c2f1bfd3d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/EWizard.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/EWizard.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip.tidepool; -import com.eveningoutpost.dexdrip.Models.Profile; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.Profile; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; import com.google.gson.annotations.Expose; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/InfoInterceptor.java b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/InfoInterceptor.java index e6da78bf99..0a23de4343 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/InfoInterceptor.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/InfoInterceptor.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip.tidepool; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import java.io.IOException; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/MAuthReply.java b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/MAuthReply.java index 77dc6e0739..88e0f274cc 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/MAuthReply.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/MAuthReply.java @@ -2,7 +2,7 @@ // jamorham -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; @@ -29,6 +29,10 @@ public class MAuthReply { @SerializedName("username") String username; + public MAuthReply(final String userid) { + this.userid = userid; + } + public String toS() { return JoH.defaultGsonInstance().toJson(this); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/MAuthRequest.java b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/MAuthRequest.java index a5b9a6a43c..e59fd56922 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/MAuthRequest.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/MAuthRequest.java @@ -2,11 +2,11 @@ // jamorham -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import okhttp3.Credentials; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; public class MAuthRequest extends BaseMessage { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/MOpenDatasetRequest.java b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/MOpenDatasetRequest.java index 072aaced3f..2edecd8388 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/MOpenDatasetRequest.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/MOpenDatasetRequest.java @@ -1,14 +1,14 @@ package com.eveningoutpost.dexdrip.tidepool; import com.eveningoutpost.dexdrip.BuildConfig; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.google.gson.annotations.Expose; import java.util.TimeZone; -import static com.eveningoutpost.dexdrip.Models.JoH.getTimeZoneOffsetMs; +import static com.eveningoutpost.dexdrip.models.JoH.getTimeZoneOffsetMs; public class MOpenDatasetRequest extends BaseMessage { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/TidepoolCallback.java b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/TidepoolCallback.java index 6d6b3aad76..2167036203 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/TidepoolCallback.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/TidepoolCallback.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.tidepool; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.store.FastStore; import lombok.RequiredArgsConstructor; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/TidepoolEntry.java b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/TidepoolEntry.java index 1cd5ef5e25..7af837c151 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/TidepoolEntry.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/TidepoolEntry.java @@ -4,10 +4,10 @@ // lightweight class entry point -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; -import static com.eveningoutpost.dexdrip.Models.JoH.isLANConnected; +import static com.eveningoutpost.dexdrip.models.JoH.isLANConnected; import static com.eveningoutpost.dexdrip.utils.PowerStateReceiver.is_power_connected; public class TidepoolEntry { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/TidepoolStatus.java b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/TidepoolStatus.java index 82e76c4d1f..34836795cf 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/TidepoolStatus.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/TidepoolStatus.java @@ -2,16 +2,16 @@ // jamorham -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; import com.eveningoutpost.dexdrip.store.FastStore; import com.eveningoutpost.dexdrip.store.KeyStore; import java.util.ArrayList; import java.util.List; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.Models.JoH.niceTimeScalar; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.niceTimeScalar; public class TidepoolStatus { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/TidepoolUploader.java b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/TidepoolUploader.java index 0e395c54c0..69b2a8a96b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/TidepoolUploader.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/TidepoolUploader.java @@ -1,16 +1,19 @@ package com.eveningoutpost.dexdrip.tidepool; +import static com.eveningoutpost.dexdrip.utilitymodels.OkHttpWrapper.enableTls12OnPreLollipop; + import android.os.PowerManager; import com.eveningoutpost.dexdrip.BuildConfig; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.store.FastStore; import java.util.List; +import lombok.Getter; import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.RequestBody; @@ -28,8 +31,6 @@ import retrofit2.http.Path; import retrofit2.http.Query; -import static com.eveningoutpost.dexdrip.UtilityModels.OkHttpWrapper.enableTls12OnPreLollipop; - /** jamorham * * Tidepool Uploader @@ -47,6 +48,7 @@ public class TidepoolUploader { private static Retrofit retrofit; private static final String INTEGRATION_BASE_URL = "https://int-api.tidepool.org"; private static final String PRODUCTION_BASE_URL = "https://api.tidepool.org"; + @Getter private static final String SESSION_TOKEN_HEADER = "x-tidepool-session-token"; private static PowerManager.WakeLock wl; @@ -112,6 +114,7 @@ public static Retrofit getRetrofitInstance() { public static void resetInstance() { retrofit = null; + AuthFlowOut.clearAllSavedData(); UserError.Log.d(TAG, "Instance reset"); } @@ -130,21 +133,26 @@ public static synchronized void doLogin(final boolean fromUi) { // TODO failure backoff if (JoH.ratelimit("tidepool-login", 10)) { extendWakeLock(30000); - final Session session = new Session(MAuthRequest.getAuthRequestHeader(), SESSION_TOKEN_HEADER); - if (session.authHeader != null) { - final Call call = session.service.getLogin(session.authHeader); - status("Connecting"); - if (fromUi) { - JoH.static_toast_long("Connecting to Tidepool"); - } - - call.enqueue(new TidepoolCallback(session, "Login", () -> startSession(session, fromUi)) - .setOnFailure(() -> loginFailed(fromUi))); + if (Pref.getBooleanDefaultFalse("tidepool_new_auth")) { + UserError.Log.d(TAG, "Using new auth method"); + AuthFlowIn.handleTokenLoginAndStartSession(); } else { - UserError.Log.e(TAG, "Cannot do login as user credentials have not been set correctly"); - status("Invalid credentials"); - if (fromUi) { - JoH.static_toast_long("Cannot login as Tidepool credentials have not been set correctly"); + UserError.Log.d(TAG, "Using old auth method"); + final Session session = new Session(MAuthRequest.getAuthRequestHeader(), SESSION_TOKEN_HEADER); + if (session.authHeader != null) { + final Call call = session.service.getLogin(session.authHeader); + status("Connecting"); + if (fromUi) { + JoH.static_toast_long("Connecting to Tidepool"); + } + call.enqueue(new TidepoolCallback(session, "Login", () -> startSession(session, fromUi)) + .setOnFailure(() -> loginFailed(fromUi))); + } else { + UserError.Log.e(TAG, "Cannot do login as user credentials have not been set correctly"); + status("Invalid credentials"); + if (fromUi) { + JoH.static_toast_long("Cannot login as Tidepool credentials have not been set correctly"); + } } releaseWakeLock(); } @@ -195,7 +203,7 @@ private static void loginFailed(boolean fromUi) { }*/ - private static void startSession(final Session session, boolean fromUi) { + public static void startSession(final Session session, boolean fromUi) { if (JoH.ratelimit("tidepool-start-session", 60)) { extendWakeLock(30000); if (session.authReply.userid != null) { @@ -207,7 +215,7 @@ private static void startSession(final Session session, boolean fromUi) { if (session.datasetReply == null) { status("New data set"); if (fromUi) { - JoH.static_toast_long("Creating new data set"); + JoH.static_toast_long("Creating new data set - all good"); } Call call = session.service.openDataSet(session.token, session.authReply.userid, new MOpenDatasetRequest().getBody()); call.enqueue(new TidepoolCallback(session, "Open New Dataset", () -> doUpload(session)) @@ -218,7 +226,7 @@ private static void startSession(final Session session, boolean fromUi) { // ie, do the openDataSet conditionally, and then do `doUpload` either way. status("Appending"); if (fromUi) { - JoH.static_toast_long("Found existing remote data set"); + JoH.static_toast_long("Found existing remote data set - all good"); } doUpload(session); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/UploadChunk.java b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/UploadChunk.java index dc3b0df8d6..0c39cb7db7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/UploadChunk.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/tidepool/UploadChunk.java @@ -1,18 +1,18 @@ package com.eveningoutpost.dexdrip.tidepool; -import static com.eveningoutpost.dexdrip.Models.JoH.dateTimeText; - -import com.eveningoutpost.dexdrip.Models.APStatus; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Profile; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import static com.eveningoutpost.dexdrip.models.JoH.dateTimeText; + +import com.eveningoutpost.dexdrip.models.APStatus; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Profile; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.LogSlider; import com.eveningoutpost.dexdrip.utils.NamedSliderProcessor; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/BaseShelf.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/BaseShelf.java index 74d173f4e2..e4eb3920bc 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/BaseShelf.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/BaseShelf.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip.ui; -import android.databinding.ObservableArrayMap; +import androidx.databinding.ObservableArrayMap; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import java.util.HashMap; import java.util.Map; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/FlashLight.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/FlashLight.java new file mode 100644 index 0000000000..2cadb76cf3 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/FlashLight.java @@ -0,0 +1,112 @@ +package com.eveningoutpost.dexdrip.ui; + +import static android.hardware.camera2.CameraCharacteristics.FLASH_INFO_AVAILABLE; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; + +import android.content.Context; +import android.hardware.camera2.CameraAccessException; +import android.hardware.camera2.CameraManager; +import android.os.Build; + +import androidx.annotation.RequiresApi; + +import com.eveningoutpost.dexdrip.models.ActiveBgAlert; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.xdrip; + +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicBoolean; + +import lombok.val; + +/** + * JamOrHam + *

+ * Use camera flash to attract attention + */ + + +public class FlashLight { + + private static final String TAG = "Torch"; + private static final AtomicBoolean running = new AtomicBoolean(); + + public static void torchPulse() { + Inevitable.task("torch-pulse", 100, () -> torchPulseReal(30, true)); + } + + private static synchronized void torchPulseReal(final int seconds, final boolean stopIfNoAlert) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + + if (running.get()) { + Log.e(TAG, "Already flashing flashlight - skipping"); + return; + } + val manager = (CameraManager) xdrip.getAppContext().getSystemService(Context.CAMERA_SERVICE); + if (manager == null) { + Log.e(TAG, "Cannot get camera manager"); + return; + } + + val flashes = new ArrayList(); + val rnd = new SecureRandom(); + + try { + running.set(true); + + val cameraIds = manager.getCameraIdList(); + // reduce list to cameras which say they have flash + for (val camera : cameraIds) { + val characteristics = manager.getCameraCharacteristics(camera); + val flashy = characteristics.get(FLASH_INFO_AVAILABLE); + if (flashy == null || flashy) { + flashes.add(camera); + } + } + + val timeEnd = tsl() + Constants.SECOND_IN_MS * seconds; + + // Flash light randomly until time period is elapsed + int i = 0; + while (tsl() < timeEnd) { + setCameraList(manager, flashes, i % 2 == 0); + JoH.threadSleep(100 + Math.abs(rnd.nextInt() % (Math.abs(400 - i)))); + i++; + if (stopIfNoAlert && JoH.quietratelimit("check-bgalert", 1)) { + if (!ActiveBgAlert.currentlyAlerting()) { + Log.d(TAG, "Exiting flash sequence as no active alert"); + break; + } + } + } + + } catch (Exception e) { + Log.e(TAG, "Cannot access flashlight: " + e); + } finally { + setCameraList(manager, flashes, false); // turn off at end + running.set(false); + } + } else { + Log.e(TAG, "Flashlight torch access requires at least Android 6"); + } + } + + @RequiresApi(api = Build.VERSION_CODES.M) + private static void setCameraList(final CameraManager manager, final ArrayList flashes, final boolean on) { + try { + for (val camera : flashes) { + try { + manager.setTorchMode(camera, on); + } catch (CameraAccessException | IllegalArgumentException e) { + // doesn't have flash + } + } + } catch (Exception e) { + Log.e(TAG, "Exception in setCameraList: " + e); + } + } +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/LockScreenWallPaper.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/LockScreenWallPaper.java index e22a258563..01220545c9 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/LockScreenWallPaper.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/LockScreenWallPaper.java @@ -8,11 +8,11 @@ import android.preference.Preference; import com.eveningoutpost.dexdrip.BestGlucose; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.ui.activities.NumberWallPreview; import com.eveningoutpost.dexdrip.ui.helpers.BitmapUtil; import com.eveningoutpost.dexdrip.utils.time.TimeRangeUtils; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/MicroStatus.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/MicroStatus.java index 1e8f75e0f9..de6f0b2850 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/MicroStatus.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/MicroStatus.java @@ -12,4 +12,5 @@ public interface MicroStatus { boolean xmitterBattery(); + } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/MicroStatusImpl.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/MicroStatusImpl.java index 7fe826cfd1..f60b79db71 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/MicroStatusImpl.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/MicroStatusImpl.java @@ -4,8 +4,9 @@ * Created by jamorham on 29/09/2017. */ -import android.databinding.BaseObservable; -import android.databinding.Bindable; +import static com.eveningoutpost.dexdrip.utils.DexCollectionType.getBestCollectorHardwareName; + +import androidx.databinding.BaseObservable; import com.eveningoutpost.dexdrip.utils.DexCollectionType; @@ -29,12 +30,13 @@ public String gs(String id) { } @Override - public boolean bluetooth() { - return DexCollectionType.hasBluetooth(); + public boolean bluetooth() { // Dexcom with Bluetooth except G7 + return DexCollectionType.hasBluetooth() && !getBestCollectorHardwareName().equals("G7"); } @Override public boolean xmitterBattery() { return DexCollectionType.usesClassicTransmitterBattery(); } + } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/NumberGraphic.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/NumberGraphic.java index 2a175b6c83..d62bf4cdea 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/NumberGraphic.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/NumberGraphic.java @@ -11,15 +11,15 @@ import android.graphics.drawable.Icon; import android.os.Build; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.ColorCache; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.ColorCache; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.xdrip; import static android.content.Context.NOTIFICATION_SERVICE; -import static com.eveningoutpost.dexdrip.UtilityModels.ColorCache.getCol; +import static com.eveningoutpost.dexdrip.utilitymodels.ColorCache.getCol; import static com.eveningoutpost.dexdrip.ui.activities.NumberWallPreview.ViewModel.PREF_numberwall_multi_param; import static com.eveningoutpost.dexdrip.ui.helpers.BitmapUtil.getScreenDpi; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/UiPing.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/UiPing.java index c15aec90ad..9c101c8fc7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/UiPing.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/UiPing.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.ui; -import android.databinding.BaseObservable; -import android.databinding.ObservableInt; +import androidx.databinding.BaseObservable; +import androidx.databinding.ObservableInt; /** * Created by jamorham on 11/03/2018. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/DatabaseAdmin.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/DatabaseAdmin.java index df360dd69f..687d90ea93 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/DatabaseAdmin.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/DatabaseAdmin.java @@ -2,14 +2,14 @@ import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; -import android.databinding.ObservableField; +import androidx.databinding.ObservableField; import android.os.Bundle; import com.activeandroid.Cache; import com.eveningoutpost.dexdrip.BaseAppCompatActivity; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; import com.eveningoutpost.dexdrip.databinding.ActivityDatabaseAdminBinding; import java.io.File; @@ -19,8 +19,8 @@ import java.util.Map; import java.util.SortedSet; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; -import static com.eveningoutpost.dexdrip.Models.JoH.mapSortedByValue; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.mapSortedByValue; /** * jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/NumberWallPreview.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/NumberWallPreview.java index c651d37e54..35fd42c582 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/NumberWallPreview.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/NumberWallPreview.java @@ -6,19 +6,19 @@ import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v7.app.AppCompatActivity; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; import android.view.View; import com.eveningoutpost.dexdrip.BestGlucose; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.ColorCache; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.PrefsViewImpl; -import com.eveningoutpost.dexdrip.UtilityModels.PrefsViewString; -import com.eveningoutpost.dexdrip.UtilityModels.Unitized; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.ColorCache; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.PrefsViewImpl; +import com.eveningoutpost.dexdrip.utilitymodels.PrefsViewString; +import com.eveningoutpost.dexdrip.utilitymodels.Unitized; import com.eveningoutpost.dexdrip.adapters.ObservableBackground; import com.eveningoutpost.dexdrip.databinding.ActivityNumberWallPreviewBinding; import com.eveningoutpost.dexdrip.ui.LockScreenWallPaper; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/SelectAudioDevice.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/SelectAudioDevice.java index 833e8dc413..ad7f0c368b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/SelectAudioDevice.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/SelectAudioDevice.java @@ -1,14 +1,13 @@ package com.eveningoutpost.dexdrip.ui.activities; -import android.databinding.ObservableField; +import androidx.databinding.ObservableField; import android.os.Bundle; import android.os.Handler; -import android.support.v7.app.AppCompatActivity; import com.eveningoutpost.dexdrip.BaseAppCompatActivity; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.databinding.ActivitySelectAudioDeviceBinding; import com.eveningoutpost.dexdrip.utils.HeadsetStateReceiver; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/ThinJamActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/ThinJamActivity.java index 639ba029b6..7d9003a996 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/ThinJamActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/ThinJamActivity.java @@ -6,18 +6,18 @@ import android.content.Intent; import android.content.ServiceConnection; import android.content.pm.PackageManager; -import android.databinding.Observable; -import android.databinding.ObservableArrayList; -import android.databinding.ObservableField; -import android.databinding.ObservableList; +import androidx.databinding.Observable; +import androidx.databinding.ObservableArrayList; +import androidx.databinding.ObservableField; +import androidx.databinding.ObservableList; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.IBinder; import android.os.ParcelUuid; -import android.support.annotation.NonNull; -import android.support.v4.app.ActivityCompat; -import android.support.v7.app.AppCompatActivity; +import androidx.annotation.NonNull; +import androidx.core.app.ActivityCompat; +import androidx.appcompat.app.AppCompatActivity; import android.text.InputType; import android.text.method.ScrollingMovementMethod; import android.util.Log; @@ -28,12 +28,12 @@ import com.eveningoutpost.dexdrip.BR; import com.eveningoutpost.dexdrip.MegaStatus; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.databinding.ActivityThinJamBinding; import com.eveningoutpost.dexdrip.ui.dialog.GenericConfirmDialog; import com.eveningoutpost.dexdrip.ui.dialog.QuickSettingsDialogs; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/TimePickerPrefActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/TimePickerPrefActivity.java index 38189aa6d4..acb052b895 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/TimePickerPrefActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/activities/TimePickerPrefActivity.java @@ -2,11 +2,11 @@ import android.content.Intent; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatActivity; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.profileeditor.TimePickerFragment; import java.util.Locale; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/charts/BasalChart.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/charts/BasalChart.java index 011737da09..ecd76ecff9 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/charts/BasalChart.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/charts/BasalChart.java @@ -1,12 +1,12 @@ package com.eveningoutpost.dexdrip.ui.charts; -import android.support.annotation.ColorInt; -import android.support.annotation.NonNull; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; import android.text.format.DateFormat; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.ColorCache; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.ColorCache; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import com.eveningoutpost.dexdrip.profileeditor.BasalProfile; import com.eveningoutpost.dexdrip.xdrip; @@ -28,7 +28,7 @@ import lecho.lib.hellocharts.model.SubcolumnValue; import lecho.lib.hellocharts.view.ColumnChartView; -import static com.eveningoutpost.dexdrip.UtilityModels.ColorCache.getCol; +import static com.eveningoutpost.dexdrip.utilitymodels.ColorCache.getCol; // jamorham @@ -65,7 +65,7 @@ public static float getTotalImmutableBasal(final ColumnChartData columnChartData } public static void refreshAxis(final ColumnChartView chart) { - chart.getChartData().setAxisYRight(chartYAxis(chart.getMaximumViewport().top)); + chart.getChartData().setAxisYRight(chartYAxis((float) chart.getMaximumViewport().top)); } private static List getColumns(final String profileName, @ColorInt int color) { @@ -148,7 +148,7 @@ public static float getMaxYvalue(ColumnChartData lineData) { float max_height = 0.2f; for (Column col : lineData.getColumns()) { final SubcolumnValue sub = col.getValues().get(0); - final float val = Math.max(sub.getValue(), sub.getImmutableOriginValue()); + final float val = (float) Math.max(sub.getValue(), sub.getImmutableOriginValue()); if (val > max_height) { max_height = val; } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/classifier/NoteClassifier.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/classifier/NoteClassifier.java index d7a37da185..78c5d7150b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/classifier/NoteClassifier.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/classifier/NoteClassifier.java @@ -3,17 +3,15 @@ // jamorham import android.graphics.Color; -import android.support.annotation.ColorInt; -import android.support.annotation.DrawableRes; +import androidx.annotation.ColorInt; +import androidx.annotation.DrawableRes; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.HPointValue; -import com.eveningoutpost.dexdrip.UtilityModels.PointValueExtended; +import com.eveningoutpost.dexdrip.utilitymodels.HPointValue; +import com.eveningoutpost.dexdrip.utilitymodels.PointValueExtended; import com.eveningoutpost.dexdrip.ui.helpers.BitmapLoader; import com.eveningoutpost.dexdrip.ui.helpers.ColorUtil; -import lecho.lib.hellocharts.model.PointValue; - public class NoteClassifier { // TODO add to colorpickerx diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/ChooseInsulinPenDialog.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/ChooseInsulinPenDialog.java index 65cd84a61c..a3164629b3 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/ChooseInsulinPenDialog.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/ChooseInsulinPenDialog.java @@ -3,7 +3,7 @@ import android.app.Activity; import android.app.AlertDialog; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.insulin.InsulinManager; import com.eveningoutpost.dexdrip.insulin.opennov.data.Pens; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/ColorPreferenceDialog.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/ColorPreferenceDialog.java index 92c1ead89b..3b1cd922b6 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/ColorPreferenceDialog.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/ColorPreferenceDialog.java @@ -6,8 +6,8 @@ import android.graphics.Color; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.ColorCache; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.ColorCache; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.rarepebble.colorpicker.ColorPickerView; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/DidYouCancelAlarm.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/DidYouCancelAlarm.java index 625cfa4ba7..424fb8f7dd 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/DidYouCancelAlarm.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/DidYouCancelAlarm.java @@ -4,7 +4,7 @@ import android.app.AlertDialog; import android.content.DialogInterface; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/DoseAdjustDialog.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/DoseAdjustDialog.java index d35b16747a..409ec8bda9 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/DoseAdjustDialog.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/DoseAdjustDialog.java @@ -4,11 +4,11 @@ import android.app.AlertDialog; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Treatments; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Treatments; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.SyncService; -import com.eveningoutpost.dexdrip.UtilityModels.UploaderQueue; +import com.eveningoutpost.dexdrip.services.SyncService; +import com.eveningoutpost.dexdrip.utilitymodels.UploaderQueue; import com.eveningoutpost.dexdrip.insulin.MultipleInsulins; import com.eveningoutpost.dexdrip.xdrip; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/G6CalibrationCodeDialog.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/G6CalibrationCodeDialog.java index 6aad43b087..22ecdc1904 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/G6CalibrationCodeDialog.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/G6CalibrationCodeDialog.java @@ -8,8 +8,8 @@ import android.view.WindowManager; import android.widget.EditText; -import com.eveningoutpost.dexdrip.G5Model.G6CalibrationParameters; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.g5model.G6CalibrationParameters; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/HeyFamUpdateOptInDialog.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/HeyFamUpdateOptInDialog.java index df79e9762b..bc89c3188b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/HeyFamUpdateOptInDialog.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/HeyFamUpdateOptInDialog.java @@ -4,13 +4,13 @@ import android.app.AlertDialog; import android.content.DialogInterface; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Experience; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Experience; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; -import static com.eveningoutpost.dexdrip.UtilityModels.UpdateActivity.AUTO_UPDATE_PREFS_NAME; +import static com.eveningoutpost.dexdrip.utilitymodels.UpdateActivity.AUTO_UPDATE_PREFS_NAME; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/QuickSettingsDialogs.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/QuickSettingsDialogs.java index 85501cb6e3..1d2532475d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/QuickSettingsDialogs.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/dialog/QuickSettingsDialogs.java @@ -3,14 +3,15 @@ import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; +import android.text.InputFilter; import android.view.View; import android.widget.CheckBox; import android.widget.EditText; import android.widget.TextView; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; // jamorham @@ -72,6 +73,11 @@ public static void textSettingDialog(Activity activity, String setting, String t edt.setInputType(input_type); } + if (setting.equals("dex_txid")) { + edt.setFilters(new InputFilter[]{new InputFilter.AllCaps()}); + } + + edt.setText(Pref.getString(setting, "")); final TextView tv = (TextView) dialogView.findViewById(R.id.dialogTextEntryTextView); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/graphic/JamTrendArrowImpl.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/graphic/JamTrendArrowImpl.java index f0582fd29f..4274547cc1 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/graphic/JamTrendArrowImpl.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/graphic/JamTrendArrowImpl.java @@ -12,7 +12,7 @@ import android.widget.SeekBar; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.xdrip; import static com.eveningoutpost.dexdrip.ui.helpers.ColorUtil.hueFilter; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/graphic/TrendArrowFactory.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/graphic/TrendArrowFactory.java index 4c882579de..2612885567 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/graphic/TrendArrowFactory.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/graphic/TrendArrowFactory.java @@ -3,9 +3,9 @@ import android.os.Build; import android.widget.ImageView; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.xdrip; /* diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/AudioFocusType.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/AudioFocusType.java index bad23dba26..1a8f18f14e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/AudioFocusType.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/AudioFocusType.java @@ -2,7 +2,7 @@ import android.media.AudioManager; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import lombok.val; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/BitmapLoader.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/BitmapLoader.java index 00cebb3f6a..f5e69ce710 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/BitmapLoader.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/BitmapLoader.java @@ -8,11 +8,13 @@ import android.os.Build; import android.os.Bundle; import android.os.Parcel; -import android.support.v4.graphics.drawable.DrawableCompat; -import android.support.v7.content.res.AppCompatResources; + +import androidx.appcompat.content.res.AppCompatResources; +import androidx.core.graphics.drawable.DrawableCompat; + import android.util.LruCache; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.xdrip; import lecho.lib.hellocharts.model.PointValue; @@ -144,8 +146,8 @@ private static int getBundleSizeInBytes(Bundle bundle) { // Accessed via interface - protect with proguard or silently fails? - public String getScaledKeyName(String key, final float scaler) { - if (scaler != 1f) { + public String getScaledKeyName(String key, final double scaler) { + if (scaler != 1d) { key += "-" + scaler; } return key; @@ -158,7 +160,7 @@ public Bitmap loadScaledBitmap(final String key) { } // Accessed via interface - public String prepareScaledBitmap(final String originalKey, final float scaler) { + public String prepareScaledBitmap(final String originalKey, final double scaler) { final String key = getScaledKeyName(originalKey, scaler); if (cache.get(key) == null) { final Bitmap discard = loadScaledBitmap(originalKey, scaler); @@ -168,7 +170,7 @@ public String prepareScaledBitmap(final String originalKey, final float scaler) // Accessed via interface - protect with proguard or silently fails // @Override - public Bitmap loadScaledBitmap(final String originalKey, final float scaler) { + public Bitmap loadScaledBitmap(final String originalKey, final double scaler) { String key = originalKey; if (scaler != 1f) { key += "-" + scaler; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/BitmapUtil.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/BitmapUtil.java index 4ac1d43349..92af42e2bc 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/BitmapUtil.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/BitmapUtil.java @@ -13,8 +13,8 @@ import android.media.ExifInterface; import android.net.Uri; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.FileUtils; import com.eveningoutpost.dexdrip.xdrip; @@ -25,6 +25,8 @@ import java.io.IOException; import java.util.Date; +import lombok.val; + public class BitmapUtil { // note: this recycles the source bitmap - TODO make this more generic @@ -199,4 +201,17 @@ public static float getScreenDensity() { return Resources.getSystem().getDisplayMetrics().density; } + public static Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) { + if (bm == null) return null; + val width = bm.getWidth(); + val height = bm.getHeight(); + val scaleWidth = ((float) newWidth) / width; + val scaleHeight = ((float) newHeight) / height; + val matrix = new Matrix(); + matrix.postScale(scaleWidth, scaleHeight); + val resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false); + bm.recycle(); + return resizedBitmap; + } + } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/ColorUtil.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/ColorUtil.java index ea3db98168..244394ceb3 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/ColorUtil.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/ColorUtil.java @@ -4,8 +4,8 @@ import android.graphics.ColorFilter; import android.graphics.ColorMatrix; import android.graphics.ColorMatrixColorFilter; -import android.support.annotation.ColorInt; -import android.support.v4.graphics.ColorUtils; +import androidx.annotation.ColorInt; +import androidx.core.graphics.ColorUtils; public class ColorUtil { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/DoNotDisturb.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/DoNotDisturb.java index 05bfcb661e..82840e1be6 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/DoNotDisturb.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/DoNotDisturb.java @@ -7,8 +7,8 @@ import android.os.Build; import android.provider.Settings; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; import lombok.val; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/Span.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/Span.java index 9961be49a4..c08f4d9b29 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/Span.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/helpers/Span.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.ui.helpers; -import android.support.annotation.ColorInt; +import androidx.annotation.ColorInt; import android.text.SpannableString; import android.text.SpannableStringBuilder; import android.text.style.BackgroundColorSpan; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/AlertPlayer.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/AlertPlayer.java similarity index 91% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/AlertPlayer.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/AlertPlayer.java index 69c7e329b8..6380d824e5 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/AlertPlayer.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/AlertPlayer.java @@ -1,9 +1,10 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import static com.eveningoutpost.dexdrip.Home.startWatchUpdaterService; -import static com.eveningoutpost.dexdrip.Models.JoH.delayedMediaPlayerRelease; -import static com.eveningoutpost.dexdrip.Models.JoH.setMediaDataSource; -import static com.eveningoutpost.dexdrip.Models.JoH.stopAndReleasePlayer; +import static com.eveningoutpost.dexdrip.models.JoH.delayedMediaPlayerRelease; +import static com.eveningoutpost.dexdrip.models.JoH.setMediaDataSource; +import static com.eveningoutpost.dexdrip.models.JoH.stopAndReleasePlayer; +import static com.eveningoutpost.dexdrip.receiver.InfoContentProvider.ping; import android.app.Notification; import android.app.NotificationManager; @@ -11,42 +12,45 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.AssetFileDescriptor; import android.media.AudioManager; import android.media.MediaPlayer; import android.net.Uri; import android.os.Handler; import android.os.Looper; +import android.os.PowerManager; import android.preference.PreferenceManager; -import android.support.v4.app.NotificationCompat; +import androidx.core.app.NotificationCompat; import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.ActiveBgAlert; -import com.eveningoutpost.dexdrip.Models.AlertType; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.ActiveBgAlert; +import com.eveningoutpost.dexdrip.models.AlertType; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.SnoozeOnNotificationDismissService; +import com.eveningoutpost.dexdrip.services.SnoozeOnNotificationDismissService; import com.eveningoutpost.dexdrip.SnoozeActivity; -import com.eveningoutpost.dexdrip.UtilityModels.pebble.PebbleWatchSync; +import com.eveningoutpost.dexdrip.utilitymodels.pebble.PebbleWatchSync; import com.eveningoutpost.dexdrip.eassist.AlertTracker; +import com.eveningoutpost.dexdrip.ui.FlashLight; import com.eveningoutpost.dexdrip.ui.helpers.AudioFocusType; +import com.eveningoutpost.dexdrip.utils.PowerStateReceiver; import com.eveningoutpost.dexdrip.watch.lefun.LeFun; import com.eveningoutpost.dexdrip.watch.lefun.LeFunEntry; import com.eveningoutpost.dexdrip.watch.miband.MiBand; import com.eveningoutpost.dexdrip.watch.miband.MiBandEntry; import com.eveningoutpost.dexdrip.watch.thinjam.BlueJayEntry; import com.eveningoutpost.dexdrip.wearintegration.Amazfitservice; -import com.eveningoutpost.dexdrip.Services.broadcastservice.BroadcastEntry; +import com.eveningoutpost.dexdrip.services.broadcastservice.BroadcastEntry; import com.eveningoutpost.dexdrip.wearintegration.WatchUpdaterService; -import com.eveningoutpost.dexdrip.Services.broadcastservice.Const; +import com.eveningoutpost.dexdrip.services.broadcastservice.Const; import com.eveningoutpost.dexdrip.xdrip; -import java.io.IOException; import java.util.Date; +import lombok.Getter; + // A helper class to create the mediaplayer on the UI thread. // This is needed in order for the callbackst to work. @@ -106,7 +110,8 @@ boolean isUiThread() { public class AlertPlayer { private volatile static AlertPlayer alertPlayerInstance; - + @Getter + private volatile static long lastVolumeChange = 0; private final static String TAG = AlertPlayer.class.getSimpleName(); private volatile MediaPlayer mediaPlayer = null; private final AudioManager manager = (AudioManager)xdrip.getAppContext().getSystemService(Context.AUDIO_SERVICE); @@ -123,6 +128,10 @@ public class AlertPlayer { final static int MAX_VIBRATING_MINUTES = 2; final static int MAX_ASCENDING_MINUTES = 5; + // Ascending without delay profile + final static float NODELAY_ASCENDING_INTERCEPT = 0.3333f; // Lower volumes are silent on some phones. + final static float NODELAY_ASCENDING_SLOPE = 0.166675f; // So that the volume reaches 1 (max) in 4 steps (1-2-3-4-5) since in most cases, we have a new reading once every 5 minutes. + public int streamType = AudioManager.STREAM_MUSIC; private final AudioManager.OnAudioFocusChangeListener focusChangeListener = @@ -180,6 +189,7 @@ public synchronized void startAlert(Context ctx, boolean trendingToAlertEnd, Al ActiveBgAlert.Create(newAlert.uuid, start_snoozed, nextAlertTime); if (!start_snoozed) VibrateNotifyMakeNoise(ctx, newAlert, bgValue, 0); + ping("alarm"); AlertTracker.evaluate(); } @@ -205,6 +215,7 @@ public synchronized void stopAlert(Context ctx, boolean ClearData, boolean clear } revertCurrentVolume(streamType); releaseAudioFocus(); + ping("alarm"); } // only do something if an alert is active - only call from interactive @@ -236,6 +247,9 @@ public synchronized void Snooze(Context ctx, int repeatTime) { && Pref.getBooleanDefaultFalse("pref_amazfit_BG_alert_enable_key")) { Amazfitservice.start("xDrip_AlarmCancel"); } + + BroadcastEntry.cancelAlert(); + ping("alarm"); } public synchronized void Snooze(Context ctx, int repeatTime, boolean from_interactive) { @@ -332,6 +346,10 @@ protected synchronized void playFile(final Context ctx, final String fileName, f return; } + if (Pref.getBooleanDefaultFalse("wake_phone_during_alerts")) { + mediaPlayer.setWakeMode(ctx, PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP); + } + mediaPlayer.setOnCompletionListener(mp -> { Log.i(TAG, "playFile: onCompletion called (finished playing) "); delayedMediaPlayerRelease(mp); @@ -431,6 +449,7 @@ private void setVolume(final int streamType, final int volume) { return; } try { + lastVolumeChange = JoH.tsl(); manager.setStreamVolume(streamType, volume, 0); Log.d(TAG, "Adjusted volume to: " + volume); } catch (SecurityException e) { @@ -534,10 +553,13 @@ protected void VibrateNotifyMakeNoise(Context context, AlertType alert, String b if (profile != ALERT_PROFILE_VIBRATE_ONLY && profile != ALERT_PROFILE_SILENT) { float volumeFrac = (float) (minsFromStartPlaying - MAX_VIBRATING_MINUTES) / (MAX_ASCENDING_MINUTES - MAX_VIBRATING_MINUTES); // While minsFromStartPlaying <= MAX_VIBRATING_MINUTES, we only vibrate ... + if (!Pref.getBoolean("delay_ascending_3min", true)) { // If delay_ascending_3min is disabled, linearly increase volume from start. + volumeFrac = (minsFromStartPlaying * NODELAY_ASCENDING_SLOPE + NODELAY_ASCENDING_INTERCEPT); + } volumeFrac = Math.max(volumeFrac, 0); // Limit volumeFrac to values greater than and equal to 0 volumeFrac = Math.min(volumeFrac, 1); // Limit volumeFrac to values less than and equal to 1 - if (!Pref.getBoolean("delay_ascending_3min", true) && volumeFrac < 0.3) { - volumeFrac = (float) 0.3; // If delay_ascending_3min is disabled, we never only vibrate. + if (Pref.getBooleanDefaultFalse("ascending_volume_to_medium") && profile == ALERT_PROFILE_ASCENDING) { // If ascending volume profile is chosen and ascending_volume_to_medium is enabled + volumeFrac = Math.min(volumeFrac, (float) 0.7); // Clamp the ascending volume at the medium level. } if (profile == ALERT_PROFILE_MEDIUM) { volumeFrac = (float) 0.7; @@ -608,6 +630,12 @@ protected void VibrateNotifyMakeNoise(Context context, AlertType alert, String b if (Pref.getBooleanDefaultFalse("speak_alerts")) { SpeechUtil.say(highlow + ", " + bgValue, 3000); } + + if (Pref.getBooleanDefaultFalse("flash_torch_alerts_charging")) { + if (PowerStateReceiver.is_power_connected()) { + FlashLight.torchPulse(); + } + } } private void notificationDismiss(Context ctx) { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BgGraphBuilder.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BgGraphBuilder.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BgGraphBuilder.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BgGraphBuilder.java index 5c4d6fe306..221ba90404 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BgGraphBuilder.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BgGraphBuilder.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.app.Activity; import android.content.Context; @@ -7,7 +7,7 @@ import android.graphics.Color; import android.graphics.DashPathEffect; import android.preference.PreferenceManager; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import android.text.format.DateFormat; import android.util.Log; import android.util.Pair; @@ -17,24 +17,24 @@ import com.eveningoutpost.dexdrip.AddCalibration; import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.APStatus; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.Forecast; -import com.eveningoutpost.dexdrip.Models.Forecast.PolyTrendLine; -import com.eveningoutpost.dexdrip.Models.Forecast.TrendLine; -import com.eveningoutpost.dexdrip.Models.HeartRate; -import com.eveningoutpost.dexdrip.Models.Iob; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Libre2RawValue; -import com.eveningoutpost.dexdrip.Models.Prediction; -import com.eveningoutpost.dexdrip.Models.Profile; -import com.eveningoutpost.dexdrip.Models.StepCounter; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.APStatus; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.Forecast; +import com.eveningoutpost.dexdrip.models.Forecast.PolyTrendLine; +import com.eveningoutpost.dexdrip.models.Forecast.TrendLine; +import com.eveningoutpost.dexdrip.models.HeartRate; +import com.eveningoutpost.dexdrip.models.Iob; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Libre2RawValue; +import com.eveningoutpost.dexdrip.models.Prediction; +import com.eveningoutpost.dexdrip.models.Profile; +import com.eveningoutpost.dexdrip.models.StepCounter; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.ActivityRecognizedService; +import com.eveningoutpost.dexdrip.services.ActivityRecognizedService; import com.eveningoutpost.dexdrip.calibrations.CalibrationAbstract; import com.eveningoutpost.dexdrip.calibrations.PluggableCalibration; import com.eveningoutpost.dexdrip.insulin.opennov.Options; @@ -82,9 +82,9 @@ import lombok.val; -import static com.eveningoutpost.dexdrip.Models.JoH.tolerantParseDouble; -import static com.eveningoutpost.dexdrip.UtilityModels.ColorCache.X; -import static com.eveningoutpost.dexdrip.UtilityModels.ColorCache.getCol; +import static com.eveningoutpost.dexdrip.models.JoH.tolerantParseDouble; +import static com.eveningoutpost.dexdrip.utilitymodels.ColorCache.X; +import static com.eveningoutpost.dexdrip.utilitymodels.ColorCache.getCol; public class BgGraphBuilder { public static final int FUZZER = (int) (30 * Constants.SECOND_IN_MS); @@ -100,6 +100,7 @@ public class BgGraphBuilder { private static long noise_processed_till_timestamp = -1; private final static String TAG = "jamorham graph"; //private final static int pluginColor = Color.parseColor("#AA00FFFF"); // temporary + public boolean custimze_y_range = Pref.getBoolean("Customize_yRange", false); // True when Customize y axis range is enabled private final static int pluginSize = 2; final int pointSize; @@ -245,6 +246,10 @@ public BgGraphBuilder(Context context, long start, long end, int numValues, bool this.doMgdl = (prefs.getString("units", "mgdl").equals("mgdl")); defaultMinY = unitized(40); defaultMaxY = unitized(250); + if (custimze_y_range) { // If Customize y axis range is enabled + defaultMinY = unitized(Pref.getStringToInt("default_ymin", 40)); // Use the user-defined ymin + defaultMaxY = unitized(Pref.getStringToInt("default_ymax", 250)); // Use the user-defined ymax + } pointSize = isXLargeTablet(context) ? 5 : 3; axisTextSize = isXLargeTablet(context) ? 20 : Axis.DEFAULT_TEXT_SIZE_SP; previewAxisTextSize = isXLargeTablet(context) ? 12 : 5; @@ -293,7 +298,8 @@ private List predictiveLines() { final List lines = new LinkedList<>(); final boolean g_prediction = Pref.getBooleanDefaultFalse("show_g_prediction"); - final boolean medtrum = Pref.getBooleanDefaultFalse("show_medtrum_secondary"); + final boolean medtrum = (DexCollectionType.getDexCollectionType() == DexCollectionType.Medtrum) + && Pref.getBooleanDefaultFalse("show_medtrum_secondary"); if (medtrum || g_prediction) { final List plist = Prediction.latestForGraph(4000, loaded_start, loaded_end); if (plist.size() > 0) { @@ -412,7 +418,7 @@ private List stepsLines() { last_point = new HPointValue((double) pm.timestamp / FUZZER, ypos); } else { final PointValue this_point = new HPointValue((double) pm.timestamp / FUZZER, ypos); - final float time_delta = this_point.getX() - last_point.getX(); + final double time_delta = this_point.getX() - last_point.getX(); if (time_delta > 1) { final List new_points = new ArrayList<>(); @@ -812,14 +818,14 @@ public void debugPrintPoints(List mypoints) { public ArrayList autoSplitLine(Line macroline, final float jumpthresh) { // if (d) Log.d(TAG, "Enter autoSplit Line"); ArrayList linearray = new ArrayList(); - float lastx = -999999; + double lastx = -999999; List macropoints = macroline.getValues(); List thesepoints = new ArrayList(); if (macropoints.size() > 0) { - final float endmarker = macropoints.get(macropoints.size() - 1).getX(); + final double endmarker = macropoints.get(macropoints.size() - 1).getX(); for (PointValue thispoint : macropoints) { // a jump too far for a line? make it a new one @@ -846,13 +852,13 @@ public ArrayList autoSplitLine(Line macroline, final float jumpthresh) { // Produce an array of cubic lines, split as needed public ArrayList filteredLines() { ArrayList linearray = new ArrayList(); - float lastx = -999999; // bogus mark value - final float jumpthresh = 15; // in minutes + double lastx = -999999; // bogus mark value + double jumpthresh = 15; // in minutes List thesepoints = new ArrayList(); if (filteredValues.size() > 0) { - final float endmarker = filteredValues.get(filteredValues.size() - 1).getX(); + final double endmarker = filteredValues.get(filteredValues.size() - 1).getX(); for (PointValue thispoint : filteredValues) { // a jump too far for a line? make it a new one @@ -1145,7 +1151,7 @@ private synchronized void addBgReadingValues(final boolean simple) { if (calibration.timestamp < (start_time * FUZZER)) break; if (calibration.slope_confidence != 0) { final long adjusted_timestamp = (calibration.timestamp + (AddCalibration.estimatedInterstitialLagSeconds * 1000)); - final PointValueExtended this_point = new PointValueExtended((double) (adjusted_timestamp / FUZZER), (float) unitized(calibration.bg)); + final PointValueExtended this_point = new PointValueExtended((double) (adjusted_timestamp / FUZZER), unitized(calibration.bg)); if (adjusted_timestamp >= close_to_side_time) { predictivehours = Math.max(predictivehours, 1); } @@ -1164,8 +1170,8 @@ private synchronized void addBgReadingValues(final boolean simple) { try { for (BloodTest bloodtest : bloodtests) { final long adjusted_timestamp = (bloodtest.timestamp + (AddCalibration.estimatedInterstitialLagSeconds * 1000)); - final PointValueExtended this_point = new PointValueExtended((float) (adjusted_timestamp / FUZZER), (float) unitized(bloodtest.mgdl)) - .setType(PointValueExtended.BloodTest) + final PointValueExtended this_point = new PointValueExtended((double) (adjusted_timestamp / FUZZER), unitized(bloodtest.mgdl)) + .setType(PointValueExtended.BloodTest) .setUUID(bloodtest.uuid); this_point.real_timestamp = bloodtest.timestamp; // exclude any which have been used for calibration @@ -1246,24 +1252,26 @@ private synchronized void addBgReadingValues(final boolean simple) { } if ((show_filtered) && (bgReading.filtered_calculated_value > 0) && (bgReading.filtered_calculated_value != bgReading.calculated_value)) { - filteredValues.add(new HPointValue((double) ((bgReading.timestamp - timeshift) / FUZZER), (float) unitized(bgReading.filtered_calculated_value))); + filteredValues.add(new HPointValue((double) ((bgReading.timestamp - timeshift) / FUZZER), (float) unitized(Math.min(bgReading.filtered_calculated_value, BgReading.BG_READING_MAXIMUM_VALUE)))); } else if (show_pseudo_filtered) { // TODO differentiate between filtered and pseudo-filtered when both may be in play at different times final double rollingValue = rollingAverage.put(bgReading.calculated_value); if (rollingAverage.reachedPeak()) { - filteredValues.add(new HPointValue((double) ((bgReading.timestamp + rollingOffset) / FUZZER), (float) unitized(rollingValue))); + filteredValues.add(new HPointValue((double) ((bgReading.timestamp + rollingOffset) / FUZZER), (float) unitized(Math.min(rollingValue, BgReading.BG_READING_MAXIMUM_VALUE)))); } } if ((interpret_raw && (bgReading.raw_calculated > 0))) { - rawInterpretedValues.add(new HPointValue((double) (bgReading.timestamp / FUZZER), (float) unitized(bgReading.raw_calculated))); + rawInterpretedValues.add(new HPointValue((double) (bgReading.timestamp / FUZZER), (float) unitized(Math.min(bgReading.raw_calculated, BgReading.BG_READING_MAXIMUM_VALUE)))); } if ((!glucose_from_plugin) && (plugin != null) && (cd != null)) { - pluginValues.add(new HPointValue((double) (bgReading.timestamp / FUZZER), (float) unitized(plugin.getGlucoseFromBgReading(bgReading, cd)))); + pluginValues.add(new HPointValue((double) (bgReading.timestamp / FUZZER), (float) unitized(Math.min(plugin.getGlucoseFromBgReading(bgReading, cd), BgReading.BG_READING_MAXIMUM_VALUE)))); } if (bgReading.ignoreForStats) { - badValues.add(new HPointValue((double) (bgReading.timestamp / FUZZER), (float) unitized(bgReading.calculated_value))); - } else if (bgReading.calculated_value >= 400) { - highValues.add(new HPointValue((double) (bgReading.timestamp / FUZZER), (float) unitized(400))); + if (unitized(bgReading.calculated_value) <= defaultMaxY) { // Don't display value marked as bad if greater than the default Max (defaultMaxY) + badValues.add(new HPointValue((double) (bgReading.timestamp / FUZZER), (float) unitized(bgReading.calculated_value))); + } + } else if (bgReading.calculated_value >= BgReading.BG_READING_MAXIMUM_VALUE) { + highValues.add(new HPointValue((double) (bgReading.timestamp / FUZZER), (float) unitized(BgReading.BG_READING_MAXIMUM_VALUE))); } else if (unitized(bgReading.calculated_value) >= highMark) { highValues.add(new HPointValue((double) (bgReading.timestamp / FUZZER), (float) unitized(bgReading.calculated_value))); } else if (unitized(bgReading.calculated_value) >= lowMark) { @@ -1570,7 +1578,7 @@ private synchronized void addBgReadingValues(final boolean simple) { height = treatment.insulin; // some scaling needed I think if (height > highMark) height = highMark; if (height < lowMark) height = lowMark; - final PointValueExtended pv = new PointValueExtended((double) (treatment.timestamp / FUZZER), (float) height); + final PointValueExtended pv = new PointValueExtended((double) (treatment.timestamp / FUZZER), height); pv.real_timestamp = treatment.timestamp; if (treatment.isPenSyncedDose()) { pv.setType(PointValueExtended.AdjustableDose).setUUID(treatment.uuid); @@ -1608,7 +1616,7 @@ private synchronized void addBgReadingValues(final boolean simple) { try { final Matcher m = posPattern.matcher(treatment.enteredBy); if (m.matches()) { - pv.set(pv.getX(), (float)Math.min(tolerantParseDouble(m.group(1)), 18 * bgScale)); // don't allow pos note to exceed 18mmol on chart + pv.set(pv.getX(), Math.min(tolerantParseDouble(m.group(1)), 18 * bgScale)); // don't allow pos note to exceed 18mmol on chart } } catch (Exception e) { Log.d(TAG, "Exception matching position: " + e); @@ -1621,7 +1629,7 @@ private synchronized void addBgReadingValues(final boolean simple) { if (Math.abs(lastpv.getX() - pv.getX()) < ((10 * 60 * 1000) / FUZZER)) { // merge label with previous - Intelligent parsing and additions go here if (d) - Log.d(TAG, "Merge treatment difference: " + Float.toString(lastpv.getX() - pv.getX())); + Log.d(TAG, "Merge treatment difference: " + Double.toString(lastpv.getX() - pv.getX())); String lastlabel = String.valueOf(lastpv.getLabelAsChars()); if (lastlabel.length() > 0) { lastpv.setLabel(lastlabel + "+" + mylabel); @@ -1678,7 +1686,7 @@ private synchronized void addBgReadingValues(final boolean simple) { final double relaxed_predicted_bg_limit = initial_predicted_bg * 1.20; final double cob_insulin_max_draw_value = highMark * 1.20; // final List iobinfo_old = Treatments.ioBForGraph(numValues, (start_time * FUZZER)); - final List iobinfo = (simulation_enabled) ? Treatments.ioBForGraph_new(MAX_VALUES, (start_time * FUZZER)) : null; // for test + final List iobinfo = (simulation_enabled) ? Treatments.ioBForGraph_new(start_time * FUZZER) : null; // for test long fuzzed_timestamp = (long) end_time; // initial value in case there are no iob records if (d) @@ -1718,7 +1726,7 @@ private synchronized void addBgReadingValues(final boolean simple) { height = cob_insulin_max_draw_value; PointValue pv = new HPointValue((double) fuzzed_timestamp, (float) height); if (d) - Log.d(TAG, "Cob total record: " + JoH.qs(height) + " " + JoH.qs(iob.cob) + " " + Float.toString(pv.getY()) + " @ timestamp: " + Long.toString(iob.timestamp)); + Log.d(TAG, "Cob total record: " + JoH.qs(height) + " " + JoH.qs(iob.cob) + " " + Double.toString(pv.getY()) + " @ timestamp: " + Long.toString(iob.timestamp)); cobValues.add(pv); // warning should not be hardcoded } @@ -1769,7 +1777,7 @@ private synchronized void addBgReadingValues(final boolean simple) { Log.d(TAG, "Predictive hours updated to: " + predictivehours); } else { //KS Log.d(TAG, "IOB DEBUG: " + (fuzzed_timestamp - end_time) + " " + iob.iob); - if (!iob_shown_already && (Math.abs(fuzzed_timestamp - end_time) < 5) && (iob.iob > 0)) { + if (!iob_shown_already && (Math.abs(fuzzed_timestamp - end_time) < ((Constants.MINUTE_IN_MS * 5) / FUZZER)) && (iob.iob > 0)) { iob_shown_already = true; // show current iob // double position = 12.4 * bgScale; // this is for mmol - needs generic for mg/dl @@ -1782,7 +1790,10 @@ private synchronized void addBgReadingValues(final boolean simple) { df.setMaximumFractionDigits(2); df.setMinimumIntegerDigits(1); // iv.setLabel("IoB: " + df.format(iob.iob)); - Home.updateStatusLine("iob", df.format(iob.iob)); + val iobformatted = df.format(iob.iob); + keyStore.putS("last_iob", iobformatted); + keyStore.putL("last_iob_timestamp", JoH.tsl()); + Home.updateStatusLine("iob", iobformatted); // annotationValues.add(iv); // needs to be different value list so we can make annotation nicer } @@ -1818,18 +1829,20 @@ private synchronized void addBgReadingValues(final boolean simple) { if (evaluation[0] > Profile.minimum_carb_recommendation) { //PointValue iv = new HPointValue((double) fuzzed_timestamp, (float) (10 * bgScale)); //iv.setLabel("+Carbs: " + JoH.qs(evaluation[0], 0)); - bwp_update = "\u224F" + " Carbs: " + JoH.qs(evaluation[0], 0); + bwp_update = "\u224F" + " Carbs: " + JoH.qs(evaluation[0], 0); // TODO I18n //annotationValues.add(iv); // needs to be different value list so we can make annotation nicer } else if (evaluation[1] > Profile.minimum_insulin_recommendation) { //PointValue iv = new HPointValue((double) fuzzed_timestamp, (float) (11 * bgScale)); //iv.setLabel("+Insulin: " + JoH.qs(evaluation[1], 1)); keyStore.putS("bwp_last_insulin", JoH.qs(evaluation[1], 1) + ((low_occurs_at > 0) ? ("!") : "")); keyStore.putL("bwp_last_insulin_timestamp", JoH.tsl()); - bwp_update = "\u224F" + " Insulin: " + JoH.qs(evaluation[1], 1) + ((low_occurs_at > 0) ? (" " + "\u26A0") : ""); // warning symbol + bwp_update = "\u224F" + " Insulin: " + JoH.qs(evaluation[1], 1) + ((low_occurs_at > 0) ? (" " + "\u26A0") : ""); // warning symbol // TODO I18n //annotationValues.add(iv); // needs to be different value list so we can make annotation nicer } } } + keyStore.putS("last_bwp", bwp_update); + keyStore.putL("last_bwp_timestamp", JoH.tsl()); Home.updateStatusLine("bwp", bwp_update); // always send so we can blank if needed } @@ -2080,7 +2093,7 @@ public Axis xAxis() { calendar.add(Calendar.HOUR, 1); } while (calendar.getTimeInMillis() < ((end_time * FUZZER) + ((long) predictivehours * 60 * 60 * 1000))) { - xAxisValues.add(new AxisValue((HPointValue.convert((double)calendar.getTimeInMillis() / FUZZER)), (timeFormat.format(calendar.getTimeInMillis())).toCharArray())); + xAxisValues.add(new AxisValue(((double)calendar.getTimeInMillis() / FUZZER), (timeFormat.format(calendar.getTimeInMillis())).toCharArray())); calendar.add(Calendar.HOUR, 1); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BgSendQueue.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BgSendQueue.java similarity index 94% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BgSendQueue.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BgSendQueue.java index 28fce1df20..658c413fc9 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BgSendQueue.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BgSendQueue.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.appwidget.AppWidgetManager; import android.content.ComponentName; @@ -14,16 +14,15 @@ import com.activeandroid.query.Select; import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.NewDataObserver; -import com.eveningoutpost.dexdrip.Services.SyncService; +import com.eveningoutpost.dexdrip.services.SyncService; import com.eveningoutpost.dexdrip.WidgetUpdateService; import com.eveningoutpost.dexdrip.calibrations.PluggableCalibration; import com.eveningoutpost.dexdrip.xDripWidget; -import com.rits.cloning.Cloner; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BgSparklineBuilder.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BgSparklineBuilder.java similarity index 94% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BgSparklineBuilder.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BgSparklineBuilder.java index b73435a8cc..c8efffe830 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BgSparklineBuilder.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BgSparklineBuilder.java @@ -1,15 +1,13 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.content.Context; -import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Matrix; -import android.util.DisplayMetrics; import android.view.View; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; import java.util.ArrayList; import java.util.Date; @@ -46,6 +44,8 @@ public class BgSparklineBuilder { protected boolean useSmallDots = true; protected boolean useTinyDots = false; protected boolean showFiltered = false; + + protected Integer useSpecificDotSize = null; protected int backgroundColor = Color.TRANSPARENT; protected final static int SCALE_TRIGGER = 84; @@ -125,6 +125,11 @@ public BgSparklineBuilder setSmallDots() { public BgSparklineBuilder setTinyDots() { return this.setTinyDots(true); } + public BgSparklineBuilder setDotSize(int size) { + this.useSpecificDotSize = size; + return this; + } + public BgSparklineBuilder setBackgroundColor(int color) { this.backgroundColor = color; @@ -215,6 +220,10 @@ public Bitmap build() { for(Line line: lines) line.setPointRadius(1); } + if (useSpecificDotSize != null) { + for(Line line: lines) + line.setPointRadius(useSpecificDotSize); + } LineChartData lineData = new LineChartData(lines); if (showAxes) { if (height<=SCALE_TRIGGER) { @@ -233,8 +242,8 @@ public Bitmap build() { chart.setBackgroundColor(backgroundColor); chart.setLineChartData(lineData); Viewport viewport = chart.getMaximumViewport(); - viewport.left = HPointValue.convert(start); - viewport.right = HPointValue.convert(end); + viewport.left = start; + viewport.right = end; if (height<=SCALE_TRIGGER) { // for pebble classic we always want the lowest mark to be in the same place on the image diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Blukon.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Blukon.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Blukon.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Blukon.java index 85903ea82e..6f8448ca00 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Blukon.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Blukon.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.app.Activity; import android.app.AlertDialog; @@ -7,19 +7,18 @@ import android.view.WindowManager; import android.widget.EditText; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.LibreBlock; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.SensorSanity; -import com.eveningoutpost.dexdrip.Models.TransmitterData; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.ActiveBluetoothDevice; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.LibreBlock; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.SensorSanity; +import com.eveningoutpost.dexdrip.models.TransmitterData; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.NFCReaderX; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.DexCollectionService; +import com.eveningoutpost.dexdrip.services.DexCollectionService; import com.eveningoutpost.dexdrip.utils.CheckBridgeBattery; import com.eveningoutpost.dexdrip.utils.CipherUtils; import com.eveningoutpost.dexdrip.xdrip; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BridgeBattery.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BridgeBattery.java similarity index 90% rename from wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BridgeBattery.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BridgeBattery.java index 3381def703..2d3192a3a6 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BridgeBattery.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BridgeBattery.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import com.eveningoutpost.dexdrip.utils.DexCollectionType; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BridgeResponse.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BridgeResponse.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BridgeResponse.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BridgeResponse.java index 75b0fcb0b8..9d0144ea51 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BridgeResponse.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BridgeResponse.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import java.nio.ByteBuffer; import java.util.LinkedList; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BroadcastGlucose.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BroadcastGlucose.java similarity index 74% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BroadcastGlucose.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BroadcastGlucose.java index 8aa9b27da1..25d9542b57 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BroadcastGlucose.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BroadcastGlucose.java @@ -1,22 +1,26 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; -import static com.eveningoutpost.dexdrip.Models.JoH.dateTimeText; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.MINUTE_IN_MS; +import static com.eveningoutpost.dexdrip.models.JoH.dateTimeText; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.getTransmitterID; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Unitized.usingMgDl; +import static com.eveningoutpost.dexdrip.utils.DexCollectionType.getBestCollectorHardwareName; import android.content.Intent; import android.os.Bundle; import com.eveningoutpost.dexdrip.BestGlucose; import com.eveningoutpost.dexdrip.BuildConfig; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Noise; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.g5model.DexSessionKeeper; +import com.eveningoutpost.dexdrip.g5model.FirmwareCapability; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Noise; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.utils.DexCollectionType; -import com.eveningoutpost.dexdrip.utils.PowerStateReceiver; import lombok.val; @@ -26,6 +30,10 @@ public class BroadcastGlucose { private static final String TAG = "BroadcastGlucose"; private static long lastTimestamp = 0; + private static long dexStartedAt = 0; + private static boolean connectedToG7 = false; + private static boolean connectedToG6 = false; + private static boolean usingG6OrG7 = false; public static void sendLocalBroadcast(final BgReading bgReading) { if (SendXdripBroadcast.enabled()) { @@ -63,8 +71,11 @@ public static void sendLocalBroadcast(final BgReading bgReading) { UserError.Log.i("SENSOR QUEUE:", "Broadcast data"); - String collectorName = DexCollectionType.getBestCollectorHardwareName(); - if (collectorName.equals("G6 Native")) { + String collectorName = getBestCollectorHardwareName(); + if (collectorName.equals("G6 Native") || collectorName.equals("G7")) { + if (collectorName.equals("G7")) { + collectorName = "G6 Native"; // compatibility for older AAPS + } collectorName += " / G5 Native"; // compatibility for older AAPS } bundle.putString(Intents.XDRIP_DATA_SOURCE_DESCRIPTION, collectorName); @@ -144,8 +155,29 @@ public static void sendLocalBroadcast(final BgReading bgReading) { } bundle.putInt(Intents.EXTRA_SENSOR_BATTERY, BridgeBattery.getBestBridgeBattery()); + if (getBestCollectorHardwareName().equals("G7") || getBestCollectorHardwareName().equals("Native G6")) { // If we are using G7 or One+, or G6 in native mode + usingG6OrG7 = true; + } + if (getBestCollectorHardwareName().equals("G7") && FirmwareCapability.isDeviceG7(getTransmitterID())) { // If we are using G7 or One+ and there is connectivity + connectedToG7 = true; + } + if (getBestCollectorHardwareName().equals("G6 Native") && FirmwareCapability.isTransmitterG6(getTransmitterID())) { // If we are using a G6 in native mode and there is connectivity + connectedToG6 = true; + } + if (usingG6OrG7) { // If we are using G7 or G6 in native mode + if (connectedToG6 || connectedToG7) { // Only if there is connectivity + dexStartedAt = DexSessionKeeper.getStart(); // Session start time reported by the Dexcom transmitter + if (dexStartedAt > 0) { // Only if dexStartedAt is valid + bundle.putLong(Intents.EXTRA_SENSOR_STARTED_AT, dexStartedAt); + } + } + } else { // If we are not using G7, One+ or G6 in native mode + bundle.putLong(Intents.EXTRA_SENSOR_STARTED_AT, sensor.started_at); + } bundle.putLong(Intents.EXTRA_TIMESTAMP, bgReading.timestamp); + addDisplayInformation(bundle); + //raw value double slope = 0, intercept = 0, scale = 0, filtered = 0, unfiltered = 0, raw = 0; final Calibration cal = Calibration.lastValid(); @@ -193,4 +225,8 @@ private static void addCollectorStatus(final Bundle bundle) { bundle.putString(Intents.EXTRA_COLLECTOR_NANOSTATUS, result); } } + + private static void addDisplayInformation(final Bundle bundle) { + bundle.putString(Intents.EXTRA_DISPLAY_UNITS, Unitized.unit(usingMgDl())); + } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BroadcastSnooze.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BroadcastSnooze.java similarity index 83% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BroadcastSnooze.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BroadcastSnooze.java index 72ef42e18d..82a7e76d7a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BroadcastSnooze.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BroadcastSnooze.java @@ -1,10 +1,10 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.content.Intent; import com.eveningoutpost.dexdrip.BuildConfig; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import static com.eveningoutpost.dexdrip.xdrip.getAppContext; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BroadcastSnoozeReceiver.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BroadcastSnoozeReceiver.java similarity index 92% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BroadcastSnoozeReceiver.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BroadcastSnoozeReceiver.java index 3f33adae35..70de6ed7be 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/BroadcastSnoozeReceiver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BroadcastSnoozeReceiver.java @@ -1,11 +1,11 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import com.eveningoutpost.dexdrip.BuildConfig; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; /** * jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/CalibrationSendQueue.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/CalibrationSendQueue.java similarity index 88% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/CalibrationSendQueue.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/CalibrationSendQueue.java index f9c25cc604..c37d0fc5a6 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/CalibrationSendQueue.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/CalibrationSendQueue.java @@ -1,8 +1,6 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.content.Context; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; import android.provider.BaseColumns; import com.activeandroid.Model; @@ -10,9 +8,9 @@ import com.activeandroid.annotation.Table; import com.activeandroid.query.Delete; import com.activeandroid.query.Select; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.UserError.Log; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/CollectionServiceStarter.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/CollectionServiceStarter.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/CollectionServiceStarter.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/CollectionServiceStarter.java index a78ce7c8d5..8f5de0272a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/CollectionServiceStarter.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/CollectionServiceStarter.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.content.Context; import android.content.Intent; @@ -10,16 +10,16 @@ import com.eveningoutpost.dexdrip.BuildConfig; import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.Services.DexCollectionService; -import com.eveningoutpost.dexdrip.Services.DexShareCollectionService; -import com.eveningoutpost.dexdrip.Services.DoNothingService; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; -import com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService; -import com.eveningoutpost.dexdrip.Services.WifiCollectionService; -import com.eveningoutpost.dexdrip.UtilityModels.pebble.PebbleUtil; -import com.eveningoutpost.dexdrip.UtilityModels.pebble.PebbleWatchSync; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.services.DexCollectionService; +import com.eveningoutpost.dexdrip.services.DexShareCollectionService; +import com.eveningoutpost.dexdrip.services.DoNothingService; +import com.eveningoutpost.dexdrip.services.G5CollectionService; +import com.eveningoutpost.dexdrip.services.Ob1G5CollectionService; +import com.eveningoutpost.dexdrip.services.WifiCollectionService; +import com.eveningoutpost.dexdrip.utilitymodels.pebble.PebbleUtil; +import com.eveningoutpost.dexdrip.utilitymodels.pebble.PebbleWatchSync; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.wearintegration.WatchUpdaterService; import com.eveningoutpost.dexdrip.xdrip; @@ -28,6 +28,7 @@ import static com.eveningoutpost.dexdrip.utils.DexCollectionType.NSFollow; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.SHFollow; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.WebFollow; +import static com.eveningoutpost.dexdrip.utils.DexCollectionType.CLFollow; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.getCollectorServiceClass; /** @@ -231,6 +232,7 @@ private void stopAll() { JoH.stopService(getCollectorServiceClass(NSFollow)); JoH.stopService(getCollectorServiceClass(SHFollow)); JoH.stopService(getCollectorServiceClass(WebFollow)); + JoH.stopService(getCollectorServiceClass(CLFollow)); } private void start(Context context, String collection_method) { @@ -335,7 +337,8 @@ private void start(Context context, String collection_method) { // TODO newer item startups should be consolidated in to a DexCollectionType has set to avoid duplicating logic if (DexCollectionType.hasBluetooth() || DexCollectionType.getDexCollectionType() == NSFollow || DexCollectionType.getDexCollectionType() == SHFollow - || DexCollectionType.getDexCollectionType() == WebFollow) { // TODO make this a set lookup + || DexCollectionType.getDexCollectionType() == WebFollow + || DexCollectionType.getDexCollectionType() == CLFollow) { // TODO make this a set lookup Log.d(TAG, "Starting service based on collector lookup"); startServiceCompat(new Intent(context, DexCollectionType.getCollectorServiceClass())); } @@ -507,7 +510,7 @@ private void startServiceCompat(final Class service) { @SuppressWarnings("ConstantConditions") private void startServiceCompat(final Intent intent) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O - && BuildConfig.targetSDK >= Build.VERSION_CODES.N + // && BuildConfig.targetSDK >= Build.VERSION_CODES.N && ForegroundServiceStarter.shouldRunCollectorInForeground()) { try { Log.d(TAG, String.format("Starting oreo foreground service: %s", intent.getComponent().getClassName())); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/ColorCache.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/ColorCache.java similarity index 77% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/ColorCache.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/ColorCache.java index 52cc9721a3..5dd3e230ea 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/ColorCache.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/ColorCache.java @@ -1,9 +1,12 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.graphics.Color; +import android.preference.PreferenceManager; import android.util.Log; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.R; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.xdrip; import java.util.EnumMap; @@ -25,8 +28,24 @@ public static void invalidateCache() { if (debug) Log.i(TAG, "Cache cleared"); } + public static void setDefaultsLoaded() { + defaultsLoaded = true; + } + + private static volatile boolean defaultsLoaded = false; + public static int getCol(final X color) { + if (color == null) return 0xABCDEF; if (!the_cache.containsKey(color)) { + if (!defaultsLoaded) { + try { + the_cache.clear(); + PreferenceManager.setDefaultValues(xdrip.getAppContext(), R.xml.xdrip_plus_prefs, false); + setDefaultsLoaded(); + } catch (Exception e) { + // + } + } try { the_cache.put(color, Pref.getInt(color.internalName, 0xABCDEF)); } catch (ClassCastException e) { @@ -36,9 +55,14 @@ public static int getCol(final X color) { if (debug) UserError.Log.d(TAG, "Setting cache for color: " + color.internalName + " / " + Pref.getInt(color.internalName, 1234)); } - return the_cache.get(color); + try { + return the_cache.get(color); + } catch (NullPointerException e) { + return 0xABCDEF; + } } + public enum X { color_high_values("color_high_values"), diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/ColorPicker.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/ColorPicker.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/ColorPicker.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/ColorPicker.java index 89de7efb7f..843793abd4 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/ColorPicker.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/ColorPicker.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.content.Context; import android.content.res.TypedArray; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/CompatibleApps.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/CompatibleApps.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/CompatibleApps.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/CompatibleApps.java index 19f32c88e3..50d4a43e4a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/CompatibleApps.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/CompatibleApps.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.app.Activity; import android.app.ActivityManager; @@ -9,20 +9,22 @@ import android.content.DialogInterface; import android.content.Intent; import android.os.Build; -import android.support.v4.app.NotificationCompat; -import android.support.v7.app.AlertDialog; + +import androidx.appcompat.app.AlertDialog; +import androidx.core.app.NotificationCompat; + import com.eveningoutpost.dexdrip.BuildConfig; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.G5BaseService; +import com.eveningoutpost.dexdrip.services.G5BaseService; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.webservices.XdripWebService; import com.eveningoutpost.dexdrip.xdrip; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.COMPATIBLE_BASE_ID; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.COMPATIBLE_BASE_ID; /** * Created by jamorham on 01/11/2017. @@ -140,7 +142,7 @@ private static void enableAndroid10Workarounds() { if (!PersistentStore.getBoolean(ANDROID_10_WORKAROUND_MARKER, false)) { UserError.Log.ueh(CompatibleApps.class.getSimpleName(),"Enabling default workarounds for Android 10+ setting minimize/avoid scanning to enabled"); Pref.setBoolean("ob1_minimize_scanning", true); - Pref.setBoolean("ob1_avoid_scanning", true); + // Pref.setBoolean("ob1_avoid_scanning", true); PersistentStore.setBoolean(ANDROID_10_WORKAROUND_MARKER, true); } } diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Constants.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Constants.java similarity index 79% rename from wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Constants.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Constants.java index 2998fcf19e..160d9e8346 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Constants.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Constants.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; /** * Various constants @@ -14,6 +14,7 @@ public class Constants { public static final long DAY_IN_MS = 86_400_000; public static final long WEEK_IN_MS = DAY_IN_MS * 7; public static final long MONTH_IN_MS = DAY_IN_MS * 30; + public static final long YEAR_IN_MS = DAY_IN_MS * 365; public static final double LIBRE_MULTIPLIER = 117.64705; // to match (raw/8.5)*1000 @@ -51,16 +52,29 @@ public class Constants { public static final int BLUEJAY_SERVICE_RETRY_ID = 1025; public static final int MIBAND_SERVICE_RETRY_ID = 1026; public static final int MIBAND_SERVICE_BG_RETRY_ID = 1027; + public static final int WEBFOLLOW_SERVICE_FAILOVER_ID = 1028; + public static final int BACKUP_ACTIVITY_ID = 1029; + public static final int CARELINK_SERVICE_FAILOVER_ID = 1030; static final int NIGHTSCOUT_ERROR_NOTIFICATION_ID = 2001; + public static final int HEALTH_CONNECT_RESPONSE_ID = 2002; + public static final int SENSORY_EXPIRY_NOTIFICATION_ID = 2003; + // increments from this start number public static final int INCOMPATIBLE_BASE_ID = 5000; public static final int COMPATIBLE_BASE_ID = 6000; public static final int DEX_BASE_ID = 6400; + public static final int SETTINGS_INADVISABLE_BASE_ID = 7000; // public static final int HEART_RATE_JOB_ID = 60920012; public static final int APK_DOWNLOAD_JOB_ID = 60920014; + public static final int LIBRE_1_2_FRAM_SIZE = 344; + + public static final int LIBREPRO_HEADER1_SIZE = 40; + public static final int LIBREPRO_HEADER2_SIZE = 32; + public static final int LIBREPRO_HEADER3_SIZE = 104; + } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/DexShareAttributes.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/DexShareAttributes.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/DexShareAttributes.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/DexShareAttributes.java index 643e6742fe..237187ceb7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/DexShareAttributes.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/DexShareAttributes.java @@ -1,6 +1,5 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; -import java.math.BigInteger; import java.util.UUID; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Experience.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Experience.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Experience.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Experience.java index ecaf1ee0a2..cad2096e28 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Experience.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Experience.java @@ -1,15 +1,15 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; -import android.support.annotation.StringRes; +import androidx.annotation.StringRes; import com.eveningoutpost.dexdrip.BuildConfig; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.utils.Preferences; import com.eveningoutpost.dexdrip.utils.SdcardImportExport; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/ForegroundServiceStarter.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/ForegroundServiceStarter.java similarity index 93% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/ForegroundServiceStarter.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/ForegroundServiceStarter.java index 5d8505f7f4..648ba43d40 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/ForegroundServiceStarter.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/ForegroundServiceStarter.java @@ -1,16 +1,16 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.app.Service; import android.content.Context; import android.os.Build; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST; -import static com.eveningoutpost.dexdrip.UtilityModels.Notifications.ongoingNotificationId; +import static com.eveningoutpost.dexdrip.utilitymodels.Notifications.ongoingNotificationId; /** * Created by Emma Black on 12/25/14. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/GraphTools.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/GraphTools.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/GraphTools.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/GraphTools.java index 82fe8d8247..cc7404ec1b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/GraphTools.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/GraphTools.java @@ -1,10 +1,10 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; // jamorham import android.util.Pair; -import com.eveningoutpost.dexdrip.Models.BgReading; +import com.eveningoutpost.dexdrip.models.BgReading; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/HM10Attributes.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/HM10Attributes.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/HM10Attributes.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/HM10Attributes.java index bcc6557c2f..222c4a12b5 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/HM10Attributes.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/HM10Attributes.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; /** * Created by Emma Black on 10/26/14. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/HPointValue.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/HPointValue.java new file mode 100644 index 0000000000..77442684e7 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/HPointValue.java @@ -0,0 +1,34 @@ +package com.eveningoutpost.dexdrip.utilitymodels; + +import static com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder.FUZZER; + +import lecho.lib.hellocharts.model.PointValue; +import lombok.AllArgsConstructor; + +/** + * JamOrHam + *

+ * Handle de-fuzzing and legacy calls + */ + +@AllArgsConstructor +public class HPointValue extends PointValue { + + public HPointValue set(double x, double y) { + super.set(x, y); + return this; + } + + public HPointValue(double x, float y) { + super(x, y); + } + + public HPointValue(double x, double y) { + super(x, y); + } + + public long getTimeStamp() { + return (long) (getX() * FUZZER); + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/IdempotentMigrations.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/IdempotentMigrations.java similarity index 79% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/IdempotentMigrations.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/IdempotentMigrations.java index b1a7f33853..9344057bce 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/IdempotentMigrations.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/IdempotentMigrations.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.content.Context; import android.content.SharedPreferences; @@ -6,18 +6,18 @@ import android.preference.PreferenceManager; import android.util.Log; -import com.eveningoutpost.dexdrip.Models.APStatus; -import com.eveningoutpost.dexdrip.Models.AlertType; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.DesertSync; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Libre2RawValue; -import com.eveningoutpost.dexdrip.Models.Libre2Sensor; -import com.eveningoutpost.dexdrip.Models.LibreBlock; -import com.eveningoutpost.dexdrip.Models.LibreData; -import com.eveningoutpost.dexdrip.Models.PenData; -import com.eveningoutpost.dexdrip.Models.Prediction; -import com.eveningoutpost.dexdrip.Models.UserNotification; +import com.eveningoutpost.dexdrip.models.APStatus; +import com.eveningoutpost.dexdrip.models.AlertType; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.DesertSync; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Libre2RawValue; +import com.eveningoutpost.dexdrip.models.Libre2Sensor; +import com.eveningoutpost.dexdrip.models.LibreBlock; +import com.eveningoutpost.dexdrip.models.LibreData; +import com.eveningoutpost.dexdrip.models.PenData; +import com.eveningoutpost.dexdrip.models.Prediction; +import com.eveningoutpost.dexdrip.models.UserNotification; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.SnoozeActivity; @@ -56,8 +56,10 @@ public void performAll() { AlertType.fixUpTable(); UserNotification.updateDB(); JoH.clearCache(); + legacySettingsFix(); IncompatibleApps.notifyAboutIncompatibleApps(); CompatibleApps.notifyAboutCompatibleApps(); + legacySettingsMoveLanguageFromNoToNb(); } @@ -141,4 +143,18 @@ public static void migrateOOP2CalibrationPreferences() { } } + // Force legacy settings to be at their recommended values + private static void legacySettingsFix() { + Pref.setBoolean("use_ob1_g5_collector_service", true); + Pref.setBoolean("ob1_g5_fallback_to_xdrip", false); + Pref.setBoolean("always_unbond_G5", false); + Pref.setBoolean("always_get_new_keys", true); + } + private static void legacySettingsMoveLanguageFromNoToNb() { + // Check if the user's language preference is set to "no" + if ("no".equals(Pref.getString("forced_language", ""))) { + // Update the language preference to "nb" + Pref.setString("forced_language", "nb"); + } + } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/IncompatibleApps.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/IncompatibleApps.java similarity index 73% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/IncompatibleApps.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/IncompatibleApps.java index a8786363f6..1364e3e3e8 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/IncompatibleApps.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/IncompatibleApps.java @@ -1,15 +1,17 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.content.Context; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.xdrip; import java.util.ArrayList; import java.util.List; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.INCOMPATIBLE_BASE_ID; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.INCOMPATIBLE_BASE_ID; + +import lombok.val; /** * Created by jamorham on 01/11/2017. @@ -54,6 +56,15 @@ public static void notifyAboutIncompatibleApps() { } } + final List speedApps = new ArrayList<>(); + speedApps.add("com.mediatek.duraspeed"); + for (val app : speedApps) { + if (InstalledApps.checkPackageExists(context, app)) { + if (JoH.pratelimit(app + NOTIFY_MARKER, RENOTIFY_TIME)) { + id = notify2("Nasty Power Manager", app, "DuraSpeed" + " " + xdrip.getAppContext().getString(R.string.aggressive_power_manager), id); + } + } + } } private static int notify(String short_name, String package_string, String msg, int id) { @@ -61,5 +72,10 @@ private static int notify(String short_name, String package_string, String msg, return id + 1; } + private static int notify2(String short_name, String package_string, String msg, int id) { + JoH.showNotification(short_name, msg, null, id, true, true, null, null, ((msg.length() > 0) ? msg + "\n\n" : "") + "The Package identifier is: " + package_string); + return id + 1; + } + } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Inevitable.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Inevitable.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Inevitable.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Inevitable.java index c781d67820..9f6fb5755f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Inevitable.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Inevitable.java @@ -1,9 +1,9 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.os.PowerManager; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import java.util.concurrent.ConcurrentHashMap; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/InstalledApps.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/InstalledApps.java similarity index 88% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/InstalledApps.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/InstalledApps.java index 48022320d7..6e4cc58989 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/InstalledApps.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/InstalledApps.java @@ -1,4 +1,6 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; + +import static com.eveningoutpost.dexdrip.watch.thinjam.BlueJayEntry.isNative; import android.content.ComponentName; import android.content.Context; @@ -8,7 +10,7 @@ import android.content.pm.ResolveInfo; import android.util.Log; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import java.util.List; @@ -23,7 +25,7 @@ public class InstalledApps { private static final String GOOGLE_PLAY_SERVICES_PACKAGE = "com.google.android.gms"; public static boolean isGooglePlayInstalled(Context context) { - return checkPackageExists(context, GOOGLE_PLAY_SERVICES_PACKAGE); + return isNative() || checkPackageExists(context, GOOGLE_PLAY_SERVICES_PACKAGE); } public static boolean checkPackageExists(Context context, String packageName) { diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Intents.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Intents.java similarity index 64% rename from wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Intents.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Intents.java index cc352c9ec2..5eda8666f0 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Intents.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Intents.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; /** * For integration. @@ -12,6 +12,7 @@ public interface Intents { String EXTRA_BG_SLOPE = "com.eveningoutpost.dexdrip.Extras.BgSlope"; String EXTRA_BG_SLOPE_NAME = "com.eveningoutpost.dexdrip.Extras.BgSlopeName"; String EXTRA_SENSOR_BATTERY = "com.eveningoutpost.dexdrip.Extras.SensorBattery"; + String EXTRA_SENSOR_STARTED_AT = "com.eveningoutpost.dexdrip.Extras.SensorStartedAt"; String EXTRA_TIMESTAMP = "com.eveningoutpost.dexdrip.Extras.Time"; String EXTRA_RAW = "com.eveningoutpost.dexdrip.Extras.Raw"; String EXTRA_NOISE = "com.eveningoutpost.dexdrip.Extras.Noise"; @@ -34,13 +35,18 @@ public interface Intents { String EXTRA_COLLECTOR_NANOSTATUS = "com.eveningoutpost.dexdrip.Extras.Collector.NanoStatus"; + String EXTRA_DISPLAY_UNITS = "com.eveningoutpost.dexdrip.Extras.Display.Units"; + // From NS Android Client // send String ACTION_NEW_TREATMENT = "info.nightscout.client.NEW_TREATMENT"; + String ACTION_NEW_FOOD = "info.nightscout.client.NEW_FOOD"; + String ACTION_NEW_DEVICESTATUS = "info.nightscout.client.NEW_DEVICESTATUS"; String ACTION_CHANGED_TREATMENT = "info.nightscout.client.CHANGED_TREATMENT"; String ACTION_REMOVED_TREATMENT = "info.nightscout.client.REMOVED_TREATMENT"; String ACTION_NEW_PROFILE = "info.nightscout.client.NEW_PROFILE"; String ACTION_NEW_SGV = "info.nightscout.client.NEW_SGV"; + String ACTION_NS_BRIDGE = "info.nightscout.client.NS_BRIDGE"; @@ -49,11 +55,11 @@ public interface Intents { String LIBRE_ALARM_TO_XDRIP_PLUS = "com.eveningoutpost.dexdrip.FROM_LIBRE_ALARM"; String XDRIP_PLUS_NS_EMULATOR = "com.eveningoutpost.dexdrip.NS_EMULATOR"; String BLUEJAY_THINJAM_API = "com.eveningoutpost.dexdrip.THINJAM_API"; - + String BLUEJAY_THINJAM_EMIT = "com.eveningoutpost.dexdrip.THINJAM_EMIT"; // Local Broadcasts String HOME_STATUS_ACTION = "com.eveningoutpost.dexdrip.HOME_STATUS_ACTION"; - // Send to LibreXposed + // Send to external decoder String XDRIP_PLUS_LIBRE_DATA = "com.eveningoutpost.dexdrip.LIBRE_DATA"; String LIBRE_DATA_BUFFER = "com.eveningoutpost.dexdrip.Extras.DATA_BUFFER"; String LIBRE_PATCH_UID_BUFFER = "com.eveningoutpost.dexdrip.Extras.LIBRE_PATCH_UID_BUFFER"; @@ -61,8 +67,37 @@ public interface Intents { String LIBRE_DATA_TIMESTAMP = "com.eveningoutpost.dexdrip.Extras.TIMESTAMP"; String LIBRE_SN = "com.eveningoutpost.dexdrip.Extras.LIBRE_SN"; + String LIBRE_RAW_ID = "com.eveningoutpost.dexdrip.Extras.LIBRE_RAW_ID"; String LIBRE2_BG = "com.librelink.app.ThirdPartyIntegration.GLUCOSE_READING"; String LIBRE2_ACTIVATION = "com.librelink.app.ThirdPartyIntegration.SENSOR_ACTIVATE"; + String LIBRE2_SCAN = "com.librelink.app.ThirdPartyIntegration.SENSOR_SCAN"; + String LIBRE2_CONNECTION = "com.librelink.app.ThirdPartyIntegration.CONNECTION_STATE"; + + + // oop 2 + String XDRIP_DECODE_FARM_RESULT = "com.eveningoutpost.dexdrip.OOP2_DECODE_FARM_RESULT"; + String XDRIP_DECODE_BLE_RESULT = "com.eveningoutpost.dexdrip.OOP2_DECODE_BLE_RESULT"; + String XDRIP_BLUETOOTH_ENABLE_RESULT = "com.eveningoutpost.dexdrip.OOP2_BLUETOOTH_ENABLE_RESULT"; + String XDRIP_PLUS_LIBRE_BLE_DATA = "com.eveningoutpost.dexdrip.LIBRE_BLE_DATA"; + String XDRIP_PLUS_BLUETOOTH_ENABLE = "com.eveningoutpost.dexdrip.BLUETOOTH_ENABLE"; + String DECODED_BUFFER = "DecodedBuffer"; + String PATCH_UID = "PatchUid"; + String PATCH_INFO = "PatchInfo"; + String ENABLE_TIME = "EnableTime"; + String CONNECTION_INDEX = "ConnectionIndex"; + String BT_UNLOCK_BUFFER_COUNT = "BtUnlockBufferCount"; + String BT_UNLOCK_BUFFER = "BtUnlockBuffer"; + String NFC_UNLOCK_BUFFER = "NfcUnlockBuffer"; + String DEVICE_NAME = "DeviceName"; + String DEVICE_MAC_ADDRESS = "MacAddress"; + String BT_UNLOCK_BUFFER_ARRAY = "BtUnlockBufferArray"; + String TREND_BG = "TrendBg"; + String HISTORIC_BG = "HistoricBg"; + String OOP2_VERSION_NAME = "OOP2_VERSION"; + + String TAG_ID = "TagId"; + String ROW_ID = "RowId"; + String PREFERENCE_INTENT = "com.eveningoutpost.dexdrip.utils.PROGRESS"; } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/JamorhamShowcaseDrawer.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/JamorhamShowcaseDrawer.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/JamorhamShowcaseDrawer.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/JamorhamShowcaseDrawer.java index 56b5ab499f..3efbf1cb8e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/JamorhamShowcaseDrawer.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/JamorhamShowcaseDrawer.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; /** * Created by jamorham on 20/06/2016. @@ -7,8 +7,6 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; -import android.util.DisplayMetrics; -import android.util.Log; import com.eveningoutpost.dexdrip.R; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/LibreUtils.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/LibreUtils.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/LibreUtils.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/LibreUtils.java index 5446cda46d..8f9c2386eb 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/LibreUtils.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/LibreUtils.java @@ -1,10 +1,10 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.LibreOOPAlgorithm; -import com.eveningoutpost.dexdrip.Models.SensorSanity; +import com.eveningoutpost.dexdrip.models.LibreOOPAlgorithm; +import com.eveningoutpost.dexdrip.models.SensorSanity; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; public class LibreUtils { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/LowPriorityThread.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/LowPriorityThread.java similarity index 85% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/LowPriorityThread.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/LowPriorityThread.java index 27dfb7649e..7cccf61e87 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/LowPriorityThread.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/LowPriorityThread.java @@ -1,8 +1,8 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.os.PowerManager; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/MockDataSource.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/MockDataSource.java similarity index 59% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/MockDataSource.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/MockDataSource.java index 82e8249086..3042464f4f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/MockDataSource.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/MockDataSource.java @@ -1,7 +1,7 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import org.json.JSONException; import org.json.JSONObject; @@ -20,14 +20,26 @@ public class MockDataSource { private static final String PREF_BROKEN_RAW = "MockDataSource-broken-raw"; + private static final String PREF_SPEED_UP = "MockDataSource-speed-up"; + + private static final String PREF_AMPLIFY = "MockDataSource-amplify"; + + public static double divisor_scale = 5000000; + public static double amplify_cnst = 100000; + public static String getFakeWifiData() { long time = JoH.tsl(); - double divisor_scale = 5000000; + if (Pref.getBooleanDefaultFalse(PREF_SPEED_UP)) { + divisor_scale = 1500000; + } double mod_raw = (time / divisor_scale) % Math.PI; double mod_filtered = ((time - 500000) / divisor_scale) % Math.PI; - double raw_value = (Math.sin(mod_raw) * 100000) + 50000; - double filtered_value = (Math.sin(mod_filtered) * 100000) + 50000; + if (Pref.getBooleanDefaultFalse(PREF_AMPLIFY)) { + amplify_cnst = 330000; + } + double raw_value = (Math.sin(mod_raw) * amplify_cnst) + 50000; + double filtered_value = (Math.sin(mod_filtered) * amplify_cnst) + 50000; if (Pref.getBooleanDefaultFalse(PREF_BROKEN_RAW)) { raw_value = Math.sin(mod_raw) * 1000; @@ -50,6 +62,11 @@ public static String getFakeWifiData() { return json.toString(); } + public static void defaults() { + Pref.setBoolean(PREF_SPEED_UP, false); + Pref.setBoolean(PREF_AMPLIFY, false); + } + public static void breakRaw() { Pref.setBoolean(PREF_BROKEN_RAW, true); } @@ -57,6 +74,14 @@ public static void breakRaw() { public static void fixRaw() { Pref.setBoolean(PREF_BROKEN_RAW, false); } + + public static void speedup() { + Pref.setBoolean(PREF_SPEED_UP, true); + } + + public static void amplify() { + Pref.setBoolean(PREF_AMPLIFY, true); + } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/MtpConfigure.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/MtpConfigure.java similarity index 92% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/MtpConfigure.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/MtpConfigure.java index edb1e542fc..270f6a2446 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/MtpConfigure.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/MtpConfigure.java @@ -1,15 +1,15 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.content.Intent; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbManager; import android.os.Build; -import android.support.annotation.RequiresApi; -import android.support.annotation.StringRes; +import androidx.annotation.RequiresApi; +import androidx.annotation.StringRes; import android.text.SpannableString; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.ui.helpers.Span; import com.eveningoutpost.dexdrip.utils.usb.MtpTools.MtpDeviceHelper; import com.eveningoutpost.dexdrip.utils.usb.UsbTools; @@ -18,9 +18,9 @@ import java.nio.charset.Charset; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.BAD; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.GOOD; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.NORMAL; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.BAD; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.GOOD; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.NORMAL; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.DEX_COLLECTION_METHOD; import static com.eveningoutpost.dexdrip.utils.GetWearApk.getBytes; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/MtpConfigureActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/MtpConfigureActivity.java similarity index 89% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/MtpConfigureActivity.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/MtpConfigureActivity.java index f32fb83619..7db37dd9c6 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/MtpConfigureActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/MtpConfigureActivity.java @@ -1,10 +1,12 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.os.Build; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import com.eveningoutpost.dexdrip.Models.JoH; + +import androidx.appcompat.app.AppCompatActivity; + +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.databinding.ActivityMtpConfigureBinding; import com.eveningoutpost.dexdrip.utils.usb.UsbTools; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/NanoStatus.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/NanoStatus.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/NanoStatus.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/NanoStatus.java index 3bd1de9ceb..5716b0ba10 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/NanoStatus.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/NanoStatus.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; /** * NanoStatus allows access to a static class based status interface @@ -12,16 +12,16 @@ * */ -import android.databinding.ObservableField; +import androidx.databinding.ObservableField; import android.text.SpannableString; import android.util.Log; import com.eveningoutpost.dexdrip.BuildConfig; -import com.eveningoutpost.dexdrip.G5Model.SensorDays; +import com.eveningoutpost.dexdrip.g5model.SensorDays; import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.adapters.SpannableSerializer; import com.eveningoutpost.dexdrip.utils.DexCollectionType; @@ -31,7 +31,7 @@ import lombok.Setter; import lombok.val; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; public class NanoStatus { @@ -123,7 +123,7 @@ public static SpannableString nanoStatusColor(final String module) { case "collector": return collectorNano(DexCollectionType.getCollectorServiceClass()); case "mtp-configure": - return collectorNano(getClassByName(".UtilityModels.MtpConfigure")); + return collectorNano(getClassByName(".utilitymodels.MtpConfigure")); case "sensor-expiry": return getLocalOrRemoteSensorExpiry(); default: diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/NightscoutBatteryDevice.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/NightscoutBatteryDevice.java similarity index 93% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/NightscoutBatteryDevice.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/NightscoutBatteryDevice.java index 727d590be9..164b44180d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/NightscoutBatteryDevice.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/NightscoutBatteryDevice.java @@ -1,15 +1,17 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.shortTxId; + import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.BatteryManager; import android.os.Build; -import com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine; -import com.eveningoutpost.dexdrip.G5Model.Ob1DexTransmitterBattery; -import com.eveningoutpost.dexdrip.Services.DexCollectionService; +import com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine; +import com.eveningoutpost.dexdrip.g5model.Ob1DexTransmitterBattery; +import com.eveningoutpost.dexdrip.services.DexCollectionService; import org.json.JSONException; import org.json.JSONObject; @@ -143,6 +145,9 @@ boolean alwaysSendBattery() { @Override String getDeviceName() { if (Ob1G5StateMachine.usingG6()) { + if (shortTxId()) { // If using G7 + return "G7 Device"; + } return "G6 Transmitter"; } return "G5 Transmitter"; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/NightscoutTreatments.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/NightscoutTreatments.java similarity index 94% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/NightscoutTreatments.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/NightscoutTreatments.java index ed9bbc2179..643bfc08da 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/NightscoutTreatments.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/NightscoutTreatments.java @@ -1,12 +1,12 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.DateUtil; -import com.eveningoutpost.dexdrip.Models.InsulinInjection; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.DateUtil; +import com.eveningoutpost.dexdrip.models.InsulinInjection; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; import org.json.JSONArray; import org.json.JSONException; @@ -16,7 +16,7 @@ import java.util.HashSet; import java.util.UUID; -import static com.eveningoutpost.dexdrip.Models.Treatments.pushTreatmentSyncToWatch; +import static com.eveningoutpost.dexdrip.models.Treatments.pushTreatmentSyncToWatch; // jamorham @@ -55,6 +55,9 @@ public static boolean processTreatmentResponse(final String response) throws Exc } catch (JSONException e) { // } + + boolean skip_from_xdrip = Pref.getBooleanDefaultFalse("cloud_storage_api_skip_download_from_xdrip"); + // extract blood test data if present try { if (!from_xdrip) { @@ -130,7 +133,7 @@ public static boolean processTreatmentResponse(final String response) throws Exc Treatments existing = Treatments.byuuid(nightscout_id); if (existing == null) existing = Treatments.byuuid(uuid); - if ((existing == null) && (!from_xdrip)) { + if ((existing == null) && !(from_xdrip && skip_from_xdrip)) { // check for close timestamp duplicates perhaps existing = Treatments.byTimestamp(timestamp, 60000); if (!((existing != null) && (JoH.roundDouble(existing.insulin, 2) == JoH.roundDouble(insulin, 2)) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/NightscoutUploader.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/NightscoutUploader.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/NightscoutUploader.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/NightscoutUploader.java index 706869d885..21e18b8f32 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/NightscoutUploader.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/NightscoutUploader.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.content.Context; import android.content.SharedPreferences; @@ -8,19 +8,19 @@ import com.eveningoutpost.dexdrip.Home; import com.eveningoutpost.dexdrip.MegaStatus; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.DateUtil; -import com.eveningoutpost.dexdrip.Models.HeartRate; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.StepCounter; -import com.eveningoutpost.dexdrip.Models.TransmitterData; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.Models.LibreBlock; -import com.eveningoutpost.dexdrip.Services.ActivityRecognizedService; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.DateUtil; +import com.eveningoutpost.dexdrip.models.HeartRate; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.StepCounter; +import com.eveningoutpost.dexdrip.models.TransmitterData; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.models.LibreBlock; +import com.eveningoutpost.dexdrip.services.ActivityRecognizedService; import com.eveningoutpost.dexdrip.utils.CipherUtils; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.utils.Mdns; @@ -77,7 +77,7 @@ import retrofit2.http.Path; import retrofit2.http.Query; -import static com.eveningoutpost.dexdrip.UtilityModels.OkHttpWrapper.enableTls12OnPreLollipop; +import static com.eveningoutpost.dexdrip.utilitymodels.OkHttpWrapper.enableTls12OnPreLollipop; /** * THIS CLASS WAS BUILT BY THE NIGHTSCOUT GROUP FOR THEIR NIGHTSCOUT ANDROID UPLOADER @@ -99,6 +99,7 @@ public class NightscoutUploader { public static long last_success_time = -1; public static long last_exception_time = -1; public static int last_exception_count = 0; + public static int last_exception_log_count = 0; public static String last_exception; public static final String VIA_NIGHTSCOUT_TAG = "via Nightscout"; @@ -110,6 +111,11 @@ public class NightscoutUploader { private static int failurecount = 0; + public static final int FAIL_NOTIFICATION_PERIOD = 24 * 60 * 60; // Failed upload notification will be shown if there is no upload for 24 hours. + public static final int FAIl_COUNT_NOTIFICATION = FAIL_NOTIFICATION_PERIOD / 60 / 5 -1; // Number of 5-minute read cycles corresponding to notification period + public static final int FAIL_LOG_PERIOD = 6 * 60 * 60; // FAILED upload/download log will be shown if there is no upload/download for 6 hours. + public static final int FAIL_COUNT_LOG = FAIL_LOG_PERIOD / 60 / 5 -1; // Number of 5-minute read cycles corresponding to log period + private Context mContext; private Boolean enableRESTUpload; private Boolean enableMongoUpload; @@ -494,6 +500,7 @@ private boolean doRESTUpload(SharedPreferences prefs, List glucoseDat any_successes = true; last_success_time = JoH.tsl(); last_exception_count = 0; + last_exception_log_count = 0; } catch (Exception e) { String msg = "Unable to do REST API Upload: " + e.getMessage() + " marking record: " + (any_successes ? "succeeded" : "failed"); handleRestFailure(msg); @@ -574,31 +581,38 @@ private void doRESTUploadTo(NightscoutService nightscoutService, String secret, } } } + } private static synchronized void handleRestFailure(String msg) { last_exception = msg; last_exception_time = JoH.tsl(); last_exception_count++; - if (last_exception_count > 5) { - if (Pref.getBooleanDefaultFalse("warn_nightscout_failures")) { - if (JoH.ratelimit("nightscout-error-notification", 1800)) { - notification_shown = true; - JoH.showNotification("Nightscout Failure", "REST-API upload to Nightscout has failed " + last_exception_count - + " times. With message: " + last_exception + " " + ((last_success_time > 0) ? "Last succeeded: " + JoH.dateTimeText(last_success_time) : ""), - - MegaStatus.getStatusPendingIntent("Uploaders"), Constants.NIGHTSCOUT_ERROR_NOTIFICATION_ID, NotificationChannels.NIGHTSCOUT_UPLOADER_CHANNEL, true, true, null, null, msg); + last_exception_log_count++; + if (last_exception_log_count > FAIL_COUNT_LOG) { // If the number of failed uploads/downloads crosses the logging target + if (JoH.pratelimit("nightscout-error-log", FAIL_LOG_PERIOD)) { // If there has been more than 6 hours since the last log + Log.e(TAG, msg); + last_exception_log_count = 0; // Reset the fail count for logging. + } + if (last_exception_count > FAIl_COUNT_NOTIFICATION) { // If the number of failed uploads crosses the notification target + if (JoH.pratelimit("nightscout-error-notification", FAIL_NOTIFICATION_PERIOD)) { // If there has been more than 24 hours since the last notification + if (Pref.getBooleanDefaultFalse("warn_nightscout_failures")) { + notification_shown = true; + JoH.showNotification("Nightscout Failure", "REST-API upload to Nightscout has failed " + last_exception_count + + " times. With message: " + last_exception + " " + ((last_success_time > 0) ? "Last succeeded: " + JoH.dateTimeText(last_success_time) : ""), + + MegaStatus.getStatusPendingIntent("Uploaders"), Constants.NIGHTSCOUT_ERROR_NOTIFICATION_ID, NotificationChannels.NIGHTSCOUT_UPLOADER_CHANNEL, false, false, null, null, msg); + } else { + Log.e(TAG, "Cannot alert for nightscout failures as preference setting is disabled"); + } } } else { - Log.e(TAG, "Cannot alert for nightscout failures as preference setting is disabled"); - } - } else { - if (notification_shown) { - JoH.cancelNotification(Constants.NIGHTSCOUT_ERROR_NOTIFICATION_ID); - notification_shown = false; + if (notification_shown) { + JoH.cancelNotification(Constants.NIGHTSCOUT_ERROR_NOTIFICATION_ID); + notification_shown = false; + } } } - Log.e(TAG, msg); } private String getDeviceString(BgReading record) { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/NotificationChannels.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/NotificationChannels.java similarity index 85% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/NotificationChannels.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/NotificationChannels.java index 489e50f517..89dbec2be5 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/NotificationChannels.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/NotificationChannels.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.annotation.TargetApi; import android.app.Notification; @@ -7,15 +7,22 @@ import android.app.NotificationManager; import android.content.Context; import android.media.AudioAttributes; -import android.support.v4.app.NotificationCompat; + + +import androidx.core.app.NotificationCompat; import com.eveningoutpost.dexdrip.R; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.xdrip; +import java.lang.reflect.Field; import java.util.Arrays; import java.util.HashMap; import java.util.List; +import lombok.val; + /** * Created by jwoglom on 10/15/2017. *

@@ -99,9 +106,9 @@ private static int myhashcode(NotificationChannel x) { @TargetApi(26) private static String my_text_hash(NotificationChannel x) { String res = ""; - if (x.getSound() != null) res += "\uD83C\uDFB5"; // 🎵 - if (x.shouldVibrate()) res += "\uD83D\uDCF3"; // 📳 - if (x.shouldShowLights()) res += "\uD83D\uDCA1"; // 💡 + if (x.getSound() != null) res += "\uD83C\uDFB5"; // � + if (x.shouldVibrate()) res += "\uD83D\uDCF3"; // � + if (x.shouldShowLights()) res += "\uD83D\uDCA1"; // � res = (res.equals("")) ? res : " " + res; int counter = 1; @@ -176,11 +183,16 @@ public static NotificationChannel getChan(NotificationCompat.Builder wip) { // mirror the notification parameters in the channel template.setGroup(temp.getChannelId()); - template.setVibrationPattern(wip.mNotification.vibrate); - template.setSound(wip.mNotification.sound, generic_audio); - template.setLightColor(wip.mNotification.ledARGB); - if ((wip.mNotification.ledOnMS != 0) && (wip.mNotification.ledOffMS != 0)) - template.enableLights(true); // weird how this doesn't work like vibration pattern + + val mNotification = getNotificationFromInsideBuilder(wip); + if (mNotification != null) { + template.setVibrationPattern(mNotification.vibrate); + template.setSound(mNotification.sound, generic_audio); + template.setLightColor(mNotification.ledARGB); + if (mNotification.ledOnMS != 0 && mNotification.ledOffMS != 0) + template.enableLights(true); // weird how this doesn't work like vibration pattern + } + template.setDescription(temp.getChannelId() + " " + wip.hashCode()); // get a nice string to identify the hash @@ -201,16 +213,20 @@ public static NotificationChannel getChan(NotificationCompat.Builder wip) { } channel.setDescription(template.getDescription()); channel.setVibrationPattern(template.getVibrationPattern()); - template.setLightColor(wip.mNotification.ledARGB); - if ((wip.mNotification.ledOnMS != 0) && (wip.mNotification.ledOffMS != 0)) - template.enableLights(true); // weird how this doesn't work like vibration pattern + + if (mNotification != null) { + template.setLightColor(mNotification.ledARGB); + if ((mNotification.ledOnMS != 0) && (mNotification.ledOffMS != 0)) + template.enableLights(true); // weird how this doesn't work like vibration pattern + } + template.setDescription(temp.getChannelId() + " " + wip.hashCode()); // create a group to hold this channel if one doesn't exist or update text getNotifManager().createNotificationChannelGroup(new NotificationChannelGroup(channel.getGroup(), getString(channel.getGroup()))); // create this channel if it doesn't exist or update text getNotifManager().createNotificationChannel(channel); - return channel; + return mNotification != null ? channel : null; // Note we return null to fallback old behavior if we can't get reflected access } @TargetApi(26) @@ -268,7 +284,21 @@ public static NotificationChannel getChan(Notification.Builder wip) { getNotifManager().createNotificationChannelGroup(new NotificationChannelGroup(channel.getGroup(), getString(channel.getGroup()))); // create this channel if it doesn't exist or update text getNotifManager().createNotificationChannel(channel); - return channel; + return channel; + } + + static Notification getNotificationFromInsideBuilder(final NotificationCompat.Builder builder) { + try { + final Class builderClass = builder.getClass(); + final Field mNotificationField = builderClass.getDeclaredField("mNotification"); + mNotificationField.setAccessible(true); + return (Notification) mNotificationField.get(builder); + } catch (NoSuchFieldException | IllegalAccessException e) { + if (JoH.ratelimit("notification-workaround", 1800)) { + UserError.Log.wtf(TAG, "Workaround being used for notification channels no longer works - please report"); + } + return null; + } } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Notifications.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Notifications.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Notifications.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Notifications.java index 0d65e4274a..12500de838 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Notifications.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Notifications.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.app.IntentService; import android.app.Notification; @@ -20,8 +20,8 @@ import android.os.PowerManager; import android.os.SystemClock; import android.preference.PreferenceManager; -import android.support.v4.app.NotificationCompat; -import android.support.v4.app.NotificationManagerCompat; +import androidx.core.app.NotificationCompat; +import androidx.core.app.NotificationManagerCompat; import android.text.SpannableString; import android.widget.RemoteViews; @@ -30,32 +30,32 @@ import com.eveningoutpost.dexdrip.DoubleCalibrationActivity; import com.eveningoutpost.dexdrip.EditAlertActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.ActiveBgAlert; -import com.eveningoutpost.dexdrip.Models.AlertType; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.CalibrationRequest; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.Models.UserNotification; +import com.eveningoutpost.dexdrip.models.ActiveBgAlert; +import com.eveningoutpost.dexdrip.models.AlertType; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.CalibrationRequest; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserNotification; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.ActivityRecognizedService; -import com.eveningoutpost.dexdrip.Services.MissedReadingService; -import com.eveningoutpost.dexdrip.Services.SnoozeOnNotificationDismissService; +import com.eveningoutpost.dexdrip.services.ActivityRecognizedService; +import com.eveningoutpost.dexdrip.services.MissedReadingService; +import com.eveningoutpost.dexdrip.services.SnoozeOnNotificationDismissService; import com.eveningoutpost.dexdrip.evaluators.PersistentHigh; import com.eveningoutpost.dexdrip.ui.NumberGraphic; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.utils.PowerStateReceiver; import com.eveningoutpost.dexdrip.wearintegration.Amazfitservice; -import com.eveningoutpost.dexdrip.Services.broadcastservice.BroadcastEntry; +import com.eveningoutpost.dexdrip.services.broadcastservice.BroadcastEntry; import com.eveningoutpost.dexdrip.xdrip; import java.util.Date; import java.util.List; -import static com.eveningoutpost.dexdrip.UtilityModels.ColorCache.X; -import static com.eveningoutpost.dexdrip.UtilityModels.ColorCache.getCol; +import static com.eveningoutpost.dexdrip.utilitymodels.ColorCache.X; +import static com.eveningoutpost.dexdrip.utilitymodels.ColorCache.getCol; /** * Created by Emma Black on 11/28/14. @@ -910,10 +910,10 @@ public static void ob1SessionRestartRequested() { } public static void RisingAlert(Context context, boolean on) { - RiseDropAlert(context, on, "bg_rise_alert", "bg rising fast" + " (@" + JoH.hourMinuteString() + ")", riseAlertNotificationId); + RiseDropAlert(context, on, "bg_rise_alert", context.getString(R.string.bg_rising_fast) + " (@" + JoH.hourMinuteString() + ")", riseAlertNotificationId); } public static void DropAlert(Context context, boolean on) { - RiseDropAlert(context, on, "bg_fall_alert", "bg falling fast" + " (@" + JoH.hourMinuteString() + ")", failAlertNotificationId); + RiseDropAlert(context, on, "bg_fall_alert", context.getString(R.string.bg_falling_fast) + " (@" + JoH.hourMinuteString() + ")", failAlertNotificationId); } public static void lowPredictAlert(Context context, boolean on, String msg) { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/OkHttpWrapper.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/OkHttpWrapper.java similarity index 92% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/OkHttpWrapper.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/OkHttpWrapper.java index b087a91c6b..74946544bd 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/OkHttpWrapper.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/OkHttpWrapper.java @@ -1,9 +1,9 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.annotation.SuppressLint; import android.os.Build; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import java.util.ArrayList; import java.util.List; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PersistentStore.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PersistentStore.java similarity index 76% rename from wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PersistentStore.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PersistentStore.java index 93dfc15cb1..78ec533ef4 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PersistentStore.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PersistentStore.java @@ -1,13 +1,19 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.xdrip; import com.google.common.primitives.Bytes; +import java.util.LinkedList; +import java.util.Map; +import java.util.Set; + +import lombok.val; + /** * Created by jamorham on 23/09/2016. *

@@ -32,6 +38,26 @@ public class PersistentStore { public static String getString(final String name) { return prefs.getString(name, ""); } + + public static String getString(final String name, String defaultValue) { + return prefs.getString(name, defaultValue); + } + + public static int getStringToInt(final String name, final int defaultValue) { + try { + return Integer.parseInt(getString(name, Integer.toString(defaultValue))); + } catch (Exception e) { + return defaultValue; + } + } + + public static boolean removeItem(final String pref) { + if (prefs != null) { + prefs.edit().remove(pref).apply(); + return true; + } + return false; + } static { try { @@ -134,4 +160,20 @@ public static void setLongZeroIfSet(String name) { public static void commit() { prefs.edit().commit(); } + + public static void cleanupOld(final String prefix) { + if (prefix == null) return; + val erase = new LinkedList(); + Set> set = prefs.getAll().entrySet(); + for (Map.Entry i : set) { + if (i.getKey().startsWith(prefix)) { + erase.add(i.getKey()); + } + } + for (val i : erase) { + System.out.println("Erasing: " + i); + removeItem(i); + } + } + } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PlusAsyncExecutor.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PlusAsyncExecutor.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PlusAsyncExecutor.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PlusAsyncExecutor.java index 6a8afdab56..edc87eb5f0 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PlusAsyncExecutor.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PlusAsyncExecutor.java @@ -1,11 +1,11 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.os.PowerManager; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; import java.util.ArrayDeque; import java.util.HashMap; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PointValueExtended.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PointValueExtended.java similarity index 89% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PointValueExtended.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PointValueExtended.java index a0bccdd637..8a6d9720a3 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PointValueExtended.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PointValueExtended.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; /** * Created by Emma Black on 11/15/14. @@ -18,7 +18,7 @@ public PointValueExtended(double x, float y, float filtered) { super(x, y); calculatedFilteredValue = filtered; } - public PointValueExtended(double x, float y) { + public PointValueExtended(double x, double y) { super(x, y); calculatedFilteredValue = -1; } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Pref.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Pref.java similarity index 90% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Pref.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Pref.java index bf5e4004a0..d7aa093014 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Pref.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Pref.java @@ -1,10 +1,10 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.content.SharedPreferences; import android.preference.PreferenceManager; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.xdrip; /** @@ -30,7 +30,11 @@ private static void initializePrefs() { } } else { if (JoH.ratelimit("prefs-failure2", 20)) { - UserError.Log.wtf(TAG, "Could not initialize preferences due to missing context!!"); + try { + UserError.Log.wtf(TAG, "Could not initialize preferences due to missing context!!"); + } catch (NullPointerException e) { + android.util.Log.wtf(TAG, "Could not initialize preferences due to missing context and then got null pointer!!"); + } } } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PrefsView.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PrefsView.java similarity index 83% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PrefsView.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PrefsView.java index 792feca8db..c316309fa1 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PrefsView.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PrefsView.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; /** * Created by jamorham on 04/10/2017. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PrefsViewImpl.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PrefsViewImpl.java new file mode 100644 index 0000000000..edc030ebc8 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PrefsViewImpl.java @@ -0,0 +1,103 @@ +package com.eveningoutpost.dexdrip.utilitymodels; + +import androidx.annotation.NonNull; + +import com.eveningoutpost.dexdrip.adapters.ObservableArrayMapNoNotify; + +import lombok.val; + +/** + * Created by jamorham on 05/10/2017. + *

+ * Implementation of PrefsView + */ + +public class PrefsViewImpl extends ObservableArrayMapNoNotify implements PrefsView { + + private Runnable runnable; + + public boolean getbool(String name) { + if (name == null) return false; + return PrefHandle.parse(name).getBoolean(); + } + + public void setbool(String name, boolean value) { + val handle = PrefHandle.parse(name); + Pref.setBoolean(handle.key, value); + super.put(handle.key, value); + doRunnable(); + } + + public void togglebool(String name) { + setbool(name, !getbool(name)); + } + + public PrefsViewImpl setRefresh(final Runnable runnable) { + this.runnable = runnable; + return this; + } + + private void doRunnable() { + if (runnable != null) { + runnable.run(); + } + } + + @NonNull + @Override + public Boolean get(Object key) { + val handle = PrefHandle.parse((String) key); + Boolean value = super.get(handle.key); + if (value == null) { + value = getbool((String) key); + super.putNoNotify(handle.key, value); + } + return value; + } + + @Override + public Boolean put(String key, Boolean value) { + val handle = PrefHandle.parse(key); + if (!(super.get(handle.key).equals(value))) { + Pref.setBoolean(handle.key, value); + super.put(handle.key, value); + doRunnable(); + } + return value; + } + + public void put(Object key, boolean value) { + val handle = PrefHandle.parse((String) key); + if (!(super.get(handle.key).equals(value))) { + super.put(handle.key, value); + } + } + + public static class PrefHandle { + public final String key; + public final boolean defaultValue; + + public PrefHandle(final String key, final boolean defaultValue) { + this.key = key; + this.defaultValue = defaultValue; + } + + boolean getBoolean() { + return Pref.getBoolean(key, defaultValue); + } + + public static PrefHandle parse(final String identifier) { + if (identifier == null) { + return null; + } + + final String[] parts = identifier.split(":", 2); + if (parts.length == 2) { + return new PrefHandle(parts[0], Boolean.parseBoolean(parts[1])); + } else { + return new PrefHandle(identifier, false); + } + } + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PrefsViewString.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PrefsViewString.java similarity index 90% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PrefsViewString.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PrefsViewString.java index 7bb037aa15..e1934d56cb 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PrefsViewString.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PrefsViewString.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.eveningoutpost.dexdrip.adapters.ObservableArrayMapNoNotify; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PumpStatus.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PumpStatus.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PumpStatus.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PumpStatus.java index fc6ed41671..2d0420d8da 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PumpStatus.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/PumpStatus.java @@ -1,11 +1,11 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.util.Log; import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import org.json.JSONException; import org.json.JSONObject; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/RedBearLabAttributes.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/RedBearLabAttributes.java similarity index 89% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/RedBearLabAttributes.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/RedBearLabAttributes.java index f84acd60cb..b04b455a9b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/RedBearLabAttributes.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/RedBearLabAttributes.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import java.util.UUID; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/RxBleProvider.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/RxBleProvider.java similarity index 90% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/RxBleProvider.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/RxBleProvider.java index fcdb6bdafc..d2f5a784d6 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/RxBleProvider.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/RxBleProvider.java @@ -1,10 +1,10 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; // jamorham // TODO check this reference handling -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.xdrip; import com.polidea.rxandroidble2.RxBleClient; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SendFeedBack.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SendFeedBack.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SendFeedBack.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SendFeedBack.java index f0b356f056..7f05385904 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SendFeedBack.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SendFeedBack.java @@ -1,10 +1,9 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; -import android.support.v7.app.AlertDialog; -import android.support.v7.app.AppCompatActivity; + import android.text.InputType; import android.util.Log; import android.view.View; @@ -15,8 +14,9 @@ import android.widget.Toast; import com.eveningoutpost.dexdrip.BaseAppCompatActivity; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; +import com.eveningoutpost.dexdrip.watch.thinjam.BlueJayEntry; import com.squareup.okhttp.FormEncodingBuilder; import com.squareup.okhttp.Interceptor; import com.squareup.okhttp.MediaType; @@ -34,6 +34,9 @@ import okio.Okio; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.getBestCollectorHardwareName; +import static com.eveningoutpost.dexdrip.watch.thinjam.BlueJayEntry.isNative; + +import androidx.appcompat.app.AlertDialog; public class SendFeedBack extends BaseAppCompatActivity { @@ -53,7 +56,7 @@ public class SendFeedBack extends BaseAppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_send_feed_back); - send_url = getString(R.string.wserviceurl) + "/joh-feedback"; + send_url = getString(isNative() ? R.string.qserviceurl : R.string.wserviceurl) + "/joh-feedback"; myrating = (RatingBar) findViewById(R.id.ratingBar); ratingtext = (TextView) findViewById(R.id.ratingtext); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SendXdripBroadcast.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SendXdripBroadcast.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SendXdripBroadcast.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SendXdripBroadcast.java index 88d5a4298b..6ec92cc91b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SendXdripBroadcast.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SendXdripBroadcast.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.content.Intent; import android.os.Bundle; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SensorSendQueue.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SensorSendQueue.java similarity index 86% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SensorSendQueue.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SensorSendQueue.java index 69a845e698..4beba494a1 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SensorSendQueue.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SensorSendQueue.java @@ -1,8 +1,5 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; -import android.content.Context; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; import android.provider.BaseColumns; import com.activeandroid.Model; @@ -11,8 +8,7 @@ import com.activeandroid.query.Select; import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.xdrip; -import com.eveningoutpost.dexdrip.Models.Sensor; +import com.eveningoutpost.dexdrip.models.Sensor; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SensorStatus.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SensorStatus.java similarity index 85% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SensorStatus.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SensorStatus.java index f84eb6d8b2..f3c3c41b87 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SensorStatus.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SensorStatus.java @@ -1,12 +1,12 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; -import com.eveningoutpost.dexdrip.Models.Sensor; +import com.eveningoutpost.dexdrip.models.Sensor; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; -import static com.eveningoutpost.dexdrip.Models.JoH.tsl; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SettingsValidation.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SettingsValidation.java similarity index 57% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SettingsValidation.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SettingsValidation.java index db0a719d5e..7f3db38d26 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SettingsValidation.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SettingsValidation.java @@ -1,12 +1,12 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.xdrip; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.SETTINGS_INADVISABLE_BASE_ID; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.SETTINGS_INADVISABLE_BASE_ID; -// navid200 +// Navid200 public class SettingsValidation { private static final String NOTIFY_MARKER = "-NOTIFY"; @@ -18,15 +18,16 @@ public static void notifyAboutInadvisableSettings() { setting_name = "engineering_mode"; if (Pref.getBooleanDefaultFalse("engineering_mode")) { if (JoH.pratelimit(setting_name + NOTIFY_MARKER, RENOTIFY_TIME)) { - id = notify("Engineering Mode", setting_name, "" + xdrip.getAppContext().getString(R.string.eng_mode_is_on), id); + id = notifyDis("Engineering Mode", setting_name, "" + xdrip.getAppContext().getString(R.string.eng_mode_is_on), id); } } // Todo Add the following items as well + // A different method than notifyDis should be created (perhaps notifyEn) for settings that are disabled and are advised to be enabled e.g. OB1. // OB1 is disabled - // Samsung workaround is disabled + // Wake workaround is disabled // Bluetooth watchdog is disabled @@ -41,9 +42,9 @@ public static void notifyAboutInadvisableSettings() { // Aggressive service restarts is disabled } - private static int notify(String short_name, String setting_string, String msg, int id) { + private static int notifyDis(String short_name, String setting_string, String msg, int id) { - JoH.showNotification("Inadvisable settings - " + short_name, "Please enable or disable " + setting_string, null, id, true, true, null, null, ((msg.length() > 0) ? msg : "")); + JoH.showNotification("Inadvisable setting ", "Please disable " + short_name, null, id, false, false, null, null, ((msg.length() > 0) ? msg : "")); return id + 1; } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/ShotStateStore.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/ShotStateStore.java similarity index 94% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/ShotStateStore.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/ShotStateStore.java index c8fcd2d5fb..95ffbb2e2a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/ShotStateStore.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/ShotStateStore.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; /** * Created by jamorham on 20/06/2016. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SimpleImageEncoder.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SimpleImageEncoder.java similarity index 99% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SimpleImageEncoder.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SimpleImageEncoder.java index e6e7dd0f65..1d3f159ca8 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SimpleImageEncoder.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SimpleImageEncoder.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.graphics.Bitmap; import android.graphics.Color; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SourceWizard.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SourceWizard.java similarity index 93% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SourceWizard.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SourceWizard.java index aa5f8d07b5..96f13f5e15 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SourceWizard.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SourceWizard.java @@ -1,16 +1,16 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; -import android.databinding.ObservableArrayList; -import android.databinding.ObservableList; -import android.support.annotation.StringRes; +import androidx.databinding.ObservableArrayList; +import androidx.databinding.ObservableList; +import androidx.annotation.StringRes; import android.view.View; import com.eveningoutpost.dexdrip.BR; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.databinding.DialogTreeSelectorBinding; import com.eveningoutpost.dexdrip.utils.DexCollectionHelper; @@ -41,7 +41,7 @@ public class SourceWizard { private Tree root = new Tree<>(new Item(gs(R.string.choose_data_source), gs(R.string.which_system_do_you_use))); { - Tree g5g6 = root.addChild(new Item("G4, G5 & G6", gs(R.string.which_type_of_device), R.drawable.g5_icon)); + Tree g5g6 = root.addChild(new Item("G4, G5, G6, G7, 1", gs(R.string.which_type_of_device), R.drawable.g5_icon)); { Tree g4 = g5g6.addChild(new Item("G4", gs(R.string.what_type_of_g4_bridge_device_do_you_use), R.drawable.g4_icon)); { @@ -55,7 +55,7 @@ public class SourceWizard { g4.addChild(new Item(gs(R.string.parakeet_wifi), DexCollectionType.WifiWixel, R.drawable.jamorham_parakeet_marker)); } g5g6.addChild(new Item("G5", DexCollectionType.DexcomG5, R.drawable.g5_icon)); - g5g6.addChild(new Item("G6", DexCollectionType.DexcomG6, R.drawable.g6_icon)); + g5g6.addChild(new Item("G6, G7, 1", DexCollectionType.DexcomG6, R.drawable.g6_icon)); } Tree libre = root.addChild(new Item(gs(R.string.libre), gs(R.string.what_type_of_libre_bridge_device_do_you_use), R.drawable.libre_icon_image)); @@ -68,6 +68,7 @@ public class SourceWizard { Tree other = root.addChild(new Item(gs(R.string.other), gs(R.string.which_type_of_device), R.drawable.wikimedia_question_mark)); { other.addChild(new Item("640G / 670G", DexCollectionType.NSEmulator, R.drawable.mm600_series)); + other.addChild(new Item("CareSens Air", DexCollectionType.NSEmulator, R.drawable.caresens_air_icon_image)); other.addChild(new Item("Medtrum A6 / S7", DexCollectionType.Medtrum, R.drawable.a6_icon)); other.addChild(new Item("Nightscout Follower", DexCollectionType.NSFollow, R.drawable.nsfollow_icon)); other.addChild(new Item("Dex Share Follower", DexCollectionType.SHFollow, R.drawable.nsfollow_icon)); @@ -86,7 +87,7 @@ public static void start(Activity activity) { } public synchronized static void start(Activity activity, boolean force) { - if (sw == null) sw = new SourceWizard(activity); + if (sw == null || sw.activity != activity) sw = new SourceWizard(activity); if (force) { if (sw.showing()) sw.dismiss(); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SpeechUtil.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SpeechUtil.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SpeechUtil.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SpeechUtil.java index 908ae767da..6602874ba9 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/SpeechUtil.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/SpeechUtil.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.content.ActivityNotFoundException; import android.content.Context; @@ -7,8 +7,8 @@ import android.os.PowerManager; import android.speech.tts.TextToSpeech; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.xdrip; import java.util.Locale; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/StandardShowcaseDrawer.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/StandardShowcaseDrawer.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/StandardShowcaseDrawer.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/StandardShowcaseDrawer.java index 467c0231c6..3bf6d00d3d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/StandardShowcaseDrawer.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/StandardShowcaseDrawer.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.content.res.Resources; import android.graphics.Bitmap; @@ -7,7 +7,7 @@ import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.drawable.Drawable; -import android.support.v4.content.res.ResourcesCompat; +import androidx.core.content.res.ResourcesCompat; import com.github.amlcurran.showcaseview.ShowcaseDrawer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/StatusItem.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/StatusItem.java similarity index 76% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/StatusItem.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/StatusItem.java index de73d6e8e3..f4ed5d3633 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/StatusItem.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/StatusItem.java @@ -1,17 +1,9 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.graphics.Color; -import android.support.annotation.ColorInt; +import androidx.annotation.ColorInt; -import com.google.common.base.MoreObjects; - -import java.util.HashMap; - -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.BAD; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.CRITICAL; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.GOOD; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.NORMAL; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.NOTICE; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.NORMAL; /** * Created by jamorham on 14/01/2017. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/StatusLine.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/StatusLine.java similarity index 94% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/StatusLine.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/StatusLine.java index f66ba27408..8cf46fae05 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/StatusLine.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/StatusLine.java @@ -1,13 +1,13 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; -import com.eveningoutpost.dexdrip.Models.Accuracy; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.Accuracy; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.calibrations.CalibrationAbstract; import com.eveningoutpost.dexdrip.calibrations.PluggableCalibration; import com.eveningoutpost.dexdrip.stats.StatsResult; @@ -16,7 +16,7 @@ import java.text.SimpleDateFormat; import java.util.Date; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.DAY_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.DAY_IN_MS; import static com.eveningoutpost.dexdrip.calibrations.PluggableCalibration.getCalibrationPlugin; import static com.eveningoutpost.dexdrip.calibrations.PluggableCalibration.getCalibrationPluginFromPreferences; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Tls12SocketFactory.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Tls12SocketFactory.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Tls12SocketFactory.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Tls12SocketFactory.java index 683540293b..23e8edbc8e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Tls12SocketFactory.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Tls12SocketFactory.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import java.io.IOException; import java.net.InetAddress; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Tree.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Tree.java similarity index 94% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Tree.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Tree.java index c5f53c94b3..70344f4dbb 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Tree.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Tree.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import java.util.LinkedList; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/UndoRedo.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/UndoRedo.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/UndoRedo.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/UndoRedo.java index 6145305c21..06bab9987d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/UndoRedo.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/UndoRedo.java @@ -1,9 +1,9 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Unitized.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Unitized.java similarity index 98% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Unitized.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Unitized.java index b59c183e81..95c6fe13ca 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/Unitized.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Unitized.java @@ -1,8 +1,8 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; // jamorham -import com.eveningoutpost.dexdrip.Models.BgReading; +import com.eveningoutpost.dexdrip.models.BgReading; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/UpdateActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/UpdateActivity.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/UpdateActivity.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/UpdateActivity.java index 0608ac7c18..16e47132d1 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/UpdateActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/UpdateActivity.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; // jamorham @@ -14,11 +14,10 @@ import android.os.Bundle; import android.os.Environment; import android.preference.PreferenceManager; -import android.support.annotation.NonNull; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; -import android.support.v4.content.FileProvider; -import android.support.v7.app.AppCompatActivity; +import androidx.annotation.NonNull; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import androidx.core.content.FileProvider; import android.util.Log; import android.view.View; import android.widget.CheckBox; @@ -30,8 +29,8 @@ import com.eveningoutpost.dexdrip.BaseAppCompatActivity; import com.eveningoutpost.dexdrip.BuildConfig; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.xdrip; @@ -53,7 +52,7 @@ import okhttp3.Request; import okhttp3.Response; -import static com.eveningoutpost.dexdrip.UtilityModels.OkHttpWrapper.enableTls12OnPreLollipop; +import static com.eveningoutpost.dexdrip.utilitymodels.OkHttpWrapper.enableTls12OnPreLollipop; public class UpdateActivity extends BaseAppCompatActivity { @@ -81,6 +80,10 @@ public class UpdateActivity extends BaseAppCompatActivity { private static String CHECKSUM = ""; public static void checkForAnUpdate(final Context context) { + checkForAnUpdate(context, false); + } + + public static void checkForAnUpdate(final Context context, final boolean fromUi) { if (prefs == null) prefs = PreferenceManager.getDefaultSharedPreferences(context); if ((last_check_time != -1) && (!prefs.getBoolean(AUTO_UPDATE_PREFS_NAME, true))) return; if (last_check_time == 0) @@ -170,6 +173,9 @@ public static void checkForAnUpdate(final Context context) { } } else { Log.i(TAG, "Our current version is the most recent: " + versionnumber + " vs " + newversion); + if (fromUi) { // Only for manual update check + JoH.static_toast_long(xdrip.gs(R.string.current_version_is_up_to_date)); + } } } catch (Exception e) { Log.e(TAG, "Got exception parsing update version: " + e.toString()); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/UploaderQueue.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/UploaderQueue.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/UploaderQueue.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/UploaderQueue.java index f311c02844..72bc3c9107 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/UploaderQueue.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/UploaderQueue.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.database.Cursor; import android.provider.BaseColumns; @@ -12,15 +12,14 @@ import com.activeandroid.query.Delete; import com.activeandroid.query.Select; import com.activeandroid.util.SQLiteUtils; -import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.LibreBlock; -import com.eveningoutpost.dexdrip.Models.TransmitterData; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.LibreBlock; +import com.eveningoutpost.dexdrip.models.TransmitterData; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.tidepool.TidepoolEntry; import com.eveningoutpost.dexdrip.tidepool.TidepoolStatus; import com.eveningoutpost.dexdrip.tidepool.TidepoolUploader; @@ -35,7 +34,7 @@ import java.util.ArrayList; import java.util.List; -import static com.eveningoutpost.dexdrip.Services.SyncService.startSyncService; +import static com.eveningoutpost.dexdrip.services.SyncService.startSyncService; /** * Created by jamorham on 15/11/2016. @@ -531,8 +530,8 @@ public void run() { /// - if (NightscoutUploader.last_exception_time > 0) { - l.add(new StatusItem("REST-API problem\n" + JoH.dateTimeText(NightscoutUploader.last_exception_time) + " (" + NightscoutUploader.last_exception_count + ")", NightscoutUploader.last_exception, JoH.msSince(NightscoutUploader.last_exception_time) < (Constants.MINUTE_IN_MS * 6) ? StatusItem.Highlight.BAD : StatusItem.Highlight.NORMAL)); + if (NightscoutUploader.last_exception_count > 0) { + l.add(new StatusItem("REST-API problem\n" + JoH.dateTimeText(NightscoutUploader.last_exception_time) + " (" + NightscoutUploader.last_exception_count + ")", NightscoutUploader.last_exception, StatusItem.Highlight.BAD)); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/UploaderTask.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/UploaderTask.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/UploaderTask.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/UploaderTask.java index e8600e63dd..c54c059094 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/UploaderTask.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/UploaderTask.java @@ -1,17 +1,17 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.os.AsyncTask; -import com.eveningoutpost.dexdrip.InfluxDB.InfluxDBUploader; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.LibreBlock; -import com.eveningoutpost.dexdrip.Models.TransmitterData; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.Services.SyncService; +import com.eveningoutpost.dexdrip.influxdb.InfluxDBUploader; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.LibreBlock; +import com.eveningoutpost.dexdrip.models.TransmitterData; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.services.SyncService; import com.eveningoutpost.dexdrip.wearintegration.WatchUpdaterService; import com.eveningoutpost.dexdrip.xdrip; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/VehicleMode.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/VehicleMode.java similarity index 86% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/VehicleMode.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/VehicleMode.java index d388bd03b3..03624dfe79 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/VehicleMode.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/VehicleMode.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; /** * jamorham @@ -11,10 +11,10 @@ import android.content.Intent; import android.os.Bundle; -import com.eveningoutpost.dexdrip.Services.ActivityRecognizedService; +import com.eveningoutpost.dexdrip.services.ActivityRecognizedService; -import static com.eveningoutpost.dexdrip.UtilityModels.Intents.ACTION_VEHICLE_MODE; -import static com.eveningoutpost.dexdrip.UtilityModels.Intents.EXTRA_VEHICLE_MODE_ENABLED; +import static com.eveningoutpost.dexdrip.utilitymodels.Intents.ACTION_VEHICLE_MODE; +import static com.eveningoutpost.dexdrip.utilitymodels.Intents.EXTRA_VEHICLE_MODE_ENABLED; public class VehicleMode { diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/VersionTracker.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/VersionTracker.java similarity index 93% rename from wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/VersionTracker.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/VersionTracker.java index bfe03b0e8f..5174abcfc2 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/VersionTracker.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/VersionTracker.java @@ -1,11 +1,11 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import com.eveningoutpost.dexdrip.BuildConfig; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.xdrip; -import static com.eveningoutpost.dexdrip.Models.JoH.dateTimeText; +import static com.eveningoutpost.dexdrip.models.JoH.dateTimeText; /** * jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/VoiceCommands.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/VoiceCommands.java similarity index 80% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/VoiceCommands.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/VoiceCommands.java index 259d5d4515..977a82fe78 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/VoiceCommands.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/VoiceCommands.java @@ -1,25 +1,26 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; // jamorham import android.app.Activity; -import com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine; +import com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine; import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.DesertSync; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Services.ActivityRecognizedService; -import com.eveningoutpost.dexdrip.Services.G5BaseService; -import com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService; -import com.eveningoutpost.dexdrip.Services.UiBasedCollector; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.DesertSync; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.services.ActivityRecognizedService; +import com.eveningoutpost.dexdrip.services.G5BaseService; +import com.eveningoutpost.dexdrip.services.Ob1G5CollectionService; +import com.eveningoutpost.dexdrip.services.UiBasedCollector; import com.eveningoutpost.dexdrip.cgm.medtrum.MedtrumCollectionService; import com.eveningoutpost.dexdrip.cloud.backup.BackupActivity; import com.eveningoutpost.dexdrip.insulin.opennov.data.SaveCompleted; +import com.eveningoutpost.dexdrip.plugin.Registry; import com.eveningoutpost.dexdrip.profileeditor.BasalProfileEditor; import com.eveningoutpost.dexdrip.ui.activities.DatabaseAdmin; import com.eveningoutpost.dexdrip.ui.dialog.G6CalibrationCodeDialog; @@ -44,12 +45,26 @@ public static void processVoiceCommand(final String allWords, final Activity mAc } else if (get_engineering_mode() && allWords.contentEquals("enable fake data source")) { Pref.setString(DexCollectionType.DEX_COLLECTION_METHOD, DexCollectionType.Mock.toString()); JoH.static_toast_long("YOU ARE NOW USING FAKE DATA!!!"); + MockDataSource.defaults(); + CollectionServiceStarter.restartCollectionServiceBackground(); + } else if (get_engineering_mode() && allWords.equals("fake data source automatic calibration")) { + Pref.setBoolean("fake_data_pre_calibrated", true); + JoH.static_toast_long("Fake data pre-calibration ON"); + } else if (get_engineering_mode() && allWords.equals("fake data source manual calibration")) { + Pref.setBoolean("fake_data_pre_calibrated", false); + JoH.static_toast_long("Fake data pre-calibration OFF"); } else if (get_engineering_mode() && allWords.equals("break fake data source")) { JoH.static_toast_long("Breaking fake data source"); MockDataSource.breakRaw(); } else if (get_engineering_mode() && allWords.equals("repair fake data source")) { JoH.static_toast_long("Repairing fake data source"); MockDataSource.fixRaw(); + } else if (get_engineering_mode() && allWords.equals("speed up fake data source")) { + JoH.static_toast_long("Speeding up fake data source"); + MockDataSource.speedup(); + } else if (get_engineering_mode() && allWords.equals("amplify fake data source")) { + JoH.static_toast_long("Amplifying fake data source"); + MockDataSource.amplify(); } else if (allWords.contentEquals("set sensor code")) { G6CalibrationCodeDialog.ask(mActivity, null); } else if (allWords.contentEquals("multiple start")) { @@ -144,8 +159,10 @@ public static void processVoiceCommand(final String allWords, final Activity mAc Home.staticRefreshBGChartsOnIdle(); break; case "stop sensor on master": - JoH.static_toast_long(allWords); - GcmActivity.push_stop_master_sensor(); + if (get_engineering_mode()) { + JoH.static_toast_long(allWords); + GcmActivity.push_stop_master_sensor(); + } break; case "start sensor on master": JoH.static_toast_long(allWords); @@ -173,9 +190,15 @@ public static void processVoiceCommand(final String allWords, final Activity mAc case "start usb configuration": JoH.startActivity(MtpConfigureActivity.class); break; + case "erase all plugins": + Registry.eraseAll(); + JoH.static_toast_long("Erasing all plugins"); + break; case "database administration": JoH.startActivity(DatabaseAdmin.class); break; + case "simulate crash": + throw new RuntimeException("Test crash"); } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/WearSyncBooleans.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/WearSyncBooleans.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/WearSyncBooleans.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/WearSyncBooleans.java index bffba51a08..10b84b0855 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/WearSyncBooleans.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/WearSyncBooleans.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/WearSyncPersistentStrings.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/WearSyncPersistentStrings.java similarity index 77% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/WearSyncPersistentStrings.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/WearSyncPersistentStrings.java index f8534adf35..72f0be8ef1 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/WearSyncPersistentStrings.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/WearSyncPersistentStrings.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; -import com.eveningoutpost.dexdrip.G5Model.G6CalibrationParameters; +import com.eveningoutpost.dexdrip.g5model.G6CalibrationParameters; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/WholeHouse.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/WholeHouse.java similarity index 89% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/WholeHouse.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/WholeHouse.java index 67935e6f3d..80f94cecc5 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/WholeHouse.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/WholeHouse.java @@ -1,11 +1,11 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; // jamorham import android.content.pm.PackageManager; import android.os.Build; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.xdrip; public class WholeHouse { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/XDripDreamService.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/XDripDreamService.java similarity index 84% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/XDripDreamService.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/XDripDreamService.java index 9f14bcef01..fa697949ac 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/XDripDreamService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/XDripDreamService.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.animation.TimeAnimator; import android.content.Context; @@ -24,12 +24,12 @@ import android.widget.TextView; import com.eveningoutpost.dexdrip.BestGlucose; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; -import static com.eveningoutpost.dexdrip.UtilityModels.ColorCache.getCol; +import static com.eveningoutpost.dexdrip.utilitymodels.ColorCache.getCol; /** * Created by jamorham on 31/10/2016. @@ -246,57 +246,61 @@ private void updateGraph() { @Override public void onSensorChanged(SensorEvent event) { - if (use_gravity) { - final Sensor source = event.sensor; - if (source.getType() == Sensor.TYPE_GRAVITY) { - // final float z = event.values[2]; - final float y = event.values[1]; - final float x = event.values[0]; - - // calculate angle from gravity sensor only - float rotation = (y * 9) - 90; - if (rotation < 0) { - if (x > 0) { - rotation = 0 - rotation; + try { + if (use_gravity) { + final Sensor source = event.sensor; + if (source.getType() == Sensor.TYPE_GRAVITY) { + // final float z = event.values[2]; + final float y = event.values[1]; + final float x = event.values[0]; + + // calculate angle from gravity sensor only + float rotation = (y * 9) - 90; + if (rotation < 0) { + if (x > 0) { + rotation = 0 - rotation; + } } - } - - // normalize 0-360 - rotation = rotation + 180; - - final int window_rotation = getWindowManager().getDefaultDisplay().getRotation(); - - // compensate for view rotation - switch (window_rotation) { - case Surface.ROTATION_90: - rotation += 270; - break; - case Surface.ROTATION_180: - rotation += 180; - break; - case Surface.ROTATION_270: - rotation += 90; - break; - } - // snap to nearest 90 degree - final float adjust_rotation = ((int) (((rotation + 225) % 360) / 90)) * 90; - // update rotation if something changed - if (adjust_rotation != last_rotation) { - last_rotation = adjust_rotation; - JoH.runOnUiThread(new Runnable() { - @Override - public void run() { - image.setRotation(adjust_rotation); - graphimage.setRotation(adjust_rotation); - inflatedLayout.setRotation(adjust_rotation); - } - }); + // normalize 0-360 + rotation = rotation + 180; + + final int window_rotation = getWindowManager().getDefaultDisplay().getRotation(); + + // compensate for view rotation + switch (window_rotation) { + case Surface.ROTATION_90: + rotation += 270; + break; + case Surface.ROTATION_180: + rotation += 180; + break; + case Surface.ROTATION_270: + rotation += 90; + break; + } + // snap to nearest 90 degree + final float adjust_rotation = ((int) (((rotation + 225) % 360) / 90)) * 90; + // update rotation if something changed + if (adjust_rotation != last_rotation) { + last_rotation = adjust_rotation; + JoH.runOnUiThread(new Runnable() { + @Override + public void run() { + image.setRotation(adjust_rotation); + graphimage.setRotation(adjust_rotation); + inflatedLayout.setRotation(adjust_rotation); + + } + }); + } } + } else { + Log.e(TAG, "Got sensor data when sensor should be disabled"); + unregister_sensor_receiver(); } - } else { - Log.e(TAG, "Got sensor data when sensor should be disabled"); - unregister_sensor_receiver(); + } catch (Exception e) { + Log.e(TAG, "Got exception handling sensor changed: " + e); } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/XDripDreamSettingsActivity.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/XDripDreamSettingsActivity.java similarity index 85% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/XDripDreamSettingsActivity.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/XDripDreamSettingsActivity.java index 16409a73a9..e8b2429800 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/XDripDreamSettingsActivity.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/XDripDreamSettingsActivity.java @@ -1,7 +1,6 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; import com.eveningoutpost.dexdrip.BaseAppCompatActivity; import com.eveningoutpost.dexdrip.databinding.ActivityXdripDreamSettingsBinding; diff --git a/wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/XbridgePlus.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/XbridgePlus.java similarity index 94% rename from wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/XbridgePlus.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/XbridgePlus.java index a3febb5183..dc039fbbfb 100644 --- a/wear/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/XbridgePlus.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/XbridgePlus.java @@ -1,12 +1,12 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.xdrip; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.LIBRE_MULTIPLIER; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.LIBRE_MULTIPLIER; /** * Created by jamorham on 27/03/2017. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/XdripNotification.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/XdripNotification.java similarity index 93% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/XdripNotification.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/XdripNotification.java index 17299d13f0..7ad177e53c 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/XdripNotification.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/XdripNotification.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.annotation.TargetApi; import android.app.Notification; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/XdripNotificationCompat.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/XdripNotificationCompat.java similarity index 91% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/XdripNotificationCompat.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/XdripNotificationCompat.java index 6d4e63ae92..f4181b1480 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/XdripNotificationCompat.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/XdripNotificationCompat.java @@ -1,9 +1,9 @@ -package com.eveningoutpost.dexdrip.UtilityModels; +package com.eveningoutpost.dexdrip.utilitymodels; import android.annotation.TargetApi; import android.app.Notification; import android.os.Build; -import android.support.v4.app.NotificationCompat; +import androidx.core.app.NotificationCompat; /** * Created by jamorham on 18/10/2017. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/desertsync/DesertComms.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/desertsync/DesertComms.java similarity index 91% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/desertsync/DesertComms.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/desertsync/DesertComms.java index ebe6ec0b8b..ce63140d60 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/desertsync/DesertComms.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/desertsync/DesertComms.java @@ -1,15 +1,15 @@ -package com.eveningoutpost.dexdrip.UtilityModels.desertsync; +package com.eveningoutpost.dexdrip.utilitymodels.desertsync; import android.os.PowerManager; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.DesertSync; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; +import com.eveningoutpost.dexdrip.models.DesertSync; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; import com.eveningoutpost.dexdrip.webservices.XdripWebService; import com.google.gson.annotations.Expose; @@ -25,20 +25,20 @@ import okhttp3.Request; import okhttp3.Response; -import static com.eveningoutpost.dexdrip.Models.JoH.cancelNotification; -import static com.eveningoutpost.dexdrip.Models.JoH.defaultGsonInstance; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; -import static com.eveningoutpost.dexdrip.Models.JoH.getWakeLock; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.Models.JoH.pratelimit; -import static com.eveningoutpost.dexdrip.Models.JoH.releaseWakeLock; -import static com.eveningoutpost.dexdrip.Models.JoH.showNotification; -import static com.eveningoutpost.dexdrip.Models.JoH.tsl; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.DESERT_MASTER_UNREACHABLE; -import static com.eveningoutpost.dexdrip.UtilityModels.desertsync.DesertComms.QueueHandler.MasterPing; -import static com.eveningoutpost.dexdrip.UtilityModels.desertsync.DesertComms.QueueHandler.None; -import static com.eveningoutpost.dexdrip.UtilityModels.desertsync.DesertComms.QueueHandler.Pull; -import static com.eveningoutpost.dexdrip.UtilityModels.desertsync.DesertComms.QueueHandler.ToFollower; +import static com.eveningoutpost.dexdrip.models.JoH.cancelNotification; +import static com.eveningoutpost.dexdrip.models.JoH.defaultGsonInstance; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.getWakeLock; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.pratelimit; +import static com.eveningoutpost.dexdrip.models.JoH.releaseWakeLock; +import static com.eveningoutpost.dexdrip.models.JoH.showNotification; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.DESERT_MASTER_UNREACHABLE; +import static com.eveningoutpost.dexdrip.utilitymodels.desertsync.DesertComms.QueueHandler.MasterPing; +import static com.eveningoutpost.dexdrip.utilitymodels.desertsync.DesertComms.QueueHandler.None; +import static com.eveningoutpost.dexdrip.utilitymodels.desertsync.DesertComms.QueueHandler.Pull; +import static com.eveningoutpost.dexdrip.utilitymodels.desertsync.DesertComms.QueueHandler.ToFollower; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/desertsync/RouteTools.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/desertsync/RouteTools.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/desertsync/RouteTools.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/desertsync/RouteTools.java index fa07b2ee2c..27c732386e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/desertsync/RouteTools.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/desertsync/RouteTools.java @@ -1,9 +1,9 @@ -package com.eveningoutpost.dexdrip.UtilityModels.desertsync; +package com.eveningoutpost.dexdrip.utilitymodels.desertsync; // jamorham -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import java.net.InetAddress; import java.net.InterfaceAddress; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/desertsync/TrustManager.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/desertsync/TrustManager.java similarity index 96% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/desertsync/TrustManager.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/desertsync/TrustManager.java index 3ddac95c75..98be3e93ed 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/desertsync/TrustManager.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/desertsync/TrustManager.java @@ -1,6 +1,6 @@ -package com.eveningoutpost.dexdrip.UtilityModels.desertsync; +package com.eveningoutpost.dexdrip.utilitymodels.desertsync; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.utils.CipherUtils; import java.security.KeyManagementException; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayAbstract.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayAbstract.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayAbstract.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayAbstract.java index c8b981d60e..fc94788f09 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayAbstract.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayAbstract.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels.pebble; +package com.eveningoutpost.dexdrip.utilitymodels.pebble; import android.content.Context; import android.content.Intent; @@ -7,13 +7,13 @@ import android.preference.PreferenceManager; import com.eveningoutpost.dexdrip.BestGlucose; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.ParakeetHelper; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.store.FastStore; import com.eveningoutpost.dexdrip.store.KeyStore; import com.eveningoutpost.dexdrip.utils.DexCollectionType; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayDummy.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayDummy.java similarity index 84% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayDummy.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayDummy.java index 14b0348285..d00d83a2fd 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayDummy.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayDummy.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels.pebble; +package com.eveningoutpost.dexdrip.utilitymodels.pebble; import com.getpebble.android.kit.util.PebbleDictionary; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayInterface.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayInterface.java similarity index 88% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayInterface.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayInterface.java index 623997de0e..01fefb6c11 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayInterface.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayInterface.java @@ -1,8 +1,8 @@ -package com.eveningoutpost.dexdrip.UtilityModels.pebble; +package com.eveningoutpost.dexdrip.utilitymodels.pebble; import android.content.Context; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; import com.getpebble.android.kit.util.PebbleDictionary; import java.util.UUID; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayStandard.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayStandard.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayStandard.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayStandard.java index 6fd33cafdf..35c712290b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayStandard.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayStandard.java @@ -1,11 +1,11 @@ -package com.eveningoutpost.dexdrip.UtilityModels.pebble; +package com.eveningoutpost.dexdrip.utilitymodels.pebble; import android.content.Intent; import com.eveningoutpost.dexdrip.BestGlucose; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.getpebble.android.kit.PebbleKit; import com.getpebble.android.kit.util.PebbleDictionary; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayTrend.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayTrend.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayTrend.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayTrend.java index 2ed035599b..494d1e2d13 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayTrend.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayTrend.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels.pebble; +package com.eveningoutpost.dexdrip.utilitymodels.pebble; import android.graphics.Bitmap; import android.os.PowerManager; @@ -6,15 +6,15 @@ import com.eveningoutpost.dexdrip.BestGlucose; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.ActiveBgAlert; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.BgSparklineBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.SimpleImageEncoder; +import com.eveningoutpost.dexdrip.models.ActiveBgAlert; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.BgSparklineBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.SimpleImageEncoder; import com.getpebble.android.kit.PebbleKit; import com.getpebble.android.kit.util.PebbleDictionary; import com.getpebble.android.kit.util.PebbleTuple; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayTrendOld.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayTrendOld.java similarity index 97% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayTrendOld.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayTrendOld.java index 2adbafa747..9666a12cc7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayTrendOld.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayTrendOld.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels.pebble; +package com.eveningoutpost.dexdrip.utilitymodels.pebble; import android.graphics.Bitmap; import android.os.PowerManager; @@ -6,15 +6,15 @@ import com.eveningoutpost.dexdrip.BestGlucose; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.ActiveBgAlert; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.BgSparklineBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.SimpleImageEncoder; +import com.eveningoutpost.dexdrip.models.ActiveBgAlert; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.BgSparklineBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.SimpleImageEncoder; import com.getpebble.android.kit.PebbleKit; import com.getpebble.android.kit.util.PebbleDictionary; import com.getpebble.android.kit.util.PebbleTuple; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayType.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayType.java similarity index 71% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayType.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayType.java index 4a8e65991f..166bb319dd 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayType.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleDisplayType.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels.pebble; +package com.eveningoutpost.dexdrip.utilitymodels.pebble; /** * Created by andy on 01/06/16. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleUtil.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleUtil.java similarity index 90% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleUtil.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleUtil.java index 9656f54a0d..6d4569c331 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleUtil.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleUtil.java @@ -1,9 +1,7 @@ -package com.eveningoutpost.dexdrip.UtilityModels.pebble; +package com.eveningoutpost.dexdrip.utilitymodels.pebble; -import android.content.SharedPreferences; - -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleWatchSync.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleWatchSync.java similarity index 95% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleWatchSync.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleWatchSync.java index c675f94788..a3244f7941 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleWatchSync.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/PebbleWatchSync.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels.pebble; +package com.eveningoutpost.dexdrip.utilitymodels.pebble; import android.bluetooth.BluetoothManager; import android.content.Context; @@ -7,15 +7,15 @@ import android.os.IBinder; import android.os.PowerManager; -import com.eveningoutpost.dexdrip.Models.HeartRate; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.StepCounter; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.BroadcastSnooze; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.HeartRate; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.StepCounter; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.BroadcastSnooze; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.framework.ForegroundService; import com.eveningoutpost.dexdrip.xdrip; import com.getpebble.android.kit.PebbleKit; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/watchface/InstallPebbleClassicTrendWatchface.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/watchface/InstallPebbleClassicTrendWatchface.java similarity index 90% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/watchface/InstallPebbleClassicTrendWatchface.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/watchface/InstallPebbleClassicTrendWatchface.java index 53e860eb0a..4713e9e298 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/watchface/InstallPebbleClassicTrendWatchface.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/watchface/InstallPebbleClassicTrendWatchface.java @@ -1,4 +1,4 @@ -package com.eveningoutpost.dexdrip.UtilityModels.pebble.watchface; +package com.eveningoutpost.dexdrip.utilitymodels.pebble.watchface; import com.eveningoutpost.dexdrip.R; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/watchface/InstallPebbleSnoozeControlApp.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/watchface/InstallPebbleSnoozeControlApp.java similarity index 90% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/watchface/InstallPebbleSnoozeControlApp.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/watchface/InstallPebbleSnoozeControlApp.java index 41f17038b1..fda109015f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/watchface/InstallPebbleSnoozeControlApp.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/watchface/InstallPebbleSnoozeControlApp.java @@ -1,5 +1,5 @@ -package com.eveningoutpost.dexdrip.UtilityModels.pebble.watchface; +package com.eveningoutpost.dexdrip.utilitymodels.pebble.watchface; import com.eveningoutpost.dexdrip.R; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/watchface/InstallPebbleTrendClayWatchFace.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/watchface/InstallPebbleTrendClayWatchFace.java similarity index 90% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/watchface/InstallPebbleTrendClayWatchFace.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/watchface/InstallPebbleTrendClayWatchFace.java index cb4f245060..24ff941421 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/watchface/InstallPebbleTrendClayWatchFace.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/watchface/InstallPebbleTrendClayWatchFace.java @@ -1,5 +1,5 @@ -package com.eveningoutpost.dexdrip.UtilityModels.pebble.watchface; +package com.eveningoutpost.dexdrip.utilitymodels.pebble.watchface; import com.eveningoutpost.dexdrip.R; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/watchface/InstallPebbleTrendWatchFace.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/watchface/InstallPebbleTrendWatchFace.java similarity index 90% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/watchface/InstallPebbleTrendWatchFace.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/watchface/InstallPebbleTrendWatchFace.java index 7a8a1adf30..5422cc1c14 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/watchface/InstallPebbleTrendWatchFace.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/watchface/InstallPebbleTrendWatchFace.java @@ -1,5 +1,5 @@ -package com.eveningoutpost.dexdrip.UtilityModels.pebble.watchface; +package com.eveningoutpost.dexdrip.utilitymodels.pebble.watchface; import com.eveningoutpost.dexdrip.R; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/watchface/InstallPebbleWatchFace.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/watchface/InstallPebbleWatchFace.java similarity index 94% rename from app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/watchface/InstallPebbleWatchFace.java rename to app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/watchface/InstallPebbleWatchFace.java index 4e6f3e81a6..e26acd0551 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/watchface/InstallPebbleWatchFace.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/pebble/watchface/InstallPebbleWatchFace.java @@ -1,5 +1,5 @@ -package com.eveningoutpost.dexdrip.UtilityModels.pebble.watchface; +package com.eveningoutpost.dexdrip.utilitymodels.pebble.watchface; import android.Manifest; import android.app.Activity; @@ -11,15 +11,15 @@ import android.os.Build; import android.os.Bundle; import android.os.Environment; -import android.support.annotation.NonNull; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; +import androidx.annotation.NonNull; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; import android.util.Log; import android.widget.Toast; import com.eveningoutpost.dexdrip.BaseAppCompatActivity; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; import java.io.File; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/ActivityWithMenu.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/ActivityWithMenu.java index 1444646fb5..7c23236539 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/ActivityWithMenu.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/ActivityWithMenu.java @@ -2,11 +2,13 @@ import android.content.Intent; import android.os.Bundle; -import android.support.v4.widget.DrawerLayout; + + +import androidx.drawerlayout.widget.DrawerLayout; import com.eveningoutpost.dexdrip.BaseAppCompatActivity; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.NavDrawerBuilder; import com.eveningoutpost.dexdrip.NavigationDrawerFragment; import com.eveningoutpost.dexdrip.R; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/AndroidBarcode.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/AndroidBarcode.java index fdaa8a4c6c..182352e0cb 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/AndroidBarcode.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/AndroidBarcode.java @@ -5,18 +5,22 @@ import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import androidx.appcompat.app.AppCompatActivity; import androidx.annotation.NonNull; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; import com.eveningoutpost.dexdrip.xdrip; import com.google.zxing.client.android.Intents; import com.google.zxing.integration.android.IntentIntegrator; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + /** * This is a helper class to facilitate asking for camera permission and returning * the scan result to the original instantiating activity @@ -66,7 +70,15 @@ public void onRequestPermissionsResult(final int requestCode, } private void actuallyStartScan() { - new IntentIntegrator(activity).initiateScan(); + new IntentIntegrator(activity) + .setPrompt(xdrip.gs(R.string.scan_to_load_xdrip_settings)) + .setDesiredBarcodeFormats(list("QR_CODE", "CODE_128")) + .initiateScan(); + } + + // TODO move to utils + private static List list(final String... values) { + return Collections.unmodifiableList(Arrays.asList(values)); } private void requestPermission() { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/AppCenterCrashReporting.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/AppCenterCrashReporting.java new file mode 100644 index 0000000000..f13e29af0d --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/AppCenterCrashReporting.java @@ -0,0 +1,52 @@ +package com.eveningoutpost.dexdrip.utils; + +import android.app.Application; + +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.microsoft.appcenter.AppCenter; +import com.microsoft.appcenter.analytics.Analytics; +import com.microsoft.appcenter.crashes.Crashes; + +// JamOrHam +public class AppCenterCrashReporting { + + private static final String TAG = "AppCenter"; + + private static final String APPLICATION_T = "85f" + "04671" + "-2414" + "-4723" + "-bcd9" + "-434a45" + "a2e66e"; + + private static volatile boolean started = false; + + public synchronized static void start(Application xdrip) { + + try { + if (started) { + UserError.Log.e(TAG, "Already started!"); + return; + } + started = true; + if (JoH.pratelimit("crash-reporting-start", 240) || + JoH.pratelimit("crash-reporting-start2", 240)) { + AppCenter.start(xdrip, APPLICATION_T, Analytics.class, Crashes.class); + } else { + if (JoH.pratelimit("crash-reporting-start-failure", 3600)) { + UserError.Log.wtf(TAG, "Unable to start crash reporter as app is restarting too frequently - if you are a developer then you can ignore this message"); + } + } + } catch (Throwable e) { + if (JoH.pratelimit("crash-reporting-start-exception", 3600)) { + UserError.Log.wtf(TAG, "Unable to start crash reporter: " + e); + } + } finally { + Inevitable.task("Commit-start", 100, () -> { + try { + PersistentStore.commit(); + } catch (Exception e) { + // + } + }); + } + } +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/BgToSpeech.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/BgToSpeech.java index 95b3efee4d..8b2c94875f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/BgToSpeech.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/BgToSpeech.java @@ -1,21 +1,21 @@ package com.eveningoutpost.dexdrip.utils; import com.eveningoutpost.dexdrip.BestGlucose; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.SpeechUtil; -import com.eveningoutpost.dexdrip.UtilityModels.VehicleMode; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.SpeechUtil; +import com.eveningoutpost.dexdrip.utilitymodels.VehicleMode; import com.eveningoutpost.dexdrip.xdrip; import java.text.DecimalFormat; -import static com.eveningoutpost.dexdrip.UtilityModels.SpeechUtil.TWICE_DELIMITER; +import static com.eveningoutpost.dexdrip.utilitymodels.SpeechUtil.TWICE_DELIMITER; /** * Created by adrian on 07/09/15. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/BlobCache.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/BlobCache.java new file mode 100644 index 0000000000..7d2ae2e14c --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/BlobCache.java @@ -0,0 +1,66 @@ +package com.eveningoutpost.dexdrip.utils; + +import android.os.SystemClock; + +// JamOrHam +public class BlobCache { + + private final Object lock = new Object(); + private volatile Object blobCache = null; + private static volatile long blobTime = 0; + static volatile long blobParamX = 0; + static volatile long blobParamY = 0; + + private final long timeout; + + public BlobCache(long timeout) { + this.timeout = timeout; + } + + public void set(Object o) { + synchronized (lock) { + blobCache = o; + blobTime = SystemClock.elapsedRealtime(); + } + } + + public Object get() { + synchronized (lock) { + if (isExpired()) { + blobCache = null; + } + return blobCache; + } + } + + public void set(Object o, long x, long y) { + synchronized (lock) { + blobParamX = x; + blobParamY = y; + blobCache = o; + blobTime = SystemClock.elapsedRealtime(); + } + } + + public Object get(long x, long y) { + synchronized (lock) { + if (x != blobParamX || y != blobParamY) { + return null; + } + return get(); + } + } + + public void clear() { + blobCache = null; + blobTime = 0; + } + + public boolean isExpired() { + synchronized (lock) { + return (blobCache == null || SystemClock.elapsedRealtime() - blobTime > timeout); + } + } + +} + diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/CRC16ccitt.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/CRC16ccitt.java index f6f7305d6c..a195513822 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/CRC16ccitt.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/CRC16ccitt.java @@ -2,8 +2,8 @@ // jamorham -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; public class CRC16ccitt { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/CheckBridgeBattery.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/CheckBridgeBattery.java index 6f2b2f7554..885227e132 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/CheckBridgeBattery.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/CheckBridgeBattery.java @@ -4,17 +4,17 @@ import android.content.Intent; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.NotificationChannels; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.NotificationChannels; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.xdrip; -import static com.eveningoutpost.dexdrip.Models.JoH.cancelNotification; -import static com.eveningoutpost.dexdrip.Models.JoH.showNotification; +import static com.eveningoutpost.dexdrip.models.JoH.cancelNotification; +import static com.eveningoutpost.dexdrip.models.JoH.showNotification; /** * Created by jamorham on 26/01/2017. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/CipherUtils.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/CipherUtils.java index 24c970d0e3..728a883a7f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/CipherUtils.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/CipherUtils.java @@ -8,7 +8,7 @@ import android.util.Log; import com.eveningoutpost.dexdrip.GoogleDriveInterface; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; @@ -206,13 +206,17 @@ public static String compressEncryptBytes(byte[] plainText) { , Base64.NO_WRAP); } - public static byte[] getRandomKey() { - byte[] keybytes = new byte[16]; + public static byte[] getRandomKey(final int length) { + byte[] keybytes = new byte[length]; SecureRandom sr = new SecureRandom(); sr.nextBytes(keybytes); return keybytes; } + public static byte[] getRandomKey() { + return getRandomKey(16); + } + public static String getRandomHexKey() { return bytesToHex(getRandomKey()); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/DatabaseUtil.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/DatabaseUtil.java index 24f6adc153..dd3cb255af 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/DatabaseUtil.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/DatabaseUtil.java @@ -9,11 +9,12 @@ import android.text.format.DateFormat; import android.widget.Toast; +import com.activeandroid.ActiveAndroid; import com.activeandroid.Cache; import com.activeandroid.Configuration; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -354,6 +355,10 @@ public static String loadSql(Context context, String path) { destStream = new FileOutputStream(currentDBtmp); dst = destStream.getChannel(); dst.transferFrom(src, 0, src.size()); + destStream.flush(); + // Close all active db connections before database import. + ActiveAndroid.clearCache(); + ActiveAndroid.dispose(); currentDB.renameTo(currentDBold); currentDBtmp.renameTo(currentDB); currentDBold.delete(); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/DexCollectionHelper.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/DexCollectionHelper.java index 5a36022f13..87c2678e72 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/DexCollectionHelper.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/DexCollectionHelper.java @@ -6,12 +6,14 @@ import com.eveningoutpost.dexdrip.BluetoothScan; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice; +import com.eveningoutpost.dexdrip.models.ActiveBluetoothDevice; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.services.Ob1G5CollectionService; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.cgm.sharefollow.ShareFollowService; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.CareLinkFollowService; +import com.eveningoutpost.dexdrip.plugin.Dialog; import com.eveningoutpost.dexdrip.xdrip; import static com.eveningoutpost.dexdrip.ui.dialog.QuickSettingsDialogs.booleanSettingDialog; @@ -48,7 +50,9 @@ public static void assistance(Activity activity, DexCollectionType type) { public void run() { // InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS does not seem functional here Pref.setString(pref, Pref.getString(pref, "").toUpperCase()); - Home.staticRefreshBGCharts(); + if (!Dialog.askIfNeeded(activity, Pref.getString(pref, ""))) { + Home.staticRefreshBGCharts(); + } CollectionServiceStarter.restartCollectionServiceBackground(); } }); @@ -129,6 +133,55 @@ public void run() { bluetoothScanIfNeeded(); break; + case LibreReceiver: + Home.staticRefreshBGChartsOnIdle(); + break; + + /* LOGIN via browser is required currently + case CLFollow: + textSettingDialog(activity, + "clfollow_country", "CareLink Country", + "Two letter country ISO code", + InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD, + new Runnable() { + @Override + public void run() { + textSettingDialog(activity, + "clfollow_user", "CareLink Username", + "Enter CareLink Username", + InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD, + new Runnable() { + @Override + public void run() { + textSettingDialog(activity, + "clfollow_pass", "CareLink Password", + "Enter CareLink Password", + InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD, + new Runnable() { + @Override + public void run() { + textSettingDialog(activity, + "clfollow_patient", "CareLink Patient", + "Enter CareLink Patient (optional)", + InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD, + new Runnable() { + @Override + public void run() { + Home.staticRefreshBGCharts(); + CareLinkFollowService.resetInstanceAndInvalidateSession(); + CollectionServiceStarter.restartCollectionServiceBackground(); + } + }); + } + }); + } + }); + } + }); + break; + + */ + // TODO G4 Share Receiver // TODO Parakeet / Wifi ?? diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/DexCollectionType.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/DexCollectionType.java index 29109d7dd1..5fc20f886c 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/DexCollectionType.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/DexCollectionType.java @@ -1,17 +1,20 @@ package com.eveningoutpost.dexdrip.utils; -import com.eveningoutpost.dexdrip.Services.DexCollectionService; -import com.eveningoutpost.dexdrip.Services.DexShareCollectionService; -import com.eveningoutpost.dexdrip.Services.DoNothingService; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; -import com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService; -import com.eveningoutpost.dexdrip.Services.UiBasedCollector; -import com.eveningoutpost.dexdrip.Services.WifiCollectionService; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.services.DexCollectionService; +import com.eveningoutpost.dexdrip.services.DexShareCollectionService; +import com.eveningoutpost.dexdrip.services.DoNothingService; +import com.eveningoutpost.dexdrip.services.G5CollectionService; +import com.eveningoutpost.dexdrip.services.Ob1G5CollectionService; +import com.eveningoutpost.dexdrip.services.UiBasedCollector; +import com.eveningoutpost.dexdrip.services.WifiCollectionService; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.cgm.medtrum.MedtrumCollectionService; import com.eveningoutpost.dexdrip.cgm.nsfollow.NightscoutFollowService; import com.eveningoutpost.dexdrip.cgm.sharefollow.ShareFollowService; import com.eveningoutpost.dexdrip.cgm.webfollow.WebFollowService; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.CareLinkFollowService; + +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.shortTxId; import java.lang.reflect.Method; import java.util.Collections; @@ -42,6 +45,7 @@ public enum DexCollectionType { NSFollow("NSFollower"), SHFollow("SHFollower"), WebFollow("WebFollower"), + CLFollow("CLFollower"), Medtrum("Medtrum"), UiBased("UiBased"), Disabled("Disabled"), @@ -81,7 +85,7 @@ public enum DexCollectionType { Collections.addAll(usesXbridge, DexbridgeWixel, WifiDexBridgeWixel); Collections.addAll(usesFiltered, DexbridgeWixel, WifiDexBridgeWixel, DexcomG5, WifiWixel, Follower, Mock); // Bluetooth and Wifi+Bluetooth need dynamic mode Collections.addAll(usesLibre, LimiTTer, LibreAlarm, LimiTTerWifi, LibreWifi, LibreReceiver); - Collections.addAll(isPassive, NSEmulator, NSFollow, SHFollow, WebFollow, LibreReceiver, UiBased); + Collections.addAll(isPassive, NSEmulator, NSFollow, SHFollow, WebFollow, LibreReceiver, UiBased, CLFollow, AidexReceiver); Collections.addAll(usesBattery, BluetoothWixel, DexbridgeWixel, WifiBlueToothWixel, WifiDexBridgeWixel, Follower, LimiTTer, LibreAlarm, LimiTTerWifi, LibreWifi); // parakeet separate Collections.addAll(usesDexcomRaw, BluetoothWixel, DexbridgeWixel, WifiWixel, WifiBlueToothWixel, DexcomG5, WifiDexBridgeWixel, Mock); Collections.addAll(usesTransmitterBattery, WifiWixel, BluetoothWixel, DexbridgeWixel, WifiBlueToothWixel, WifiDexBridgeWixel); // G4 transmitter battery @@ -205,6 +209,8 @@ public static Class getCollectorServiceClass(final DexCollectionType type) { return WebFollowService.class; case UiBased: return UiBasedCollector.class; + case CLFollow: + return CareLinkFollowService.class; default: return DexCollectionService.class; } @@ -272,7 +278,7 @@ public static String getBestCollectorHardwareName() { return "Network G4 and Classic xDrip"; case DexcomG5: if (Ob1G5CollectionService.usingNativeMode()) { - return Ob1G5CollectionService.usingG6() ? "G6 Native" : "G5 Native"; + return Ob1G5CollectionService.usingG6() ? (shortTxId() ? "G7" : "G6 Native") : "G5 Native"; } return dct.name(); case LibreWifi: @@ -284,6 +290,8 @@ public static String getBestCollectorHardwareName() { case UiBased: return "UI Based"; + case CLFollow: + return "CareLink"; default: return dct.name(); } @@ -321,8 +329,13 @@ public long getSamplePeriod() { return getCollectorSamplePeriod(this); } + private static final boolean libreOneMinute = Pref.getBooleanDefaultFalse("libre_one_minute") + && Pref.getBooleanDefaultFalse("engineering_mode"); + public static long getCollectorSamplePeriod(final DexCollectionType type) { switch (type) { + case LibreReceiver: + return libreOneMinute ? 60_000 : 300_000; default: return 300_000; // 5 minutes } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/DisconnectReceiver.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/DisconnectReceiver.java index bb1766db0e..2fa4ebb677 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/DisconnectReceiver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/DisconnectReceiver.java @@ -5,7 +5,7 @@ import android.content.Context; import android.content.Intent; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/DisplayQRCode.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/DisplayQRCode.java index f2d4d414e9..89d9848bbe 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/DisplayQRCode.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/DisplayQRCode.java @@ -1,7 +1,18 @@ package com.eveningoutpost.dexdrip.utils; +import static com.eveningoutpost.dexdrip.ui.helpers.BitmapUtil.getScreenHeight; +import static com.eveningoutpost.dexdrip.ui.helpers.BitmapUtil.getScreenWidth; +import static com.eveningoutpost.dexdrip.utils.QRcodeUtils.createQRCodeBitmap; +import static com.eveningoutpost.dexdrip.utils.QRcodeUtils.qrmarker; +import static com.eveningoutpost.dexdrip.utils.QRcodeUtils.serializeBinaryPrefsMap; + import android.content.Intent; import android.content.SharedPreferences; +import androidx.databinding.ObservableBoolean; +import androidx.databinding.ObservableField; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.os.Build; import android.os.Bundle; import android.os.PowerManager; import android.preference.PreferenceManager; @@ -11,15 +22,14 @@ import com.eveningoutpost.dexdrip.BaseAppCompatActivity; import com.eveningoutpost.dexdrip.GcmActivity; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.PrefsViewImpl; -import com.eveningoutpost.dexdrip.UtilityModels.desertsync.RouteTools; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.PrefsViewImpl; +import com.eveningoutpost.dexdrip.utilitymodels.desertsync.RouteTools; import com.eveningoutpost.dexdrip.databinding.ActivityDisplayQrcodeBinding; import com.eveningoutpost.dexdrip.xdrip; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; +import com.google.zxing.WriterException; import com.google.zxing.integration.android.IntentIntegrator; import com.squareup.okhttp.FormEncodingBuilder; import com.squareup.okhttp.OkHttpClient; @@ -29,47 +39,36 @@ import org.json.JSONObject; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; +import lombok.val; + public class DisplayQRCode extends BaseAppCompatActivity { - public static final String qrmarker = "xdpref:"; + private static final String TAG = "jamorham qr"; private static String send_url; private final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext()); private static DisplayQRCode mInstance; private Map prefsMap = new HashMap<>(); + private Map binaryPrefsMap = new HashMap<>(); + private String mapChecksum = "empty"; - public static Map decodeString(String data) { - try { - if (data.startsWith(qrmarker)) { - data = data.substring(qrmarker.length()); - Log.d(TAG, "String to uncompress: " + data); - data = JoH.uncompressString(data); - //Log.d(TAG, "Json after decompression: " + data); - Map mymap = new Gson().fromJson(data, new TypeToken>() { - }.getType()); - return mymap; - } else { - Log.e(TAG, "No qrmarker on qrcode"); - return null; - } - } catch (Exception e) { - Log.e(TAG, "Got exception during decodingString: " + e.toString()); - return null; - } - } + private ActivityDisplayQrcodeBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mInstance = this; - final ActivityDisplayQrcodeBinding binding = ActivityDisplayQrcodeBinding.inflate(getLayoutInflater()); + binding = ActivityDisplayQrcodeBinding.inflate(getLayoutInflater()); binding.setPrefs(new PrefsViewImpl()); + binding.setViewmodel(new ViewModel()); setContentView(binding.getRoot()); JoH.fixActionBar(this); processIntent(getIntent()); @@ -89,6 +88,9 @@ private void processIntent(final Intent intent) { case "xdrip_plus_desert_sync_qr": desertSyncSettings(null); break; + case "xdrip_plus_keks_qr": + showGKey(null); + break; } } } @@ -141,6 +143,36 @@ public synchronized void desertSyncSettings(View view) { } + public boolean generateKeksBinaryPrefs() { + binaryPrefsMap.clear(); + mapChecksum = "error"; + try { + val digest = MessageDigest.getInstance("SHA-256"); + val tem = "keks_p"; + for (int i = 1; i < 4; i++) { + val pn = tem + i; + val bb = JoH.hexStringToByteArray(Pref.getStringDefaultBlank(pn)); + if (bb == null || bb.length == 0) { + Log.d(TAG, "Null or empty at: " + i); + return false; + } + val px = "b__" + pn; + binaryPrefsMap.put(px, bb); + digest.update(px.getBytes(StandardCharsets.UTF_8)); + digest.update(bb); + } + mapChecksum = JoH.bytesToHex(digest.digest()); + return true; + } catch (Exception e) { + Log.d(TAG, "Got exception making binary prefs map " + e); + } + return false; + } + + public synchronized void showGKey(View view) { + showQRCode2("G Key settings\n\n" + Preferences.getMapKeysString(binaryPrefsMap).replace("\n", " ") + "\n\nHash: " + mapChecksum.substring(0, 16)); + } + public static synchronized void uploadBytes(byte[] result, final int callback_option) { final PowerManager.WakeLock wl = JoH.getWakeLock("uploadBytes", 1200000); if ((result != null) && (result.length > 0)) { @@ -262,6 +294,26 @@ private void showQRCode() { integrator.shareText(qrmarker + compressedstring); } + + private void showQRCode2(final String hint) { + val bytes = serializeBinaryPrefsMap(binaryPrefsMap); + Log.d(TAG, "QR bytes: " + bytes.length); + val bytesc = JoH.compressBytesToBytes(bytes); + Log.d(TAG, "QR bytes: " + bytesc.length); + val scale = (getScreenWidth() > getScreenHeight()) ? 0.8d : 1; + val desiredPixels = (int) (Math.min(getScreenWidth(), getScreenHeight()) * scale); + try { + val bitmap = createQRCodeBitmap(bytesc, desiredPixels, desiredPixels); + binding.getViewmodel().showQr.set(false); + binding.getViewmodel().narrative.set(JoH.dateTimeText(JoH.tsl()) + "\n" + Build.MANUFACTURER + " " + Build.MODEL + "\n" + hint); + binding.getViewmodel().qrbitmap.set(new BitmapDrawable(xdrip.getAppContext().getResources(), bitmap)); + binding.getViewmodel().showQr.set(true); + } catch (WriterException e) { + Log.e(TAG, "ERROR: " + e); + } + } + + public void closeNow(View view) { try { mInstance = null; @@ -276,4 +328,16 @@ private static void toast(final String msg) { JoH.static_toast_short(msg); } + + public class ViewModel { + public final ObservableBoolean showQr = new ObservableBoolean(); + public final ObservableField qrbitmap = new ObservableField<>(); + public final ObservableBoolean showGkey = new ObservableBoolean(); + public final ObservableField narrative = new ObservableField<>(); + + { + showGkey.set(generateKeksBinaryPrefs()); + } + + } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/ExampleChartPreferenceView.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/ExampleChartPreferenceView.java index 76d92179c1..330a96452a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/ExampleChartPreferenceView.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/ExampleChartPreferenceView.java @@ -9,7 +9,7 @@ import android.view.ViewGroup; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; import lecho.lib.hellocharts.model.Viewport; import lecho.lib.hellocharts.view.LineChartView; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/FileUtils.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/FileUtils.java index abfb204541..a817f6be7a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/FileUtils.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/FileUtils.java @@ -3,15 +3,18 @@ import android.content.Context; import android.os.Environment; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.xdrip; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; +import lombok.val; + public class FileUtils { public static boolean makeSureDirectoryExists(final String dir) { @@ -46,21 +49,47 @@ public static void writeToFileWithCurrentDate(String TAG, String file, byte[] da } public static void writeToFile(String TAG, String fileName, byte[] data) { - - - UserError.Log.i(TAG, "Writing to file" + fileName); + UserError.Log.d(TAG, "Writing to file" + fileName); try { - FileOutputStream f = new FileOutputStream(new File(fileName)); + FileOutputStream f = new FileOutputStream(fileName); if (data != null) { // if no data exists, file will be written with zero length to let the user know what is happening. f.write(data); + f.flush(); } f.close(); } catch (IOException e) { - UserError.Log.e(TAG, "Cought exception when trying to write file", e); + UserError.Log.e(TAG, "Caught exception when trying to write file", e); + } + } + + public static byte[] readFromFile(final String TAG, final String fileName) { + val fl = new File(fileName); + return readFromFile(TAG, fl); + } + + public static byte[] readFromFile(final String TAG, final File fl) { + if (!fl.exists()) { + UserError.Log.e(TAG, "File does not exist " + fl.getName()); + return null; + } + val data = new byte[(int) fl.length()]; + try { + val f = new FileInputStream(fl); + int size = f.read(data); + f.close(); + if (size != data.length) { + UserError.Log.e(TAG, "File read size mismatch"); + return null; + } + return data; + } catch (IOException e) { + UserError.Log.e(TAG, "Caught exception when trying to read file " + e); } + return null; } + /** * Recursively deletes a directory with all the files and directories inside of it * diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/GetWearApk.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/GetWearApk.java index 33f8e16bd3..145eee5547 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/GetWearApk.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/GetWearApk.java @@ -3,7 +3,7 @@ import android.content.pm.ApplicationInfo; import com.eveningoutpost.dexdrip.BuildConfig; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.xdrip; import java.io.BufferedInputStream; @@ -84,7 +84,7 @@ private static byte[] extractFromApk(File file) { while ((zipEntry = zip_stream.getNextEntry()) != null) { if (zipEntry.isDirectory()) continue; final String filename = zipEntry.getName(); - if (filename.endsWith("android_wear_micro_apk.apk")) { + if (filename.endsWith(".apk")) { final byte[] buffer = new byte[Math.min((int) zipEntry.getSize(), MAX_BYTES)]; final int read_bytes = readAllToBuffer(zip_stream, buffer); if (read_bytes != buffer.length) { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/HeadsetStateReceiver.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/HeadsetStateReceiver.java index 4b75553b6c..d735138529 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/HeadsetStateReceiver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/HeadsetStateReceiver.java @@ -9,17 +9,17 @@ import android.content.Intent; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.SpeechUtil; -import com.eveningoutpost.dexdrip.UtilityModels.VehicleMode; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.SpeechUtil; +import com.eveningoutpost.dexdrip.utilitymodels.VehicleMode; import com.eveningoutpost.dexdrip.ui.activities.SelectAudioDevice; import com.eveningoutpost.dexdrip.xdrip; -import static com.eveningoutpost.dexdrip.UtilityModels.SpeechUtil.TWICE_DELIMITER; +import static com.eveningoutpost.dexdrip.utilitymodels.SpeechUtil.TWICE_DELIMITER; /** * jamorham @@ -44,18 +44,16 @@ public void onReceive(Context context, Intent intent) { final int state = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE, -1); final int previousState = intent.getIntExtra(BluetoothHeadset.EXTRA_PREVIOUS_STATE, -1); final String deviceInfo = device.getName() + "\n" + device.getAddress() + " " + (device.getBluetoothClass() != null ? device.getBluetoothClass() : ""); - //UserError.Log.uel(TAG, "Bluetooth audio connection state change: " + state + " was " + previousState + " " + device.getAddress() + " " + device.getName()); + // UserError.Log.uel(TAG, "Bluetooth audio connection state change: from " + previousState + " to " + state + " " + device.getAddress() + " " + device.getName()); if (state == BluetoothProfile.STATE_CONNECTED && previousState != BluetoothProfile.STATE_CONNECTED) { PersistentStore.setString(PREF_LAST_CONNECTED_MAC, device.getAddress()); PersistentStore.setString(PREF_LAST_CONNECTED_NAME, device.getName()); UserError.Log.uel(TAG, "Bluetooth Audio connected: " + deviceInfo); processDevice(device.getAddress(), true); - - } else if (state == BluetoothProfile.STATE_DISCONNECTED && previousState == BluetoothProfile.STATE_CONNECTED) { + } else if (state == BluetoothProfile.STATE_DISCONNECTED && previousState != BluetoothProfile.STATE_DISCONNECTED) { UserError.Log.uel(TAG, "Bluetooth Audio disconnected: " + deviceInfo); processDevice(device.getAddress(), false); } - } else { UserError.Log.d(TAG, "Device was null in intent!"); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/HomeWifi.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/HomeWifi.java index 2139a5581b..7983a67448 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/HomeWifi.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/HomeWifi.java @@ -4,11 +4,11 @@ import android.app.AlertDialog; import android.content.DialogInterface; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; -import static com.eveningoutpost.dexdrip.Models.JoH.isLANConnected; +import static com.eveningoutpost.dexdrip.models.JoH.isLANConnected; /** * jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/LibreTrendGraph.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/LibreTrendGraph.java index cedd3d2cdc..6b94d4ae02 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/LibreTrendGraph.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/LibreTrendGraph.java @@ -1,22 +1,17 @@ package com.eveningoutpost.dexdrip.utils; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.TextView; import com.eveningoutpost.dexdrip.BaseAppCompatActivity; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.GlucoseData; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.LibreBlock; -import com.eveningoutpost.dexdrip.Models.ReadingData; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.NFCReaderX; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.LibreBlock; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.HPointValue; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.HPointValue; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import java.text.DateFormat; import java.util.ArrayList; @@ -30,7 +25,7 @@ import lecho.lib.hellocharts.util.ChartUtils; import lecho.lib.hellocharts.view.LineChartView; -import static com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder.FUZZER; +import static com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder.FUZZER; public class LibreTrendGraph extends BaseAppCompatActivity { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/LibreTrendPoint.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/LibreTrendPoint.java index 9fc694c0f8..8fef7b7c2b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/LibreTrendPoint.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/LibreTrendPoint.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.utils; -import com.eveningoutpost.dexdrip.Models.GlucoseData; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.GlucoseData; +import com.eveningoutpost.dexdrip.models.UserError.Log; //This class represents a per minute data from the libre. public class LibreTrendPoint { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/LibreTrendUtil.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/LibreTrendUtil.java index 633680c118..c33070a202 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/LibreTrendUtil.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/LibreTrendUtil.java @@ -6,16 +6,14 @@ import java.util.List; import java.util.ListIterator; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.NFCReaderX; -import com.eveningoutpost.dexdrip.Models.GlucoseData; -import com.eveningoutpost.dexdrip.Models.LibreBlock; -import com.eveningoutpost.dexdrip.Models.ReadingData; +import com.eveningoutpost.dexdrip.models.GlucoseData; +import com.eveningoutpost.dexdrip.models.LibreBlock; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.utils.LibreTrendPoint; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; /* This class helps to retrieve the latest libre trend points. It holds data of one sensor only. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/ListActivityWithMenu.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/ListActivityWithMenu.java index 7a7d570964..f395b82642 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/ListActivityWithMenu.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/ListActivityWithMenu.java @@ -1,9 +1,10 @@ package com.eveningoutpost.dexdrip.utils; -import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; -import android.support.v4.widget.DrawerLayout; + + +import androidx.drawerlayout.widget.DrawerLayout; import com.eveningoutpost.dexdrip.BaseListActivity; import com.eveningoutpost.dexdrip.NavDrawerBuilder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/LocationHelper.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/LocationHelper.java index a5544d2902..9851d1984c 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/LocationHelper.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/LocationHelper.java @@ -10,11 +10,13 @@ import android.location.LocationManager; import android.os.Build; import android.os.Looper; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; /** * Helper for checking if location services are enabled on the device. @@ -22,6 +24,7 @@ public class LocationHelper { static final String TAG = "xDrip LocationHelper"; + private static final boolean newType = false; /** * Determine if Network provider is currently enabled. * @@ -81,9 +84,40 @@ public void onClick(DialogInterface dialogInterface, int i) { * Android 6 (Marshmallow) needs GPS enabled for Bluetooth discovery to work. * * @param activity The currently visible activity. + * @return true if we have needed permissions, false if we needed to ask for more */ - public static void requestLocationForBluetooth(final Activity activity) { + public static boolean requestLocationForBluetooth(final Activity activity) { // Location needs to be enabled for Bluetooth discovery on Marshmallow. + + if (newType && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + if ((ContextCompat.checkSelfPermission(activity, + Manifest.permission.BLUETOOTH_SCAN) + != PackageManager.PERMISSION_GRANTED) + || (ContextCompat.checkSelfPermission(activity, + Manifest.permission.BLUETOOTH_CONNECT) + != PackageManager.PERMISSION_GRANTED)) { + + JoH.show_ok_dialog(activity, activity.getString(R.string.please_allow_permission), "Need bluetooth permissions", new Runnable() { + @Override + public void run() { + try { + ActivityCompat.requestPermissions(activity, + new String[]{Manifest.permission.BLUETOOTH_SCAN + , Manifest.permission.BLUETOOTH_CONNECT}, + 0); + // below is not ideal as we should really trap the activity result but it can come from different activities and there is no parent... + Inevitable.task("location-perm-restart", 6000, CollectionServiceStarter::restartCollectionServiceBackground); + } catch (Exception e) { + JoH.static_toast_long("Got Exception with Bluetooth Permission: " + e); + } + } + }); + return false; + + } + return true; + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ContextCompat.checkSelfPermission(activity, @@ -97,35 +131,40 @@ public void run() { ActivityCompat.requestPermissions(activity, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 0); + // below is not ideal as we should really trap the activity result but it can come from different activities and there is no parent... + Inevitable.task("location-perm-restart", 6000, CollectionServiceStarter::restartCollectionServiceBackground); } catch (Exception e) { JoH.static_toast_long("Got Exception with Location Permission: " + e); } } }); + return false; } else { // Android 10 check additional permissions if (Build.VERSION.SDK_INT >= 29) { if (ContextCompat.checkSelfPermission(activity, ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED) { - JoH.show_ok_dialog(activity, activity.getString(R.string.please_allow_permission), activity.getString(R.string.android_10_need_background_location), new Runnable() { - @Override - public void run() { - try { - ActivityCompat.requestPermissions(activity, - new String[]{ACCESS_BACKGROUND_LOCATION}, - 0); - } catch (Exception e) { - JoH.static_toast_long("Got Exception with Android 10 Location Permission: " + e); + JoH.show_ok_dialog(activity, activity.getString(R.string.please_allow_permission), activity.getString(R.string.android_10_need_background_location), new Runnable() { + @Override + public void run() { + try { + ActivityCompat.requestPermissions(activity, + new String[]{ACCESS_BACKGROUND_LOCATION}, + 0); + } catch (Exception e) { + JoH.static_toast_long("Got Exception with Android 10 Location Permission: " + e); + } } - } - }); + }); + return false; } } } LocationHelper.requestLocation(activity); } + return true; } public static void requestLocationForEmergencyMessage(final Activity activity) { @@ -174,13 +213,17 @@ public static boolean isLocationPermissionOk(Context context) { } public static Boolean locationPermission(final Activity activity) { - if (Build.VERSION.SDK_INT >= 29) { - // check background location as well on android 10+ - return ((ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) - && (ActivityCompat.checkSelfPermission(activity, ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED)); - } else { - return ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED; - } + if (newType && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + return ((ActivityCompat.checkSelfPermission(activity, Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED) + && (ActivityCompat.checkSelfPermission(activity, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED)); + } else if (Build.VERSION.SDK_INT >= 29) { + // check background location as well on android 10+ + return ((ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) + && (ActivityCompat.checkSelfPermission(activity, ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED)); + } else { + return ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED; + } + } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/Mdns.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/Mdns.java index c6f00fd465..1ee897c816 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/Mdns.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/Mdns.java @@ -11,21 +11,26 @@ import com.eveningoutpost.dexdrip.Home; import com.eveningoutpost.dexdrip.MegaStatus; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.JamorhamShowcaseDrawer; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.ShotStateStore; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.JamorhamShowcaseDrawer; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.ShotStateStore; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; import com.eveningoutpost.dexdrip.xdrip; import com.github.amlcurran.showcaseview.ShowcaseView; import com.github.amlcurran.showcaseview.targets.ViewTarget; +import java.net.Inet4Address; +import java.net.Inet6Address; import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -79,6 +84,10 @@ String prettyName() { private static final String TAG = "Mdns-discovery"; private static final boolean d = true; + private static NetworkInterface wifi_scope_id; + private static long wifi_scope_id_received; + + // resolve a normal or .local hostname public static String genericResolver(String name) throws UnknownHostException { final String lower = name.toLowerCase(); @@ -92,7 +101,7 @@ public static String genericResolver(String name) throws UnknownHostException { } } - public static String fastResolve(String name) { + private static String fastResolve(String name) { String address = superFastResolve(name); if (address != null) return address; final long wait_until = JoH.tsl() + NORMAL_RESOLVE_TIMEOUT_MS; @@ -107,7 +116,7 @@ public static String fastResolve(String name) { return address; } - public static String superFastResolve(String name) { + private static String superFastResolve(String name) { final LookUpInfo li = iplookup.get(name); if ((li == null) || (JoH.msSince(li.received) > CACHE_REFRESH_MS)) { if (JoH.quietratelimit("mdns-hunting", 60)) { @@ -123,6 +132,34 @@ public void run() { return li.address; } + private NetworkInterface getWifiScopeId() { + if (wifi_scope_id != null && JoH.msSince(wifi_scope_id_received) < CACHE_REFRESH_MS) { + UserError.Log.d(TAG, "Found network interface in cache"); + return wifi_scope_id; + } + + Enumeration networkInterfaces; + + try { + networkInterfaces = NetworkInterface.getNetworkInterfaces(); + while (networkInterfaces.hasMoreElements()) { + NetworkInterface networkInterface = networkInterfaces.nextElement(); + if (networkInterface.getDisplayName().equals("wlan0") || networkInterface.getDisplayName().equals("eth0")) { + UserError.Log.d(TAG, "Found network interface" ); + wifi_scope_id_received = JoH.tsl(); + wifi_scope_id = networkInterface; + return networkInterface; + } + } + } catch (SocketException e) { + UserError.Log.e(TAG,"Error: Got exception in getWifiScopeId", e); + return null; + + } + UserError.Log.e(TAG,"Error: found network interface not found"); + return null; + } + private void hunt() { final PowerManager.WakeLock wl = JoH.getWakeLock("mdns-hunt", 30000); if (hunt_running) { @@ -294,15 +331,40 @@ public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) { locked_until = 0; } + // Fix the host addresses returned for LocalLink and sitelocal ipv6 addresses. The address returned for them should + // be in the format IPv6-address%scope_id. See https://docs.oracle.com/javase/8/docs/api/java/net/Inet6Address.html + // for more details. + private String getFixedHostAddress(InetAddress host ) { + if(host instanceof Inet6Address){ + UserError.Log.d(TAG,"Resolved IPV6"+ host ); + Inet6Address i6 = (Inet6Address)host; + if(i6.isLinkLocalAddress() || i6.isSiteLocalAddress()) { + try { + host = Inet6Address.getByAddress(null, host.getAddress(), getWifiScopeId()); + return host.getHostAddress(); + } catch (UnknownHostException e) { + UserError.Log.e(TAG, "Error: Got exception in Inet6Address.getByAddress ipv6 will probably not work", e); + // Fall back to the original behavior. + return host.getHostAddress(); + } + } + UserError.Log.d(TAG,"Resolved IPV6 golbal addresses"); + return host.getHostAddress(); + } else{ + UserError.Log.d(TAG,"Resolved IPV4"); + return host.getHostAddress(); + } + } + @Override public void onServiceResolved(NsdServiceInfo serviceInfo) { final InetAddress host = serviceInfo.getHost(); - final String address = host.getHostAddress(); - UserError.Log.d(TAG, serviceInfo.getServiceName() + " Resolved address = " + address); + final String address = getFixedHostAddress(host); + UserError.Log.d(TAG, serviceInfo.getServiceName() + " Resolved address = " + address ); final String short_name = shortenName(serviceInfo.getServiceName().toLowerCase()); if (!address.contains(":") || (iplookup.get(short_name) == null) || (JoH.msSince(iplookup.get(short_name).received) > 60000)) { - iplookup.put(short_name, new LookUpInfo(address, JoH.tsl(), serviceInfo)); + iplookup.put(short_name, new LookUpInfo(address, JoH.tsl(), serviceInfo )); } else { UserError.Log.d(TAG, "Skipping overwrite of " + short_name + " with " + address + " due to ipv4 priority"); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/NewRelicCrashReporting.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/NewRelicCrashReporting.java index addc15e8e9..dfdcb1f763 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/NewRelicCrashReporting.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/NewRelicCrashReporting.java @@ -4,10 +4,10 @@ import static com.eveningoutpost.dexdrip.utils.NewRelicCrashReporting.StateMonitor.checkReportingInterval; import com.eveningoutpost.dexdrip.BuildConfig; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; import com.eveningoutpost.dexdrip.xdrip; import com.newrelic.agent.android.AgentConfiguration; import com.newrelic.agent.android.AndroidAgentImpl; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/PowerStateReceiver.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/PowerStateReceiver.java index 37481a09e2..5b8e81866b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/PowerStateReceiver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/PowerStateReceiver.java @@ -8,6 +8,7 @@ import android.os.BatteryManager; import android.util.Log; +import com.eveningoutpost.dexdrip.alert.Poller; import com.eveningoutpost.dexdrip.xdrip; /** @@ -66,9 +67,11 @@ public void onReceive(Context context, Intent intent) { if (action.equals(Intent.ACTION_POWER_CONNECTED)) { setInternalPrefsBoolean(PREFS_POWER_STATE, true); Log.d(TAG, "Power connected"); + Poller.chargerConnectedDisconnected(); } else if (action.equals(Intent.ACTION_POWER_DISCONNECTED)) { setInternalPrefsBoolean(PREFS_POWER_STATE, false); Log.d(TAG, "Power disconnected "); + Poller.chargerConnectedDisconnected(); } } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java index caee32d459..afbb490e9a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java @@ -1,5 +1,8 @@ package com.eveningoutpost.dexdrip.utils; +import static com.eveningoutpost.dexdrip.utils.DexCollectionType.getBestCollectorHardwareName; +import static com.eveningoutpost.dexdrip.xdrip.gs; + import android.Manifest; import android.annotation.SuppressLint; import android.app.Activity; @@ -32,10 +35,10 @@ import android.preference.PreferenceScreen; import android.preference.RingtonePreference; import android.preference.SwitchPreference; -import android.support.annotation.NonNull; -import android.support.annotation.RequiresApi; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.LocalBroadcastManager; +import androidx.annotation.NonNull; +import androidx.annotation.RequiresApi; +import androidx.core.app.ActivityCompat; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; import android.text.InputFilter; import android.text.TextUtils; import android.view.Menu; @@ -47,54 +50,67 @@ import com.bytehamster.lib.preferencesearch.SearchPreferenceResult; import com.bytehamster.lib.preferencesearch.SearchPreferenceResultListener; import com.eveningoutpost.dexdrip.BasePreferenceActivity; -import com.eveningoutpost.dexdrip.G5Model.DexSyncKeeper; -import com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine; import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.DesertSync; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Profile; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Models.UserError.ExtraLogTags; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.Models.UserNotification; import com.eveningoutpost.dexdrip.NFCReaderX; import com.eveningoutpost.dexdrip.ParakeetHelper; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.ActivityRecognizedService; -import com.eveningoutpost.dexdrip.Services.BluetoothGlucoseMeter; -import com.eveningoutpost.dexdrip.Services.DexCollectionService; -import com.eveningoutpost.dexdrip.Services.G5BaseService; -import com.eveningoutpost.dexdrip.Services.PlusSyncService; -import com.eveningoutpost.dexdrip.Services.UiBasedCollector; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Experience; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Intents; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.ShotStateStore; -import com.eveningoutpost.dexdrip.UtilityModels.SpeechUtil; -import com.eveningoutpost.dexdrip.UtilityModels.UpdateActivity; -import com.eveningoutpost.dexdrip.UtilityModels.WholeHouse; -import com.eveningoutpost.dexdrip.UtilityModels.pebble.PebbleUtil; -import com.eveningoutpost.dexdrip.UtilityModels.pebble.PebbleWatchSync; -import com.eveningoutpost.dexdrip.UtilityModels.pebble.watchface.InstallPebbleClassicTrendWatchface; -import com.eveningoutpost.dexdrip.UtilityModels.pebble.watchface.InstallPebbleSnoozeControlApp; -import com.eveningoutpost.dexdrip.UtilityModels.pebble.watchface.InstallPebbleTrendClayWatchFace; -import com.eveningoutpost.dexdrip.UtilityModels.pebble.watchface.InstallPebbleTrendWatchFace; -import com.eveningoutpost.dexdrip.UtilityModels.pebble.watchface.InstallPebbleWatchFace; import com.eveningoutpost.dexdrip.WidgetUpdateService; +import com.eveningoutpost.dexdrip.alert.Registry; import com.eveningoutpost.dexdrip.calibrations.PluggableCalibration; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.CareLinkFollowService; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth.CareLinkAuthType; import com.eveningoutpost.dexdrip.cgm.nsfollow.NightscoutFollow; import com.eveningoutpost.dexdrip.cgm.sharefollow.ShareFollowService; import com.eveningoutpost.dexdrip.cgm.webfollow.Cpref; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth.CareLinkAuthenticator; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.auth.CareLinkCredentialStore; +import com.eveningoutpost.dexdrip.g5model.DexSyncKeeper; +import com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine; +import com.eveningoutpost.dexdrip.healthconnect.HealthConnectEntry; +import com.eveningoutpost.dexdrip.healthconnect.HealthGamut; import com.eveningoutpost.dexdrip.insulin.inpen.InPenEntry; +import com.eveningoutpost.dexdrip.models.DesertSync; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Profile; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.UserError.ExtraLogTags; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserNotification; +import com.eveningoutpost.dexdrip.plugin.Dialog; import com.eveningoutpost.dexdrip.profileeditor.ProfileEditor; +import com.eveningoutpost.dexdrip.receiver.InfoContentProvider; +import com.eveningoutpost.dexdrip.services.ActivityRecognizedService; +import com.eveningoutpost.dexdrip.services.BluetoothGlucoseMeter; +import com.eveningoutpost.dexdrip.services.DexCollectionService; +import com.eveningoutpost.dexdrip.services.G5BaseService; +import com.eveningoutpost.dexdrip.services.Ob1G5CollectionService; +import com.eveningoutpost.dexdrip.services.PlusSyncService; +import com.eveningoutpost.dexdrip.services.UiBasedCollector; +import com.eveningoutpost.dexdrip.services.broadcastservice.BroadcastService; +import com.eveningoutpost.dexdrip.tidepool.AuthFlowOut; import com.eveningoutpost.dexdrip.tidepool.TidepoolUploader; import com.eveningoutpost.dexdrip.tidepool.UploadChunk; import com.eveningoutpost.dexdrip.ui.LockScreenWallPaper; +import com.eveningoutpost.dexdrip.ui.dialog.GenericConfirmDialog; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Experience; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Intents; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.ShotStateStore; +import com.eveningoutpost.dexdrip.utilitymodels.SpeechUtil; +import com.eveningoutpost.dexdrip.utilitymodels.UpdateActivity; +import com.eveningoutpost.dexdrip.utilitymodels.WholeHouse; +import com.eveningoutpost.dexdrip.utilitymodels.pebble.PebbleUtil; +import com.eveningoutpost.dexdrip.utilitymodels.pebble.PebbleWatchSync; +import com.eveningoutpost.dexdrip.utilitymodels.pebble.watchface.InstallPebbleClassicTrendWatchface; +import com.eveningoutpost.dexdrip.utilitymodels.pebble.watchface.InstallPebbleSnoozeControlApp; +import com.eveningoutpost.dexdrip.utilitymodels.pebble.watchface.InstallPebbleTrendClayWatchFace; +import com.eveningoutpost.dexdrip.utilitymodels.pebble.watchface.InstallPebbleTrendWatchFace; +import com.eveningoutpost.dexdrip.utilitymodels.pebble.watchface.InstallPebbleWatchFace; import com.eveningoutpost.dexdrip.utils.framework.IncomingCallsReceiver; import com.eveningoutpost.dexdrip.watch.lefun.LeFunEntry; import com.eveningoutpost.dexdrip.watch.miband.MiBand; @@ -104,7 +120,6 @@ import com.eveningoutpost.dexdrip.watch.thinjam.BlueJayAdapter; import com.eveningoutpost.dexdrip.watch.thinjam.BlueJayEntry; import com.eveningoutpost.dexdrip.wearintegration.Amazfitservice; -import com.eveningoutpost.dexdrip.Services.broadcastservice.BroadcastService; import com.eveningoutpost.dexdrip.wearintegration.WatchUpdaterService; import com.eveningoutpost.dexdrip.webservices.XdripWebService; import com.eveningoutpost.dexdrip.xDripWidget; @@ -119,13 +134,13 @@ import java.net.URI; import java.text.DecimalFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import lombok.RequiredArgsConstructor; import lombok.Setter; - -import static com.eveningoutpost.dexdrip.xdrip.gs; +import lombok.val; /** * A {@link PreferenceActivity} that presents a set of application settings. On @@ -247,7 +262,7 @@ public void run() { private void installxDripPlusPreferencesFromQRCode(SharedPreferences prefs, String data) { Log.d(TAG, "installing preferences from QRcode"); try { - Map prefsmap = DisplayQRCode.decodeString(data); + Map prefsmap = QRcodeUtils.decodeString(data); if (prefsmap != null) { if (prefsmap.containsKey(getString(R.string.all_settings_wizard))) { if (prefsmap.containsKey(getString(R.string.wizard_key)) @@ -261,31 +276,38 @@ private void installxDripPlusPreferencesFromQRCode(SharedPreferences prefs, Stri return; } - final SharedPreferences.Editor editor = prefs.edit(); - int changes = 0; - for (Map.Entry entry : prefsmap.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - // Log.d(TAG, "Saving preferences: " + key + " = " + value); - if (value.equals("true") || (value.equals("false"))) { - editor.putBoolean(key, Boolean.parseBoolean(value)); - changes++; - } else if (!value.equals("null")) { - editor.putString(key, value); - changes++; + val sb = getMapKeysString(prefsmap); + val msg = getString(R.string.import_qr_code_warning) + sb; + + GenericConfirmDialog.show(this, gs(R.string.are_you_sure), msg, () -> { + final SharedPreferences.Editor editor = prefs.edit(); + int changes = 0; + for (Map.Entry entry : prefsmap.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + // Log.d(TAG, "Saving preferences: " + key + " = " + value); + if (value.equals("true") || (value.equals("false"))) { + editor.putBoolean(key, Boolean.parseBoolean(value)); + changes++; + } else if (!value.equals("null")) { + editor.putString(key, value); + changes++; + } } - } - editor.apply(); - refreshFragments(); - ExtraLogTags.readPreference(Pref.getStringDefaultBlank("extra_tags_for_logging")); - Toast.makeText(getApplicationContext(), "Loaded " + Integer.toString(changes) + " preferences from QR code", Toast.LENGTH_LONG).show(); - PlusSyncService.clearandRestartSyncService(getApplicationContext()); - DesertSync.settingsChanged(); // refresh - if (prefs.getString("dex_collection_method", "").equals("Follower")) { + editor.apply(); + refreshFragments(); + ExtraLogTags.readPreference(Pref.getStringDefaultBlank("extra_tags_for_logging")); + Toast.makeText(getApplicationContext(), "Loaded " + Integer.toString(changes) + " preferences from QR code", Toast.LENGTH_LONG).show(); PlusSyncService.clearandRestartSyncService(getApplicationContext()); - GcmActivity.last_sync_request = 0; - GcmActivity.requestBGsync(); - } + DesertSync.settingsChanged(); // refresh + InfoContentProvider.ping("pref"); + if (prefs.getString("dex_collection_method", "").equals("Follower")) { + PlusSyncService.clearandRestartSyncService(getApplicationContext()); + GcmActivity.last_sync_request = 0; + GcmActivity.requestBGsync(); + } + }); + } else { android.util.Log.e(TAG, "Got null prefsmap during decode"); } @@ -295,6 +317,18 @@ private void installxDripPlusPreferencesFromQRCode(SharedPreferences prefs, Stri } + public static String getMapKeysString(final Map prefsmap) { + val sb = new StringBuilder(); + val keysSet = prefsmap.keySet(); + val keyList = new ArrayList<>(keysSet); + Collections.sort(keyList); + for (val entry : keyList) { + sb.append(entry); + sb.append("\n"); + } + return sb.toString(); + } + public static Boolean getBooleanPreferenceViaContextWithoutException(Context context, String key, Boolean defaultValue) { try { @@ -308,6 +342,17 @@ public static Boolean getBooleanPreferenceViaContextWithoutException(Context con @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == Constants.HEALTH_CONNECT_RESPONSE_ID) { + if (HealthConnectEntry.enabled()) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (JoH.ratelimit("health-connect-bump", 2)) { + HealthGamut.init(this); + } + } + } + } + + IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (scanResult == null || scanResult.getContents() == null) { @@ -316,7 +361,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { if (scanResult.getFormatName().equals("QR_CODE")) { final String scanresults = scanResult.getContents(); - if (scanresults.startsWith(DisplayQRCode.qrmarker)) { + if (QRcodeUtils.hasDecoderMarker(scanresults)) { installxDripPlusPreferencesFromQRCode(prefs, scanresults); return; } @@ -475,6 +520,7 @@ protected void onResume() PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(BroadcastService.prefListener); PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(BlueJayEntry.prefListener); PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(uiPrefListener); + PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(Registry.prefListener); LocalBroadcastManager.getInstance(this).registerReceiver(mibandStatusReceiver, new IntentFilter(Intents.PREFERENCE_INTENT)); } @@ -489,6 +535,7 @@ protected void onPause() PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(BroadcastService.prefListener); PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(BlueJayEntry.prefListener); PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(uiPrefListener); + PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(Registry.prefListener); LocalBroadcastManager.getInstance(this).unregisterReceiver(mibandStatusReceiver); pFragment = null; super.onPause(); @@ -1094,24 +1141,6 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { // } - findPreference("use_ob1_g5_collector_service").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - new Thread(new Runnable() { - @Override - public void run() { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - // - } - CollectionServiceStarter.restartCollectionService(xdrip.getAppContext()); - } - }).start(); - - return true; - } - }); final Preference profile_carb_absorption_default = findPreference("profile_carb_absorption_default"); profile_carb_absorption_default.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @@ -1196,18 +1225,44 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { final Preference tidepoolTestLogin = findPreference("tidepool_test_login"); tidepoolTestLogin.setOnPreferenceClickListener(preference -> { - Inevitable.task("tidepool-upload", 200, TidepoolUploader::doLoginFromUi); + if (Pref.getBooleanDefaultFalse("tidepool_new_auth")) { + Inevitable.task("tidepool-upload", 200, AuthFlowOut::doTidePoolInitialLogin); + } else { + Inevitable.task("tidepool-upload", 200, TidepoolUploader::doLoginFromUi); + } return false; }); - final Preference tidePoolType = findPreference("tidepool_dev_servers"); - tidePoolType.setOnPreferenceChangeListener((preference, newValue) -> { + try { + final Preference tidePoolType = findPreference("tidepool_dev_servers"); + tidePoolType.setOnPreferenceChangeListener((preference, newValue) -> { TidepoolUploader.resetInstance(); return true; - }); + }); + findPreference("tidepool_username") + .setOnPreferenceChangeListener((preference, newValue) -> { + TidepoolUploader.resetInstance(); + if (!newValue.equals(Pref.getStringDefaultBlank("tidepool_username"))) { + Pref.setString("tidepool_username", (String) newValue); + AuthFlowOut.doTidePoolInitialLogin(true); + } + return true; + }); + findPreference("tidepool_password") + .setOnPreferenceChangeListener((preference, newValue) -> { + TidepoolUploader.resetInstance(); + AuthFlowOut.doTidePoolInitialLogin(true); + return true; + }); + } catch (Exception e) { + UserError.Log.e(TAG,"Could not attach listener for tidepool prefs: " + e); + } - final Preference nsFollowDownload = findPreference("nsfollow_download_treatments"); + + final Preference nsFollowDownload = findPreference("nsfollow_download_treatments_screen"); final Preference nsFollowUrl = findPreference("nsfollow_url"); + final Preference nsFollowLag = findPreference("nsfollow_lag"); // Show the Nightscout follow wake delay setting only when NS follow is the data source + bindPreferenceSummaryToValue(findPreference("nsfollow_lag")); // Show the selected value as summary try { nsFollowUrl.setOnPreferenceChangeListener((preference, newValue) -> { NightscoutFollow.resetInstance(); @@ -1257,6 +1312,101 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { } } + //CareLink Follow preferences + //final Preference carelinkFollowUser = findPreference("clfollow_user"); + //final Preference carelinkFollowPass = findPreference("clfollow_pass"); + final Preference carelinkFollowCountry = findPreference("clfollow_country"); + final Preference carelinkFollowPatient = findPreference("clfollow_patient"); + final Preference carelinkFollowLogin = findPreference("clfollow_login"); + final Preference carelinkFollowGracePeriod = findPreference("clfollow_grace_period"); + final Preference carelinkFollowMissedPollInterval = findPreference("clfollow_missed_poll_interval"); + final Preference carelinkFollowDownloadFingerBGs = findPreference("clfollow_download_finger_bgs"); + final Preference carelinkFollowDownloadBoluses = findPreference("clfollow_download_boluses"); + final Preference carelinkFollowDownloadMeals = findPreference("clfollow_download_meals"); + final Preference carelinkFollowDownloadNotifications = findPreference("clfollow_download_notifications"); + //Add CL prefs for CLFollower + if (collectionType == DexCollectionType.CLFollow) { + //Add CL prefs + //collectionCategory.addPreference(carelinkFollowUser); + //collectionCategory.addPreference(carelinkFollowPass); + collectionCategory.addPreference(carelinkFollowCountry); + collectionCategory.addPreference(carelinkFollowPatient); + collectionCategory.addPreference(carelinkFollowLogin); + collectionCategory.addPreference(carelinkFollowGracePeriod); + collectionCategory.addPreference(carelinkFollowMissedPollInterval); + collectionCategory.addPreference(carelinkFollowDownloadFingerBGs); + collectionCategory.addPreference(carelinkFollowDownloadBoluses); + collectionCategory.addPreference(carelinkFollowDownloadMeals); + collectionCategory.addPreference(carelinkFollowDownloadNotifications); + //Create prefChange handler + final Preference.OnPreferenceChangeListener carelinkFollowListener = new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + CareLinkFollowService.resetInstanceAndInvalidateSession(); + CollectionServiceStarter.restartCollectionServiceBackground(); + return true; + } + }; + //Pref click handler for Login + final Preference.OnPreferenceClickListener carelinkLoginListener = new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + new Thread() { + public void run() { + try { + String country = Pref.getString("clfollow_country", "").toLowerCase(); + if (country.equals("")) { + JoH.static_toast(preference.getContext(), xdrip.gs(R.string.carelink_auth_country_required), Toast.LENGTH_LONG); + } else { + CareLinkAuthenticator authenticator = new CareLinkAuthenticator(country, CareLinkCredentialStore.getInstance()); + if (authenticator.authenticate(getActivity(), CareLinkAuthType.MobileApp)) { + JoH.static_toast(preference.getContext(), xdrip.gs(R.string.carelink_auth_status_authenticated), Toast.LENGTH_LONG); + CareLinkFollowService.resetInstanceAndInvalidateSession(); + CollectionServiceStarter.restartCollectionServiceBackground(); + } + else { + JoH.static_toast(preference.getContext(), xdrip.gs(R.string.carelink_auth_status_not_authenticated), Toast.LENGTH_LONG); + } + } + } catch (InterruptedException e) { + + } + } + }.start(); + + return true; + } + }; + //Register preference handlers + try { + //carelinkFollowUser.setOnPreferenceChangeListener(carelinkFollowListener); + //carelinkFollowPass.setOnPreferenceChangeListener(carelinkFollowListener); + carelinkFollowCountry.setOnPreferenceChangeListener(carelinkFollowListener); + carelinkFollowPatient.setOnPreferenceChangeListener(carelinkFollowListener); + carelinkFollowLogin.setOnPreferenceClickListener(carelinkLoginListener); + //carelinkFollowGracePeriod.setOnPreferenceChangeListener(carelinkFollowListener); + //carelinkFollowMissedPollInterval.setOnPreferenceChangeListener(carelinkFollowListener); + } catch (Exception e) { + // + } + //Remove CL prefs for NON CLFollower + } else { + try { + //collectionCategory.removePreference(carelinkFollowUser); + //collectionCategory.removePreference(carelinkFollowPass); + collectionCategory.removePreference(carelinkFollowCountry); + collectionCategory.removePreference(carelinkFollowPatient); + collectionCategory.removePreference(carelinkFollowLogin); + collectionCategory.removePreference(carelinkFollowGracePeriod); + collectionCategory.removePreference(carelinkFollowMissedPollInterval); + collectionCategory.removePreference(carelinkFollowDownloadFingerBGs); + collectionCategory.removePreference(carelinkFollowDownloadBoluses); + collectionCategory.removePreference(carelinkFollowDownloadMeals); + collectionCategory.removePreference(carelinkFollowDownloadNotifications); + } catch (Exception e) { + // + } + } final Preference inpen_enabled = findPreference("inpen_enabled"); try { @@ -1578,6 +1728,34 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { try { collectionCategory.removePreference(nsFollowUrl); collectionCategory.removePreference(nsFollowDownload); + collectionCategory.removePreference(nsFollowLag); + } catch (Exception e) { + // + } + } + + if (getBestCollectorHardwareName().equals("G7")) { // Remove battery options, from G5/G6/Dex1/G7 Debug Settings, if we are using G7 or One+ + try { + PreferenceScreen screen = (PreferenceScreen) findPreference("xdrip_plus_g5_extra_settings"); + Preference pref = getPreferenceManager().findPreference("dex_battery_category"); + screen.removePreference(pref); + } catch (Exception e) { + UserError.Log.wtf(TAG, "Failed to remove G7 battery options"); + } + } + + //Remove CL prefs for NON CLFollower + if (collectionType != DexCollectionType.CLFollow) { + try { + collectionCategory.removePreference(carelinkFollowCountry); + collectionCategory.removePreference(carelinkFollowPatient); + //collectionCategory.removePreference(carelinkFollowPass); + //collectionCategory.removePreference(carelinkFollowUser); + collectionCategory.removePreference(carelinkFollowGracePeriod); + collectionCategory.removePreference(carelinkFollowMissedPollInterval); + collectionCategory.removePreference(carelinkFollowDownloadFingerBGs); + collectionCategory.removePreference(carelinkFollowDownloadMeals); + collectionCategory.removePreference(carelinkFollowDownloadNotifications); } catch (Exception e) { // } @@ -1874,6 +2052,29 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { // } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + try { + findPreference("health_connect_enable").setOnPreferenceChangeListener((preference, newValue) -> { + if ((Boolean) newValue) { + Inevitable.task("check-health-connect", 300, () -> HealthGamut.init(getActivity())); + } + return true; + }); + } catch (Exception e) { + // + } + + try { + findPreference("health_connect_manage").setOnPreferenceClickListener((preference) -> { + HealthGamut.init(getActivity()).openPermissionManager(); + return true; + }); + } catch (Exception e) { + // + } + } + + bindPreferenceSummaryToValue(collectionMethod); bindPreferenceSummaryToValue(shareKey); @@ -2133,9 +2334,11 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { transmitterId.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { + val activity = getActivity(); new Thread(new Runnable() { @Override public void run() { + Dialog.askIfNeeded(activity, (String)newValue); try { Thread.sleep(1000); } catch (InterruptedException e) { @@ -2148,6 +2351,7 @@ public void run() { } catch (Exception e) { // } + Ob1G5CollectionService.clearPersist(); CollectionServiceStarter.restartCollectionService(xdrip.getAppContext()); } }).start(); @@ -2240,6 +2444,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { if (collectionType == DexCollectionType.NSFollow) { collectionCategory.addPreference(nsFollowUrl); collectionCategory.addPreference(nsFollowDownload); + collectionCategory.addPreference(nsFollowLag); } @@ -2308,11 +2513,28 @@ public void run() { return true; } }); - + removeLegacyPreferences(); jumpToScreen(jumpTo); } - public static void checkReadPermission(final Activity activity) { + private void removeLegacyPreferences() { + // removePreferenceFromCategory("use_ob1_g5_collector_service", "ob1_options"); + // removePreferenceFromCategory("ob1_g5_fallback_to_xdrip", "ob1_options"); + // removePreferenceFromCategory("always_unbond_G5", "ob1_options"); + // removePreferenceFromCategory("always_get_new_keys", "ob1_options"); + } + + private void removePreferenceFromCategory(final String preference, final String category) { + try { + final Preference pref = findPreference(preference); + final PreferenceGroup cat = (PreferenceGroup) findPreference(category); + cat.removePreference(pref); + } catch (Exception e) { + UserError.Log.e(TAG, "Exception removing preference " + preference + " from " + category + " " + e); + } + } + + public static void checkReadPermission(final Activity activity) { // TODO call log permission - especially for Android 9+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/QRcodeUtils.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/QRcodeUtils.java new file mode 100644 index 0000000000..bfa2c0da14 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/QRcodeUtils.java @@ -0,0 +1,155 @@ +package com.eveningoutpost.dexdrip.utils; + +import static com.eveningoutpost.dexdrip.models.JoH.bytesToHex; +import static com.eveningoutpost.dexdrip.models.JoH.static_toast_long; + +import android.graphics.Bitmap; +import android.graphics.Color; +import android.util.Base64; +import android.util.Log; + +import com.eveningoutpost.dexdrip.models.JoH; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.google.zxing.BarcodeFormat; +import com.google.zxing.EncodeHintType; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.WriterException; + +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.Map; + +import lombok.val; + +/** + * JamOrHam + *

+ * Utils for serializing and deserializing QR codes + */ + +public class QRcodeUtils { + + private static final String TAG = "qrcode utils"; + public static final String qrmarker = "xdpref:"; + private static final String qrmarker2 = "xdp2:"; + + public static boolean hasDecoderMarker(final String scanresults) { + if (scanresults == null) return false; + return scanresults.startsWith(qrmarker) || scanresults.startsWith(qrmarker2); + } + + public static Map decodeString(String data) { + Log.d(TAG, "jamorham qr decode: " + data); + try { + if (data.startsWith(qrmarker)) { + data = data.substring(qrmarker.length()); + Log.d(TAG, "String to uncompress: " + data); + data = JoH.uncompressString(data); + Log.d(TAG, "Json after decompression: " + data); + return new Gson().fromJson(data, new TypeToken>() { + }.getType()); + + } else if (data.startsWith(qrmarker2)) { + data = data.substring(qrmarker2.length()); + Log.d(TAG, "String to uncompress: " + data + " len: " + data.length()); + val bytes = JoH.decompressBytesToBytes(Base64.decode(data, Base64.NO_PADDING | Base64.NO_WRAP)); + Log.d(TAG, "Json after decompression: " + bytes.length); + return deserializeQr2(bytes); + + } else { + Log.e(TAG, "No qrmarker on qrcode"); + return null; + } + } catch (Exception e) { + Log.e(TAG, "Got exception during decodingString: " + e.toString()); + return null; + } + + } + + public static byte[] serializeBinaryPrefsMap(final Map binaryPrefsMap) { + int size = 2; + short count = 0; + for (val item : binaryPrefsMap.entrySet()) { + size += item.getKey().getBytes(StandardCharsets.UTF_8).length; + size += item.getValue().length; + size += 4; + count++; + } + val bb = ByteBuffer.allocate(size); + bb.putShort(count); + for (val item : binaryPrefsMap.entrySet()) { + val key = item.getKey().getBytes(StandardCharsets.UTF_8); + val value = item.getValue(); + bb.putShort((short) key.length); + bb.put(key); + bb.putShort((short) value.length); + bb.put(value); + } + return bb.array(); + } + + + public static Map deserializeQr2(final byte[] bytes) { + if (bytes == null) return null; + val bb = ByteBuffer.wrap(bytes); + val count = bb.getShort(); + if (count < 1 || count > 100) { + val msg = "Count invalid on QR Code " + count; + Log.e(TAG, msg); + static_toast_long(msg); + return null; + } + Log.d(TAG, "QR code element count: " + count); + val reply = new HashMap(); + try { + for (int i = 0; i < count; i++) { + val keylen = bb.getShort(); + val keyBytes = new byte[keylen]; + bb.get(keyBytes); + val valuelen = bb.getShort(); + val valueBytes = new byte[valuelen]; + bb.get(valueBytes); + String keyString = new String(keyBytes, StandardCharsets.UTF_8); + boolean isBinary = false; + if (keyString.startsWith("b__")) { + keyString = keyString.substring(3); + isBinary = true; + } + Log.d(TAG, "KEY: " + keyString + " byte length: " + valuelen); + if (isBinary) { + reply.put(keyString, bytesToHex(valueBytes)); + } else { + reply.put(keyString, new String(valueBytes, StandardCharsets.UTF_8)); + } + } + return reply; + + } catch (Exception e) { + val msg = "QR code decoding error: " + e; + Log.e(TAG, msg); + static_toast_long(msg); + } + return null; + } + + public static Bitmap createQRCodeBitmap(final byte[] data, final int width, final int height) throws WriterException { + val inputData = qrmarker2 + Base64.encodeToString(data, Base64.NO_WRAP | Base64.NO_PADDING); + Log.d(TAG, "Input data length: " + inputData.length()); + Map hints = new EnumMap<>(EncodeHintType.class); + hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); + val multiFormatWriter = new MultiFormatWriter(); + val bitMatrix = multiFormatWriter.encode(inputData, BarcodeFormat.QR_CODE, width, height, hints); + val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); + for (int i = 0; i < width; i++) { + for (int j = 0; j < height; j++) { + bitmap.setPixel(i, j, bitMatrix.get(i, j) ? Color.BLACK : Color.WHITE); + } + } + return bitmap; + } + +} diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/Root.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/Root.java index 917fb813e6..55a47f1514 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/Root.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/Root.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.utils; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.WholeHouse; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.WholeHouse; import java.io.DataOutputStream; import java.io.IOException; @@ -15,7 +15,7 @@ public class Root { private static final String TAG = "RootTools"; - private static Boolean gotRoot; + public static Boolean gotRoot; public static boolean gotRoot() { if (gotRoot == null) { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/SMS.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/SMS.java index a61c2c72bb..b91ddcce16 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/SMS.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/SMS.java @@ -4,7 +4,7 @@ import android.telephony.SmsManager; import android.telephony.TelephonyManager; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.xdrip; import java.util.ArrayList; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/SdcardImportExport.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/SdcardImportExport.java index 509057b582..6b527a8583 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/SdcardImportExport.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/SdcardImportExport.java @@ -8,8 +8,8 @@ import android.os.Build; import android.os.Bundle; import android.os.Environment; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; import android.util.Log; import android.view.View; import android.widget.Toast; @@ -17,10 +17,10 @@ import com.eveningoutpost.dexdrip.BaseAppCompatActivity; import com.eveningoutpost.dexdrip.GcmActivity; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.AlertType; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.AlertType; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.xdrip; import java.io.File; @@ -31,6 +31,7 @@ import java.util.ArrayList; import java.util.List; +import static com.eveningoutpost.dexdrip.receiver.InfoContentProvider.ping; import static com.eveningoutpost.dexdrip.utils.FileUtils.getExternalDir; @@ -162,6 +163,7 @@ public void loadPreferencesToSD(View myview) { public static void storePreferencesFromBytes(byte[] bytes, Context context) { if (dataFromBytes(bytes, PREFERENCES_FILE, context)) { + ping("pref"); Log.i(TAG, "Restarting as new preferences loaded from bytes"); hardReset(); } else { @@ -291,6 +293,7 @@ public static void restoreSettingsNow(Activity activity) { JoH.static_toast_long("Restoring Settings"); if (copyPreferencesFileBack(activity, results.get(0))) { Log.e(TAG, "Restoring preferences succeeded from first match: " + results.get(0)); + ping("pref"); hardReset(); } else { JoH.static_toast_long("Couldn't restore preferences from: " + results.get(0)); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/SqliteRejigger.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/SqliteRejigger.java index 68452d7ab7..a816399acb 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/SqliteRejigger.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/SqliteRejigger.java @@ -7,7 +7,7 @@ import android.database.sqlite.SQLiteDatabase; import com.activeandroid.Cache; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import lombok.NonNull; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/Telemetry.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/Telemetry.java index d2178c2a6e..d8fc169f64 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/Telemetry.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/Telemetry.java @@ -3,16 +3,16 @@ import android.preference.PreferenceManager; import android.util.Log; -import com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine; +import com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; import com.eveningoutpost.dexdrip.NFCReaderX; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.stats.StatsResult; import com.eveningoutpost.dexdrip.xdrip; -import static com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService.getTransmitterID; +import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.getTransmitterID; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.DexcomG5; //import com.crashlytics.android.answers.Answers; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/UniqueId.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/UniqueId.java index a5e08692b7..c97728ec50 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/UniqueId.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/UniqueId.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.utils; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; /** * JamOrHam diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/BtReconnect.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/BtReconnect.java index d73fca4a21..05ddf0631b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/BtReconnect.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/BtReconnect.java @@ -9,9 +9,9 @@ import android.os.Build; import android.os.Handler; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.xdrip; import java.lang.reflect.Method; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/ConnectReceiver.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/ConnectReceiver.java index 78ccdde2dc..b8af43871d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/ConnectReceiver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/ConnectReceiver.java @@ -5,7 +5,7 @@ import android.content.Context; import android.content.Intent; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/HandleBleScanException.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/HandleBleScanException.java index 990988c084..756c939927 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/HandleBleScanException.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/HandleBleScanException.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.utils.bt; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import java.util.Date; import java.util.Locale; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/Mimeograph.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/Mimeograph.java index 085173fdba..fba2b77ab2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/Mimeograph.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/Mimeograph.java @@ -1,11 +1,11 @@ package com.eveningoutpost.dexdrip.utils.bt; import com.eveningoutpost.dexdrip.GcmActivity; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.WholeHouse; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.services.Ob1G5CollectionService; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.WholeHouse; import com.eveningoutpost.dexdrip.utils.CipherUtils; import com.eveningoutpost.dexdrip.utils.Root; import com.eveningoutpost.dexdrip.xdrip; @@ -22,7 +22,7 @@ import lombok.RequiredArgsConstructor; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; import static com.eveningoutpost.dexdrip.utils.bt.Mimeograph.SearchState.COPY_COLLISION_KEY; import static com.eveningoutpost.dexdrip.utils.bt.Mimeograph.SearchState.COPY_DEVICE_KEY; import static com.eveningoutpost.dexdrip.utils.bt.Mimeograph.SearchState.COPY_SCAN; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/ScanMeister.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/ScanMeister.java index 57a2850b09..a476d00d35 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/ScanMeister.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/ScanMeister.java @@ -5,11 +5,11 @@ import android.os.ParcelUuid; import android.os.PowerManager; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.RxBleProvider; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.RxBleProvider; import com.eveningoutpost.dexdrip.utils.BtCallBack; import com.eveningoutpost.dexdrip.xdrip; import com.polidea.rxandroidble2.RxBleClient; @@ -29,7 +29,7 @@ import io.reactivex.schedulers.Schedulers; import lombok.NoArgsConstructor; -import static com.eveningoutpost.dexdrip.Models.JoH.ratelimit; +import static com.eveningoutpost.dexdrip.models.JoH.ratelimit; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/ScanRecordImplCompatLocal.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/ScanRecordImplCompatLocal.java index b8cfb3d179..4b46fa34e1 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/ScanRecordImplCompatLocal.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/ScanRecordImplCompatLocal.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.utils.bt; import android.os.ParcelUuid; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import android.util.SparseArray; import com.polidea.rxandroidble2.scan.ScanRecord; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/Subscription.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/Subscription.java index a53b6f7159..b0280e346b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/Subscription.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/bt/Subscription.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.utils.bt; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.UndeliverableException; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/BuggySamsung.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/BuggySamsung.java index a1267d017e..697f0b4d30 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/BuggySamsung.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/BuggySamsung.java @@ -2,15 +2,15 @@ import android.os.Build; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; import lombok.Getter; import lombok.RequiredArgsConstructor; -import static com.eveningoutpost.dexdrip.Models.JoH.buggy_samsung; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.buggy_samsung; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; /** * jamorham @@ -42,7 +42,7 @@ public long evaluate(final long wakeup_time) { if (wakeup_jitter > 1000) { UserError.Log.d(TAG, "Wake up, time jitter: " + JoH.niceTimeScalar(wakeup_jitter)); if ((wakeup_jitter > TOLERABLE_JITTER) && (!buggy_samsung) && isSamsung()) { - UserError.Log.wtf(TAG, "Enabled Buggy Samsung workaround due to jitter of: " + JoH.niceTimeScalar(wakeup_jitter)); + UserError.Log.wtf(TAG, "Enabled wake workaround due to jitter of: " + JoH.niceTimeScalar(wakeup_jitter)); buggy_samsung = true; PersistentStore.incrementLong(BUGGY_SAMSUNG_ENABLED); max_wakeup_jitter = 0; @@ -61,13 +61,17 @@ public long evaluate(final long wakeup_time) { // enable if we have historic markers showing previous enabling public void checkWasBuggy() { if (!buggy_samsung && isSamsung() && PersistentStore.getLong(BUGGY_SAMSUNG_ENABLED) > 4) { - UserError.Log.e(TAG, "Enabling buggy samsung due to persistent metric"); + UserError.Log.e(TAG, "Enabling wake workaround due to persistent metric"); buggy_samsung = true; } } public static boolean isSamsung() { - return Build.MANUFACTURER.toLowerCase().contains("samsung"); + return Build.MANUFACTURER.toLowerCase().contains("samsung") + || Build.MANUFACTURER.toLowerCase().contains("xiaomi") + || Build.MANUFACTURER.toLowerCase().contains("oneplus") // experimental test + || Build.MANUFACTURER.toLowerCase().contains("oppo") // experimental test + || Build.MANUFACTURER.toLowerCase().contains("huawei"); // experimental test } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/ForegroundService.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/ForegroundService.java index 5c3c220c37..53d0a9d488 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/ForegroundService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/ForegroundService.java @@ -4,10 +4,10 @@ import android.app.Service; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.ForegroundServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.ForegroundServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; public abstract class ForegroundService extends Service { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/IncomingCallsReceiver.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/IncomingCallsReceiver.java index e3b64f592b..0d4a54a9c3 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/IncomingCallsReceiver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/IncomingCallsReceiver.java @@ -13,14 +13,14 @@ import android.net.Uri; import android.os.Build; import android.provider.ContactsContract; -import android.support.v4.app.ActivityCompat; +import androidx.core.app.ActivityCompat; import android.telephony.PhoneNumberUtils; import android.telephony.TelephonyManager; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; import com.eveningoutpost.dexdrip.watch.lefun.LeFun; import com.eveningoutpost.dexdrip.watch.lefun.LeFunEntry; import com.eveningoutpost.dexdrip.watch.miband.MiBand; @@ -33,7 +33,6 @@ import static com.eveningoutpost.dexdrip.watch.miband.Const.MIBAND_NOTIFY_TYPE_CALL; import static com.eveningoutpost.dexdrip.watch.miband.Const.MIBAND_NOTIFY_TYPE_CANCEL; import static com.eveningoutpost.dexdrip.watch.thinjam.Const.THINJAM_NOTIFY_TYPE_CALL; -import static com.eveningoutpost.dexdrip.watch.thinjam.Const.THINJAM_NOTIFY_TYPE_CANCEL; public class IncomingCallsReceiver extends BroadcastReceiver { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/TestKot.kt b/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/TestKot.kt new file mode 100644 index 0000000000..cea3705586 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/TestKot.kt @@ -0,0 +1,18 @@ +package com.eveningoutpost.dexdrip.utils.framework + +/** + * JamOrHam + * + * Simple test to ensure compilation success + */ + +class TestKot { + + companion object { + @JvmStatic + fun compileOkay() : Boolean { + return true; + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/WakeLockTrampoline.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/WakeLockTrampoline.java index 3dd5565233..1c34b46c51 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/WakeLockTrampoline.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/framework/WakeLockTrampoline.java @@ -9,9 +9,9 @@ import android.util.SparseArray; import com.eveningoutpost.dexdrip.BuildConfig; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.ForegroundServiceStarter; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.ForegroundServiceStarter; import com.eveningoutpost.dexdrip.xdrip; import java.util.HashMap; @@ -64,7 +64,7 @@ public void onReceive(final Context context, final Intent broadcastIntent) { ComponentName startResult; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O - && BuildConfig.targetSDK >= Build.VERSION_CODES.N + // && BuildConfig.targetSDK >= Build.VERSION_CODES.N && ForegroundServiceStarter.shouldRunCollectorInForeground()) { try { UserError.Log.d(TAG, String.format("Starting oreo foreground service: %s", serviceIntent.getComponent().getClassName())); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/jobs/BackgroundQueue.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/jobs/BackgroundQueue.java index 413967f42f..751e216df7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/jobs/BackgroundQueue.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/jobs/BackgroundQueue.java @@ -9,8 +9,8 @@ import androidx.annotation.NonNull; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import lombok.val; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/jobs/DailyJob.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/jobs/DailyJob.java index 91f59f2edb..77a57976b7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/jobs/DailyJob.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/jobs/DailyJob.java @@ -1,11 +1,11 @@ package com.eveningoutpost.dexdrip.utils.jobs; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.Services.DailyIntentService; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.services.DailyIntentService; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import com.evernote.android.job.Job; import com.evernote.android.job.JobRequest; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/jobs/XDripJobCreator.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/jobs/XDripJobCreator.java index 08e5f99e36..9087f206f1 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/jobs/XDripJobCreator.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/jobs/XDripJobCreator.java @@ -1,10 +1,10 @@ package com.eveningoutpost.dexdrip.utils.jobs; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.evernote.android.job.Job; import com.evernote.android.job.JobCreator; import com.evernote.android.job.JobManager; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java index 07569e5298..cfe540dd6b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/math/BlockFinder.java @@ -1,6 +1,8 @@ package com.eveningoutpost.dexdrip.utils.math; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; + import java.util.LinkedList; import java.util.List; import java.util.Random; @@ -33,9 +35,14 @@ public String toString() { } public Block set(final int top, final int bottom) { - if (top < 0 || bottom < 0) return null; - this.top = top; - this.bottom = bottom; + if (top < 0 || bottom < 0) + { + this.top = 0; + this.bottom = 0; + } else { + this.top = top; + this.bottom = bottom; + } return this; } } @@ -69,31 +76,47 @@ public Block addBlockWithMerge(int top, int bottom) { return b; } + // TODO this could be a bit smarter public int findRandomAvailablePositionWithFailSafe(final int height, final int maxHeight) { - val pos = findRandomAvailablePosition(height, maxHeight); - if (pos < 0) { - return new Random().nextInt(maxHeight - height); - } else { - return pos; + boolean useTop, useTopCenter, useCenter, useCenterBottom, useBottom; + final int sectionSize = maxHeight / 5; + + try { + useTop = Pref.getBooleanDefaultFalse("aod_use_top"); + useTopCenter = Pref.getBooleanDefaultFalse("aod_use_top_center"); + useCenter = Pref.getBooleanDefaultFalse("aod_use_center"); + useCenterBottom = Pref.getBooleanDefaultFalse("aod_use_center_bottom"); + useBottom = Pref.getBooleanDefaultFalse("aod_use_bottom"); + } catch (NullPointerException e) { + useTop = useTopCenter = useCenter = useCenterBottom = useBottom = true; } - } - // TODO this could be a bit smarter - public int findRandomAvailablePosition(final int height, final int maxHeight) { + if (!(useTop || useTopCenter || useCenter || useCenterBottom || useBottom)) + { + useTop = useTopCenter = useCenter = useCenterBottom = useBottom = true; + } final int bound = maxHeight - height; - if (bound < 1) return -2; - - int tries = 200; - val random = new Random(); - while (tries-- > 0) { - val pos = random.nextInt(bound); - if (findOverlappingBlock(pos, pos + height) == null) { - return pos; + if (bound >= 1) { + int tries = 200; + val random = new Random(); + + while (tries-- > 0) { + int pos = random.nextInt(bound); + if (findOverlappingBlock(pos, pos + height) == null) { + if ((pos <= sectionSize && useTop) + || (pos >= sectionSize && pos <= 2 * sectionSize && useTopCenter) + || (pos >= 2 * sectionSize && pos <= 3 * sectionSize && useCenter) + || (pos >= 3 * sectionSize && pos <= 4 * sectionSize && useCenterBottom) + || (pos >= 4 * sectionSize && useBottom)) { + return pos; + } + } } } - return -1; + // FailSafe + return new Random().nextInt(bound); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/time/SlidingWindowConstraint.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/time/SlidingWindowConstraint.java index 8a222c8d69..55d2cbe9b6 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/time/SlidingWindowConstraint.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/time/SlidingWindowConstraint.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.utils.time; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -10,7 +10,7 @@ import lombok.RequiredArgsConstructor; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; /** * Created by jamorham on 14/02/2018. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/time/TimeRangeUtils.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/time/TimeRangeUtils.java index 0df5434623..85b84f1187 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/time/TimeRangeUtils.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/time/TimeRangeUtils.java @@ -6,14 +6,14 @@ import android.text.format.DateFormat; import android.util.Pair; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.xdrip; import java.text.SimpleDateFormat; import java.util.Calendar; -import static com.eveningoutpost.dexdrip.Models.JoH.tolerantParseInt; +import static com.eveningoutpost.dexdrip.models.JoH.tolerantParseInt; public class TimeRangeUtils { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/usb/MtpTools.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/usb/MtpTools.java index 0943b87f3a..ad2b80cf66 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/usb/MtpTools.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/usb/MtpTools.java @@ -9,11 +9,11 @@ import android.mtp.MtpObjectInfo; import android.os.Build; import android.os.ParcelFileDescriptor; -import android.support.annotation.RequiresApi; +import androidx.annotation.RequiresApi; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; import com.eveningoutpost.dexdrip.utils.CipherUtils; import com.eveningoutpost.dexdrip.xdrip; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/usb/UsbTools.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/usb/UsbTools.java index 29d4ea996f..a19090e94d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/usb/UsbTools.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/usb/UsbTools.java @@ -8,7 +8,7 @@ import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbManager; -import com.eveningoutpost.dexdrip.Models.UserError.Log; +import com.eveningoutpost.dexdrip.models.UserError.Log; import com.eveningoutpost.dexdrip.xdrip; import java.util.HashMap; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/PrefBinding.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/PrefBinding.java index 24d826b133..716a77c5e2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/PrefBinding.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/PrefBinding.java @@ -4,7 +4,7 @@ import android.util.Pair; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/PrefBindingFactory.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/PrefBindingFactory.java index 1dc7e66633..6e58ff46f8 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/PrefBindingFactory.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/PrefBindingFactory.java @@ -1,6 +1,8 @@ package com.eveningoutpost.dexdrip.watch; -import android.support.v4.util.ArrayMap; + + +import androidx.collection.ArrayMap; import java.util.Map; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/FindNearby.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/FindNearby.java index 7ec6d39a38..375768dfe2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/FindNearby.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/FindNearby.java @@ -2,7 +2,7 @@ // jamorham -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.utils.BtCallBack; import com.eveningoutpost.dexdrip.utils.bt.ScanMeister; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/FunAlmanac.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/FunAlmanac.java index 23d80629e9..1c2ca81af8 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/FunAlmanac.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/FunAlmanac.java @@ -2,8 +2,7 @@ // jamorham -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; import java.util.Calendar; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/LeFun.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/LeFun.java index d9f3a1e76a..027487a57b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/LeFun.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/LeFun.java @@ -1,9 +1,9 @@ package com.eveningoutpost.dexdrip.watch.lefun; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; /** * Jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/LeFunEntry.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/LeFunEntry.java index f9745a885b..7f13a2739f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/LeFunEntry.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/LeFunEntry.java @@ -2,9 +2,9 @@ import android.content.SharedPreferences; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/LeFunService.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/LeFunService.java index 55043dce55..dc5f261f41 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/LeFunService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/LeFunService.java @@ -6,16 +6,16 @@ import android.os.PowerManager; import android.util.Pair; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; +import com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; import com.eveningoutpost.dexdrip.store.FastStore; import com.eveningoutpost.dexdrip.store.KeyStore; import com.eveningoutpost.dexdrip.utils.framework.IncomingCallsReceiver; @@ -44,16 +44,16 @@ import io.reactivex.schedulers.Schedulers; -import static com.eveningoutpost.dexdrip.Models.ActiveBgAlert.currentlyAlerting; -import static com.eveningoutpost.dexdrip.Models.JoH.bytesToHex; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; -import static com.eveningoutpost.dexdrip.Models.JoH.msTill; -import static com.eveningoutpost.dexdrip.Models.JoH.niceTimeScalar; -import static com.eveningoutpost.dexdrip.Models.JoH.roundDouble; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.CLOSE; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.DISCOVER; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.INIT; -import static com.eveningoutpost.dexdrip.UtilityModels.Unitized.mmolConvert; +import static com.eveningoutpost.dexdrip.models.ActiveBgAlert.currentlyAlerting; +import static com.eveningoutpost.dexdrip.models.JoH.bytesToHex; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.msTill; +import static com.eveningoutpost.dexdrip.models.JoH.niceTimeScalar; +import static com.eveningoutpost.dexdrip.models.JoH.roundDouble; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.CLOSE; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.DISCOVER; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.INIT; +import static com.eveningoutpost.dexdrip.utilitymodels.Unitized.mmolConvert; import static com.eveningoutpost.dexdrip.watch.lefun.Const.REPLY_CHARACTERISTIC; import static com.eveningoutpost.dexdrip.watch.lefun.Const.WRITE_CHARACTERISTIC; import static com.eveningoutpost.dexdrip.watch.lefun.LeFun.shakeToSnooze; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/ModelFeatures.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/ModelFeatures.java index d0c390f7b3..eaff802778 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/ModelFeatures.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/ModelFeatures.java @@ -2,7 +2,7 @@ // jamorham -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; public class ModelFeatures { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/messages/BaseTx.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/messages/BaseTx.java index 2f1a891ee8..8bed34980f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/messages/BaseTx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/lefun/messages/BaseTx.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.watch.lefun.messages; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; import java.nio.ByteBuffer; import java.util.LinkedList; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/FindNearby.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/FindNearby.java index a1d23cafca..932eaa1a9b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/FindNearby.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/FindNearby.java @@ -4,7 +4,7 @@ import android.os.Bundle; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.utils.bt.BtCallBack2; import com.eveningoutpost.dexdrip.utils.bt.ScanMeister; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/Firmware/FirmwareOperations.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/Firmware/FirmwareOperations.java index 88f466489b..b55fcf7556 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/Firmware/FirmwareOperations.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/Firmware/FirmwareOperations.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.watch.miband.Firmware; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.watch.miband.Const; import java.io.ByteArrayOutputStream; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/Firmware/WatchFaceGenerator.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/Firmware/WatchFaceGenerator.java index fe2c156e2d..8aeb140cc6 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/Firmware/WatchFaceGenerator.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/Firmware/WatchFaceGenerator.java @@ -10,11 +10,11 @@ import android.graphics.Typeface; import com.eveningoutpost.dexdrip.BestGlucose; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import com.eveningoutpost.dexdrip.watch.miband.Firmware.WatchFaceParts.Header; import com.eveningoutpost.dexdrip.watch.miband.Firmware.WatchFaceParts.Image; import com.eveningoutpost.dexdrip.watch.miband.Firmware.WatchFaceParts.Parameter; @@ -33,8 +33,8 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; -import static com.eveningoutpost.dexdrip.Models.JoH.hourMinuteString; -import static com.eveningoutpost.dexdrip.Models.JoH.threadSleep; +import static com.eveningoutpost.dexdrip.models.JoH.hourMinuteString; +import static com.eveningoutpost.dexdrip.models.JoH.threadSleep; import static com.eveningoutpost.dexdrip.utils.FileUtils.getExternalDir; import static com.eveningoutpost.dexdrip.utils.FileUtils.makeSureDirectoryExists; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/Firmware/WatchFaceParts/Image.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/Firmware/WatchFaceParts/Image.java index 1158aa1efb..6c01d69286 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/Firmware/WatchFaceParts/Image.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/Firmware/WatchFaceParts/Image.java @@ -3,7 +3,7 @@ import android.graphics.Bitmap; import android.graphics.Color; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.watch.miband.Firmware.WatchFaceGenerator; import com.eveningoutpost.dexdrip.watch.miband.Firmware.WatchFaceParts.Utils.PnnQuantizer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/Firmware/WatchFaceParts/Utils/BgMibandSparklineBuilder.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/Firmware/WatchFaceParts/Utils/BgMibandSparklineBuilder.java index c2890b5ea3..ab0ea42cd7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/Firmware/WatchFaceParts/Utils/BgMibandSparklineBuilder.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/Firmware/WatchFaceParts/Utils/BgMibandSparklineBuilder.java @@ -3,9 +3,8 @@ import android.content.Context; import android.graphics.Bitmap; -import com.eveningoutpost.dexdrip.UtilityModels.BgSparklineBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.HPointValue; +import com.eveningoutpost.dexdrip.utilitymodels.BgSparklineBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import java.util.ArrayList; import java.util.List; @@ -99,8 +98,8 @@ public Bitmap build() { chart.setBackgroundColor(backgroundColor); chart.setLineChartData(lineData); Viewport viewport = chart.getMaximumViewport(); - viewport.left = HPointValue.convert(start); - viewport.right = HPointValue.convert(end); + viewport.left = start; + viewport.right = end; if (height <= SCALE_TRIGGER) { viewport.bottom = 0; viewport.top = (float) (bgGraphBuilder.doMgdl ? 16 * Constants.MMOLL_TO_MGDL : 16); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/FunAlmanac.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/FunAlmanac.java index 3bc3725f92..cf831edbfa 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/FunAlmanac.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/FunAlmanac.java @@ -1,14 +1,14 @@ package com.eveningoutpost.dexdrip.watch.miband; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Unitized; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Unitized; import java.util.Calendar; import lombok.AllArgsConstructor; -import static com.eveningoutpost.dexdrip.Models.JoH.roundDouble; -import static com.eveningoutpost.dexdrip.UtilityModels.Unitized.mmolConvert; +import static com.eveningoutpost.dexdrip.models.JoH.roundDouble; +import static com.eveningoutpost.dexdrip.utilitymodels.Unitized.mmolConvert; public class FunAlmanac { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/MiBand.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/MiBand.java index 923fc812d9..2f5e56f842 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/MiBand.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/MiBand.java @@ -1,9 +1,9 @@ package com.eveningoutpost.dexdrip.watch.miband; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import static com.eveningoutpost.dexdrip.watch.miband.Const.MIBAND_NAME_2; import static com.eveningoutpost.dexdrip.watch.miband.Const.MIBAND_NAME_3; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/MiBandEntry.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/MiBandEntry.java index a40693d2d5..754439f5d9 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/MiBandEntry.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/MiBandEntry.java @@ -3,14 +3,14 @@ import android.content.Intent; import android.content.SharedPreferences; import android.preference.Preference; -import android.support.v4.content.LocalBroadcastManager; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Intents; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Intents; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.xdrip; import java.util.Date; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/MiBandService.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/MiBandService.java index dc8348f021..9feced5a02 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/MiBandService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/MiBandService.java @@ -8,17 +8,17 @@ import android.os.PowerManager; import android.util.Pair; -import com.eveningoutpost.dexdrip.Models.ActiveBgAlert; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.HeartRate; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.ActiveBgAlert; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.HeartRate; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; +import com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; import com.eveningoutpost.dexdrip.utils.bt.Subscription; import com.eveningoutpost.dexdrip.utils.framework.PoorMansConcurrentLinkedDeque; import com.eveningoutpost.dexdrip.utils.framework.WakeLockTrampoline; @@ -53,15 +53,15 @@ import io.reactivex.schedulers.Schedulers; import lombok.Getter; -import static com.eveningoutpost.dexdrip.Models.JoH.bytesToHex; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; -import static com.eveningoutpost.dexdrip.Models.JoH.getResourceURI; -import static com.eveningoutpost.dexdrip.Models.JoH.msTill; -import static com.eveningoutpost.dexdrip.Models.JoH.niceTimeScalar; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.CLOSE; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.CLOSED; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.INIT; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.SLEEP; +import static com.eveningoutpost.dexdrip.models.JoH.bytesToHex; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.getResourceURI; +import static com.eveningoutpost.dexdrip.models.JoH.msTill; +import static com.eveningoutpost.dexdrip.models.JoH.niceTimeScalar; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.CLOSE; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.CLOSED; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.INIT; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.SLEEP; import static com.eveningoutpost.dexdrip.watch.miband.Const.MIBAND_NOTIFY_TYPE_ALARM; import static com.eveningoutpost.dexdrip.watch.miband.Const.MIBAND_NOTIFY_TYPE_CALL; import static com.eveningoutpost.dexdrip.watch.miband.Const.MIBAND_NOTIFY_TYPE_CANCEL; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/message/AuthMessages.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/message/AuthMessages.java index 599da1a11b..90e8065c76 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/message/AuthMessages.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/miband/message/AuthMessages.java @@ -2,9 +2,9 @@ import android.os.Environment; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.utils.CipherUtils; import com.eveningoutpost.dexdrip.watch.miband.Const; import com.eveningoutpost.dexdrip.watch.miband.MiBand; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BackgroundScanReceiver.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BackgroundScanReceiver.java index a9d3123a8c..ee0821228b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BackgroundScanReceiver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BackgroundScanReceiver.java @@ -5,10 +5,10 @@ import android.content.Context; import android.content.Intent; import android.os.Build; -import android.support.annotation.RequiresApi; +import androidx.annotation.RequiresApi; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.RxBleProvider; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.RxBleProvider; import com.eveningoutpost.dexdrip.utils.bt.BtCallBack2; import com.eveningoutpost.dexdrip.xdrip; import com.polidea.rxandroidble2.exceptions.BleScanException; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJay.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJay.java index 45a06891cd..f9c64fcd4f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJay.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJay.java @@ -1,17 +1,17 @@ package com.eveningoutpost.dexdrip.watch.thinjam; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.StatusLine; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusLine; import com.eveningoutpost.dexdrip.ui.activities.ThinJamActivity; import java.util.Arrays; import lombok.val; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; import static com.eveningoutpost.dexdrip.watch.thinjam.BlueJayEntry.isEnabled; import static com.eveningoutpost.dexdrip.watch.thinjam.BlueJayInfo.getInfo; import static com.eveningoutpost.dexdrip.watch.thinjam.Const.FEATURE_TJ_AUDIO_I; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayAPI.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayAPI.java index 79ce3fce6c..0e355e716d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayAPI.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayAPI.java @@ -2,7 +2,7 @@ // jamorham -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import static com.eveningoutpost.dexdrip.watch.thinjam.Const.THINJAM_NOTIFY_TYPE_DIALOG; import static com.eveningoutpost.dexdrip.watch.thinjam.Const.THINJAM_NOTIFY_TYPE_OTHER_ALERT; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayAdapter.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayAdapter.java index e4f544ff23..dbd54c6358 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayAdapter.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayAdapter.java @@ -4,9 +4,9 @@ import android.preference.Preference; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.xdrip; public class BlueJayAdapter { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayAsset.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayAsset.java index 2a1d0c8a20..0a35b24546 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayAsset.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayAsset.java @@ -1,10 +1,10 @@ package com.eveningoutpost.dexdrip.watch.thinjam; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor; import com.eveningoutpost.dexdrip.watch.thinjam.messages.BaseTx; import com.eveningoutpost.dexdrip.watch.thinjam.messages.DefineWindowTx; @@ -13,8 +13,8 @@ import lombok.val; -import static com.eveningoutpost.dexdrip.Models.JoH.bytesToHex; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.bytesToHex; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; import static com.eveningoutpost.dexdrip.watch.thinjam.assets.AssetDownload.getAsset; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayEmit.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayEmit.java index b90964d3cf..27ebbc504f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayEmit.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayEmit.java @@ -4,12 +4,12 @@ import android.content.Intent; -import com.eveningoutpost.dexdrip.UtilityModels.Intents; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Intents; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import lombok.val; -import static com.eveningoutpost.dexdrip.Models.JoH.tsl; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; import static com.eveningoutpost.dexdrip.xdrip.getAppContext; public class BlueJayEmit { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayEntry.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayEntry.java index cbf56f898d..053c4dbf06 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayEntry.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayEntry.java @@ -1,11 +1,12 @@ package com.eveningoutpost.dexdrip.watch.thinjam; import android.content.SharedPreferences; +import android.os.Build; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import lombok.val; @@ -124,6 +125,10 @@ public static void sendPngIfEnabled(final byte[] bytes, final String parameters, } } + public static boolean isNative() { + return Build.MODEL.startsWith("BlueJay U"); + } + static void startWithRefresh() { Inevitable.task("bluejay-preference-changed", 1000, () -> JoH.startService(BlueJayService.class, "function", "refresh")); } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayInfo.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayInfo.java index f634a54079..22bd4a4b31 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayInfo.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayInfo.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip.watch.thinjam; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; import com.eveningoutpost.dexdrip.watch.thinjam.messages.BaseTx; import com.eveningoutpost.dexdrip.watch.thinjam.messages.PushRx; import com.eveningoutpost.dexdrip.watch.thinjam.messages.SetTimeTx; @@ -13,7 +13,7 @@ import java.util.HashMap; import java.util.Locale; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; public class BlueJayInfo extends BaseTx { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayRemote.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayRemote.java index 4bfd6a3595..d5b3e96432 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayRemote.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayRemote.java @@ -5,14 +5,14 @@ import android.content.Intent; import com.eveningoutpost.dexdrip.BestGlucose; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Intents; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Intents; import com.eveningoutpost.dexdrip.watch.thinjam.io.ThinJamApiReceiver; import lombok.val; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.MINUTE_IN_MS; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS; import static com.eveningoutpost.dexdrip.xdrip.getAppContext; public class BlueJayRemote { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayService.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayService.java index f4c367dd28..220d483886 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/BlueJayService.java @@ -4,30 +4,30 @@ import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattService; import android.content.Intent; -import android.databinding.ObservableField; +import androidx.databinding.ObservableField; import android.os.Binder; import android.os.IBinder; import android.os.PowerManager; import android.util.Pair; -import com.eveningoutpost.dexdrip.G5Model.CalibrationState; +import com.eveningoutpost.dexdrip.g5model.CalibrationState; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.importedlibraries.usbserial.util.HexDump; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer; -import com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; -import com.eveningoutpost.dexdrip.UtilityModels.BroadcastSnooze; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.StatusItem; -import com.eveningoutpost.dexdrip.UtilityModels.Unitized; +import com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer; +import com.eveningoutpost.dexdrip.services.Ob1G5CollectionService; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.BroadcastSnooze; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusItem; +import com.eveningoutpost.dexdrip.utilitymodels.Unitized; import com.eveningoutpost.dexdrip.ui.activities.ThinJamActivity; import com.eveningoutpost.dexdrip.utils.BytesGenerator; import com.eveningoutpost.dexdrip.utils.bt.Helper; @@ -76,27 +76,27 @@ import lombok.Setter; import lombok.val; -import static com.eveningoutpost.dexdrip.Models.JoH.bytesToHex; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.Models.JoH.msTill; -import static com.eveningoutpost.dexdrip.Models.JoH.niceTimeScalar; -import static com.eveningoutpost.dexdrip.Models.JoH.threadSleep; -import static com.eveningoutpost.dexdrip.Models.JoH.tsl; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.CLOSE; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.CLOSED; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.DISCOVER; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.INIT; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.SEND_QUEUE; -import static com.eveningoutpost.dexdrip.Services.JamBaseBluetoothSequencer.BaseState.SLEEP; -import static com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder.DEXCOM_PERIOD; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.HOUR_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.MINUTE_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.SECOND_IN_MS; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.BAD; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.CRITICAL; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.GOOD; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.NORMAL; -import static com.eveningoutpost.dexdrip.UtilityModels.StatusItem.Highlight.NOTICE; +import static com.eveningoutpost.dexdrip.models.JoH.bytesToHex; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.models.JoH.msTill; +import static com.eveningoutpost.dexdrip.models.JoH.niceTimeScalar; +import static com.eveningoutpost.dexdrip.models.JoH.threadSleep; +import static com.eveningoutpost.dexdrip.models.JoH.tsl; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.CLOSE; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.CLOSED; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.DISCOVER; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.INIT; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.SEND_QUEUE; +import static com.eveningoutpost.dexdrip.services.JamBaseBluetoothSequencer.BaseState.SLEEP; +import static com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder.DEXCOM_PERIOD; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.HOUR_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.SECOND_IN_MS; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.BAD; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.CRITICAL; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.GOOD; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.NORMAL; +import static com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight.NOTICE; import static com.eveningoutpost.dexdrip.watch.thinjam.BlueJay.shouldSendReadings; import static com.eveningoutpost.dexdrip.watch.thinjam.BlueJay.versionSufficient; import static com.eveningoutpost.dexdrip.watch.thinjam.BlueJayService.ThinJamState.ENABLE_NOTIFICATIONS; @@ -120,7 +120,6 @@ import static com.eveningoutpost.dexdrip.watch.thinjam.Const.OPCODE_RESET_ALL; import static com.eveningoutpost.dexdrip.watch.thinjam.Const.OPCODE_SHOW_QRCODE; import static com.eveningoutpost.dexdrip.watch.thinjam.Const.THINJAM_BULK; -import static com.eveningoutpost.dexdrip.watch.thinjam.Const.THINJAM_NOTIFY_TYPE_CALL; import static com.eveningoutpost.dexdrip.watch.thinjam.Const.THINJAM_NOTIFY_TYPE_CANCEL; import static com.eveningoutpost.dexdrip.watch.thinjam.Const.THINJAM_NOTIFY_TYPE_DIALOG; import static com.eveningoutpost.dexdrip.watch.thinjam.Const.THINJAM_NOTIFY_TYPE_HIGH_ALERT; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/DebugUnitTestLogger.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/DebugUnitTestLogger.java index fa25d44c30..24f939e42b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/DebugUnitTestLogger.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/DebugUnitTestLogger.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip.watch.thinjam; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; import com.eveningoutpost.dexdrip.watch.thinjam.io.GetURL; import lombok.RequiredArgsConstructor; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/assets/AssetDownload.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/assets/AssetDownload.java index 1f84b070b1..386ef9ccc5 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/assets/AssetDownload.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/assets/AssetDownload.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.watch.thinjam.assets; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.eveningoutpost.dexdrip.watch.thinjam.io.GetURL; import java.util.Locale; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/assets/AssetPackage.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/assets/AssetPackage.java index 13fb98b066..d608dfbbb8 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/assets/AssetPackage.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/assets/AssetPackage.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.watch.thinjam.assets; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/assets/DigitalSignature.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/assets/DigitalSignature.java index a7685725eb..991f5aab40 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/assets/DigitalSignature.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/assets/DigitalSignature.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.watch.thinjam.assets; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import java.security.KeyFactory; import java.security.PublicKey; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/BlueJayFirmware.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/BlueJayFirmware.java index aa4694a146..dfcb6de772 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/BlueJayFirmware.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/BlueJayFirmware.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.watch.thinjam.firmware; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.utils.CipherUtils; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/BlueJayFwId.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/BlueJayFwId.java index f0c812da53..05aefbe3a4 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/BlueJayFwId.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/BlueJayFwId.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.watch.thinjam.firmware; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/BlueJayManifest.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/BlueJayManifest.java index d1efb9121f..bd16d6f078 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/BlueJayManifest.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/BlueJayManifest.java @@ -2,8 +2,8 @@ // jamorham -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.google.gson.JsonSyntaxException; import com.google.gson.annotations.Expose; import com.google.gson.reflect.TypeToken; @@ -12,7 +12,7 @@ import java.util.ArrayList; import java.util.List; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; public class BlueJayManifest { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/DigitalSignature.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/DigitalSignature.java index f5843f347e..fafffecee7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/DigitalSignature.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/DigitalSignature.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.watch.thinjam.firmware; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import java.security.KeyFactory; import java.security.PublicKey; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/FirmwareDownload.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/FirmwareDownload.java index 8b2cbdc6c8..001889b3aa 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/FirmwareDownload.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/FirmwareDownload.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip.watch.thinjam.firmware; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; import com.eveningoutpost.dexdrip.watch.thinjam.BlueJay; import com.eveningoutpost.dexdrip.watch.thinjam.BlueJayInfo; import com.eveningoutpost.dexdrip.watch.thinjam.io.GetURL; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/FirmwareInfo.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/FirmwareInfo.java index f9b0816b5a..1bed9dc020 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/FirmwareInfo.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/firmware/FirmwareInfo.java @@ -2,9 +2,9 @@ // jamorham -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; import com.eveningoutpost.dexdrip.watch.thinjam.BlueJay; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/io/GetURL.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/io/GetURL.java index 05bcbe72fa..a82b573f35 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/io/GetURL.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/io/GetURL.java @@ -8,7 +8,7 @@ import okhttp3.Request; import okhttp3.Response; -import static com.eveningoutpost.dexdrip.UtilityModels.OkHttpWrapper.enableTls12OnPreLollipop; +import static com.eveningoutpost.dexdrip.utilitymodels.OkHttpWrapper.enableTls12OnPreLollipop; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/io/ThinJamApiReceiver.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/io/ThinJamApiReceiver.java index 84b7d82861..c02e75f7e6 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/io/ThinJamApiReceiver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/io/ThinJamApiReceiver.java @@ -7,14 +7,14 @@ import android.content.Intent; import android.os.PowerManager; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.watch.thinjam.BlueJayAPI; import lombok.val; -import static com.eveningoutpost.dexdrip.Models.JoH.emptyString; -import static com.eveningoutpost.dexdrip.UtilityModels.Intents.BLUEJAY_THINJAM_API; +import static com.eveningoutpost.dexdrip.models.JoH.emptyString; +import static com.eveningoutpost.dexdrip.utilitymodels.Intents.BLUEJAY_THINJAM_API; public class ThinJamApiReceiver extends BroadcastReceiver { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/AuthReqTx.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/AuthReqTx.java index c0a9a1df47..6ad3dd799f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/AuthReqTx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/AuthReqTx.java @@ -2,8 +2,8 @@ import android.annotation.SuppressLint; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.watch.thinjam.BlueJay; import java.util.Arrays; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/BaseTx.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/BaseTx.java index 3125edd4b8..1726624718 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/BaseTx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/BaseTx.java @@ -2,7 +2,7 @@ // jamorham -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/GlucoseTx.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/GlucoseTx.java index 4e738a4fbe..43ef17fede 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/GlucoseTx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/GlucoseTx.java @@ -1,14 +1,14 @@ package com.eveningoutpost.dexdrip.watch.thinjam.messages; import com.eveningoutpost.dexdrip.BestGlucose; -import com.eveningoutpost.dexdrip.G5Model.CalibrationState; -import com.eveningoutpost.dexdrip.Models.BgReading; +import com.eveningoutpost.dexdrip.g5model.CalibrationState; +import com.eveningoutpost.dexdrip.models.BgReading; import lombok.Getter; import lombok.val; -import static com.eveningoutpost.dexdrip.Models.JoH.msSince; -import static com.eveningoutpost.dexdrip.UtilityModels.Constants.MINUTE_IN_MS; +import static com.eveningoutpost.dexdrip.models.JoH.msSince; +import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS; import static com.eveningoutpost.dexdrip.watch.thinjam.Const.OPCODE_INBOUND_GLUCOSE; // jamorham diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/NotifyTx.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/NotifyTx.java index 121369de5c..870ef6c0f7 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/NotifyTx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/NotifyTx.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.watch.thinjam.messages; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import java.io.UnsupportedEncodingException; import java.util.ArrayList; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/PushRx.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/PushRx.java index ae9083398d..c35a23c32d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/PushRx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/PushRx.java @@ -2,9 +2,9 @@ import android.util.SparseArray; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Unitized; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Unitized; import com.eveningoutpost.dexdrip.watch.thinjam.Const; import com.google.gson.annotations.Expose; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/SetTimeTx.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/SetTimeTx.java index 6f839491c0..4554408493 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/SetTimeTx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/SetTimeTx.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.watch.thinjam.messages; -import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.models.JoH; import com.google.gson.annotations.Expose; import java.nio.ByteBuffer; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/SetTxIdTx.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/SetTxIdTx.java index ee7c086e7a..5aba52c0ea 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/SetTxIdTx.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/messages/SetTxIdTx.java @@ -1,9 +1,9 @@ package com.eveningoutpost.dexdrip.watch.thinjam.messages; -import com.eveningoutpost.dexdrip.Models.AlertType; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.Unitized; +import com.eveningoutpost.dexdrip.models.AlertType; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.Unitized; import com.eveningoutpost.dexdrip.watch.thinjam.BlueJay; import com.eveningoutpost.dexdrip.xdrip; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/utils/BitmapTools.java b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/utils/BitmapTools.java index 12be462f4e..91431bb8c1 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/utils/BitmapTools.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/watch/thinjam/utils/BitmapTools.java @@ -3,7 +3,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import java.io.FileInputStream; import java.io.FileNotFoundException; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/Amazfitservice.java b/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/Amazfitservice.java index 76ec6a9ccd..6214bd4a5d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/Amazfitservice.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/Amazfitservice.java @@ -11,26 +11,26 @@ import android.os.Build; import android.os.IBinder; import android.preference.PreferenceManager; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import android.util.Base64; import android.util.Log; import com.eveningoutpost.dexdrip.BestGlucose; -import com.eveningoutpost.dexdrip.G5Model.Extensions; -import com.eveningoutpost.dexdrip.G5Model.Transmitter; -import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants; -import com.eveningoutpost.dexdrip.Models.ActiveBgAlert; -import com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice; -import com.eveningoutpost.dexdrip.Models.HeartRate; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.StepCounter; -import com.eveningoutpost.dexdrip.Models.TransmitterData; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.BgSparklineBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.g5model.Extensions; +import com.eveningoutpost.dexdrip.g5model.Transmitter; +import com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants; +import com.eveningoutpost.dexdrip.models.ActiveBgAlert; +import com.eveningoutpost.dexdrip.models.ActiveBluetoothDevice; +import com.eveningoutpost.dexdrip.models.HeartRate; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.StepCounter; +import com.eveningoutpost.dexdrip.models.TransmitterData; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.BgSparklineBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.PowerStateReceiver; import com.eveningoutpost.dexdrip.xdrip; import com.huami.watch.transport.DataBundle; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/ExternalStatusBroadcastReceiver.java b/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/ExternalStatusBroadcastReceiver.java index 69a64968c3..dcef39d9bc 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/ExternalStatusBroadcastReceiver.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/ExternalStatusBroadcastReceiver.java @@ -2,10 +2,12 @@ import android.content.Context; import android.content.Intent; -import android.support.v4.content.WakefulBroadcastReceiver; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; + +import androidx.legacy.content.WakefulBroadcastReceiver; + +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; /** * Created by adrian on 14/02/16. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/ExternalStatusService.java b/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/ExternalStatusService.java index 9e95d81bf3..da06596e8a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/ExternalStatusService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/ExternalStatusService.java @@ -2,17 +2,17 @@ import android.app.IntentService; import android.content.Intent; -import android.support.annotation.NonNull; -import android.support.v4.content.WakefulBroadcastReceiver; +import androidx.annotation.NonNull; +import androidx.legacy.content.WakefulBroadcastReceiver; -import com.eveningoutpost.dexdrip.Models.APStatus; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; + +import com.eveningoutpost.dexdrip.models.APStatus; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.NewDataObserver; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; -import java.util.regex.Matcher; import java.util.regex.Pattern; import lombok.val; @@ -27,7 +27,7 @@ public class ExternalStatusService extends IntentService { private static final String EXTRA_STATUSLINE = "com.eveningoutpost.dexdrip.Extras.Statusline"; public static final String ACTION_NEW_EXTERNAL_STATUSLINE = "com.eveningoutpost.dexdrip.ExternalStatusline"; //public static final String RECEIVER_PERMISSION = "com.eveningoutpost.dexdrip.permissions.RECEIVE_EXTERNAL_STATUSLINE"; - private static final int MAX_LEN = 40; + private static final int MAX_LEN = 70; private final static String TAG = ExternalStatusService.class.getSimpleName(); public ExternalStatusService() { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/SendToDataLayerThread.java b/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/SendToDataLayerThread.java index 9cc4c41ebc..c08dcd3373 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/SendToDataLayerThread.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/SendToDataLayerThread.java @@ -4,8 +4,8 @@ import android.util.Log; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.wearable.DataApi; import com.google.android.gms.wearable.DataMap; @@ -16,7 +16,6 @@ import com.google.android.gms.wearable.Wearable; import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; /** diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/WatchUpdaterService.java b/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/WatchUpdaterService.java index 5287294200..ed61e7baf2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/WatchUpdaterService.java @@ -10,43 +10,43 @@ import android.os.Bundle; import android.os.PowerManager; import android.preference.PreferenceManager; -import android.support.v4.content.LocalBroadcastManager; + import android.util.Log; import android.widget.Toast; import com.eveningoutpost.dexdrip.BestGlucose; import com.eveningoutpost.dexdrip.BuildConfig; -import com.eveningoutpost.dexdrip.G5Model.CalibrationState; -import com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine; +import com.eveningoutpost.dexdrip.g5model.CalibrationState; +import com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice; -import com.eveningoutpost.dexdrip.Models.AlertType; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.BloodTest; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.HeartRate; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.StepCounter; -import com.eveningoutpost.dexdrip.Models.TransmitterData; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.ActiveBluetoothDevice; +import com.eveningoutpost.dexdrip.models.AlertType; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.BloodTest; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.HeartRate; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.StepCounter; +import com.eveningoutpost.dexdrip.models.TransmitterData; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.Services.G5CollectionService; -import com.eveningoutpost.dexdrip.Services.Ob1G5CollectionService; -import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.BgSendQueue; -import com.eveningoutpost.dexdrip.UtilityModels.Blukon; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Inevitable; -import com.eveningoutpost.dexdrip.UtilityModels.LowPriorityThread; -import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.StatusLine; -import com.eveningoutpost.dexdrip.UtilityModels.WearSyncBooleans; -import com.eveningoutpost.dexdrip.UtilityModels.WearSyncPersistentStrings; +import com.eveningoutpost.dexdrip.services.G5CollectionService; +import com.eveningoutpost.dexdrip.services.Ob1G5CollectionService; +import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.BgSendQueue; +import com.eveningoutpost.dexdrip.utilitymodels.Blukon; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Inevitable; +import com.eveningoutpost.dexdrip.utilitymodels.LowPriorityThread; +import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusLine; +import com.eveningoutpost.dexdrip.utilitymodels.WearSyncBooleans; +import com.eveningoutpost.dexdrip.utilitymodels.WearSyncPersistentStrings; import com.eveningoutpost.dexdrip.utils.CheckBridgeBattery; import com.eveningoutpost.dexdrip.utils.DexCollectionType; import com.eveningoutpost.dexdrip.utils.GetWearApk; @@ -87,9 +87,11 @@ import java.util.Set; import java.util.concurrent.TimeUnit; -import static com.eveningoutpost.dexdrip.G5Model.Ob1G5StateMachine.PREF_QUEUE_DRAINED; -import static com.eveningoutpost.dexdrip.Models.JoH.showNotification; -import static com.eveningoutpost.dexdrip.Models.JoH.ts; +import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.PREF_QUEUE_DRAINED; +import static com.eveningoutpost.dexdrip.models.JoH.showNotification; +import static com.eveningoutpost.dexdrip.models.JoH.ts; + +import androidx.localbroadcastmanager.content.LocalBroadcastManager; @SuppressLint("LogNotTimber") public class WatchUpdaterService extends WearableListenerService implements diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebLibre2ConnectCode.java b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebLibre2ConnectCode.java index d148c99c16..f70ef752c1 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebLibre2ConnectCode.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebLibre2ConnectCode.java @@ -3,10 +3,10 @@ import android.util.Base64; import android.util.Log; -import com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice; -import com.eveningoutpost.dexdrip.Models.LibreOOPAlgorithm; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Intents; +import com.eveningoutpost.dexdrip.models.ActiveBluetoothDevice; +import com.eveningoutpost.dexdrip.models.LibreOOPAlgorithm; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Intents; import org.json.JSONException; import org.json.JSONObject; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebResponse.java b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebResponse.java index e36442752c..bd23279f9e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebResponse.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebResponse.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip.webservices; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import java.io.UnsupportedEncodingException; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceHeart.java b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceHeart.java index 021995087e..2285aa7492 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceHeart.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceHeart.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip.webservices; -import com.eveningoutpost.dexdrip.Models.HeartRate; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.HeartRate; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceModule.java b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceModule.java index 7f7d5c14e1..3e99fda121 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceModule.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceModule.java @@ -1,8 +1,6 @@ package com.eveningoutpost.dexdrip.webservices; -import android.util.Log; - -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import javax.inject.Named; import javax.inject.Singleton; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServicePebble.java b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServicePebble.java index afd29319f8..e643277551 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServicePebble.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServicePebble.java @@ -1,16 +1,20 @@ package com.eveningoutpost.dexdrip.webservices; -import android.support.annotation.NonNull; +import android.content.Context; +import android.app.Activity; import android.util.Log; import com.eveningoutpost.dexdrip.BestGlucose; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.Calibration; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.Calibration; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.models.Treatments; import com.eveningoutpost.dexdrip.dagger.Injectors; import com.eveningoutpost.dexdrip.ui.MicroStatus; -import com.eveningoutpost.dexdrip.ui.MicroStatusImpl; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.xdrip; + import org.json.JSONArray; import org.json.JSONException; @@ -84,7 +88,12 @@ public WebResponse request(String query) { } bgs.put("battery", microStatus.gs("bestBridgeBattery")); - bgs.put("iob", 0); // TODO get iob + if (!Pref.getBooleanDefaultFalse("enable_iob_in_api_endpoint")) { + bgs.put("iob", 0.0); + } else { + Double iob = Treatments.getCurrentIoB(); + bgs.put("iob", (iob == null) ? "unknown" : String.format("%.02f", iob)); + } // TODO output bwp and bwpo status_array.put(status); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceSgv.java b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceSgv.java index 601bd34419..cd5d990dd3 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceSgv.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceSgv.java @@ -1,17 +1,15 @@ package com.eveningoutpost.dexdrip.webservices; -import android.util.Log; - import androidx.annotation.VisibleForTesting; import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.DateUtil; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.NanoStatus; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.SensorStatus; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.DateUtil; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.NanoStatus; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.SensorStatus; import com.eveningoutpost.dexdrip.dagger.Singleton; import com.eveningoutpost.dexdrip.utils.DexCollectionType; @@ -21,7 +19,6 @@ import java.math.BigDecimal; import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceStatus.java b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceStatus.java index a2fcfe1165..cb92d8a33b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceStatus.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceStatus.java @@ -2,15 +2,15 @@ import android.util.Log; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import org.json.JSONException; import org.json.JSONObject; -import static com.eveningoutpost.dexdrip.Models.JoH.tolerantParseDouble; +import static com.eveningoutpost.dexdrip.models.JoH.tolerantParseDouble; /** * Created by jamorham on 04/02/2018. diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceSteps.java b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceSteps.java index 39342f0f67..6e87be6e81 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceSteps.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceSteps.java @@ -1,8 +1,8 @@ package com.eveningoutpost.dexdrip.webservices; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.StepCounter; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.StepCounter; +import com.eveningoutpost.dexdrip.models.UserError; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceSync.java b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceSync.java index 1b4e6950e1..942ddc082a 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceSync.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceSync.java @@ -1,7 +1,7 @@ package com.eveningoutpost.dexdrip.webservices; -import com.eveningoutpost.dexdrip.Models.DesertSync; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.DesertSync; +import com.eveningoutpost.dexdrip.models.UserError; import java.net.InetAddress; import java.util.List; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceTasker.java b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceTasker.java index 0cfc87a166..9d396384ad 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceTasker.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceTasker.java @@ -2,9 +2,8 @@ import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import com.eveningoutpost.dexdrip.Models.UserError; +import com.eveningoutpost.dexdrip.models.UserError; import com.eveningoutpost.dexdrip.localeTasker.bundle.PluginBundleManager; import com.eveningoutpost.dexdrip.xdrip; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceTreatments.java b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceTreatments.java index d872ea0be6..e9ec886e8e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceTreatments.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/WebServiceTreatments.java @@ -4,30 +4,18 @@ import androidx.annotation.VisibleForTesting; -import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.DateUtil; -import com.eveningoutpost.dexdrip.Models.Treatments; -import com.eveningoutpost.dexdrip.Models.UserError; -import com.eveningoutpost.dexdrip.UtilityModels.NanoStatus; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.SensorStatus; -import com.eveningoutpost.dexdrip.dagger.Singleton; -import com.eveningoutpost.dexdrip.utils.DexCollectionType; +import com.eveningoutpost.dexdrip.models.Treatments; +import com.eveningoutpost.dexdrip.models.UserError; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import java.math.BigDecimal; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; -import static com.eveningoutpost.dexdrip.wearintegration.ExternalStatusService.getLastStatusLine; -import static com.eveningoutpost.dexdrip.wearintegration.ExternalStatusService.getLastStatusLineTime; - /** * Emulates the Nightscout /api/v1/treatments.json endpoint at treatments.json diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/XdripWebService.java b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/XdripWebService.java index bb42fa3b8c..e41146a35f 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/webservices/XdripWebService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/webservices/XdripWebService.java @@ -5,35 +5,33 @@ import android.text.TextUtils; import android.util.Log; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.UserError; import com.eveningoutpost.dexdrip.R; -import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; import com.eveningoutpost.dexdrip.dagger.Singleton; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.UserError; +import com.eveningoutpost.dexdrip.utilitymodels.Constants; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; import com.eveningoutpost.dexdrip.utils.TriState; import com.eveningoutpost.dexdrip.xdrip; import com.google.common.base.Charsets; import com.google.common.hash.Hashing; -import org.apache.commons.lang3.exception.ExceptionUtils; - import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.io.OutputStream; import java.io.PrintStream; import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketException; import java.net.SocketTimeoutException; -import java.net.URLDecoder; -import java.time.format.DateTimeFormatter; -import java.time.ZonedDateTime; import java.time.ZoneOffset; -import java.util.concurrent.atomic.AtomicInteger; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.Locale; +import java.util.concurrent.atomic.AtomicInteger; import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLServerSocketFactory; @@ -220,6 +218,24 @@ public void run() { } } + // Makes \n be \r\n for HTTP specification compliance + static class CRLFPrintStream extends PrintStream { + + public CRLFPrintStream(OutputStream out) { + super(out); + } + + @Override + public void println(String x) { + super.println(x + "\r"); + } + + @Override + public void println() { + println(""); + } + } + /** * Respond to a request from a client. * @@ -229,7 +245,7 @@ public void run() { private void handle(Socket socket) throws IOException { final PowerManager.WakeLock wl = JoH.getWakeLock("webservice-handler", 20000); BufferedReader reader = null; - PrintStream output = null; + CRLFPrintStream output = null; try { socket.setSoTimeout((int) (Constants.SECOND_IN_MS * 10)); try { @@ -291,7 +307,7 @@ private void handle(Socket socket) throws IOException { } // Output stream that we send the response to - output = new PrintStream(socket.getOutputStream()); + output = new CRLFPrintStream(socket.getOutputStream()); // Prepare the content to send. if (null == route) { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/xDripWidget.java b/app/src/main/java/com/eveningoutpost/dexdrip/xDripWidget.java index 758eb0e452..26007ac2b3 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/xDripWidget.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/xDripWidget.java @@ -1,6 +1,6 @@ package com.eveningoutpost.dexdrip; -import static com.eveningoutpost.dexdrip.UtilityModels.ColorCache.getCol; +import static com.eveningoutpost.dexdrip.utilitymodels.ColorCache.getCol; import android.app.PendingIntent; import android.appwidget.AppWidgetManager; @@ -14,15 +14,15 @@ import android.view.View; import android.widget.RemoteViews; -import com.eveningoutpost.dexdrip.Models.BgReading; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Sensor; -import com.eveningoutpost.dexdrip.Models.UserError.Log; -import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.BgSparklineBuilder; -import com.eveningoutpost.dexdrip.UtilityModels.ColorCache; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.StatusLine; +import com.eveningoutpost.dexdrip.models.BgReading; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Sensor; +import com.eveningoutpost.dexdrip.models.UserError.Log; +import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.BgSparklineBuilder; +import com.eveningoutpost.dexdrip.utilitymodels.ColorCache; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.StatusLine; import com.eveningoutpost.dexdrip.calibrations.PluggableCalibration; import java.text.MessageFormat; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/xdrip.java b/app/src/main/java/com/eveningoutpost/dexdrip/xdrip.java index 25c69929bf..0c513b2c1e 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/xdrip.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/xdrip.java @@ -7,30 +7,32 @@ import android.content.res.Configuration; import android.os.Build; import android.preference.PreferenceManager; -import android.support.annotation.StringRes; -import android.support.multidex.MultiDexApplication; +import androidx.annotation.StringRes; import android.util.Log; -import com.eveningoutpost.dexdrip.Models.AlertType; -import com.eveningoutpost.dexdrip.Models.JoH; -import com.eveningoutpost.dexdrip.Models.Reminder; -import com.eveningoutpost.dexdrip.Services.ActivityRecognizedService; -import com.eveningoutpost.dexdrip.Services.BluetoothGlucoseMeter; -import com.eveningoutpost.dexdrip.Services.MissedReadingService; -import com.eveningoutpost.dexdrip.Services.PlusSyncService; -import com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter; -import com.eveningoutpost.dexdrip.UtilityModels.IdempotentMigrations; -import com.eveningoutpost.dexdrip.UtilityModels.PlusAsyncExecutor; -import com.eveningoutpost.dexdrip.UtilityModels.Pref; -import com.eveningoutpost.dexdrip.UtilityModels.VersionTracker; +import com.eveningoutpost.dexdrip.models.AlertType; +import com.eveningoutpost.dexdrip.models.JoH; +import com.eveningoutpost.dexdrip.models.Reminder; +import com.eveningoutpost.dexdrip.alert.Poller; +import com.eveningoutpost.dexdrip.services.ActivityRecognizedService; +import com.eveningoutpost.dexdrip.services.BluetoothGlucoseMeter; +import com.eveningoutpost.dexdrip.services.MissedReadingService; +import com.eveningoutpost.dexdrip.services.PlusSyncService; +import com.eveningoutpost.dexdrip.utilitymodels.CollectionServiceStarter; +import com.eveningoutpost.dexdrip.utilitymodels.ColorCache; +import com.eveningoutpost.dexdrip.utilitymodels.IdempotentMigrations; +import com.eveningoutpost.dexdrip.utilitymodels.PlusAsyncExecutor; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; +import com.eveningoutpost.dexdrip.utilitymodels.VersionTracker; import com.eveningoutpost.dexdrip.calibrations.PluggableCalibration; +import com.eveningoutpost.dexdrip.utils.AppCenterCrashReporting; import com.eveningoutpost.dexdrip.utils.NewRelicCrashReporting; import com.eveningoutpost.dexdrip.utils.jobs.DailyJob; import com.eveningoutpost.dexdrip.utils.jobs.XDripJobCreator; import com.eveningoutpost.dexdrip.watch.lefun.LeFunEntry; import com.eveningoutpost.dexdrip.watch.miband.MiBandEntry; import com.eveningoutpost.dexdrip.watch.thinjam.BlueJayEntry; -import com.eveningoutpost.dexdrip.Services.broadcastservice.BroadcastEntry; +import com.eveningoutpost.dexdrip.services.broadcastservice.BroadcastEntry; import com.eveningoutpost.dexdrip.webservices.XdripWebService; import com.evernote.android.job.JobManager; @@ -44,11 +46,11 @@ * Created by Emma Black on 3/21/15. */ -public class xdrip extends MultiDexApplication { +public class xdrip extends Application { private static final String TAG = "xdrip.java"; @SuppressLint("StaticFieldLeak") - private static Context context; + private static volatile Context context; private static boolean fabricInited = false; private static boolean bfInited = false; private static Locale LOCALE; @@ -56,6 +58,12 @@ public class xdrip extends MultiDexApplication { public static boolean useBF = false; private static Boolean isRunningTestCache; + public static void setContext(final Context context) { + if (context == null) return; + if (xdrip.context == null) { + xdrip.context = context.getApplicationContext(); + } + } @Override public void onCreate() { @@ -64,7 +72,8 @@ public void onCreate() { JodaTimeAndroid.init(this); try { if (PreferenceManager.getDefaultSharedPreferences(xdrip.context).getBoolean("enable_crashlytics", true)) { - NewRelicCrashReporting.start(); + //NewRelicCrashReporting.start(); + AppCenterCrashReporting.start(this); } } catch (Exception e) { Log.e(TAG, e.toString()); @@ -80,6 +89,7 @@ public void onCreate() { PreferenceManager.setDefaultValues(this, R.xml.pref_data_source, true); PreferenceManager.setDefaultValues(this, R.xml.xdrip_plus_defaults, true); PreferenceManager.setDefaultValues(this, R.xml.xdrip_plus_prefs, true); + ColorCache.setDefaultsLoaded(); checkForcedEnglish(xdrip.context); @@ -114,6 +124,7 @@ public void onCreate() { } Reminder.firstInit(xdrip.getAppContext()); PluggableCalibration.invalidateCache(); + Poller.init(); } diff --git a/app/src/main/res/drawable-xhdpi/caresens_air_icon_image.png b/app/src/main/res/drawable-xhdpi/caresens_air_icon_image.png new file mode 100755 index 0000000000..4bb1e6578e Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/caresens_air_icon_image.png differ diff --git a/app/src/main/res/layout/activity_add_calibration.xml b/app/src/main/res/layout/activity_add_calibration.xml index a321d6e5ce..767f3c548e 100644 --- a/app/src/main/res/layout/activity_add_calibration.xml +++ b/app/src/main/res/layout/activity_add_calibration.xml @@ -1,4 +1,4 @@ - @@ -43,5 +43,5 @@ android:layout_gravity="start" android:name="com.eveningoutpost.dexdrip.NavigationDrawerFragment" tools:layout="@layout/fragment_navigation_drawer" /> - + diff --git a/app/src/main/res/layout/activity_add_comparison.xml b/app/src/main/res/layout/activity_add_comparison.xml index f19dc392e9..b577e8cbcb 100644 --- a/app/src/main/res/layout/activity_add_comparison.xml +++ b/app/src/main/res/layout/activity_add_comparison.xml @@ -1,4 +1,4 @@ - @@ -51,5 +51,5 @@ android:layout_gravity="start" android:name="com.eveningoutpost.dexdrip.NavigationDrawerFragment" tools:layout="@layout/fragment_navigation_drawer" /> - + diff --git a/app/src/main/res/layout/activity_alert_list.xml b/app/src/main/res/layout/activity_alert_list.xml index c7ccc4b5ed..b220d1cfb9 100644 --- a/app/src/main/res/layout/activity_alert_list.xml +++ b/app/src/main/res/layout/activity_alert_list.xml @@ -1,4 +1,4 @@ - @@ -68,4 +68,4 @@ android:layout_width="@dimen/navigation_drawer_width" android:layout_height="mat android:layout_gravity="start" android:name="com.eveningoutpost.dexdrip.NavigationDrawerFragment" tools:layout="@layout/fragment_navigation_drawer" /> - + diff --git a/app/src/main/res/layout/activity_backup_picker.xml b/app/src/main/res/layout/activity_backup_picker.xml index 7a112b6f56..129c1a49de 100644 --- a/app/src/main/res/layout/activity_backup_picker.xml +++ b/app/src/main/res/layout/activity_backup_picker.xml @@ -7,7 +7,7 @@ name="vm" type="com.eveningoutpost.dexdrip.cloud.backup.BackupActivity.ViewModel" /> - + + type="com.eveningoutpost.dexdrip.utilitymodels.PrefsViewImpl" /> @@ -80,19 +80,23 @@