-
Notifications
You must be signed in to change notification settings - Fork 678
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(android): add support for badge count (#207)
* feature(android): add support for badge count (#1) Using Leolin's ShortcutBadger we are able to support any badge counts that are sent as part of the notifications data-payload. * refactor(android): expand badge support (#3)
- Loading branch information
1 parent
1b1f886
commit 62dce36
Showing
5 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
build | ||
xcuserdata | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
android/src/main/java/com/evollu/react/fcm/BadgeHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.evollu.react.fcm; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.util.Log; | ||
|
||
import me.leolin.shortcutbadger.ShortcutBadger; | ||
|
||
public class BadgeHelper { | ||
|
||
private static final String TAG = "BadgeHelper"; | ||
private static final String PREFERENCES_FILE = "BadgeCountFile"; | ||
private static final String BADGE_COUNT_KEY = "BadgeCount"; | ||
|
||
private Context mContext; | ||
private SharedPreferences sharedPreferences = null; | ||
|
||
public BadgeHelper(Context context) { | ||
mContext = context; | ||
sharedPreferences = (SharedPreferences) mContext.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE); | ||
} | ||
|
||
public int getBadgeCount() { | ||
return sharedPreferences.getInt(BADGE_COUNT_KEY, 0); | ||
} | ||
|
||
public void setBadgeCount(int badgeCount) { | ||
storeBadgeCount(badgeCount); | ||
if (badgeCount == 0) { | ||
ShortcutBadger.removeCount(mContext); | ||
Log.d(TAG, "Remove count"); | ||
} else { | ||
ShortcutBadger.applyCount(mContext, badgeCount); | ||
Log.d(TAG, "Apply count: " + badgeCount); | ||
} | ||
} | ||
|
||
private void storeBadgeCount(int badgeCount) { | ||
SharedPreferences.Editor editor = sharedPreferences.edit(); | ||
editor.putInt(BADGE_COUNT_KEY, badgeCount); | ||
editor.apply(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters