cleanup core extensions

This commit is contained in:
Milos Kozak 2022-11-23 13:45:55 +01:00
parent de7a6422d8
commit 50aac4aae7
11 changed files with 53 additions and 69 deletions

View file

@ -55,6 +55,7 @@ import javax.inject.Singleton
CoreModule::class,
DatabaseModule::class,
ImplementationModule::class,
ImplementationModule.Bindings::class,
OpenHumansModule::class,
PluginsModule::class,
RxModule::class,

View file

@ -16,28 +16,9 @@ import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefsI
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.database.impl.AppRepository
import info.nightscout.implementation.AndroidPermissionImpl
import info.nightscout.implementation.BolusTimerImpl
import info.nightscout.implementation.CarbTimerImpl
import info.nightscout.implementation.LocalAlertUtilsImpl
import info.nightscout.implementation.TrendCalculatorImpl
import info.nightscout.implementation.XDripBroadcastImpl
import info.nightscout.implementation.androidNotification.NotificationHolderImpl
import info.nightscout.implementation.constraints.ConstraintsImpl
import info.nightscout.implementation.pump.PumpSyncImplementation
import info.nightscout.implementation.queue.CommandQueueImplementation
import info.nightscout.implementation.resources.IconsProviderImplementation
import info.nightscout.implementation.stats.DexcomTirCalculatorImpl
import info.nightscout.implementation.stats.TddCalculatorImpl
import info.nightscout.implementation.stats.TirCalculatorImpl
import info.nightscout.interfaces.AndroidPermission
import info.nightscout.interfaces.BolusTimer
import info.nightscout.interfaces.CarbTimer
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.ConfigBuilder
import info.nightscout.interfaces.LocalAlertUtils
import info.nightscout.interfaces.NotificationHolder
import info.nightscout.interfaces.XDripBroadcast
import info.nightscout.interfaces.aps.Loop
import info.nightscout.interfaces.autotune.Autotune
import info.nightscout.interfaces.constraints.Constraints
@ -46,19 +27,12 @@ import info.nightscout.interfaces.maintenance.ImportExportPrefs
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.pump.PumpSync
import info.nightscout.interfaces.queue.CommandQueue
import info.nightscout.interfaces.smsCommunicator.SmsCommunicator
import info.nightscout.interfaces.stats.DexcomTirCalculator
import info.nightscout.interfaces.stats.TddCalculator
import info.nightscout.interfaces.stats.TirCalculator
import info.nightscout.interfaces.storage.FileStorage
import info.nightscout.interfaces.storage.Storage
import info.nightscout.interfaces.sync.DataSyncSelector
import info.nightscout.interfaces.ui.ActivityNames
import info.nightscout.interfaces.ui.IconsProvider
import info.nightscout.interfaces.utils.HardLimits
import info.nightscout.interfaces.utils.TrendCalculator
import info.nightscout.plugins.aps.loop.LoopPlugin
import info.nightscout.plugins.general.autotune.AutotunePlugin
import info.nightscout.plugins.general.smsCommunicator.SmsCommunicatorPlugin
@ -125,29 +99,16 @@ open class AppModule {
@Binds fun bindContext(mainApp: MainApp): Context
@Binds fun bindInjector(mainApp: MainApp): HasAndroidInjector
@Binds fun bindActivePlugin(pluginStore: PluginStore): ActivePlugin
@Binds fun bindCommandQueue(commandQueue: CommandQueueImplementation): CommandQueue
@Binds fun bindConfigInterface(config: ConfigImpl): Config
@Binds fun bindConfigBuilderInterface(configBuilderPlugin: ConfigBuilderPlugin): ConfigBuilder
@Binds fun bindNotificationHolderInterface(notificationHolder: NotificationHolderImpl): NotificationHolder
@Binds fun bindImportExportPrefsInterface(importExportPrefs: ImportExportPrefsImpl): ImportExportPrefs
@Binds fun bindIconsProviderInterface(iconsProvider: IconsProviderImplementation): IconsProvider
@Binds fun bindLoopInterface(loopPlugin: LoopPlugin): Loop
@Binds fun bindAutotuneInterface(autotunePlugin: AutotunePlugin): Autotune
@Binds fun bindIobCobCalculatorInterface(iobCobCalculatorPlugin: IobCobCalculatorPlugin): IobCobCalculator
@Binds fun bindSmsCommunicatorInterface(smsCommunicatorPlugin: SmsCommunicatorPlugin): SmsCommunicator
@Binds fun bindDataSyncSelectorInterface(dataSyncSelectorImplementation: DataSyncSelectorImplementation): DataSyncSelector
@Binds fun bindPumpSyncInterface(pumpSyncImplementation: PumpSyncImplementation): PumpSync
@Binds fun bindXDripBroadcastInterface(xDripBroadcastImpl: XDripBroadcastImpl): XDripBroadcast
@Binds fun bindCarbTimerInterface(carbTimer: CarbTimerImpl): CarbTimer
@Binds fun bindBolusTimerInterface(bolusTimer: BolusTimerImpl): BolusTimer
@Binds fun bindAndroidPermissionInterface(androidPermission: AndroidPermissionImpl): AndroidPermission
@Binds fun bindLocalAlertUtilsInterface(localAlertUtils: LocalAlertUtilsImpl): LocalAlertUtils
@Binds fun bindActivityNamesInterface(activityNames: ActivityNamesImpl): ActivityNames
@Binds fun bindTrendCalculatorInterface(trendCalculator: TrendCalculatorImpl): TrendCalculator
@Binds fun bindTddCalculatorInterface(tddCalculator: TddCalculatorImpl): TddCalculator
@Binds fun bindTirCalculatorInterface(tirCalculator: TirCalculatorImpl): TirCalculator
@Binds fun bindDexcomTirCalculatorInterface(dexcomTirCalculator: DexcomTirCalculatorImpl): DexcomTirCalculator
}
}

View file

@ -6,7 +6,6 @@ import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.extensions.convertedToAbsolute
import info.nightscout.androidaps.extensions.toStringShort
import info.nightscout.androidaps.extensions.total
import info.nightscout.androidaps.extensions.valueToUnits
import info.nightscout.androidaps.extensions.valueToUnitsString
import info.nightscout.androidaps.logging.UserEntryLogger
@ -1056,6 +1055,9 @@ class DataHandlerMobile @Inject constructor(
return historyList
}
private val TotalDailyDose.total
get() = if (totalAmount > 0) totalAmount else basalAmount + bolusAmount
private fun generateTDDMessage(historyList: MutableList<TotalDailyDose>, dummies: MutableList<TotalDailyDose>): String {
val profile = profileFunction.getProfile() ?: return "No profile loaded :("
if (historyList.isEmpty()) {

View file

@ -30,7 +30,7 @@ fun TemporaryBasal.convertedToPercent(time: Long, profile: Profile): Int =
if (!isAbsolute) rate.toInt()
else (rate / profile.getBasal(time) * 100).toInt()
fun TemporaryBasal.netExtendedRate(profile: Profile) = rate - profile.getBasal(timestamp)
private fun TemporaryBasal.netExtendedRate(profile: Profile) = rate - profile.getBasal(timestamp)
val TemporaryBasal.durationInMinutes
get() = T.msecs(duration).mins()

View file

@ -10,9 +10,6 @@ import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
import java.util.concurrent.TimeUnit
fun TemporaryTarget.isInProgress(dateUtil: DateUtil): Boolean =
dateUtil.now() in timestamp..timestamp + duration
fun TemporaryTarget.lowValueToUnitsToString(units: GlucoseUnit): String =
if (units == GlucoseUnit.MGDL) DecimalFormatter.to0Decimal(this.lowTarget)
else DecimalFormatter.to1Decimal(this.lowTarget * Constants.MGDL_TO_MMOLL)

View file

@ -1,19 +0,0 @@
package info.nightscout.androidaps.extensions
import info.nightscout.core.main.R
import info.nightscout.database.entities.UserEntry.ColorGroup
fun ColorGroup.colorId(): Int {
return when (this) {
ColorGroup.InsulinTreatment -> R.color.basal
ColorGroup.CarbTreatment -> R.color.carbs
ColorGroup.TT -> R.color.tempTargetConfirmation
ColorGroup.Profile -> R.color.white
ColorGroup.Loop -> R.color.loopClosed
ColorGroup.Careportal -> R.color.high
ColorGroup.Pump -> R.color.iob
ColorGroup.Aaps -> R.color.defaultText
else -> R.color.defaultText
}
}

View file

@ -1,6 +1,7 @@
package info.nightscout.implementation.di
import android.content.Context
import dagger.Binds
import dagger.Lazy
import dagger.Module
import dagger.Provides
@ -10,19 +11,38 @@ import info.nightscout.core.graph.OverviewData
import info.nightscout.core.utils.CryptoUtil
import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.database.impl.AppRepository
import info.nightscout.implementation.AndroidPermissionImpl
import info.nightscout.implementation.BolusTimerImpl
import info.nightscout.implementation.CarbTimerImpl
import info.nightscout.implementation.DefaultValueHelperImpl
import info.nightscout.implementation.HardLimitsImpl
import info.nightscout.implementation.LocalAlertUtilsImpl
import info.nightscout.implementation.TranslatorImpl
import info.nightscout.implementation.TrendCalculatorImpl
import info.nightscout.implementation.XDripBroadcastImpl
import info.nightscout.implementation.androidNotification.NotificationHolderImpl
import info.nightscout.implementation.logging.LoggerUtilsImpl
import info.nightscout.implementation.maintenance.PrefFileListProviderImpl
import info.nightscout.implementation.overview.OverviewDataImpl
import info.nightscout.implementation.profiling.ProfilerImpl
import info.nightscout.implementation.protection.PasswordCheckImpl
import info.nightscout.implementation.protection.ProtectionCheckImpl
import info.nightscout.implementation.pump.PumpSyncImplementation
import info.nightscout.implementation.pump.WarnColorsImpl
import info.nightscout.implementation.queue.CommandQueueImplementation
import info.nightscout.implementation.resources.IconsProviderImplementation
import info.nightscout.implementation.resources.ResourceHelperImpl
import info.nightscout.implementation.stats.DexcomTirCalculatorImpl
import info.nightscout.implementation.stats.TddCalculatorImpl
import info.nightscout.implementation.stats.TirCalculatorImpl
import info.nightscout.interfaces.AndroidPermission
import info.nightscout.interfaces.BolusTimer
import info.nightscout.interfaces.CarbTimer
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.LocalAlertUtils
import info.nightscout.interfaces.NotificationHolder
import info.nightscout.interfaces.Translator
import info.nightscout.interfaces.XDripBroadcast
import info.nightscout.interfaces.logging.LoggerUtils
import info.nightscout.interfaces.maintenance.PrefFileListProvider
import info.nightscout.interfaces.plugin.ActivePlugin
@ -31,9 +51,16 @@ import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.profiling.Profiler
import info.nightscout.interfaces.protection.PasswordCheck
import info.nightscout.interfaces.protection.ProtectionCheck
import info.nightscout.interfaces.pump.PumpSync
import info.nightscout.interfaces.pump.WarnColors
import info.nightscout.interfaces.queue.CommandQueue
import info.nightscout.interfaces.stats.DexcomTirCalculator
import info.nightscout.interfaces.stats.TddCalculator
import info.nightscout.interfaces.stats.TirCalculator
import info.nightscout.interfaces.storage.Storage
import info.nightscout.interfaces.ui.IconsProvider
import info.nightscout.interfaces.utils.HardLimits
import info.nightscout.interfaces.utils.TrendCalculator
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.shared.interfaces.ResourceHelper
@ -111,4 +138,21 @@ open class ImplementationModule {
versionCheckerUtils: VersionCheckerUtils,
context: Context
): PrefFileListProvider = PrefFileListProviderImpl(rh, config, encryptedPrefsFormat, storage, versionCheckerUtils, context)
@Module
interface Bindings {
@Binds fun bindTrendCalculatorInterface(trendCalculator: TrendCalculatorImpl): TrendCalculator
@Binds fun bindTddCalculatorInterface(tddCalculator: TddCalculatorImpl): TddCalculator
@Binds fun bindTirCalculatorInterface(tirCalculator: TirCalculatorImpl): TirCalculator
@Binds fun bindDexcomTirCalculatorInterface(dexcomTirCalculator: DexcomTirCalculatorImpl): DexcomTirCalculator
@Binds fun bindPumpSyncInterface(pumpSyncImplementation: PumpSyncImplementation): PumpSync
@Binds fun bindXDripBroadcastInterface(xDripBroadcastImpl: XDripBroadcastImpl): XDripBroadcast
@Binds fun bindCarbTimerInterface(carbTimer: CarbTimerImpl): CarbTimer
@Binds fun bindBolusTimerInterface(bolusTimer: BolusTimerImpl): BolusTimer
@Binds fun bindAndroidPermissionInterface(androidPermission: AndroidPermissionImpl): AndroidPermission
@Binds fun bindLocalAlertUtilsInterface(localAlertUtils: LocalAlertUtilsImpl): LocalAlertUtils
@Binds fun bindIconsProviderInterface(iconsProvider: IconsProviderImplementation): IconsProvider
@Binds fun bindNotificationHolderInterface(notificationHolder: NotificationHolderImpl): NotificationHolder
@Binds fun bindCommandQueue(commandQueue: CommandQueueImplementation): CommandQueue
}
}

View file

@ -9,7 +9,6 @@ import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.stats.DexcomTIR
import info.nightscout.interfaces.stats.DexcomTirCalculator
import info.nightscout.interfaces.utils.MidnightTime
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
import info.nightscout.shared.utils.T
import javax.inject.Inject
@ -17,7 +16,6 @@ import javax.inject.Singleton
@Singleton
class DexcomTirCalculatorImpl @Inject constructor(
private val rh: ResourceHelper,
private val profileFunction: ProfileFunction,
private val dateUtil: DateUtil,
private val repository: AppRepository

View file

@ -8,8 +8,6 @@ import android.view.ViewGroup
import android.widget.TableLayout
import android.widget.TableRow
import android.widget.TextView
import info.nightscout.androidaps.extensions.toTableRow
import info.nightscout.androidaps.extensions.toTableRowHeader
import info.nightscout.database.entities.Bolus
import info.nightscout.database.entities.TotalDailyDose
import info.nightscout.database.entities.embedments.InterfaceIDs

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.extensions
package info.nightscout.implementation.stats
import android.annotation.SuppressLint
import android.content.Context

View file

@ -15,7 +15,6 @@ import android.widget.TableLayout
import android.widget.TableRow
import android.widget.TextView
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
import info.nightscout.androidaps.extensions.total
import info.nightscout.core.main.R
import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.database.entities.TotalDailyDose
@ -228,6 +227,9 @@ class TDDStatsActivity : NoSplashAppCompatActivity() {
return super.dispatchTouchEvent(event)
}
private val TotalDailyDose.total
get() = if (totalAmount > 0) totalAmount else basalAmount + bolusAmount
@SuppressLint("SetTextI18n")
private fun loadDataFromDB() {
historyList.clear()