Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class NotificationItem extends BaseNotificationItem {
- PendingIntent pendingIntent;
- NotificationCompat.Builder builder;
- private NotificationManager notificationManager;
- private NotificationItem(int id, String title, String desc) {
- super(id, title, desc);
- notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
- Intent cancelIntent = new Intent(getContext(), CancelReceiver.class);
- Intent pauseIntent = new Intent(getContext(), PauseReceiver.class);
- cancelIntent.putExtra("url", data.getVideo().getFiles().getOffline().getSd().getFile());
- cancelIntent.putExtra("id", getId());
- pauseIntent.putExtra("id", getId());
- PendingIntent pendingCancel = PendingIntent.getBroadcast(getContext(), 0,
- cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT);
- PendingIntent pendingPause = PendingIntent.getBroadcast(getContext(), 0,
- pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- NotificationChannel notificationChannel = new NotificationChannel("channelid", "Notification", NotificationManager.IMPORTANCE_LOW);
- notificationChannel.setDescription("Notification");
- notificationChannel.setSound(null, null);
- notificationChannel.enableLights(false);
- notificationChannel.setLightColor(Color.BLUE);
- notificationChannel.enableVibration(false);
- notificationManager.createNotificationChannel(notificationChannel);
- }
- builder = new NotificationCompat.
- Builder(FileDownloadHelper.getAppContext(), "channelid")
- .setDefaults(Notification.DEFAULT_LIGHTS)
- .setOngoing(true)
- .setPriority(NotificationCompat.PRIORITY_MIN)
- .setContentTitle(getTitle())
- .setContentText(desc)
- .addAction(R.drawable.exo_controls_play, "PAUSE", pendingPause)
- .addAction(R.drawable.exo_controls_play, "CANCEL", pendingCancel)
- .setContentIntent(pendingIntent)
- .setSmallIcon(R.drawable.exo_controls_play);
- }
- @Override
- public void show(boolean statusChanged, int status, boolean isShowProgress) {
- String desc = getDesc();
- switch (status) {
- case FileDownloadStatus.pending:
- desc += " pending";
- Log.e("status", "FileDownloadStatus.pending");
- break;
- case FileDownloadStatus.started:
- desc += " started";
- Log.e("status", "FileDownloadStatus.started");
- break;
- case FileDownloadStatus.progress:
- desc += " progress";
- Log.e("status", "FileDownloadStatus.progress");
- break;
- case FileDownloadStatus.retry:
- desc += " retry";
- Log.e("status", "FileDownloadStatus.retry");
- break;
- case FileDownloadStatus.error:
- desc += " error";
- Log.e("status", "FileDownloadStatus.error");
- break;
- case FileDownloadStatus.paused:
- desc += " paused";
- Log.e("status", "FileDownloadStatus.paused");
- break;
- case FileDownloadStatus.completed:
- desc += " completed";
- Log.e("status", "FileDownloadStatus.completed");
- break;
- case FileDownloadStatus.warn:
- desc += " warn";
- Log.e("status", "FileDownloadStatus.warn");
- break;
- }
- builder.setContentTitle(getTitle())
- .setContentText(desc);
- if (statusChanged) {
- builder.setTicker(desc);
- }
- builder.setProgress(getTotal(), getSofar(), !isShowProgress);
- Log.e("tagg", ""+getSofar());
- fileDownloader.startForeground(data.getId(), builder.build());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement