diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt index 03f53421f8..36246c4c2c 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt @@ -1,7 +1,6 @@ package info.nightscout.androidaps.dialogs import android.content.Context -import android.content.Intent import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -92,12 +91,7 @@ class ExtendedBolusDialog : DialogFragmentWithDate() { commandQueue.extendedBolus(insulinAfterConstraint, durationInMinutes, object : Callback() { override fun run() { if (!result.success) { - val i = Intent(ctx, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.treatmentdeliveryerror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - ctx.startActivity(i) + ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), info.nightscout.androidaps.dana.R.raw.boluserror) } } }) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt index 1d215a3b46..90ee51cf63 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt @@ -1,7 +1,6 @@ package info.nightscout.androidaps.dialogs import android.content.Context -import android.content.Intent import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -161,12 +160,7 @@ class FillDialog : DialogFragmentWithDate() { commandQueue.bolus(detailedBolusInfo, object : Callback() { override fun run() { if (!result.success) { - val i = Intent(ctx, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.treatmentdeliveryerror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - ctx.startActivity(i) + ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), info.nightscout.androidaps.dana.R.raw.boluserror) } } }) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt index cfb84df81a..afc68a1e30 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt @@ -1,7 +1,6 @@ package info.nightscout.androidaps.dialogs import android.content.Context -import android.content.Intent import android.os.Bundle import android.text.Editable import android.text.TextWatcher @@ -206,12 +205,7 @@ class InsulinDialog : DialogFragmentWithDate() { commandQueue.bolus(detailedBolusInfo, object : Callback() { override fun run() { if (!result.success) { - val i = Intent(ctx, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.treatmentdeliveryerror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - ctx.startActivity(i) + ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), info.nightscout.androidaps.dana.R.raw.boluserror) } } }) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt index 4d4378655b..484e445136 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt @@ -1,7 +1,6 @@ package info.nightscout.androidaps.dialogs import android.content.Context -import android.content.Intent import android.os.Bundle import android.os.Handler import android.view.LayoutInflater @@ -14,7 +13,8 @@ import dagger.android.support.DaggerDialogFragment import info.nightscout.androidaps.R import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.databinding.DialogLoopBinding -import info.nightscout.androidaps.events.* +import info.nightscout.androidaps.events.EventPreferenceChange +import info.nightscout.androidaps.events.EventRefreshOverview import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.UserEntryLogger @@ -53,6 +53,7 @@ class LoopDialog : DaggerDialogFragment() { private var _binding: DialogLoopBinding? = null private var loopHandler = Handler() private var refreshDialog: Runnable? = null + // This property is only valid between onCreateView and // onDestroyView. private val binding get() = _binding!! @@ -293,12 +294,7 @@ class LoopDialog : DaggerDialogFragment() { commandQueue.cancelTempBasal(true, object : Callback() { override fun run() { if (!result.success) { - val i = Intent(ctx, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.tempbasaldeliveryerror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - ctx.startActivity(i) + ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.tempbasaldeliveryerror), info.nightscout.androidaps.dana.R.raw.boluserror) } } }) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt index 098253b035..b72625a664 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt @@ -1,7 +1,6 @@ package info.nightscout.androidaps.dialogs import android.content.Context -import android.content.Intent import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -121,12 +120,7 @@ class TempBasalDialog : DialogFragmentWithDate() { val callback: Callback = object : Callback() { override fun run() { if (!result.success) { - val i = Intent(ctx, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.tempbasaldeliveryerror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - ctx.startActivity(i) + ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.tempbasaldeliveryerror), info.nightscout.androidaps.dana.R.raw.boluserror) } } } diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt index 4ebaf3b7d2..fe45d727a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt @@ -1,7 +1,6 @@ package info.nightscout.androidaps.dialogs import android.content.Context -import android.content.Intent import android.os.Bundle import android.text.Editable import android.text.TextWatcher @@ -142,12 +141,7 @@ class TreatmentDialog : DialogFragmentWithDate() { commandQueue.bolus(detailedBolusInfo, object : Callback() { override fun run() { if (!result.success) { - val i = Intent(ctx, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.treatmentdeliveryerror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - ctx.startActivity(i) + ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), info.nightscout.androidaps.dana.R.raw.boluserror) } } }) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt index d59f8fa169..91ced93606 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt @@ -613,12 +613,7 @@ open class LoopPlugin @Inject constructor( commandQueue.tempBasalAbsolute(0.0, durationInMinutes, true, profile!!, object : Callback() { override fun run() { if (!result.success) { - val i = Intent(context, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.tempbasaldeliveryerror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(i) + ErrorHelperActivity.runAlarm(context, result.comment, resourceHelper.gs(R.string.tempbasaldeliveryerror), info.nightscout.androidaps.dana.R.raw.boluserror) } } }) @@ -626,12 +621,7 @@ open class LoopPlugin @Inject constructor( commandQueue.tempBasalPercent(0, durationInMinutes, true, profile!!, object : Callback() { override fun run() { if (!result.success) { - val i = Intent(context, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.tempbasaldeliveryerror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(i) + ErrorHelperActivity.runAlarm(context, result.comment, resourceHelper.gs(R.string.tempbasaldeliveryerror), info.nightscout.androidaps.dana.R.raw.boluserror) } } }) @@ -640,12 +630,7 @@ open class LoopPlugin @Inject constructor( commandQueue.cancelExtended(object : Callback() { override fun run() { if (!result.success) { - val i = Intent(context, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.extendedbolusdeliveryerror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(i) + ErrorHelperActivity.runAlarm(context, result.comment, resourceHelper.gs(R.string.extendedbolusdeliveryerror), info.nightscout.androidaps.dana.R.raw.boluserror) } } }) @@ -658,12 +643,7 @@ open class LoopPlugin @Inject constructor( commandQueue.cancelTempBasal(true, object : Callback() { override fun run() { if (!result.success) { - val i = Intent(context, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.tempbasaldeliveryerror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(i) + ErrorHelperActivity.runAlarm(context, result.comment, resourceHelper.gs(R.string.tempbasaldeliveryerror), info.nightscout.androidaps.dana.R.raw.boluserror) } } }) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt index 0a3696b3fb..291971e428 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt @@ -33,7 +33,6 @@ import info.nightscout.androidaps.skins.SkinProvider import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.buildHelper.BuildHelper -import io.reactivex.rxkotlin.plusAssign import info.nightscout.androidaps.utils.extensions.toVisibility import info.nightscout.androidaps.utils.protection.ProtectionCheck import info.nightscout.androidaps.utils.resources.ResourceHelper @@ -42,6 +41,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.ui.SingleClickButton import info.nightscout.androidaps.utils.ui.UIRunnable import io.reactivex.disposables.CompositeDisposable +import io.reactivex.rxkotlin.plusAssign import java.util.* import javax.inject.Inject @@ -158,12 +158,7 @@ class ActionsFragment : DaggerFragment() { commandQueue.cancelExtended(object : Callback() { override fun run() { if (!result.success) { - val i = Intent(ctx, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.extendedbolusdeliveryerror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - ctx.startActivity(i) + ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.extendedbolusdeliveryerror), R.raw.boluserror) } } }) @@ -178,12 +173,7 @@ class ActionsFragment : DaggerFragment() { commandQueue.cancelTempBasal(true, object : Callback() { override fun run() { if (!result.success) { - val i = Intent(ctx, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.tempbasaldeliveryerror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - ctx.startActivity(i) + ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.tempbasaldeliveryerror), R.raw.boluserror) } } }) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt index 45480a4c3f..c387e70f33 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt @@ -1,7 +1,6 @@ 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 @@ -29,6 +28,7 @@ class ActionAlarm(injector: HasAndroidInjector) : Action(injector) { constructor(injector: HasAndroidInjector, text: String) : this(injector) { this.text = InputString(injector, text) } + 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 @@ -36,13 +36,7 @@ class ActionAlarm(injector: HasAndroidInjector) : Action(injector) { override fun isValid(): Boolean = text.value.isNotEmpty() 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) - + ErrorHelperActivity.runAlarm(context, text.value, resourceHelper.gs(R.string.alarm), R.raw.modern_alarm) callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run() } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/CarbsGenerator.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/CarbsGenerator.kt index 8dc1fc859d..4ac7446474 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/CarbsGenerator.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/CarbsGenerator.kt @@ -1,7 +1,6 @@ package info.nightscout.androidaps.plugins.treatments import android.content.Context -import android.content.Intent import info.nightscout.androidaps.R import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.data.DetailedBolusInfo @@ -47,12 +46,7 @@ class CarbsGenerator @Inject constructor( commandQueue.bolus(carbInfo, object : Callback() { override fun run() { if (!result.success) { - val i = Intent(context, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.treatmentdeliveryerror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(i) + ErrorHelperActivity.runAlarm(context, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), R.raw.boluserror) } } }) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java index b1a02ce819..dbb4846bde 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java @@ -1,7 +1,6 @@ package info.nightscout.androidaps.plugins.treatments; import android.content.Context; -import android.content.Intent; import android.os.Bundle; import androidx.annotation.NonNull; @@ -679,12 +678,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface String status = String.format(resourceHelper.gs(R.string.error_adding_treatment_message), treatment.insulin, (int) treatment.carbs, dateUtil.dateAndTimeString(treatment.date)); - Intent i = new Intent(context, ErrorHelperActivity.class); - i.putExtra("soundid", R.raw.error); - i.putExtra("title", resourceHelper.gs(R.string.error_adding_treatment_title)); - i.putExtra("status", status); - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(i); + ErrorHelperActivity.Companion.runAlarm(context, status, resourceHelper.gs(R.string.error_adding_treatment_title), R.raw.error); Bundle bundle = new Bundle(); bundle.putString(FirebaseAnalytics.Param.ITEM_LIST_ID, "TreatmentClash"); diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt index a94806bd5e..9cc9e1720d 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt @@ -116,12 +116,7 @@ class CommandQueue @Inject constructor( setProfile(it, object : Callback() { override fun run() { if (!result.success) { - val i = Intent(context, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.failedupdatebasalprofile)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(i) + ErrorHelperActivity.runAlarm(context, result.comment, resourceHelper.gs(R.string.failedupdatebasalprofile), R.raw.boluserror) } if (result.enacted) rxBus.send(EventNewBasalProfile()) } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt b/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt index e32f62e61b..5f09d04d0c 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt @@ -361,12 +361,7 @@ class BolusWizard @Inject constructor( commandQueue.bolus(this, object : Callback() { override fun run() { if (!result.success) { - val i = Intent(ctx, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.treatmentdeliveryerror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - ctx.startActivity(i) + ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), R.raw.boluserror) } else scheduleEatReminder() } @@ -394,12 +389,7 @@ class BolusWizard @Inject constructor( commandQueue.tempBasalAbsolute(0.0, 120, true, profile, object : Callback() { override fun run() { if (!result.success) { - val i = Intent(ctx, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.tempbasaldeliveryerror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - ctx.startActivity(i) + ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.tempbasaldeliveryerror), R.raw.boluserror) } } }) @@ -409,9 +399,9 @@ class BolusWizard @Inject constructor( override fun run() { if (!result.success) { val i = Intent(ctx, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.tempbasaldeliveryerror)) + i.putExtra(ErrorHelperActivity.SOUND_ID, R.raw.boluserror) + i.putExtra(ErrorHelperActivity.STATUS, result.comment) + i.putExtra(ErrorHelperActivity.TITLE, resourceHelper.gs(R.string.tempbasaldeliveryerror)) i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) ctx.startActivity(i) } @@ -435,12 +425,7 @@ class BolusWizard @Inject constructor( commandQueue.bolus(this, object : Callback() { override fun run() { if (!result.success) { - val i = Intent(ctx, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.treatmentdeliveryerror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - ctx.startActivity(i) + ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), R.raw.boluserror) } } }) diff --git a/core/src/main/java/info/nightscout/androidaps/activities/ErrorHelperActivity.kt b/core/src/main/java/info/nightscout/androidaps/activities/ErrorHelperActivity.kt index 11affb41d3..0b970ccbe0 100644 --- a/core/src/main/java/info/nightscout/androidaps/activities/ErrorHelperActivity.kt +++ b/core/src/main/java/info/nightscout/androidaps/activities/ErrorHelperActivity.kt @@ -1,6 +1,9 @@ package info.nightscout.androidaps.activities +import android.content.Context +import android.content.Intent import android.os.Bundle +import androidx.annotation.RawRes import info.nightscout.androidaps.core.R import info.nightscout.androidaps.dialogs.ErrorDialog import info.nightscout.androidaps.plugins.general.nsclient.NSUpload @@ -16,13 +19,28 @@ class ErrorHelperActivity : DialogAppCompatActivity() { super.onCreate(savedInstanceState) val errorDialog = ErrorDialog() errorDialog.helperActivity = this - errorDialog.status = intent.getStringExtra("status") - errorDialog.sound = intent.getIntExtra("soundid", R.raw.error) - errorDialog.title = intent.getStringExtra("title") + errorDialog.status = intent.getStringExtra(STATUS) + errorDialog.sound = intent.getIntExtra(SOUND_ID, R.raw.error) + errorDialog.title = intent.getStringExtra(TITLE) errorDialog.show(supportFragmentManager, "Error") if (sp.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) { - nsUpload.uploadError(intent.getStringExtra("status")) + nsUpload.uploadError(intent.getStringExtra(STATUS)) + } + } + + companion object { + const val SOUND_ID = "soundId" + const val STATUS = "status" + const val TITLE = "title" + + fun runAlarm(ctx: Context, status: String, title : String, @RawRes soundId: Int = 0) { + val i = Intent(ctx, ErrorHelperActivity::class.java) + i.putExtra(SOUND_ID, soundId) + i.putExtra(STATUS, status) + i.putExtra(TITLE, title) + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + ctx.startActivity(i) } } } diff --git a/core/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.kt b/core/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.kt index 37709081ab..4c6ce89400 100644 --- a/core/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.kt +++ b/core/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.kt @@ -8,6 +8,7 @@ import android.os.Binder import android.os.Handler import android.os.IBinder import dagger.android.DaggerService +import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.core.R import info.nightscout.androidaps.interfaces.NotificationHolderInterface import info.nightscout.androidaps.logging.AAPSLogger @@ -69,7 +70,7 @@ class AlarmSoundService : DaggerService() { player?.let { if (it.isPlaying) it.stop() } - if (intent?.hasExtra("soundid") == true) resourceId = intent.getIntExtra("soundid", R.raw.error) + if (intent?.hasExtra(ErrorHelperActivity.SOUND_ID) == true) resourceId = intent.getIntExtra(ErrorHelperActivity.SOUND_ID, R.raw.error) player = MediaPlayer() try { val afd = resourceHelper.openRawResourceFd(resourceId) ?: return START_STICKY diff --git a/core/src/main/java/info/nightscout/androidaps/services/AlarmSoundServiceHelper.kt b/core/src/main/java/info/nightscout/androidaps/services/AlarmSoundServiceHelper.kt index a01106c5b0..2ea92fd952 100644 --- a/core/src/main/java/info/nightscout/androidaps/services/AlarmSoundServiceHelper.kt +++ b/core/src/main/java/info/nightscout/androidaps/services/AlarmSoundServiceHelper.kt @@ -7,6 +7,7 @@ import android.content.ServiceConnection import android.os.Build import android.os.IBinder import androidx.annotation.RequiresApi +import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.interfaces.NotificationHolderInterface import javax.inject.Inject import javax.inject.Singleton @@ -67,7 +68,7 @@ class AlarmSoundServiceHelper @Inject constructor( private fun getServiceIntent(context: Context, sound: Int): Intent { val alarm = Intent(context, AlarmSoundService::class.java) - alarm.putExtra("soundid", sound) + alarm.putExtra(ErrorHelperActivity.SOUND_ID, sound) return alarm } } \ No newline at end of file diff --git a/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaUserOptionsActivity.kt b/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaUserOptionsActivity.kt index fd1ee31fbf..e6e8698e13 100644 --- a/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaUserOptionsActivity.kt +++ b/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaUserOptionsActivity.kt @@ -1,7 +1,6 @@ package info.nightscout.androidaps.dana.activities import android.content.Context -import android.content.Intent import android.os.Bundle import info.nightscout.androidaps.Constants import info.nightscout.androidaps.activities.ErrorHelperActivity @@ -18,9 +17,9 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.FabricPrivacy -import io.reactivex.rxkotlin.plusAssign import info.nightscout.androidaps.utils.rx.AapsSchedulers import io.reactivex.disposables.CompositeDisposable +import io.reactivex.rxkotlin.plusAssign import java.text.DecimalFormat import javax.inject.Inject import kotlin.math.max @@ -154,12 +153,7 @@ class DanaUserOptionsActivity : NoSplashAppCompatActivity() { commandQueue.setUserOptions(object : Callback() { override fun run() { if (!result.success) { - val i = Intent(context, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.boluserror) - i.putExtra("status", result.comment) - i.putExtra("title", resourceHelper.gs(R.string.pumperror)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(i) + ErrorHelperActivity.runAlarm(context, result.comment, resourceHelper.gs(R.string.pumperror), R.raw.boluserror) } } }) diff --git a/danar/src/main/java/info/nightscout/androidaps/danaRv2/services/DanaRv2ExecutionService.java b/danar/src/main/java/info/nightscout/androidaps/danaRv2/services/DanaRv2ExecutionService.java index 41267b5854..923920a43d 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danaRv2/services/DanaRv2ExecutionService.java +++ b/danar/src/main/java/info/nightscout/androidaps/danaRv2/services/DanaRv2ExecutionService.java @@ -1,7 +1,6 @@ package info.nightscout.androidaps.danaRv2.services; import android.content.Context; -import android.content.Intent; import android.os.Binder; import android.os.SystemClock; @@ -205,12 +204,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { if (Math.abs(timeDiff) > 60 * 60 * 1.5) { aapsLogger.debug(LTag.PUMP, "Pump time difference: " + timeDiff + " seconds - large difference"); //If time-diff is very large, warn user until we can synchronize history readings properly - Intent i = new Intent(context, ErrorHelperActivity.class); - i.putExtra("soundid", R.raw.error); - i.putExtra("status", resourceHelper.gs(R.string.largetimediff)); - i.putExtra("title", resourceHelper.gs(R.string.largetimedifftitle)); - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(i); + ErrorHelperActivity.Companion.runAlarm(context, resourceHelper.gs(R.string.largetimediff), resourceHelper.gs(R.string.largetimedifftitle), R.raw.error); //deinitialize pump danaPump.reset(); diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/services/DanaRSService.kt b/danars/src/main/java/info/nightscout/androidaps/danars/services/DanaRSService.kt index c6f795efeb..1c9890995c 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/services/DanaRSService.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/services/DanaRSService.kt @@ -168,12 +168,7 @@ class DanaRSService : DaggerService() { if (abs(timeDiff) > 60 * 60 * 1.5) { aapsLogger.debug(LTag.PUMPCOMM, "Pump time difference: $timeDiff seconds - large difference") //If time-diff is very large, warn user until we can synchronize history readings properly - val i = Intent(context, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.error) - i.putExtra("status", resourceHelper.gs(R.string.largetimediff)) - i.putExtra("title", resourceHelper.gs(R.string.largetimedifftitle)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(i) + ErrorHelperActivity.runAlarm(context, resourceHelper.gs(R.string.largetimediff), resourceHelper.gs(R.string.largetimedifftitle), R.raw.error) //de-initialize pump danaPump.reset() diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java index 34280bdca4..89aa6fcc7e 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java @@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.pump.medtronic; import android.content.ComponentName; import android.content.Context; -import android.content.Intent; import android.content.ServiceConnection; import android.os.IBinder; import android.os.SystemClock; @@ -876,13 +875,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter // LOG.debug("MedtronicPumpPlugin::deliverBolus - Show dialog. Context: " // + MainApp.instance().getApplicationContext()); - Intent i = new Intent(context, ErrorHelperActivity.class); - i.putExtra("soundid", R.raw.boluserror); - i.putExtra("status", getResourceHelper().gs(R.string.medtronic_cmd_cancel_bolus_not_supported)); - i.putExtra("title", getResourceHelper().gs(R.string.medtronic_warning)); - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(i); - + ErrorHelperActivity.Companion.runAlarm(context,getResourceHelper().gs(R.string.medtronic_cmd_cancel_bolus_not_supported), getResourceHelper().gs(R.string.medtronic_warning), R.raw.boluserror); }).start(); } @@ -1563,12 +1556,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter if (rileyLinkMedtronicService.verifyConfiguration()) { serviceTaskExecutor.startTask(new WakeAndTuneTask(getInjector())); } else { - Intent i = new Intent(context, ErrorHelperActivity.class); - i.putExtra("soundid", R.raw.boluserror); - i.putExtra("status", getResourceHelper().gs(R.string.medtronic_error_operation_not_possible_no_configuration)); - i.putExtra("title", getResourceHelper().gs(R.string.medtronic_warning)); - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(i); + ErrorHelperActivity.Companion.runAlarm(context, getResourceHelper().gs(R.string.medtronic_error_operation_not_possible_no_configuration), getResourceHelper().gs(R.string.medtronic_warning), R.raw.boluserror); } } break; diff --git a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/OmnipodErosPumpPlugin.java b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/OmnipodErosPumpPlugin.java index 6a5364dbca..2248faeada 100644 --- a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/OmnipodErosPumpPlugin.java +++ b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/OmnipodErosPumpPlugin.java @@ -878,9 +878,9 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa } Intent i = new Intent(context, ErrorHelperActivity.class); - i.putExtra("soundid", 0); - i.putExtra("status", resourceHelper.gs(R.string.omnipod_pulse_log_value) + ":\n" + result.toString()); - i.putExtra("title", resourceHelper.gs(R.string.omnipod_pulse_log)); + i.putExtra(ErrorHelperActivity.SOUND_ID, 0); + i.putExtra(ErrorHelperActivity.STATUS, resourceHelper.gs(R.string.omnipod_pulse_log_value) + ":\n" + result.toString()); + i.putExtra(ErrorHelperActivity.TITLE, resourceHelper.gs(R.string.omnipod_pulse_log)); i.putExtra("clipboardContent", result.toString()); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); diff --git a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/manager/AapsOmnipodManager.java b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/manager/AapsOmnipodManager.java index d4a76b8bae..9b3ac55763 100644 --- a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/manager/AapsOmnipodManager.java +++ b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/manager/AapsOmnipodManager.java @@ -1,7 +1,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.eros.manager; import android.content.Context; -import android.content.Intent; import org.joda.time.DateTime; import org.joda.time.Duration; @@ -957,12 +956,7 @@ public class AapsOmnipodManager { } private void showErrorDialog(String message, Integer sound) { - Intent intent = new Intent(context, ErrorHelperActivity.class); - intent.putExtra("soundid", sound); - intent.putExtra("status", message); - intent.putExtra("title", resourceHelper.gs(R.string.error)); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); + ErrorHelperActivity.Companion.runAlarm(context, message, resourceHelper.gs(R.string.error), sound); } private void showPodFaultNotification(FaultEventCode faultEventCode) { diff --git a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/OmnipodOverviewFragment.kt b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/OmnipodOverviewFragment.kt index d2b91f0044..af55f56953 100644 --- a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/OmnipodOverviewFragment.kt +++ b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/OmnipodOverviewFragment.kt @@ -537,12 +537,7 @@ class OmnipodOverviewFragment : DaggerFragment() { private fun displayErrorDialog(title: String, message: String, withSound: Boolean) { context?.let { - val i = Intent(it, ErrorHelperActivity::class.java) - i.putExtra("soundid", if (withSound) R.raw.boluserror else 0) - i.putExtra("status", message) - i.putExtra("title", title) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - it.startActivity(i) + ErrorHelperActivity.runAlarm(it, message, title, if (withSound) R.raw.boluserror else 0) } } diff --git a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/PodManagementActivity.kt b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/PodManagementActivity.kt index 2b58fb5693..fd807df724 100644 --- a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/PodManagementActivity.kt +++ b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/ui/PodManagementActivity.kt @@ -209,12 +209,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() { private fun displayErrorDialog(title: String, message: String, @Suppress("SameParameterValue") withSound: Boolean) { context.let { - val i = Intent(it, ErrorHelperActivity::class.java) - i.putExtra("soundid", if (withSound) R.raw.boluserror else 0) - i.putExtra("status", message) - i.putExtra("title", title) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - it.startActivity(i) + ErrorHelperActivity.runAlarm(it, message, title, if (withSound) R.raw.boluserror else 0) } }