diff --git a/app/build.gradle b/app/build.gradle index d94df5f5f1..67924f5289 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -99,7 +99,7 @@ def allCommitted = { -> android { - namespace 'info.nightscout.androidaps' + namespace 'app.aaps' ndkVersion "21.1.6352462" defaultConfig { diff --git a/app/src/main/kotlin/app/aaps/MainActivity.kt b/app/src/main/kotlin/app/aaps/MainActivity.kt index fcb1e69c17..1ccd5e2a35 100644 --- a/app/src/main/kotlin/app/aaps/MainActivity.kt +++ b/app/src/main/kotlin/app/aaps/MainActivity.kt @@ -59,22 +59,20 @@ import app.aaps.core.ui.toast.ToastUtils import app.aaps.core.utils.isRunningRealPumpTest import app.aaps.database.entities.UserEntry.Action import app.aaps.database.entities.UserEntry.Sources +import app.aaps.databinding.ActivityMainBinding import app.aaps.plugins.configuration.activities.DaggerAppCompatActivityWithResult import app.aaps.plugins.configuration.activities.SingleFragmentActivity import app.aaps.plugins.configuration.setupwizard.SetupWizardActivity import app.aaps.plugins.constraints.signatureVerifier.SignatureVerifierPlugin +import app.aaps.ui.activities.ProfileHelperActivity +import app.aaps.ui.activities.StatsActivity +import app.aaps.ui.activities.TreatmentsActivity +import app.aaps.ui.tabs.TabPageAdapter import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.tabs.TabLayoutMediator import com.google.firebase.crashlytics.FirebaseCrashlytics import com.joanzapata.iconify.Iconify import com.joanzapata.iconify.fonts.FontAwesomeModule -import info.nightscout.androidaps.BuildConfig -import info.nightscout.androidaps.R -import info.nightscout.androidaps.databinding.ActivityMainBinding -import app.aaps.ui.activities.ProfileHelperActivity -import app.aaps.ui.activities.StatsActivity -import app.aaps.ui.activities.TreatmentsActivity -import app.aaps.ui.tabs.TabPageAdapter import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import java.io.File diff --git a/app/src/main/kotlin/app/aaps/MainApp.kt b/app/src/main/kotlin/app/aaps/MainApp.kt index 3621ae4c12..f2bae3284c 100644 --- a/app/src/main/kotlin/app/aaps/MainApp.kt +++ b/app/src/main/kotlin/app/aaps/MainApp.kt @@ -42,15 +42,13 @@ import app.aaps.receivers.BTReceiver import app.aaps.receivers.ChargingStateReceiver import app.aaps.receivers.KeepAliveWorker import app.aaps.receivers.TimeDateOrTZChangeReceiver +import app.aaps.ui.activityMonitor.ActivityMonitor +import app.aaps.ui.widget.Widget import dagger.android.AndroidInjector import dagger.android.DaggerApplication -import info.nightscout.androidaps.BuildConfig -import info.nightscout.androidaps.R import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.transactions.InsertIfNewByTimestampTherapyEventTransaction import info.nightscout.database.impl.transactions.VersionChangeTransaction -import app.aaps.ui.activityMonitor.ActivityMonitor -import app.aaps.ui.widget.Widget import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.exceptions.UndeliverableException import io.reactivex.rxjava3.kotlin.plusAssign diff --git a/app/src/main/kotlin/app/aaps/activities/HistoryBrowseActivity.kt b/app/src/main/kotlin/app/aaps/activities/HistoryBrowseActivity.kt index aa64fe3aa8..5ab29d1384 100644 --- a/app/src/main/kotlin/app/aaps/activities/HistoryBrowseActivity.kt +++ b/app/src/main/kotlin/app/aaps/activities/HistoryBrowseActivity.kt @@ -30,11 +30,11 @@ import app.aaps.core.main.events.EventIobCalculationProgress import app.aaps.core.main.utils.fabric.FabricPrivacy import app.aaps.core.main.workflow.CalculationWorkflow import app.aaps.core.ui.activities.TranslatedDaggerAppCompatActivity +import app.aaps.databinding.ActivityHistorybrowseBinding import app.aaps.plugins.main.general.overview.graphData.GraphData import com.google.android.material.datepicker.MaterialDatePicker import com.jjoe64.graphview.GraphView import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.databinding.ActivityHistorybrowseBinding import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import java.util.Calendar diff --git a/app/src/main/kotlin/app/aaps/activities/MyPreferenceFragment.kt b/app/src/main/kotlin/app/aaps/activities/MyPreferenceFragment.kt index 96cbbf2728..7167a8fdb9 100644 --- a/app/src/main/kotlin/app/aaps/activities/MyPreferenceFragment.kt +++ b/app/src/main/kotlin/app/aaps/activities/MyPreferenceFragment.kt @@ -15,6 +15,7 @@ import androidx.preference.PreferenceGroup import androidx.preference.PreferenceManager import androidx.preference.PreferenceScreen import androidx.preference.size +import app.aaps.R import app.aaps.core.interfaces.configuration.Config import app.aaps.core.interfaces.nsclient.NSSettingsStatus import app.aaps.core.interfaces.plugin.PluginBase @@ -60,7 +61,6 @@ import app.aaps.plugins.sync.openhumans.OpenHumansUploaderPlugin import app.aaps.plugins.sync.tidepool.TidepoolPlugin import app.aaps.plugins.sync.xdrip.XdripPlugin import dagger.android.support.AndroidSupportInjection -import info.nightscout.androidaps.R import info.nightscout.androidaps.danaRKorean.DanaRKoreanPlugin import info.nightscout.androidaps.danaRv2.DanaRv2Plugin import info.nightscout.androidaps.danar.DanaRPlugin diff --git a/app/src/main/kotlin/app/aaps/activities/PreferencesActivity.kt b/app/src/main/kotlin/app/aaps/activities/PreferencesActivity.kt index 656146f503..13ee750747 100644 --- a/app/src/main/kotlin/app/aaps/activities/PreferencesActivity.kt +++ b/app/src/main/kotlin/app/aaps/activities/PreferencesActivity.kt @@ -8,9 +8,9 @@ import androidx.appcompat.widget.SearchView import androidx.core.view.MenuProvider import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceScreen +import app.aaps.R +import app.aaps.databinding.ActivityPreferencesBinding import app.aaps.plugins.configuration.activities.DaggerAppCompatActivityWithResult -import info.nightscout.androidaps.R -import info.nightscout.androidaps.databinding.ActivityPreferencesBinding class PreferencesActivity : DaggerAppCompatActivityWithResult(), PreferenceFragmentCompat.OnPreferenceStartScreenCallback { diff --git a/app/src/main/kotlin/app/aaps/implementations/ConfigImpl.kt b/app/src/main/kotlin/app/aaps/implementations/ConfigImpl.kt index d729a327f5..7102b9ab80 100644 --- a/app/src/main/kotlin/app/aaps/implementations/ConfigImpl.kt +++ b/app/src/main/kotlin/app/aaps/implementations/ConfigImpl.kt @@ -1,10 +1,10 @@ package app.aaps.implementations import android.os.Build +import app.aaps.BuildConfig +import app.aaps.R import app.aaps.core.interfaces.configuration.Config import app.aaps.core.interfaces.maintenance.PrefFileListProvider -import info.nightscout.androidaps.BuildConfig -import info.nightscout.androidaps.R import java.io.File import javax.inject.Inject import javax.inject.Singleton diff --git a/app/src/main/kotlin/app/aaps/implementations/UiInteractionImpl.kt b/app/src/main/kotlin/app/aaps/implementations/UiInteractionImpl.kt index b7d41ceda3..774c88d9c0 100644 --- a/app/src/main/kotlin/app/aaps/implementations/UiInteractionImpl.kt +++ b/app/src/main/kotlin/app/aaps/implementations/UiInteractionImpl.kt @@ -7,6 +7,7 @@ import androidx.annotation.RawRes import androidx.annotation.StringRes import androidx.fragment.app.FragmentManager import app.aaps.MainActivity +import app.aaps.R import app.aaps.activities.HistoryBrowseActivity import app.aaps.activities.MyPreferenceFragment import app.aaps.activities.PreferencesActivity @@ -18,8 +19,6 @@ import app.aaps.core.main.events.EventNewNotification import app.aaps.core.ui.toast.ToastUtils import app.aaps.plugins.configuration.activities.SingleFragmentActivity import app.aaps.plugins.main.general.overview.notifications.NotificationWithAction -import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R import app.aaps.ui.activities.BolusProgressHelperActivity import app.aaps.ui.activities.ErrorHelperActivity import app.aaps.ui.activities.QuickWizardListActivity @@ -41,6 +40,7 @@ import app.aaps.ui.dialogs.WizardDialog import app.aaps.ui.services.AlarmSoundService import app.aaps.ui.services.AlarmSoundServiceHelper import app.aaps.ui.widget.Widget +import dagger.android.HasAndroidInjector import javax.inject.Inject class UiInteractionImpl @Inject constructor( diff --git a/app/src/main/kotlin/app/aaps/receivers/KeepAliveWorker.kt b/app/src/main/kotlin/app/aaps/receivers/KeepAliveWorker.kt index 0483f61d56..fcefc76ec7 100644 --- a/app/src/main/kotlin/app/aaps/receivers/KeepAliveWorker.kt +++ b/app/src/main/kotlin/app/aaps/receivers/KeepAliveWorker.kt @@ -9,6 +9,7 @@ import androidx.work.WorkManager import androidx.work.WorkQuery import androidx.work.WorkerParameters import androidx.work.workDataOf +import app.aaps.R import app.aaps.core.interfaces.alerts.LocalAlertUtils import app.aaps.core.interfaces.aps.Loop import app.aaps.core.interfaces.configuration.Config @@ -28,7 +29,6 @@ import app.aaps.core.main.profile.ProfileSealed import app.aaps.core.main.utils.worker.LoggingWorker import app.aaps.plugins.configuration.maintenance.MaintenancePlugin import com.google.common.util.concurrent.ListenableFuture -import info.nightscout.androidaps.R import info.nightscout.database.impl.AppRepository import kotlinx.coroutines.Dispatchers import java.util.concurrent.TimeUnit diff --git a/core/utils/src/main/kotlin/app/aaps/core/utils/EspressoTestHelper.kt b/core/utils/src/main/kotlin/app/aaps/core/utils/EspressoTestHelper.kt index f4f79f8824..9804c491af 100644 --- a/core/utils/src/main/kotlin/app/aaps/core/utils/EspressoTestHelper.kt +++ b/core/utils/src/main/kotlin/app/aaps/core/utils/EspressoTestHelper.kt @@ -13,7 +13,7 @@ fun isRunningTest(): Boolean { @Synchronized fun isRunningRealPumpTest(): Boolean { return try { - Class.forName("info.nightscout.androidaps.RealPumpTest") + Class.forName("app.aaps.RealPumpTest") true } catch (e: ClassNotFoundException) { false diff --git a/wear/build.gradle b/wear/build.gradle index 4b98278a83..61a7da54d7 100644 --- a/wear/build.gradle +++ b/wear/build.gradle @@ -80,7 +80,7 @@ android { versionName version + "-aapsclient" } } - namespace 'info.nightscout.androidaps' + namespace 'app.aaps.wear' } allprojects { diff --git a/wear/src/main/java/info/nightscout/androidaps/WearApp.kt b/wear/src/main/kotlin/app/aaps/wear/WearApp.kt similarity index 83% rename from wear/src/main/java/info/nightscout/androidaps/WearApp.kt rename to wear/src/main/kotlin/app/aaps/wear/WearApp.kt index 56a213a15a..fd752670ae 100644 --- a/wear/src/main/java/info/nightscout/androidaps/WearApp.kt +++ b/wear/src/main/kotlin/app/aaps/wear/WearApp.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps +package app.aaps.wear import android.content.Intent import android.content.SharedPreferences @@ -8,19 +8,20 @@ import androidx.preference.PreferenceManager import app.aaps.core.interfaces.logging.AAPSLogger import app.aaps.core.interfaces.logging.LTag import app.aaps.core.interfaces.rx.bus.RxBus +import app.aaps.wear.comm.DataHandlerWear +import app.aaps.wear.comm.DataLayerListenerServiceWear +import app.aaps.wear.comm.ExceptionHandlerWear +import app.aaps.wear.di.DaggerWearComponent +import app.aaps.wear.events.EventWearPreferenceChange import dagger.android.AndroidInjector import dagger.android.DaggerApplication -import info.nightscout.androidaps.comm.DataHandlerWear -import info.nightscout.androidaps.comm.DataLayerListenerServiceWear -import info.nightscout.androidaps.comm.ExceptionHandlerWear -import info.nightscout.androidaps.di.DaggerWearComponent -import info.nightscout.androidaps.events.EventWearPreferenceChange import javax.inject.Inject class WearApp : DaggerApplication(), OnSharedPreferenceChangeListener { @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var rxBus: RxBus + @Suppress("unused") @Inject lateinit var dataHandlerWear: DataHandlerWear // instantiate only @Inject lateinit var exceptionHandlerWear: ExceptionHandlerWear diff --git a/wear/src/main/java/info/nightscout/androidaps/comm/DataHandlerWear.kt b/wear/src/main/kotlin/app/aaps/wear/comm/DataHandlerWear.kt similarity index 96% rename from wear/src/main/java/info/nightscout/androidaps/comm/DataHandlerWear.kt rename to wear/src/main/kotlin/app/aaps/wear/comm/DataHandlerWear.kt index dfa3a28565..119fc92587 100644 --- a/wear/src/main/java/info/nightscout/androidaps/comm/DataHandlerWear.kt +++ b/wear/src/main/kotlin/app/aaps/wear/comm/DataHandlerWear.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.comm +package app.aaps.wear.comm import android.annotation.TargetApi import android.app.Notification @@ -22,15 +22,15 @@ import app.aaps.core.interfaces.rx.events.EventWearDataToMobile import app.aaps.core.interfaces.rx.events.EventWearToMobile import app.aaps.core.interfaces.rx.weardata.EventData import app.aaps.core.interfaces.sharedPreferences.SP +import app.aaps.wear.R +import app.aaps.wear.interaction.WatchfaceConfigurationActivity +import app.aaps.wear.interaction.actions.AcceptActivity +import app.aaps.wear.interaction.actions.ProfileSwitchActivity +import app.aaps.wear.interaction.utils.Persistence +import app.aaps.wear.tile.ActionsTileService +import app.aaps.wear.tile.QuickWizardTileService +import app.aaps.wear.tile.TempTargetTileService import com.google.android.gms.wearable.WearableListenerService -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.WatchfaceConfigurationActivity -import info.nightscout.androidaps.interaction.actions.AcceptActivity -import info.nightscout.androidaps.interaction.actions.ProfileSwitchActivity -import info.nightscout.androidaps.interaction.utils.Persistence -import info.nightscout.androidaps.tile.ActionsTileService -import info.nightscout.androidaps.tile.QuickWizardTileService -import info.nightscout.androidaps.tile.TempTargetTileService import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import javax.inject.Inject diff --git a/wear/src/main/java/info/nightscout/androidaps/comm/DataLayerListenerServiceWear.kt b/wear/src/main/kotlin/app/aaps/wear/comm/DataLayerListenerServiceWear.kt similarity index 98% rename from wear/src/main/java/info/nightscout/androidaps/comm/DataLayerListenerServiceWear.kt rename to wear/src/main/kotlin/app/aaps/wear/comm/DataLayerListenerServiceWear.kt index 238e60ea67..11914555ad 100644 --- a/wear/src/main/java/info/nightscout/androidaps/comm/DataLayerListenerServiceWear.kt +++ b/wear/src/main/kotlin/app/aaps/wear/comm/DataLayerListenerServiceWear.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.comm +package app.aaps.wear.comm import android.app.NotificationManager import android.content.Intent @@ -13,6 +13,8 @@ import app.aaps.core.interfaces.rx.events.EventWearDataToMobile import app.aaps.core.interfaces.rx.events.EventWearToMobile import app.aaps.core.interfaces.rx.weardata.EventData import app.aaps.core.interfaces.sharedPreferences.SP +import app.aaps.wear.interaction.utils.Persistence +import app.aaps.wear.interaction.utils.WearUtil import com.google.android.gms.tasks.Tasks import com.google.android.gms.wearable.CapabilityClient import com.google.android.gms.wearable.CapabilityInfo @@ -25,8 +27,6 @@ import com.google.android.gms.wearable.PutDataMapRequest import com.google.android.gms.wearable.Wearable import com.google.android.gms.wearable.WearableListenerService import dagger.android.AndroidInjection -import info.nightscout.androidaps.interaction.utils.Persistence -import info.nightscout.androidaps.interaction.utils.WearUtil import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import kotlinx.coroutines.CancellationException diff --git a/wear/src/main/java/info/nightscout/androidaps/comm/ExceptionHandlerWear.kt b/wear/src/main/kotlin/app/aaps/wear/comm/ExceptionHandlerWear.kt similarity index 95% rename from wear/src/main/java/info/nightscout/androidaps/comm/ExceptionHandlerWear.kt rename to wear/src/main/kotlin/app/aaps/wear/comm/ExceptionHandlerWear.kt index 986ec34c24..5ff6468d70 100644 --- a/wear/src/main/java/info/nightscout/androidaps/comm/ExceptionHandlerWear.kt +++ b/wear/src/main/kotlin/app/aaps/wear/comm/ExceptionHandlerWear.kt @@ -1,70 +1,70 @@ -package info.nightscout.androidaps.comm - -import android.os.Build -import android.util.Log -import app.aaps.core.interfaces.rx.bus.RxBus -import app.aaps.core.interfaces.rx.events.EventWearToMobile -import app.aaps.core.interfaces.rx.weardata.EventData -import java.io.ByteArrayOutputStream -import java.io.IOException -import java.io.ObjectOutputStream -import javax.inject.Inject - -class ExceptionHandlerWear @Inject constructor( - private val rxBus: RxBus, -) { - - private var mDefaultUEH: Thread.UncaughtExceptionHandler? = null - - private val mWearUEH = Thread.UncaughtExceptionHandler { thread, ex -> - Log.d("WEAR", "uncaughtException :" + ex.message) - - // Pass the exception to the bus which will send the data upstream to your Smartphone/Tablet - val wearException = EventData.WearException( - timeStamp = System.currentTimeMillis(), - exception = exceptionToByteArray(ex), - board = Build.BOARD, - sdk = Build.VERSION.SDK_INT.toString(), - fingerprint = Build.FINGERPRINT, - model = Build.MODEL, - manufacturer = Build.MANUFACTURER, - product = Build.PRODUCT - ) - rxBus.send(EventWearToMobile(wearException)) - - // Let the default UncaughtExceptionHandler take it from here - mDefaultUEH?.uncaughtException(thread, ex) - } - - fun register() { - mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler() - Thread.setDefaultUncaughtExceptionHandler(mWearUEH) - } - - private fun exceptionToByteArray(ex: Throwable): ByteArray { - ex.stackTrace // Make sure the stacktrace gets built up - val bos = ByteArrayOutputStream() - var oos: ObjectOutputStream? = null - try { - oos = ObjectOutputStream(bos) - oos.writeObject(ex) - return bos.toByteArray() - - } catch (e: IOException) { - e.printStackTrace() - } finally { - try { - oos?.close() - } catch (exx: IOException) { - // Ignore close exception - } - try { - bos.close() - } catch (exx: IOException) { - // Ignore close exception - } - } - return byteArrayOf() - } - -} +package app.aaps.wear.comm + +import android.os.Build +import android.util.Log +import app.aaps.core.interfaces.rx.bus.RxBus +import app.aaps.core.interfaces.rx.events.EventWearToMobile +import app.aaps.core.interfaces.rx.weardata.EventData +import java.io.ByteArrayOutputStream +import java.io.IOException +import java.io.ObjectOutputStream +import javax.inject.Inject + +class ExceptionHandlerWear @Inject constructor( + private val rxBus: RxBus, +) { + + private var mDefaultUEH: Thread.UncaughtExceptionHandler? = null + + private val mWearUEH = Thread.UncaughtExceptionHandler { thread, ex -> + Log.d("WEAR", "uncaughtException :" + ex.message) + + // Pass the exception to the bus which will send the data upstream to your Smartphone/Tablet + val wearException = EventData.WearException( + timeStamp = System.currentTimeMillis(), + exception = exceptionToByteArray(ex), + board = Build.BOARD, + sdk = Build.VERSION.SDK_INT.toString(), + fingerprint = Build.FINGERPRINT, + model = Build.MODEL, + manufacturer = Build.MANUFACTURER, + product = Build.PRODUCT + ) + rxBus.send(EventWearToMobile(wearException)) + + // Let the default UncaughtExceptionHandler take it from here + mDefaultUEH?.uncaughtException(thread, ex) + } + + fun register() { + mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler() + Thread.setDefaultUncaughtExceptionHandler(mWearUEH) + } + + private fun exceptionToByteArray(ex: Throwable): ByteArray { + ex.stackTrace // Make sure the stacktrace gets built up + val bos = ByteArrayOutputStream() + var oos: ObjectOutputStream? = null + try { + oos = ObjectOutputStream(bos) + oos.writeObject(ex) + return bos.toByteArray() + + } catch (e: IOException) { + e.printStackTrace() + } finally { + try { + oos?.close() + } catch (exx: IOException) { + // Ignore close exception + } + try { + bos.close() + } catch (exx: IOException) { + // Ignore close exception + } + } + return byteArrayOf() + } + +} diff --git a/wear/src/main/java/info/nightscout/androidaps/comm/IntentCancelNotification.kt b/wear/src/main/kotlin/app/aaps/wear/comm/IntentCancelNotification.kt similarity index 88% rename from wear/src/main/java/info/nightscout/androidaps/comm/IntentCancelNotification.kt rename to wear/src/main/kotlin/app/aaps/wear/comm/IntentCancelNotification.kt index 3c8b557ceb..2efac6b4b4 100644 --- a/wear/src/main/java/info/nightscout/androidaps/comm/IntentCancelNotification.kt +++ b/wear/src/main/kotlin/app/aaps/wear/comm/IntentCancelNotification.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.comm +package app.aaps.wear.comm import android.content.Context import android.content.Intent diff --git a/wear/src/main/java/info/nightscout/androidaps/comm/IntentWearToMobile.kt b/wear/src/main/kotlin/app/aaps/wear/comm/IntentWearToMobile.kt similarity index 94% rename from wear/src/main/java/info/nightscout/androidaps/comm/IntentWearToMobile.kt rename to wear/src/main/kotlin/app/aaps/wear/comm/IntentWearToMobile.kt index 7ee0b94f82..faf93f77e9 100644 --- a/wear/src/main/java/info/nightscout/androidaps/comm/IntentWearToMobile.kt +++ b/wear/src/main/kotlin/app/aaps/wear/comm/IntentWearToMobile.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.comm +package app.aaps.wear.comm import android.content.Context import android.content.Intent diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/BaseComplicationProviderService.kt b/wear/src/main/kotlin/app/aaps/wear/complications/BaseComplicationProviderService.kt similarity index 95% rename from wear/src/main/java/info/nightscout/androidaps/complications/BaseComplicationProviderService.kt rename to wear/src/main/kotlin/app/aaps/wear/complications/BaseComplicationProviderService.kt index ccfa9e908d..60b2ff748d 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/BaseComplicationProviderService.kt +++ b/wear/src/main/kotlin/app/aaps/wear/complications/BaseComplicationProviderService.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.complications +package app.aaps.wear.complications import android.app.PendingIntent import android.content.BroadcastReceiver @@ -20,17 +20,17 @@ import app.aaps.core.interfaces.logging.LTag import app.aaps.core.interfaces.rx.bus.RxBus import app.aaps.core.interfaces.rx.events.EventWearToMobile import app.aaps.core.interfaces.rx.weardata.EventData.ActionResendData +import app.aaps.wear.R +import app.aaps.wear.comm.DataLayerListenerServiceWear.Companion.INTENT_NEW_DATA +import app.aaps.wear.complications.ComplicationTapBroadcastReceiver.Companion.getTapActionIntent +import app.aaps.wear.complications.ComplicationTapBroadcastReceiver.Companion.getTapWarningSinceIntent +import app.aaps.wear.data.RawDisplayData +import app.aaps.wear.interaction.utils.Constants +import app.aaps.wear.interaction.utils.DisplayFormat +import app.aaps.wear.interaction.utils.Inevitable +import app.aaps.wear.interaction.utils.Persistence +import app.aaps.wear.interaction.utils.WearUtil import dagger.android.AndroidInjection -import info.nightscout.androidaps.R -import info.nightscout.androidaps.comm.DataLayerListenerServiceWear.Companion.INTENT_NEW_DATA -import info.nightscout.androidaps.complications.ComplicationTapBroadcastReceiver.Companion.getTapActionIntent -import info.nightscout.androidaps.complications.ComplicationTapBroadcastReceiver.Companion.getTapWarningSinceIntent -import info.nightscout.androidaps.data.RawDisplayData -import info.nightscout.androidaps.interaction.utils.Constants -import info.nightscout.androidaps.interaction.utils.DisplayFormat -import info.nightscout.androidaps.interaction.utils.Inevitable -import info.nightscout.androidaps.interaction.utils.Persistence -import info.nightscout.androidaps.interaction.utils.WearUtil import javax.inject.Inject /** diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/BrCobIobComplication.kt b/wear/src/main/kotlin/app/aaps/wear/complications/BrCobIobComplication.kt similarity index 87% rename from wear/src/main/java/info/nightscout/androidaps/complications/BrCobIobComplication.kt rename to wear/src/main/kotlin/app/aaps/wear/complications/BrCobIobComplication.kt index 3870679499..6120b6db10 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/BrCobIobComplication.kt +++ b/wear/src/main/kotlin/app/aaps/wear/complications/BrCobIobComplication.kt @@ -1,15 +1,15 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.complications +package app.aaps.wear.complications import android.app.PendingIntent import android.support.wearable.complications.ComplicationData import android.support.wearable.complications.ComplicationText import app.aaps.core.interfaces.logging.LTag +import app.aaps.wear.data.RawDisplayData +import app.aaps.wear.interaction.utils.DisplayFormat +import app.aaps.wear.interaction.utils.SmallestDoubleString import dagger.android.AndroidInjection -import info.nightscout.androidaps.data.RawDisplayData -import info.nightscout.androidaps.interaction.utils.DisplayFormat -import info.nightscout.androidaps.interaction.utils.SmallestDoubleString import kotlin.math.max /* diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/CobDetailedComplication.kt b/wear/src/main/kotlin/app/aaps/wear/complications/CobDetailedComplication.kt similarity index 93% rename from wear/src/main/java/info/nightscout/androidaps/complications/CobDetailedComplication.kt rename to wear/src/main/kotlin/app/aaps/wear/complications/CobDetailedComplication.kt index a7234e6850..48527c14e2 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/CobDetailedComplication.kt +++ b/wear/src/main/kotlin/app/aaps/wear/complications/CobDetailedComplication.kt @@ -1,12 +1,12 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.complications +package app.aaps.wear.complications import android.app.PendingIntent import android.support.wearable.complications.ComplicationData import android.support.wearable.complications.ComplicationText import app.aaps.core.interfaces.logging.LTag -import info.nightscout.androidaps.data.RawDisplayData +import app.aaps.wear.data.RawDisplayData /* * Created by dlvoy on 2019-11-12 diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/CobIconComplication.kt b/wear/src/main/kotlin/app/aaps/wear/complications/CobIconComplication.kt similarity index 91% rename from wear/src/main/java/info/nightscout/androidaps/complications/CobIconComplication.kt rename to wear/src/main/kotlin/app/aaps/wear/complications/CobIconComplication.kt index b9ed4a7d98..b12692e67b 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/CobIconComplication.kt +++ b/wear/src/main/kotlin/app/aaps/wear/complications/CobIconComplication.kt @@ -1,14 +1,14 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.complications +package app.aaps.wear.complications import android.app.PendingIntent import android.graphics.drawable.Icon import android.support.wearable.complications.ComplicationData import android.support.wearable.complications.ComplicationText import app.aaps.core.interfaces.logging.LTag -import info.nightscout.androidaps.R -import info.nightscout.androidaps.data.RawDisplayData +import app.aaps.wear.R +import app.aaps.wear.data.RawDisplayData /* * Created by dlvoy on 2019-11-12 diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/CobIobComplication.kt b/wear/src/main/kotlin/app/aaps/wear/complications/CobIobComplication.kt similarity index 84% rename from wear/src/main/java/info/nightscout/androidaps/complications/CobIobComplication.kt rename to wear/src/main/kotlin/app/aaps/wear/complications/CobIobComplication.kt index f7c3c75cf1..9193e707f9 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/CobIobComplication.kt +++ b/wear/src/main/kotlin/app/aaps/wear/complications/CobIobComplication.kt @@ -1,14 +1,14 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.complications +package app.aaps.wear.complications import android.app.PendingIntent import android.support.wearable.complications.ComplicationData import android.support.wearable.complications.ComplicationText import app.aaps.core.interfaces.logging.LTag -import info.nightscout.androidaps.data.RawDisplayData -import info.nightscout.androidaps.interaction.utils.DisplayFormat -import info.nightscout.androidaps.interaction.utils.SmallestDoubleString +import app.aaps.wear.data.RawDisplayData +import app.aaps.wear.interaction.utils.DisplayFormat +import app.aaps.wear.interaction.utils.SmallestDoubleString /* * Created by dlvoy on 2019-11-12 diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/ComplicationAction.kt b/wear/src/main/kotlin/app/aaps/wear/complications/ComplicationAction.kt similarity index 68% rename from wear/src/main/java/info/nightscout/androidaps/complications/ComplicationAction.kt rename to wear/src/main/kotlin/app/aaps/wear/complications/ComplicationAction.kt index 5ad6c80ee7..0bfd241596 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/ComplicationAction.kt +++ b/wear/src/main/kotlin/app/aaps/wear/complications/ComplicationAction.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.complications +package app.aaps.wear.complications enum class ComplicationAction { NONE, MENU, WIZARD, BOLUS, E_CARB, STATUS, WARNING_SYNC, WARNING_OLD diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/ComplicationTapBroadcastReceiver.kt b/wear/src/main/kotlin/app/aaps/wear/complications/ComplicationTapBroadcastReceiver.kt similarity index 91% rename from wear/src/main/java/info/nightscout/androidaps/complications/ComplicationTapBroadcastReceiver.kt rename to wear/src/main/kotlin/app/aaps/wear/complications/ComplicationTapBroadcastReceiver.kt index a0e43a27db..8a34dc7a9c 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/ComplicationTapBroadcastReceiver.kt +++ b/wear/src/main/kotlin/app/aaps/wear/complications/ComplicationTapBroadcastReceiver.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.complications +package app.aaps.wear.complications import android.app.PendingIntent import android.content.ComponentName @@ -12,16 +12,16 @@ import androidx.annotation.StringRes import app.aaps.core.interfaces.logging.AAPSLogger import app.aaps.core.interfaces.logging.LTag import app.aaps.core.interfaces.sharedPreferences.SP +import app.aaps.wear.R +import app.aaps.wear.interaction.actions.ECarbActivity +import app.aaps.wear.interaction.actions.TreatmentActivity +import app.aaps.wear.interaction.actions.WizardActivity +import app.aaps.wear.interaction.menus.MainMenuActivity +import app.aaps.wear.interaction.menus.StatusMenuActivity +import app.aaps.wear.interaction.utils.Constants +import app.aaps.wear.interaction.utils.DisplayFormat +import app.aaps.wear.interaction.utils.WearUtil import dagger.android.DaggerBroadcastReceiver -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.actions.ECarbActivity -import info.nightscout.androidaps.interaction.actions.TreatmentActivity -import info.nightscout.androidaps.interaction.actions.WizardActivity -import info.nightscout.androidaps.interaction.menus.MainMenuActivity -import info.nightscout.androidaps.interaction.menus.StatusMenuActivity -import info.nightscout.androidaps.interaction.utils.Constants -import info.nightscout.androidaps.interaction.utils.DisplayFormat -import info.nightscout.androidaps.interaction.utils.WearUtil import javax.inject.Inject /* diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/IobDetailedComplication.kt b/wear/src/main/kotlin/app/aaps/wear/complications/IobDetailedComplication.kt similarity index 93% rename from wear/src/main/java/info/nightscout/androidaps/complications/IobDetailedComplication.kt rename to wear/src/main/kotlin/app/aaps/wear/complications/IobDetailedComplication.kt index 7f49b8b46b..5addf73ae2 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/IobDetailedComplication.kt +++ b/wear/src/main/kotlin/app/aaps/wear/complications/IobDetailedComplication.kt @@ -1,12 +1,12 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.complications +package app.aaps.wear.complications import android.app.PendingIntent import android.support.wearable.complications.ComplicationData import android.support.wearable.complications.ComplicationText import app.aaps.core.interfaces.logging.LTag -import info.nightscout.androidaps.data.RawDisplayData +import app.aaps.wear.data.RawDisplayData /* * Created by dlvoy on 2019-11-12 diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/IobIconComplication.kt b/wear/src/main/kotlin/app/aaps/wear/complications/IobIconComplication.kt similarity index 84% rename from wear/src/main/java/info/nightscout/androidaps/complications/IobIconComplication.kt rename to wear/src/main/kotlin/app/aaps/wear/complications/IobIconComplication.kt index 24db065872..804550298c 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/IobIconComplication.kt +++ b/wear/src/main/kotlin/app/aaps/wear/complications/IobIconComplication.kt @@ -1,16 +1,16 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.complications +package app.aaps.wear.complications import android.app.PendingIntent import android.graphics.drawable.Icon import android.support.wearable.complications.ComplicationData import android.support.wearable.complications.ComplicationText import app.aaps.core.interfaces.logging.LTag -import info.nightscout.androidaps.R -import info.nightscout.androidaps.data.RawDisplayData -import info.nightscout.androidaps.interaction.utils.DisplayFormat -import info.nightscout.androidaps.interaction.utils.SmallestDoubleString +import app.aaps.wear.R +import app.aaps.wear.data.RawDisplayData +import app.aaps.wear.interaction.utils.DisplayFormat +import app.aaps.wear.interaction.utils.SmallestDoubleString /* * Created by dlvoy on 2019-11-12 diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/LongStatusComplication.kt b/wear/src/main/kotlin/app/aaps/wear/complications/LongStatusComplication.kt similarity index 94% rename from wear/src/main/java/info/nightscout/androidaps/complications/LongStatusComplication.kt rename to wear/src/main/kotlin/app/aaps/wear/complications/LongStatusComplication.kt index 308047b0cb..ad8567066a 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/LongStatusComplication.kt +++ b/wear/src/main/kotlin/app/aaps/wear/complications/LongStatusComplication.kt @@ -1,13 +1,13 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.complications +package app.aaps.wear.complications import android.app.PendingIntent import android.support.wearable.complications.ComplicationData import android.support.wearable.complications.ComplicationText import app.aaps.core.interfaces.logging.LTag +import app.aaps.wear.data.RawDisplayData import dagger.android.AndroidInjection -import info.nightscout.androidaps.data.RawDisplayData /* * Created by dlvoy on 2019-11-12 diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/LongStatusFlippedComplication.kt b/wear/src/main/kotlin/app/aaps/wear/complications/LongStatusFlippedComplication.kt similarity index 94% rename from wear/src/main/java/info/nightscout/androidaps/complications/LongStatusFlippedComplication.kt rename to wear/src/main/kotlin/app/aaps/wear/complications/LongStatusFlippedComplication.kt index 179d4017f2..e5107094e0 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/LongStatusFlippedComplication.kt +++ b/wear/src/main/kotlin/app/aaps/wear/complications/LongStatusFlippedComplication.kt @@ -1,13 +1,13 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.complications +package app.aaps.wear.complications import android.app.PendingIntent import android.support.wearable.complications.ComplicationData import android.support.wearable.complications.ComplicationText import app.aaps.core.interfaces.logging.LTag +import app.aaps.wear.data.RawDisplayData import dagger.android.AndroidInjection -import info.nightscout.androidaps.data.RawDisplayData /* * Created by dlvoy on 2019-11-12 diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/SgvComplication.kt b/wear/src/main/kotlin/app/aaps/wear/complications/SgvComplication.kt similarity index 93% rename from wear/src/main/java/info/nightscout/androidaps/complications/SgvComplication.kt rename to wear/src/main/kotlin/app/aaps/wear/complications/SgvComplication.kt index fd6c1b3fb1..ede42b0bba 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/SgvComplication.kt +++ b/wear/src/main/kotlin/app/aaps/wear/complications/SgvComplication.kt @@ -1,13 +1,13 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.complications +package app.aaps.wear.complications import android.app.PendingIntent import android.support.wearable.complications.ComplicationData import android.support.wearable.complications.ComplicationText import app.aaps.core.interfaces.logging.LTag +import app.aaps.wear.data.RawDisplayData import dagger.android.AndroidInjection -import info.nightscout.androidaps.data.RawDisplayData /* * Created by dlvoy on 2019-11-12 diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/UploaderBatteryComplication.kt b/wear/src/main/kotlin/app/aaps/wear/complications/UploaderBatteryComplication.kt similarity index 97% rename from wear/src/main/java/info/nightscout/androidaps/complications/UploaderBatteryComplication.kt rename to wear/src/main/kotlin/app/aaps/wear/complications/UploaderBatteryComplication.kt index 1db261478f..d540205600 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/UploaderBatteryComplication.kt +++ b/wear/src/main/kotlin/app/aaps/wear/complications/UploaderBatteryComplication.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.complications +package app.aaps.wear.complications import android.app.PendingIntent import android.graphics.drawable.Icon @@ -8,8 +8,8 @@ import android.support.wearable.complications.ComplicationData import android.support.wearable.complications.ComplicationText import androidx.annotation.DrawableRes import app.aaps.core.interfaces.logging.LTag -import info.nightscout.androidaps.R -import info.nightscout.androidaps.data.RawDisplayData +import app.aaps.wear.R +import app.aaps.wear.data.RawDisplayData import kotlin.math.floor import kotlin.math.max import kotlin.math.min diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/WallpaperComplication.kt b/wear/src/main/kotlin/app/aaps/wear/complications/WallpaperComplication.kt similarity index 94% rename from wear/src/main/java/info/nightscout/androidaps/complications/WallpaperComplication.kt rename to wear/src/main/kotlin/app/aaps/wear/complications/WallpaperComplication.kt index d4ea563947..559ecc3160 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/WallpaperComplication.kt +++ b/wear/src/main/kotlin/app/aaps/wear/complications/WallpaperComplication.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.complications +package app.aaps.wear.complications import android.app.PendingIntent import android.graphics.Bitmap @@ -10,7 +10,7 @@ import android.support.wearable.complications.ComplicationData import android.util.DisplayMetrics import android.view.WindowManager import app.aaps.core.interfaces.logging.LTag -import info.nightscout.androidaps.data.RawDisplayData +import app.aaps.wear.data.RawDisplayData import java.io.IOException /* diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/WallpaperDarkComplication.kt b/wear/src/main/kotlin/app/aaps/wear/complications/WallpaperDarkComplication.kt similarity index 88% rename from wear/src/main/java/info/nightscout/androidaps/complications/WallpaperDarkComplication.kt rename to wear/src/main/kotlin/app/aaps/wear/complications/WallpaperDarkComplication.kt index ccc6159694..1e469b3140 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/WallpaperDarkComplication.kt +++ b/wear/src/main/kotlin/app/aaps/wear/complications/WallpaperDarkComplication.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.complications +package app.aaps.wear.complications /* * Created by dlvoy on 2019-11-12 diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/WallpaperGrayComplication.kt b/wear/src/main/kotlin/app/aaps/wear/complications/WallpaperGrayComplication.kt similarity index 88% rename from wear/src/main/java/info/nightscout/androidaps/complications/WallpaperGrayComplication.kt rename to wear/src/main/kotlin/app/aaps/wear/complications/WallpaperGrayComplication.kt index ff2028d01b..029d7a64db 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/WallpaperGrayComplication.kt +++ b/wear/src/main/kotlin/app/aaps/wear/complications/WallpaperGrayComplication.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.complications +package app.aaps.wear.complications /* * Created by dlvoy on 2019-11-12 diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/WallpaperLightComplication.kt b/wear/src/main/kotlin/app/aaps/wear/complications/WallpaperLightComplication.kt similarity index 88% rename from wear/src/main/java/info/nightscout/androidaps/complications/WallpaperLightComplication.kt rename to wear/src/main/kotlin/app/aaps/wear/complications/WallpaperLightComplication.kt index 9ac71e953a..22dc797469 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/WallpaperLightComplication.kt +++ b/wear/src/main/kotlin/app/aaps/wear/complications/WallpaperLightComplication.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.complications +package app.aaps.wear.complications /* * Created by dlvoy on 2019-11-12 diff --git a/wear/src/main/java/info/nightscout/androidaps/data/RawDisplayData.kt b/wear/src/main/kotlin/app/aaps/wear/data/RawDisplayData.kt similarity index 94% rename from wear/src/main/java/info/nightscout/androidaps/data/RawDisplayData.kt rename to wear/src/main/kotlin/app/aaps/wear/data/RawDisplayData.kt index f692831d53..14678b2135 100644 --- a/wear/src/main/java/info/nightscout/androidaps/data/RawDisplayData.kt +++ b/wear/src/main/kotlin/app/aaps/wear/data/RawDisplayData.kt @@ -1,7 +1,7 @@ -package info.nightscout.androidaps.data +package app.aaps.wear.data import app.aaps.core.interfaces.rx.weardata.EventData -import info.nightscout.androidaps.interaction.utils.Persistence +import app.aaps.wear.interaction.utils.Persistence /** * Holds bunch of data model variables and lists that arrive from phone app and are due to be diff --git a/wear/src/main/java/info/nightscout/androidaps/di/WearActivitiesModule.kt b/wear/src/main/kotlin/app/aaps/wear/di/WearActivitiesModule.kt similarity index 63% rename from wear/src/main/java/info/nightscout/androidaps/di/WearActivitiesModule.kt rename to wear/src/main/kotlin/app/aaps/wear/di/WearActivitiesModule.kt index dac10f8011..8e5c5c6078 100644 --- a/wear/src/main/java/info/nightscout/androidaps/di/WearActivitiesModule.kt +++ b/wear/src/main/kotlin/app/aaps/wear/di/WearActivitiesModule.kt @@ -1,16 +1,26 @@ -package info.nightscout.androidaps.di +package app.aaps.wear.di +import app.aaps.wear.interaction.ConfigurationActivity +import app.aaps.wear.interaction.TileConfigurationActivity +import app.aaps.wear.interaction.actions.AcceptActivity +import app.aaps.wear.interaction.actions.BackgroundActionActivity +import app.aaps.wear.interaction.actions.BolusActivity +import app.aaps.wear.interaction.actions.CarbActivity +import app.aaps.wear.interaction.actions.ECarbActivity +import app.aaps.wear.interaction.actions.FillActivity +import app.aaps.wear.interaction.actions.ProfileSwitchActivity +import app.aaps.wear.interaction.actions.QuickSnoozeActivity +import app.aaps.wear.interaction.actions.TempTargetActivity +import app.aaps.wear.interaction.actions.TreatmentActivity +import app.aaps.wear.interaction.actions.ViewSelectorActivity +import app.aaps.wear.interaction.actions.WizardActivity +import app.aaps.wear.interaction.menus.FillMenuActivity +import app.aaps.wear.interaction.menus.MainMenuActivity +import app.aaps.wear.interaction.menus.PreferenceMenuActivity +import app.aaps.wear.interaction.menus.StatusMenuActivity +import app.aaps.wear.interaction.utils.MenuListActivity import dagger.Module import dagger.android.ContributesAndroidInjector -import info.nightscout.androidaps.interaction.actions.QuickSnoozeActivity -import info.nightscout.androidaps.interaction.ConfigurationActivity -import info.nightscout.androidaps.interaction.TileConfigurationActivity -import info.nightscout.androidaps.interaction.actions.* -import info.nightscout.androidaps.interaction.menus.FillMenuActivity -import info.nightscout.androidaps.interaction.menus.MainMenuActivity -import info.nightscout.androidaps.interaction.menus.PreferenceMenuActivity -import info.nightscout.androidaps.interaction.menus.StatusMenuActivity -import info.nightscout.androidaps.interaction.utils.MenuListActivity @Module @Suppress("unused") diff --git a/wear/src/main/java/info/nightscout/androidaps/di/WearComponent.kt b/wear/src/main/kotlin/app/aaps/wear/di/WearComponent.kt similarity index 86% rename from wear/src/main/java/info/nightscout/androidaps/di/WearComponent.kt rename to wear/src/main/kotlin/app/aaps/wear/di/WearComponent.kt index 8a27a7719d..5b81047595 100644 --- a/wear/src/main/java/info/nightscout/androidaps/di/WearComponent.kt +++ b/wear/src/main/kotlin/app/aaps/wear/di/WearComponent.kt @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.di +package app.aaps.wear.di +import app.aaps.wear.WearApp import dagger.BindsInstance import dagger.Component import dagger.android.AndroidInjectionModule import dagger.android.AndroidInjector -import info.nightscout.androidaps.WearApp import javax.inject.Singleton @Singleton diff --git a/wear/src/main/java/info/nightscout/androidaps/di/WearModule.kt b/wear/src/main/kotlin/app/aaps/wear/di/WearModule.kt similarity index 88% rename from wear/src/main/java/info/nightscout/androidaps/di/WearModule.kt rename to wear/src/main/kotlin/app/aaps/wear/di/WearModule.kt index 78e7cf7985..a3267870be 100644 --- a/wear/src/main/java/info/nightscout/androidaps/di/WearModule.kt +++ b/wear/src/main/kotlin/app/aaps/wear/di/WearModule.kt @@ -1,12 +1,12 @@ -package info.nightscout.androidaps.di +package app.aaps.wear.di import android.content.Context import app.aaps.shared.impl.di.SharedImplModule +import app.aaps.wear.WearApp import dagger.Binds import dagger.Module import dagger.Provides import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.WearApp import kotlinx.datetime.Clock @Suppress("unused") diff --git a/wear/src/main/java/info/nightscout/androidaps/di/WearServicesModule.kt b/wear/src/main/kotlin/app/aaps/wear/di/WearServicesModule.kt similarity index 65% rename from wear/src/main/java/info/nightscout/androidaps/di/WearServicesModule.kt rename to wear/src/main/kotlin/app/aaps/wear/di/WearServicesModule.kt index 3cc8baa387..ea11f0b81c 100644 --- a/wear/src/main/java/info/nightscout/androidaps/di/WearServicesModule.kt +++ b/wear/src/main/kotlin/app/aaps/wear/di/WearServicesModule.kt @@ -1,13 +1,37 @@ -package info.nightscout.androidaps.di +package app.aaps.wear.di +import app.aaps.wear.comm.DataLayerListenerServiceWear +import app.aaps.wear.complications.BaseComplicationProviderService +import app.aaps.wear.complications.BrCobIobComplication +import app.aaps.wear.complications.CobDetailedComplication +import app.aaps.wear.complications.CobIconComplication +import app.aaps.wear.complications.CobIobComplication +import app.aaps.wear.complications.ComplicationTapBroadcastReceiver +import app.aaps.wear.complications.IobDetailedComplication +import app.aaps.wear.complications.IobIconComplication +import app.aaps.wear.complications.LongStatusComplication +import app.aaps.wear.complications.LongStatusFlippedComplication +import app.aaps.wear.complications.SgvComplication +import app.aaps.wear.complications.UploaderBatteryComplication +import app.aaps.wear.complications.WallpaperComplication +import app.aaps.wear.heartrate.HeartRateListener +import app.aaps.wear.tile.ActionsTileService +import app.aaps.wear.tile.QuickWizardTileService +import app.aaps.wear.tile.TempTargetTileService +import app.aaps.wear.tile.TileBase +import app.aaps.wear.watchfaces.AapsLargeWatchface +import app.aaps.wear.watchfaces.AapsV2Watchface +import app.aaps.wear.watchfaces.AapsWatchface +import app.aaps.wear.watchfaces.BigChartWatchface +import app.aaps.wear.watchfaces.CircleWatchface +import app.aaps.wear.watchfaces.CockpitWatchface +import app.aaps.wear.watchfaces.CustomWatchface +import app.aaps.wear.watchfaces.DigitalStyleWatchface +import app.aaps.wear.watchfaces.NoChartWatchface +import app.aaps.wear.watchfaces.SteampunkWatchface +import app.aaps.wear.watchfaces.utils.BaseWatchFace import dagger.Module import dagger.android.ContributesAndroidInjector -import info.nightscout.androidaps.comm.DataLayerListenerServiceWear -import info.nightscout.androidaps.complications.* -import info.nightscout.androidaps.heartrate.HeartRateListener -import info.nightscout.androidaps.tile.* -import info.nightscout.androidaps.watchfaces.* -import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace @Module @Suppress("unused") @@ -36,7 +60,6 @@ abstract class WearServicesModule { @ContributesAndroidInjector abstract fun contributesSteampunk(): SteampunkWatchface @ContributesAndroidInjector abstract fun contributesDigitalStyleWatchface(): DigitalStyleWatchface @ContributesAndroidInjector abstract fun contributesCockpitWatchface(): CockpitWatchface - @ContributesAndroidInjector abstract fun contributesBIGChart(): BigChartWatchface @ContributesAndroidInjector abstract fun contributesNOChart(): NoChartWatchface @ContributesAndroidInjector abstract fun contributesCircleWatchface(): CircleWatchface diff --git a/wear/src/main/java/info/nightscout/androidaps/events/EventWearPreferenceChange.kt b/wear/src/main/kotlin/app/aaps/wear/events/EventWearPreferenceChange.kt similarity index 92% rename from wear/src/main/java/info/nightscout/androidaps/events/EventWearPreferenceChange.kt rename to wear/src/main/kotlin/app/aaps/wear/events/EventWearPreferenceChange.kt index 2c1bf496cc..693fabfd81 100644 --- a/wear/src/main/java/info/nightscout/androidaps/events/EventWearPreferenceChange.kt +++ b/wear/src/main/kotlin/app/aaps/wear/events/EventWearPreferenceChange.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.events +package app.aaps.wear.events import android.content.Context import app.aaps.core.interfaces.rx.events.Event diff --git a/wear/src/main/java/info/nightscout/androidaps/heartrate/HeartRateListener.kt b/wear/src/main/kotlin/app/aaps/wear/heartrate/HeartRateListener.kt similarity index 98% rename from wear/src/main/java/info/nightscout/androidaps/heartrate/HeartRateListener.kt rename to wear/src/main/kotlin/app/aaps/wear/heartrate/HeartRateListener.kt index 37ac13bcf7..4679813a06 100644 --- a/wear/src/main/java/info/nightscout/androidaps/heartrate/HeartRateListener.kt +++ b/wear/src/main/kotlin/app/aaps/wear/heartrate/HeartRateListener.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.heartrate +package app.aaps.wear.heartrate import android.content.Context import android.content.Context.SENSOR_SERVICE @@ -12,7 +12,7 @@ import app.aaps.core.interfaces.logging.AAPSLogger import app.aaps.core.interfaces.logging.LTag import app.aaps.core.interfaces.rx.AapsSchedulers import app.aaps.core.interfaces.rx.weardata.EventData -import info.nightscout.androidaps.comm.IntentWearToMobile +import app.aaps.wear.comm.IntentWearToMobile import io.reactivex.rxjava3.disposables.Disposable import java.util.concurrent.TimeUnit import java.util.concurrent.locks.ReentrantLock diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/ConfigurationActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/ConfigurationActivity.kt similarity index 94% rename from wear/src/main/java/info/nightscout/androidaps/interaction/ConfigurationActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/ConfigurationActivity.kt index b29a6c3f58..6c6d6d1ff1 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/ConfigurationActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/ConfigurationActivity.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.interaction +package app.aaps.wear.interaction import android.os.Bundle import android.view.View @@ -6,8 +6,8 @@ import android.view.ViewGroup import androidx.core.content.ContextCompat import app.aaps.core.interfaces.logging.AAPSLogger import app.aaps.core.interfaces.logging.LTag +import app.aaps.wear.R import dagger.android.AndroidInjection -import info.nightscout.androidaps.R import preference.WearPreferenceActivity import javax.inject.Inject diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/TileConfigurationActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/TileConfigurationActivity.kt similarity index 92% rename from wear/src/main/java/info/nightscout/androidaps/interaction/TileConfigurationActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/TileConfigurationActivity.kt index ad2a06c8b4..e6f6f93a54 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/TileConfigurationActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/TileConfigurationActivity.kt @@ -1,13 +1,13 @@ -package info.nightscout.androidaps.interaction +package app.aaps.wear.interaction import android.os.Bundle import android.view.ViewGroup import androidx.wear.tiles.TileService import app.aaps.core.interfaces.logging.AAPSLogger import app.aaps.core.interfaces.logging.LTag +import app.aaps.wear.tile.ActionsTileService +import app.aaps.wear.tile.TempTargetTileService import dagger.android.AndroidInjection -import info.nightscout.androidaps.tile.ActionsTileService -import info.nightscout.androidaps.tile.TempTargetTileService import preference.WearPreferenceActivity import javax.inject.Inject diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/WatchfaceConfigurationActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/WatchfaceConfigurationActivity.kt similarity index 97% rename from wear/src/main/java/info/nightscout/androidaps/interaction/WatchfaceConfigurationActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/WatchfaceConfigurationActivity.kt index 946d2f87db..e22f825dcc 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/WatchfaceConfigurationActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/WatchfaceConfigurationActivity.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.interaction +package app.aaps.wear.interaction import android.Manifest import android.content.SharedPreferences @@ -11,7 +11,7 @@ import androidx.core.content.ContextCompat import androidx.preference.PreferenceManager import app.aaps.core.interfaces.logging.AAPSLogger import app.aaps.core.interfaces.logging.LTag -import info.nightscout.androidaps.R +import app.aaps.wear.R import preference.WearPreferenceActivity import javax.inject.Inject diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/AcceptActivity.kt similarity index 92% rename from wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/actions/AcceptActivity.kt index fcdd45b818..0f762c08dc 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/AcceptActivity.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.interaction.actions +package app.aaps.wear.interaction.actions import android.content.Intent import android.os.Bundle @@ -16,11 +16,11 @@ import android.widget.TextView import androidx.core.view.InputDeviceCompat import androidx.core.view.MotionEventCompat import androidx.core.view.ViewConfigurationCompat -import info.nightscout.androidaps.R -import info.nightscout.androidaps.comm.DataLayerListenerServiceWear -import info.nightscout.androidaps.comm.IntentCancelNotification -import info.nightscout.androidaps.comm.IntentWearToMobile -import info.nightscout.androidaps.nondeprecated.GridPagerAdapterNonDeprecated +import app.aaps.wear.R +import app.aaps.wear.comm.DataLayerListenerServiceWear +import app.aaps.wear.comm.IntentCancelNotification +import app.aaps.wear.comm.IntentWearToMobile +import app.aaps.wear.nondeprecated.GridPagerAdapterNonDeprecated import kotlin.math.roundToInt class AcceptActivity : ViewSelectorActivity() { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BackgroundActionActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/BackgroundActionActivity.kt similarity index 90% rename from wear/src/main/java/info/nightscout/androidaps/interaction/actions/BackgroundActionActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/actions/BackgroundActionActivity.kt index 01713b5fd6..01949a6ad6 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BackgroundActionActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/BackgroundActionActivity.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.interaction.actions +package app.aaps.wear.interaction.actions import android.os.Bundle import android.widget.Toast @@ -7,8 +7,8 @@ import app.aaps.core.interfaces.logging.LTag import app.aaps.core.interfaces.rx.bus.RxBus import app.aaps.core.interfaces.rx.events.EventWearToMobile import app.aaps.core.interfaces.rx.weardata.EventData +import app.aaps.wear.comm.DataLayerListenerServiceWear import dagger.android.DaggerActivity -import info.nightscout.androidaps.comm.DataLayerListenerServiceWear import javax.inject.Inject class BackgroundActionActivity : DaggerActivity() { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/BolusActivity.kt similarity index 90% rename from wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/actions/BolusActivity.kt index 580e17db4f..99085c6470 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/BolusActivity.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.interaction.actions +package app.aaps.wear.interaction.actions import android.os.Bundle import android.view.LayoutInflater @@ -10,10 +10,10 @@ import android.widget.ImageView import app.aaps.core.interfaces.rx.events.EventWearToMobile import app.aaps.core.interfaces.rx.weardata.EventData.ActionBolusPreCheck import app.aaps.core.interfaces.utils.SafeParse -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter -import info.nightscout.androidaps.interaction.utils.PlusMinusEditText -import info.nightscout.androidaps.nondeprecated.GridPagerAdapterNonDeprecated +import app.aaps.wear.R +import app.aaps.wear.interaction.utils.EditPlusMinusViewAdapter +import app.aaps.wear.interaction.utils.PlusMinusEditText +import app.aaps.wear.nondeprecated.GridPagerAdapterNonDeprecated import java.text.DecimalFormat import kotlin.math.roundToInt diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CarbActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/CarbActivity.kt similarity index 90% rename from wear/src/main/java/info/nightscout/androidaps/interaction/actions/CarbActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/actions/CarbActivity.kt index 4b5a838cba..2d78768194 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CarbActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/CarbActivity.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.interaction.actions +package app.aaps.wear.interaction.actions import android.os.Bundle import android.view.LayoutInflater @@ -10,10 +10,10 @@ import android.widget.ImageView import app.aaps.core.interfaces.rx.events.EventWearToMobile import app.aaps.core.interfaces.rx.weardata.EventData.ActionECarbsPreCheck import app.aaps.core.interfaces.utils.SafeParse -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter -import info.nightscout.androidaps.interaction.utils.PlusMinusEditText -import info.nightscout.androidaps.nondeprecated.GridPagerAdapterNonDeprecated +import app.aaps.wear.R +import app.aaps.wear.interaction.utils.EditPlusMinusViewAdapter +import app.aaps.wear.interaction.utils.PlusMinusEditText +import app.aaps.wear.nondeprecated.GridPagerAdapterNonDeprecated import java.text.DecimalFormat class CarbActivity : ViewSelectorActivity() { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/ECarbActivity.kt similarity index 93% rename from wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/actions/ECarbActivity.kt index 5a5e141ef8..537139ceb1 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/ECarbActivity.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.interaction.actions +package app.aaps.wear.interaction.actions import android.os.Bundle import android.view.LayoutInflater @@ -11,10 +11,10 @@ import app.aaps.core.interfaces.rx.events.EventWearToMobile import app.aaps.core.interfaces.rx.weardata.EventData.ActionECarbsPreCheck import app.aaps.core.interfaces.utils.SafeParse.stringToDouble import app.aaps.core.interfaces.utils.SafeParse.stringToInt -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter -import info.nightscout.androidaps.interaction.utils.PlusMinusEditText -import info.nightscout.androidaps.nondeprecated.GridPagerAdapterNonDeprecated +import app.aaps.wear.R +import app.aaps.wear.interaction.utils.EditPlusMinusViewAdapter +import app.aaps.wear.interaction.utils.PlusMinusEditText +import app.aaps.wear.nondeprecated.GridPagerAdapterNonDeprecated import java.text.DecimalFormat class ECarbActivity : ViewSelectorActivity() { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/FillActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/FillActivity.kt similarity index 89% rename from wear/src/main/java/info/nightscout/androidaps/interaction/actions/FillActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/actions/FillActivity.kt index 7aea8b1dcc..344af1c8a1 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/FillActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/FillActivity.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.interaction.actions +package app.aaps.wear.interaction.actions import android.os.Bundle import android.view.LayoutInflater @@ -10,10 +10,10 @@ import android.widget.ImageView import app.aaps.core.interfaces.rx.events.EventWearToMobile import app.aaps.core.interfaces.rx.weardata.EventData.ActionFillPreCheck import app.aaps.core.interfaces.utils.SafeParse.stringToDouble -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter -import info.nightscout.androidaps.interaction.utils.PlusMinusEditText -import info.nightscout.androidaps.nondeprecated.GridPagerAdapterNonDeprecated +import app.aaps.wear.R +import app.aaps.wear.interaction.utils.EditPlusMinusViewAdapter +import app.aaps.wear.interaction.utils.PlusMinusEditText +import app.aaps.wear.nondeprecated.GridPagerAdapterNonDeprecated import java.text.DecimalFormat class FillActivity : ViewSelectorActivity() { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ProfileSwitchActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/ProfileSwitchActivity.kt similarity index 92% rename from wear/src/main/java/info/nightscout/androidaps/interaction/actions/ProfileSwitchActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/actions/ProfileSwitchActivity.kt index 67a5fa20d9..b7c543bdbb 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ProfileSwitchActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/ProfileSwitchActivity.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.interaction.actions +package app.aaps.wear.interaction.actions import android.os.Bundle import android.view.LayoutInflater @@ -10,10 +10,10 @@ import android.widget.ImageView import app.aaps.core.interfaces.rx.events.EventWearToMobile import app.aaps.core.interfaces.rx.weardata.EventData.ActionProfileSwitchPreCheck import app.aaps.core.interfaces.utils.SafeParse -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter -import info.nightscout.androidaps.interaction.utils.PlusMinusEditText -import info.nightscout.androidaps.nondeprecated.GridPagerAdapterNonDeprecated +import app.aaps.wear.R +import app.aaps.wear.interaction.utils.EditPlusMinusViewAdapter +import app.aaps.wear.interaction.utils.PlusMinusEditText +import app.aaps.wear.nondeprecated.GridPagerAdapterNonDeprecated import java.text.DecimalFormat class ProfileSwitchActivity : ViewSelectorActivity() { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/QuickSnoozeActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/QuickSnoozeActivity.kt similarity index 92% rename from wear/src/main/java/info/nightscout/androidaps/interaction/actions/QuickSnoozeActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/actions/QuickSnoozeActivity.kt index 6f4d237560..70a06d8918 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/QuickSnoozeActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/QuickSnoozeActivity.kt @@ -1,54 +1,54 @@ -package info.nightscout.androidaps.interaction.actions - -import android.content.Intent -import android.content.pm.PackageManager -import android.os.Bundle -import android.util.Log -import android.widget.Toast -import app.aaps.core.interfaces.rx.bus.RxBus -import app.aaps.core.interfaces.rx.events.EventWearToMobile -import app.aaps.core.interfaces.rx.weardata.EventData -import app.aaps.shared.impl.extensions.safeGetPackageInfo -import dagger.android.DaggerActivity -import info.nightscout.androidaps.R -import javax.inject.Inject - -/** - * Send a snooze request to silence any alarm. Designed to be bound to a button for fast access - */ - -class QuickSnoozeActivity : DaggerActivity() { - - @Inject lateinit var rxBus: RxBus - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - Toast.makeText(this, R.string.sending_snooze, Toast.LENGTH_LONG).show() - rxBus.send(EventWearToMobile(EventData.SnoozeAlert(System.currentTimeMillis()))) - - val xDripPackageName = "com.eveningoutpost.dexdrip" - if (isPackageExisted(xDripPackageName)) { - try { - val i = Intent() - i.setClassName(xDripPackageName, "$xDripPackageName.QuickSnooze") - startActivity(i) - } catch (e: Exception) { - Log.e("WEAR", "failed to snooze xDrip: ", e) - } - } else { - Log.d("WEAR", "Package $xDripPackageName not available for snooze") - } - - finish() - } - - @Suppress("SameParameterValue") - private fun isPackageExisted(targetPackage: String): Boolean { - try { - packageManager.safeGetPackageInfo(targetPackage, 0) - } catch (e: PackageManager.NameNotFoundException) { - return false - } - return true - } -} +package app.aaps.wear.interaction.actions + +import android.content.Intent +import android.content.pm.PackageManager +import android.os.Bundle +import android.util.Log +import android.widget.Toast +import app.aaps.core.interfaces.rx.bus.RxBus +import app.aaps.core.interfaces.rx.events.EventWearToMobile +import app.aaps.core.interfaces.rx.weardata.EventData +import app.aaps.shared.impl.extensions.safeGetPackageInfo +import app.aaps.wear.R +import dagger.android.DaggerActivity +import javax.inject.Inject + +/** + * Send a snooze request to silence any alarm. Designed to be bound to a button for fast access + */ + +class QuickSnoozeActivity : DaggerActivity() { + + @Inject lateinit var rxBus: RxBus + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + Toast.makeText(this, R.string.sending_snooze, Toast.LENGTH_LONG).show() + rxBus.send(EventWearToMobile(EventData.SnoozeAlert(System.currentTimeMillis()))) + + val xDripPackageName = "com.eveningoutpost.dexdrip" + if (isPackageExisted(xDripPackageName)) { + try { + val i = Intent() + i.setClassName(xDripPackageName, "$xDripPackageName.QuickSnooze") + startActivity(i) + } catch (e: Exception) { + Log.e("WEAR", "failed to snooze xDrip: ", e) + } + } else { + Log.d("WEAR", "Package $xDripPackageName not available for snooze") + } + + finish() + } + + @Suppress("SameParameterValue") + private fun isPackageExisted(targetPackage: String): Boolean { + try { + packageManager.safeGetPackageInfo(targetPackage, 0) + } catch (e: PackageManager.NameNotFoundException) { + return false + } + return true + } +} diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/TempTargetActivity.kt similarity index 94% rename from wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/actions/TempTargetActivity.kt index 667ec73703..b7a3cb1422 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/TempTargetActivity.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.interaction.actions +package app.aaps.wear.interaction.actions import android.os.Bundle import android.view.LayoutInflater @@ -10,10 +10,10 @@ import android.widget.ImageView import app.aaps.core.interfaces.rx.events.EventWearToMobile import app.aaps.core.interfaces.rx.weardata.EventData.ActionTempTargetPreCheck import app.aaps.core.interfaces.utils.SafeParse -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter -import info.nightscout.androidaps.interaction.utils.PlusMinusEditText -import info.nightscout.androidaps.nondeprecated.GridPagerAdapterNonDeprecated +import app.aaps.wear.R +import app.aaps.wear.interaction.utils.EditPlusMinusViewAdapter +import app.aaps.wear.interaction.utils.PlusMinusEditText +import app.aaps.wear.nondeprecated.GridPagerAdapterNonDeprecated import java.text.DecimalFormat class TempTargetActivity : ViewSelectorActivity() { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TreatmentActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/TreatmentActivity.kt similarity index 93% rename from wear/src/main/java/info/nightscout/androidaps/interaction/actions/TreatmentActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/actions/TreatmentActivity.kt index b9e21414cd..40ab8599a1 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TreatmentActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/TreatmentActivity.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.interaction.actions +package app.aaps.wear.interaction.actions import android.os.Bundle import android.view.LayoutInflater @@ -11,10 +11,10 @@ import app.aaps.core.interfaces.rx.events.EventWearToMobile import app.aaps.core.interfaces.rx.weardata.EventData.ActionBolusPreCheck import app.aaps.core.interfaces.utils.SafeParse.stringToDouble import app.aaps.core.interfaces.utils.SafeParse.stringToInt -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter -import info.nightscout.androidaps.interaction.utils.PlusMinusEditText -import info.nightscout.androidaps.nondeprecated.GridPagerAdapterNonDeprecated +import app.aaps.wear.R +import app.aaps.wear.interaction.utils.EditPlusMinusViewAdapter +import app.aaps.wear.interaction.utils.PlusMinusEditText +import app.aaps.wear.nondeprecated.GridPagerAdapterNonDeprecated import java.text.DecimalFormat import kotlin.math.roundToInt diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ViewSelectorActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/ViewSelectorActivity.kt similarity index 89% rename from wear/src/main/java/info/nightscout/androidaps/interaction/actions/ViewSelectorActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/actions/ViewSelectorActivity.kt index 5236338ff9..255e892bfe 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ViewSelectorActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/ViewSelectorActivity.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.interaction.actions +package app.aaps.wear.interaction.actions import android.content.Context import android.os.Bundle @@ -11,11 +11,11 @@ import android.widget.Toast import androidx.wear.widget.CurvedTextView import app.aaps.core.interfaces.rx.bus.RxBus import app.aaps.core.interfaces.sharedPreferences.SP +import app.aaps.wear.R +import app.aaps.wear.nondeprecated.DotsPageIndicatorNonDeprecated +import app.aaps.wear.nondeprecated.GridPagerAdapterNonDeprecated +import app.aaps.wear.nondeprecated.GridViewPagerNonDeprecated import dagger.android.DaggerActivity -import info.nightscout.androidaps.R -import info.nightscout.androidaps.nondeprecated.DotsPageIndicatorNonDeprecated -import info.nightscout.androidaps.nondeprecated.GridPagerAdapterNonDeprecated -import info.nightscout.androidaps.nondeprecated.GridViewPagerNonDeprecated import javax.inject.Inject /** diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/WizardActivity.kt similarity index 92% rename from wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/actions/WizardActivity.kt index ec62dc1289..1d4c16e3af 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/actions/WizardActivity.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.interaction.actions +package app.aaps.wear.interaction.actions import android.os.Bundle import android.view.LayoutInflater @@ -10,10 +10,10 @@ import android.widget.ImageView import app.aaps.core.interfaces.rx.events.EventWearToMobile import app.aaps.core.interfaces.rx.weardata.EventData.ActionWizardPreCheck import app.aaps.core.interfaces.utils.SafeParse -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter -import info.nightscout.androidaps.interaction.utils.PlusMinusEditText -import info.nightscout.androidaps.nondeprecated.GridPagerAdapterNonDeprecated +import app.aaps.wear.R +import app.aaps.wear.interaction.utils.EditPlusMinusViewAdapter +import app.aaps.wear.interaction.utils.PlusMinusEditText +import app.aaps.wear.nondeprecated.GridPagerAdapterNonDeprecated import java.text.DecimalFormat class WizardActivity : ViewSelectorActivity() { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/FillMenuActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/menus/FillMenuActivity.kt similarity index 86% rename from wear/src/main/java/info/nightscout/androidaps/interaction/menus/FillMenuActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/menus/FillMenuActivity.kt index 2b65aa9e02..cf8e08009e 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/FillMenuActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/menus/FillMenuActivity.kt @@ -1,12 +1,12 @@ -package info.nightscout.androidaps.interaction.menus +package app.aaps.wear.interaction.menus import android.content.Intent import android.os.Bundle import app.aaps.core.interfaces.rx.events.EventWearToMobile import app.aaps.core.interfaces.rx.weardata.EventData -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.actions.FillActivity -import info.nightscout.androidaps.interaction.utils.MenuListActivity +import app.aaps.wear.R +import app.aaps.wear.interaction.actions.FillActivity +import app.aaps.wear.interaction.utils.MenuListActivity class FillMenuActivity : MenuListActivity() { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/menus/MainMenuActivity.kt similarity index 88% rename from wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/menus/MainMenuActivity.kt index 2b73da0dc6..21bdb290e6 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/menus/MainMenuActivity.kt @@ -1,16 +1,16 @@ -package info.nightscout.androidaps.interaction.menus +package app.aaps.wear.interaction.menus import android.content.Intent import android.os.Bundle import app.aaps.core.interfaces.rx.events.EventWearToMobile import app.aaps.core.interfaces.rx.weardata.EventData import app.aaps.core.interfaces.rx.weardata.EventData.ActionResendData -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.actions.ECarbActivity -import info.nightscout.androidaps.interaction.actions.TempTargetActivity -import info.nightscout.androidaps.interaction.actions.TreatmentActivity -import info.nightscout.androidaps.interaction.actions.WizardActivity -import info.nightscout.androidaps.interaction.utils.MenuListActivity +import app.aaps.wear.R +import app.aaps.wear.interaction.actions.ECarbActivity +import app.aaps.wear.interaction.actions.TempTargetActivity +import app.aaps.wear.interaction.actions.TreatmentActivity +import app.aaps.wear.interaction.actions.WizardActivity +import app.aaps.wear.interaction.utils.MenuListActivity class MainMenuActivity : MenuListActivity() { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/PreferenceMenuActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/menus/PreferenceMenuActivity.kt similarity index 80% rename from wear/src/main/java/info/nightscout/androidaps/interaction/menus/PreferenceMenuActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/menus/PreferenceMenuActivity.kt index 8607645d06..4fd8dc6c9c 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/PreferenceMenuActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/menus/PreferenceMenuActivity.kt @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.interaction.menus +package app.aaps.wear.interaction.menus import android.content.Intent import android.os.Bundle -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.WatchfaceConfigurationActivity -import info.nightscout.androidaps.interaction.utils.MenuListActivity +import app.aaps.wear.R +import app.aaps.wear.interaction.WatchfaceConfigurationActivity +import app.aaps.wear.interaction.utils.MenuListActivity class PreferenceMenuActivity : MenuListActivity() { @@ -24,23 +24,27 @@ class PreferenceMenuActivity : MenuListActivity() { override fun doAction(position: String) { when (position) { - getString(R.string.pref_display_settings) -> startActivity(Intent(this, WatchfaceConfigurationActivity::class.java).apply { + getString(R.string.pref_display_settings) -> startActivity(Intent(this, WatchfaceConfigurationActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) putExtra(getString(R.string.key_preference_id), R.xml.display_preferences) }) + getString(R.string.pref_graph_settings) -> startActivity(Intent(this, WatchfaceConfigurationActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) putExtra(getString(R.string.key_preference_id), R.xml.graph_preferences) }) + getString(R.string.pref_interface_settings) -> startActivity(Intent(this, WatchfaceConfigurationActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) putExtra(getString(R.string.key_preference_id), R.xml.interface_preferences) }) + getString(R.string.pref_complication_settings) -> startActivity(Intent(this, WatchfaceConfigurationActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) putExtra(getString(R.string.key_preference_id), R.xml.complication_preferences) }) - getString(R.string.pref_others_settings) -> startActivity(Intent(this, WatchfaceConfigurationActivity::class.java).apply { + + getString(R.string.pref_others_settings) -> startActivity(Intent(this, WatchfaceConfigurationActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) putExtra(getString(R.string.key_preference_id), R.xml.others_preferences) }) diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/menus/StatusMenuActivity.kt similarity index 89% rename from wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/menus/StatusMenuActivity.kt index 5931d68a09..b44416b17e 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/menus/StatusMenuActivity.kt @@ -1,12 +1,12 @@ -package info.nightscout.androidaps.interaction.menus +package app.aaps.wear.interaction.menus import android.os.Bundle import app.aaps.core.interfaces.rx.events.EventWearToMobile import app.aaps.core.interfaces.rx.weardata.EventData.ActionLoopStatus import app.aaps.core.interfaces.rx.weardata.EventData.ActionPumpStatus import app.aaps.core.interfaces.rx.weardata.EventData.ActionTddStatus -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.utils.MenuListActivity +import app.aaps.wear.R +import app.aaps.wear.interaction.utils.MenuListActivity class StatusMenuActivity : MenuListActivity() { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Constants.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/Constants.kt similarity index 86% rename from wear/src/main/java/info/nightscout/androidaps/interaction/utils/Constants.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/utils/Constants.kt index 3c8ce54949..fa33226563 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Constants.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/Constants.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.interaction.utils +package app.aaps.wear.interaction.utils @Suppress("unused") object Constants { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/DisplayFormat.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/DisplayFormat.kt similarity index 94% rename from wear/src/main/java/info/nightscout/androidaps/interaction/utils/DisplayFormat.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/utils/DisplayFormat.kt index 1f5ba2f361..dbf7bb3323 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/DisplayFormat.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/DisplayFormat.kt @@ -1,142 +1,142 @@ -package info.nightscout.androidaps.interaction.utils - -import android.content.Context -import app.aaps.core.interfaces.sharedPreferences.SP -import info.nightscout.androidaps.R -import info.nightscout.androidaps.data.RawDisplayData -import info.nightscout.androidaps.interaction.utils.Pair.Companion.create -import javax.inject.Inject -import javax.inject.Singleton -import kotlin.math.max - -@Singleton -class DisplayFormat @Inject internal constructor() { - - companion object { - - const val MAX_FIELD_LEN_LONG = 22 // this is found out empirical, for TYPE_LONG_TEXT - const val MAX_FIELD_LEN_SHORT = 7 // according to Wear OS docs for TYPE_SHORT_TEXT - const val MIN_FIELD_LEN_COB = 3 // since carbs are usually 0..99g - const val MIN_FIELD_LEN_IOB = 3 // IoB can range from like .1U to 99U - } - - @Inject lateinit var sp: SP - @Inject lateinit var wearUtil: WearUtil - @Inject lateinit var context: Context - - /** - * Maximal and minimal lengths of fields/labels shown in complications, in characters - * For MAX values - above that WearOS and watch faces may start ellipsize (...) contents - * For MIN values - this is minimal length that can hold legible data - */ - - private fun areComplicationsUnicode() = sp.getBoolean("complication_unicode", true) - - private fun deltaSymbol() = if (areComplicationsUnicode()) "\u0394" else "" - - private fun verticalSeparatorSymbol() = if (areComplicationsUnicode()) "\u205E" else "|" - - fun basalRateSymbol() = if (areComplicationsUnicode()) "\u238D\u2006" else "" - - fun shortTimeSince(refTime: Long): String { - val deltaTimeMs = wearUtil.msSince(refTime) - return if (deltaTimeMs < Constants.MINUTE_IN_MS) { - "0'" - } else if (deltaTimeMs < Constants.HOUR_IN_MS) { - val minutes = (deltaTimeMs / Constants.MINUTE_IN_MS).toInt() - "$minutes'" - } else if (deltaTimeMs < Constants.DAY_IN_MS) { - val hours = (deltaTimeMs / Constants.HOUR_IN_MS).toInt() - hours.toString() + context.getString(R.string.hour_short) - } else { - val days = (deltaTimeMs / Constants.DAY_IN_MS).toInt() - if (days < 7) { - days.toString() + context.getString(R.string.day_short) - } else { - val weeks = days / 7 - weeks.toString() + context.getString(R.string.week_short) - } - } - } - - fun shortTrend(raw: RawDisplayData): String { - var minutes = "--" - val rawDelta = if (sp.getBoolean(R.string.key_show_detailed_delta, false)) raw.singleBg.deltaDetailed else raw.singleBg.delta - if (raw.singleBg.timeStamp > 0) { - minutes = shortTimeSince(raw.singleBg.timeStamp) - } - if (minutes.length + rawDelta.length + deltaSymbol().length + 1 <= MAX_FIELD_LEN_SHORT) { - return minutes + " " + deltaSymbol() + rawDelta - } - - // that only optimizes obvious things like 0 before . or at end, + at beginning - val delta = SmallestDoubleString(rawDelta).minimise(MAX_FIELD_LEN_SHORT - 1) - if (minutes.length + delta.length + deltaSymbol().length + 1 <= MAX_FIELD_LEN_SHORT) { - return minutes + " " + deltaSymbol() + delta - } - val shortDelta = SmallestDoubleString(rawDelta).minimise(MAX_FIELD_LEN_SHORT - (1 + minutes.length)) - return "$minutes $shortDelta" - } - - fun longGlucoseLine(raw: RawDisplayData): String { - val rawDelta = if (sp.getBoolean(R.string.key_show_detailed_delta, false)) raw.singleBg.deltaDetailed else raw.singleBg.delta - return raw.singleBg.sgvString + raw.singleBg.slopeArrow + " " + deltaSymbol() + SmallestDoubleString(rawDelta).minimise(8) + " (" + shortTimeSince(raw.singleBg.timeStamp) + ")" - } - - fun longDetailsLine(raw: RawDisplayData): String { - val sepLong = " " + verticalSeparatorSymbol() + " " - val sepShort = " " + verticalSeparatorSymbol() + " " - val sepShortLen = sepShort.length - val sepMin = " " - var line = raw.status.cob + sepLong + raw.status.iobSum + sepLong + basalRateSymbol() + raw.status.currentBasal - if (line.length <= MAX_FIELD_LEN_LONG) { - return line - } - line = raw.status.cob + sepShort + raw.status.iobSum + sepShort + raw.status.currentBasal - if (line.length <= MAX_FIELD_LEN_LONG) { - return line - } - var remainingMax = MAX_FIELD_LEN_LONG - (raw.status.cob.length + raw.status.currentBasal.length + sepShortLen * 2) - val smallestIoB = SmallestDoubleString(raw.status.iobSum, SmallestDoubleString.Units.USE).minimise(max(MIN_FIELD_LEN_IOB, remainingMax)) - line = raw.status.cob + sepShort + smallestIoB + sepShort + raw.status.currentBasal - if (line.length <= MAX_FIELD_LEN_LONG) { - return line - } - remainingMax = MAX_FIELD_LEN_LONG - (smallestIoB.length + raw.status.currentBasal.length + sepShortLen * 2) - val simplifiedCob = SmallestDoubleString(raw.status.cob, SmallestDoubleString.Units.USE).minimise(max(MIN_FIELD_LEN_COB, remainingMax)) - line = simplifiedCob + sepShort + smallestIoB + sepShort + raw.status.currentBasal - if (line.length <= MAX_FIELD_LEN_LONG) { - return line - } - line = simplifiedCob + sepMin + smallestIoB + sepMin + raw.status.currentBasal - return line - } - - fun detailedIob(raw: RawDisplayData): Pair { - val iob1 = SmallestDoubleString(raw.status.iobSum, SmallestDoubleString.Units.USE).minimise(MAX_FIELD_LEN_SHORT) - var iob2 = "" - if (raw.status.iobDetail.contains("|")) { - val iobs = raw.status.iobDetail.replace("(", "").replace(")", "").split("|").toTypedArray() - var iobBolus = SmallestDoubleString(iobs[0]).minimise(MIN_FIELD_LEN_IOB) - if (iobBolus.trim().isEmpty()) { - iobBolus = "--" - } - var iobBasal = SmallestDoubleString(iobs[1]).minimise(MAX_FIELD_LEN_SHORT - 1 - max(MIN_FIELD_LEN_IOB, iobBolus.length)) - if (iobBasal.trim().isEmpty()) { - iobBasal = "--" - } - iob2 = "$iobBolus $iobBasal" - } - return create(iob1, iob2) - } - - fun detailedCob(raw: RawDisplayData): Pair { - val cobMini = SmallestDoubleString(raw.status.cob, SmallestDoubleString.Units.USE) - var cob2 = "" - if (cobMini.extra.isNotEmpty()) { - cob2 = cobMini.extra + cobMini.units - } - val cob1 = cobMini.minimise(MAX_FIELD_LEN_SHORT) - return create(cob1, cob2) - } -} +package app.aaps.wear.interaction.utils + +import android.content.Context +import app.aaps.core.interfaces.sharedPreferences.SP +import app.aaps.wear.R +import app.aaps.wear.data.RawDisplayData +import app.aaps.wear.interaction.utils.Pair.Companion.create +import javax.inject.Inject +import javax.inject.Singleton +import kotlin.math.max + +@Singleton +class DisplayFormat @Inject internal constructor() { + + companion object { + + const val MAX_FIELD_LEN_LONG = 22 // this is found out empirical, for TYPE_LONG_TEXT + const val MAX_FIELD_LEN_SHORT = 7 // according to Wear OS docs for TYPE_SHORT_TEXT + const val MIN_FIELD_LEN_COB = 3 // since carbs are usually 0..99g + const val MIN_FIELD_LEN_IOB = 3 // IoB can range from like .1U to 99U + } + + @Inject lateinit var sp: SP + @Inject lateinit var wearUtil: WearUtil + @Inject lateinit var context: Context + + /** + * Maximal and minimal lengths of fields/labels shown in complications, in characters + * For MAX values - above that WearOS and watch faces may start ellipsize (...) contents + * For MIN values - this is minimal length that can hold legible data + */ + + private fun areComplicationsUnicode() = sp.getBoolean("complication_unicode", true) + + private fun deltaSymbol() = if (areComplicationsUnicode()) "\u0394" else "" + + private fun verticalSeparatorSymbol() = if (areComplicationsUnicode()) "\u205E" else "|" + + fun basalRateSymbol() = if (areComplicationsUnicode()) "\u238D\u2006" else "" + + fun shortTimeSince(refTime: Long): String { + val deltaTimeMs = wearUtil.msSince(refTime) + return if (deltaTimeMs < Constants.MINUTE_IN_MS) { + "0'" + } else if (deltaTimeMs < Constants.HOUR_IN_MS) { + val minutes = (deltaTimeMs / Constants.MINUTE_IN_MS).toInt() + "$minutes'" + } else if (deltaTimeMs < Constants.DAY_IN_MS) { + val hours = (deltaTimeMs / Constants.HOUR_IN_MS).toInt() + hours.toString() + context.getString(R.string.hour_short) + } else { + val days = (deltaTimeMs / Constants.DAY_IN_MS).toInt() + if (days < 7) { + days.toString() + context.getString(R.string.day_short) + } else { + val weeks = days / 7 + weeks.toString() + context.getString(R.string.week_short) + } + } + } + + fun shortTrend(raw: RawDisplayData): String { + var minutes = "--" + val rawDelta = if (sp.getBoolean(R.string.key_show_detailed_delta, false)) raw.singleBg.deltaDetailed else raw.singleBg.delta + if (raw.singleBg.timeStamp > 0) { + minutes = shortTimeSince(raw.singleBg.timeStamp) + } + if (minutes.length + rawDelta.length + deltaSymbol().length + 1 <= MAX_FIELD_LEN_SHORT) { + return minutes + " " + deltaSymbol() + rawDelta + } + + // that only optimizes obvious things like 0 before . or at end, + at beginning + val delta = SmallestDoubleString(rawDelta).minimise(MAX_FIELD_LEN_SHORT - 1) + if (minutes.length + delta.length + deltaSymbol().length + 1 <= MAX_FIELD_LEN_SHORT) { + return minutes + " " + deltaSymbol() + delta + } + val shortDelta = SmallestDoubleString(rawDelta).minimise(MAX_FIELD_LEN_SHORT - (1 + minutes.length)) + return "$minutes $shortDelta" + } + + fun longGlucoseLine(raw: RawDisplayData): String { + val rawDelta = if (sp.getBoolean(R.string.key_show_detailed_delta, false)) raw.singleBg.deltaDetailed else raw.singleBg.delta + return raw.singleBg.sgvString + raw.singleBg.slopeArrow + " " + deltaSymbol() + SmallestDoubleString(rawDelta).minimise(8) + " (" + shortTimeSince(raw.singleBg.timeStamp) + ")" + } + + fun longDetailsLine(raw: RawDisplayData): String { + val sepLong = " " + verticalSeparatorSymbol() + " " + val sepShort = " " + verticalSeparatorSymbol() + " " + val sepShortLen = sepShort.length + val sepMin = " " + var line = raw.status.cob + sepLong + raw.status.iobSum + sepLong + basalRateSymbol() + raw.status.currentBasal + if (line.length <= MAX_FIELD_LEN_LONG) { + return line + } + line = raw.status.cob + sepShort + raw.status.iobSum + sepShort + raw.status.currentBasal + if (line.length <= MAX_FIELD_LEN_LONG) { + return line + } + var remainingMax = MAX_FIELD_LEN_LONG - (raw.status.cob.length + raw.status.currentBasal.length + sepShortLen * 2) + val smallestIoB = SmallestDoubleString(raw.status.iobSum, SmallestDoubleString.Units.USE).minimise(max(MIN_FIELD_LEN_IOB, remainingMax)) + line = raw.status.cob + sepShort + smallestIoB + sepShort + raw.status.currentBasal + if (line.length <= MAX_FIELD_LEN_LONG) { + return line + } + remainingMax = MAX_FIELD_LEN_LONG - (smallestIoB.length + raw.status.currentBasal.length + sepShortLen * 2) + val simplifiedCob = SmallestDoubleString(raw.status.cob, SmallestDoubleString.Units.USE).minimise(max(MIN_FIELD_LEN_COB, remainingMax)) + line = simplifiedCob + sepShort + smallestIoB + sepShort + raw.status.currentBasal + if (line.length <= MAX_FIELD_LEN_LONG) { + return line + } + line = simplifiedCob + sepMin + smallestIoB + sepMin + raw.status.currentBasal + return line + } + + fun detailedIob(raw: RawDisplayData): Pair { + val iob1 = SmallestDoubleString(raw.status.iobSum, SmallestDoubleString.Units.USE).minimise(MAX_FIELD_LEN_SHORT) + var iob2 = "" + if (raw.status.iobDetail.contains("|")) { + val iobs = raw.status.iobDetail.replace("(", "").replace(")", "").split("|").toTypedArray() + var iobBolus = SmallestDoubleString(iobs[0]).minimise(MIN_FIELD_LEN_IOB) + if (iobBolus.trim().isEmpty()) { + iobBolus = "--" + } + var iobBasal = SmallestDoubleString(iobs[1]).minimise(MAX_FIELD_LEN_SHORT - 1 - max(MIN_FIELD_LEN_IOB, iobBolus.length)) + if (iobBasal.trim().isEmpty()) { + iobBasal = "--" + } + iob2 = "$iobBolus $iobBasal" + } + return create(iob1, iob2) + } + + fun detailedCob(raw: RawDisplayData): Pair { + val cobMini = SmallestDoubleString(raw.status.cob, SmallestDoubleString.Units.USE) + var cob2 = "" + if (cobMini.extra.isNotEmpty()) { + cob2 = cobMini.extra + cobMini.units + } + val cob1 = cobMini.minimise(MAX_FIELD_LEN_SHORT) + return create(cob1, cob2) + } +} diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/EditPlusMinusViewAdapter.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/EditPlusMinusViewAdapter.kt similarity index 85% rename from wear/src/main/java/info/nightscout/androidaps/interaction/utils/EditPlusMinusViewAdapter.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/utils/EditPlusMinusViewAdapter.kt index 9bd43ec7d0..605caf8913 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/EditPlusMinusViewAdapter.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/EditPlusMinusViewAdapter.kt @@ -1,98 +1,98 @@ -package info.nightscout.androidaps.interaction.utils - -import android.content.Context -import android.view.LayoutInflater -import android.view.ViewGroup -import app.aaps.core.interfaces.sharedPreferences.SP -import info.nightscout.androidaps.R -import info.nightscout.androidaps.databinding.ActionEditplusminBinding -import info.nightscout.androidaps.databinding.ActionEditplusminMultiBinding -import info.nightscout.androidaps.databinding.ActionEditplusminQuickleftyBinding -import info.nightscout.androidaps.databinding.ActionEditplusminQuickleftyMultiBinding -import info.nightscout.androidaps.databinding.ActionEditplusminQuickrightyBinding -import info.nightscout.androidaps.databinding.ActionEditplusminQuickrightyMultiBinding -import info.nightscout.androidaps.databinding.ActionEditplusminViktoriaBinding - -/** - * EditPlusMinusViewAdapter binds both ActionEditplusminBinding variants shared attributes to one common view adapter. - * Requires at least one of the ViewBinding as a parameter. Recommended to use the factory object to create the binding. - */ -class EditPlusMinusViewAdapter( - eD: ActionEditplusminBinding?, - eDP: ActionEditplusminMultiBinding?, - eQL: ActionEditplusminQuickleftyBinding?, - eQLP: ActionEditplusminQuickleftyMultiBinding?, - eQR: ActionEditplusminQuickrightyBinding?, - eQRP: ActionEditplusminQuickrightyMultiBinding?, - eV: ActionEditplusminViktoriaBinding? -) { - - init { - if (eD == null && eDP == null && eQL == null && eQLP == null && eQR == null && eQRP == null && eV == null) { - throw IllegalArgumentException("Require at least on Binding parameter") - } - } - - private val errorMessage = "Missing require View Binding parameter" - val editText = - eD?.editText ?: eDP?.editText ?: eQL?.editText ?: eQLP?.editText ?: eQR?.editText ?: eQRP?.editText ?: eV?.editText - ?: throw IllegalArgumentException(errorMessage) - val minButton = - eD?.minButton ?: eDP?.minButton ?: eQL?.minButton ?: eQLP?.minButton ?: eQR?.minButton ?: eQRP?.minButton ?: eV?.minButton - ?: throw IllegalArgumentException(errorMessage) - val plusButton1 = - eD?.plusButton1 ?: eDP?.plusButton1 ?: eQL?.plusButton1 ?: eQLP?.plusButton1 ?: eQR?.plusButton1 ?: eQRP?.plusButton1 ?: eV?.plusButton1 - ?: throw IllegalArgumentException(errorMessage) - val label = - eD?.label ?: eDP?.label ?: eQL?.label ?: eQLP?.label ?: eQR?.label ?: eQRP?.label ?: eV?.label - ?: throw IllegalArgumentException(errorMessage) - val plusButton2 = eDP?.plusButton2 ?: eQLP?.plusButton2 ?: eQRP?.plusButton2 - val plusButton3 = eDP?.plusButton3 ?: eQLP?.plusButton3 ?: eQRP?.plusButton3 - val root = - eD?.root ?: eDP?.root ?: eQL?.root ?: eQLP?.root ?: eQR?.root ?: eQRP?.root ?: eV?.root - ?: throw IllegalArgumentException(errorMessage) - - companion object { - - fun getViewAdapter(sp: SP, context: Context, container: ViewGroup, multiple: Boolean = false): EditPlusMinusViewAdapter { - val inflater = LayoutInflater.from(context) - - return when (sp.getInt(R.string.key_input_design, 1)) { - 2 -> { - if (multiple) { - val bindLayout = ActionEditplusminQuickrightyMultiBinding.inflate(inflater, container, false) - EditPlusMinusViewAdapter(null, null, null, null, null, bindLayout, null) - } else { - val bindLayout = ActionEditplusminQuickrightyBinding.inflate(inflater, container, false) - EditPlusMinusViewAdapter(null, null, null, null, bindLayout, null, null) - } - } - - 3 -> { - if (multiple) { - val bindLayout = ActionEditplusminQuickleftyMultiBinding.inflate(inflater, container, false) - EditPlusMinusViewAdapter(null, null, null, bindLayout, null, null, null) - } else { - val bindLayout = ActionEditplusminQuickleftyBinding.inflate(inflater, container, false) - EditPlusMinusViewAdapter(null, null, bindLayout, null, null, null, null) - } - } - - 4 -> { - val bindLayout = ActionEditplusminViktoriaBinding.inflate(inflater, container, false) - EditPlusMinusViewAdapter(null, null, null, null, null, null, bindLayout) - } - - else -> { - if (multiple) { - val bindLayout = ActionEditplusminMultiBinding.inflate(inflater, container, false) - EditPlusMinusViewAdapter(null, bindLayout, null, null, null, null, null) - } else { - val bindLayout = ActionEditplusminBinding.inflate(inflater, container, false) - EditPlusMinusViewAdapter(bindLayout, null, null, null, null, null, null) - } - } - } - } - } -} +package app.aaps.wear.interaction.utils + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import app.aaps.core.interfaces.sharedPreferences.SP +import app.aaps.wear.R +import app.aaps.wear.databinding.ActionEditplusminBinding +import app.aaps.wear.databinding.ActionEditplusminMultiBinding +import app.aaps.wear.databinding.ActionEditplusminQuickleftyBinding +import app.aaps.wear.databinding.ActionEditplusminQuickleftyMultiBinding +import app.aaps.wear.databinding.ActionEditplusminQuickrightyBinding +import app.aaps.wear.databinding.ActionEditplusminQuickrightyMultiBinding +import app.aaps.wear.databinding.ActionEditplusminViktoriaBinding + +/** + * EditPlusMinusViewAdapter binds both ActionEditplusminBinding variants shared attributes to one common view adapter. + * Requires at least one of the ViewBinding as a parameter. Recommended to use the factory object to create the binding. + */ +class EditPlusMinusViewAdapter( + eD: ActionEditplusminBinding?, + eDP: ActionEditplusminMultiBinding?, + eQL: ActionEditplusminQuickleftyBinding?, + eQLP: ActionEditplusminQuickleftyMultiBinding?, + eQR: ActionEditplusminQuickrightyBinding?, + eQRP: ActionEditplusminQuickrightyMultiBinding?, + eV: ActionEditplusminViktoriaBinding? +) { + + init { + if (eD == null && eDP == null && eQL == null && eQLP == null && eQR == null && eQRP == null && eV == null) { + throw IllegalArgumentException("Require at least on Binding parameter") + } + } + + private val errorMessage = "Missing require View Binding parameter" + val editText = + eD?.editText ?: eDP?.editText ?: eQL?.editText ?: eQLP?.editText ?: eQR?.editText ?: eQRP?.editText ?: eV?.editText + ?: throw IllegalArgumentException(errorMessage) + val minButton = + eD?.minButton ?: eDP?.minButton ?: eQL?.minButton ?: eQLP?.minButton ?: eQR?.minButton ?: eQRP?.minButton ?: eV?.minButton + ?: throw IllegalArgumentException(errorMessage) + val plusButton1 = + eD?.plusButton1 ?: eDP?.plusButton1 ?: eQL?.plusButton1 ?: eQLP?.plusButton1 ?: eQR?.plusButton1 ?: eQRP?.plusButton1 ?: eV?.plusButton1 + ?: throw IllegalArgumentException(errorMessage) + val label = + eD?.label ?: eDP?.label ?: eQL?.label ?: eQLP?.label ?: eQR?.label ?: eQRP?.label ?: eV?.label + ?: throw IllegalArgumentException(errorMessage) + val plusButton2 = eDP?.plusButton2 ?: eQLP?.plusButton2 ?: eQRP?.plusButton2 + val plusButton3 = eDP?.plusButton3 ?: eQLP?.plusButton3 ?: eQRP?.plusButton3 + val root = + eD?.root ?: eDP?.root ?: eQL?.root ?: eQLP?.root ?: eQR?.root ?: eQRP?.root ?: eV?.root + ?: throw IllegalArgumentException(errorMessage) + + companion object { + + fun getViewAdapter(sp: SP, context: Context, container: ViewGroup, multiple: Boolean = false): EditPlusMinusViewAdapter { + val inflater = LayoutInflater.from(context) + + return when (sp.getInt(R.string.key_input_design, 1)) { + 2 -> { + if (multiple) { + val bindLayout = ActionEditplusminQuickrightyMultiBinding.inflate(inflater, container, false) + EditPlusMinusViewAdapter(null, null, null, null, null, bindLayout, null) + } else { + val bindLayout = ActionEditplusminQuickrightyBinding.inflate(inflater, container, false) + EditPlusMinusViewAdapter(null, null, null, null, bindLayout, null, null) + } + } + + 3 -> { + if (multiple) { + val bindLayout = ActionEditplusminQuickleftyMultiBinding.inflate(inflater, container, false) + EditPlusMinusViewAdapter(null, null, null, bindLayout, null, null, null) + } else { + val bindLayout = ActionEditplusminQuickleftyBinding.inflate(inflater, container, false) + EditPlusMinusViewAdapter(null, null, bindLayout, null, null, null, null) + } + } + + 4 -> { + val bindLayout = ActionEditplusminViktoriaBinding.inflate(inflater, container, false) + EditPlusMinusViewAdapter(null, null, null, null, null, null, bindLayout) + } + + else -> { + if (multiple) { + val bindLayout = ActionEditplusminMultiBinding.inflate(inflater, container, false) + EditPlusMinusViewAdapter(null, bindLayout, null, null, null, null, null) + } else { + val bindLayout = ActionEditplusminBinding.inflate(inflater, container, false) + EditPlusMinusViewAdapter(bindLayout, null, null, null, null, null, null) + } + } + } + } + } +} diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Inevitable.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/Inevitable.kt similarity index 89% rename from wear/src/main/java/info/nightscout/androidaps/interaction/utils/Inevitable.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/utils/Inevitable.kt index 3636fb54ae..1914bfd8a7 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Inevitable.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/Inevitable.kt @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.interaction.utils +package app.aaps.wear.interaction.utils import android.os.SystemClock import app.aaps.core.interfaces.logging.AAPSLogger import app.aaps.core.interfaces.logging.LTag import app.aaps.core.interfaces.utils.DateUtil -import info.nightscout.androidaps.BuildConfig +import app.aaps.wear.BuildConfig import java.util.concurrent.ConcurrentHashMap import javax.inject.Inject import javax.inject.Singleton @@ -25,19 +25,19 @@ class Inevitable @Inject internal constructor() { @Inject lateinit var dateUtil: DateUtil private val tasks = ConcurrentHashMap() - fun task(id: String, idle_for: Long, runnable: Runnable?) { - if (idle_for > MAX_QUEUE_TIME) { - throw RuntimeException("$id Requested time: $idle_for beyond max queue time") + fun task(id: String, idleFor: Long, runnable: Runnable?) { + if (idleFor > MAX_QUEUE_TIME) { + throw RuntimeException("$id Requested time: $idleFor beyond max queue time") } val task = tasks[id] if (task != null) { // if it already exists then extend the time - task.extendTime(idle_for) + task.extendTime(idleFor) if (debug) aapsLogger.debug(LTag.WEAR, "Extending time for: " + id + " to " + dateUtil.dateAndTimeAndSecondsString(task.`when`)) } else { // otherwise create new task if (runnable == null) return // extension only if already exists - tasks[id] = Task(id, idle_for, runnable) + tasks[id] = Task(id, idleFor, runnable) if (debug) { aapsLogger.debug( LTag.WEAR, diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/MenuListActivity.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/MenuListActivity.kt similarity index 96% rename from wear/src/main/java/info/nightscout/androidaps/interaction/utils/MenuListActivity.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/utils/MenuListActivity.kt index 9d3a66104c..af6af62efb 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/MenuListActivity.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/MenuListActivity.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.interaction.utils +package app.aaps.wear.interaction.utils import android.os.Bundle import android.view.LayoutInflater @@ -14,9 +14,9 @@ import androidx.wear.widget.WearableLinearLayoutManager.LayoutCallback import androidx.wear.widget.WearableRecyclerView import app.aaps.core.interfaces.rx.bus.RxBus import app.aaps.core.interfaces.sharedPreferences.SP +import app.aaps.wear.R +import app.aaps.wear.interaction.utils.MenuListActivity.MenuAdapter.ItemViewHolder import dagger.android.DaggerActivity -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.utils.MenuListActivity.MenuAdapter.ItemViewHolder import javax.inject.Inject import kotlin.math.abs import kotlin.math.min diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Pair.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/Pair.kt similarity index 88% rename from wear/src/main/java/info/nightscout/androidaps/interaction/utils/Pair.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/utils/Pair.kt index 9d087b0bc8..03087dd28c 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Pair.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/Pair.kt @@ -1,6 +1,6 @@ -package info.nightscout.androidaps.interaction.utils +package app.aaps.wear.interaction.utils -import java.util.* +import java.util.Objects /** * Same as android Pair, but clean room java class - does not require Android SDK for tests diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Persistence.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/Persistence.kt similarity index 99% rename from wear/src/main/java/info/nightscout/androidaps/interaction/utils/Persistence.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/utils/Persistence.kt index 06a857a4d0..67dcf70797 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Persistence.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/Persistence.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.interaction.utils +package app.aaps.wear.interaction.utils import app.aaps.annotations.OpenForTesting import app.aaps.core.interfaces.logging.AAPSLogger diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/PlusMinusEditText.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/PlusMinusEditText.kt similarity index 97% rename from wear/src/main/java/info/nightscout/androidaps/interaction/utils/PlusMinusEditText.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/utils/PlusMinusEditText.kt index d6933c1a13..9289a52423 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/PlusMinusEditText.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/PlusMinusEditText.kt @@ -1,7 +1,14 @@ -package info.nightscout.androidaps.interaction.utils +package app.aaps.wear.interaction.utils import android.content.Context -import android.os.* +import android.os.Build +import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.os.Message +import android.os.VibrationEffect +import android.os.Vibrator +import android.os.VibratorManager import android.view.KeyEvent import android.view.MotionEvent import android.view.View diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/SmallestDoubleString.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/SmallestDoubleString.kt similarity index 97% rename from wear/src/main/java/info/nightscout/androidaps/interaction/utils/SmallestDoubleString.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/utils/SmallestDoubleString.kt index 5eb6b8946a..bdb4938405 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/SmallestDoubleString.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/SmallestDoubleString.kt @@ -1,6 +1,5 @@ -package info.nightscout.androidaps.interaction.utils +package app.aaps.wear.interaction.utils -import kotlin.jvm.JvmOverloads import java.math.RoundingMode import java.text.DecimalFormat import java.util.regex.Pattern diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/VersionPreference.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/VersionPreference.kt similarity index 88% rename from wear/src/main/java/info/nightscout/androidaps/interaction/utils/VersionPreference.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/utils/VersionPreference.kt index d63d7ca252..d848c5c1c7 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/VersionPreference.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/VersionPreference.kt @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.interaction.utils +package app.aaps.wear.interaction.utils import android.content.Context import android.util.AttributeSet -import preference.WearListPreference import android.widget.Toast -import info.nightscout.androidaps.BuildConfig +import app.aaps.wear.BuildConfig +import preference.WearListPreference /** * Created by adrian on 07/08/17. diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WatchfaceSettingsPreference.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/WatchfaceSettingsPreference.kt similarity index 90% rename from wear/src/main/java/info/nightscout/androidaps/interaction/utils/WatchfaceSettingsPreference.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/utils/WatchfaceSettingsPreference.kt index 6ae373d8e8..979237a8ec 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WatchfaceSettingsPreference.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/WatchfaceSettingsPreference.kt @@ -1,9 +1,9 @@ -package info.nightscout.androidaps.interaction.utils +package app.aaps.wear.interaction.utils import android.content.Context import android.util.AttributeSet import android.widget.Toast -import info.nightscout.androidaps.R +import app.aaps.wear.R import preference.WearListPreference @Suppress("unused") diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.kt b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/WearUtil.kt similarity index 97% rename from wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.kt rename to wear/src/main/kotlin/app/aaps/wear/interaction/utils/WearUtil.kt index 93f0848026..ed1110bb9e 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.kt +++ b/wear/src/main/kotlin/app/aaps/wear/interaction/utils/WearUtil.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.interaction.utils +package app.aaps.wear.interaction.utils import android.content.Context import android.os.PowerManager diff --git a/wear/src/main/java/info/nightscout/androidaps/nondeprecated/DotsPageIndicatorNonDeprecated.kt b/wear/src/main/kotlin/app/aaps/wear/nondeprecated/DotsPageIndicatorNonDeprecated.kt similarity index 89% rename from wear/src/main/java/info/nightscout/androidaps/nondeprecated/DotsPageIndicatorNonDeprecated.kt rename to wear/src/main/kotlin/app/aaps/wear/nondeprecated/DotsPageIndicatorNonDeprecated.kt index f2fc56b633..17612b8735 100644 --- a/wear/src/main/java/info/nightscout/androidaps/nondeprecated/DotsPageIndicatorNonDeprecated.kt +++ b/wear/src/main/kotlin/app/aaps/wear/nondeprecated/DotsPageIndicatorNonDeprecated.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.nondeprecated +package app.aaps.wear.nondeprecated import android.content.Context import android.support.wearable.view.DotsPageIndicator diff --git a/wear/src/main/java/info/nightscout/androidaps/nondeprecated/GridPagerAdapterNonDeprecated.kt b/wear/src/main/kotlin/app/aaps/wear/nondeprecated/GridPagerAdapterNonDeprecated.kt similarity index 82% rename from wear/src/main/java/info/nightscout/androidaps/nondeprecated/GridPagerAdapterNonDeprecated.kt rename to wear/src/main/kotlin/app/aaps/wear/nondeprecated/GridPagerAdapterNonDeprecated.kt index 5af3500ce6..9233c14b63 100644 --- a/wear/src/main/java/info/nightscout/androidaps/nondeprecated/GridPagerAdapterNonDeprecated.kt +++ b/wear/src/main/kotlin/app/aaps/wear/nondeprecated/GridPagerAdapterNonDeprecated.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.nondeprecated +package app.aaps.wear.nondeprecated import android.support.wearable.view.GridPagerAdapter diff --git a/wear/src/main/java/info/nightscout/androidaps/nondeprecated/GridViewPagerNonDeprecated.kt b/wear/src/main/kotlin/app/aaps/wear/nondeprecated/GridViewPagerNonDeprecated.kt similarity index 88% rename from wear/src/main/java/info/nightscout/androidaps/nondeprecated/GridViewPagerNonDeprecated.kt rename to wear/src/main/kotlin/app/aaps/wear/nondeprecated/GridViewPagerNonDeprecated.kt index eeb476f4ab..747a0f42b9 100644 --- a/wear/src/main/java/info/nightscout/androidaps/nondeprecated/GridViewPagerNonDeprecated.kt +++ b/wear/src/main/kotlin/app/aaps/wear/nondeprecated/GridViewPagerNonDeprecated.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.nondeprecated +package app.aaps.wear.nondeprecated import android.content.Context import android.support.wearable.view.GridViewPager diff --git a/wear/src/main/java/info/nightscout/androidaps/tile/ActionsTileService.kt b/wear/src/main/kotlin/app/aaps/wear/tile/ActionsTileService.kt similarity index 78% rename from wear/src/main/java/info/nightscout/androidaps/tile/ActionsTileService.kt rename to wear/src/main/kotlin/app/aaps/wear/tile/ActionsTileService.kt index 18fdcace9c..72235303cb 100644 --- a/wear/src/main/java/info/nightscout/androidaps/tile/ActionsTileService.kt +++ b/wear/src/main/kotlin/app/aaps/wear/tile/ActionsTileService.kt @@ -1,19 +1,19 @@ -package info.nightscout.androidaps.tile - -import dagger.android.AndroidInjection -import info.nightscout.androidaps.tile.source.ActionSource -import javax.inject.Inject - -class ActionsTileService : TileBase() { - - @Inject lateinit var actionSource: ActionSource - - // Not derived from DaggerService, do injection here - override fun onCreate() { - AndroidInjection.inject(this) - super.onCreate() - } - - override val resourceVersion = "ActionsTileService" - override val source get() = actionSource -} +package app.aaps.wear.tile + +import app.aaps.wear.tile.source.ActionSource +import dagger.android.AndroidInjection +import javax.inject.Inject + +class ActionsTileService : TileBase() { + + @Inject lateinit var actionSource: ActionSource + + // Not derived from DaggerService, do injection here + override fun onCreate() { + AndroidInjection.inject(this) + super.onCreate() + } + + override val resourceVersion = "ActionsTileService" + override val source get() = actionSource +} diff --git a/wear/src/main/java/info/nightscout/androidaps/tile/QuickWizardTileService.kt b/wear/src/main/kotlin/app/aaps/wear/tile/QuickWizardTileService.kt similarity index 78% rename from wear/src/main/java/info/nightscout/androidaps/tile/QuickWizardTileService.kt rename to wear/src/main/kotlin/app/aaps/wear/tile/QuickWizardTileService.kt index 23cd00ca27..61cead0fd8 100644 --- a/wear/src/main/java/info/nightscout/androidaps/tile/QuickWizardTileService.kt +++ b/wear/src/main/kotlin/app/aaps/wear/tile/QuickWizardTileService.kt @@ -1,19 +1,19 @@ -package info.nightscout.androidaps.tile - -import dagger.android.AndroidInjection -import info.nightscout.androidaps.tile.source.QuickWizardSource -import javax.inject.Inject - -class QuickWizardTileService : TileBase() { - - @Inject lateinit var quickWizardSource: QuickWizardSource - - // Not derived from DaggerService, do injection here - override fun onCreate() { - AndroidInjection.inject(this) - super.onCreate() - } - - override val resourceVersion = "QuickWizardTileService" - override val source get() = quickWizardSource -} +package app.aaps.wear.tile + +import app.aaps.wear.tile.source.QuickWizardSource +import dagger.android.AndroidInjection +import javax.inject.Inject + +class QuickWizardTileService : TileBase() { + + @Inject lateinit var quickWizardSource: QuickWizardSource + + // Not derived from DaggerService, do injection here + override fun onCreate() { + AndroidInjection.inject(this) + super.onCreate() + } + + override val resourceVersion = "QuickWizardTileService" + override val source get() = quickWizardSource +} diff --git a/wear/src/main/java/info/nightscout/androidaps/tile/TempTargetTileService.kt b/wear/src/main/kotlin/app/aaps/wear/tile/TempTargetTileService.kt similarity index 78% rename from wear/src/main/java/info/nightscout/androidaps/tile/TempTargetTileService.kt rename to wear/src/main/kotlin/app/aaps/wear/tile/TempTargetTileService.kt index 9526b3feba..daa0ff3783 100644 --- a/wear/src/main/java/info/nightscout/androidaps/tile/TempTargetTileService.kt +++ b/wear/src/main/kotlin/app/aaps/wear/tile/TempTargetTileService.kt @@ -1,19 +1,19 @@ -package info.nightscout.androidaps.tile - -import dagger.android.AndroidInjection -import info.nightscout.androidaps.tile.source.TempTargetSource -import javax.inject.Inject - -class TempTargetTileService : TileBase() { - - @Inject lateinit var tempTargetSource: TempTargetSource - - // Not derived from DaggerService, do injection here - override fun onCreate() { - AndroidInjection.inject(this) - super.onCreate() - } - - override val resourceVersion = "TempTargetTileService" - override val source get() = tempTargetSource -} +package app.aaps.wear.tile + +import app.aaps.wear.tile.source.TempTargetSource +import dagger.android.AndroidInjection +import javax.inject.Inject + +class TempTargetTileService : TileBase() { + + @Inject lateinit var tempTargetSource: TempTargetSource + + // Not derived from DaggerService, do injection here + override fun onCreate() { + AndroidInjection.inject(this) + super.onCreate() + } + + override val resourceVersion = "TempTargetTileService" + override val source get() = tempTargetSource +} diff --git a/wear/src/main/java/info/nightscout/androidaps/tile/TileBase.kt b/wear/src/main/kotlin/app/aaps/wear/tile/TileBase.kt similarity index 96% rename from wear/src/main/java/info/nightscout/androidaps/tile/TileBase.kt rename to wear/src/main/kotlin/app/aaps/wear/tile/TileBase.kt index 4f4c4b7a65..51d28279b0 100644 --- a/wear/src/main/java/info/nightscout/androidaps/tile/TileBase.kt +++ b/wear/src/main/kotlin/app/aaps/wear/tile/TileBase.kt @@ -1,309 +1,309 @@ -@file:Suppress("DEPRECATION") - -package info.nightscout.androidaps.tile - -import androidx.annotation.DrawableRes -import androidx.core.content.ContextCompat -import androidx.wear.tiles.ActionBuilders -import androidx.wear.tiles.ColorBuilders.argb -import androidx.wear.tiles.DeviceParametersBuilders.DeviceParameters -import androidx.wear.tiles.DeviceParametersBuilders.SCREEN_SHAPE_ROUND -import androidx.wear.tiles.DimensionBuilders.SpProp -import androidx.wear.tiles.DimensionBuilders.dp -import androidx.wear.tiles.DimensionBuilders.sp -import androidx.wear.tiles.LayoutElementBuilders.Box -import androidx.wear.tiles.LayoutElementBuilders.Column -import androidx.wear.tiles.LayoutElementBuilders.FONT_WEIGHT_BOLD -import androidx.wear.tiles.LayoutElementBuilders.FontStyle -import androidx.wear.tiles.LayoutElementBuilders.Image -import androidx.wear.tiles.LayoutElementBuilders.Layout -import androidx.wear.tiles.LayoutElementBuilders.LayoutElement -import androidx.wear.tiles.LayoutElementBuilders.Row -import androidx.wear.tiles.LayoutElementBuilders.Spacer -import androidx.wear.tiles.LayoutElementBuilders.Text -import androidx.wear.tiles.ModifiersBuilders.Background -import androidx.wear.tiles.ModifiersBuilders.Clickable -import androidx.wear.tiles.ModifiersBuilders.Corner -import androidx.wear.tiles.ModifiersBuilders.Modifiers -import androidx.wear.tiles.ModifiersBuilders.Semantics -import androidx.wear.tiles.RequestBuilders -import androidx.wear.tiles.RequestBuilders.ResourcesRequest -import androidx.wear.tiles.ResourceBuilders.AndroidImageResourceByResId -import androidx.wear.tiles.ResourceBuilders.ImageResource -import androidx.wear.tiles.ResourceBuilders.Resources -import androidx.wear.tiles.TileBuilders.Tile -import androidx.wear.tiles.TileService -import androidx.wear.tiles.TimelineBuilders.Timeline -import androidx.wear.tiles.TimelineBuilders.TimelineEntry -import app.aaps.core.interfaces.logging.AAPSLogger -import app.aaps.core.interfaces.rx.weardata.EventData -import app.aaps.core.interfaces.sharedPreferences.SP -import com.google.common.util.concurrent.ListenableFuture -import dagger.android.AndroidInjection -import info.nightscout.androidaps.R -import info.nightscout.androidaps.comm.DataLayerListenerServiceWear -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.Job -import kotlinx.coroutines.guava.future -import javax.inject.Inject -import kotlin.math.sqrt - -private const val SPACING_ACTIONS = 3f -private const val ICON_SIZE_FRACTION = 0.4f // Percentage of button diameter -private val BUTTON_COLOR = R.color.gray_850 -private const val LARGE_SCREEN_WIDTH_DP = 210 - -interface TileSource { - - fun getResourceReferences(resources: android.content.res.Resources): List - fun getSelectedActions(): List - fun getValidFor(): Long? -} - -open class Action( - val buttonText: String, - val buttonTextSub: String? = null, - val activityClass: String, - @DrawableRes val iconRes: Int, - val action: EventData? = null, - val message: String? = null, -) - -enum class WearControl { - NO_DATA, ENABLED, DISABLED -} - -abstract class TileBase : TileService() { - - @Inject lateinit var sp: SP - @Inject lateinit var aapsLogger: AAPSLogger - - abstract val resourceVersion: String - abstract val source: TileSource - - private val serviceJob = Job() - private val serviceScope = CoroutineScope(Dispatchers.IO + serviceJob) - - // Not derived from DaggerService, do injection here - override fun onCreate() { - AndroidInjection.inject(this) - super.onCreate() - } - - override fun onTileRequest( - requestParams: RequestBuilders.TileRequest - ): ListenableFuture = serviceScope.future { - val actionsSelected = getSelectedActions() - val wearControl = getWearControl() - val tile = Tile.Builder() - .setResourcesVersion(resourceVersion) - .setTimeline( - Timeline.Builder().addTimelineEntry( - TimelineEntry.Builder().setLayout( - Layout.Builder().setRoot(layout(wearControl, actionsSelected, requestParams.deviceParameters!!)).build() - ).build() - ).build() - ) - - val validFor = validFor() - if (validFor != null) { - tile.setFreshnessIntervalMillis(validFor) - } - tile.build() - } - - private fun getSelectedActions(): List { - // TODO check why thi scan not be don in scope of the coroutine - return source.getSelectedActions() - } - - private fun validFor(): Long? { - return source.getValidFor() - } - - override fun onResourcesRequest( - requestParams: ResourcesRequest - ): ListenableFuture = serviceScope.future { - Resources.Builder() - .setVersion(resourceVersion) - .apply { - source.getResourceReferences(resources).forEach { resourceId -> - addIdToImageMapping( - resourceId.toString(), - ImageResource.Builder() - .setAndroidResourceByResId( - AndroidImageResourceByResId.Builder() - .setResourceId(resourceId) - .build() - ) - .build() - ) - } - } - .build() - } - - private fun layout(wearControl: WearControl, actions: List, deviceParameters: DeviceParameters): LayoutElement { - if (wearControl == WearControl.DISABLED) { - return Text.Builder() - .setText(resources.getString(R.string.wear_control_not_enabled)) - .build() - } else if (wearControl == WearControl.NO_DATA) { - return Text.Builder() - .setText(resources.getString(R.string.wear_control_no_data)) - .build() - } - if (actions.isNotEmpty()) { - with(Column.Builder()) { - if (actions.size == 1 || actions.size == 3) { - addContent(addRowSingle(actions[0], deviceParameters)) - } - if (actions.size == 4 || actions.size == 2) { - addContent(addRowDouble(actions[0], actions[1], deviceParameters)) - } - if (actions.size == 3) { - addContent(addRowDouble(actions[1], actions[2], deviceParameters)) - } - if (actions.size == 4) { - addContent(Spacer.Builder().setHeight(dp(SPACING_ACTIONS)).build()) - addContent(addRowDouble(actions[2], actions[3], deviceParameters)) - } - return build() - } - } - return Text.Builder() - .setText(resources.getString(R.string.tile_no_config)) - .build() - } - - private fun addRowSingle(action: Action, deviceParameters: DeviceParameters): LayoutElement = - Row.Builder() - .addContent(action(action, deviceParameters)) - .build() - - private fun addRowDouble(action1: Action, action2: Action, deviceParameters: DeviceParameters): LayoutElement = - Row.Builder() - .addContent(action(action1, deviceParameters)) - .addContent(Spacer.Builder().setWidth(dp(SPACING_ACTIONS)).build()) - .addContent(action(action2, deviceParameters)) - .build() - - private fun doAction(action: Action): ActionBuilders.Action { - val builder = ActionBuilders.AndroidActivity.Builder() - .setClassName(action.activityClass) - .setPackageName(this.packageName) - if (action.action != null) { - val actionString = ActionBuilders.AndroidStringExtra.Builder().setValue(action.action.serialize()).build() - builder.addKeyToExtraMapping(DataLayerListenerServiceWear.KEY_ACTION, actionString) - } - if (action.message != null) { - val message = ActionBuilders.AndroidStringExtra.Builder().setValue(action.message).build() - builder.addKeyToExtraMapping(DataLayerListenerServiceWear.KEY_MESSAGE, message) - } - - return ActionBuilders.LaunchAction.Builder() - .setAndroidActivity(builder.build()) - .build() - } - - private fun action(action: Action, deviceParameters: DeviceParameters): LayoutElement { - val circleDiameter = circleDiameter(deviceParameters) - val text = action.buttonText - val textSub = action.buttonTextSub - return Box.Builder() - .setWidth(dp(circleDiameter)) - .setHeight(dp(circleDiameter)) - .setModifiers( - Modifiers.Builder() - .setBackground( - Background.Builder() - .setColor(argb(ContextCompat.getColor(baseContext, BUTTON_COLOR))) - .setCorner(Corner.Builder().setRadius(dp(circleDiameter / 2)).build()) - .build() - ) - .setSemantics( - Semantics.Builder() - .setContentDescription("$text $textSub") - .build() - ) - .setClickable( - Clickable.Builder() - .setOnClick(doAction(action)) - .build() - ) - .build() - ) - .addContent(addTextContent(action, deviceParameters)) - .build() - } - - private fun addTextContent(action: Action, deviceParameters: DeviceParameters): LayoutElement { - val circleDiameter = circleDiameter(deviceParameters) - val iconSize = dp(circleDiameter * ICON_SIZE_FRACTION) - val text = action.buttonText - val textSub = action.buttonTextSub - val col = Column.Builder() - .addContent( - Image.Builder() - .setWidth(iconSize) - .setHeight(iconSize) - .setResourceId(action.iconRes.toString()) - .build() - ).addContent( - Text.Builder() - .setText(text) - .setFontStyle( - FontStyle.Builder() - .setWeight(FONT_WEIGHT_BOLD) - .setColor(argb(ContextCompat.getColor(baseContext, R.color.white))) - .setSize(buttonTextSize(deviceParameters, text)) - .build() - ) - .build() - ) - if (textSub != null) { - col.addContent( - Text.Builder() - .setText(textSub) - .setFontStyle( - FontStyle.Builder() - .setColor(argb(ContextCompat.getColor(baseContext, R.color.white))) - .setSize(buttonTextSize(deviceParameters, textSub)) - .build() - ) - .build() - ) - } - - return col.build() - } - - private fun circleDiameter(deviceParameters: DeviceParameters) = when (deviceParameters.screenShape) { - SCREEN_SHAPE_ROUND -> ((sqrt(2f) - 1) * deviceParameters.screenHeightDp) - (2 * SPACING_ACTIONS) - else -> 0.5f * deviceParameters.screenHeightDp - SPACING_ACTIONS - } - - private fun buttonTextSize(deviceParameters: DeviceParameters, text: String): SpProp { - if (text.length > 6) { - return sp(if (isLargeScreen(deviceParameters)) 14f else 12f) - } - return sp(if (isLargeScreen(deviceParameters)) 16f else 14f) - } - - private fun isLargeScreen(deviceParameters: DeviceParameters): Boolean { - return deviceParameters.screenWidthDp >= LARGE_SCREEN_WIDTH_DP - } - - private fun getWearControl(): WearControl { - if (!sp.contains(R.string.key_wear_control)) { - return WearControl.NO_DATA - } - val wearControlPref = sp.getBoolean(R.string.key_wear_control, false) - if (wearControlPref) { - return WearControl.ENABLED - } - return WearControl.DISABLED - } - -} +@file:Suppress("DEPRECATION") + +package app.aaps.wear.tile + +import androidx.annotation.DrawableRes +import androidx.core.content.ContextCompat +import androidx.wear.tiles.ActionBuilders +import androidx.wear.tiles.ColorBuilders.argb +import androidx.wear.tiles.DeviceParametersBuilders.DeviceParameters +import androidx.wear.tiles.DeviceParametersBuilders.SCREEN_SHAPE_ROUND +import androidx.wear.tiles.DimensionBuilders.SpProp +import androidx.wear.tiles.DimensionBuilders.dp +import androidx.wear.tiles.DimensionBuilders.sp +import androidx.wear.tiles.LayoutElementBuilders.Box +import androidx.wear.tiles.LayoutElementBuilders.Column +import androidx.wear.tiles.LayoutElementBuilders.FONT_WEIGHT_BOLD +import androidx.wear.tiles.LayoutElementBuilders.FontStyle +import androidx.wear.tiles.LayoutElementBuilders.Image +import androidx.wear.tiles.LayoutElementBuilders.Layout +import androidx.wear.tiles.LayoutElementBuilders.LayoutElement +import androidx.wear.tiles.LayoutElementBuilders.Row +import androidx.wear.tiles.LayoutElementBuilders.Spacer +import androidx.wear.tiles.LayoutElementBuilders.Text +import androidx.wear.tiles.ModifiersBuilders.Background +import androidx.wear.tiles.ModifiersBuilders.Clickable +import androidx.wear.tiles.ModifiersBuilders.Corner +import androidx.wear.tiles.ModifiersBuilders.Modifiers +import androidx.wear.tiles.ModifiersBuilders.Semantics +import androidx.wear.tiles.RequestBuilders +import androidx.wear.tiles.RequestBuilders.ResourcesRequest +import androidx.wear.tiles.ResourceBuilders.AndroidImageResourceByResId +import androidx.wear.tiles.ResourceBuilders.ImageResource +import androidx.wear.tiles.ResourceBuilders.Resources +import androidx.wear.tiles.TileBuilders.Tile +import androidx.wear.tiles.TileService +import androidx.wear.tiles.TimelineBuilders.Timeline +import androidx.wear.tiles.TimelineBuilders.TimelineEntry +import app.aaps.core.interfaces.logging.AAPSLogger +import app.aaps.core.interfaces.rx.weardata.EventData +import app.aaps.core.interfaces.sharedPreferences.SP +import app.aaps.wear.R +import app.aaps.wear.comm.DataLayerListenerServiceWear +import com.google.common.util.concurrent.ListenableFuture +import dagger.android.AndroidInjection +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.guava.future +import javax.inject.Inject +import kotlin.math.sqrt + +private const val SPACING_ACTIONS = 3f +private const val ICON_SIZE_FRACTION = 0.4f // Percentage of button diameter +private val BUTTON_COLOR = R.color.gray_850 +private const val LARGE_SCREEN_WIDTH_DP = 210 + +interface TileSource { + + fun getResourceReferences(resources: android.content.res.Resources): List + fun getSelectedActions(): List + fun getValidFor(): Long? +} + +open class Action( + val buttonText: String, + val buttonTextSub: String? = null, + val activityClass: String, + @DrawableRes val iconRes: Int, + val action: EventData? = null, + val message: String? = null, +) + +enum class WearControl { + NO_DATA, ENABLED, DISABLED +} + +abstract class TileBase : TileService() { + + @Inject lateinit var sp: SP + @Inject lateinit var aapsLogger: AAPSLogger + + abstract val resourceVersion: String + abstract val source: TileSource + + private val serviceJob = Job() + private val serviceScope = CoroutineScope(Dispatchers.IO + serviceJob) + + // Not derived from DaggerService, do injection here + override fun onCreate() { + AndroidInjection.inject(this) + super.onCreate() + } + + override fun onTileRequest( + requestParams: RequestBuilders.TileRequest + ): ListenableFuture = serviceScope.future { + val actionsSelected = getSelectedActions() + val wearControl = getWearControl() + val tile = Tile.Builder() + .setResourcesVersion(resourceVersion) + .setTimeline( + Timeline.Builder().addTimelineEntry( + TimelineEntry.Builder().setLayout( + Layout.Builder().setRoot(layout(wearControl, actionsSelected, requestParams.deviceParameters!!)).build() + ).build() + ).build() + ) + + val validFor = validFor() + if (validFor != null) { + tile.setFreshnessIntervalMillis(validFor) + } + tile.build() + } + + private fun getSelectedActions(): List { + // TODO check why thi scan not be don in scope of the coroutine + return source.getSelectedActions() + } + + private fun validFor(): Long? { + return source.getValidFor() + } + + override fun onResourcesRequest( + requestParams: ResourcesRequest + ): ListenableFuture = serviceScope.future { + Resources.Builder() + .setVersion(resourceVersion) + .apply { + source.getResourceReferences(resources).forEach { resourceId -> + addIdToImageMapping( + resourceId.toString(), + ImageResource.Builder() + .setAndroidResourceByResId( + AndroidImageResourceByResId.Builder() + .setResourceId(resourceId) + .build() + ) + .build() + ) + } + } + .build() + } + + private fun layout(wearControl: WearControl, actions: List, deviceParameters: DeviceParameters): LayoutElement { + if (wearControl == WearControl.DISABLED) { + return Text.Builder() + .setText(resources.getString(R.string.wear_control_not_enabled)) + .build() + } else if (wearControl == WearControl.NO_DATA) { + return Text.Builder() + .setText(resources.getString(R.string.wear_control_no_data)) + .build() + } + if (actions.isNotEmpty()) { + with(Column.Builder()) { + if (actions.size == 1 || actions.size == 3) { + addContent(addRowSingle(actions[0], deviceParameters)) + } + if (actions.size == 4 || actions.size == 2) { + addContent(addRowDouble(actions[0], actions[1], deviceParameters)) + } + if (actions.size == 3) { + addContent(addRowDouble(actions[1], actions[2], deviceParameters)) + } + if (actions.size == 4) { + addContent(Spacer.Builder().setHeight(dp(SPACING_ACTIONS)).build()) + addContent(addRowDouble(actions[2], actions[3], deviceParameters)) + } + return build() + } + } + return Text.Builder() + .setText(resources.getString(R.string.tile_no_config)) + .build() + } + + private fun addRowSingle(action: Action, deviceParameters: DeviceParameters): LayoutElement = + Row.Builder() + .addContent(action(action, deviceParameters)) + .build() + + private fun addRowDouble(action1: Action, action2: Action, deviceParameters: DeviceParameters): LayoutElement = + Row.Builder() + .addContent(action(action1, deviceParameters)) + .addContent(Spacer.Builder().setWidth(dp(SPACING_ACTIONS)).build()) + .addContent(action(action2, deviceParameters)) + .build() + + private fun doAction(action: Action): ActionBuilders.Action { + val builder = ActionBuilders.AndroidActivity.Builder() + .setClassName(action.activityClass) + .setPackageName(this.packageName) + if (action.action != null) { + val actionString = ActionBuilders.AndroidStringExtra.Builder().setValue(action.action.serialize()).build() + builder.addKeyToExtraMapping(DataLayerListenerServiceWear.KEY_ACTION, actionString) + } + if (action.message != null) { + val message = ActionBuilders.AndroidStringExtra.Builder().setValue(action.message).build() + builder.addKeyToExtraMapping(DataLayerListenerServiceWear.KEY_MESSAGE, message) + } + + return ActionBuilders.LaunchAction.Builder() + .setAndroidActivity(builder.build()) + .build() + } + + private fun action(action: Action, deviceParameters: DeviceParameters): LayoutElement { + val circleDiameter = circleDiameter(deviceParameters) + val text = action.buttonText + val textSub = action.buttonTextSub + return Box.Builder() + .setWidth(dp(circleDiameter)) + .setHeight(dp(circleDiameter)) + .setModifiers( + Modifiers.Builder() + .setBackground( + Background.Builder() + .setColor(argb(ContextCompat.getColor(baseContext, BUTTON_COLOR))) + .setCorner(Corner.Builder().setRadius(dp(circleDiameter / 2)).build()) + .build() + ) + .setSemantics( + Semantics.Builder() + .setContentDescription("$text $textSub") + .build() + ) + .setClickable( + Clickable.Builder() + .setOnClick(doAction(action)) + .build() + ) + .build() + ) + .addContent(addTextContent(action, deviceParameters)) + .build() + } + + private fun addTextContent(action: Action, deviceParameters: DeviceParameters): LayoutElement { + val circleDiameter = circleDiameter(deviceParameters) + val iconSize = dp(circleDiameter * ICON_SIZE_FRACTION) + val text = action.buttonText + val textSub = action.buttonTextSub + val col = Column.Builder() + .addContent( + Image.Builder() + .setWidth(iconSize) + .setHeight(iconSize) + .setResourceId(action.iconRes.toString()) + .build() + ).addContent( + Text.Builder() + .setText(text) + .setFontStyle( + FontStyle.Builder() + .setWeight(FONT_WEIGHT_BOLD) + .setColor(argb(ContextCompat.getColor(baseContext, R.color.white))) + .setSize(buttonTextSize(deviceParameters, text)) + .build() + ) + .build() + ) + if (textSub != null) { + col.addContent( + Text.Builder() + .setText(textSub) + .setFontStyle( + FontStyle.Builder() + .setColor(argb(ContextCompat.getColor(baseContext, R.color.white))) + .setSize(buttonTextSize(deviceParameters, textSub)) + .build() + ) + .build() + ) + } + + return col.build() + } + + private fun circleDiameter(deviceParameters: DeviceParameters) = when (deviceParameters.screenShape) { + SCREEN_SHAPE_ROUND -> ((sqrt(2f) - 1) * deviceParameters.screenHeightDp) - (2 * SPACING_ACTIONS) + else -> 0.5f * deviceParameters.screenHeightDp - SPACING_ACTIONS + } + + private fun buttonTextSize(deviceParameters: DeviceParameters, text: String): SpProp { + if (text.length > 6) { + return sp(if (isLargeScreen(deviceParameters)) 14f else 12f) + } + return sp(if (isLargeScreen(deviceParameters)) 16f else 14f) + } + + private fun isLargeScreen(deviceParameters: DeviceParameters): Boolean { + return deviceParameters.screenWidthDp >= LARGE_SCREEN_WIDTH_DP + } + + private fun getWearControl(): WearControl { + if (!sp.contains(R.string.key_wear_control)) { + return WearControl.NO_DATA + } + val wearControlPref = sp.getBoolean(R.string.key_wear_control, false) + if (wearControlPref) { + return WearControl.ENABLED + } + return WearControl.DISABLED + } + +} diff --git a/wear/src/main/java/info/nightscout/androidaps/tile/source/ActionSource.kt b/wear/src/main/kotlin/app/aaps/wear/tile/source/ActionSource.kt similarity index 81% rename from wear/src/main/java/info/nightscout/androidaps/tile/source/ActionSource.kt rename to wear/src/main/kotlin/app/aaps/wear/tile/source/ActionSource.kt index 36ace680f2..62ec956a9d 100644 --- a/wear/src/main/java/info/nightscout/androidaps/tile/source/ActionSource.kt +++ b/wear/src/main/kotlin/app/aaps/wear/tile/source/ActionSource.kt @@ -1,76 +1,76 @@ -package info.nightscout.androidaps.tile.source - -import android.content.Context -import android.content.res.Resources -import app.aaps.core.interfaces.logging.AAPSLogger -import app.aaps.core.interfaces.sharedPreferences.SP -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.actions.BolusActivity -import info.nightscout.androidaps.interaction.actions.CarbActivity -import info.nightscout.androidaps.interaction.actions.ECarbActivity -import info.nightscout.androidaps.interaction.actions.TempTargetActivity -import info.nightscout.androidaps.interaction.actions.TreatmentActivity -import info.nightscout.androidaps.interaction.actions.WizardActivity -import javax.inject.Inject -import javax.inject.Singleton - -@Singleton -class ActionSource @Inject constructor(context: Context, sp: SP, aapsLogger: AAPSLogger) : StaticTileSource(context, sp, aapsLogger) { - - override val preferencePrefix = "tile_action_" - - override fun getActions(resources: Resources): List { - return listOf( - StaticAction( - settingName = "wizard", - buttonText = resources.getString(R.string.menu_wizard_short), - iconRes = R.drawable.ic_calculator_green, - activityClass = WizardActivity::class.java.name, - ), - StaticAction( - settingName = "treatment", - buttonText = resources.getString(R.string.menu_treatment_short), - iconRes = R.drawable.ic_bolus_carbs, - activityClass = TreatmentActivity::class.java.name, - ), - StaticAction( - settingName = "bolus", - buttonText = resources.getString(R.string.action_insulin), - iconRes = R.drawable.ic_bolus, - activityClass = BolusActivity::class.java.name, - ), - StaticAction( - settingName = "carbs", - buttonText = resources.getString(R.string.action_carbs), - iconRes = R.drawable.ic_carbs_orange, - activityClass = CarbActivity::class.java.name, - ), - StaticAction( - settingName = "ecarbs", - buttonText = resources.getString(R.string.action_ecarbs), - iconRes = R.drawable.ic_carbs_orange, - activityClass = ECarbActivity::class.java.name, - ), - StaticAction( - settingName = "temp_target", - buttonText = resources.getString(R.string.menu_tempt), - iconRes = R.drawable.ic_temptarget_flat, - activityClass = TempTargetActivity::class.java.name, - ) - ) - } - - override fun getResourceReferences(resources: Resources): List { - return getActions(resources).map { it.iconRes } - } - - override fun getDefaultConfig(): Map { - return mapOf( - "tile_action_1" to "wizard", - "tile_action_2" to "treatment", - "tile_action_3" to "ecarbs", - "tile_action_4" to "temp_target" - ) - } - -} +package app.aaps.wear.tile.source + +import android.content.Context +import android.content.res.Resources +import app.aaps.core.interfaces.logging.AAPSLogger +import app.aaps.core.interfaces.sharedPreferences.SP +import app.aaps.wear.R +import app.aaps.wear.interaction.actions.BolusActivity +import app.aaps.wear.interaction.actions.CarbActivity +import app.aaps.wear.interaction.actions.ECarbActivity +import app.aaps.wear.interaction.actions.TempTargetActivity +import app.aaps.wear.interaction.actions.TreatmentActivity +import app.aaps.wear.interaction.actions.WizardActivity +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class ActionSource @Inject constructor(context: Context, sp: SP, aapsLogger: AAPSLogger) : StaticTileSource(context, sp, aapsLogger) { + + override val preferencePrefix = "tile_action_" + + override fun getActions(resources: Resources): List { + return listOf( + StaticAction( + settingName = "wizard", + buttonText = resources.getString(R.string.menu_wizard_short), + iconRes = R.drawable.ic_calculator_green, + activityClass = WizardActivity::class.java.name, + ), + StaticAction( + settingName = "treatment", + buttonText = resources.getString(R.string.menu_treatment_short), + iconRes = R.drawable.ic_bolus_carbs, + activityClass = TreatmentActivity::class.java.name, + ), + StaticAction( + settingName = "bolus", + buttonText = resources.getString(R.string.action_insulin), + iconRes = R.drawable.ic_bolus, + activityClass = BolusActivity::class.java.name, + ), + StaticAction( + settingName = "carbs", + buttonText = resources.getString(R.string.action_carbs), + iconRes = R.drawable.ic_carbs_orange, + activityClass = CarbActivity::class.java.name, + ), + StaticAction( + settingName = "ecarbs", + buttonText = resources.getString(R.string.action_ecarbs), + iconRes = R.drawable.ic_carbs_orange, + activityClass = ECarbActivity::class.java.name, + ), + StaticAction( + settingName = "temp_target", + buttonText = resources.getString(R.string.menu_tempt), + iconRes = R.drawable.ic_temptarget_flat, + activityClass = TempTargetActivity::class.java.name, + ) + ) + } + + override fun getResourceReferences(resources: Resources): List { + return getActions(resources).map { it.iconRes } + } + + override fun getDefaultConfig(): Map { + return mapOf( + "tile_action_1" to "wizard", + "tile_action_2" to "treatment", + "tile_action_3" to "ecarbs", + "tile_action_4" to "temp_target" + ) + } + +} diff --git a/wear/src/main/java/info/nightscout/androidaps/tile/source/QuickWizardSource.kt b/wear/src/main/kotlin/app/aaps/wear/tile/source/QuickWizardSource.kt similarity index 90% rename from wear/src/main/java/info/nightscout/androidaps/tile/source/QuickWizardSource.kt rename to wear/src/main/kotlin/app/aaps/wear/tile/source/QuickWizardSource.kt index 48829ff81d..9da00b8ca5 100644 --- a/wear/src/main/java/info/nightscout/androidaps/tile/source/QuickWizardSource.kt +++ b/wear/src/main/kotlin/app/aaps/wear/tile/source/QuickWizardSource.kt @@ -1,81 +1,81 @@ -package info.nightscout.androidaps.tile.source - -import android.content.Context -import android.content.res.Resources -import app.aaps.core.interfaces.logging.AAPSLogger -import app.aaps.core.interfaces.logging.LTag -import app.aaps.core.interfaces.rx.weardata.EventData -import app.aaps.core.interfaces.sharedPreferences.SP -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.actions.BackgroundActionActivity -import info.nightscout.androidaps.tile.Action -import info.nightscout.androidaps.tile.TileSource -import java.util.Calendar -import javax.inject.Inject -import javax.inject.Singleton - -@Singleton -class QuickWizardSource @Inject constructor(private val context: Context, private val sp: SP, private val aapsLogger: AAPSLogger) : TileSource { - - override fun getSelectedActions(): List { - val quickList = mutableListOf() - val quickMap = getQuickWizardData(sp) - val sfm = secondsFromMidnight() - - for (quick in quickMap.entries) { - val isActive = sfm in quick.validFrom..quick.validTo - if (isActive && quick.guid.isNotEmpty()) { - quickList.add( - Action( - buttonText = quick.buttonText, - buttonTextSub = "${quick.carbs} g", - iconRes = R.drawable.ic_quick_wizard, - activityClass = BackgroundActionActivity::class.java.name, - action = EventData.ActionQuickWizardPreCheck(quick.guid), - message = context.resources.getString(R.string.action_quick_wizard_confirmation) - ) - ) - aapsLogger.info(LTag.WEAR, """getSelectedActions: active ${quick.buttonText} guid=${quick.guid}""") - } else { - aapsLogger.info(LTag.WEAR, """getSelectedActions: not active ${quick.buttonText} guid=${quick.guid}""") - } - } - return quickList - } - - override fun getValidFor(): Long? { - val quickMap = getQuickWizardData(sp) - if (quickMap.entries.size == 0) return null - - val sfm = secondsFromMidnight() - var validTill = 24 * 60 * 60 - - for (quick in quickMap.entries) { - val isActive = sfm in quick.validFrom..quick.validTo - if (quick.guid.isNotEmpty()) { - if (isActive && validTill > quick.validTo) validTill = quick.validTo - if (quick.validFrom in (sfm + 1) until validTill) validTill = quick.validFrom - } - } - - val validWithin = 60 - //aapsLogger.info(LTag.WEAR, "getValidTill: sfm$sfm till$validTill d=$delta") - return (validTill - sfm + validWithin) * 1000L - } - - private fun getQuickWizardData(sp: SP): EventData.QuickWizard = - EventData.deserialize(sp.getString(R.string.key_quick_wizard_data, EventData.QuickWizard(arrayListOf()).serialize())) as EventData.QuickWizard - - private fun secondsFromMidnight(): Int { - val c = Calendar.getInstance() - c.set(Calendar.HOUR_OF_DAY, 0) - c.set(Calendar.MINUTE, 0) - c.set(Calendar.SECOND, 0) - c.set(Calendar.MILLISECOND, 0) - val passed: Long = System.currentTimeMillis() - c.timeInMillis - - return (passed / 1000).toInt() - } - - override fun getResourceReferences(resources: Resources): List = listOf(R.drawable.ic_quick_wizard) -} +package app.aaps.wear.tile.source + +import android.content.Context +import android.content.res.Resources +import app.aaps.core.interfaces.logging.AAPSLogger +import app.aaps.core.interfaces.logging.LTag +import app.aaps.core.interfaces.rx.weardata.EventData +import app.aaps.core.interfaces.sharedPreferences.SP +import app.aaps.wear.R +import app.aaps.wear.interaction.actions.BackgroundActionActivity +import app.aaps.wear.tile.Action +import app.aaps.wear.tile.TileSource +import java.util.Calendar +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class QuickWizardSource @Inject constructor(private val context: Context, private val sp: SP, private val aapsLogger: AAPSLogger) : TileSource { + + override fun getSelectedActions(): List { + val quickList = mutableListOf() + val quickMap = getQuickWizardData(sp) + val sfm = secondsFromMidnight() + + for (quick in quickMap.entries) { + val isActive = sfm in quick.validFrom..quick.validTo + if (isActive && quick.guid.isNotEmpty()) { + quickList.add( + Action( + buttonText = quick.buttonText, + buttonTextSub = "${quick.carbs} g", + iconRes = R.drawable.ic_quick_wizard, + activityClass = BackgroundActionActivity::class.java.name, + action = EventData.ActionQuickWizardPreCheck(quick.guid), + message = context.resources.getString(R.string.action_quick_wizard_confirmation) + ) + ) + aapsLogger.info(LTag.WEAR, """getSelectedActions: active ${quick.buttonText} guid=${quick.guid}""") + } else { + aapsLogger.info(LTag.WEAR, """getSelectedActions: not active ${quick.buttonText} guid=${quick.guid}""") + } + } + return quickList + } + + override fun getValidFor(): Long? { + val quickMap = getQuickWizardData(sp) + if (quickMap.entries.size == 0) return null + + val sfm = secondsFromMidnight() + var validTill = 24 * 60 * 60 + + for (quick in quickMap.entries) { + val isActive = sfm in quick.validFrom..quick.validTo + if (quick.guid.isNotEmpty()) { + if (isActive && validTill > quick.validTo) validTill = quick.validTo + if (quick.validFrom in (sfm + 1) until validTill) validTill = quick.validFrom + } + } + + val validWithin = 60 + //aapsLogger.info(LTag.WEAR, "getValidTill: sfm$sfm till$validTill d=$delta") + return (validTill - sfm + validWithin) * 1000L + } + + private fun getQuickWizardData(sp: SP): EventData.QuickWizard = + EventData.deserialize(sp.getString(R.string.key_quick_wizard_data, EventData.QuickWizard(arrayListOf()).serialize())) as EventData.QuickWizard + + private fun secondsFromMidnight(): Int { + val c = Calendar.getInstance() + c.set(Calendar.HOUR_OF_DAY, 0) + c.set(Calendar.MINUTE, 0) + c.set(Calendar.SECOND, 0) + c.set(Calendar.MILLISECOND, 0) + val passed: Long = System.currentTimeMillis() - c.timeInMillis + + return (passed / 1000).toInt() + } + + override fun getResourceReferences(resources: Resources): List = listOf(R.drawable.ic_quick_wizard) +} diff --git a/wear/src/main/java/info/nightscout/androidaps/tile/source/StaticTileSource.kt b/wear/src/main/kotlin/app/aaps/wear/tile/source/StaticTileSource.kt similarity index 90% rename from wear/src/main/java/info/nightscout/androidaps/tile/source/StaticTileSource.kt rename to wear/src/main/kotlin/app/aaps/wear/tile/source/StaticTileSource.kt index 0ac9a7381f..2d5e1489a3 100644 --- a/wear/src/main/java/info/nightscout/androidaps/tile/source/StaticTileSource.kt +++ b/wear/src/main/kotlin/app/aaps/wear/tile/source/StaticTileSource.kt @@ -1,61 +1,61 @@ -package info.nightscout.androidaps.tile.source - -import android.content.Context -import android.content.res.Resources -import androidx.annotation.DrawableRes -import app.aaps.core.interfaces.logging.AAPSLogger -import app.aaps.core.interfaces.rx.weardata.EventData -import app.aaps.core.interfaces.sharedPreferences.SP -import info.nightscout.androidaps.tile.Action -import info.nightscout.androidaps.tile.TileSource - -abstract class StaticTileSource(val context: Context, val sp: SP, val aapsLogger: AAPSLogger) : TileSource { - - class StaticAction( - val settingName: String, - buttonText: String, - buttonTextSub: String? = null, - activityClass: String, - @DrawableRes iconRes: Int, - action: EventData? = null, - message: String? = null, - ) : Action(buttonText, buttonTextSub, activityClass, iconRes, action, message) - - abstract fun getActions(resources: Resources): List - - abstract val preferencePrefix: String - abstract fun getDefaultConfig(): Map - - override fun getSelectedActions(): List { - setDefaultSettings() - - val actionList: MutableList = mutableListOf() - for (i in 1..4) { - val action = getActionFromPreference(i) - if (action != null) { - actionList.add(action) - } - } - if (actionList.isEmpty()) { - return getActions(context.resources).take(4) - } - return actionList - } - - override fun getValidFor(): Long? = null - - private fun getActionFromPreference(index: Int): Action? { - val actionPref = sp.getString(preferencePrefix + index, "none") - return getActions(context.resources).find { action -> action.settingName == actionPref } - } - - private fun setDefaultSettings() { - val defaults = getDefaultConfig() - val firstKey = defaults.firstNotNullOf { settings -> settings.key } - if (!sp.contains(firstKey)) { - for ((key, value) in defaults) { - sp.putString(key, value) - } - } - } -} +package app.aaps.wear.tile.source + +import android.content.Context +import android.content.res.Resources +import androidx.annotation.DrawableRes +import app.aaps.core.interfaces.logging.AAPSLogger +import app.aaps.core.interfaces.rx.weardata.EventData +import app.aaps.core.interfaces.sharedPreferences.SP +import app.aaps.wear.tile.Action +import app.aaps.wear.tile.TileSource + +abstract class StaticTileSource(val context: Context, val sp: SP, val aapsLogger: AAPSLogger) : TileSource { + + class StaticAction( + val settingName: String, + buttonText: String, + buttonTextSub: String? = null, + activityClass: String, + @DrawableRes iconRes: Int, + action: EventData? = null, + message: String? = null, + ) : Action(buttonText, buttonTextSub, activityClass, iconRes, action, message) + + abstract fun getActions(resources: Resources): List + + abstract val preferencePrefix: String + abstract fun getDefaultConfig(): Map + + override fun getSelectedActions(): List { + setDefaultSettings() + + val actionList: MutableList = mutableListOf() + for (i in 1..4) { + val action = getActionFromPreference(i) + if (action != null) { + actionList.add(action) + } + } + if (actionList.isEmpty()) { + return getActions(context.resources).take(4) + } + return actionList + } + + override fun getValidFor(): Long? = null + + private fun getActionFromPreference(index: Int): Action? { + val actionPref = sp.getString(preferencePrefix + index, "none") + return getActions(context.resources).find { action -> action.settingName == actionPref } + } + + private fun setDefaultSettings() { + val defaults = getDefaultConfig() + val firstKey = defaults.firstNotNullOf { settings -> settings.key } + if (!sp.contains(firstKey)) { + for ((key, value) in defaults) { + sp.putString(key, value) + } + } + } +} diff --git a/wear/src/main/java/info/nightscout/androidaps/tile/source/TempTargetSource.kt b/wear/src/main/kotlin/app/aaps/wear/tile/source/TempTargetSource.kt similarity index 92% rename from wear/src/main/java/info/nightscout/androidaps/tile/source/TempTargetSource.kt rename to wear/src/main/kotlin/app/aaps/wear/tile/source/TempTargetSource.kt index deaefb3318..12db6c6fd8 100644 --- a/wear/src/main/java/info/nightscout/androidaps/tile/source/TempTargetSource.kt +++ b/wear/src/main/kotlin/app/aaps/wear/tile/source/TempTargetSource.kt @@ -1,83 +1,83 @@ -package info.nightscout.androidaps.tile.source - -import android.content.Context -import android.content.res.Resources -import app.aaps.core.interfaces.logging.AAPSLogger -import app.aaps.core.interfaces.rx.weardata.EventData -import app.aaps.core.interfaces.sharedPreferences.SP -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interaction.actions.BackgroundActionActivity -import info.nightscout.androidaps.interaction.actions.TempTargetActivity -import javax.inject.Inject -import javax.inject.Singleton - -@Singleton -class TempTargetSource @Inject constructor(context: Context, sp: SP, aapsLogger: AAPSLogger) : StaticTileSource(context, sp, aapsLogger) { - - override val preferencePrefix = "tile_tempt_" - - override fun getActions(resources: Resources): List { - val message = resources.getString(R.string.action_tempt_confirmation) - return listOf( - StaticAction( - settingName = "activity", - buttonText = resources.getString(R.string.temp_target_activity), - iconRes = R.drawable.ic_target_activity, - activityClass = BackgroundActionActivity::class.java.name, - message = message, - // actionString = "temptarget false 90 8.0 8.0", - // actionString = "temptarget preset activity", - action = EventData.ActionTempTargetPreCheck(EventData.ActionTempTargetPreCheck.TempTargetCommand.PRESET_ACTIVITY) - ), - StaticAction( - settingName = "eating_soon", - buttonText = resources.getString(R.string.temp_target_eating_soon), - iconRes = R.drawable.ic_target_eatingsoon, - activityClass = BackgroundActionActivity::class.java.name, - message = message, - // actionString = "temptarget false 45 4.5 4.5", - // actionString = "temptarget preset eating", - action = EventData.ActionTempTargetPreCheck(EventData.ActionTempTargetPreCheck.TempTargetCommand.PRESET_EATING) - ), - StaticAction( - settingName = "hypo", - buttonText = resources.getString(R.string.temp_target_hypo), - iconRes = R.drawable.ic_target_hypo, - activityClass = BackgroundActionActivity::class.java.name, - message = message, - // actionString = "temptarget false 45 7.0 7.0", - // actionString = "temptarget preset hypo", - action = EventData.ActionTempTargetPreCheck(EventData.ActionTempTargetPreCheck.TempTargetCommand.PRESET_HYPO) - ), - StaticAction( - settingName = "manual", - buttonText = resources.getString(R.string.temp_target_manual), - iconRes = R.drawable.ic_target_manual, - activityClass = TempTargetActivity::class.java.name, - action = null - ), - StaticAction( - settingName = "cancel", - buttonText = resources.getString(android.support.wearable.R.string.generic_cancel), - iconRes = R.drawable.ic_target_cancel, - activityClass = BackgroundActionActivity::class.java.name, - message = message, - //actionString = "temptarget cancel", - action = EventData.ActionTempTargetPreCheck(EventData.ActionTempTargetPreCheck.TempTargetCommand.CANCEL) - ) - ) - } - - override fun getResourceReferences(resources: Resources): List { - return getActions(resources).map { it.iconRes } - } - - override fun getDefaultConfig(): Map { - return mapOf( - "tile_tempt_1" to "activity", - "tile_tempt_2" to "eating_soon", - "tile_tempt_3" to "hypo", - "tile_tempt_4" to "manual" - ) - } -} +package app.aaps.wear.tile.source + +import android.content.Context +import android.content.res.Resources +import app.aaps.core.interfaces.logging.AAPSLogger +import app.aaps.core.interfaces.rx.weardata.EventData +import app.aaps.core.interfaces.sharedPreferences.SP +import app.aaps.wear.R +import app.aaps.wear.interaction.actions.BackgroundActionActivity +import app.aaps.wear.interaction.actions.TempTargetActivity +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class TempTargetSource @Inject constructor(context: Context, sp: SP, aapsLogger: AAPSLogger) : StaticTileSource(context, sp, aapsLogger) { + + override val preferencePrefix = "tile_tempt_" + + override fun getActions(resources: Resources): List { + val message = resources.getString(R.string.action_tempt_confirmation) + return listOf( + StaticAction( + settingName = "activity", + buttonText = resources.getString(R.string.temp_target_activity), + iconRes = R.drawable.ic_target_activity, + activityClass = BackgroundActionActivity::class.java.name, + message = message, + // actionString = "temptarget false 90 8.0 8.0", + // actionString = "temptarget preset activity", + action = EventData.ActionTempTargetPreCheck(EventData.ActionTempTargetPreCheck.TempTargetCommand.PRESET_ACTIVITY) + ), + StaticAction( + settingName = "eating_soon", + buttonText = resources.getString(R.string.temp_target_eating_soon), + iconRes = R.drawable.ic_target_eatingsoon, + activityClass = BackgroundActionActivity::class.java.name, + message = message, + // actionString = "temptarget false 45 4.5 4.5", + // actionString = "temptarget preset eating", + action = EventData.ActionTempTargetPreCheck(EventData.ActionTempTargetPreCheck.TempTargetCommand.PRESET_EATING) + ), + StaticAction( + settingName = "hypo", + buttonText = resources.getString(R.string.temp_target_hypo), + iconRes = R.drawable.ic_target_hypo, + activityClass = BackgroundActionActivity::class.java.name, + message = message, + // actionString = "temptarget false 45 7.0 7.0", + // actionString = "temptarget preset hypo", + action = EventData.ActionTempTargetPreCheck(EventData.ActionTempTargetPreCheck.TempTargetCommand.PRESET_HYPO) + ), + StaticAction( + settingName = "manual", + buttonText = resources.getString(R.string.temp_target_manual), + iconRes = R.drawable.ic_target_manual, + activityClass = TempTargetActivity::class.java.name, + action = null + ), + StaticAction( + settingName = "cancel", + buttonText = resources.getString(android.support.wearable.R.string.generic_cancel), + iconRes = R.drawable.ic_target_cancel, + activityClass = BackgroundActionActivity::class.java.name, + message = message, + //actionString = "temptarget cancel", + action = EventData.ActionTempTargetPreCheck(EventData.ActionTempTargetPreCheck.TempTargetCommand.CANCEL) + ) + ) + } + + override fun getResourceReferences(resources: Resources): List { + return getActions(resources).map { it.iconRes } + } + + override fun getDefaultConfig(): Map { + return mapOf( + "tile_tempt_1" to "activity", + "tile_tempt_2" to "eating_soon", + "tile_tempt_3" to "hypo", + "tile_tempt_4" to "manual" + ) + } +} diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsLargeWatchface.kt b/wear/src/main/kotlin/app/aaps/wear/watchfaces/AapsLargeWatchface.kt similarity index 96% rename from wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsLargeWatchface.kt rename to wear/src/main/kotlin/app/aaps/wear/watchfaces/AapsLargeWatchface.kt index b8f922f300..9e6abbfb02 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsLargeWatchface.kt +++ b/wear/src/main/kotlin/app/aaps/wear/watchfaces/AapsLargeWatchface.kt @@ -1,13 +1,13 @@ -package info.nightscout.androidaps.watchfaces +package app.aaps.wear.watchfaces import android.graphics.Color import android.view.LayoutInflater import androidx.core.content.ContextCompat import androidx.viewbinding.ViewBinding +import app.aaps.wear.R +import app.aaps.wear.databinding.ActivityHomeLargeBinding +import app.aaps.wear.watchfaces.utils.BaseWatchFace import com.ustwo.clockwise.common.WatchMode -import info.nightscout.androidaps.R -import info.nightscout.androidaps.databinding.ActivityHomeLargeBinding -import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace class AapsLargeWatchface : BaseWatchFace() { diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsV2Watchface.kt b/wear/src/main/kotlin/app/aaps/wear/watchfaces/AapsV2Watchface.kt similarity index 97% rename from wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsV2Watchface.kt rename to wear/src/main/kotlin/app/aaps/wear/watchfaces/AapsV2Watchface.kt index 2bd28d0866..df7723998d 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsV2Watchface.kt +++ b/wear/src/main/kotlin/app/aaps/wear/watchfaces/AapsV2Watchface.kt @@ -1,14 +1,14 @@ -package info.nightscout.androidaps.watchfaces +package app.aaps.wear.watchfaces import android.graphics.Color import android.view.LayoutInflater import androidx.annotation.ColorInt import androidx.core.content.ContextCompat import androidx.viewbinding.ViewBinding +import app.aaps.wear.R +import app.aaps.wear.databinding.ActivityHome2Binding +import app.aaps.wear.watchfaces.utils.BaseWatchFace import com.ustwo.clockwise.common.WatchMode -import info.nightscout.androidaps.R -import info.nightscout.androidaps.databinding.ActivityHome2Binding -import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace class AapsV2Watchface : BaseWatchFace() { diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsWatchface.kt b/wear/src/main/kotlin/app/aaps/wear/watchfaces/AapsWatchface.kt similarity index 96% rename from wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsWatchface.kt rename to wear/src/main/kotlin/app/aaps/wear/watchfaces/AapsWatchface.kt index 4fb3bfc30e..5523e06b88 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsWatchface.kt +++ b/wear/src/main/kotlin/app/aaps/wear/watchfaces/AapsWatchface.kt @@ -1,13 +1,13 @@ -package info.nightscout.androidaps.watchfaces +package app.aaps.wear.watchfaces import android.graphics.Color import android.view.LayoutInflater import androidx.core.content.ContextCompat import androidx.viewbinding.ViewBinding +import app.aaps.wear.R +import app.aaps.wear.databinding.ActivityHomeBinding +import app.aaps.wear.watchfaces.utils.BaseWatchFace import com.ustwo.clockwise.common.WatchMode -import info.nightscout.androidaps.R -import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace -import info.nightscout.androidaps.databinding.ActivityHomeBinding class AapsWatchface : BaseWatchFace() { diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BigChartWatchface.kt b/wear/src/main/kotlin/app/aaps/wear/watchfaces/BigChartWatchface.kt similarity index 90% rename from wear/src/main/java/info/nightscout/androidaps/watchfaces/BigChartWatchface.kt rename to wear/src/main/kotlin/app/aaps/wear/watchfaces/BigChartWatchface.kt index 020c1c8d4b..dbad8dbd01 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BigChartWatchface.kt +++ b/wear/src/main/kotlin/app/aaps/wear/watchfaces/BigChartWatchface.kt @@ -1,16 +1,16 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.watchfaces +package app.aaps.wear.watchfaces import android.annotation.SuppressLint import android.view.LayoutInflater import androidx.core.content.ContextCompat import androidx.viewbinding.ViewBinding +import app.aaps.wear.R +import app.aaps.wear.databinding.ActivityBigchartBinding +import app.aaps.wear.watchfaces.utils.BaseWatchFace +import app.aaps.wear.watchfaces.utils.WatchfaceViewAdapter import com.ustwo.clockwise.common.WatchMode -import info.nightscout.androidaps.R -import info.nightscout.androidaps.databinding.ActivityBigchartBinding -import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace -import info.nightscout.androidaps.watchfaces.utils.WatchfaceViewAdapter class BigChartWatchface : BaseWatchFace() { @@ -53,9 +53,9 @@ class BigChartWatchface : BaseWatchFace() { binding.status?.setTextColor(ContextCompat.getColor(this, R.color.dark_statusView)) binding.mainLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) val color = when (singleBg.sgvLevel) { - 1L -> R.color.dark_highColor - 0L -> R.color.dark_midColor - -1L -> R.color.dark_lowColor + 1L -> R.color.dark_highColor + 0L -> R.color.dark_midColor + -1L -> R.color.dark_lowColor else -> R.color.dark_midColor } binding.sgv?.setTextColor(ContextCompat.getColor(this, color)) @@ -82,9 +82,9 @@ class BigChartWatchface : BaseWatchFace() { binding.status?.setTextColor(ContextCompat.getColor(this, R.color.light_bigchart_status)) binding.mainLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.light_background)) val color = when (singleBg.sgvLevel) { - 1L -> R.color.light_highColor - 0L -> R.color.light_midColor - -1L -> R.color.light_lowColor + 1L -> R.color.light_highColor + 0L -> R.color.light_midColor + -1L -> R.color.light_lowColor else -> R.color.light_midColor } binding.sgv?.setTextColor(ContextCompat.getColor(this, color)) diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.kt b/wear/src/main/kotlin/app/aaps/wear/watchfaces/CircleWatchface.kt similarity index 98% rename from wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.kt rename to wear/src/main/kotlin/app/aaps/wear/watchfaces/CircleWatchface.kt index cd132d0c74..1d92a673d5 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.kt +++ b/wear/src/main/kotlin/app/aaps/wear/watchfaces/CircleWatchface.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.watchfaces +package app.aaps.wear.watchfaces import android.annotation.SuppressLint import android.content.Intent @@ -25,13 +25,13 @@ import app.aaps.core.interfaces.rx.weardata.EventData import app.aaps.core.interfaces.rx.weardata.EventData.ActionResendData import app.aaps.core.interfaces.rx.weardata.EventData.SingleBg import app.aaps.core.interfaces.sharedPreferences.SP +import app.aaps.wear.R +import app.aaps.wear.data.RawDisplayData +import app.aaps.wear.interaction.menus.MainMenuActivity +import app.aaps.wear.interaction.utils.Persistence import com.ustwo.clockwise.common.WatchFaceTime import com.ustwo.clockwise.wearable.WatchFace import dagger.android.AndroidInjection -import info.nightscout.androidaps.R -import info.nightscout.androidaps.data.RawDisplayData -import info.nightscout.androidaps.interaction.menus.MainMenuActivity -import info.nightscout.androidaps.interaction.utils.Persistence import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import java.util.* diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CockpitWatchface.kt b/wear/src/main/kotlin/app/aaps/wear/watchfaces/CockpitWatchface.kt similarity index 86% rename from wear/src/main/java/info/nightscout/androidaps/watchfaces/CockpitWatchface.kt rename to wear/src/main/kotlin/app/aaps/wear/watchfaces/CockpitWatchface.kt index 97af6a42e1..7c0ac08220 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CockpitWatchface.kt +++ b/wear/src/main/kotlin/app/aaps/wear/watchfaces/CockpitWatchface.kt @@ -1,11 +1,11 @@ -package info.nightscout.androidaps.watchfaces +package app.aaps.wear.watchfaces import android.view.LayoutInflater import android.view.View import androidx.viewbinding.ViewBinding -import info.nightscout.androidaps.R -import info.nightscout.androidaps.databinding.ActivityCockpitBinding -import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace +import app.aaps.wear.R +import app.aaps.wear.databinding.ActivityCockpitBinding +import app.aaps.wear.watchfaces.utils.BaseWatchFace /** * Created by andrew-warrington on 18/11/2017. @@ -24,9 +24,9 @@ class CockpitWatchface : BaseWatchFace() { binding.mainLayout.setBackgroundResource(R.drawable.airplane_cockpit_outside_clouds) setTextSizes() val led = when (singleBg.sgvLevel) { - 1L -> R.drawable.airplane_led_yellow_lit - 0L -> R.drawable.airplane_led_grey_unlit - -1L -> R.drawable.airplane_led_red_lit + 1L -> R.drawable.airplane_led_yellow_lit + 0L -> R.drawable.airplane_led_grey_unlit + -1L -> R.drawable.airplane_led_red_lit else -> R.drawable.airplane_led_grey_unlit } diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt b/wear/src/main/kotlin/app/aaps/wear/watchfaces/CustomWatchface.kt similarity index 99% rename from wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt rename to wear/src/main/kotlin/app/aaps/wear/watchfaces/CustomWatchface.kt index c5b47976d0..e8d5d868ae 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt +++ b/wear/src/main/kotlin/app/aaps/wear/watchfaces/CustomWatchface.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.watchfaces +package app.aaps.wear.watchfaces import android.annotation.SuppressLint import android.content.Context @@ -44,9 +44,9 @@ import app.aaps.core.interfaces.rx.weardata.ResFileMap import app.aaps.core.interfaces.rx.weardata.ResFormat import app.aaps.core.interfaces.rx.weardata.ViewKeys import app.aaps.core.interfaces.rx.weardata.ZipWatchfaceFormat -import info.nightscout.androidaps.R -import info.nightscout.androidaps.databinding.ActivityCustomBinding -import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace +import app.aaps.wear.R +import app.aaps.wear.databinding.ActivityCustomBinding +import app.aaps.wear.watchfaces.utils.BaseWatchFace import org.joda.time.TimeOfDay import org.json.JSONObject import java.io.ByteArrayOutputStream diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/DigitalStyleWatchface.kt b/wear/src/main/kotlin/app/aaps/wear/watchfaces/DigitalStyleWatchface.kt similarity index 96% rename from wear/src/main/java/info/nightscout/androidaps/watchfaces/DigitalStyleWatchface.kt rename to wear/src/main/kotlin/app/aaps/wear/watchfaces/DigitalStyleWatchface.kt index c490adf38e..377632b0c4 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/DigitalStyleWatchface.kt +++ b/wear/src/main/kotlin/app/aaps/wear/watchfaces/DigitalStyleWatchface.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.watchfaces +package app.aaps.wear.watchfaces import android.annotation.SuppressLint import android.support.wearable.watchface.WatchFaceStyle @@ -10,9 +10,9 @@ import android.widget.LinearLayout import androidx.core.content.ContextCompat import androidx.viewbinding.ViewBinding import app.aaps.core.interfaces.logging.LTag -import info.nightscout.androidaps.R -import info.nightscout.androidaps.databinding.ActivityDigitalstyleBinding -import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace +import app.aaps.wear.R +import app.aaps.wear.databinding.ActivityDigitalstyleBinding +import app.aaps.wear.watchfaces.utils.BaseWatchFace class DigitalStyleWatchface : BaseWatchFace() { diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/NoChartWatchface.kt b/wear/src/main/kotlin/app/aaps/wear/watchfaces/NoChartWatchface.kt similarity index 90% rename from wear/src/main/java/info/nightscout/androidaps/watchfaces/NoChartWatchface.kt rename to wear/src/main/kotlin/app/aaps/wear/watchfaces/NoChartWatchface.kt index ac160baaf3..4f64489e9c 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/NoChartWatchface.kt +++ b/wear/src/main/kotlin/app/aaps/wear/watchfaces/NoChartWatchface.kt @@ -1,14 +1,13 @@ -package info.nightscout.androidaps.watchfaces +package app.aaps.wear.watchfaces import android.view.LayoutInflater import androidx.core.content.ContextCompat import androidx.viewbinding.ViewBinding +import app.aaps.wear.R +import app.aaps.wear.databinding.ActivityNochartBinding +import app.aaps.wear.watchfaces.utils.BaseWatchFace +import app.aaps.wear.watchfaces.utils.WatchfaceViewAdapter import com.ustwo.clockwise.common.WatchMode -import info.nightscout.androidaps.R -import info.nightscout.androidaps.databinding.ActivityBigchartBinding -import info.nightscout.androidaps.databinding.ActivityNochartBinding -import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace -import info.nightscout.androidaps.watchfaces.utils.WatchfaceViewAdapter class NoChartWatchface : BaseWatchFace() { diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/SteampunkWatchface.kt b/wear/src/main/kotlin/app/aaps/wear/watchfaces/SteampunkWatchface.kt similarity index 97% rename from wear/src/main/java/info/nightscout/androidaps/watchfaces/SteampunkWatchface.kt rename to wear/src/main/kotlin/app/aaps/wear/watchfaces/SteampunkWatchface.kt index f17ceb84b7..dc3acea391 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/SteampunkWatchface.kt +++ b/wear/src/main/kotlin/app/aaps/wear/watchfaces/SteampunkWatchface.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.watchfaces +package app.aaps.wear.watchfaces import android.view.LayoutInflater import android.view.animation.Animation @@ -9,9 +9,9 @@ import android.view.animation.RotateAnimation import androidx.core.content.ContextCompat import androidx.viewbinding.ViewBinding import app.aaps.core.interfaces.utils.SafeParse.stringToFloat -import info.nightscout.androidaps.R -import info.nightscout.androidaps.databinding.ActivitySteampunkBinding -import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace +import app.aaps.wear.R +import app.aaps.wear.databinding.ActivitySteampunkBinding +import app.aaps.wear.watchfaces.utils.BaseWatchFace import org.joda.time.TimeOfDay /** diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BaseWatchFace.kt b/wear/src/main/kotlin/app/aaps/wear/watchfaces/utils/BaseWatchFace.kt similarity index 97% rename from wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BaseWatchFace.kt rename to wear/src/main/kotlin/app/aaps/wear/watchfaces/utils/BaseWatchFace.kt index a69a4f5595..ea623a9946 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BaseWatchFace.kt +++ b/wear/src/main/kotlin/app/aaps/wear/watchfaces/utils/BaseWatchFace.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package info.nightscout.androidaps.watchfaces.utils +package app.aaps.wear.watchfaces.utils import android.annotation.SuppressLint import android.content.Intent @@ -23,18 +23,18 @@ import app.aaps.core.interfaces.rx.weardata.EventData import app.aaps.core.interfaces.rx.weardata.EventData.ActionResendData import app.aaps.core.interfaces.sharedPreferences.SP import app.aaps.core.interfaces.utils.DateUtil +import app.aaps.wear.R +import app.aaps.wear.data.RawDisplayData +import app.aaps.wear.events.EventWearPreferenceChange +import app.aaps.wear.heartrate.HeartRateListener +import app.aaps.wear.interaction.menus.MainMenuActivity +import app.aaps.wear.interaction.utils.Persistence +import app.aaps.wear.interaction.utils.WearUtil import com.ustwo.clockwise.common.WatchFaceTime import com.ustwo.clockwise.common.WatchMode import com.ustwo.clockwise.common.WatchShape import com.ustwo.clockwise.wearable.WatchFace import dagger.android.AndroidInjection -import info.nightscout.androidaps.R -import info.nightscout.androidaps.data.RawDisplayData -import info.nightscout.androidaps.events.EventWearPreferenceChange -import info.nightscout.androidaps.heartrate.HeartRateListener -import info.nightscout.androidaps.interaction.menus.MainMenuActivity -import info.nightscout.androidaps.interaction.utils.Persistence -import info.nightscout.androidaps.interaction.utils.WearUtil import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import javax.inject.Inject diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BgGraphBuilder.kt b/wear/src/main/kotlin/app/aaps/wear/watchfaces/utils/BgGraphBuilder.kt similarity index 99% rename from wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BgGraphBuilder.kt rename to wear/src/main/kotlin/app/aaps/wear/watchfaces/utils/BgGraphBuilder.kt index 6e2f27edf3..d33fc56006 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BgGraphBuilder.kt +++ b/wear/src/main/kotlin/app/aaps/wear/watchfaces/utils/BgGraphBuilder.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.watchfaces.utils +package app.aaps.wear.watchfaces.utils import android.graphics.DashPathEffect import app.aaps.core.interfaces.rx.weardata.EventData @@ -6,7 +6,7 @@ import app.aaps.core.interfaces.rx.weardata.EventData.SingleBg import app.aaps.core.interfaces.rx.weardata.EventData.TreatmentData.Basal import app.aaps.core.interfaces.sharedPreferences.SP import app.aaps.core.interfaces.utils.DateUtil -import info.nightscout.androidaps.R +import app.aaps.wear.R import lecho.lib.hellocharts.model.Axis import lecho.lib.hellocharts.model.AxisValue import lecho.lib.hellocharts.model.Line diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/SimpleUi.kt b/wear/src/main/kotlin/app/aaps/wear/watchfaces/utils/SimpleUi.kt similarity index 96% rename from wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/SimpleUi.kt rename to wear/src/main/kotlin/app/aaps/wear/watchfaces/utils/SimpleUi.kt index 5036848c4a..6cd4d5890c 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/SimpleUi.kt +++ b/wear/src/main/kotlin/app/aaps/wear/watchfaces/utils/SimpleUi.kt @@ -1,154 +1,154 @@ -package info.nightscout.androidaps.watchfaces.utils - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.graphics.Canvas -import android.graphics.Paint -import android.graphics.Point -import android.graphics.Typeface -import android.os.BatteryManager -import android.view.WindowManager -import androidx.core.content.ContextCompat -import app.aaps.core.interfaces.rx.weardata.EventData -import app.aaps.core.interfaces.sharedPreferences.SP -import app.aaps.core.interfaces.utils.DateUtil -import com.ustwo.clockwise.common.WatchMode -import com.ustwo.clockwise.wearable.WatchFace -import info.nightscout.androidaps.R -import javax.inject.Inject - -class SimpleUi @Inject constructor( - private val context: Context, - private val sp: SP, - private val dateUtil: DateUtil -) { - - private var batteryReceiver: BroadcastReceiver? = null - private var mBackgroundPaint = Paint() - private lateinit var mTimePaint: Paint - private lateinit var mSvgPaint: Paint - private lateinit var mDirectionPaint: Paint - private var mYOffset = 0f - private val colorDarkHigh = ContextCompat.getColor(context, R.color.dark_highColor) - private var colorDarkMid = ContextCompat.getColor(context, R.color.dark_midColor) - private var colorDarkLow = ContextCompat.getColor(context, R.color.dark_lowColor) - private val displaySize = Point() - private lateinit var callback: () -> Unit - - fun onCreate(callback: () -> Unit) { - this.callback = callback - @Suppress("DEPRECATION") - (context.getSystemService(WatchFace.WINDOW_SERVICE) as WindowManager).defaultDisplay.getSize(displaySize) - setupBatteryReceiver() - setupUi() - } - - fun updatePreferences() { - setupBatteryReceiver() - } - - fun setAntiAlias(currentWatchMode: WatchMode) { - val antiAlias = currentWatchMode == WatchMode.AMBIENT - mSvgPaint.isAntiAlias = antiAlias - mDirectionPaint.isAntiAlias = antiAlias - mTimePaint.isAntiAlias = antiAlias - } - - fun isEnabled(currentWatchMode: WatchMode): Boolean { - val simplify = sp.getString(R.string.key_simplify_ui, "off") - return if (simplify == "off") false - else if ((simplify == "ambient" || simplify == "ambient_charging") && currentWatchMode == WatchMode.AMBIENT) true - else (simplify == "charging" || simplify == "ambient_charging") && isCharging - } - - fun onDraw(canvas: Canvas, singleBg: EventData.SingleBg) { - canvas.drawRect(0f, 0f, displaySize.x.toFloat(), displaySize.y.toFloat(), mBackgroundPaint) - val xHalf = displaySize.x / 2f - val yThird = displaySize.y / 3f - - mSvgPaint.isStrikeThruText = isOutdated(singleBg) - mSvgPaint.color = getBgColour(singleBg.sgvLevel) - mDirectionPaint.color = getBgColour(singleBg.sgvLevel) - val sSvg = singleBg.sgvString - val svgWidth = mSvgPaint.measureText(sSvg) - val sDirection = " " + singleBg.slopeArrow + "\uFE0E" - val directionWidth = mDirectionPaint.measureText(sDirection) - val xSvg = xHalf - (svgWidth + directionWidth) / 2 - canvas.drawText(sSvg, xSvg, yThird + mYOffset, mSvgPaint) - val xDirection = xSvg + svgWidth - canvas.drawText(sDirection, xDirection, yThird + mYOffset, mDirectionPaint) - val sTime = dateUtil.timeString() - val xTime = xHalf - mTimePaint.measureText(sTime) / 2f - canvas.drawText(sTime, xTime, yThird * 2f + mYOffset, mTimePaint) - } - - fun onDestroy() { - if (batteryReceiver != null) { - context.unregisterReceiver(batteryReceiver) - } - } - - private fun isOutdated(singleBg: EventData.SingleBg): Boolean = - singleBg.timeStamp > 0 && (System.currentTimeMillis() - singleBg.timeStamp) > 1000 * 60 * 12 - - private fun getBgColour(level: Long): Int = - when (level) { - 1L -> colorDarkHigh - 0L -> colorDarkMid - else -> colorDarkLow - } - - private val isCharging: Boolean - get() { - val mBatteryStatus = context.registerReceiver(null, iFilter) - val status = mBatteryStatus?.getIntExtra(BatteryManager.EXTRA_STATUS, -1) - return status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL - } - - private fun setupUi() { - val black = ContextCompat.getColor(context, R.color.black) - mBackgroundPaint.color = black - val white = ContextCompat.getColor(context, R.color.white) - val resources = context.resources - val textSizeSvg = resources.getDimension(R.dimen.simple_ui_svg_text_size) - val textSizeDirection = resources.getDimension(R.dimen.simple_ui_direction_text_size) - val textSizeTime = resources.getDimension(R.dimen.simple_ui_time_text_size) - mYOffset = resources.getDimension(R.dimen.simple_ui_y_offset) - mSvgPaint = createTextPaint(NORMAL_TYPEFACE, white, textSizeSvg) - mDirectionPaint = createTextPaint(BOLD_TYPEFACE, white, textSizeDirection) - mTimePaint = createTextPaint(NORMAL_TYPEFACE, white, textSizeTime) - } - - private fun setupBatteryReceiver() { - val setting = sp.getString(R.string.key_simplify_ui, "off") - if ((setting == "charging" || setting == "ambient_charging") && batteryReceiver == null) { - val intentBatteryFilter = IntentFilter() - intentBatteryFilter.addAction(BatteryManager.ACTION_CHARGING) - intentBatteryFilter.addAction(BatteryManager.ACTION_DISCHARGING) - batteryReceiver = object : BroadcastReceiver() { - override fun onReceive(context: Context, intent: Intent) { - callback() - } - } - context.registerReceiver(batteryReceiver, intentBatteryFilter) - } - } - - private fun createTextPaint(typeface: Typeface, colour: Int, textSize: Float): Paint { - val paint = Paint() - paint.color = colour - paint.typeface = typeface - paint.isAntiAlias = true - paint.textSize = textSize - return paint - } - - companion object { - - var iFilter = IntentFilter(Intent.ACTION_BATTERY_CHANGED) - val NORMAL_TYPEFACE: Typeface = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL) - val BOLD_TYPEFACE: Typeface = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD) - } -} +package app.aaps.wear.watchfaces.utils + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.content.IntentFilter +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.Point +import android.graphics.Typeface +import android.os.BatteryManager +import android.view.WindowManager +import androidx.core.content.ContextCompat +import app.aaps.core.interfaces.rx.weardata.EventData +import app.aaps.core.interfaces.sharedPreferences.SP +import app.aaps.core.interfaces.utils.DateUtil +import app.aaps.wear.R +import com.ustwo.clockwise.common.WatchMode +import com.ustwo.clockwise.wearable.WatchFace +import javax.inject.Inject + +class SimpleUi @Inject constructor( + private val context: Context, + private val sp: SP, + private val dateUtil: DateUtil +) { + + private var batteryReceiver: BroadcastReceiver? = null + private var mBackgroundPaint = Paint() + private lateinit var mTimePaint: Paint + private lateinit var mSvgPaint: Paint + private lateinit var mDirectionPaint: Paint + private var mYOffset = 0f + private val colorDarkHigh = ContextCompat.getColor(context, R.color.dark_highColor) + private var colorDarkMid = ContextCompat.getColor(context, R.color.dark_midColor) + private var colorDarkLow = ContextCompat.getColor(context, R.color.dark_lowColor) + private val displaySize = Point() + private lateinit var callback: () -> Unit + + fun onCreate(callback: () -> Unit) { + this.callback = callback + @Suppress("DEPRECATION") + (context.getSystemService(WatchFace.WINDOW_SERVICE) as WindowManager).defaultDisplay.getSize(displaySize) + setupBatteryReceiver() + setupUi() + } + + fun updatePreferences() { + setupBatteryReceiver() + } + + fun setAntiAlias(currentWatchMode: WatchMode) { + val antiAlias = currentWatchMode == WatchMode.AMBIENT + mSvgPaint.isAntiAlias = antiAlias + mDirectionPaint.isAntiAlias = antiAlias + mTimePaint.isAntiAlias = antiAlias + } + + fun isEnabled(currentWatchMode: WatchMode): Boolean { + val simplify = sp.getString(R.string.key_simplify_ui, "off") + return if (simplify == "off") false + else if ((simplify == "ambient" || simplify == "ambient_charging") && currentWatchMode == WatchMode.AMBIENT) true + else (simplify == "charging" || simplify == "ambient_charging") && isCharging + } + + fun onDraw(canvas: Canvas, singleBg: EventData.SingleBg) { + canvas.drawRect(0f, 0f, displaySize.x.toFloat(), displaySize.y.toFloat(), mBackgroundPaint) + val xHalf = displaySize.x / 2f + val yThird = displaySize.y / 3f + + mSvgPaint.isStrikeThruText = isOutdated(singleBg) + mSvgPaint.color = getBgColour(singleBg.sgvLevel) + mDirectionPaint.color = getBgColour(singleBg.sgvLevel) + val sSvg = singleBg.sgvString + val svgWidth = mSvgPaint.measureText(sSvg) + val sDirection = " " + singleBg.slopeArrow + "\uFE0E" + val directionWidth = mDirectionPaint.measureText(sDirection) + val xSvg = xHalf - (svgWidth + directionWidth) / 2 + canvas.drawText(sSvg, xSvg, yThird + mYOffset, mSvgPaint) + val xDirection = xSvg + svgWidth + canvas.drawText(sDirection, xDirection, yThird + mYOffset, mDirectionPaint) + val sTime = dateUtil.timeString() + val xTime = xHalf - mTimePaint.measureText(sTime) / 2f + canvas.drawText(sTime, xTime, yThird * 2f + mYOffset, mTimePaint) + } + + fun onDestroy() { + if (batteryReceiver != null) { + context.unregisterReceiver(batteryReceiver) + } + } + + private fun isOutdated(singleBg: EventData.SingleBg): Boolean = + singleBg.timeStamp > 0 && (System.currentTimeMillis() - singleBg.timeStamp) > 1000 * 60 * 12 + + private fun getBgColour(level: Long): Int = + when (level) { + 1L -> colorDarkHigh + 0L -> colorDarkMid + else -> colorDarkLow + } + + private val isCharging: Boolean + get() { + val mBatteryStatus = context.registerReceiver(null, iFilter) + val status = mBatteryStatus?.getIntExtra(BatteryManager.EXTRA_STATUS, -1) + return status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL + } + + private fun setupUi() { + val black = ContextCompat.getColor(context, R.color.black) + mBackgroundPaint.color = black + val white = ContextCompat.getColor(context, R.color.white) + val resources = context.resources + val textSizeSvg = resources.getDimension(R.dimen.simple_ui_svg_text_size) + val textSizeDirection = resources.getDimension(R.dimen.simple_ui_direction_text_size) + val textSizeTime = resources.getDimension(R.dimen.simple_ui_time_text_size) + mYOffset = resources.getDimension(R.dimen.simple_ui_y_offset) + mSvgPaint = createTextPaint(NORMAL_TYPEFACE, white, textSizeSvg) + mDirectionPaint = createTextPaint(BOLD_TYPEFACE, white, textSizeDirection) + mTimePaint = createTextPaint(NORMAL_TYPEFACE, white, textSizeTime) + } + + private fun setupBatteryReceiver() { + val setting = sp.getString(R.string.key_simplify_ui, "off") + if ((setting == "charging" || setting == "ambient_charging") && batteryReceiver == null) { + val intentBatteryFilter = IntentFilter() + intentBatteryFilter.addAction(BatteryManager.ACTION_CHARGING) + intentBatteryFilter.addAction(BatteryManager.ACTION_DISCHARGING) + batteryReceiver = object : BroadcastReceiver() { + override fun onReceive(context: Context, intent: Intent) { + callback() + } + } + context.registerReceiver(batteryReceiver, intentBatteryFilter) + } + } + + private fun createTextPaint(typeface: Typeface, colour: Int, textSize: Float): Paint { + val paint = Paint() + paint.color = colour + paint.typeface = typeface + paint.isAntiAlias = true + paint.textSize = textSize + return paint + } + + companion object { + + var iFilter = IntentFilter(Intent.ACTION_BATTERY_CHANGED) + val NORMAL_TYPEFACE: Typeface = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL) + val BOLD_TYPEFACE: Typeface = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD) + } +} diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/WatchfaceViewAdapter.kt b/wear/src/main/kotlin/app/aaps/wear/watchfaces/utils/WatchfaceViewAdapter.kt similarity index 70% rename from wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/WatchfaceViewAdapter.kt rename to wear/src/main/kotlin/app/aaps/wear/watchfaces/utils/WatchfaceViewAdapter.kt index 9ccd931586..88e365096b 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/WatchfaceViewAdapter.kt +++ b/wear/src/main/kotlin/app/aaps/wear/watchfaces/utils/WatchfaceViewAdapter.kt @@ -1,104 +1,105 @@ -package info.nightscout.androidaps.watchfaces.utils - -import androidx.viewbinding.ViewBinding -import info.nightscout.androidaps.databinding.ActivityHomeLargeBinding -import info.nightscout.androidaps.databinding.ActivityHome2Binding -import info.nightscout.androidaps.databinding.ActivityHomeBinding -import info.nightscout.androidaps.databinding.ActivityBigchartBinding -import info.nightscout.androidaps.databinding.ActivityCockpitBinding -import info.nightscout.androidaps.databinding.ActivityCustomBinding -import info.nightscout.androidaps.databinding.ActivityDigitalstyleBinding -import info.nightscout.androidaps.databinding.ActivityNochartBinding -import info.nightscout.androidaps.databinding.ActivitySteampunkBinding - -/** - * WatchfaceViewAdapter binds all WatchFace variants shared attributes to one common view adapter. - * Requires at least one of the ViewBinding as a parameter. Recommended to use the factory object to create the binding. - */ -class WatchfaceViewAdapter( - aL: ActivityHomeLargeBinding? = null, - a2: ActivityHome2Binding? = null, - aa: ActivityHomeBinding? = null, - bC: ActivityBigchartBinding? = null, - cp: ActivityCockpitBinding? = null, - ds: ActivityDigitalstyleBinding? = null, - nC: ActivityNochartBinding? = null, - sP: ActivitySteampunkBinding? = null, - cU: ActivityCustomBinding? = null -) { - - init { - if (aL == null && a2 == null && aa == null && bC == null && cp == null && ds == null && nC == null && sP == null && cU == null) { - throw IllegalArgumentException("Require at least on Binding parameter") - } - } - - private val errorMessage = "Missing require View Binding parameter" - // Required attributes - val mainLayout = - aL?.mainLayout ?: a2?.mainLayout ?: aa?.mainLayout ?: bC?.mainLayout ?: bC?.mainLayout ?: cp?.mainLayout ?: ds?.mainLayout ?: nC?.mainLayout ?: sP?.mainLayout ?: cU?.mainLayout - ?: throw IllegalArgumentException(errorMessage) - val timestamp = - aL?.timestamp ?: a2?.timestamp ?: aa?.timestamp ?: bC?.timestamp ?: bC?.timestamp ?: cp?.timestamp ?: ds?.timestamp ?: nC?.timestamp ?: sP?.timestamp ?: cU?.timestamp - ?: throw IllegalArgumentException(errorMessage) - val root = - aL?.root ?: a2?.root ?: aa?.root ?: bC?.root ?: bC?.root ?: cp?.root ?: ds?.root ?: nC?.root ?: sP?.root ?: cU?.root - ?: throw IllegalArgumentException(errorMessage) - - // Optional attributes - val sgv = aL?.sgv ?: a2?.sgv ?: aa?.sgv ?: bC?.sgv ?: bC?.sgv ?: cp?.sgv ?: ds?.sgv ?: nC?.sgv ?: cU?.sgv - val direction = aL?.direction ?: a2?.direction ?: aa?.direction ?: cp?.direction ?: ds?.direction - val loop = a2?.loop ?: cp?.loop ?: sP?.loop ?: cU?.loop - val delta = aL?.delta ?: a2?.delta ?: aa?.delta ?: bC?.delta ?: bC?.delta ?: cp?.delta ?: ds?.delta ?: nC?.delta ?: cU?.delta - val avgDelta = a2?.avgDelta ?: bC?.avgDelta ?: bC?.avgDelta ?: cp?.avgDelta ?: ds?.avgDelta ?: nC?.avgDelta ?: cU?.avgDelta - val uploaderBattery = aL?.uploaderBattery ?: a2?.uploaderBattery ?: aa?.uploaderBattery ?: cp?.uploaderBattery ?: ds?.uploaderBattery ?: sP?.uploaderBattery ?: cU?.uploaderBattery - val rigBattery = a2?.rigBattery ?: cp?.rigBattery ?: ds?.rigBattery ?: sP?.rigBattery ?: cU?.rigBattery - val basalRate = a2?.basalRate ?: cp?.basalRate ?: ds?.basalRate ?: sP?.basalRate ?: cU?.basalRate - val bgi = a2?.bgi ?: ds?.bgi ?: cU?.bgi - val AAPSv2 = a2?.AAPSv2 ?: cp?.AAPSv2 ?: ds?.AAPSv2 ?: sP?.AAPSv2 ?: cU?.AAPSv2 - val cob1 = a2?.cob1 ?: ds?.cob1 ?: cU?.cob1 - val cob2 = a2?.cob2 ?: cp?.cob2 ?: ds?.cob2 ?: sP?.cob2 ?: cU?.cob2 - val time = aL?.time ?: a2?.time ?: aa?.time ?: bC?.time ?: bC?.time ?: cp?.time ?: nC?.time ?: cU?.time - val second = cU?.second - val minute = ds?.minute ?: cU?.minute - val hour = ds?.hour ?: cU?.hour - val day = a2?.day ?: ds?.day ?: cU?.day - val month = a2?.month ?: ds?.month ?: cU?.month - val iob1 = a2?.iob1 ?: ds?.iob1 ?: cU?.iob1 - val iob2 = a2?.iob2 ?: cp?.iob2 ?: ds?.iob2 ?: sP?.iob2 ?: cU?.iob2 - val chart = a2?.chart ?: aa?.chart ?: bC?.chart ?: bC?.chart ?: ds?.chart ?: sP?.chart ?: cU?.chart - val status = aL?.status ?: aa?.status ?: bC?.status ?: bC?.status ?: nC?.status - val timePeriod = ds?.timePeriod ?: aL?.timePeriod ?: nC?.timePeriod ?: bC?.timePeriod ?: cU?.timePeriod - val dayName = ds?.dayName ?: cU?.dayName - val mainMenuTap = ds?.mainMenuTap ?: sP?.mainMenuTap - val chartZoomTap = ds?.chartZoomTap ?: sP?.chartZoomTap - val dateTime = ds?.dateTime ?: a2?.dateTime - val weekNumber = ds?.weekNumber ?: cU?.weekNumber - // val minuteHand = sP?.minuteHand - // val secondaryLayout = aL?.secondaryLayout ?: a2?.secondaryLayout ?: aa?.secondaryLayout ?: ds?.secondaryLayout ?: sP?.secondaryLayout - // val tertiaryLayout = a2?.tertiaryLayout ?: sP?.tertiaryLayout - // val highLight = cp?.highLight - // val lowLight = cp?.lowLight - // val deltaGauge = sP?.deltaPointer - // val hourHand = sP?.hourHand - // val glucoseDial = sP?.glucoseDial - - companion object { - - fun getBinding(bindLayout: ViewBinding): WatchfaceViewAdapter { - return when (bindLayout) { - is ActivityHomeLargeBinding -> WatchfaceViewAdapter(bindLayout) - is ActivityHome2Binding -> WatchfaceViewAdapter(null, bindLayout) - is ActivityHomeBinding -> WatchfaceViewAdapter(null, null, bindLayout) - is ActivityBigchartBinding -> WatchfaceViewAdapter(null, null, null, bindLayout) - is ActivityCockpitBinding -> WatchfaceViewAdapter(null, null, null, null, bindLayout) - is ActivityDigitalstyleBinding -> WatchfaceViewAdapter(null, null, null, null, null, bindLayout) - is ActivityNochartBinding -> WatchfaceViewAdapter(null, null, null, null, null, null, bindLayout) - is ActivitySteampunkBinding -> WatchfaceViewAdapter(null, null, null, null, null, null, null, bindLayout) - is ActivityCustomBinding -> WatchfaceViewAdapter(null, null, null, null, null, null, null, null, bindLayout) - else -> throw IllegalArgumentException("ViewBinding is not implement in WatchfaceViewAdapter") - } - } - } - -} +package app.aaps.wear.watchfaces.utils + +import androidx.viewbinding.ViewBinding +import app.aaps.wear.databinding.ActivityBigchartBinding +import app.aaps.wear.databinding.ActivityCockpitBinding +import app.aaps.wear.databinding.ActivityCustomBinding +import app.aaps.wear.databinding.ActivityDigitalstyleBinding +import app.aaps.wear.databinding.ActivityHome2Binding +import app.aaps.wear.databinding.ActivityHomeBinding +import app.aaps.wear.databinding.ActivityHomeLargeBinding +import app.aaps.wear.databinding.ActivityNochartBinding +import app.aaps.wear.databinding.ActivitySteampunkBinding + +/** + * WatchfaceViewAdapter binds all WatchFace variants shared attributes to one common view adapter. + * Requires at least one of the ViewBinding as a parameter. Recommended to use the factory object to create the binding. + */ +class WatchfaceViewAdapter( + aL: ActivityHomeLargeBinding? = null, + a2: ActivityHome2Binding? = null, + aa: ActivityHomeBinding? = null, + bC: ActivityBigchartBinding? = null, + cp: ActivityCockpitBinding? = null, + ds: ActivityDigitalstyleBinding? = null, + nC: ActivityNochartBinding? = null, + sP: ActivitySteampunkBinding? = null, + cU: ActivityCustomBinding? = null +) { + + init { + if (aL == null && a2 == null && aa == null && bC == null && cp == null && ds == null && nC == null && sP == null && cU == null) { + throw IllegalArgumentException("Require at least on Binding parameter") + } + } + + private val errorMessage = "Missing require View Binding parameter" + + // Required attributes + val mainLayout = + aL?.mainLayout ?: a2?.mainLayout ?: aa?.mainLayout ?: bC?.mainLayout ?: bC?.mainLayout ?: cp?.mainLayout ?: ds?.mainLayout ?: nC?.mainLayout ?: sP?.mainLayout ?: cU?.mainLayout + ?: throw IllegalArgumentException(errorMessage) + val timestamp = + aL?.timestamp ?: a2?.timestamp ?: aa?.timestamp ?: bC?.timestamp ?: bC?.timestamp ?: cp?.timestamp ?: ds?.timestamp ?: nC?.timestamp ?: sP?.timestamp ?: cU?.timestamp + ?: throw IllegalArgumentException(errorMessage) + val root = + aL?.root ?: a2?.root ?: aa?.root ?: bC?.root ?: bC?.root ?: cp?.root ?: ds?.root ?: nC?.root ?: sP?.root ?: cU?.root + ?: throw IllegalArgumentException(errorMessage) + + // Optional attributes + val sgv = aL?.sgv ?: a2?.sgv ?: aa?.sgv ?: bC?.sgv ?: bC?.sgv ?: cp?.sgv ?: ds?.sgv ?: nC?.sgv ?: cU?.sgv + val direction = aL?.direction ?: a2?.direction ?: aa?.direction ?: cp?.direction ?: ds?.direction + val loop = a2?.loop ?: cp?.loop ?: sP?.loop ?: cU?.loop + val delta = aL?.delta ?: a2?.delta ?: aa?.delta ?: bC?.delta ?: bC?.delta ?: cp?.delta ?: ds?.delta ?: nC?.delta ?: cU?.delta + val avgDelta = a2?.avgDelta ?: bC?.avgDelta ?: bC?.avgDelta ?: cp?.avgDelta ?: ds?.avgDelta ?: nC?.avgDelta ?: cU?.avgDelta + val uploaderBattery = aL?.uploaderBattery ?: a2?.uploaderBattery ?: aa?.uploaderBattery ?: cp?.uploaderBattery ?: ds?.uploaderBattery ?: sP?.uploaderBattery ?: cU?.uploaderBattery + val rigBattery = a2?.rigBattery ?: cp?.rigBattery ?: ds?.rigBattery ?: sP?.rigBattery ?: cU?.rigBattery + val basalRate = a2?.basalRate ?: cp?.basalRate ?: ds?.basalRate ?: sP?.basalRate ?: cU?.basalRate + val bgi = a2?.bgi ?: ds?.bgi ?: cU?.bgi + val AAPSv2 = a2?.AAPSv2 ?: cp?.AAPSv2 ?: ds?.AAPSv2 ?: sP?.AAPSv2 ?: cU?.AAPSv2 + val cob1 = a2?.cob1 ?: ds?.cob1 ?: cU?.cob1 + val cob2 = a2?.cob2 ?: cp?.cob2 ?: ds?.cob2 ?: sP?.cob2 ?: cU?.cob2 + val time = aL?.time ?: a2?.time ?: aa?.time ?: bC?.time ?: bC?.time ?: cp?.time ?: nC?.time ?: cU?.time + val second = cU?.second + val minute = ds?.minute ?: cU?.minute + val hour = ds?.hour ?: cU?.hour + val day = a2?.day ?: ds?.day ?: cU?.day + val month = a2?.month ?: ds?.month ?: cU?.month + val iob1 = a2?.iob1 ?: ds?.iob1 ?: cU?.iob1 + val iob2 = a2?.iob2 ?: cp?.iob2 ?: ds?.iob2 ?: sP?.iob2 ?: cU?.iob2 + val chart = a2?.chart ?: aa?.chart ?: bC?.chart ?: bC?.chart ?: ds?.chart ?: sP?.chart ?: cU?.chart + val status = aL?.status ?: aa?.status ?: bC?.status ?: bC?.status ?: nC?.status + val timePeriod = ds?.timePeriod ?: aL?.timePeriod ?: nC?.timePeriod ?: bC?.timePeriod ?: cU?.timePeriod + val dayName = ds?.dayName ?: cU?.dayName + val mainMenuTap = ds?.mainMenuTap ?: sP?.mainMenuTap + val chartZoomTap = ds?.chartZoomTap ?: sP?.chartZoomTap + val dateTime = ds?.dateTime ?: a2?.dateTime + val weekNumber = ds?.weekNumber ?: cU?.weekNumber + // val minuteHand = sP?.minuteHand + // val secondaryLayout = aL?.secondaryLayout ?: a2?.secondaryLayout ?: aa?.secondaryLayout ?: ds?.secondaryLayout ?: sP?.secondaryLayout + // val tertiaryLayout = a2?.tertiaryLayout ?: sP?.tertiaryLayout + // val highLight = cp?.highLight + // val lowLight = cp?.lowLight + // val deltaGauge = sP?.deltaPointer + // val hourHand = sP?.hourHand + // val glucoseDial = sP?.glucoseDial + + companion object { + + fun getBinding(bindLayout: ViewBinding): WatchfaceViewAdapter { + return when (bindLayout) { + is ActivityHomeLargeBinding -> WatchfaceViewAdapter(bindLayout) + is ActivityHome2Binding -> WatchfaceViewAdapter(null, bindLayout) + is ActivityHomeBinding -> WatchfaceViewAdapter(null, null, bindLayout) + is ActivityBigchartBinding -> WatchfaceViewAdapter(null, null, null, bindLayout) + is ActivityCockpitBinding -> WatchfaceViewAdapter(null, null, null, null, bindLayout) + is ActivityDigitalstyleBinding -> WatchfaceViewAdapter(null, null, null, null, null, bindLayout) + is ActivityNochartBinding -> WatchfaceViewAdapter(null, null, null, null, null, null, bindLayout) + is ActivitySteampunkBinding -> WatchfaceViewAdapter(null, null, null, null, null, null, null, bindLayout) + is ActivityCustomBinding -> WatchfaceViewAdapter(null, null, null, null, null, null, null, null, bindLayout) + else -> throw IllegalArgumentException("ViewBinding is not implement in WatchfaceViewAdapter") + } + } + } + +} diff --git a/wear/src/main/res/layout/activity_custom.xml b/wear/src/main/res/layout/activity_custom.xml index 95c231dbcb..edc2efd1d0 100644 --- a/wear/src/main/res/layout/activity_custom.xml +++ b/wear/src/main/res/layout/activity_custom.xml @@ -1,6 +1,5 @@ + android:visibility="visible" /> + android:layout_marginTop="0px" + android:orientation="vertical" + android:visibility="gone" /> + android:textColor="@color/light_grey" + android:textSize="21px" + android:visibility="gone" /> + android:textColor="@color/light_grey" + android:textSize="21px" + android:visibility="gone" /> + android:textColor="@color/light_grey" + android:textSize="21px" + android:visibility="gone" /> + android:textColor="@color/light_grey" + android:textSize="21px" + android:visibility="gone" /> @@ -153,26 +152,26 @@ android:id="@+id/uploader_battery" android:layout_width="60px" android:layout_height="32px" - android:gravity="center" - android:layout_marginTop="133px" android:layout_marginLeft="129px" - android:textSize="23px" + android:layout_marginTop="133px" android:fontFamily="@font/roboto_condensed_bold" - android:textStyle="bold" + android:gravity="center" android:textColor="@color/light_grey" + android:textSize="23px" + android:textStyle="bold" tools:text="100%" /> @@ -180,25 +179,25 @@ android:id="@+id/basalRate" android:layout_width="91px" android:layout_height="32px" - android:layout_marginTop="133px" android:layout_marginLeft="249px" - android:gravity="center" + android:layout_marginTop="133px" android:fontFamily="@font/roboto_condensed_bold" + android:gravity="center" + android:textColor="@color/light_grey" android:textSize="23px" android:textStyle="bold" - android:textColor="@color/light_grey" tools:text="@string/no_tmp_basal_u_h" /> @@ -208,11 +207,11 @@ android:layout_width="0px" android:layout_height="0px" android:layout_marginTop="151px" - android:gravity="center" android:fontFamily="@font/roboto_condensed_bold" + android:gravity="center" + android:textColor="@color/light_grey" android:textSize="70px" android:textStyle="bold" - android:textColor="@color/light_grey" android:visibility="gone" tools:text="22:00" /> @@ -221,13 +220,13 @@ android:id="@+id/hour" android:layout_width="0px" android:layout_height="0px" - android:layout_marginTop="151px" android:layout_marginLeft="119px" + android:layout_marginTop="151px" android:fontFamily="@font/roboto_condensed_bold" android:textAllCaps="true" + android:textColor="@color/light_grey" android:textSize="70px" android:textStyle="bold" - android:textColor="@color/light_grey" android:visibility="gone" tools:text="20" /> @@ -235,8 +234,8 @@ android:id="@+id/minute" android:layout_width="0px" android:layout_height="0px" - android:layout_marginTop="158px" android:layout_marginLeft="210px" + android:layout_marginTop="158px" android:fontFamily="@font/roboto_condensed_bold" android:textColor="@color/light_grey" android:textSize="46px" @@ -247,8 +246,8 @@ android:id="@+id/second" android:layout_width="0px" android:layout_height="0px" - android:layout_marginTop="158px" android:layout_marginLeft="210px" + android:layout_marginTop="158px" android:fontFamily="@font/roboto_condensed_bold" android:textColor="@color/light_grey" android:textSize="46px" @@ -265,9 +264,9 @@ android:layout_marginLeft="210px" android:layout_marginTop="205px" android:fontFamily="@font/roboto_condensed_bold" + android:textColor="@color/light_grey" android:textSize="17px" android:textStyle="bold" - android:textColor="@color/light_grey" android:visibility="gone" tools:text="AM" /> @@ -275,12 +274,12 @@ android:id="@+id/day_name" android:layout_width="56px" android:layout_height="36px" - android:layout_marginTop="172px" android:layout_marginLeft="120px" + android:layout_marginTop="172px" android:gravity="center" + android:textColor="@color/white" android:textSize="24px" android:textStyle="bold" - android:textColor="@color/white" android:visibility="visible" tools:text="day" /> @@ -288,24 +287,24 @@ android:id="@+id/day" android:layout_width="56px" android:layout_height="36px" - android:layout_marginTop="198px" android:layout_marginLeft="120px" + android:layout_marginTop="198px" android:gravity="center" - android:textStyle="bold" - android:textSize="24px" android:textColor="@color/white" + android:textSize="24px" + android:textStyle="bold" tools:text="01" /> @@ -313,60 +312,60 @@ android:id="@+id/month" android:layout_width="50px" android:layout_height="36px" - android:layout_marginTop="180px" android:layout_marginLeft="220px" + android:layout_marginTop="180px" android:gravity="center" - android:textStyle="bold" - android:textSize="24px" android:textColor="@color/white" + android:textSize="24px" + android:textStyle="bold" tools:text="févr." /> + android:visibility="visible" /> + android:src="@drawable/simplified_dial" + android:visibility="visible" /> - -