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
...
@@ -40,7 +40,7 @@ import java.util.concurrent.atomic.AtomicInteger
import
kotlin.collections.HashMap
import
kotlin.collections.HashMap
typealias
TupleRoomUser
=
Pair
<
Room
,
User
>
typealias
TupleRoomUser
=
Pair
<
Room
,
User
>
typealias
Tuple
IntAtomicI
nt
=
Pair
<
Int
,
AtomicInteger
>
typealias
Tuple
GroupIdMessageCou
nt
=
Pair
<
Int
,
AtomicInteger
>
object
PushManager
{
object
PushManager
{
const
val
REPLY_LABEL
=
"REPLY"
const
val
REPLY_LABEL
=
"REPLY"
...
@@ -50,7 +50,7 @@ object PushManager {
...
@@ -50,7 +50,7 @@ object PushManager {
private
val
messageStack
=
SparseArray
<
ArrayList
<
CharSequence
>>()
private
val
messageStack
=
SparseArray
<
ArrayList
<
CharSequence
>>()
// Notifications received from the same server are grouped in a single bundled notification.
// Notifications received from the same server are grouped in a single bundled notification.
// This map associates a host to a group id.
// 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
()
private
val
randomizer
=
Random
()
/**
/**
...
@@ -98,14 +98,14 @@ object PushManager {
...
@@ -98,14 +98,14 @@ object PushManager {
val
notification
:
Notification
val
notification
:
Notification
if
(
isAndroidVersionAtLeast
(
Build
.
VERSION_CODES
.
O
))
{
if
(
isAndroidVersionAtLeast
(
Build
.
VERSION_CODES
.
O
))
{
notification
=
createNotificationForOreoAndAbove
(
context
,
pushMessage
)
notification
=
createNotificationForOreoAndAbove
(
context
,
pushMessage
)
if
(
groupTuple
!=
null
)
{
groupTuple
?.
let
{
notificationManager
.
notify
(
groupTuple
.
first
,
groupNotification
)
notificationManager
.
notify
(
groupTuple
.
first
,
groupNotification
)
groupTuple
.
second
.
incrementAndGet
()
groupTuple
.
second
.
incrementAndGet
()
}
}
notificationManager
.
notify
(
notId
,
notification
)
notificationManager
.
notify
(
notId
,
notification
)
}
else
{
}
else
{
notification
=
createCompatNotification
(
context
,
pushMessage
)
notification
=
createCompatNotification
(
context
,
pushMessage
)
if
(
groupTuple
!=
null
)
{
groupTuple
?.
let
{
NotificationManagerCompat
.
from
(
context
).
notify
(
groupTuple
.
first
,
groupNotification
)
NotificationManagerCompat
.
from
(
context
).
notify
(
groupTuple
.
first
,
groupNotification
)
groupTuple
.
second
.
incrementAndGet
()
groupTuple
.
second
.
incrementAndGet
()
}
}
...
@@ -117,8 +117,8 @@ object PushManager {
...
@@ -117,8 +117,8 @@ object PushManager {
private
fun
bundleNotificationsToHost
(
host
:
String
)
{
private
fun
bundleNotificationsToHost
(
host
:
String
)
{
val
size
=
groupMap
.
size
val
size
=
groupMap
.
size
if
(
groupMap
.
get
(
host
)
==
null
)
{
groupMap
.
get
(
host
)
?.
let
{
groupMap
.
put
(
host
,
Tuple
IntAtomicI
nt
(
size
+
1
,
AtomicInteger
(
0
)))
groupMap
.
put
(
host
,
Tuple
GroupIdMessageCou
nt
(
size
+
1
,
AtomicInteger
(
0
)))
}
}
}
}
...
@@ -154,8 +154,8 @@ object PushManager {
...
@@ -154,8 +154,8 @@ object PushManager {
.
setSummaryText
(
summary
)
.
setSummaryText
(
summary
)
notGroupBuilder
.
setStyle
(
inbox
)
notGroupBuilder
.
setStyle
(
inbox
)
}
else
{
}
else
{
val
bigText
=
NotificationCompat
.
BigTextStyle
()
val
bigText
=
NotificationCompat
.
BigTextStyle
()
.
bigText
(
pushMessage
.
message
.
fromHtml
())
.
bigText
(
pushMessage
.
message
.
fromHtml
())
.
setBigContentTitle
(
pushMessage
.
title
.
fromHtml
())
.
setBigContentTitle
(
pushMessage
.
title
.
fromHtml
())
...
@@ -308,7 +308,7 @@ object PushManager {
...
@@ -308,7 +308,7 @@ object PushManager {
}
}
// CharSequence extensions
// CharSequence extensions
fun
CharSequence
.
fromHtml
():
Spanned
{
private
fun
CharSequence
.
fromHtml
():
Spanned
{
return
Html
.
fromHtml
(
this
as
String
)
return
Html
.
fromHtml
(
this
as
String
)
}
}
...
@@ -333,13 +333,14 @@ object PushManager {
...
@@ -333,13 +333,14 @@ object PushManager {
}
}
@RequiresApi
(
Build
.
VERSION_CODES
.
O
)
@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
res
=
ctx
.
resources
val
smallIcon
=
res
.
getIdentifier
(
val
smallIcon
=
res
.
getIdentifier
(
"rocket_chat_notification"
,
"drawable"
,
ctx
.
packageName
)
"rocket_chat_notification"
,
"drawable"
,
ctx
.
packageName
)
with
(
this
,
{
with
(
this
,
{
setAutoCancel
(
true
)
setAutoCancel
(
true
)
setShowWhen
(
true
)
setShowWhen
(
true
)
setColor
(
res
.
getColor
(
R
.
color
.
colorRed400
,
ctx
.
theme
))
setDefaults
(
Notification
.
DEFAULT_ALL
)
setDefaults
(
Notification
.
DEFAULT_ALL
)
setSmallIcon
(
smallIcon
)
setSmallIcon
(
smallIcon
)
})
})
...
@@ -366,7 +367,7 @@ object PushManager {
...
@@ -366,7 +367,7 @@ object PushManager {
return
this
return
this
}
}
fun
NotificationCompat
.
Builder
.
setMessageNotification
():
NotificationCompat
.
Builder
{
private
fun
NotificationCompat
.
Builder
.
setMessageNotification
():
NotificationCompat
.
Builder
{
val
ctx
=
this
.
mContext
val
ctx
=
this
.
mContext
val
res
=
ctx
.
resources
val
res
=
ctx
.
resources
val
smallIcon
=
res
.
getIdentifier
(
val
smallIcon
=
res
.
getIdentifier
(
...
@@ -374,6 +375,7 @@ object PushManager {
...
@@ -374,6 +375,7 @@ object PushManager {
with
(
this
,
{
with
(
this
,
{
setAutoCancel
(
true
)
setAutoCancel
(
true
)
setShowWhen
(
true
)
setShowWhen
(
true
)
setColor
(
ctx
.
resources
.
getColor
(
R
.
color
.
colorRed400
))
setDefaults
(
Notification
.
DEFAULT_ALL
)
setDefaults
(
Notification
.
DEFAULT_ALL
)
setSmallIcon
(
smallIcon
)
setSmallIcon
(
smallIcon
)
})
})
...
@@ -419,6 +421,9 @@ object PushManager {
...
@@ -419,6 +421,9 @@ object PushManager {
}
}
}
}
/**
* BroadcastReceiver for dismissed notifications.
*/
class
DeleteReceiver
:
BroadcastReceiver
()
{
class
DeleteReceiver
:
BroadcastReceiver
()
{
override
fun
onReceive
(
context
:
Context
?,
intent
:
Intent
?)
{
override
fun
onReceive
(
context
:
Context
?,
intent
:
Intent
?)
{
val
notificationId
=
intent
?.
extras
?.
getInt
(
"notId"
)
val
notificationId
=
intent
?.
extras
?.
getInt
(
"notId"
)
...
@@ -428,7 +433,11 @@ object PushManager {
...
@@ -428,7 +433,11 @@ object PushManager {
}
}
}
}
// EXPERIMENTAL
/**
* *EXPERIMENTAL*
*
* BroadcastReceiver for notifications' replies.
*/
class
ReplyReceiver
:
BroadcastReceiver
()
{
class
ReplyReceiver
:
BroadcastReceiver
()
{
override
fun
onReceive
(
context
:
Context
?,
intent
:
Intent
?)
{
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