From 11012e21e58a6e9b4ee7f8366e93121b659e01b8 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Sat, 4 Apr 2015 13:54:47 -0700 Subject: [PATCH] Added a different notification message for failed file transfers --- res/values/strings.xml | 1 + .../Plugins/SharePlugin/SharePlugin.java | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index c4d16a4d..6984ce6a 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -70,6 +70,7 @@ Sending file to %1s %1s Received file from %1s + Failed receiving file from %1s Tap to open \'%1s\' Sent file to %1s %1s diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java index 8de43ec4..26c27730 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java @@ -142,6 +142,7 @@ public class SharePlugin extends Plugin { @Override public void run() { OutputStream output = null; + boolean successul = true; try { output = new FileOutputStream(destinationFullPath.getPath()); byte data[] = new byte[1024]; @@ -165,6 +166,7 @@ public class SharePlugin extends Plugin { output.flush(); } catch (Exception e) { + successul = false; Log.e("SharePlugin", "Receiver thread exception"); e.printStackTrace(); } finally { @@ -193,23 +195,25 @@ public class SharePlugin extends Plugin { Resources res = context.getResources(); + String message = successul? res.getString(R.string.received_file_title, device.getName()) : res.getString(R.string.received_file_fail_title, device.getName()); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) - .setContentTitle(res.getString(R.string.received_file_title, device.getName())) - .setContentText(res.getString(R.string.received_file_text, filename)) - .setContentIntent(resultPendingIntent) - .setTicker(res.getString(R.string.received_file_title, device.getName())) + .setContentTitle(message) + .setTicker(message) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setAutoCancel(true); + if (successul) { + builder.setContentText(res.getString(R.string.received_file_text, filename)) + .setContentIntent(resultPendingIntent); + } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (prefs.getBoolean("share_notification_preference", true)) { builder.setDefaults(Notification.DEFAULT_ALL); } - Notification noti = builder.build(); - - notificationManager.notify(notificationId, noti); + Notification notification = builder.build(); + notificationManager.notify(notificationId, notification); } catch (Exception e) { Log.e("SharePlugin", "Receiver thread exception");