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
6c62d59b
Commit
6c62d59b
authored
Oct 24, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Build and show notifications on android N the same way as of O
parent
941cfa58
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
24 deletions
+31
-24
PushManager.kt
app/src/main/java/chat/rocket/android/push/PushManager.kt
+31
-24
No files found.
app/src/main/java/chat/rocket/android/push/PushManager.kt
View file @
6c62d59b
...
@@ -130,9 +130,9 @@ object PushManager {
...
@@ -130,9 +130,9 @@ object PushManager {
}
else
{
}
else
{
notIdListForHostname
.
add
(
0
,
lastPushMessage
)
notIdListForHostname
.
add
(
0
,
lastPushMessage
)
}
}
if
(
isAndroidVersionAtLeast
(
Build
.
VERSION_CODES
.
O
))
{
if
(
isAndroidVersionAtLeast
(
Build
.
VERSION_CODES
.
N
))
{
val
notification
=
createSingleNotificationFor
Oreo
(
context
,
lastPushMessage
)
val
notification
=
createSingleNotificationFor
NougatAndAbove
(
context
,
lastPushMessage
)
val
groupNotification
=
createGroupNotificationFor
Oreo
(
context
,
lastPushMessage
)
val
groupNotification
=
createGroupNotificationFor
NougatAndAbove
(
context
,
lastPushMessage
)
manager
.
notify
(
notId
,
notification
)
manager
.
notify
(
notId
,
notification
)
manager
.
notify
(
groupTuple
.
first
,
groupNotification
)
manager
.
notify
(
groupTuple
.
first
,
groupNotification
)
}
else
{
}
else
{
...
@@ -209,21 +209,16 @@ object PushManager {
...
@@ -209,21 +209,16 @@ object PushManager {
}
}
}
}
@RequiresApi
(
Build
.
VERSION_CODES
.
O
)
@RequiresApi
(
Build
.
VERSION_CODES
.
N
)
private
fun
createGroupNotificationFor
Oreo
(
context
:
Context
,
lastPushMessage
:
PushMessage
):
Notification
{
private
fun
createGroupNotificationFor
NougatAndAbove
(
context
:
Context
,
lastPushMessage
:
PushMessage
):
Notification
{
with
(
lastPushMessage
)
{
with
(
lastPushMessage
)
{
val
manager
:
NotificationManager
=
val
manager
:
NotificationManager
=
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
val
id
=
notificationId
.
toInt
()
val
id
=
notificationId
.
toInt
()
val
contentIntent
=
getContentIntent
(
context
,
id
,
lastPushMessage
,
singleConversation
=
true
)
val
contentIntent
=
getContentIntent
(
context
,
id
,
lastPushMessage
,
singleConversation
=
true
)
val
deleteIntent
=
getDismissIntent
(
context
,
lastPushMessage
)
val
deleteIntent
=
getDismissIntent
(
context
,
lastPushMessage
)
val
groupChannel
=
NotificationChannel
(
host
,
host
,
NotificationManager
.
IMPORTANCE_HIGH
)
groupChannel
.
lockscreenVisibility
=
Notification
.
VISIBILITY_PUBLIC
val
builder
=
Notification
.
Builder
(
context
)
groupChannel
.
enableLights
(
true
)
groupChannel
.
enableVibration
(
true
)
groupChannel
.
setShowBadge
(
true
)
manager
.
createNotificationChannel
(
groupChannel
)
val
builder
=
Notification
.
Builder
(
context
,
host
)
.
setWhen
(
createdAt
)
.
setWhen
(
createdAt
)
.
setContentTitle
(
title
.
fromHtml
())
.
setContentTitle
(
title
.
fromHtml
())
.
setContentText
(
message
.
fromHtml
())
.
setContentText
(
message
.
fromHtml
())
...
@@ -233,6 +228,16 @@ object PushManager {
...
@@ -233,6 +228,16 @@ object PushManager {
.
setDeleteIntent
(
deleteIntent
)
.
setDeleteIntent
(
deleteIntent
)
.
setMessageNotification
(
context
)
.
setMessageNotification
(
context
)
if
(
isAndroidVersionAtLeast
(
Build
.
VERSION_CODES
.
O
))
{
builder
.
setChannelId
(
host
)
val
groupChannel
=
NotificationChannel
(
host
,
host
,
NotificationManager
.
IMPORTANCE_HIGH
)
groupChannel
.
lockscreenVisibility
=
Notification
.
VISIBILITY_PUBLIC
groupChannel
.
enableLights
(
false
)
groupChannel
.
enableVibration
(
true
)
groupChannel
.
setShowBadge
(
true
)
manager
.
createNotificationChannel
(
groupChannel
)
}
val
subText
=
RocketChatCache
(
context
).
getHostSiteName
(
host
)
val
subText
=
RocketChatCache
(
context
).
getHostSiteName
(
host
)
if
(
subText
.
isNotEmpty
())
{
if
(
subText
.
isNotEmpty
())
{
builder
.
setSubText
(
subText
)
builder
.
setSubText
(
subText
)
...
@@ -308,8 +313,8 @@ object PushManager {
...
@@ -308,8 +313,8 @@ object PushManager {
}
}
}
}
@RequiresApi
(
Build
.
VERSION_CODES
.
O
)
@RequiresApi
(
Build
.
VERSION_CODES
.
N
)
private
fun
createSingleNotificationFor
Oreo
(
context
:
Context
,
lastPushMessage
:
PushMessage
):
Notification
{
private
fun
createSingleNotificationFor
NougatAndAbove
(
context
:
Context
,
lastPushMessage
:
PushMessage
):
Notification
{
val
manager
:
NotificationManager
=
val
manager
:
NotificationManager
=
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
...
@@ -318,13 +323,7 @@ object PushManager {
...
@@ -318,13 +323,7 @@ object PushManager {
val
contentIntent
=
getContentIntent
(
context
,
id
,
lastPushMessage
)
val
contentIntent
=
getContentIntent
(
context
,
id
,
lastPushMessage
)
val
deleteIntent
=
getDismissIntent
(
context
,
lastPushMessage
)
val
deleteIntent
=
getDismissIntent
(
context
,
lastPushMessage
)
val
channel
=
NotificationChannel
(
host
,
host
,
NotificationManager
.
IMPORTANCE_HIGH
)
val
builder
=
Notification
.
Builder
(
context
)
channel
.
lockscreenVisibility
=
Notification
.
VISIBILITY_PUBLIC
channel
.
enableLights
(
true
)
channel
.
enableVibration
(
true
)
channel
.
setShowBadge
(
true
)
manager
.
createNotificationChannel
(
channel
)
val
builder
=
Notification
.
Builder
(
context
,
host
)
.
setWhen
(
createdAt
)
.
setWhen
(
createdAt
)
.
setContentTitle
(
title
.
fromHtml
())
.
setContentTitle
(
title
.
fromHtml
())
.
setContentText
(
message
.
fromHtml
())
.
setContentText
(
message
.
fromHtml
())
...
@@ -335,6 +334,16 @@ object PushManager {
...
@@ -335,6 +334,16 @@ object PushManager {
.
setMessageNotification
(
context
)
.
setMessageNotification
(
context
)
.
addReplyAction
(
context
,
lastPushMessage
)
.
addReplyAction
(
context
,
lastPushMessage
)
if
(
isAndroidVersionAtLeast
(
android
.
os
.
Build
.
VERSION_CODES
.
O
))
{
builder
.
setChannelId
(
host
)
val
channel
=
NotificationChannel
(
host
,
host
,
NotificationManager
.
IMPORTANCE_HIGH
)
channel
.
lockscreenVisibility
=
Notification
.
VISIBILITY_PUBLIC
channel
.
enableLights
(
false
)
channel
.
enableVibration
(
true
)
channel
.
setShowBadge
(
true
)
manager
.
createNotificationChannel
(
channel
)
}
val
subText
=
RocketChatCache
(
context
).
getHostSiteName
(
lastPushMessage
.
host
)
val
subText
=
RocketChatCache
(
context
).
getHostSiteName
(
lastPushMessage
.
host
)
if
(
subText
.
isNotEmpty
())
{
if
(
subText
.
isNotEmpty
())
{
builder
.
setSubText
(
subText
)
builder
.
setSubText
(
subText
)
...
@@ -344,8 +353,6 @@ object PushManager {
...
@@ -344,8 +353,6 @@ object PushManager {
val
pushMessageList
=
hostToPushMessageList
.
get
(
host
)
val
pushMessageList
=
hostToPushMessageList
.
get
(
host
)
pushMessageList
?.
let
{
pushMessageList
?.
let
{
val
messageCount
=
pushMessageList
.
size
val
inbox
=
Notification
.
InboxStyle
()
val
inbox
=
Notification
.
InboxStyle
()
val
userMessages
=
pushMessageList
.
filter
{
val
userMessages
=
pushMessageList
.
filter
{
...
@@ -419,7 +426,7 @@ object PushManager {
...
@@ -419,7 +426,7 @@ object PushManager {
return
this
return
this
}
}
@RequiresApi
(
Build
.
VERSION_CODES
.
O
)
@RequiresApi
(
Build
.
VERSION_CODES
.
N
)
private
fun
Notification
.
Builder
.
setMessageNotification
(
ctx
:
Context
):
Notification
.
Builder
{
private
fun
Notification
.
Builder
.
setMessageNotification
(
ctx
:
Context
):
Notification
.
Builder
{
val
res
=
ctx
.
resources
val
res
=
ctx
.
resources
val
smallIcon
=
res
.
getIdentifier
(
val
smallIcon
=
res
.
getIdentifier
(
...
...
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