Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
InstiApp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
RAHUL SHARMA
InstiApp
Commits
3df7ad16
Commit
3df7ad16
authored
Feb 02, 2019
by
Varun Patil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make delete call to server when notification is swiped away
parent
8e8faaff
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
1 deletion
+52
-1
app/src/main/AndroidManifest.xml
app/src/main/AndroidManifest.xml
+6
-0
app/src/main/java/app/insti/Constants.java
app/src/main/java/app/insti/Constants.java
+1
-0
app/src/main/java/app/insti/InstiAppFirebaseMessagingService.java
...main/java/app/insti/InstiAppFirebaseMessagingService.java
+10
-1
app/src/main/java/app/insti/NotificationBroadcastReceiver.java
...rc/main/java/app/insti/NotificationBroadcastReceiver.java
+32
-0
app/src/main/java/app/insti/api/RetrofitInterface.java
app/src/main/java/app/insti/api/RetrofitInterface.java
+3
-0
No files found.
app/src/main/AndroidManifest.xml
View file @
3df7ad16
...
...
@@ -99,6 +99,12 @@
</intent-filter>
</service>
<receiver
android:name=
".NotificationBroadcastReceiver"
>
<intent-filter>
<action
android:name=
"notification_cancelled"
/>
</intent-filter>
</receiver>
<meta-data
android:name=
"com.google.firebase.messaging.default_notification_channel_id"
android:value=
"@string/default_notification_channel_id"
/>
...
...
app/src/main/java/app/insti/Constants.java
View file @
3df7ad16
...
...
@@ -45,6 +45,7 @@ public class Constants {
public
static
final
String
FCM_BUNDLE_IMAGE
=
"image_url"
;
public
static
final
String
FCM_BUNDLE_LARGE_ICON
=
"large_icon"
;
public
static
final
String
FCM_BUNDLE_LARGE_CONTENT
=
"large_content"
;
public
static
final
String
NOTIF_CANCELLED
=
"notif_cancelled"
;
public
static
final
String
FCM_BUNDLE_ACTION_STARTING
=
"starting"
;
...
...
app/src/main/java/app/insti/InstiAppFirebaseMessagingService.java
View file @
3df7ad16
...
...
@@ -53,6 +53,14 @@ public class InstiAppFirebaseMessagingService extends FirebaseMessagingService {
return
PendingIntent
.
getActivity
(
this
,
notificationId
,
intent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
}
/** In case the notification is dismissed */
protected
PendingIntent
getDeleteIntent
(
RemoteMessage
remoteMessage
)
{
Intent
intent
=
new
Intent
(
getApplicationContext
(),
NotificationBroadcastReceiver
.
class
);
intent
.
setAction
(
Constants
.
NOTIF_CANCELLED
);
intent
.
putExtra
(
Constants
.
FCM_BUNDLE_NOTIFICATION_ID
,
remoteMessage
.
getData
().
get
(
Constants
.
FCM_BUNDLE_NOTIFICATION_ID
));
return
PendingIntent
.
getBroadcast
(
getApplicationContext
(),
0
,
intent
,
PendingIntent
.
FLAG_CANCEL_CURRENT
);
}
@Override
public
void
onMessageReceived
(
RemoteMessage
remoteMessage
)
{
channel
=
getResources
().
getString
(
R
.
string
.
default_notification_channel_id
);
...
...
@@ -84,7 +92,8 @@ public class InstiAppFirebaseMessagingService extends FirebaseMessagingService {
NotificationCompat
.
Builder
builder
=
standardNotificationBuilder
()
.
setContentTitle
(
remoteMessage
.
getData
().
get
(
Constants
.
FCM_BUNDLE_TITLE
))
.
setContentText
(
message
)
.
setContentIntent
(
getNotificationIntent
(
remoteMessage
,
notification_id
));
.
setContentIntent
(
getNotificationIntent
(
remoteMessage
,
notification_id
))
.
setDeleteIntent
(
getDeleteIntent
(
remoteMessage
));
/* Check for article */
String
largeContent
=
remoteMessage
.
getData
().
get
(
Constants
.
FCM_BUNDLE_LARGE_CONTENT
);
...
...
app/src/main/java/app/insti/NotificationBroadcastReceiver.java
0 → 100644
View file @
3df7ad16
package
app.insti
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
import
app.insti.api.EmptyCallback
;
import
app.insti.api.RetrofitInterface
;
import
app.insti.api.ServiceGenerator
;
public
class
NotificationBroadcastReceiver
extends
BroadcastReceiver
{
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
if
(
intent
.
getAction
().
equals
(
Constants
.
NOTIF_CANCELLED
))
{
// Get the notification id
String
id
=
intent
.
getExtras
().
getString
(
Constants
.
FCM_BUNDLE_NOTIFICATION_ID
);
if
(
id
==
null
||
id
.
equals
(
""
))
return
;
// Get retrofit and session id
ServiceGenerator
serviceGenerator
=
new
ServiceGenerator
(
context
);
RetrofitInterface
retrofitInterface
=
serviceGenerator
.
getRetrofitInterface
();
SessionManager
session
=
new
SessionManager
(
context
);
if
(
session
.
isLoggedIn
())
{
Utils
.
setSessionId
(
session
.
getSessionID
());
}
// Mark as read
retrofitInterface
.
markNotificationDeleted
(
Utils
.
getSessionIDHeader
(),
id
).
enqueue
(
new
EmptyCallback
<
Void
>());
}
}
}
app/src/main/java/app/insti/api/RetrofitInterface.java
View file @
3df7ad16
...
...
@@ -112,6 +112,9 @@ public interface RetrofitInterface {
@GET
(
"notifications/read/{notificationID}"
)
Call
<
Void
>
markNotificationRead
(
@Header
(
"Cookie"
)
String
sessionID
,
@Path
(
"notificationID"
)
String
notificationID
);
@GET
(
"notifications/read/{notificationID}?delete=1"
)
Call
<
Void
>
markNotificationDeleted
(
@Header
(
"Cookie"
)
String
sessionID
,
@Path
(
"notificationID"
)
String
notificationID
);
@GET
(
"logout"
)
Call
<
Void
>
logout
(
@Header
(
"Cookie"
)
String
sessionID
);
...
...
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