From 4a67e0263962561be3fbaae5652a37fc73b9e7f2 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 6 Nov 2020 19:33:45 +0800 Subject: Maybe fixed a lot of bugs in DownloadRedditVideoService, DownloadMediaService and GlideImageGetter. Fix gfycat video not playing when opening in compact layout. --- app/src/main/AndroidManifest.xml | 2 +- .../Adapter/PostRecyclerViewAdapter.java | 17 +++++++++++++---- .../infinityforreddit/Fragment/PostFragment.java | 12 +++++++----- .../infinityforreddit/Service/DownloadMediaService.java | 3 ++- .../Service/DownloadRedditVideoService.java | 2 +- .../infinityforreddit/Utils/GlideImageGetter.java | 11 +++++++++-- 6 files changed, 33 insertions(+), 14 deletions(-) (limited to 'app/src') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d636665f..b174ee0e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -365,7 +365,7 @@ { - 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 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)); + } + } } } -- cgit v1.2.3