2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 14:15:14 +00:00

Split notification channels for received and sent files

BUG: 433051
This commit is contained in:
Albert Vaca Cintora
2023-09-12 05:14:37 +02:00
parent 708889eed7
commit 17757908c4
4 changed files with 20 additions and 10 deletions

View File

@@ -358,7 +358,8 @@ SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted
<string name="notification_channel_default">Other notifications</string> <string name="notification_channel_default">Other notifications</string>
<string name="notification_channel_persistent">Persistent indicator</string> <string name="notification_channel_persistent">Persistent indicator</string>
<string name="notification_channel_media_control">Media control</string> <string name="notification_channel_media_control">Media control</string>
<string name="notification_channel_filetransfer">File transfer</string> <string name="notification_channel_filetransfer">Incoming file transfer</string>
<string name="notification_channel_filetransfer_upload">Outgoing file transfer</string>
<string name="notification_channel_high_priority">High priority</string> <string name="notification_channel_high_priority">High priority</string>
<string name="mpris_stop">Stop the current player</string> <string name="mpris_stop">Stop the current player</string>

View File

@@ -28,7 +28,10 @@ public class NotificationHelper {
public final static String PERSISTENT = "persistent"; public final static String PERSISTENT = "persistent";
public final static String DEFAULT = "default"; public final static String DEFAULT = "default";
public final static String MEDIA_CONTROL = "media_control"; public final static String MEDIA_CONTROL = "media_control";
public final static String FILETRANSFER = "filetransfer";
public final static String FILETRANSFER_DOWNLOAD = "filetransfer";
public final static String FILETRANSFER_UPLOAD = "filetransfer_upload";
public final static String RECEIVENOTIFICATION = "receive"; public final static String RECEIVENOTIFICATION = "receive";
public final static String HIGHPRIORITY = "highpriority"; public final static String HIGHPRIORITY = "highpriority";
} }
@@ -64,11 +67,16 @@ public class NotificationHelper {
.Builder(Channels.MEDIA_CONTROL, NotificationManagerCompat.IMPORTANCE_LOW) .Builder(Channels.MEDIA_CONTROL, NotificationManagerCompat.IMPORTANCE_LOW)
.setName(context.getString(R.string.notification_channel_media_control)) .setName(context.getString(R.string.notification_channel_media_control))
.build(); .build();
final NotificationChannelCompat fileTransferChannel = new NotificationChannelCompat final NotificationChannelCompat fileTransferDownloadChannel = new NotificationChannelCompat
.Builder(Channels.FILETRANSFER, NotificationManagerCompat.IMPORTANCE_LOW) .Builder(Channels.FILETRANSFER_DOWNLOAD, NotificationManagerCompat.IMPORTANCE_LOW)
.setName(context.getString(R.string.notification_channel_filetransfer)) .setName(context.getString(R.string.notification_channel_filetransfer))
.setVibrationEnabled(false) .setVibrationEnabled(false)
.build(); .build();
final NotificationChannelCompat fileTransferUploadChannel = new NotificationChannelCompat
.Builder(Channels.FILETRANSFER_UPLOAD, NotificationManagerCompat.IMPORTANCE_LOW)
.setName(context.getString(R.string.notification_channel_filetransfer_upload))
.setVibrationEnabled(false)
.build();
final NotificationChannelCompat receiveNotificationChannel = new NotificationChannelCompat final NotificationChannelCompat receiveNotificationChannel = new NotificationChannelCompat
.Builder(Channels.RECEIVENOTIFICATION, NotificationManagerCompat.IMPORTANCE_DEFAULT) .Builder(Channels.RECEIVENOTIFICATION, NotificationManagerCompat.IMPORTANCE_DEFAULT)
.setName(context.getString(R.string.notification_channel_receivenotification)) .setName(context.getString(R.string.notification_channel_receivenotification))
@@ -79,8 +87,9 @@ public class NotificationHelper {
.build(); .build();
final List<NotificationChannelCompat> channels = Arrays.asList(persistentChannel, final List<NotificationChannelCompat> channels = Arrays.asList(persistentChannel,
defaultChannel, mediaChannel, fileTransferChannel, receiveNotificationChannel, defaultChannel, mediaChannel, fileTransferDownloadChannel, fileTransferUploadChannel,
highPriorityChannel); receiveNotificationChannel, highPriorityChannel);
NotificationManagerCompat.from(context).createNotificationChannelsCompat(channels); NotificationManagerCompat.from(context).createNotificationChannelsCompat(channels);
// Delete any notification channels which weren't added. // Delete any notification channels which weren't added.

View File

@@ -46,7 +46,7 @@ class ReceiveNotification {
this.jobId = jobId; this.jobId = jobId;
notificationId = (int) System.currentTimeMillis(); notificationId = (int) System.currentTimeMillis();
notificationManager = ContextCompat.getSystemService(device.getContext(), NotificationManager.class); notificationManager = ContextCompat.getSystemService(device.getContext(), NotificationManager.class);
builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.Channels.FILETRANSFER) builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.Channels.FILETRANSFER_DOWNLOAD)
.setSmallIcon(android.R.drawable.stat_sys_download) .setSmallIcon(android.R.drawable.stat_sys_download)
.setAutoCancel(true) .setAutoCancel(true)
.setOngoing(true) .setOngoing(true)
@@ -86,7 +86,7 @@ class ReceiveNotification {
} }
public void setFinished(String message) { public void setFinished(String message) {
builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.Channels.FILETRANSFER); builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.Channels.FILETRANSFER_DOWNLOAD);
builder.setContentTitle(message) builder.setContentTitle(message)
.setTicker(message) .setTicker(message)
.setSmallIcon(android.R.drawable.stat_sys_download_done) .setSmallIcon(android.R.drawable.stat_sys_download_done)

View File

@@ -33,7 +33,7 @@ class UploadNotification {
notificationId = (int) System.currentTimeMillis(); notificationId = (int) System.currentTimeMillis();
notificationManager = ContextCompat.getSystemService(device.getContext(), NotificationManager.class); notificationManager = ContextCompat.getSystemService(device.getContext(), NotificationManager.class);
builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.Channels.FILETRANSFER) builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.Channels.FILETRANSFER_UPLOAD)
.setSmallIcon(android.R.drawable.stat_sys_upload) .setSmallIcon(android.R.drawable.stat_sys_upload)
.setAutoCancel(true) .setAutoCancel(true)
.setOngoing(true) .setOngoing(true)
@@ -64,7 +64,7 @@ class UploadNotification {
} }
public void setFinished(String message) { public void setFinished(String message) {
builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.Channels.FILETRANSFER); builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.Channels.FILETRANSFER_UPLOAD);
builder.setContentTitle(message) builder.setContentTitle(message)
.setTicker(message) .setTicker(message)
.setSmallIcon(android.R.drawable.stat_sys_upload_done) .setSmallIcon(android.R.drawable.stat_sys_upload_done)