Skip to content

Commit aba5edb

Browse files
committed
Show response handling errors
1 parent fd129a2 commit aba5edb

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

app/src/main/java/re/flande/xshare/UploadFile.kt

+14-8
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,21 @@ fun uploadFile(context: Context, uploader: Uploader, file: Uri) {
8080
nBuilder.setContentText(context.resources.getString(R.string.upload_failed))
8181
.setStyle(Notification.BigTextStyle().bigText(err.toString()))
8282
} else {
83-
val url = uploader.prepareUrl(d)
84-
val i = Intent(Intent.ACTION_VIEW, Uri.parse(url))
85-
val intent = PendingIntent.getActivity(context, 0, i, 0)
86-
nBuilder.setContentText(url)
87-
.setStyle(Notification.BigTextStyle().bigText(url))
88-
.setContentIntent(intent)
83+
try {
84+
val url = uploader.prepareUrl(d)
85+
val i = Intent(Intent.ACTION_VIEW, Uri.parse(url))
86+
val intent = PendingIntent.getActivity(context, 0, i, 0)
87+
nBuilder.setContentText(url)
88+
.setStyle(Notification.BigTextStyle().bigText(url))
89+
.setContentIntent(intent)
8990

90-
if (prefs.getBoolean("autoclip", false))
91-
clipManager.primaryClip = ClipData.newPlainText("URL", url)
91+
if (prefs.getBoolean("autoclip", false))
92+
clipManager.primaryClip = ClipData.newPlainText("URL", url)
93+
} catch(e: Exception) {
94+
val msg = context.resources.getString(R.string.response_text_and_error, d, e.toString())
95+
nBuilder.setContentText(context.resources.getString(R.string.response_handling_error))
96+
.setStyle(Notification.BigTextStyle().bigText(msg))
97+
}
9298
}
9399

94100
notifManager.notify(notifID, nBuilder.build())

app/src/main/res/values/strings.xml

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
<!-- Notifications -->
77
<string name="upload_complete">Upload complete.</string>
88
<string name="upload_failed">Upload failed.</string>
9+
<string name="response_handling_error">Response handling error.</string>
10+
11+
<string name="response_text_and_error">Response text:\n%1$s \nError:\n%2$s</string>
912

1013
<!-- Toasts -->
1114
<string name="failed_to_add">Failed to add %1$s: %2$s</string>

0 commit comments

Comments
 (0)