@Test public void updateNotificationWithNewMapDownload() throws NoSuchFieldException, IllegalAccessException { DownloadProgressNotification downloadProgressNotification = new DownloadProgressNotification(context); String mapName = UUID.randomUUID().toString(); String mapBoxAccessToken = "sample_access_token"; int requestCode = 89238087; downloadProgressNotification.createInitialNotification(mapName, mapBoxAccessToken, requestCode, true); assertNotificationBuilder(downloadProgressNotification.notificationBuilder, mapName); String newMapName = "notification channel"; downloadProgressNotification.updateNotificationWithNewMapDownload(newMapName, requestCode); assertNotificationBuilder(downloadProgressNotification.notificationBuilder, newMapName); 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, newMapName); stopDownloadIntent.putExtra(Constants.PARCELABLE_KEY_MAPBOX_ACCESS_TOKEN, mapBoxAccessToken); stopDownloadIntent.putExtra(Constants.PARCELABLE_KEY_DELETE_TASK_TYPE, MapBoxOfflineQueueTask.TASK_TYPE_DOWNLOAD); assertEquals(1, downloadProgressNotification.notificationBuilder.mActions.size()); compareIntent(stopDownloadIntent, getIntent(downloadProgressNotification.notificationBuilder.mActions.get(0).getActionIntent())); }
public void updateNotificationWithNewMapDownload(String mapName, int requestCode) { notificationBuilder.setContentTitle(String.format(context.getString(R.string.notification_download_progress_title), mapName)); stopDownloadIntent.putExtra(Constants.PARCELABLE_KEY_MAP_UNIQUE_NAME, mapName); PendingIntent stopDownloadPendingIntent = PendingIntent.getService(context, requestCode, stopDownloadIntent, PendingIntent.FLAG_CANCEL_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 updateNotificationWithNewMapDownload(String mapName, int requestCode) { notificationBuilder.setContentTitle(String.format(context.getString(R.string.notification_download_progress_title), mapName)); stopDownloadIntent.putExtra(Constants.PARCELABLE_KEY_MAP_UNIQUE_NAME, mapName); PendingIntent stopDownloadPendingIntent = PendingIntent.getService(context, requestCode, stopDownloadIntent, PendingIntent.FLAG_CANCEL_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 updateNotificationWithNewMapDownload(String mapName, int requestCode) { notificationBuilder.setContentTitle(String.format(context.getString(R.string.notification_download_progress_title), mapName)); stopDownloadIntent.putExtra(Constants.PARCELABLE_KEY_MAP_UNIQUE_NAME, mapName); PendingIntent stopDownloadPendingIntent = PendingIntent.getService(context, requestCode, stopDownloadIntent, PendingIntent.FLAG_CANCEL_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 updateNotificationWithNewMapDownload(String mapName, int requestCode) { notificationBuilder.setContentTitle(String.format(context.getString(R.string.notification_download_progress_title), mapName)); stopDownloadIntent.putExtra(Constants.PARCELABLE_KEY_MAP_UNIQUE_NAME, mapName); PendingIntent stopDownloadPendingIntent = PendingIntent.getService(context, requestCode, stopDownloadIntent, PendingIntent.FLAG_CANCEL_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 updateNotificationWithNewMapDownload(String mapName, int requestCode) { notificationBuilder.setContentTitle(String.format(context.getString(R.string.notification_download_progress_title), mapName)); stopDownloadIntent.putExtra(Constants.PARCELABLE_KEY_MAP_UNIQUE_NAME, mapName); PendingIntent stopDownloadPendingIntent = PendingIntent.getService(context, requestCode, stopDownloadIntent, PendingIntent.FLAG_CANCEL_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; }