ActionAlarm
This commit is contained in:
parent
4d02587bb7
commit
f5f4c655c5
6 changed files with 174 additions and 0 deletions
|
@ -39,6 +39,7 @@ abstract class AutomationModule {
|
|||
@ContributesAndroidInjector abstract fun actionLoopResumeInjector(): ActionLoopResume
|
||||
@ContributesAndroidInjector abstract fun actionLoopSuspendInjector(): ActionLoopSuspend
|
||||
@ContributesAndroidInjector abstract fun actionNotificationInjector(): ActionNotification
|
||||
@ContributesAndroidInjector abstract fun actionAlarmInjector(): ActionAlarm
|
||||
@ContributesAndroidInjector abstract fun actionProfileSwitchInjector(): ActionProfileSwitch
|
||||
@ContributesAndroidInjector abstract fun actionProfileSwitchPercentInjector(): ActionProfileSwitchPercent
|
||||
@ContributesAndroidInjector abstract fun actionSendSMSInjector(): ActionSendSMS
|
||||
|
|
|
@ -239,6 +239,7 @@ class AutomationPlugin @Inject constructor(
|
|||
ActionStartTempTarget(injector),
|
||||
ActionStopTempTarget(injector),
|
||||
ActionNotification(injector),
|
||||
ActionAlarm(injector),
|
||||
ActionProfileSwitchPercent(injector),
|
||||
ActionProfileSwitch(injector),
|
||||
ActionSendSMS(injector)
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.widget.LinearLayout
|
||||
import androidx.annotation.DrawableRes
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.activities.ErrorHelperActivity
|
||||
import info.nightscout.androidaps.activities.PreferencesActivity
|
||||
import info.nightscout.androidaps.data.PumpEnactResult
|
||||
import info.nightscout.androidaps.events.EventRefreshOverview
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputString
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithElement
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationUserMessage
|
||||
import info.nightscout.androidaps.queue.Callback
|
||||
import info.nightscout.androidaps.utils.JsonHelper
|
||||
import info.nightscout.androidaps.utils.alertDialogs.WarningDialog
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import org.json.JSONObject
|
||||
import javax.inject.Inject
|
||||
|
||||
class ActionAlarm(injector: HasAndroidInjector) : Action(injector) {
|
||||
|
||||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var rxBus: RxBusWrapper
|
||||
@Inject lateinit var nsUpload: NSUpload
|
||||
@Inject lateinit var context: Context
|
||||
|
||||
var text = InputString(injector)
|
||||
|
||||
override fun friendlyName(): Int = R.string.alarm
|
||||
override fun shortDescription(): String = resourceHelper.gs(R.string.alarm_message, text.value)
|
||||
@DrawableRes override fun icon(): Int = R.drawable.ic_access_alarm_24dp
|
||||
|
||||
override fun doAction(callback: Callback) {
|
||||
val i = Intent(context, ErrorHelperActivity::class.java)
|
||||
i.putExtra("soundid", R.raw.modern_alarm)
|
||||
i.putExtra("status", text.value)
|
||||
i.putExtra("title", resourceHelper.gs(R.string.alarm))
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
context.startActivity(i)
|
||||
|
||||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
|
||||
}
|
||||
|
||||
override fun toJSON(): String {
|
||||
val data = JSONObject().put("text", text.value)
|
||||
return JSONObject()
|
||||
.put("type", this.javaClass.name)
|
||||
.put("data", data)
|
||||
.toString()
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Action {
|
||||
val o = JSONObject(data)
|
||||
text.value = JsonHelper.safeGetString(o, "text", "")
|
||||
return this
|
||||
}
|
||||
|
||||
override fun hasDialog(): Boolean = true
|
||||
|
||||
override fun generateDialog(root: LinearLayout) {
|
||||
LayoutBuilder()
|
||||
.add(LabelWithElement(injector, resourceHelper.gs(R.string.alarm_short), "", text))
|
||||
.build(root)
|
||||
}
|
||||
}
|
BIN
app/src/main/res/raw/modern_alarm.mp3
Normal file
BIN
app/src/main/res/raw/modern_alarm.mp3
Normal file
Binary file not shown.
|
@ -1174,7 +1174,9 @@
|
|||
|
||||
<string name="notification">Notification</string>
|
||||
<string name="notification_message">Notification: %1$s</string>
|
||||
<string name="alarm_message">Alarm: %1$s</string>
|
||||
<string name="message_short">Msg:</string>
|
||||
<string name="alarm_short">Alarm:</string>
|
||||
<string name="profilepercentage">Profile percentage</string>
|
||||
<string name="percent_u">Percent [%]:</string>
|
||||
<string name="startprofile">Start profile %1$d%% for %2$d min</string>
|
||||
|
@ -1411,5 +1413,6 @@
|
|||
<string name="filter">Filter</string>
|
||||
<string name="copytolocalprofile_invalid">Unable to create local profile. Profile is invalid.</string>
|
||||
<string name="cta_dont_kill_my_app_info">Don\'t kill my app?</string>
|
||||
<string name="alarm">Alarm</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||
|
||||
import android.content.Context
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.androidaps.data.PumpEnactResult
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputString
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||
import info.nightscout.androidaps.queue.Callback
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.powermock.api.mockito.PowerMockito
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest(NSUpload::class, RxBusWrapper::class)
|
||||
class ActionAlarmTest : TestBase() {
|
||||
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var rxBus: RxBusWrapper
|
||||
@Mock lateinit var nsUpload: NSUpload
|
||||
@Mock lateinit var context: Context
|
||||
|
||||
private lateinit var sut: ActionAlarm
|
||||
var injector: HasAndroidInjector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is ActionAlarm) {
|
||||
it.resourceHelper = resourceHelper
|
||||
it.rxBus = rxBus
|
||||
it.nsUpload = nsUpload
|
||||
it.context = context
|
||||
}
|
||||
if (it is PumpEnactResult) {
|
||||
it.aapsLogger = aapsLogger
|
||||
it.resourceHelper = resourceHelper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
PowerMockito.mockStatic(NSUpload::class.java)
|
||||
`when`(resourceHelper.gs(R.string.ok)).thenReturn("OK")
|
||||
`when`(resourceHelper.gs(R.string.alarm)).thenReturn("Alarm")
|
||||
`when`(resourceHelper.gs(ArgumentMatchers.eq(R.string.alarm_message), ArgumentMatchers.anyString())).thenReturn("Alarm: %s")
|
||||
|
||||
sut = ActionAlarm(injector)
|
||||
}
|
||||
|
||||
@Test fun friendlyNameTest() {
|
||||
Assert.assertEquals(R.string.alarm, sut.friendlyName())
|
||||
}
|
||||
|
||||
@Test fun shortDescriptionTest() {
|
||||
sut.text = InputString(injector, "Asd")
|
||||
Assert.assertEquals("Alarm: %s", sut.shortDescription())
|
||||
}
|
||||
|
||||
@Test fun iconTest() {
|
||||
Assert.assertEquals(R.drawable.ic_access_alarm_24dp, sut.icon())
|
||||
}
|
||||
|
||||
@Test fun doActionTest() {
|
||||
sut.doAction(object : Callback() {
|
||||
override fun run() {
|
||||
Assert.assertTrue(result.success)
|
||||
}
|
||||
})
|
||||
PowerMockito.verifyStatic(NSUpload::class.java, Mockito.times(1))
|
||||
}
|
||||
|
||||
@Test fun hasDialogTest() {
|
||||
Assert.assertTrue(sut.hasDialog())
|
||||
}
|
||||
|
||||
@Test fun toJSONTest() {
|
||||
sut.text = InputString(injector, "Asd")
|
||||
Assert.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionAlarm\"}", sut.toJSON())
|
||||
}
|
||||
|
||||
@Test fun fromJSONTest() {
|
||||
sut.text = InputString(injector, "Asd")
|
||||
sut.fromJSON("{\"text\":\"Asd\"}")
|
||||
Assert.assertEquals("Asd", sut.text.value)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue