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
da3d16cd
Commit
da3d16cd
authored
Oct 20, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More refactoring
parent
855cc652
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
12 deletions
+21
-12
PushManager.kt
app/src/main/java/chat/rocket/android/push/PushManager.kt
+21
-12
No files found.
app/src/main/java/chat/rocket/android/push/PushManager.kt
View file @
da3d16cd
...
...
@@ -40,7 +40,7 @@ import java.util.concurrent.atomic.AtomicInteger
import
kotlin.collections.HashMap
typealias
TupleRoomUser
=
Pair
<
Room
,
User
>
typealias
Tuple
IntAtomicI
nt
=
Pair
<
Int
,
AtomicInteger
>
typealias
Tuple
GroupIdMessageCou
nt
=
Pair
<
Int
,
AtomicInteger
>
object
PushManager
{
const
val
REPLY_LABEL
=
"REPLY"
...
...
@@ -50,7 +50,7 @@ object PushManager {
private
val
messageStack
=
SparseArray
<
ArrayList
<
CharSequence
>>()
// Notifications received from the same server are grouped in a single bundled notification.
// This map associates a host to a group id.
private
val
groupMap
=
HashMap
<
String
,
Tuple
IntAtomicI
nt
>()
private
val
groupMap
=
HashMap
<
String
,
Tuple
GroupIdMessageCou
nt
>()
private
val
randomizer
=
Random
()
/**
...
...
@@ -98,14 +98,14 @@ object PushManager {
val
notification
:
Notification
if
(
isAndroidVersionAtLeast
(
Build
.
VERSION_CODES
.
O
))
{
notification
=
createNotificationForOreoAndAbove
(
context
,
pushMessage
)
if
(
groupTuple
!=
null
)
{
groupTuple
?.
let
{
notificationManager
.
notify
(
groupTuple
.
first
,
groupNotification
)
groupTuple
.
second
.
incrementAndGet
()
}
notificationManager
.
notify
(
notId
,
notification
)
}
else
{
notification
=
createCompatNotification
(
context
,
pushMessage
)
if
(
groupTuple
!=
null
)
{
groupTuple
?.
let
{
NotificationManagerCompat
.
from
(
context
).
notify
(
groupTuple
.
first
,
groupNotification
)
groupTuple
.
second
.
incrementAndGet
()
}
...
...
@@ -117,8 +117,8 @@ object PushManager {
private
fun
bundleNotificationsToHost
(
host
:
String
)
{
val
size
=
groupMap
.
size
if
(
groupMap
.
get
(
host
)
==
null
)
{
groupMap
.
put
(
host
,
Tuple
IntAtomicI
nt
(
size
+
1
,
AtomicInteger
(
0
)))
groupMap
.
get
(
host
)
?.
let
{
groupMap
.
put
(
host
,
Tuple
GroupIdMessageCou
nt
(
size
+
1
,
AtomicInteger
(
0
)))
}
}
...
...
@@ -154,8 +154,8 @@ object PushManager {
.
setSummaryText
(
summary
)
notGroupBuilder
.
setStyle
(
inbox
)
}
else
{
val
bigText
=
NotificationCompat
.
BigTextStyle
()
}
else
{
val
bigText
=
NotificationCompat
.
BigTextStyle
()
.
bigText
(
pushMessage
.
message
.
fromHtml
())
.
setBigContentTitle
(
pushMessage
.
title
.
fromHtml
())
...
...
@@ -308,7 +308,7 @@ object PushManager {
}
// CharSequence extensions
fun
CharSequence
.
fromHtml
():
Spanned
{
private
fun
CharSequence
.
fromHtml
():
Spanned
{
return
Html
.
fromHtml
(
this
as
String
)
}
...
...
@@ -333,13 +333,14 @@ object PushManager {
}
@RequiresApi
(
Build
.
VERSION_CODES
.
O
)
fun
Notification
.
Builder
.
setMessageNotification
(
ctx
:
Context
):
Notification
.
Builder
{
private
fun
Notification
.
Builder
.
setMessageNotification
(
ctx
:
Context
):
Notification
.
Builder
{
val
res
=
ctx
.
resources
val
smallIcon
=
res
.
getIdentifier
(
"rocket_chat_notification"
,
"drawable"
,
ctx
.
packageName
)
with
(
this
,
{
setAutoCancel
(
true
)
setShowWhen
(
true
)
setColor
(
res
.
getColor
(
R
.
color
.
colorRed400
,
ctx
.
theme
))
setDefaults
(
Notification
.
DEFAULT_ALL
)
setSmallIcon
(
smallIcon
)
})
...
...
@@ -366,7 +367,7 @@ object PushManager {
return
this
}
fun
NotificationCompat
.
Builder
.
setMessageNotification
():
NotificationCompat
.
Builder
{
private
fun
NotificationCompat
.
Builder
.
setMessageNotification
():
NotificationCompat
.
Builder
{
val
ctx
=
this
.
mContext
val
res
=
ctx
.
resources
val
smallIcon
=
res
.
getIdentifier
(
...
...
@@ -374,6 +375,7 @@ object PushManager {
with
(
this
,
{
setAutoCancel
(
true
)
setShowWhen
(
true
)
setColor
(
ctx
.
resources
.
getColor
(
R
.
color
.
colorRed400
))
setDefaults
(
Notification
.
DEFAULT_ALL
)
setSmallIcon
(
smallIcon
)
})
...
...
@@ -419,6 +421,9 @@ object PushManager {
}
}
/**
* BroadcastReceiver for dismissed notifications.
*/
class
DeleteReceiver
:
BroadcastReceiver
()
{
override
fun
onReceive
(
context
:
Context
?,
intent
:
Intent
?)
{
val
notificationId
=
intent
?.
extras
?.
getInt
(
"notId"
)
...
...
@@ -428,7 +433,11 @@ object PushManager {
}
}
// EXPERIMENTAL
/**
* *EXPERIMENTAL*
*
* BroadcastReceiver for notifications' replies.
*/
class
ReplyReceiver
:
BroadcastReceiver
()
{
override
fun
onReceive
(
context
:
Context
?,
intent
:
Intent
?)
{
...
...
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