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
5f535d4b
Commit
5f535d4b
authored
Feb 02, 2019
by
Varun Patil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add launcher badges for number of notifications
parent
21710850
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
49 additions
and
0 deletions
+49
-0
app/build.gradle
app/build.gradle
+2
-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
+12
-0
app/src/main/java/app/insti/NotificationBroadcastReceiver.java
...rc/main/java/app/insti/NotificationBroadcastReceiver.java
+5
-0
app/src/main/java/app/insti/activity/MainActivity.java
app/src/main/java/app/insti/activity/MainActivity.java
+5
-0
app/src/main/java/app/insti/adapter/NotificationsAdapter.java
...src/main/java/app/insti/adapter/NotificationsAdapter.java
+3
-0
app/src/main/java/app/insti/fragment/NotificationsFragment.java
...c/main/java/app/insti/fragment/NotificationsFragment.java
+5
-0
app/src/main/java/app/insti/notifications/NotificationId.java
...src/main/java/app/insti/notifications/NotificationId.java
+16
-0
No files found.
app/build.gradle
View file @
5f535d4b
...
...
@@ -35,6 +35,7 @@ ext {
flexboxVersion
=
'1.0.0'
sectionedRecyclerViewVersion
=
'1.2.0'
lottieVersion
=
'2.7.0'
shortcutBadgerVersion
=
'1.1.22@aar'
}
dependencies
{
...
...
@@ -59,5 +60,6 @@ dependencies {
implementation
"com.google.android:flexbox:${flexboxVersion}"
implementation
"io.github.luizgrp.sectionedrecyclerviewadapter:sectionedrecyclerviewadapter:${sectionedRecyclerViewVersion}"
implementation
"com.airbnb.android:lottie:$lottieVersion"
implementation
"me.leolin:ShortcutBadger:$shortcutBadgerVersion"
}
apply
plugin:
'com.google.gms.google-services'
app/src/main/java/app/insti/Constants.java
View file @
5f535d4b
...
...
@@ -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
FCM_BUNDLE_TOTAL_COUNT
=
"total_count"
;
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 @
5f535d4b
...
...
@@ -26,6 +26,7 @@ import java.util.Map;
import
app.insti.activity.MainActivity
;
import
app.insti.notifications.NotificationId
;
import
me.leolin.shortcutbadger.ShortcutBadger
;
public
class
InstiAppFirebaseMessagingService
extends
FirebaseMessagingService
{
String
channel
;
...
...
@@ -95,6 +96,17 @@ public class InstiAppFirebaseMessagingService extends FirebaseMessagingService {
.
setContentIntent
(
getNotificationIntent
(
remoteMessage
,
notification_id
))
.
setDeleteIntent
(
getDeleteIntent
(
remoteMessage
,
notification_id
));
/* Update the badge */
final
String
count
=
remoteMessage
.
getData
().
get
(
Constants
.
FCM_BUNDLE_TOTAL_COUNT
);
if
(
count
!=
null
)
{
try
{
int
total_count
=
Integer
.
parseInt
(
count
);
NotificationId
.
setCurrentCount
(
total_count
);
ShortcutBadger
.
applyCount
(
getApplicationContext
(),
total_count
);
}
catch
(
NumberFormatException
ignored
)
{}
}
/* Check for article */
String
largeContent
=
remoteMessage
.
getData
().
get
(
Constants
.
FCM_BUNDLE_LARGE_CONTENT
);
if
(
largeContent
!=
null
)
{
...
...
app/src/main/java/app/insti/NotificationBroadcastReceiver.java
View file @
5f535d4b
...
...
@@ -7,6 +7,8 @@ import android.content.Intent;
import
app.insti.api.EmptyCallback
;
import
app.insti.api.RetrofitInterface
;
import
app.insti.api.ServiceGenerator
;
import
app.insti.notifications.NotificationId
;
import
me.leolin.shortcutbadger.ShortcutBadger
;
public
class
NotificationBroadcastReceiver
extends
BroadcastReceiver
{
@Override
...
...
@@ -27,6 +29,9 @@ public class NotificationBroadcastReceiver extends BroadcastReceiver {
// Mark as read
retrofitInterface
.
markNotificationDeleted
(
Utils
.
getSessionIDHeader
(),
id
).
enqueue
(
new
EmptyCallback
<
Void
>());
// Reduce current count
ShortcutBadger
.
applyCount
(
context
.
getApplicationContext
(),
NotificationId
.
decrementAndGetCurrentCount
());
}
}
}
app/src/main/java/app/insti/activity/MainActivity.java
View file @
5f535d4b
...
...
@@ -75,6 +75,8 @@ import app.insti.fragment.QuickLinksFragment;
import
app.insti.fragment.SettingsFragment
;
import
app.insti.fragment.TrainingBlogFragment
;
import
app.insti.fragment.UserFragment
;
import
app.insti.notifications.NotificationId
;
import
me.leolin.shortcutbadger.ShortcutBadger
;
import
retrofit2.Call
;
import
retrofit2.Response
;
...
...
@@ -195,6 +197,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
Utils
.
notificationCache
=
new
UpdatableList
<>();
Utils
.
notificationCache
.
setList
(
response
.
body
());
showNotifications
();
NotificationId
.
setCurrentCount
(
Utils
.
notificationCache
.
size
());
ShortcutBadger
.
applyCount
(
getApplicationContext
(),
NotificationId
.
getCurrentCount
());
}
}
});
...
...
app/src/main/java/app/insti/adapter/NotificationsAdapter.java
View file @
5f535d4b
...
...
@@ -19,6 +19,8 @@ import app.insti.fragment.NewsFragment;
import
app.insti.fragment.NotificationsFragment
;
import
app.insti.fragment.PlacementBlogFragment
;
import
app.insti.fragment.TrainingBlogFragment
;
import
app.insti.notifications.NotificationId
;
import
me.leolin.shortcutbadger.ShortcutBadger
;
public
class
NotificationsAdapter
extends
CardAdapter
<
Notification
>
{
private
NotificationsFragment
notificationsFragment
;
...
...
@@ -34,6 +36,7 @@ public class NotificationsAdapter extends CardAdapter<Notification> {
RetrofitInterface
retrofitInterface
=
Utils
.
getRetrofitInterface
();
String
sessId
=
Utils
.
getSessionIDHeader
();
retrofitInterface
.
markNotificationRead
(
sessId
,
notification
.
getNotificationId
().
toString
()).
enqueue
(
new
EmptyCallback
<
Void
>());
ShortcutBadger
.
applyCount
(
fragmentActivity
.
getApplicationContext
(),
NotificationId
.
decrementAndGetCurrentCount
());
/* Close the bottom sheet */
notificationsFragment
.
dismiss
();
...
...
app/src/main/java/app/insti/fragment/NotificationsFragment.java
View file @
5f535d4b
...
...
@@ -19,6 +19,8 @@ import app.insti.adapter.NotificationsAdapter;
import
app.insti.api.EmptyCallback
;
import
app.insti.api.RetrofitInterface
;
import
app.insti.api.model.Notification
;
import
app.insti.notifications.NotificationId
;
import
me.leolin.shortcutbadger.ShortcutBadger
;
import
retrofit2.Call
;
import
retrofit2.Response
;
...
...
@@ -61,6 +63,9 @@ public class NotificationsFragment extends BottomSheetDialogFragment {
if
(
response
.
isSuccessful
())
{
Utils
.
notificationCache
.
setList
(
response
.
body
());
showNotifications
(
Utils
.
notificationCache
);
NotificationId
.
setCurrentCount
(
Utils
.
notificationCache
.
size
());
ShortcutBadger
.
applyCount
(
getContext
().
getApplicationContext
(),
NotificationId
.
getCurrentCount
());
}
}
});
...
...
app/src/main/java/app/insti/notifications/NotificationId.java
View file @
5f535d4b
...
...
@@ -7,4 +7,20 @@ public class NotificationId {
public
static
int
getID
()
{
return
c
.
incrementAndGet
();
}
private
final
static
AtomicInteger
current_count
=
new
AtomicInteger
(
0
);
public
static
int
getCurrentCount
()
{
return
c
.
get
();
}
public
static
int
decrementAndGetCurrentCount
()
{
if
(
c
.
get
()
>
0
)
return
c
.
decrementAndGet
();
else
return
0
;
}
public
static
void
setCurrentCount
(
int
count
)
{
c
.
set
(
count
);
}
}
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