open app on notification press
This commit is contained in:
parent
98334eb541
commit
9da8f188b7
|
@ -449,14 +449,14 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
|
|||
&& resultAfterConstraints.carbsReq >= sp.getInt(R.string.key_smb_enable_carbs_suggestions_threshold, 0)
|
||||
&& carbsSuggestionsSuspendedUntil < System.currentTimeMillis() && !treatmentTimethreshold(-15)) {
|
||||
|
||||
if (sp.getBoolean(R.string.key_enable_carbs_required_alert_local, true) && !sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, false)) {
|
||||
if (sp.getBoolean(R.string.key_enable_carbs_required_alert_local, true) && !sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, true)) {
|
||||
Notification carbreqlocal = new Notification(Notification.CARBS_REQUIRED, resultAfterConstraints.getCarbsRequiredText(), Notification.NORMAL);
|
||||
rxBus.send(new EventNewNotification(carbreqlocal));
|
||||
}
|
||||
if (sp.getBoolean(R.string.key_ns_create_announcements_from_carbs_req, false)) {
|
||||
nsUpload.uploadError(resultAfterConstraints.getCarbsRequiredText());
|
||||
}
|
||||
if (sp.getBoolean(R.string.key_enable_carbs_required_alert_local, true) && sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, false)) {
|
||||
if (sp.getBoolean(R.string.key_enable_carbs_required_alert_local, true) && sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, true)) {
|
||||
Intent intentAction5m = new Intent(context, CarbSuggestionReceiver.class);
|
||||
intentAction5m.putExtra("ignoreDuration", 5);
|
||||
PendingIntent pendingIntent5m = PendingIntent.getBroadcast(context, 1, intentAction5m, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
@ -496,7 +496,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
|
|||
rxBus.send(new EventNewOpenLoopNotification());
|
||||
|
||||
//only send to wear if Native notifications are turned off
|
||||
if (!sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, false)) {
|
||||
if (!sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, true)) {
|
||||
// Send to Wear
|
||||
actionStringHandler.get().handleInitiate("changeRequest");
|
||||
}
|
||||
|
|
|
@ -15,7 +15,9 @@ import android.widget.Button
|
|||
import android.widget.TextView
|
||||
import androidx.cardview.widget.CardView
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.TaskStackBuilder
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import info.nightscout.androidaps.MainActivity
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
|
@ -23,6 +25,7 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
|||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
|
||||
import info.nightscout.androidaps.services.AlarmSoundServiceHelper
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.androidNotification.openAppIntent
|
||||
import info.nightscout.androidaps.utils.resources.IconsProvider
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
|
@ -68,7 +71,7 @@ class NotificationStore @Inject constructor(
|
|||
}
|
||||
}
|
||||
store.add(n)
|
||||
if (sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, false) && n !is NotificationWithAction) {
|
||||
if (sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, true) && n !is NotificationWithAction) {
|
||||
raiseSystemNotification(n)
|
||||
if (usesChannels && n.soundId != null && n.soundId != 0) alarmSoundServiceHelper.startAlarm(context, n.soundId)
|
||||
} else {
|
||||
|
@ -113,6 +116,7 @@ class NotificationStore @Inject constructor(
|
|||
.setStyle(NotificationCompat.BigTextStyle().bigText(n.text))
|
||||
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||
.setDeleteIntent(deleteIntent(n.id))
|
||||
.setContentIntent(openAppIntent(context))
|
||||
if (n.level == Notification.URGENT) {
|
||||
notificationBuilder.setVibrate(longArrayOf(1000, 1000, 1000, 1000))
|
||||
.setContentTitle(resourceHelper.gs(R.string.urgent_alarm))
|
||||
|
|
|
@ -23,6 +23,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutos
|
|||
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.androidNotification.NotificationHolder
|
||||
import info.nightscout.androidaps.utils.androidNotification.openAppIntent
|
||||
import info.nightscout.androidaps.utils.resources.IconsProvider
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
|
@ -215,15 +216,7 @@ class PersistentNotificationPlugin @Inject constructor(
|
|||
.setUnreadConversation(unreadConversationBuilder.build()))
|
||||
}
|
||||
/// End Android Auto
|
||||
val resultIntent = Intent(context, MainActivity::class.java)
|
||||
val stackBuilder = TaskStackBuilder.create(context)
|
||||
stackBuilder.addParentStack(MainActivity::class.java)
|
||||
stackBuilder.addNextIntent(resultIntent)
|
||||
val resultPendingIntent = stackBuilder.getPendingIntent(
|
||||
0,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
builder.setContentIntent(resultPendingIntent)
|
||||
builder.setContentIntent(openAppIntent(context))
|
||||
val mNotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
val notification = builder.build()
|
||||
mNotificationManager.notify(notificationHolder.notificationID, notification)
|
||||
|
|
|
@ -2,13 +2,8 @@ package info.nightscout.androidaps.utils.androidNotification
|
|||
|
||||
import android.app.Notification
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.TaskStackBuilder
|
||||
import info.nightscout.androidaps.MainActivity
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.interfaces.NotificationHolderInterface
|
||||
import info.nightscout.androidaps.utils.resources.IconsProvider
|
||||
|
@ -18,28 +13,23 @@ import javax.inject.Singleton
|
|||
|
||||
@Singleton
|
||||
class NotificationHolder @Inject constructor(
|
||||
private val resourceHelper: ResourceHelper,
|
||||
private val context: Context,
|
||||
private val iconsProvider: IconsProvider
|
||||
resourceHelper: ResourceHelper,
|
||||
context: Context,
|
||||
iconsProvider: IconsProvider
|
||||
) : NotificationHolderInterface {
|
||||
|
||||
override val channelID = "AndroidAPS-Ongoing"
|
||||
override val notificationID = 4711
|
||||
override lateinit var notification: Notification
|
||||
|
||||
init {
|
||||
val stackBuilder = TaskStackBuilder.create(context)
|
||||
.addParentStack(MainActivity::class.java)
|
||||
.addNextIntent(Intent(context, MainApp::class.java))
|
||||
val builder = NotificationCompat.Builder(context, channelID)
|
||||
.setOngoing(true)
|
||||
.setOnlyAlertOnce(true)
|
||||
.setCategory(NotificationCompat.CATEGORY_STATUS)
|
||||
.setSmallIcon(iconsProvider.getNotificationIcon())
|
||||
.setLargeIcon(resourceHelper.decodeResource(iconsProvider.getIcon()))
|
||||
.setContentTitle(resourceHelper.gs(R.string.loading))
|
||||
.setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT))
|
||||
notification = builder.build()
|
||||
(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).notify(notificationID, notification)
|
||||
}
|
||||
override var notification: Notification = NotificationCompat.Builder(context, channelID)
|
||||
.setOngoing(true)
|
||||
.setOnlyAlertOnce(true)
|
||||
.setCategory(NotificationCompat.CATEGORY_STATUS)
|
||||
.setSmallIcon(iconsProvider.getNotificationIcon())
|
||||
.setLargeIcon(resourceHelper.decodeResource(iconsProvider.getIcon()))
|
||||
.setContentTitle(resourceHelper.gs(R.string.loading))
|
||||
.setContentIntent(openAppIntent(context))
|
||||
.build()
|
||||
.also {
|
||||
(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).notify(notificationID, it)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package info.nightscout.androidaps.utils.androidNotification
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.core.app.TaskStackBuilder
|
||||
import info.nightscout.androidaps.MainActivity
|
||||
|
||||
fun openAppIntent(context: Context): PendingIntent? = TaskStackBuilder.create(context).run {
|
||||
addParentStack(MainActivity::class.java)
|
||||
addNextIntent(Intent(context, MainActivity::class.java))
|
||||
getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
}
|
|
@ -43,7 +43,7 @@
|
|||
validate:testType="numericRange" />
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:defaultValue="true"
|
||||
android:key="@string/key_raise_notifications_as_android_notifications"
|
||||
android:title="@string/raise_notifications_as_android_notifications" />
|
||||
|
||||
|
|
Loading…
Reference in a new issue