diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-10-14 14:13:46 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-10-14 14:13:46 +0000 |
commit | db818d8ca86cc603b2d7e9d8cb9b90e82ff83639 (patch) | |
tree | 09b5dffb9a3d68d5b8dd9bf4a3f9e7ad18e6ea11 /app | |
parent | 2f94ef3f9af0e6fc05e2b243b3f181e6769d8b2e (diff) | |
download | infinity-for-reddit-db818d8ca86cc603b2d7e9d8cb9b90e82ff83639.tar infinity-for-reddit-db818d8ca86cc603b2d7e9d8cb9b90e82ff83639.tar.gz infinity-for-reddit-db818d8ca86cc603b2d7e9d8cb9b90e82ff83639.tar.bz2 infinity-for-reddit-db818d8ca86cc603b2d7e9d8cb9b90e82ff83639.tar.lz infinity-for-reddit-db818d8ca86cc603b2d7e9d8cb9b90e82ff83639.tar.xz infinity-for-reddit-db818d8ca86cc603b2d7e9d8cb9b90e82ff83639.tar.zst infinity-for-reddit-db818d8ca86cc603b2d7e9d8cb9b90e82ff83639.zip |
Fix media cannot be opened by clicking the download finished notification. Fix random post or subreddit still showing after users go back from FetchRandomSubredditOrPostActivity.
Diffstat (limited to 'app')
4 files changed, 29 insertions, 15 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FetchRandomSubredditOrPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FetchRandomSubredditOrPostActivity.java index 422f326e..ebc87764 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FetchRandomSubredditOrPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FetchRandomSubredditOrPostActivity.java @@ -36,6 +36,7 @@ public class FetchRandomSubredditOrPostActivity extends BaseActivity { SharedPreferences mSharedPreferences; @Inject CustomThemeWrapper mCustomThemeWrapper; + private boolean isCanceled = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -51,23 +52,25 @@ public class FetchRandomSubredditOrPostActivity extends BaseActivity { || option == RandomBottomSheetFragment.RANDOM_NSFW_POST, new FetchPost.FetchRandomPostListener() { @Override public void fetchRandomPostSuccess(String postId, String subredditName) { - switch (option) { - case RandomBottomSheetFragment.RANDOM_SUBREDDIT: - case RandomBottomSheetFragment.RANDOM_NSFW_SUBREDDIT: { - Intent intent = new Intent(FetchRandomSubredditOrPostActivity.this, ViewSubredditDetailActivity.class); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditName); - startActivity(intent); - } - break; - case RandomBottomSheetFragment.RANDOM_POST: - case RandomBottomSheetFragment.RANDOM_NSFW_POST: - Intent intent = new Intent(FetchRandomSubredditOrPostActivity.this, ViewPostDetailActivity.class); - intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, postId); - startActivity(intent); + if (!isCanceled) { + switch (option) { + case RandomBottomSheetFragment.RANDOM_SUBREDDIT: + case RandomBottomSheetFragment.RANDOM_NSFW_SUBREDDIT: { + Intent intent = new Intent(FetchRandomSubredditOrPostActivity.this, ViewSubredditDetailActivity.class); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditName); + startActivity(intent); + } break; - } + case RandomBottomSheetFragment.RANDOM_POST: + case RandomBottomSheetFragment.RANDOM_NSFW_POST: + Intent intent = new Intent(FetchRandomSubredditOrPostActivity.this, ViewPostDetailActivity.class); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, postId); + startActivity(intent); + break; + } - finish(); + finish(); + } } @Override @@ -79,6 +82,12 @@ public class FetchRandomSubredditOrPostActivity extends BaseActivity { } @Override + public void onBackPressed() { + super.onBackPressed(); + isCanceled = true; + } + + @Override protected SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Service/DownloadMediaService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Service/DownloadMediaService.java index a1b625ef..e3f5e10e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Service/DownloadMediaService.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Service/DownloadMediaService.java @@ -302,6 +302,7 @@ public class DownloadMediaService extends Service { Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setDataAndType(destinationFileUri, mimeType); + intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); updateNotification(R.string.downloading_media_finished, fileName, pendingIntent); EventBus.getDefault().post(new DownloadMediaEvent(true)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Service/DownloadRedditVideoService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Service/DownloadRedditVideoService.java index 63b0e9ff..c8d31b8d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Service/DownloadRedditVideoService.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Service/DownloadRedditVideoService.java @@ -306,6 +306,7 @@ public class DownloadRedditVideoService extends Service { Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setDataAndType(destinationFileUri, "video/*"); + intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); updateNotification(R.string.downloading_reddit_video_finished, fileName, pendingIntent); EventBus.getDefault().post(new DownloadRedditVideoEvent(true)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Subreddit/ParseSubredditData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Subreddit/ParseSubredditData.java index 4eb9aecd..1a4bcb74 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Subreddit/ParseSubredditData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Subreddit/ParseSubredditData.java @@ -2,6 +2,8 @@ package ml.docilealligator.infinityforreddit.Subreddit; import android.os.AsyncTask; +import androidx.annotation.Nullable; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -20,6 +22,7 @@ class ParseSubredditData { new ParseSubredditListingDataAsyncTask(response, nsfw, parseSubredditListingDataListener).execute(); } + @Nullable private static SubredditData parseSubredditData(JSONObject subredditDataJsonObject, boolean nsfw) throws JSONException { boolean isNSFW = !subredditDataJsonObject.isNull(JSONUtils.OVER18_KEY) && subredditDataJsonObject.getBoolean(JSONUtils.OVER18_KEY); if (!nsfw && isNSFW) { |