Update NotificationHolderImpl.kt
This commit is contained in:
parent
85b2d2aeac
commit
e4c3e4c560
1 changed files with 33 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.androidaps.utils.androidNotification
|
package info.nightscout.androidaps.utils.androidNotification
|
||||||
|
|
||||||
import android.app.Notification
|
import android.app.Notification
|
||||||
|
import android.app.NotificationChannel
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
@ -17,14 +18,31 @@ import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class NotificationHolderImpl @Inject constructor(
|
class NotificationHolderImpl @Inject constructor(
|
||||||
rh: ResourceHelper,
|
val rh: ResourceHelper,
|
||||||
context: Context,
|
val context: Context,
|
||||||
iconsProvider: IconsProvider
|
val iconsProvider: IconsProvider
|
||||||
) : NotificationHolder {
|
) : NotificationHolder {
|
||||||
|
|
||||||
override val channelID = "AndroidAPS-Ongoing"
|
override val channelID = "AndroidAPS-Ongoing"
|
||||||
override val notificationID = 4711
|
override val notificationID = 4711
|
||||||
override var notification: Notification = NotificationCompat.Builder(context, channelID)
|
private var _notification: Notification? = null
|
||||||
|
override var notification: Notification
|
||||||
|
set(value) {
|
||||||
|
_notification = value
|
||||||
|
}
|
||||||
|
get() = _notification ?: placeholderNotification()
|
||||||
|
|
||||||
|
override fun openAppIntent(context: Context): PendingIntent? = TaskStackBuilder.create(context).run {
|
||||||
|
addParentStack(MainActivity::class.java)
|
||||||
|
addNextIntent(Intent(context, MainActivity::class.java))
|
||||||
|
getPendingIntent(0, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun placeholderNotification(): Notification {
|
||||||
|
|
||||||
|
createNotificationChannel()
|
||||||
|
|
||||||
|
return NotificationCompat.Builder(context, channelID)
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setOnlyAlertOnce(true)
|
.setOnlyAlertOnce(true)
|
||||||
.setCategory(NotificationCompat.CATEGORY_STATUS)
|
.setCategory(NotificationCompat.CATEGORY_STATUS)
|
||||||
|
@ -36,10 +54,11 @@ class NotificationHolderImpl @Inject constructor(
|
||||||
.also {
|
.also {
|
||||||
(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).notify(notificationID, it)
|
(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).notify(notificationID, it)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun openAppIntent(context: Context): PendingIntent? = TaskStackBuilder.create(context).run {
|
override fun createNotificationChannel() {
|
||||||
addParentStack(MainActivity::class.java)
|
val mNotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
addNextIntent(Intent(context, MainActivity::class.java))
|
val channel = NotificationChannel(channelID, channelID as CharSequence, NotificationManager.IMPORTANCE_HIGH)
|
||||||
getPendingIntent(0, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
|
mNotificationManager.createNotificationChannel(channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue