diff --git a/app/build.gradle b/app/build.gradle index 732b465487..f1f1afa44f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -177,10 +177,12 @@ dependencies { wearApp project(':wear') implementation project(':core') + implementation project(':combo') implementation project(':database') implementation project(':dana') implementation project(':danars') implementation project(':danar') + implementation project(':insight') implementation project(':rileylink') implementation project(':medtronic') implementation project(':omnipod-common') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1abc55ecfe..a367417120 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -219,8 +219,6 @@ android:exported="false" /> - - - - - @@ -259,13 +243,6 @@ - - - - diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt index 09505d0e18..072e621cdc 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt @@ -138,7 +138,7 @@ class MainActivity : NoSplashAppCompatActivity() { .observeOn(aapsSchedulers.main) .subscribe({ processPreferenceChange(it) }, fabricPrivacy::logException) ) - if (!sp.getBoolean(R.string.key_setupwizard_processed, false) && !isRunningRealPumpTest()) { + if (startWizard() && !isRunningRealPumpTest()) { protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, { startActivity(Intent(this, SetupWizardActivity::class.java)) }) @@ -156,6 +156,9 @@ class MainActivity : NoSplashAppCompatActivity() { if (viewPager.currentItem >= 0) pluginPreferencesMenuItem?.isEnabled = (viewPager.adapter as TabPageAdapter).getPluginAt(viewPager.currentItem).preferencesId != -1 } + private fun startWizard() : Boolean = + !sp.getBoolean(R.string.key_setupwizard_processed, false) + override fun onPostCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) { super.onPostCreate(savedInstanceState, persistentState) actionBarDrawerToggle.syncState() @@ -381,6 +384,7 @@ class MainActivity : NoSplashAppCompatActivity() { FirebaseCrashlytics.getInstance().setCustomKey("Remote", remote) FirebaseCrashlytics.getInstance().setCustomKey("Committed", BuildConfig.COMMITTED) FirebaseCrashlytics.getInstance().setCustomKey("Hash", hashes[0]) + FirebaseCrashlytics.getInstance().setCustomKey("Email", sp.getString(R.string.key_email_for_crash_report, "")) } } diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index ae7a6e4436..9eb8a59a5e 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -46,6 +46,7 @@ import info.nightscout.androidaps.events.EventReloadTreatmentData; import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempTargetChange; import info.nightscout.androidaps.interfaces.ActivePluginProvider; +import info.nightscout.androidaps.interfaces.DatabaseHelperInterface; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.ProfileStore; import info.nightscout.androidaps.logging.AAPSLogger; @@ -54,9 +55,6 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.openhumans.OpenHumansUploader; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData; -import info.nightscout.androidaps.plugins.pump.insight.database.InsightBolusID; -import info.nightscout.androidaps.plugins.pump.insight.database.InsightHistoryOffset; -import info.nightscout.androidaps.plugins.pump.insight.database.InsightPumpID; import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin; import info.nightscout.androidaps.utils.JsonHelper; import info.nightscout.androidaps.utils.PercentageSplitter; @@ -83,9 +81,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { public static final String DATABASE_DBREQUESTS = "DBRequests"; public static final String DATABASE_CAREPORTALEVENTS = "CareportalEvents"; public static final String DATABASE_TDDS = "TDDs"; - public static final String DATABASE_INSIGHT_HISTORY_OFFSETS = "InsightHistoryOffsets"; - public static final String DATABASE_INSIGHT_BOLUS_IDS = "InsightBolusIDs"; - public static final String DATABASE_INSIGHT_PUMP_IDS = "InsightPumpIDs"; public static final String DATABASE_OPEN_HUMANS_QUEUE = "OpenHumansQueue"; private static final int DATABASE_VERSION = 13; @@ -138,10 +133,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, InsightPumpID.class); TableUtils.createTableIfNotExists(connectionSource, OmnipodHistoryRecord.class); TableUtils.createTableIfNotExists(connectionSource, OHQueueItem.class); - database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DATABASE_INSIGHT_BOLUS_IDS + "\", " + System.currentTimeMillis() + " " + - "WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DATABASE_INSIGHT_BOLUS_IDS + "\")"); - database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DATABASE_INSIGHT_PUMP_IDS + "\", " + System.currentTimeMillis() + " " + - "WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DATABASE_INSIGHT_PUMP_IDS + "\")"); + database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_BOLUS_IDS + "\", " + System.currentTimeMillis() + " " + + "WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_BOLUS_IDS + "\")"); + database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_PUMP_IDS + "\", " + System.currentTimeMillis() + " " + + "WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_PUMP_IDS + "\")"); } catch (SQLException e) { aapsLogger.error("Can't create database", e); throw new RuntimeException(e); @@ -169,13 +164,13 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, InsightHistoryOffset.class); TableUtils.createTableIfNotExists(connectionSource, InsightBolusID.class); TableUtils.createTableIfNotExists(connectionSource, InsightPumpID.class); - database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DATABASE_INSIGHT_BOLUS_IDS + "\", " + System.currentTimeMillis() + " " + - "WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DATABASE_INSIGHT_BOLUS_IDS + "\")"); - database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DATABASE_INSIGHT_PUMP_IDS + "\", " + System.currentTimeMillis() + " " + - "WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DATABASE_INSIGHT_PUMP_IDS + "\")"); + database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_BOLUS_IDS + "\", " + System.currentTimeMillis() + " " + + "WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_BOLUS_IDS + "\")"); + database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_PUMP_IDS + "\", " + System.currentTimeMillis() + " " + + "WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_PUMP_IDS + "\")"); } else if (oldVersion < 11) { - database.execSQL("UPDATE sqlite_sequence SET seq = " + System.currentTimeMillis() + " WHERE name = \"" + DATABASE_INSIGHT_BOLUS_IDS + "\""); - database.execSQL("UPDATE sqlite_sequence SET seq = " + System.currentTimeMillis() + " WHERE name = \"" + DATABASE_INSIGHT_PUMP_IDS + "\""); + database.execSQL("UPDATE sqlite_sequence SET seq = " + System.currentTimeMillis() + " WHERE name = \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_BOLUS_IDS + "\""); + database.execSQL("UPDATE sqlite_sequence SET seq = " + System.currentTimeMillis() + " WHERE name = \"" + DatabaseHelperInterface.Companion.DATABASE_INSIGHT_PUMP_IDS + "\""); } TableUtils.createTableIfNotExists(connectionSource, OHQueueItem.class); } catch (SQLException e) { diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java index 41f7cabdd9..71d61d7276 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelperProvider.java @@ -108,4 +108,35 @@ public class DatabaseHelperProvider implements DatabaseHelperInterface { return MainApp.getDbHelper().getProfileSwitchData(from, ascending); } + @Override public void createOrUpdate(@NotNull InsightBolusID record) { + MainApp.getDbHelper().createOrUpdate(record); + } + + @Override public void createOrUpdate(@NotNull InsightPumpID record) { + MainApp.getDbHelper().createOrUpdate(record); + } + + @Override public void createOrUpdate(@NotNull InsightHistoryOffset record) { + MainApp.getDbHelper().createOrUpdate(record); + } + + @Override public void delete(@NotNull ExtendedBolus extendedBolus) { + MainApp.getDbHelper().delete(extendedBolus); + } + + @Nullable @Override public ExtendedBolus getExtendedBolusByPumpId(long pumpId) { + return MainApp.getDbHelper().getExtendedBolusByPumpId(pumpId); + } + + @Nullable @Override public InsightBolusID getInsightBolusID(@NotNull String pumpSerial, int bolusID, long timestamp) { + return MainApp.getDbHelper().getInsightBolusID(pumpSerial, bolusID, timestamp); + } + + @Nullable @Override public InsightHistoryOffset getInsightHistoryOffset(@NotNull String pumpSerial) { + return MainApp.getDbHelper().getInsightHistoryOffset(pumpSerial); + } + + @Nullable @Override public InsightPumpID getPumpStoppedEvent(@NotNull String pumpSerial, long before) { + return MainApp.getDbHelper().getPumpStoppedEvent(pumpSerial, before); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ActivitiesModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ActivitiesModule.kt index 54f139f0e8..95e0888b79 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ActivitiesModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ActivitiesModule.kt @@ -9,12 +9,6 @@ import info.nightscout.androidaps.plugins.general.maintenance.activities.LogSett import info.nightscout.androidaps.plugins.general.openhumans.OpenHumansLoginActivity import info.nightscout.androidaps.plugins.general.overview.activities.QuickWizardListActivity import info.nightscout.androidaps.plugins.general.smsCommunicator.activities.SmsCommunicatorOtpActivity -import info.nightscout.androidaps.plugins.pump.common.dialog.RileyLinkBLEConfigActivity -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity -import info.nightscout.androidaps.plugins.pump.insight.activities.InsightAlertActivity -import info.nightscout.androidaps.plugins.pump.insight.activities.InsightPairingActivity -import info.nightscout.androidaps.plugins.pump.insight.activities.InsightPairingInformationActivity -import info.nightscout.androidaps.plugins.pump.medtronic.dialog.MedtronicHistoryActivity import info.nightscout.androidaps.setupwizard.SetupWizardActivity @Module @@ -22,17 +16,11 @@ import info.nightscout.androidaps.setupwizard.SetupWizardActivity abstract class ActivitiesModule { @ContributesAndroidInjector abstract fun contributesHistoryBrowseActivity(): HistoryBrowseActivity - @ContributesAndroidInjector abstract fun contributesInsightAlertActivity(): InsightAlertActivity - @ContributesAndroidInjector abstract fun contributesInsightPairingActivity(): InsightPairingActivity - @ContributesAndroidInjector abstract fun contributesInsightPairingInformationActivity(): InsightPairingInformationActivity @ContributesAndroidInjector abstract fun contributesLogSettingActivity(): LogSettingActivity @ContributesAndroidInjector abstract fun contributeMainActivity(): MainActivity - @ContributesAndroidInjector abstract fun contributesMedtronicHistoryActivity(): MedtronicHistoryActivity @ContributesAndroidInjector abstract fun contributesPreferencesActivity(): PreferencesActivity @ContributesAndroidInjector abstract fun contributesQuickWizardListActivity(): QuickWizardListActivity @ContributesAndroidInjector abstract fun contributesRequestDexcomPermissionActivity(): RequestDexcomPermissionActivity - @ContributesAndroidInjector abstract fun contributesRileyLinkStatusActivity(): RileyLinkStatusActivity - @ContributesAndroidInjector abstract fun contributesRileyLinkBLEConfigActivity(): RileyLinkBLEConfigActivity @ContributesAndroidInjector abstract fun contributesSetupWizardActivity(): SetupWizardActivity @ContributesAndroidInjector abstract fun contributesSingleFragmentActivity(): SingleFragmentActivity @ContributesAndroidInjector abstract fun contributesSmsCommunicatorOtpActivity(): SmsCommunicatorOtpActivity diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt index 61cb5334b0..f1075e2e9c 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt @@ -5,12 +5,15 @@ import dagger.Component import dagger.android.AndroidInjectionModule import dagger.android.AndroidInjector import info.nightscout.androidaps.MainApp +import info.nightscout.androidaps.combo.di.ComboModule import info.nightscout.androidaps.core.di.CoreModule import info.nightscout.androidaps.dana.di.DanaModule import info.nightscout.androidaps.danar.di.DanaRModule import info.nightscout.androidaps.danars.di.DanaRSModule +import info.nightscout.androidaps.danars.di.InsightModule import info.nightscout.androidaps.database.DatabaseModule -import info.nightscout.androidaps.plugins.pump.common.dagger.RileyLinkModule +import info.nightscout.androidaps.plugins.pump.common.di.RileyLinkModule +import info.nightscout.androidaps.plugins.pump.medtronic.di.MedtronicModule import info.nightscout.androidaps.plugins.pump.omnipod.eros.dagger.OmnipodErosModule import javax.inject.Singleton @@ -43,6 +46,8 @@ import javax.inject.Singleton DanaModule::class, DanaRModule::class, DanaRSModule::class, + ComboModule::class, + InsightModule::class, WorkersModule::class, OHUploaderModule::class ] diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt index d7f9e11759..4acdd1f0db 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt @@ -30,13 +30,6 @@ import info.nightscout.androidaps.plugins.general.wear.WearFragment import info.nightscout.androidaps.plugins.insulin.InsulinFragment import info.nightscout.androidaps.plugins.profile.local.LocalProfileFragment import info.nightscout.androidaps.plugins.profile.ns.NSProfileFragment -import info.nightscout.androidaps.plugins.pump.combo.ComboFragment -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusGeneralFragment -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusHistoryFragment -import info.nightscout.androidaps.plugins.pump.insight.LocalInsightFragment -import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicFragment -import info.nightscout.androidaps.plugins.pump.medtronic.dialog.RileyLinkStatusDeviceMedtronic -import info.nightscout.androidaps.plugins.pump.omnipod.eros.ui.OmnipodErosOverviewFragment import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpFragment import info.nightscout.androidaps.plugins.source.BGSourceFragment import info.nightscout.androidaps.plugins.treatments.TreatmentsFragment @@ -52,7 +45,6 @@ abstract class FragmentsModule { @ContributesAndroidInjector abstract fun contributesActionsFragment(): ActionsFragment @ContributesAndroidInjector abstract fun contributesAutomationFragment(): AutomationFragment @ContributesAndroidInjector abstract fun contributesBGSourceFragment(): BGSourceFragment - @ContributesAndroidInjector abstract fun contributesComboFragment(): ComboFragment @ContributesAndroidInjector abstract fun contributesConfigBuilderFragment(): ConfigBuilderFragment @@ -64,11 +56,8 @@ abstract class FragmentsModule { @ContributesAndroidInjector abstract fun contributesOpenAPSAMAFragment(): OpenAPSAMAFragment @ContributesAndroidInjector abstract fun contributesOpenAPSSMBFragment(): OpenAPSSMBFragment @ContributesAndroidInjector abstract fun contributesOverviewFragment(): OverviewFragment - @ContributesAndroidInjector abstract fun contributesLocalInsightFragment(): LocalInsightFragment @ContributesAndroidInjector abstract fun contributesLoopFragment(): LoopFragment @ContributesAndroidInjector abstract fun contributesMaintenanceFragment(): MaintenanceFragment - @ContributesAndroidInjector abstract fun contributesMedtronicFragment(): MedtronicFragment - @ContributesAndroidInjector abstract fun contributesOmnipodFragment(): OmnipodErosOverviewFragment @ContributesAndroidInjector abstract fun contributesNSProfileFragment(): NSProfileFragment @ContributesAndroidInjector abstract fun contributesNSClientFragment(): NSClientFragment @ContributesAndroidInjector @@ -117,11 +106,4 @@ abstract class FragmentsModule { abstract fun contributesExchangeAuthTokenDialot(): OpenHumansLoginActivity.ExchangeAuthTokenDialog @ContributesAndroidInjector abstract fun contributesPasswordCheck(): PasswordCheck - - @ContributesAndroidInjector - abstract fun contributesRileyLinkStatusGeneral(): RileyLinkStatusGeneralFragment - @ContributesAndroidInjector - abstract fun contributesRileyLinkStatusHistoryFragment(): RileyLinkStatusHistoryFragment - @ContributesAndroidInjector - abstract fun contributesRileyLinkStatusDeviceMedtronic(): RileyLinkStatusDeviceMedtronic } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/MedtronicModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/MedtronicModule.kt deleted file mode 100644 index cadac7d13c..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/MedtronicModule.kt +++ /dev/null @@ -1,13 +0,0 @@ -package info.nightscout.androidaps.dependencyInjection - -import dagger.Module -import dagger.android.ContributesAndroidInjector -import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager -import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUITask - -@Module -@Suppress("unused") -abstract class MedtronicModule { - @ContributesAndroidInjector abstract fun medtronicCommunicationManagerProvider(): MedtronicCommunicationManager - @ContributesAndroidInjector abstract fun medtronicUITaskProvider(): MedtronicUITask -} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ServicesModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ServicesModule.kt index 50f8695bf9..04165b32a1 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ServicesModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ServicesModule.kt @@ -6,11 +6,6 @@ import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientServ import info.nightscout.androidaps.plugins.general.overview.notifications.DismissNotificationService import info.nightscout.androidaps.plugins.general.persistentNotification.DummyService import info.nightscout.androidaps.plugins.general.wear.wearintegration.WatchUpdaterService -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService -import info.nightscout.androidaps.plugins.pump.insight.InsightAlertService -import info.nightscout.androidaps.plugins.pump.insight.connection_service.InsightConnectionService -import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService -import info.nightscout.androidaps.plugins.pump.omnipod.eros.rileylink.service.RileyLinkOmnipodService import info.nightscout.androidaps.services.AlarmSoundService import info.nightscout.androidaps.services.LocationService @@ -24,9 +19,4 @@ abstract class ServicesModule { @ContributesAndroidInjector abstract fun contributesLocationService(): LocationService @ContributesAndroidInjector abstract fun contributesNSClientService(): NSClientService @ContributesAndroidInjector abstract fun contributesWatchUpdaterService(): WatchUpdaterService - @ContributesAndroidInjector abstract fun contributesInsightAlertService(): InsightAlertService - @ContributesAndroidInjector abstract fun contributesInsightConnectionService(): InsightConnectionService - @ContributesAndroidInjector abstract fun contributesRileyLinkService(): RileyLinkService - @ContributesAndroidInjector abstract fun contributesRileyLinkMedtronicService(): RileyLinkMedtronicService - @ContributesAndroidInjector abstract fun contributesRileyLinkOmnipodService(): RileyLinkOmnipodService } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/WizardModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/WizardModule.kt index 2c105e9ce7..1405b8867f 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/WizardModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/WizardModule.kt @@ -18,6 +18,7 @@ abstract class WizardModule { @ContributesAndroidInjector abstract fun swEditEncryptedPasswordInjector(): SWEditEncryptedPassword @ContributesAndroidInjector abstract fun swEditUrlInjector(): SWEditUrl @ContributesAndroidInjector abstract fun swFragmentInjector(): SWFragment + @ContributesAndroidInjector abstract fun swPreferenceInjector(): SWPreference @ContributesAndroidInjector abstract fun swHtmlLinkInjector(): SWHtmlLink @ContributesAndroidInjector abstract fun swInfotextInjector(): SWInfoText @ContributesAndroidInjector abstract fun swItemInjector(): SWItem diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt index 36246c4c2c..de7e3f4d4f 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt @@ -91,7 +91,7 @@ class ExtendedBolusDialog : DialogFragmentWithDate() { commandQueue.extendedBolus(insulinAfterConstraint, durationInMinutes, object : Callback() { override fun run() { if (!result.success) { - ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), info.nightscout.androidaps.dana.R.raw.boluserror) + ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), R.raw.boluserror) } } }) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt index a736e78367..e818dd8fc1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt @@ -1,6 +1,5 @@ package info.nightscout.androidaps.plugins.general.overview.notifications -import android.annotation.SuppressLint import android.app.NotificationChannel import android.app.NotificationManager import android.app.PendingIntent @@ -11,14 +10,10 @@ import android.media.RingtoneManager import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.Button -import android.widget.TextView -import androidx.cardview.widget.CardView import androidx.core.app.NotificationCompat -import androidx.core.app.TaskStackBuilder import androidx.recyclerview.widget.RecyclerView -import info.nightscout.androidaps.MainActivity import info.nightscout.androidaps.R +import info.nightscout.androidaps.databinding.OverviewNotificationItemBinding import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper @@ -45,8 +40,7 @@ class NotificationStore @Inject constructor( private val dateUtil: DateUtil ) { - var store: MutableList = ArrayList() - private var usesChannels = false + private var store: MutableList = ArrayList() companion object { @@ -71,20 +65,19 @@ class NotificationStore @Inject constructor( } } store.add(n) - if (sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, true) && n !is NotificationWithAction) { + if (sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, true) && n !is NotificationWithAction) raiseSystemNotification(n) - if (usesChannels && n.soundId != null && n.soundId != 0) alarmSoundServiceHelper.startAlarm(context, n.soundId) - } else { - if (n.soundId != null && n.soundId != 0) alarmSoundServiceHelper.startAlarm(context, n.soundId) - } + if (n.soundId != null && n.soundId != 0) alarmSoundServiceHelper.startAlarm(context, n.soundId) Collections.sort(store, NotificationComparator()) return true } - @Synchronized fun remove(id: Int): Boolean { + @Synchronized + fun remove(id: Int): Boolean { for (i in store.indices) { if (store[i].id == id) { if (store[i].soundId != null) alarmSoundServiceHelper.stopService(context) + aapsLogger.debug(LTag.NOTIFICATION, "Notification removed: " + store[i].text) store.removeAt(i) return true } @@ -92,11 +85,14 @@ class NotificationStore @Inject constructor( return false } - @Synchronized private fun removeExpired() { + @Synchronized + private fun removeExpired() { var i = 0 while (i < store.size) { val n = store[i] if (n.validTo != 0L && n.validTo < System.currentTimeMillis()) { + if (store[i].soundId != null) alarmSoundServiceHelper.stopService(context) + aapsLogger.debug(LTag.NOTIFICATION, "Notification expired: " + store[i].text) store.removeAt(i) i-- } @@ -135,20 +131,17 @@ class NotificationStore @Inject constructor( } fun createNotificationChannel() { - usesChannels = true val mNotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - @SuppressLint("WrongConstant") val channel = NotificationChannel(CHANNEL_ID, - CHANNEL_ID, - NotificationManager.IMPORTANCE_HIGH) + val channel = NotificationChannel(CHANNEL_ID, CHANNEL_ID, NotificationManager.IMPORTANCE_HIGH) mNotificationManager.createNotificationChannel(channel) } @Synchronized fun updateNotifications(notificationsView: RecyclerView) { removeExpired() -// unSnooze() - if (store.size > 0) { - val adapter = NotificationRecyclerViewAdapter(cloneStore()) + val clonedStore = ArrayList(store) + if (clonedStore.isNotEmpty()) { + val adapter = NotificationRecyclerViewAdapter(clonedStore) notificationsView.adapter = adapter notificationsView.visibility = View.VISIBLE } else { @@ -156,33 +149,24 @@ class NotificationStore @Inject constructor( } } - @Synchronized - private fun cloneStore(): List { - val clone: MutableList = ArrayList(store.size) - clone.addAll(store) - return clone - } - inner class NotificationRecyclerViewAdapter internal constructor(private val notificationsList: List) : RecyclerView.Adapter() { - override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): NotificationsViewHolder { - val v = LayoutInflater.from(viewGroup.context).inflate(R.layout.overview_notification_item, viewGroup, false) - return NotificationsViewHolder(v) - } + override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): NotificationsViewHolder = + NotificationsViewHolder(LayoutInflater.from(viewGroup.context).inflate(R.layout.overview_notification_item, viewGroup, false)) override fun onBindViewHolder(holder: NotificationsViewHolder, position: Int) { val notification = notificationsList[position] - holder.dismiss.tag = notification - if (notification.buttonText != 0) holder.dismiss.setText(notification.buttonText) - else holder.dismiss.setText(R.string.snooze) + holder.binding.dismiss.tag = notification + if (notification.buttonText != 0) holder.binding.dismiss.setText(notification.buttonText) + else holder.binding.dismiss.setText(R.string.snooze) @Suppress("SetTextI18n") - holder.text.text = dateUtil.timeString(notification.date) + " " + notification.text + holder.binding.text.text = dateUtil.timeString(notification.date) + " " + notification.text when (notification.level) { - Notification.URGENT -> holder.cv.setBackgroundColor(resourceHelper.gc(R.color.notificationUrgent)) - Notification.NORMAL -> holder.cv.setBackgroundColor(resourceHelper.gc(R.color.notificationNormal)) - Notification.LOW -> holder.cv.setBackgroundColor(resourceHelper.gc(R.color.notificationLow)) - Notification.INFO -> holder.cv.setBackgroundColor(resourceHelper.gc(R.color.notificationInfo)) - Notification.ANNOUNCEMENT -> holder.cv.setBackgroundColor(resourceHelper.gc(R.color.notificationAnnouncement)) + Notification.URGENT -> holder.binding.cv.setBackgroundColor(resourceHelper.gc(R.color.notificationUrgent)) + Notification.NORMAL -> holder.binding.cv.setBackgroundColor(resourceHelper.gc(R.color.notificationNormal)) + Notification.LOW -> holder.binding.cv.setBackgroundColor(resourceHelper.gc(R.color.notificationLow)) + Notification.INFO -> holder.binding.cv.setBackgroundColor(resourceHelper.gc(R.color.notificationInfo)) + Notification.ANNOUNCEMENT -> holder.binding.cv.setBackgroundColor(resourceHelper.gc(R.color.notificationAnnouncement)) } } @@ -192,12 +176,10 @@ class NotificationStore @Inject constructor( inner class NotificationsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { - var cv: CardView = itemView.findViewById(R.id.notification_cardview) - var text: TextView = itemView.findViewById(R.id.notification_text) - var dismiss: Button = itemView.findViewById(R.id.notification_dismiss) + val binding = OverviewNotificationItemBinding.bind(itemView) init { - dismiss.setOnClickListener { + binding.dismiss.setOnClickListener { val notification = it.tag as Notification rxBus.send(EventDismissNotification(notification.id)) notification.action?.run() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyServiceHelper.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyServiceHelper.kt index d1adfc00ed..5f52035bac 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyServiceHelper.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/DummyServiceHelper.kt @@ -4,9 +4,7 @@ import android.content.ComponentName import android.content.Context import android.content.Intent import android.content.ServiceConnection -import android.os.Build import android.os.IBinder -import androidx.annotation.RequiresApi import info.nightscout.androidaps.interfaces.NotificationHolderInterface import javax.inject.Inject import javax.inject.Singleton @@ -14,14 +12,13 @@ import javax.inject.Singleton /* This code replaces following val alarm = Intent(context, DummyService::class.java) - alarm.putExtra("soundid", n.soundId) + alarm.putExtra("soundId", n.soundId) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) context.startForegroundService(alarm) else context.startService(alarm) it fails randomly with error Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{e317f7e u0 info.nightscout.nsclient/info.nightscout.androidaps.services.DummyService} */ -@RequiresApi(Build.VERSION_CODES.O) @Singleton class DummyServiceHelper @Inject constructor( private val notificationHolder: NotificationHolderInterface diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt index 0d6defc736..d65114f9ff 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt @@ -30,7 +30,7 @@ import io.reactivex.disposables.CompositeDisposable import javax.inject.Inject import javax.inject.Singleton -@Suppress("PrivatePropertyName") +@Suppress("PrivatePropertyName", "DEPRECATION") @Singleton class PersistentNotificationPlugin @Inject constructor( injector: HasAndroidInjector, diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt index 9a077ce965..5e1dbb7cb5 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt @@ -189,6 +189,13 @@ class SWDefinition @Inject constructor( .add(SWEditString(injector) .validator(SWTextValidator(String::isNotEmpty)) .preferenceId(R.string.key_patient_name)) + private val privacy = SWScreen(injector, R.string.privacy_settings) + .skippable(true) + .add(SWInfoText(injector) + .label(R.string.privacy_summary)) + .add(SWPreference(injector, this) + .option(R.xml.pref_datachoices) + ) private val screenMasterPassword = SWScreen(injector, R.string.master_password) .skippable(false) .add(SWInfoText(injector) @@ -374,6 +381,7 @@ class SWDefinition @Inject constructor( .add(screenPermissionStore) .add(screenMasterPassword) .add(screenImport) + .add(privacy) .add(screenUnits) .add(displaySettings) .add(screenNsClient) diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.kt index c6cc3f9620..2a25c2ea91 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.kt @@ -31,8 +31,9 @@ open class SWItem(val injector: HasAndroidInjector, var type: Type) { injector.androidInjector().inject(this) } + @Suppress("unused") enum class Type { - NONE, TEXT, HTML_LINK, BREAK, LISTENER, URL, STRING, NUMBER, DECIMAL_NUMBER, RADIOBUTTON, PLUGIN, BUTTON, FRAGMENT, UNIT_NUMBER + NONE, TEXT, HTML_LINK, BREAK, LISTENER, URL, STRING, NUMBER, DECIMAL_NUMBER, RADIOBUTTON, PLUGIN, BUTTON, FRAGMENT, UNIT_NUMBER, PREFERENCE } var label: Int? = null diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPlugin.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPlugin.kt index 76c140d708..95401bdfab 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPlugin.kt @@ -18,7 +18,7 @@ import info.nightscout.androidaps.setupwizard.SWDefinition import info.nightscout.androidaps.setupwizard.events.EventSWUpdate import javax.inject.Inject -class SWPlugin(injector: HasAndroidInjector, val definition: SWDefinition) : SWItem(injector, Type.PLUGIN) { +class SWPlugin(injector: HasAndroidInjector, private val definition: SWDefinition) : SWItem(injector, Type.PLUGIN) { @Inject lateinit var pluginStore: PluginStore @Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPreference.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPreference.kt new file mode 100644 index 0000000000..7abafa7c82 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPreference.kt @@ -0,0 +1,38 @@ +package info.nightscout.androidaps.setupwizard.elements + +import android.os.Bundle +import android.widget.LinearLayout +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.activities.MyPreferenceFragment +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin +import info.nightscout.androidaps.plugins.configBuilder.PluginStore +import info.nightscout.androidaps.setupwizard.SWDefinition +import javax.inject.Inject + +class SWPreference(injector: HasAndroidInjector, private val definition: SWDefinition) : SWItem(injector, Type.PREFERENCE) { + + @Inject lateinit var pluginStore: PluginStore + @Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin + + private var xml: Int = -1 + + fun option(xml: Int): SWPreference { + this.xml = xml + return this + } + + override fun generateDialog(layout: LinearLayout) { + addConfiguration(layout, xml) + super.generateDialog(layout) + } + + private fun addConfiguration(layout: LinearLayout, xml: Int) { + MyPreferenceFragment().also { fragment -> + fragment.arguments = Bundle().also { it.putInt("id", xml) } + definition.activity.supportFragmentManager.beginTransaction().run { + replace(layout.id, fragment) + commit() + } + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/overview_notification_item.xml b/app/src/main/res/layout/overview_notification_item.xml index 03b5688fc3..f8f1974d33 100644 --- a/app/src/main/res/layout/overview_notification_item.xml +++ b/app/src/main/res/layout/overview_notification_item.xml @@ -1,7 +1,8 @@ + android:text="Notification text. Notification text. Notification text. Notification text. Notification text. Notification text. " + tools:ignore="HardcodedText" />