Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. public class NotificationItem extends BaseNotificationItem {
  2.  
  3. PendingIntent pendingIntent;
  4. NotificationCompat.Builder builder;
  5. private NotificationManager notificationManager;
  6.  
  7. private NotificationItem(int id, String title, String desc) {
  8. super(id, title, desc);
  9. notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  10. Intent cancelIntent = new Intent(getContext(), CancelReceiver.class);
  11. Intent pauseIntent = new Intent(getContext(), PauseReceiver.class);
  12. cancelIntent.putExtra("url", data.getVideo().getFiles().getOffline().getSd().getFile());
  13. cancelIntent.putExtra("id", getId());
  14. pauseIntent.putExtra("id", getId());
  15.  
  16. PendingIntent pendingCancel = PendingIntent.getBroadcast(getContext(), 0,
  17. cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  18. PendingIntent pendingPause = PendingIntent.getBroadcast(getContext(), 0,
  19. pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  20.  
  21. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  22. NotificationChannel notificationChannel = new NotificationChannel("channelid", "Notification", NotificationManager.IMPORTANCE_LOW);
  23.  
  24. notificationChannel.setDescription("Notification");
  25. notificationChannel.setSound(null, null);
  26. notificationChannel.enableLights(false);
  27. notificationChannel.setLightColor(Color.BLUE);
  28. notificationChannel.enableVibration(false);
  29. notificationManager.createNotificationChannel(notificationChannel);
  30. }
  31.  
  32. builder = new NotificationCompat.
  33. Builder(FileDownloadHelper.getAppContext(), "channelid")
  34. .setDefaults(Notification.DEFAULT_LIGHTS)
  35. .setOngoing(true)
  36. .setPriority(NotificationCompat.PRIORITY_MIN)
  37. .setContentTitle(getTitle())
  38. .setContentText(desc)
  39. .addAction(R.drawable.exo_controls_play, "PAUSE", pendingPause)
  40. .addAction(R.drawable.exo_controls_play, "CANCEL", pendingCancel)
  41. .setContentIntent(pendingIntent)
  42. .setSmallIcon(R.drawable.exo_controls_play);
  43.  
  44. }
  45.  
  46. @Override
  47. public void show(boolean statusChanged, int status, boolean isShowProgress) {
  48.  
  49. String desc = getDesc();
  50. switch (status) {
  51. case FileDownloadStatus.pending:
  52. desc += " pending";
  53. Log.e("status", "FileDownloadStatus.pending");
  54. break;
  55. case FileDownloadStatus.started:
  56. desc += " started";
  57. Log.e("status", "FileDownloadStatus.started");
  58. break;
  59. case FileDownloadStatus.progress:
  60. desc += " progress";
  61. Log.e("status", "FileDownloadStatus.progress");
  62. break;
  63. case FileDownloadStatus.retry:
  64. desc += " retry";
  65. Log.e("status", "FileDownloadStatus.retry");
  66. break;
  67. case FileDownloadStatus.error:
  68. desc += " error";
  69. Log.e("status", "FileDownloadStatus.error");
  70. break;
  71. case FileDownloadStatus.paused:
  72. desc += " paused";
  73. Log.e("status", "FileDownloadStatus.paused");
  74. break;
  75. case FileDownloadStatus.completed:
  76. desc += " completed";
  77. Log.e("status", "FileDownloadStatus.completed");
  78. break;
  79. case FileDownloadStatus.warn:
  80. desc += " warn";
  81. Log.e("status", "FileDownloadStatus.warn");
  82. break;
  83. }
  84.  
  85. builder.setContentTitle(getTitle())
  86. .setContentText(desc);
  87.  
  88.  
  89. if (statusChanged) {
  90. builder.setTicker(desc);
  91. }
  92.  
  93. builder.setProgress(getTotal(), getSofar(), !isShowProgress);
  94. Log.e("tagg", ""+getSofar());
  95. fileDownloader.startForeground(data.getId(), builder.build());
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement