OsmAnd/OsmAnd-telegram/src/net/osmand/telegram/notifications/NotificationHelper.kt

51 lines
1.9 KiB
Kotlin
Raw Normal View History

package net.osmand.telegram.notifications
import android.annotation.TargetApi
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.support.v4.app.NotificationManagerCompat
import net.osmand.telegram.R
import net.osmand.telegram.TelegramApplication
import net.osmand.telegram.notifications.TelegramNotification.NotificationType
import java.util.*
class NotificationHelper(private val app: TelegramApplication) {
2018-06-11 16:12:03 +02:00
val shareLocationNotification = ShareLocationNotification(app)
val showLocationNotification = ShowLocationNotification(app)
2018-06-11 16:12:03 +02:00
private val all = listOf(shareLocationNotification, showLocationNotification)
2018-06-11 16:12:03 +02:00
fun buildNotification(telegramNotification: TelegramNotification): Notification {
return telegramNotification.buildNotification(false).build()
}
fun refreshNotification(notificationType: NotificationType) {
for (notification in all) {
if (notification.type == notificationType) {
notification.refreshNotification()
break
}
}
}
@TargetApi(26)
fun createNotificationChannel() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
val channel = NotificationChannel(NOTIFICATION_CHANEL_ID,
app.getString(R.string.osmand_service), NotificationManager.IMPORTANCE_LOW)
channel.enableVibration(false)
channel.description = app.getString(R.string.osmand_service_descr)
val mNotificationManager = app
.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
mNotificationManager.createNotificationChannel(channel)
}
}
companion object {
const val NOTIFICATION_CHANEL_ID = "osmand_telegram_background_service"
}
}