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
0c274573
Commit
0c274573
authored
Dec 13, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update lastSeenAt on Notification dismissal.
parent
500b0e78
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
5 deletions
+80
-5
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+2
-0
NotificationDismissalCallbackService.java
...ce/notification/NotificationDismissalCallbackService.java
+42
-0
NotificationItemObserver.java
...et/android/service/observer/NotificationItemObserver.java
+23
-4
RealmHelper.java
...in/java/chat/rocket/android/realm_helper/RealmHelper.java
+13
-1
No files found.
app/src/main/AndroidManifest.xml
View file @
0c274573
...
...
@@ -31,6 +31,8 @@
android:windowSoftInputMode=
"adjustResize"
/>
<service
android:name=
".service.RocketChatService"
/>
<service
android:name=
".service.notification.NotificationDismissalCallbackService"
/>
</application>
</manifest>
app/src/main/java/chat/rocket/android/service/notification/NotificationDismissalCallbackService.java
0 → 100644
View file @
0c274573
package
chat
.
rocket
.
android
.
service
.
notification
;
import
android.app.IntentService
;
import
android.content.Intent
;
import
chat.rocket.android.model.internal.NotificationItem
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmStore
;
/**
* triggered when notification is dismissed.
*/
public
class
NotificationDismissalCallbackService
extends
IntentService
{
public
NotificationDismissalCallbackService
()
{
super
(
NotificationDismissalCallbackService
.
class
.
getSimpleName
());
}
@Override
protected
void
onHandleIntent
(
Intent
intent
)
{
if
(!
intent
.
hasExtra
(
"serverConfigId"
)
||
!
intent
.
hasExtra
(
"roomId"
))
{
return
;
}
String
serverConfigId
=
intent
.
getStringExtra
(
"serverConfigId"
);
String
roomId
=
intent
.
getStringExtra
(
"roomId"
);
RealmHelper
realmHelper
=
RealmStore
.
get
(
serverConfigId
);
if
(
realmHelper
==
null
)
{
return
;
}
realmHelper
.
executeTransaction
(
realm
->
{
NotificationItem
item
=
realm
.
where
(
NotificationItem
.
class
).
equalTo
(
"roomId"
,
roomId
).
findFirst
();
if
(
item
!=
null
)
{
long
currentTime
=
System
.
currentTimeMillis
();
if
(
item
.
getLastSeenAt
()
<=
currentTime
)
{
item
.
setLastSeenAt
(
currentTime
);
}
}
return
null
;
});
}
}
app/src/main/java/chat/rocket/android/service/observer/NotificationItemObserver.java
View file @
0c274573
...
...
@@ -20,6 +20,7 @@ import chat.rocket.android.model.ServerConfig;
import
chat.rocket.android.model.internal.NotificationItem
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmStore
;
import
chat.rocket.android.service.notification.NotificationDismissalCallbackService
;
import
io.realm.Realm
;
import
io.realm.RealmResults
;
import
java.util.List
;
...
...
@@ -83,8 +84,7 @@ public class NotificationItemObserver extends AbstractModelObserver<Notification
});
}
private
Notification
generateNotification
(
String
roomId
,
String
title
,
@NonNull
String
description
,
int
unreadCount
,
@Nullable
Bitmap
icon
)
{
private
PendingIntent
getContentIntent
(
String
roomId
)
{
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
->
...
...
@@ -94,9 +94,27 @@ public class NotificationItemObserver extends AbstractModelObserver<Notification
intent
.
putExtra
(
"roomId"
,
roomId
);
}
PendingIntent
pendingIntent
=
PendingIntent
.
getActivity
(
context
.
getApplicationContext
(),
return
PendingIntent
.
getActivity
(
context
.
getApplicationContext
(),
(
int
)
(
System
.
currentTimeMillis
()
%
Integer
.
MAX_VALUE
),
intent
,
PendingIntent
.
FLAG_ONE_SHOT
);
}
private
PendingIntent
getDeleteIntent
(
String
roomId
)
{
Intent
intent
=
new
Intent
(
context
,
NotificationDismissalCallbackService
.
class
);
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
);
}
return
PendingIntent
.
getService
(
context
.
getApplicationContext
(),
(
int
)
(
System
.
currentTimeMillis
()
%
Integer
.
MAX_VALUE
),
intent
,
PendingIntent
.
FLAG_ONE_SHOT
);
}
private
Notification
generateNotification
(
String
roomId
,
String
title
,
@NonNull
String
description
,
int
unreadCount
,
@Nullable
Bitmap
icon
)
{
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
context
)
.
setContentTitle
(
title
)
...
...
@@ -104,7 +122,8 @@ public class NotificationItemObserver extends AbstractModelObserver<Notification
.
setNumber
(
unreadCount
)
.
setColor
(
ContextCompat
.
getColor
(
context
,
R
.
color
.
colorPrimary
))
.
setSmallIcon
(
R
.
drawable
.
rocket_chat_notification_24dp
)
.
setContentIntent
(
pendingIntent
);
.
setContentIntent
(
getContentIntent
(
roomId
))
.
setDeleteIntent
(
getDeleteIntent
(
roomId
));
if
(
icon
!=
null
)
{
builder
.
setLargeIcon
(
icon
);
...
...
realm-helpers/src/main/java/chat/rocket/android/realm_helper/RealmHelper.java
View file @
0c274573
...
...
@@ -76,8 +76,20 @@ public class RealmHelper {
}
}
private
boolean
shouldUseSync
()
{
// ref: realm-java:realm/realm-library/src/main/java/io/realm/AndroidNotifier.java
// #isAutoRefreshAvailable()
if
(
Looper
.
myLooper
()
==
null
)
{
return
true
;
}
String
threadName
=
Thread
.
currentThread
().
getName
();
return
threadName
!=
null
&&
threadName
.
startsWith
(
"IntentService["
);
}
public
Task
<
Void
>
executeTransaction
(
final
RealmHelper
.
Transaction
transaction
)
{
return
Looper
.
myLooper
()
==
null
?
executeTransactionSync
(
transaction
)
return
shouldUseSync
()
?
executeTransactionSync
(
transaction
)
:
executeTransactionAsync
(
transaction
);
}
...
...
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