@Test public void onUpdatesAvailable_whenUpdateForFormHasBeenHasNewHash_notifies() { List<ServerFormDetails> updates = asList( new ServerFormDetails("form-1", "http: ); notifier.onUpdatesAvailable(updates); assertThat(shadowOf(notificationManager).getAllNotifications().size(), is(1)); updates = asList( new ServerFormDetails("form-1", "http: ); notificationManager.cancelAll(); notifier.onUpdatesAvailable(updates); assertThat(shadowOf(notificationManager).getAllNotifications().size(), is(1)); }
@Override public void onUpdatesAvailable(List<ServerFormDetails> updates) { SharedPreferences metaPrefs = preferencesProvider.getMetaSharedPreferences(); Set<String> updateId = updates.stream().map(f -> f.getFormId() + f.getHash() + f.getManifestFileHash()).collect(toSet()); if (metaPrefs.getStringSet(MetaKeys.LAST_UPDATED_NOTIFICATION, emptySet()).equals(updateId)) { return; } Intent intent = new Intent(application, FormDownloadListActivity.class); intent.putExtra(DISPLAY_ONLY_UPDATED_FORMS, true); PendingIntent contentIntent = PendingIntent.getActivity(application, FORM_UPDATES_AVAILABLE_NOTIFICATION, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(application, COLLECT_NOTIFICATION_CHANNEL) .setContentIntent(contentIntent) .setContentTitle(TranslationHandler.getString(application, R.string.form_updates_available)) .setContentText(null) .setSmallIcon(IconUtils.getNotificationAppIcon()) .setAutoCancel(true); notificationManager.notify(FORM_UPDATE_NOTIFICATION_ID, builder.build()); metaPrefs.edit() .putStringSet(MetaKeys.LAST_UPDATED_NOTIFICATION, updateId) .apply(); }
NotificationManagerNotifier implements Notifier { @Override public void onUpdatesAvailable(List<ServerFormDetails> updates) { SharedPreferences metaPrefs = preferencesProvider.getMetaSharedPreferences(); Set<String> updateId = updates.stream().map(f -> f.getFormId() + f.getHash() + f.getManifestFileHash()).collect(toSet()); if (metaPrefs.getStringSet(MetaKeys.LAST_UPDATED_NOTIFICATION, emptySet()).equals(updateId)) { return; } Intent intent = new Intent(application, FormDownloadListActivity.class); intent.putExtra(DISPLAY_ONLY_UPDATED_FORMS, true); PendingIntent contentIntent = PendingIntent.getActivity(application, FORM_UPDATES_AVAILABLE_NOTIFICATION, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(application, COLLECT_NOTIFICATION_CHANNEL) .setContentIntent(contentIntent) .setContentTitle(TranslationHandler.getString(application, R.string.form_updates_available)) .setContentText(null) .setSmallIcon(IconUtils.getNotificationAppIcon()) .setAutoCancel(true); notificationManager.notify(FORM_UPDATE_NOTIFICATION_ID, builder.build()); metaPrefs.edit() .putStringSet(MetaKeys.LAST_UPDATED_NOTIFICATION, updateId) .apply(); } }
NotificationManagerNotifier implements Notifier { @Override public void onUpdatesAvailable(List<ServerFormDetails> updates) { SharedPreferences metaPrefs = preferencesProvider.getMetaSharedPreferences(); Set<String> updateId = updates.stream().map(f -> f.getFormId() + f.getHash() + f.getManifestFileHash()).collect(toSet()); if (metaPrefs.getStringSet(MetaKeys.LAST_UPDATED_NOTIFICATION, emptySet()).equals(updateId)) { return; } Intent intent = new Intent(application, FormDownloadListActivity.class); intent.putExtra(DISPLAY_ONLY_UPDATED_FORMS, true); PendingIntent contentIntent = PendingIntent.getActivity(application, FORM_UPDATES_AVAILABLE_NOTIFICATION, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(application, COLLECT_NOTIFICATION_CHANNEL) .setContentIntent(contentIntent) .setContentTitle(TranslationHandler.getString(application, R.string.form_updates_available)) .setContentText(null) .setSmallIcon(IconUtils.getNotificationAppIcon()) .setAutoCancel(true); notificationManager.notify(FORM_UPDATE_NOTIFICATION_ID, builder.build()); metaPrefs.edit() .putStringSet(MetaKeys.LAST_UPDATED_NOTIFICATION, updateId) .apply(); } NotificationManagerNotifier(Application application, PreferencesProvider preferencesProvider); }
NotificationManagerNotifier implements Notifier { @Override public void onUpdatesAvailable(List<ServerFormDetails> updates) { SharedPreferences metaPrefs = preferencesProvider.getMetaSharedPreferences(); Set<String> updateId = updates.stream().map(f -> f.getFormId() + f.getHash() + f.getManifestFileHash()).collect(toSet()); if (metaPrefs.getStringSet(MetaKeys.LAST_UPDATED_NOTIFICATION, emptySet()).equals(updateId)) { return; } Intent intent = new Intent(application, FormDownloadListActivity.class); intent.putExtra(DISPLAY_ONLY_UPDATED_FORMS, true); PendingIntent contentIntent = PendingIntent.getActivity(application, FORM_UPDATES_AVAILABLE_NOTIFICATION, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(application, COLLECT_NOTIFICATION_CHANNEL) .setContentIntent(contentIntent) .setContentTitle(TranslationHandler.getString(application, R.string.form_updates_available)) .setContentText(null) .setSmallIcon(IconUtils.getNotificationAppIcon()) .setAutoCancel(true); notificationManager.notify(FORM_UPDATE_NOTIFICATION_ID, builder.build()); metaPrefs.edit() .putStringSet(MetaKeys.LAST_UPDATED_NOTIFICATION, updateId) .apply(); } NotificationManagerNotifier(Application application, PreferencesProvider preferencesProvider); @Override void onUpdatesAvailable(List<ServerFormDetails> updates); @Override void onUpdatesDownloaded(HashMap<ServerFormDetails, String> result); @Override void onSync(@Nullable FormApiException exception); @Override void onSubmission(boolean failure, String message); }
NotificationManagerNotifier implements Notifier { @Override public void onUpdatesAvailable(List<ServerFormDetails> updates) { SharedPreferences metaPrefs = preferencesProvider.getMetaSharedPreferences(); Set<String> updateId = updates.stream().map(f -> f.getFormId() + f.getHash() + f.getManifestFileHash()).collect(toSet()); if (metaPrefs.getStringSet(MetaKeys.LAST_UPDATED_NOTIFICATION, emptySet()).equals(updateId)) { return; } Intent intent = new Intent(application, FormDownloadListActivity.class); intent.putExtra(DISPLAY_ONLY_UPDATED_FORMS, true); PendingIntent contentIntent = PendingIntent.getActivity(application, FORM_UPDATES_AVAILABLE_NOTIFICATION, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(application, COLLECT_NOTIFICATION_CHANNEL) .setContentIntent(contentIntent) .setContentTitle(TranslationHandler.getString(application, R.string.form_updates_available)) .setContentText(null) .setSmallIcon(IconUtils.getNotificationAppIcon()) .setAutoCancel(true); notificationManager.notify(FORM_UPDATE_NOTIFICATION_ID, builder.build()); metaPrefs.edit() .putStringSet(MetaKeys.LAST_UPDATED_NOTIFICATION, updateId) .apply(); } NotificationManagerNotifier(Application application, PreferencesProvider preferencesProvider); @Override void onUpdatesAvailable(List<ServerFormDetails> updates); @Override void onUpdatesDownloaded(HashMap<ServerFormDetails, String> result); @Override void onSync(@Nullable FormApiException exception); @Override void onSubmission(boolean failure, String message);  }