@Test public void createInitialNotificationShouldCreateNotificationBuilderWithStopDownloadAction() throws NoSuchFieldException, IllegalAccessException { DownloadProgressNotification downloadProgressNotification = new DownloadProgressNotification(context); String mapName = UUID.randomUUID().toString(); String mapBoxAccessToken = "sample_access_token"; int requestCode = 89230923; downloadProgressNotification.createInitialNotification(mapName, mapBoxAccessToken, requestCode, true); NotificationCompat.Builder builder = downloadProgressNotification.notificationBuilder; assertNotificationBuilder(builder, mapName); Intent stopDownloadIntent = new Intent(context, MapboxOfflineDownloaderService.class); stopDownloadIntent.putExtra(Constants.PARCELABLE_KEY_SERVICE_ACTION, MapboxOfflineDownloaderService.SERVICE_ACTION.STOP_CURRENT_DOWNLOAD); stopDownloadIntent.putExtra(Constants.PARCELABLE_KEY_MAP_UNIQUE_NAME, mapName); stopDownloadIntent.putExtra(Constants.PARCELABLE_KEY_MAPBOX_ACCESS_TOKEN, mapBoxAccessToken); stopDownloadIntent.putExtra(Constants.PARCELABLE_KEY_DELETE_TASK_TYPE, MapBoxOfflineQueueTask.TASK_TYPE_DOWNLOAD); NotificationCompat.Action actualAction = builder.mActions.get(0); compareIntent(stopDownloadIntent, getIntent(actualAction.getActionIntent())); }
public void createInitialNotification(String mapName, String mapBoxAccessToken, int requestCode, boolean showAction) { notificationBuilder = createNotification(String.format(context.getString(R.string.notification_download_progress_title), mapName)); if (showAction) { stopDownloadIntent = createStopDownloadIntent(mapName, mapBoxAccessToken); PendingIntent stopDownloadPendingIntent = PendingIntent.getService(context, requestCode, stopDownloadIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action stopDownloadAction = new NotificationCompat.Action(R.drawable.ic_mapbox_download_stop, context.getString(R.string.stop_download), stopDownloadPendingIntent); notificationBuilder.mActions.clear(); notificationBuilder.addAction(stopDownloadAction); } }
DownloadProgressNotification extends KujakuNotification { public void createInitialNotification(String mapName, String mapBoxAccessToken, int requestCode, boolean showAction) { notificationBuilder = createNotification(String.format(context.getString(R.string.notification_download_progress_title), mapName)); if (showAction) { stopDownloadIntent = createStopDownloadIntent(mapName, mapBoxAccessToken); PendingIntent stopDownloadPendingIntent = PendingIntent.getService(context, requestCode, stopDownloadIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action stopDownloadAction = new NotificationCompat.Action(R.drawable.ic_mapbox_download_stop, context.getString(R.string.stop_download), stopDownloadPendingIntent); notificationBuilder.mActions.clear(); notificationBuilder.addAction(stopDownloadAction); } } }
DownloadProgressNotification extends KujakuNotification { public void createInitialNotification(String mapName, String mapBoxAccessToken, int requestCode, boolean showAction) { notificationBuilder = createNotification(String.format(context.getString(R.string.notification_download_progress_title), mapName)); if (showAction) { stopDownloadIntent = createStopDownloadIntent(mapName, mapBoxAccessToken); PendingIntent stopDownloadPendingIntent = PendingIntent.getService(context, requestCode, stopDownloadIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action stopDownloadAction = new NotificationCompat.Action(R.drawable.ic_mapbox_download_stop, context.getString(R.string.stop_download), stopDownloadPendingIntent); notificationBuilder.mActions.clear(); notificationBuilder.addAction(stopDownloadAction); } } DownloadProgressNotification(Context context); }
DownloadProgressNotification extends KujakuNotification { public void createInitialNotification(String mapName, String mapBoxAccessToken, int requestCode, boolean showAction) { notificationBuilder = createNotification(String.format(context.getString(R.string.notification_download_progress_title), mapName)); if (showAction) { stopDownloadIntent = createStopDownloadIntent(mapName, mapBoxAccessToken); PendingIntent stopDownloadPendingIntent = PendingIntent.getService(context, requestCode, stopDownloadIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action stopDownloadAction = new NotificationCompat.Action(R.drawable.ic_mapbox_download_stop, context.getString(R.string.stop_download), stopDownloadPendingIntent); notificationBuilder.mActions.clear(); notificationBuilder.addAction(stopDownloadAction); } } DownloadProgressNotification(Context context); void createInitialNotification(String mapName, String mapBoxAccessToken, int requestCode, boolean showAction); void updateNotification(double percentageProgress, String mapName, int requestCode, boolean showAction); void displayForegroundNotification(NotificationCompat.Builder notificationBuilder, int notificationId); void displayForegroundNotification(int notificationId); void updateNotificationWithNewMapDownload(String mapName, int requestCode); void displayNotification(int notificationId); void updateNotificationWithDownloadProgress(double percentageProgress); void clearActions(); Intent createStopDownloadIntent(String mapName, String mapBoxAccessToken); }
DownloadProgressNotification extends KujakuNotification { public void createInitialNotification(String mapName, String mapBoxAccessToken, int requestCode, boolean showAction) { notificationBuilder = createNotification(String.format(context.getString(R.string.notification_download_progress_title), mapName)); if (showAction) { stopDownloadIntent = createStopDownloadIntent(mapName, mapBoxAccessToken); PendingIntent stopDownloadPendingIntent = PendingIntent.getService(context, requestCode, stopDownloadIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action stopDownloadAction = new NotificationCompat.Action(R.drawable.ic_mapbox_download_stop, context.getString(R.string.stop_download), stopDownloadPendingIntent); notificationBuilder.mActions.clear(); notificationBuilder.addAction(stopDownloadAction); } } DownloadProgressNotification(Context context); void createInitialNotification(String mapName, String mapBoxAccessToken, int requestCode, boolean showAction); void updateNotification(double percentageProgress, String mapName, int requestCode, boolean showAction); void displayForegroundNotification(NotificationCompat.Builder notificationBuilder, int notificationId); void displayForegroundNotification(int notificationId); void updateNotificationWithNewMapDownload(String mapName, int requestCode); void displayNotification(int notificationId); void updateNotificationWithDownloadProgress(double percentageProgress); void clearActions(); Intent createStopDownloadIntent(String mapName, String mapBoxAccessToken); static final String CHANNEL_ID; }