From 3247cc6f35303511a8faeead4ad0d539a5f71a2d Mon Sep 17 00:00:00 2001 From: pandasoft0 Date: Fri, 12 Apr 2019 23:10:52 +0300 Subject: [PATCH] Cancel media uploads when closing ComposeActivity #838 (#1189) * Cancel media uploads on remove the draft message * Fix formatting --- .../java/com/keylesspalace/tusky/ComposeActivity.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index 40570e70..882db4eb 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -1539,13 +1539,21 @@ public final class ComposeActivity new AlertDialog.Builder(this) .setMessage(R.string.compose_save_draft) .setPositiveButton(R.string.action_save, (d, w) -> saveDraftAndFinish()) - .setNegativeButton(R.string.action_delete, (d, w) -> finishWithoutSlideOutAnimation()) + .setNegativeButton(R.string.action_delete, (d, w) -> deleteDraftAndFinish()) .show(); } else { finishWithoutSlideOutAnimation(); } } + private void deleteDraftAndFinish() { + for (QueuedMedia media : mediaQueued) { + if (media.uploadRequest != null) + media.uploadRequest.cancel(); + } + finishWithoutSlideOutAnimation(); + } + private void saveDraftAndFinish() { ArrayList mediaUris = new ArrayList<>(); ArrayList mediaDescriptions = new ArrayList<>();