From c3b9002419b8a272c3cfd83ab37ec2c4d29f40be Mon Sep 17 00:00:00 2001 From: Vavassor Date: Sun, 2 Jul 2017 17:45:13 -0400 Subject: [PATCH] Fixes a crash where photoUploadUri can be nullified if the activity is evicted from memory while taking a picture, so when it resumes and recreates it no longer has a valid URI. Closes #326 --- .../java/com/keylesspalace/tusky/ComposeActivity.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index e9f2975c..7dc23abf 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -238,11 +238,13 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm if (previousInputContentInfo != null) { onCommitContentInternal(previousInputContentInfo, previousFlags); } + photoUploadUri = savedInstanceState.getParcelable("photoUploadUri"); } else { showMarkSensitive = false; startingVisibility = preferences.getString("rememberedVisibility", "public"); statusMarkSensitive = false; startingHideText = false; + photoUploadUri = null; } /* If the composer is started up as a reply to another post, override the "starting" state @@ -435,6 +437,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm } currentInputContentInfo = null; currentFlags = 0; + outState.putParcelable("photoUploadUri", photoUploadUri); super.onSaveInstanceState(outState); } @@ -821,6 +824,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm } } + @NonNull private File createNewImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date()); @@ -1092,11 +1096,11 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - if (requestCode == MEDIA_PICK_RESULT && resultCode == RESULT_OK && data != null) { + if (resultCode == RESULT_OK && requestCode == MEDIA_PICK_RESULT && data != null) { Uri uri = data.getData(); long mediaSize = MediaUtils.getMediaSize(getContentResolver(), uri); pickMedia(uri, mediaSize); - } else if (requestCode == MEDIA_TAKE_PHOTO_RESULT && resultCode == RESULT_OK) { + } else if (resultCode == RESULT_OK && requestCode == MEDIA_TAKE_PHOTO_RESULT) { long mediaSize = MediaUtils.getMediaSize(getContentResolver(), photoUploadUri); pickMedia(photoUploadUri, mediaSize); }