@Test public void onSync_whenExceptionNull_clearsNotification() { notifier.onSync(new FormApiException(FormApiException.Type.FETCH_ERROR)); assertThat(shadowOf(notificationManager).getAllNotifications().size(), is(1)); notifier.onSync(null); assertThat(shadowOf(notificationManager).getAllNotifications().size(), is(0)); }
@Override public void onSync(@Nullable FormApiException exception) { if (exception != null) { Intent intent = new Intent(application, FillBlankFormActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(application, FORM_SYNC_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(application, COLLECT_NOTIFICATION_CHANNEL) .setContentIntent(contentIntent) .setContentTitle(TranslationHandler.getString(application, R.string.form_update_error)) .setStyle(new NotificationCompat.BigTextStyle().bigText(new FormApiExceptionMapper(application).getMessage(exception))) .setSmallIcon(IconUtils.getNotificationAppIcon()) .setAutoCancel(true); notificationManager.notify(FORM_SYNC_NOTIFICATION_ID, builder.build()); } else { notificationManager.cancel(FORM_SYNC_NOTIFICATION_ID); } }
NotificationManagerNotifier implements Notifier { @Override public void onSync(@Nullable FormApiException exception) { if (exception != null) { Intent intent = new Intent(application, FillBlankFormActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(application, FORM_SYNC_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(application, COLLECT_NOTIFICATION_CHANNEL) .setContentIntent(contentIntent) .setContentTitle(TranslationHandler.getString(application, R.string.form_update_error)) .setStyle(new NotificationCompat.BigTextStyle().bigText(new FormApiExceptionMapper(application).getMessage(exception))) .setSmallIcon(IconUtils.getNotificationAppIcon()) .setAutoCancel(true); notificationManager.notify(FORM_SYNC_NOTIFICATION_ID, builder.build()); } else { notificationManager.cancel(FORM_SYNC_NOTIFICATION_ID); } } }
NotificationManagerNotifier implements Notifier { @Override public void onSync(@Nullable FormApiException exception) { if (exception != null) { Intent intent = new Intent(application, FillBlankFormActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(application, FORM_SYNC_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(application, COLLECT_NOTIFICATION_CHANNEL) .setContentIntent(contentIntent) .setContentTitle(TranslationHandler.getString(application, R.string.form_update_error)) .setStyle(new NotificationCompat.BigTextStyle().bigText(new FormApiExceptionMapper(application).getMessage(exception))) .setSmallIcon(IconUtils.getNotificationAppIcon()) .setAutoCancel(true); notificationManager.notify(FORM_SYNC_NOTIFICATION_ID, builder.build()); } else { notificationManager.cancel(FORM_SYNC_NOTIFICATION_ID); } } NotificationManagerNotifier(Application application, PreferencesProvider preferencesProvider); }
NotificationManagerNotifier implements Notifier { @Override public void onSync(@Nullable FormApiException exception) { if (exception != null) { Intent intent = new Intent(application, FillBlankFormActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(application, FORM_SYNC_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(application, COLLECT_NOTIFICATION_CHANNEL) .setContentIntent(contentIntent) .setContentTitle(TranslationHandler.getString(application, R.string.form_update_error)) .setStyle(new NotificationCompat.BigTextStyle().bigText(new FormApiExceptionMapper(application).getMessage(exception))) .setSmallIcon(IconUtils.getNotificationAppIcon()) .setAutoCancel(true); notificationManager.notify(FORM_SYNC_NOTIFICATION_ID, builder.build()); } else { notificationManager.cancel(FORM_SYNC_NOTIFICATION_ID); } } 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 onSync(@Nullable FormApiException exception) { if (exception != null) { Intent intent = new Intent(application, FillBlankFormActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(application, FORM_SYNC_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(application, COLLECT_NOTIFICATION_CHANNEL) .setContentIntent(contentIntent) .setContentTitle(TranslationHandler.getString(application, R.string.form_update_error)) .setStyle(new NotificationCompat.BigTextStyle().bigText(new FormApiExceptionMapper(application).getMessage(exception))) .setSmallIcon(IconUtils.getNotificationAppIcon()) .setAutoCancel(true); notificationManager.notify(FORM_SYNC_NOTIFICATION_ID, builder.build()); } else { notificationManager.cancel(FORM_SYNC_NOTIFICATION_ID); } } 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);  }