From 072324d1069ed8baa9286e4acc4c718c9155b803 Mon Sep 17 00:00:00 2001 From: Andries Smit Date: Tue, 21 Jun 2022 20:05:53 +0200 Subject: [PATCH] fear: wear mute alarm --- .../wear/wearintegration/DataHandlerMobile.kt | 11 +++- .../nightscout/shared/weardata/EventData.kt | 5 +- wear/src/main/AndroidManifest.xml | 12 ++++ .../androidaps/di/WearActivitiesModule.kt | 4 +- .../actions/QuickSnoozeActivity.kt | 52 ++++++++++++++++++ wear/src/main/res/drawable/ic_icon_snooze.png | Bin 0 -> 3919 bytes wear/src/main/res/values/strings.xml | 3 + 7 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 wear/src/main/java/info/nightscout/androidaps/interaction/actions/QuickSnoozeActivity.kt create mode 100644 wear/src/main/res/drawable/ic_icon_snooze.png diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/DataHandlerMobile.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/DataHandlerMobile.kt index cb21aeb5ba..a0ccacf982 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/DataHandlerMobile.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/DataHandlerMobile.kt @@ -27,6 +27,7 @@ import info.nightscout.androidaps.plugins.general.overview.graphExtensions.Gluco import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.receivers.ReceiverStatusStore +import info.nightscout.androidaps.services.AlarmSoundServiceHelper import info.nightscout.androidaps.utils.* import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.wizard.BolusWizard @@ -73,7 +74,8 @@ class DataHandlerMobile @Inject constructor( private val uel: UserEntryLogger, private val activePlugin: ActivePlugin, private val commandQueue: CommandQueue, - private val fabricPrivacy: FabricPrivacy + private val fabricPrivacy: FabricPrivacy, + private val alarmSoundServiceHelper: AlarmSoundServiceHelper ) { private val disposable = CompositeDisposable() @@ -260,6 +262,13 @@ class DataHandlerMobile @Inject constructor( } lastBolusWizard = null }, fabricPrivacy::logException) + disposable += rxBus + .toObservable(EventData.SnoozeAlert::class.java) + .observeOn(aapsSchedulers.io) + .subscribe({ + aapsLogger.debug(LTag.WEAR, "SnoozeAlert received $it from ${it.sourceNodeId}") + alarmSoundServiceHelper.stopService(context, "Muted from wear") + }, fabricPrivacy::logException) } private fun handleTddStatus() { diff --git a/shared/src/main/java/info/nightscout/shared/weardata/EventData.kt b/shared/src/main/java/info/nightscout/shared/weardata/EventData.kt index f570743aa6..aca2303c89 100644 --- a/shared/src/main/java/info/nightscout/shared/weardata/EventData.kt +++ b/shared/src/main/java/info/nightscout/shared/weardata/EventData.kt @@ -234,4 +234,7 @@ sealed class EventData : Event() { @Serializable // returnCommand is sent back to Mobile after confirmation data class ConfirmAction(val title: String, val message: String, val returnCommand: EventData?) : EventData() -} \ No newline at end of file + + @Serializable + data class SnoozeAlert(val timeStamp: Long) : EventData() +} diff --git a/wear/src/main/AndroidManifest.xml b/wear/src/main/AndroidManifest.xml index 88b52fc779..3d10810e37 100644 --- a/wear/src/main/AndroidManifest.xml +++ b/wear/src/main/AndroidManifest.xml @@ -629,5 +629,17 @@ + + + + + + + + diff --git a/wear/src/main/java/info/nightscout/androidaps/di/WearActivitiesModule.kt b/wear/src/main/java/info/nightscout/androidaps/di/WearActivitiesModule.kt index 18a63adb66..7055b32be0 100644 --- a/wear/src/main/java/info/nightscout/androidaps/di/WearActivitiesModule.kt +++ b/wear/src/main/java/info/nightscout/androidaps/di/WearActivitiesModule.kt @@ -2,6 +2,7 @@ package info.nightscout.androidaps.di 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.* @@ -34,4 +35,5 @@ abstract class WearActivitiesModule { @ContributesAndroidInjector abstract fun contributesFillMenuActivity(): FillMenuActivity @ContributesAndroidInjector abstract fun contributesMainMenuActivity(): MainMenuActivity @ContributesAndroidInjector abstract fun contributesStatusMenuActivity(): StatusMenuActivity -} \ No newline at end of file + @ContributesAndroidInjector abstract fun contributesQuickSnoozeActivity(): QuickSnoozeActivity +} diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/QuickSnoozeActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/QuickSnoozeActivity.kt new file mode 100644 index 0000000000..bb36a43221 --- /dev/null +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/QuickSnoozeActivity.kt @@ -0,0 +1,52 @@ +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 dagger.android.DaggerActivity +import info.nightscout.androidaps.R +import info.nightscout.androidaps.events.EventWearToMobile +import info.nightscout.androidaps.plugins.bus.RxBus +import info.nightscout.shared.weardata.EventData +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() + } + + private fun isPackageExisted(targetPackage: String?): Boolean { + try { + packageManager.getPackageInfo(targetPackage!!, PackageManager.GET_META_DATA) + } catch (e: PackageManager.NameNotFoundException) { + return false + } + return true + } +} diff --git a/wear/src/main/res/drawable/ic_icon_snooze.png b/wear/src/main/res/drawable/ic_icon_snooze.png new file mode 100644 index 0000000000000000000000000000000000000000..78334d1d78c13cfac185deba07b8280d1bcbf33a GIT binary patch literal 3919 zcmV-V53ulwP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vG&=l}pD=mCOb1snhX4&+HhK~!i%)meFT zl-1e)&6=6XOor^4EQBQ_!4O0ODewUz{f-LmfF9gxMf|YksI=9CRxMDM7WJ!WD~bh0 zzxvq)DA-~FWf6r?b_hWdAPJBSvQB1S-#*Ws?VW4__MiUFxhL;??=$y(p8M=K3WdoFo!tiy}5-2q&52VnOF#kx_WM5a!K;YlitPS#>_W&);V zCBURni1qJ+s}>+gzuMC1#+uU(e0ISFcR+$hDWQm%EHJ8&rBfnN9b(Yom(b!4;*33j zY7&m+(y5e~k*ml2!bIGhql5A)Ww~Mjn0UiE7nU5cqN>w}v;+la=V@_EwiXl8)G&mZ z?hj59^q*~h{JqhO4Hvv<^#oBuT3L3T8ME^BxKcT;NPsilek`cy#EvF63X_z0s#uRX zgA<@7PpYHS-Eq-}1MPm)*aB#B1))&-#qXq`8rga!3Qa1EPgUcFObv#Smb|2ib>}^J z{geweq?zd!9ac?BK|zvQ{O)pa*#dlA>%?PwJIL!LEE#3MBLzA#1qq+jd+o zLOXI8wE-v;5^SD$hWM1nB&+f8ums#YB!Ns%fi-8`Sa!k*5*zPMOve4g6GOz`f^QXo z7oR(9#jlQaV`7>LYbKbGOQ-pl1_z!$>P0i1bbshi068qQ*Gt!Gad%!K8fdRa_SsND zCicu|6J9Ax{#KJ3Pyk-|F`3M}r|fuWs1_^AjKVbjXTKe1-FCFt5<-Oi;Bo|DSWF%a z(;4wzxlx$fqC<9kSm(ilLIYM#N+k#HUyK3sz|RkL3FaR!Ou+BP8|h?xnDTiS_O$xK z6fv;xPR-EZ=OqTLn{2}GiJ4qOY`uqLyZ&9?r+0D zM$)ea{&3cT2X}XfljjXLQ`GoDg-tjfBa2Rr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