From 1ff6aa7bbf5abae17df4355cef2e8e403f5477db Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 19 Sep 2023 14:36:36 +0200 Subject: [PATCH] cleanup --- app/src/main/java/info/nightscout/androidaps/MainActivity.kt | 3 +-- .../src/main/java/info/nightscout/interfaces/iob/CobInfo.kt | 2 +- .../interfaces/notifications/NotificationUserMessage.kt | 2 +- .../nightscout/interfaces/smsCommunicator/SmsCommunicator.kt | 1 + .../src/main/java/info/nightscout/core/wizard/BolusWizard.kt | 3 +-- .../main/java/info/nightscout/core/wizard/QuickWizardEntry.kt | 3 +-- .../implementation/queue/commands/CommandSetProfile.kt | 3 +-- .../info/nightscout/automation/actions/ActionLoopDisable.kt | 2 +- .../info/nightscout/automation/actions/ActionLoopEnable.kt | 2 +- .../info/nightscout/configuration/AndroidPermissionImpl.kt | 3 +-- .../activities/DaggerAppCompatActivityWithResult.kt | 1 - .../activities}/OptimizationPermissionContract.kt | 2 +- .../plugins/general/wear/wearintegration/DataHandlerMobile.kt | 4 ++-- ui/src/main/java/info/nightscout/ui/dialogs/LoopDialog.kt | 2 +- 14 files changed, 14 insertions(+), 19 deletions(-) rename {core/interfaces/src/main/java/info/nightscout/interfaces/permissions => plugins/configuration/src/main/java/info/nightscout/configuration/activities}/OptimizationPermissionContract.kt (92%) diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt index ffc876d687..468547aa58 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt @@ -56,7 +56,6 @@ import info.nightscout.interfaces.constraints.ConstraintsChecker import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.maintenance.PrefFileListProvider import info.nightscout.interfaces.plugin.ActivePlugin -import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.protection.ProtectionCheck import info.nightscout.interfaces.smsCommunicator.SmsCommunicator @@ -283,7 +282,7 @@ class MainActivity : DaggerAppCompatActivityWithResult() { private fun start() { binding.splash.visibility = View.GONE //Check here if loop plugin is disabled. Else check via constraints - if (!(loop as PluginBase).isEnabled()) versionCheckerUtils.triggerCheckVersion() + if (!loop.isEnabled()) versionCheckerUtils.triggerCheckVersion() setUserStats() setupViews() diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/iob/CobInfo.kt b/core/interfaces/src/main/java/info/nightscout/interfaces/iob/CobInfo.kt index 35c70f8d5f..4a52fefcec 100644 --- a/core/interfaces/src/main/java/info/nightscout/interfaces/iob/CobInfo.kt +++ b/core/interfaces/src/main/java/info/nightscout/interfaces/iob/CobInfo.kt @@ -1,4 +1,4 @@ package info.nightscout.interfaces.iob /** All COB up to now, including carbs not yet processed by IobCob calculation. */ -class CobInfo(val timestamp: Long, val displayCob: Double?, val futureCarbs: Double) \ No newline at end of file +data class CobInfo(val timestamp: Long, val displayCob: Double?, val futureCarbs: Double) \ No newline at end of file diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/notifications/NotificationUserMessage.kt b/core/interfaces/src/main/java/info/nightscout/interfaces/notifications/NotificationUserMessage.kt index be39876b5a..3eb2d74945 100644 --- a/core/interfaces/src/main/java/info/nightscout/interfaces/notifications/NotificationUserMessage.kt +++ b/core/interfaces/src/main/java/info/nightscout/interfaces/notifications/NotificationUserMessage.kt @@ -1,6 +1,6 @@ package info.nightscout.interfaces.notifications -class NotificationUserMessage (text :String): Notification() { +class NotificationUserMessage(text: String) : Notification() { init { var hash = text.hashCode() diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/smsCommunicator/SmsCommunicator.kt b/core/interfaces/src/main/java/info/nightscout/interfaces/smsCommunicator/SmsCommunicator.kt index a699169598..ae5484cf6d 100644 --- a/core/interfaces/src/main/java/info/nightscout/interfaces/smsCommunicator/SmsCommunicator.kt +++ b/core/interfaces/src/main/java/info/nightscout/interfaces/smsCommunicator/SmsCommunicator.kt @@ -5,4 +5,5 @@ interface SmsCommunicator { var messages: ArrayList fun sendNotificationToAllNumbers(text: String): Boolean fun sendSMS(sms: Sms): Boolean + fun isEnabled(): Boolean } \ No newline at end of file diff --git a/core/main/src/main/java/info/nightscout/core/wizard/BolusWizard.kt b/core/main/src/main/java/info/nightscout/core/wizard/BolusWizard.kt index f623f9681e..4bba468c45 100644 --- a/core/main/src/main/java/info/nightscout/core/wizard/BolusWizard.kt +++ b/core/main/src/main/java/info/nightscout/core/wizard/BolusWizard.kt @@ -27,7 +27,6 @@ import info.nightscout.interfaces.iob.GlucoseStatusProvider import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.plugin.ActivePlugin -import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.pump.DetailedBolusInfo @@ -455,7 +454,7 @@ class BolusWizard @Inject constructor( if (insulinAfterConstraints > 0 || carbs > 0) { if (useSuperBolus) { uel.log(Action.SUPERBOLUS_TBR, Sources.WizardDialog) - if ((loop as PluginBase).isEnabled()) { + if (loop.isEnabled()) { loop.goToZeroTemp(2 * 60, profile, OfflineEvent.Reason.SUPER_BOLUS) rxBus.send(EventRefreshOverview("WizardDialog")) } diff --git a/core/main/src/main/java/info/nightscout/core/wizard/QuickWizardEntry.kt b/core/main/src/main/java/info/nightscout/core/wizard/QuickWizardEntry.kt index eeb936de5d..ff0d7ff78f 100644 --- a/core/main/src/main/java/info/nightscout/core/wizard/QuickWizardEntry.kt +++ b/core/main/src/main/java/info/nightscout/core/wizard/QuickWizardEntry.kt @@ -13,7 +13,6 @@ import info.nightscout.interfaces.db.PersistenceLayer import info.nightscout.interfaces.iob.GlucoseStatusProvider import info.nightscout.interfaces.iob.InMemoryGlucoseValue import info.nightscout.interfaces.iob.IobCobCalculator -import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.rx.logging.AAPSLogger @@ -141,7 +140,7 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec if (useSuperBolus() == YES && sp.getBoolean(info.nightscout.core.utils.R.string.key_usesuperbolus, false)) { superBolus = true } - if ((loop as PluginBase).isEnabled() && loop.isSuperBolus) superBolus = false + if (loop.isEnabled() && loop.isSuperBolus) superBolus = false // Trend val glucoseStatus = glucoseStatusProvider.glucoseStatusData var trend = false diff --git a/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandSetProfile.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandSetProfile.kt index 1167b0a127..eae3887c20 100644 --- a/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandSetProfile.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandSetProfile.kt @@ -5,7 +5,6 @@ import info.nightscout.database.ValueWrapper import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.Config import info.nightscout.interfaces.plugin.ActivePlugin -import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.pump.PumpEnactResult import info.nightscout.interfaces.queue.Callback @@ -42,7 +41,7 @@ class CommandSetProfile constructor( // Send SMS notification if ProfileSwitch is coming from NS val profileSwitch = repository.getEffectiveProfileSwitchActiveAt(dateUtil.now()).blockingGet() if (profileSwitch is ValueWrapper.Existing && r.enacted && hasNsId && !config.NSCLIENT) { - if ((smsCommunicator as PluginBase).isEnabled()) + if (smsCommunicator.isEnabled()) smsCommunicator.sendNotificationToAllNumbers(rh.gs(info.nightscout.core.ui.R.string.profile_set_ok)) } } diff --git a/plugins/automation/src/main/java/info/nightscout/automation/actions/ActionLoopDisable.kt b/plugins/automation/src/main/java/info/nightscout/automation/actions/ActionLoopDisable.kt index d39ff2f888..ee6301043d 100644 --- a/plugins/automation/src/main/java/info/nightscout/automation/actions/ActionLoopDisable.kt +++ b/plugins/automation/src/main/java/info/nightscout/automation/actions/ActionLoopDisable.kt @@ -30,7 +30,7 @@ class ActionLoopDisable(injector: HasAndroidInjector) : Action(injector) { @DrawableRes override fun icon(): Int = R.drawable.ic_stop_24dp override fun doAction(callback: Callback) { - if ((loopPlugin as PluginBase).isEnabled()) { + if (loopPlugin.isEnabled()) { (loopPlugin as PluginBase).setPluginEnabled(PluginType.LOOP, false) configBuilder.storeSettings("ActionLoopDisable") uel.log(UserEntry.Action.LOOP_DISABLED, Sources.Automation, title) diff --git a/plugins/automation/src/main/java/info/nightscout/automation/actions/ActionLoopEnable.kt b/plugins/automation/src/main/java/info/nightscout/automation/actions/ActionLoopEnable.kt index 5caad06cad..30617bdd49 100644 --- a/plugins/automation/src/main/java/info/nightscout/automation/actions/ActionLoopEnable.kt +++ b/plugins/automation/src/main/java/info/nightscout/automation/actions/ActionLoopEnable.kt @@ -28,7 +28,7 @@ class ActionLoopEnable(injector: HasAndroidInjector) : Action(injector) { @DrawableRes override fun icon(): Int = R.drawable.ic_play_circle_outline_24dp override fun doAction(callback: Callback) { - if (!(loopPlugin as PluginBase).isEnabled()) { + if (!loopPlugin.isEnabled()) { (loopPlugin as PluginBase).setPluginEnabled(PluginType.LOOP, true) configBuilder.storeSettings("ActionLoopEnable") rxBus.send(EventRefreshOverview("ActionLoopEnable")) diff --git a/plugins/configuration/src/main/java/info/nightscout/configuration/AndroidPermissionImpl.kt b/plugins/configuration/src/main/java/info/nightscout/configuration/AndroidPermissionImpl.kt index d6113c01d8..6e2c57c310 100644 --- a/plugins/configuration/src/main/java/info/nightscout/configuration/AndroidPermissionImpl.kt +++ b/plugins/configuration/src/main/java/info/nightscout/configuration/AndroidPermissionImpl.kt @@ -20,7 +20,6 @@ import info.nightscout.interfaces.AndroidPermission import info.nightscout.interfaces.Config import info.nightscout.interfaces.notifications.Notification import info.nightscout.interfaces.plugin.ActivePlugin -import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.smsCommunicator.SmsCommunicator import info.nightscout.shared.interfaces.ResourceHelper import javax.inject.Inject @@ -86,7 +85,7 @@ class AndroidPermissionImpl @Inject constructor( @Synchronized override fun notifyForSMSPermissions(activity: FragmentActivity, smsCommunicator: SmsCommunicator) { - if ((smsCommunicator as PluginBase).isEnabled()) { + if (smsCommunicator.isEnabled()) { if (permissionNotGranted(activity, Manifest.permission.RECEIVE_SMS)) activePlugin.activeOverview.addNotification( id = Notification.PERMISSION_SMS, diff --git a/plugins/configuration/src/main/java/info/nightscout/configuration/activities/DaggerAppCompatActivityWithResult.kt b/plugins/configuration/src/main/java/info/nightscout/configuration/activities/DaggerAppCompatActivityWithResult.kt index febf53fe67..f13e61ffe9 100644 --- a/plugins/configuration/src/main/java/info/nightscout/configuration/activities/DaggerAppCompatActivityWithResult.kt +++ b/plugins/configuration/src/main/java/info/nightscout/configuration/activities/DaggerAppCompatActivityWithResult.kt @@ -13,7 +13,6 @@ import info.nightscout.configuration.maintenance.PrefsFileContract import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.core.ui.locale.LocaleHelper import info.nightscout.interfaces.maintenance.ImportExportPrefs -import info.nightscout.interfaces.permissions.OptimizationPermissionContract import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventThemeSwitch import info.nightscout.rx.logging.AAPSLogger diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/permissions/OptimizationPermissionContract.kt b/plugins/configuration/src/main/java/info/nightscout/configuration/activities/OptimizationPermissionContract.kt similarity index 92% rename from core/interfaces/src/main/java/info/nightscout/interfaces/permissions/OptimizationPermissionContract.kt rename to plugins/configuration/src/main/java/info/nightscout/configuration/activities/OptimizationPermissionContract.kt index c28d65c84f..b68ebc579d 100644 --- a/core/interfaces/src/main/java/info/nightscout/interfaces/permissions/OptimizationPermissionContract.kt +++ b/plugins/configuration/src/main/java/info/nightscout/configuration/activities/OptimizationPermissionContract.kt @@ -1,4 +1,4 @@ -package info.nightscout.interfaces.permissions +package info.nightscout.configuration.activities import android.content.Context import android.content.Intent diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt index 55b368a20f..953b7c3f42 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt @@ -1038,7 +1038,7 @@ class DataHandlerMobile @Inject constructor( get() { var ret = "" // decide if enabled/disabled closed/open; what Plugin as APS? - if ((loop as PluginBase).isEnabled()) { + if (loop.isEnabled()) { ret += if (constraintChecker.isClosedLoopAllowed().value()) { rh.gs(R.string.loop_status_closed) + "\n" } else { @@ -1137,7 +1137,7 @@ class DataHandlerMobile @Inject constructor( private fun generateStatusString(profile: Profile?): String { var status = "" profile ?: return rh.gs(info.nightscout.core.ui.R.string.noprofile) - if (!(loop as PluginBase).isEnabled()) status += rh.gs(R.string.disabled_loop) + "\n" + if (!loop.isEnabled()) status += rh.gs(R.string.disabled_loop) + "\n" return status } diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/LoopDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/LoopDialog.kt index eb9ed9bbee..00577a4b11 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/LoopDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/LoopDialog.kt @@ -189,7 +189,7 @@ class LoopDialog : DaggerDialogFragment() { binding.overviewReconnect.visibility = View.VISIBLE } - !(loop as PluginBase).isEnabled() -> { + !loop.isEnabled() -> { binding.overviewLoop.visibility = View.VISIBLE binding.overviewEnable.visibility = View.VISIBLE binding.overviewDisable.visibility = View.GONE