This commit is contained in:
Milos Kozak 2022-06-28 11:51:40 +02:00
commit c9dda14c06
7 changed files with 84 additions and 3 deletions

View file

@ -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.plugins.iob.iobCobCalculator.GlucoseStatusProvider
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.receivers.ReceiverStatusStore import info.nightscout.androidaps.receivers.ReceiverStatusStore
import info.nightscout.androidaps.services.AlarmSoundServiceHelper
import info.nightscout.androidaps.utils.* import info.nightscout.androidaps.utils.*
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.wizard.BolusWizard import info.nightscout.androidaps.utils.wizard.BolusWizard
@ -73,7 +74,8 @@ class DataHandlerMobile @Inject constructor(
private val uel: UserEntryLogger, private val uel: UserEntryLogger,
private val activePlugin: ActivePlugin, private val activePlugin: ActivePlugin,
private val commandQueue: CommandQueue, private val commandQueue: CommandQueue,
private val fabricPrivacy: FabricPrivacy private val fabricPrivacy: FabricPrivacy,
private val alarmSoundServiceHelper: AlarmSoundServiceHelper
) { ) {
private val disposable = CompositeDisposable() private val disposable = CompositeDisposable()
@ -260,6 +262,13 @@ class DataHandlerMobile @Inject constructor(
} }
lastBolusWizard = null lastBolusWizard = null
}, fabricPrivacy::logException) }, 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() { private fun handleTddStatus() {

View file

@ -234,4 +234,7 @@ sealed class EventData : Event() {
@Serializable // returnCommand is sent back to Mobile after confirmation @Serializable // returnCommand is sent back to Mobile after confirmation
data class ConfirmAction(val title: String, val message: String, val returnCommand: EventData?) : EventData() data class ConfirmAction(val title: String, val message: String, val returnCommand: EventData?) : EventData()
@Serializable
data class SnoozeAlert(val timeStamp: Long) : EventData()
} }

View file

@ -629,5 +629,17 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".interaction.actions.QuickSnoozeActivity"
android:icon="@drawable/ic_icon_snooze"
android:label="@string/snooze_alert"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application> </application>
</manifest> </manifest>

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.di
import dagger.Module import dagger.Module
import dagger.android.ContributesAndroidInjector import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.interaction.actions.QuickSnoozeActivity
import info.nightscout.androidaps.interaction.ConfigurationActivity import info.nightscout.androidaps.interaction.ConfigurationActivity
import info.nightscout.androidaps.interaction.TileConfigurationActivity import info.nightscout.androidaps.interaction.TileConfigurationActivity
import info.nightscout.androidaps.interaction.actions.* import info.nightscout.androidaps.interaction.actions.*
@ -34,4 +35,5 @@ abstract class WearActivitiesModule {
@ContributesAndroidInjector abstract fun contributesFillMenuActivity(): FillMenuActivity @ContributesAndroidInjector abstract fun contributesFillMenuActivity(): FillMenuActivity
@ContributesAndroidInjector abstract fun contributesMainMenuActivity(): MainMenuActivity @ContributesAndroidInjector abstract fun contributesMainMenuActivity(): MainMenuActivity
@ContributesAndroidInjector abstract fun contributesStatusMenuActivity(): StatusMenuActivity @ContributesAndroidInjector abstract fun contributesStatusMenuActivity(): StatusMenuActivity
@ContributesAndroidInjector abstract fun contributesQuickSnoozeActivity(): QuickSnoozeActivity
} }

View file

@ -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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View file

@ -222,4 +222,7 @@
<string name="cob_000g">000g</string> <string name="cob_000g">000g</string>
<string name="svg_00_0" comment="use , or . only">00,0</string> <string name="svg_00_0" comment="use , or . only">00,0</string>
<string name="iob_0_00u">0,00U</string> <string name="iob_0_00u">0,00U</string>
<string name="snooze_alert">AAPS Snooze Alert</string>
<string name="sending_snooze">Sending Snooze to AAPS</string>
</resources> </resources>