Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Room Park Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vladislav Bogdashkin
Room Park Android
Commits
0a966929
You need to sign in or sign up before continuing.
Commit
0a966929
authored
Apr 20, 2020
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add noty manager
parent
fa9765ed
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
2 deletions
+64
-2
RoomParkMessageService.kt
...om/biganto/visual/roompark/data/RoomParkMessageService.kt
+6
-0
NotificationCenter.kt
.../roompark/data/service/notification/NotificationCenter.kt
+51
-2
strings.xml
app/src/main/res/values/strings.xml
+7
-0
No files found.
app/src/main/java/com/biganto/visual/roompark/data/RoomParkMessageService.kt
View file @
0a966929
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
...
...
app/src/main/java/com/biganto/visual/roompark/data/service/notification/NotificationCenter.kt
View file @
0a966929
...
...
@@ -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
)
...
...
app/src/main/res/values/strings.xml
View file @
0a966929
...
...
@@ -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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment