Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
AloqaIM-Android
Commits
fd798148
Commit
fd798148
authored
Oct 19, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor refactoring
parent
76e7a2db
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
32 deletions
+45
-32
PushManager.kt
app/src/main/java/chat/rocket/android/push/PushManager.kt
+45
-32
No files found.
app/src/main/java/chat/rocket/android/push/PushManager.kt
View file @
fd798148
...
@@ -42,14 +42,8 @@ object PushManager {
...
@@ -42,14 +42,8 @@ object PushManager {
val
style
=
data
[
"style"
]
as
String
val
style
=
data
[
"style"
]
as
String
val
summaryText
=
data
[
"summaryText"
]
as
String
val
summaryText
=
data
[
"summaryText"
]
as
String
val
count
=
data
[
"count"
]
as
String
val
count
=
data
[
"count"
]
as
String
val
pushMessage
=
PushMessage
(
data
[
"title"
]
as
String
,
val
title
=
data
[
"title"
]
as
String
message
,
val
pushMessage
=
PushMessage
(
title
,
message
,
image
,
ejson
,
count
,
notificationId
,
summaryText
,
style
)
image
,
ejson
,
count
,
notificationId
,
summaryText
,
style
)
// We should use Timber here
// We should use Timber here
if
(
BuildConfig
.
DEBUG
)
{
if
(
BuildConfig
.
DEBUG
)
{
...
@@ -65,6 +59,39 @@ object PushManager {
...
@@ -65,6 +59,39 @@ object PushManager {
val
notificationManager
:
NotificationManager
=
val
notificationManager
:
NotificationManager
=
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
val
groupNotification
=
createGroupNotification
(
context
,
pushMessage
,
data
,
smallIcon
)
val
groupId
=
groupMap
.
get
(
pushMessage
.
host
)
val
notification
:
Notification
if
(
isAndroidVersionAtLeast
(
Build
.
VERSION_CODES
.
O
))
{
notification
=
createNotificationForOreoAndAbove
(
appContext
,
pushMessage
,
smallIcon
,
data
)
if
(
groupId
!=
null
)
{
notificationManager
.
notify
(
groupId
,
notification
)
}
notificationManager
.
notify
(
notificationId
.
toInt
(),
notification
)
}
else
{
notification
=
createCompatNotification
(
appContext
,
pushMessage
,
smallIcon
,
data
)
if
(
groupId
!=
null
)
{
NotificationManagerCompat
.
from
(
appContext
).
notify
(
groupId
,
groupNotification
)
}
NotificationManagerCompat
.
from
(
appContext
).
notify
(
notificationId
.
toInt
(),
notification
)
}
}
private
fun
isAndroidVersionAtLeast
(
minVersion
:
Int
)
=
Build
.
VERSION
.
SDK_INT
>=
minVersion
private
fun
addGroupToBundle
(
host
:
String
)
{
val
size
=
groupMap
.
size
if
(
groupMap
.
get
(
host
)
==
null
)
{
groupMap
.
put
(
host
,
size
+
1
)
}
}
fun
clearMessageStack
(
notificationId
:
Int
)
{
messageStack
.
delete
(
notificationId
)
}
private
fun
createGroupNotification
(
context
:
Context
,
pushMessage
:
PushMessage
,
data
:
Bundle
,
smallIcon
:
Int
):
Notification
{
// Create notification group.
// Create notification group.
addGroupToBundle
(
pushMessage
.
host
)
addGroupToBundle
(
pushMessage
.
host
)
val
id
=
pushMessage
.
notificationId
.
toInt
()
val
id
=
pushMessage
.
notificationId
.
toInt
()
...
@@ -89,26 +116,7 @@ object PushManager {
...
@@ -89,26 +116,7 @@ object PushManager {
notGroupBuilder
.
setSubText
(
subText
)
notGroupBuilder
.
setSubText
(
subText
)
}
}
val
notification
:
Notification
return
notGroupBuilder
.
build
()
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
notification
=
createNotificationForOreoAndAbove
(
appContext
,
pushMessage
,
smallIcon
,
data
)
notificationManager
.
notify
(
notificationId
.
toInt
(),
notification
)
}
else
{
notification
=
createCompatNotification
(
appContext
,
pushMessage
,
smallIcon
,
data
)
NotificationManagerCompat
.
from
(
appContext
).
notify
(
groupMap
.
get
(
pushMessage
.
host
)
!!
,
notGroupBuilder
.
build
())
NotificationManagerCompat
.
from
(
appContext
).
notify
(
notificationId
.
toInt
(),
notification
)
}
}
private
fun
addGroupToBundle
(
host
:
String
)
{
val
size
=
groupMap
.
size
if
(
groupMap
.
get
(
host
)
==
null
)
{
groupMap
.
put
(
host
,
size
+
1
)
}
}
fun
clearMessageStack
(
notificationId
:
Int
)
{
messageStack
.
delete
(
notificationId
)
}
}
private
fun
createCompatNotification
(
context
:
Context
,
pushMessage
:
PushMessage
,
smallIcon
:
Int
,
data
:
Bundle
):
Notification
{
private
fun
createCompatNotification
(
context
:
Context
,
pushMessage
:
PushMessage
,
smallIcon
:
Int
,
data
:
Bundle
):
Notification
{
...
@@ -176,22 +184,27 @@ object PushManager {
...
@@ -176,22 +184,27 @@ object PushManager {
val
deleteIntent
=
getDismissIntent
(
context
,
id
)
val
deleteIntent
=
getDismissIntent
(
context
,
id
)
val
channel
=
NotificationChannel
(
notificationId
,
sender
.
username
,
NotificationManager
.
IMPORTANCE_HIGH
)
val
channel
=
NotificationChannel
(
notificationId
,
sender
.
username
,
NotificationManager
.
IMPORTANCE_HIGH
)
val
notification
=
Notification
.
Builder
(
context
,
pushMessage
.
rid
)
val
notification
Builder
=
Notification
.
Builder
(
context
,
pushMessage
.
rid
)
.
setAutoCancel
(
true
)
.
setAutoCancel
(
true
)
.
setShowWhen
(
true
)
.
setShowWhen
(
true
)
.
setWhen
(
createdAt
)
.
setWhen
(
createdAt
)
.
setContentTitle
(
title
.
fromHtml
())
.
setContentTitle
(
title
.
fromHtml
())
.
setContentText
(
message
.
fromHtml
())
.
setContentText
(
message
.
fromHtml
())
.
setNumber
(
count
.
toInt
())
.
setNumber
(
count
.
toInt
())
.
setGroup
(
host
)
.
setSmallIcon
(
smallIcon
)
.
setSmallIcon
(
smallIcon
)
.
setDeleteIntent
(
deleteIntent
)
.
setDeleteIntent
(
deleteIntent
)
.
setContentIntent
(
contentIntent
)
.
setContentIntent
(
contentIntent
)
.
build
()
val
subText
=
RocketChatCache
(
context
).
getHostSiteName
(
pushMessage
.
host
)
if
(
subText
.
isNotEmpty
())
{
notificationBuilder
.
setSubText
(
subText
)
}
channel
.
enableLights
(
true
)
channel
.
enableLights
(
true
)
channel
.
enableVibration
(
true
)
channel
.
enableVibration
(
true
)
notificationManager
.
createNotificationChannel
(
channel
)
notificationManager
.
createNotificationChannel
(
channel
)
return
notification
return
notification
Builder
.
build
()
}
}
}
}
...
@@ -224,7 +237,7 @@ object PushManager {
...
@@ -224,7 +237,7 @@ object PushManager {
return
PendingIntent
.
getActivity
(
context
,
randomizer
.
nextInt
(),
notificationIntent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
)
return
PendingIntent
.
getActivity
(
context
,
randomizer
.
nextInt
(),
notificationIntent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
)
}
}
data class
PushMessage
(
val
title
:
String
,
private
data class
PushMessage
(
val
title
:
String
,
val
message
:
String
,
val
message
:
String
,
val
image
:
String
?,
val
image
:
String
?,
val
ejson
:
String
,
val
ejson
:
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