Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android notification special symbols #5

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
50ea463
Added timestamp while storing mark as read data
prashant000chaudhary Nov 22, 2018
9d61c0d
Merge branch 'prashant-master'
stefansaenger Nov 22, 2018
c9d9ebd
API to schedule local notifications (#1)
soulfly Nov 23, 2018
cfdfc1f
Review of notifications ids storing logic
soulfly Nov 27, 2018
d1d9359
fixes to context
soulfly Nov 27, 2018
a453dfe
Added grouping notification messages by title
yuriy-kaplunov Nov 27, 2018
bfdb1c7
hide other notifications for target when mark as read
soulfly Nov 27, 2018
7f0df67
some import fixes
soulfly Nov 27, 2018
1fc10f4
Merge branch 'android_add_notification_grouping' into feature/android…
soulfly Nov 27, 2018
fd1d419
automatically update previous notification text;
soulfly Nov 28, 2018
9754238
Change tag of notification defenition to "target"
yuriy-kaplunov Nov 28, 2018
a7c3bf0
fix NPE
soulfly Nov 28, 2018
1d9bb57
fixes for inline reply action (not worked in groups)
soulfly Nov 28, 2018
4053638
set notification id as hashcode from target
soulfly Nov 28, 2018
24eb741
type
soulfly Nov 28, 2018
1257f08
Fixed crash problem with StatusBarNotification for android version le…
yuriy-kaplunov Nov 29, 2018
a2fa73d
added onNotificationMarkAsRead callback
soulfly Nov 29, 2018
9e62a84
Merge branch 'feature/android-review-ids-storing-logic_AND_notificati…
soulfly Nov 29, 2018
e9c85a3
fixes for sendNotificationMarkAsRead
soulfly Nov 30, 2018
b354a63
cleanup
soulfly Nov 30, 2018
445c8f4
Added parser and handler for notification's texts format
yuriy-kaplunov Nov 30, 2018
0d4b03b
Corrected conditions for define link
yuriy-kaplunov Nov 30, 2018
8d217e2
Revert "Corrected conditions for define link"
yuriy-kaplunov Nov 30, 2018
0aeab10
Fixed bugs with conditions for link defenition
yuriy-kaplunov Nov 30, 2018
1a16bd5
Fixed msgs format for group msgs
yuriy-kaplunov Nov 30, 2018
429b6cf
Merge pull request #6 from vnc-biz/feature/android-review-ids-storing…
soulfly Nov 30, 2018
83cc0f7
Fixed notification title on Android9
Dec 3, 2018
1e2255a
Merge pull request #8 from vnc-biz/fix/android9-notification-title
soulfly Dec 3, 2018
241fa41
Added special symbols for special notifications
yuriy-kaplunov Dec 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 74 additions & 2 deletions src/android/FirebasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class FirebasePlugin extends CordovaPlugin {
private static ArrayList<Bundle> notificationStack = null;
private static CallbackContext notificationCallbackContext;
private static CallbackContext tokenRefreshCallbackContext;
private static CallbackContext notificationMarkAsReadCallbackContext;

@Override
protected void pluginInitialize() {
Expand Down Expand Up @@ -134,6 +135,9 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
} else if (action.equals("onNotificationOpen")) {
this.onNotificationOpen(callbackContext);
return true;
} else if (action.equals("onNotificationMarkAsRead")) {
this.onNotificationMarkAsRead(callbackContext);
return true;
} else if (action.equals("onTokenRefresh")) {
this.onTokenRefresh(callbackContext);
return true;
Expand Down Expand Up @@ -205,14 +209,17 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
this.setAnalyticsCollectionEnabled(callbackContext, args.getBoolean(0));
return true;
} else if (action.equals("setPerformanceCollectionEnabled")) {
this.setPerformanceCollectionEnabled(callbackContext, args.getBoolean(0));
return true;
this.setPerformanceCollectionEnabled(callbackContext, args.getBoolean(0));
return true;
} else if (action.equals("clearAllNotifications")) {
this.clearAllNotifications(callbackContext);
return true;
} else if (action.equals("clear")) {
this.clear(callbackContext, args.getInt(0));
return true;
} else if (action.equals("scheduleLocalNotification")) {
this.scheduleLocalNotification(callbackContext, args.getJSONObject(0));
return true;
}

return false;
Expand All @@ -232,6 +239,7 @@ public void onResume(boolean multitasking) {
public void onReset() {
FirebasePlugin.notificationCallbackContext = null;
FirebasePlugin.tokenRefreshCallbackContext = null;
FirebasePlugin.notificationMarkAsReadCallbackContext = null;
}

@Override
Expand Down Expand Up @@ -299,6 +307,10 @@ private void onNotificationOpen(final CallbackContext callbackContext) {
}
}

private void onNotificationMarkAsRead(final CallbackContext callbackContext) {
FirebasePlugin.notificationMarkAsReadCallbackContext = callbackContext;
}

private void onTokenRefresh(final CallbackContext callbackContext) {
FirebasePlugin.tokenRefreshCallbackContext = callbackContext;

Expand Down Expand Up @@ -351,6 +363,32 @@ public static void sendNotification(Bundle bundle, Context context) {
}
}

public static void sendNotificationMarkAsRead(Bundle bundle) {
final CallbackContext callbackContext = FirebasePlugin.notificationMarkAsReadCallbackContext;

if(callbackContext == null || bundle == null){
return;
}

JSONObject json = new JSONObject();
Set<String> keys = bundle.keySet();
for (String key : keys) {
try {
json.put(key, bundle.get(key));
} catch (JSONException e) {
if(FirebasePlugin.crashlyticsInit()){
Crashlytics.logException(e);
}
callbackContext.error(e.getMessage());
return;
}
}

PluginResult pluginresult = new PluginResult(PluginResult.Status.OK, json);
pluginresult.setKeepCallback(true);
callbackContext.sendPluginResult(pluginresult);
}

public static void sendToken(String token) {
if (FirebasePlugin.tokenRefreshCallbackContext == null) {
return;
Expand Down Expand Up @@ -384,6 +422,10 @@ public static boolean hasNotificationsCallback() {
return FirebasePlugin.notificationCallbackContext != null;
}

public static boolean hasNotificationsMarkAsReadCallback() {
return FirebasePlugin.notificationMarkAsReadCallbackContext != null;
}

@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Expand Down Expand Up @@ -1124,4 +1166,34 @@ public void run() {
}
});
}

public void scheduleLocalNotification(final CallbackContext callbackContext, final JSONObject params) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
Context activityContext = cordova.getActivity();
Context appContext = activityContext.getApplicationContext();

String id = params.getString("id");
String target = params.getString("target");
String username = params.getString("username");
String groupName = params.getString("groupName");
String message = params.getString("message");
String eventType = params.getString("eventType");
String nsound = params.getString("nsound");
String sound = params.getString("sound");
String lights = params.getString("lights");

FirebasePluginMessagingService.displayNotification(activityContext, appContext, id, target, username, groupName, message, eventType, nsound, true, sound, lights);

callbackContext.success();
} catch (Exception e) {
if(FirebasePlugin.crashlyticsInit()){
Crashlytics.log(e.getMessage());
}
callbackContext.error(e.getMessage());
}
}
});
}
}
Loading