Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Plugins/SharePlugin/ShareNotification.java
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 42 | public class ShareNotification { | |||
---|---|---|---|---|---|
47 | private NotificationCompat.Builder builder; | 47 | private NotificationCompat.Builder builder; | ||
48 | private Device device; | 48 | private Device device; | ||
49 | 49 | | |||
50 | public ShareNotification(Device device, String filename) { | 50 | public ShareNotification(Device device, String filename) { | ||
51 | this.device = device; | 51 | this.device = device; | ||
52 | this.filename = filename; | 52 | this.filename = filename; | ||
53 | notificationId = (int) System.currentTimeMillis(); | 53 | notificationId = (int) System.currentTimeMillis(); | ||
54 | notificationManager = (NotificationManager) device.getContext().getSystemService(Context.NOTIFICATION_SERVICE); | 54 | notificationManager = (NotificationManager) device.getContext().getSystemService(Context.NOTIFICATION_SERVICE); | ||
55 | builder = new NotificationCompat.Builder(device.getContext()) | 55 | builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.getDefaultChannelId(notificationManager)) | ||
56 | .setContentTitle(device.getContext().getResources().getString(R.string.incoming_file_title, device.getName())) | 56 | .setContentTitle(device.getContext().getResources().getString(R.string.incoming_file_title, device.getName())) | ||
57 | .setContentText(device.getContext().getResources().getString(R.string.incoming_file_text, filename)) | 57 | .setContentText(device.getContext().getResources().getString(R.string.incoming_file_text, filename)) | ||
58 | .setTicker(device.getContext().getResources().getString(R.string.incoming_file_title, device.getName())) | 58 | .setTicker(device.getContext().getResources().getString(R.string.incoming_file_title, device.getName())) | ||
59 | .setSmallIcon(android.R.drawable.stat_sys_download) | 59 | .setSmallIcon(android.R.drawable.stat_sys_download) | ||
60 | .setAutoCancel(true) | 60 | .setAutoCancel(true) | ||
61 | .setOngoing(true) | 61 | .setOngoing(true) | ||
62 | .setProgress(100, 0, true); | 62 | .setProgress(100, 0, true); | ||
63 | } | 63 | } | ||
64 | 64 | | |||
65 | public void show() { | 65 | public void show() { | ||
66 | NotificationHelper.notifyCompat(notificationManager, notificationId, builder.build()); | 66 | NotificationHelper.notifyCompat(notificationManager, notificationId, builder.build()); | ||
67 | } | 67 | } | ||
68 | 68 | | |||
69 | public int getId() { | 69 | public int getId() { | ||
70 | return notificationId; | 70 | return notificationId; | ||
71 | } | 71 | } | ||
72 | 72 | | |||
73 | public void setProgress(int progress) { | 73 | public void setProgress(int progress) { | ||
74 | builder.setProgress(100, progress, false) | 74 | builder.setProgress(100, progress, false) | ||
75 | .setContentTitle(device.getContext().getResources().getString(R.string.incoming_file_title, device.getName()) + " (" + progress + "%)"); | 75 | .setContentTitle(device.getContext().getResources().getString(R.string.incoming_file_title, device.getName()) + " (" + progress + "%)"); | ||
76 | } | 76 | } | ||
77 | 77 | | |||
78 | public void setFinished(boolean success) { | 78 | public void setFinished(boolean success) { | ||
79 | String message = success ? device.getContext().getResources().getString(R.string.received_file_title, device.getName()) : device.getContext().getResources().getString(R.string.received_file_fail_title, device.getName()); | 79 | String message = success ? device.getContext().getResources().getString(R.string.received_file_title, device.getName()) : device.getContext().getResources().getString(R.string.received_file_fail_title, device.getName()); | ||
80 | builder = new NotificationCompat.Builder(device.getContext()); | 80 | builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.getDefaultChannelId(notificationManager)); | ||
81 | builder.setContentTitle(message) | 81 | builder.setContentTitle(message) | ||
82 | .setTicker(message) | 82 | .setTicker(message) | ||
83 | .setSmallIcon(android.R.drawable.stat_sys_download_done) | 83 | .setSmallIcon(android.R.drawable.stat_sys_download_done) | ||
84 | .setAutoCancel(true) | 84 | .setAutoCancel(true) | ||
85 | .setOngoing(false); | 85 | .setOngoing(false); | ||
86 | 86 | | |||
87 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(device.getContext()); | 87 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(device.getContext()); | ||
88 | if (prefs.getBoolean("share_notification_preference", true)) { | 88 | if (prefs.getBoolean("share_notification_preference", true)) { | ||
Show All 35 Lines |