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
8e0983e2
Commit
8e0983e2
authored
Dec 13, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reactive notification base
parent
21d1e564
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
111 additions
and
1 deletion
+111
-1
RocketChatWebSocketThread.java
...hat/rocket/android/service/RocketChatWebSocketThread.java
+5
-1
ReactiveNotificationCancelManager.java
...d/service/observer/ReactiveNotificationCancelManager.java
+38
-0
ReactiveNotificationManager.java
...android/service/observer/ReactiveNotificationManager.java
+68
-0
No files found.
app/src/main/java/chat/rocket/android/service/RocketChatWebSocketThread.java
View file @
8e0983e2
...
...
@@ -22,6 +22,8 @@ import chat.rocket.android.service.observer.GetUsersOfRoomsProcedureObserver;
import
chat.rocket.android.service.observer.LoadMessageProcedureObserver
;
import
chat.rocket.android.service.observer.MethodCallObserver
;
import
chat.rocket.android.service.observer.NewMessageObserver
;
import
chat.rocket.android.service.observer.ReactiveNotificationCancelManager
;
import
chat.rocket.android.service.observer.ReactiveNotificationManager
;
import
chat.rocket.android.service.observer.SessionObserver
;
import
chat.rocket.android.service.observer.TokenLoginObserver
;
import
chat.rocket.android_ddp.DDPClientCallback
;
...
...
@@ -45,7 +47,9 @@ public class RocketChatWebSocketThread extends HandlerThread {
LoadMessageProcedureObserver
.
class
,
GetUsersOfRoomsProcedureObserver
.
class
,
NewMessageObserver
.
class
,
CurrentUserObserver
.
class
CurrentUserObserver
.
class
,
ReactiveNotificationManager
.
class
,
ReactiveNotificationCancelManager
.
class
};
private
final
Context
appContext
;
private
final
String
serverConfigId
;
...
...
app/src/main/java/chat/rocket/android/service/observer/ReactiveNotificationCancelManager.java
0 → 100644
View file @
8e0983e2
package
chat
.
rocket
.
android
.
service
.
observer
;
import
android.content.Context
;
import
android.support.v4.app.NotificationManagerCompat
;
import
chat.rocket.android.api.DDPClientWraper
;
import
chat.rocket.android.model.ddp.RoomSubscription
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
hugo.weaving.DebugLog
;
import
io.realm.Realm
;
import
io.realm.RealmResults
;
import
java.util.List
;
/**
* observing room subscriptions with unread>0.
*/
public
class
ReactiveNotificationCancelManager
extends
AbstractModelObserver
<
RoomSubscription
>
{
public
ReactiveNotificationCancelManager
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
}
@Override
public
RealmResults
<
RoomSubscription
>
queryItems
(
Realm
realm
)
{
return
realm
.
where
(
RoomSubscription
.
class
)
.
equalTo
(
"open"
,
true
)
.
equalTo
(
"unread"
,
0
)
.
findAll
();
}
@DebugLog
@Override
public
void
onUpdateResults
(
List
<
RoomSubscription
>
roomSubscriptions
)
{
// TODO implement!
for
(
RoomSubscription
roomSubscription
:
roomSubscriptions
)
{
final
String
roomId
=
roomSubscription
.
getRid
();
NotificationManagerCompat
.
from
(
context
).
cancel
(
roomId
.
hashCode
());
}
}
}
app/src/main/java/chat/rocket/android/service/observer/ReactiveNotificationManager.java
0 → 100644
View file @
8e0983e2
package
chat
.
rocket
.
android
.
service
.
observer
;
import
android.app.Notification
;
import
android.app.PendingIntent
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.app.NotificationManagerCompat
;
import
android.support.v4.content.ContextCompat
;
import
chat.rocket.android.R
;
import
chat.rocket.android.activity.MainActivity
;
import
chat.rocket.android.api.DDPClientWraper
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.model.ddp.RoomSubscription
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmStore
;
import
hugo.weaving.DebugLog
;
import
io.realm.Realm
;
import
io.realm.RealmResults
;
import
java.util.List
;
/**
* observing room subscriptions with unread>0.
*/
public
class
ReactiveNotificationManager
extends
AbstractModelObserver
<
RoomSubscription
>
{
public
ReactiveNotificationManager
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
}
@Override
public
RealmResults
<
RoomSubscription
>
queryItems
(
Realm
realm
)
{
return
realm
.
where
(
RoomSubscription
.
class
)
.
equalTo
(
"open"
,
true
)
.
greaterThan
(
"unread"
,
0
)
.
findAll
();
}
@DebugLog
@Override
public
void
onUpdateResults
(
List
<
RoomSubscription
>
roomSubscriptions
)
{
// TODO implement!
for
(
RoomSubscription
roomSubscription
:
roomSubscriptions
)
{
final
String
roomId
=
roomSubscription
.
getRid
();
Intent
intent
=
new
Intent
(
context
,
MainActivity
.
class
);
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_REORDER_TO_FRONT
|
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
);
ServerConfig
config
=
RealmStore
.
getDefault
().
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"hostname"
,
hostname
).
findFirst
());
if
(
config
!=
null
)
{
intent
.
putExtra
(
"serverConfigId"
,
config
.
getServerConfigId
());
intent
.
putExtra
(
"roomId"
,
roomId
);
}
PendingIntent
pendingIntent
=
PendingIntent
.
getActivity
(
context
.
getApplicationContext
(),
(
int
)
(
System
.
currentTimeMillis
()
%
Integer
.
MAX_VALUE
),
intent
,
PendingIntent
.
FLAG_ONE_SHOT
);
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
context
)
.
setContentTitle
(
roomSubscription
.
getName
())
.
setColor
(
ContextCompat
.
getColor
(
context
,
R
.
color
.
colorPrimary
))
.
setSmallIcon
(
R
.
drawable
.
rocket_chat_notification_24dp
)
.
setContentIntent
(
pendingIntent
);
Notification
notification
=
builder
.
build
();
NotificationManagerCompat
.
from
(
context
).
notify
(
roomId
.
hashCode
(),
notification
);
}
}
}
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