You need to sign in or sign up before continuing.
Commit 0a966929 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

add noty manager

parent fa9765ed
package com.biganto.visual.roompark.data
import com.biganto.visual.roompark.data.service.notification.INotificationCenter
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import timber.log.Timber
import javax.inject.Inject
class RoomParkMessageService : FirebaseMessagingService() {
@Inject
lateinit var notyCenter: INotificationCenter
override fun onNewToken(p0: String) {
super.onNewToken(p0)
Timber.d("NEW TOKEN REGISTERED: ${p0}")
......@@ -19,6 +24,7 @@ class RoomParkMessageService : FirebaseMessagingService() {
// Check if message contains a data payload.
if (remoteMessage.data.size > 0) {
Timber.d("Message data payload: %s", remoteMessage.data)
notyCenter.showPushNotifyMessage(remoteMessage.notification?.body?:"Уведомление")
if ( /* Check if data needs to be processed by long running job */true) { // For long-running tasks (10 seconds or more) use Firebase Job Dispatcher.
// scheduleJob()
} else { // Handle message within 10 seconds
......
......@@ -22,8 +22,11 @@ import javax.inject.Singleton
const val ANDROID_CHANNEL_ID = "com.biganto.visual.androidplayer.data.services.downloader.DownloadManagerService.CHANNEL_ID"
const val TOURS_CHANNEL_ID = "com.biganto.visual.androidplayer.data.services.downloader.DownloadManagerService.TOURS_CHANNEL_ID"
const val DOWNLOAD_SERVICE_ID = 7897
const val TOUR_INFO_SERVICE_ID = 7899
const val PUSH_CHANNEL_ID = "com.biganto.visual.androidplayer.data.services.downloader.DownloadManagerService.PUSH_CHANNEL_ID"
const val DOWNLOAD_SERVICE_ID = 7990
const val TOUR_INFO_SERVICE_ID = 7991
const val PUSH_INFO_SERVICE_ID = 7992
const val NOTIFICATION_INTENT="NOTIFICATION_INTENT_KEY"
const val NOTIFICATION_START_SCREEN="NOTIFICATION_START_SCREEN_KEY"
......@@ -48,6 +51,9 @@ interface INotificationCenter{
,progressMax:Int=0
,indeterminate:Boolean=true
,message: String)
val IncomingPushServiceNotification: Notification
fun showPushNotifyMessage(message: String)
}
......@@ -64,11 +70,13 @@ class NotificationCenter @Inject constructor(val context: Application) : INotif
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel()
createToursNotificationChannel()
createPushNotificationChannel()
}
}
private val builder = NotificationCompat.Builder(context, ANDROID_CHANNEL_ID)
private val toursNotyBuilder = NotificationCompat.Builder(context, TOURS_CHANNEL_ID)
private val pushNotyBuilder = NotificationCompat.Builder(context, PUSH_CHANNEL_ID)
private val notificationSystemColor = ContextCompat.getColor(context, R.color.colorAccent)
private val icon = BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher_round);
......@@ -85,6 +93,14 @@ class NotificationCenter @Inject constructor(val context: Application) : INotif
.setColor(notificationSystemColor)
.build()
override val IncomingPushServiceNotification: Notification =
pushNotyBuilder
.setContentTitle(context.getString(R.string.notification_content_title))//getString(R.string.app_name))
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setSmallIcon(R.mipmap.ic_launcher)
.setColor(notificationSystemColor)
.build()
//Заготовка под переход в определенный экран приложения по нажатию на нотификацию
private val toDownloadsIntent =
Intent(context, RoomParkMainActivity::class.java)
......@@ -113,6 +129,21 @@ class NotificationCenter @Inject constructor(val context: Application) : INotif
donwloadServiceProgressNotfication(indeterminate = false,message = message)
}
override fun showPushNotifyMessage(message: String){
val noty = pushNotyBuilder
.setContentTitle(context.getString(R.string.notification_content_title))//getString(R.string.app_name))
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentText(message)
.setColor(notificationSystemColor)
.build()
actualNotifyManager.notify(
PUSH_INFO_SERVICE_ID
, noty)
}
override fun donwloadServiceProgressNotfication(progress:Int
, progressMax:Int
, indeterminate:Boolean
......@@ -175,6 +206,24 @@ class NotificationCenter @Inject constructor(val context: Application) : INotif
return channelId
}
@TargetApi(Build.VERSION_CODES.O)
@RequiresApi(Build.VERSION_CODES.O)
private fun createPushNotificationChannel(): String {
val channelId = PUSH_CHANNEL_ID
val channelName = "RoomPark push info update"
val chan = NotificationChannel(channelId,
channelName, NotificationManager.IMPORTANCE_DEFAULT)
chan.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
chan.enableVibration(true)
chan.lightColor = R.color.colorPrimary
val service = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
service.createNotificationChannel(chan)
return channelId
}
private fun DownloadState.notyName() =
when(this){
DownloadState.Downloaded ->context.getString(R.string.state_downloaded_notify_message)
......
......@@ -112,6 +112,13 @@
<!--endregion-->
<!-- region notifications-->
<string name="push_notification_content_title">Уведомление!</string>
<!--endregion-->
<string name="on_all_tours_downloaded_notification_message">Загрузка туров завершена</string>
<string name="on_all_tours_deleted_notification_message">Удаление туров завершено</string>
<string name="noty_tours_delete_left">Осталось удалить: %d%n</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment