diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefsImpl.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefsImpl.kt index af3f9aaac8..495042ed26 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefsImpl.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefsImpl.kt @@ -29,10 +29,10 @@ import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.general.maintenance.formats.EncryptedPrefsFormat import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.alertDialogs.PrefImportSummaryDialog -import info.nightscout.androidaps.utils.alertDialogs.TwoMessagesAlertDialog import info.nightscout.androidaps.utils.protection.PasswordCheck import info.nightscout.androidaps.utils.userEntry.UserEntryPresentationHelper import info.nightscout.core.ui.dialogs.OKDialog +import info.nightscout.core.ui.dialogs.TwoMessagesAlertDialog import info.nightscout.database.entities.UserEntry import info.nightscout.database.entities.UserEntry.Action import info.nightscout.database.entities.UserEntry.Sources diff --git a/app/src/main/java/info/nightscout/androidaps/utils/ui/SpinnerHelper.kt b/app/src/main/java/info/nightscout/androidaps/utils/ui/SpinnerHelper.kt deleted file mode 100644 index 3623e8cf0c..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/utils/ui/SpinnerHelper.kt +++ /dev/null @@ -1,4 +0,0 @@ -@file:Suppress("SpellCheckingInspection") - -package info.nightscout.androidaps.utils.ui - diff --git a/core/core-main/src/main/java/info/nightscout/androidaps/utils/WarnColors.kt b/core/core-main/src/main/java/info/nightscout/androidaps/utils/WarnColors.kt deleted file mode 100644 index 5788becbb7..0000000000 --- a/core/core-main/src/main/java/info/nightscout/androidaps/utils/WarnColors.kt +++ /dev/null @@ -1,34 +0,0 @@ -package info.nightscout.androidaps.utils - -import android.widget.TextView -import info.nightscout.androidaps.extensions.isOlderThan -import info.nightscout.core.main.R -import info.nightscout.database.entities.TherapyEvent -import info.nightscout.shared.interfaces.ResourceHelper -import javax.inject.Inject -import javax.inject.Singleton - -@Singleton -class WarnColors @Inject constructor(val rh: ResourceHelper) { - - fun setColor(view: TextView?, value: Double, warnLevel: Double, urgentLevel: Double) = - view?.setTextColor( rh.gac( view.context ,when { - value >= urgentLevel -> R.attr.urgentColor - value >= warnLevel -> R.attr.warnColor - else -> R.attr.defaultTextColor - })) - - fun setColorInverse(view: TextView?, value: Double, warnLevel: Double, urgentLevel: Double) = - view?.setTextColor( rh.gac( view.context , when { - value <= urgentLevel -> R.attr.urgentColor - value <= warnLevel -> R.attr.warnColor - else -> R.attr.defaultTextColor - })) - - fun setColorByAge(view: TextView?, therapyEvent: TherapyEvent, warnThreshold: Double, urgentThreshold: Double) = - view?.setTextColor( rh.gac( view.context , when { - therapyEvent.isOlderThan(urgentThreshold) -> R.attr.lowColor - therapyEvent.isOlderThan(warnThreshold) -> R.attr.highColor - else -> R.attr.defaultTextColor - })) -} diff --git a/app/src/main/java/info/nightscout/androidaps/utils/alertDialogs/TwoMessagesAlertDialog.kt b/core/ui/src/main/java/info/nightscout/core/ui/dialogs/TwoMessagesAlertDialog.kt similarity index 84% rename from app/src/main/java/info/nightscout/androidaps/utils/alertDialogs/TwoMessagesAlertDialog.kt rename to core/ui/src/main/java/info/nightscout/core/ui/dialogs/TwoMessagesAlertDialog.kt index 9662a575c9..797daaa926 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/alertDialogs/TwoMessagesAlertDialog.kt +++ b/core/ui/src/main/java/info/nightscout/core/ui/dialogs/TwoMessagesAlertDialog.kt @@ -1,19 +1,24 @@ -package info.nightscout.androidaps.utils.alertDialogs +package info.nightscout.core.ui.dialogs import android.annotation.SuppressLint import android.content.Context import android.content.DialogInterface +import android.os.Handler +import android.os.Looper import android.os.SystemClock import android.view.LayoutInflater import android.view.View import android.widget.TextView import androidx.annotation.DrawableRes import com.google.android.material.dialog.MaterialAlertDialogBuilder -import info.nightscout.androidaps.R -import info.nightscout.shared.extensions.runOnUiThread +import info.nightscout.core.ui.R object TwoMessagesAlertDialog { + private fun runOnUiThread(theRunnable: Runnable?) = theRunnable?.let { + Handler(Looper.getMainLooper()).post(it) + } + @SuppressLint("InflateParams") fun showAlert(context: Context, title: String, message: String, secondMessage: String, ok: (() -> Unit)?, cancel: (() -> Unit)? = null, @DrawableRes icon: Int? = null) { @@ -23,7 +28,7 @@ object TwoMessagesAlertDialog { MaterialAlertDialogBuilder(context, R.style.DialogTheme) .setMessage(message) .setCustomTitle( - info.nightscout.core.ui.dialogs.AlertDialogHelper.buildCustomTitle( + AlertDialogHelper.buildCustomTitle( context, title, icon ?: R.drawable.ic_check_white_48dp ) diff --git a/plugins/src/main/java/info/nightscout/plugins/ui/SpinnerHelper.kt b/core/ui/src/main/java/info/nightscout/core/ui/elements/SpinnerHelper.kt similarity index 99% rename from plugins/src/main/java/info/nightscout/plugins/ui/SpinnerHelper.kt rename to core/ui/src/main/java/info/nightscout/core/ui/elements/SpinnerHelper.kt index 0d38c47e19..e0d1efbf6a 100644 --- a/plugins/src/main/java/info/nightscout/plugins/ui/SpinnerHelper.kt +++ b/core/ui/src/main/java/info/nightscout/core/ui/elements/SpinnerHelper.kt @@ -1,4 +1,4 @@ -package info.nightscout.plugins.ui +package info.nightscout.core.ui.elements import android.view.MotionEvent import android.view.View diff --git a/app/src/main/java/info/nightscout/androidaps/utils/extensions/RadioGroupExtension.kt b/core/ui/src/main/java/info/nightscout/core/ui/extensions/RadioGroupExtension.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/extensions/RadioGroupExtension.kt rename to core/ui/src/main/java/info/nightscout/core/ui/extensions/RadioGroupExtension.kt diff --git a/app/src/main/res/layout/dialog_alert_two_messages.xml b/core/ui/src/main/res/layout/dialog_alert_two_messages.xml similarity index 100% rename from app/src/main/res/layout/dialog_alert_two_messages.xml rename to core/ui/src/main/res/layout/dialog_alert_two_messages.xml diff --git a/implementation/src/main/java/info/nightscout/implementation/di/ImplementationModule.kt b/implementation/src/main/java/info/nightscout/implementation/di/ImplementationModule.kt index e6cf6101c2..0b9d93e0f9 100644 --- a/implementation/src/main/java/info/nightscout/implementation/di/ImplementationModule.kt +++ b/implementation/src/main/java/info/nightscout/implementation/di/ImplementationModule.kt @@ -6,7 +6,9 @@ import dagger.Provides import info.nightscout.core.fabric.FabricPrivacy import info.nightscout.database.impl.AppRepository import info.nightscout.implementation.HardLimitsImpl +import info.nightscout.implementation.pump.WarnColorsImpl import info.nightscout.implementation.resources.ResourceHelperImpl +import info.nightscout.interfaces.pump.WarnColors import info.nightscout.interfaces.utils.HardLimits import info.nightscout.rx.bus.RxBus import info.nightscout.rx.logging.AAPSLogger @@ -32,4 +34,8 @@ open class ImplementationModule { @Singleton fun provideHardLimits(aapsLogger: AAPSLogger, rxBus: RxBus, sp: SP, rh: ResourceHelper, context: Context, repository: AppRepository): HardLimits = HardLimitsImpl(aapsLogger, rxBus, sp, rh, context, repository) + + @Provides + @Singleton + fun provideWarnColors(rh: ResourceHelper): WarnColors = WarnColorsImpl(rh) } \ No newline at end of file diff --git a/implementation/src/main/java/info/nightscout/implementation/pump/WarnColorsImpl.kt b/implementation/src/main/java/info/nightscout/implementation/pump/WarnColorsImpl.kt new file mode 100644 index 0000000000..27c64201e4 --- /dev/null +++ b/implementation/src/main/java/info/nightscout/implementation/pump/WarnColorsImpl.kt @@ -0,0 +1,50 @@ +package info.nightscout.implementation.pump + +import android.widget.TextView +import info.nightscout.androidaps.extensions.isOlderThan +import info.nightscout.core.main.R +import info.nightscout.database.entities.TherapyEvent +import info.nightscout.interfaces.pump.WarnColors +import info.nightscout.shared.interfaces.ResourceHelper +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class WarnColorsImpl @Inject constructor(val rh: ResourceHelper): WarnColors { + + override fun setColor(view: TextView?, value: Double, warnLevel: Double, urgentLevel: Double) { + view?.setTextColor( + rh.gac( + view.context, when { + value >= urgentLevel -> R.attr.urgentColor + value >= warnLevel -> R.attr.warnColor + else -> R.attr.defaultTextColor + } + ) + ) + } + + override fun setColorInverse(view: TextView?, value: Double, warnLevel: Double, urgentLevel: Double) { + view?.setTextColor( + rh.gac( + view.context, when { + value <= urgentLevel -> R.attr.urgentColor + value <= warnLevel -> R.attr.warnColor + else -> R.attr.defaultTextColor + } + ) + ) + } + + override fun setColorByAge(view: TextView?, therapyEvent: TherapyEvent, warnThreshold: Double, urgentThreshold: Double) { + view?.setTextColor( + rh.gac( + view.context, when { + therapyEvent.isOlderThan(urgentThreshold) -> R.attr.lowColor + therapyEvent.isOlderThan(warnThreshold) -> R.attr.highColor + else -> R.attr.defaultTextColor + } + ) + ) + } +} diff --git a/interfaces/src/main/java/info/nightscout/interfaces/pump/WarnColors.kt b/interfaces/src/main/java/info/nightscout/interfaces/pump/WarnColors.kt new file mode 100644 index 0000000000..8a7a8adf9f --- /dev/null +++ b/interfaces/src/main/java/info/nightscout/interfaces/pump/WarnColors.kt @@ -0,0 +1,10 @@ +package info.nightscout.interfaces.pump + +import android.widget.TextView +import info.nightscout.database.entities.TherapyEvent + +interface WarnColors { + fun setColor(view: TextView?, value: Double, warnLevel: Double, urgentLevel: Double) + fun setColorInverse(view: TextView?, value: Double, warnLevel: Double, urgentLevel: Double) + fun setColorByAge(view: TextView?, therapyEvent: TherapyEvent, warnThreshold: Double, urgentThreshold: Double) +} \ No newline at end of file diff --git a/plugins/src/main/java/info/nightscout/plugins/ui/StatusLightHandler.kt b/plugins/src/main/java/info/nightscout/plugins/ui/StatusLightHandler.kt index 2c9bb5da2b..643b214913 100644 --- a/plugins/src/main/java/info/nightscout/plugins/ui/StatusLightHandler.kt +++ b/plugins/src/main/java/info/nightscout/plugins/ui/StatusLightHandler.kt @@ -3,12 +3,12 @@ package info.nightscout.plugins.ui import android.widget.TextView import androidx.annotation.StringRes import info.nightscout.androidaps.utils.DecimalFormatter -import info.nightscout.androidaps.utils.WarnColors import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.Config import info.nightscout.interfaces.plugin.ActivePlugin +import info.nightscout.interfaces.pump.WarnColors import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.plugins.R import info.nightscout.plugins.sync.nsclient.extensions.age diff --git a/plugins/src/main/java/info/nightscout/plugins/ui/TimeListEdit.java b/plugins/src/main/java/info/nightscout/plugins/ui/TimeListEdit.java index 6b6d7c35ff..848145d58a 100644 --- a/plugins/src/main/java/info/nightscout/plugins/ui/TimeListEdit.java +++ b/plugins/src/main/java/info/nightscout/plugins/ui/TimeListEdit.java @@ -24,11 +24,12 @@ import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; -import info.nightscout.shared.utils.DateUtil; import info.nightscout.androidaps.utils.ui.NumberPicker; +import info.nightscout.core.ui.elements.SpinnerHelper; import info.nightscout.plugins.R; import info.nightscout.rx.logging.AAPSLogger; import info.nightscout.shared.SafeParse; +import info.nightscout.shared.utils.DateUtil; /** * Created by mike on 29.12.2016. diff --git a/pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt b/pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt index 05f6290474..245a79164b 100644 --- a/pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt +++ b/pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt @@ -15,7 +15,6 @@ import info.nightscout.androidaps.dana.activities.DanaUserOptionsActivity import info.nightscout.androidaps.dana.databinding.DanarFragmentBinding import info.nightscout.androidaps.dana.events.EventDanaRNewStatus import info.nightscout.androidaps.logging.UserEntryLogger -import info.nightscout.androidaps.utils.WarnColors import info.nightscout.androidaps.utils.userEntry.UserEntryMapper.Action import info.nightscout.androidaps.utils.userEntry.UserEntryMapper.Sources import info.nightscout.core.fabric.FabricPrivacy @@ -23,6 +22,7 @@ import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.pump.Dana import info.nightscout.interfaces.pump.Pump +import info.nightscout.interfaces.pump.WarnColors import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.interfaces.queue.CommandQueue import info.nightscout.interfaces.ui.ActivityNames diff --git a/pump/diaconn/src/main/java/info/nightscout/androidaps/diaconn/DiaconnG8Fragment.kt b/pump/diaconn/src/main/java/info/nightscout/androidaps/diaconn/DiaconnG8Fragment.kt index 3cb55f408e..2c10ee7b60 100644 --- a/pump/diaconn/src/main/java/info/nightscout/androidaps/diaconn/DiaconnG8Fragment.kt +++ b/pump/diaconn/src/main/java/info/nightscout/androidaps/diaconn/DiaconnG8Fragment.kt @@ -13,10 +13,10 @@ import info.nightscout.androidaps.diaconn.activities.DiaconnG8HistoryActivity import info.nightscout.androidaps.diaconn.activities.DiaconnG8UserOptionsActivity import info.nightscout.androidaps.diaconn.databinding.DiaconnG8FragmentBinding import info.nightscout.androidaps.diaconn.events.EventDiaconnG8NewStatus -import info.nightscout.androidaps.utils.WarnColors import info.nightscout.core.fabric.FabricPrivacy import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.pump.Pump +import info.nightscout.interfaces.pump.WarnColors import info.nightscout.interfaces.queue.CommandQueue import info.nightscout.interfaces.ui.ActivityNames import info.nightscout.rx.AapsSchedulers diff --git a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt index 191c2df260..216a0e0ded 100644 --- a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt +++ b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt @@ -22,11 +22,11 @@ import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpSta import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpConfigurationChanged import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpValuesChanged import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil -import info.nightscout.androidaps.utils.WarnColors import info.nightscout.core.fabric.FabricPrivacy import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.pump.PumpSync +import info.nightscout.interfaces.pump.WarnColors import info.nightscout.interfaces.queue.Callback import info.nightscout.interfaces.queue.CommandQueue import info.nightscout.pump.core.defs.PumpDeviceState