diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-11-06 11:33:45 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-11-06 11:33:45 +0000 |
commit | 4a67e0263962561be3fbaae5652a37fc73b9e7f2 (patch) | |
tree | 9a236722848f51dd985237b17bfb1f7241837eb1 /app/src/main/java | |
parent | 979ff84f46024d11f78fb1ed1cbeacf873bc29b8 (diff) | |
download | infinity-for-reddit-4a67e0263962561be3fbaae5652a37fc73b9e7f2.tar infinity-for-reddit-4a67e0263962561be3fbaae5652a37fc73b9e7f2.tar.gz infinity-for-reddit-4a67e0263962561be3fbaae5652a37fc73b9e7f2.tar.bz2 infinity-for-reddit-4a67e0263962561be3fbaae5652a37fc73b9e7f2.tar.lz infinity-for-reddit-4a67e0263962561be3fbaae5652a37fc73b9e7f2.tar.xz infinity-for-reddit-4a67e0263962561be3fbaae5652a37fc73b9e7f2.tar.zst infinity-for-reddit-4a67e0263962561be3fbaae5652a37fc73b9e7f2.zip |
Maybe fixed a lot of bugs in DownloadRedditVideoService, DownloadMediaService and GlideImageGetter. Fix gfycat video not playing when opening in compact layout.
Diffstat (limited to 'app/src/main/java')
5 files changed, 32 insertions, 13 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index ac223d3d..73d7bb8d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -2507,10 +2507,19 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView } case Post.VIDEO_TYPE: { Intent intent = new Intent(mActivity, ViewVideoActivity.class); - intent.setData(Uri.parse(post.getVideoUrl())); - intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); - intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName()); - intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId()); + if (post.isGfycat()) { + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); + intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId()); + } else if (post.isRedgifs()) { + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS); + intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId()); + } else { + intent.setData(Uri.parse(post.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); + intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName()); + intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId()); + } + intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, post.getTitle()); intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, post.isNSFW()); mActivity.startActivity(intent); break; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java index 553df57f..49da464a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -516,12 +516,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator { postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, filter, nsfw, subredditFilterList)).get(PostViewModel.class); } else { FetchSubredditFilters.fetchSubredditFilters(mRedditDataRoomDatabase, subredditFilters -> { - subredditFilterList = subredditFilters; - mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, - accountName, getResources().getConfiguration().locale, mSharedPreferences, - postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, filter, nsfw, subredditFilters)).get(PostViewModel.class); + if (activity != null) { + subredditFilterList = subredditFilters; + mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, + accountName, getResources().getConfiguration().locale, mSharedPreferences, + postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, filter, nsfw, subredditFilters)).get(PostViewModel.class); - bindPostViewModel(); + bindPostViewModel(); + } }); } } else { 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 30dfd001..49182903 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Service/DownloadMediaService.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Service/DownloadMediaService.java @@ -284,7 +284,8 @@ public class DownloadMediaService extends Service { downloadFinished(null, ERROR_FILE_CANNOT_DOWNLOAD); } }); - return super.onStartCommand(intent, flags, startId); + + return START_NOT_STICKY; } private Notification createNotification(String fileName) { 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 440441c7..575a0868 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Service/DownloadRedditVideoService.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Service/DownloadRedditVideoService.java @@ -568,7 +568,7 @@ public class DownloadRedditVideoService extends Service { muxer.stop(); muxer.release(); - } catch (IllegalStateException ignore) { + } catch (IllegalArgumentException ignore) { } catch (IOException e) { e.printStackTrace(); return false; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/GlideImageGetter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/GlideImageGetter.java index f3cef706..bd100469 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/GlideImageGetter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/GlideImageGetter.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Utils; import android.app.Activity; import android.content.Context; +import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.drawable.BitmapDrawable; @@ -56,7 +57,7 @@ public class GlideImageGetter implements Html.ImageGetter { BitmapDrawablePlaceholder drawable = new BitmapDrawablePlaceholder(textSize); Context context = container.get().getContext(); - if (!(context instanceof Activity && ((Activity) context).isDestroyed())) { + if (!(context instanceof Activity && (((Activity) context).isFinishing() || ((Activity) context).isDestroyed()))) { container.get().post(() -> Glide.with(context) .asBitmap() .load(source) @@ -119,7 +120,13 @@ public class GlideImageGetter implements Html.ImageGetter { @Override public void onResourceReady(@NonNull Bitmap bitmap, @Nullable Transition<? super Bitmap> transition) { if (container != null) { - setDrawable(new BitmapDrawable(container.get().getResources(), bitmap)); + TextView textView = container.get(); + if (textView != null) { + Resources resources = textView.getResources(); + if (resources != null) { + setDrawable(new BitmapDrawable(resources, bitmap)); + } + } } } |