From 68d9abea679f71a84de6a772b749ecf0b09a0636 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 9 Mar 2023 14:31:02 +0100 Subject: [PATCH] settings to automatically fetch remote media when it fails (default: disabled) --- .../ui/fragment/media/FragmentMedia.java | 34 ++++++++++++++----- .../res/layouts/mastodon/values/strings.xml | 1 + app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_timelines.xml | 6 ++++ .../metadata/android/en/changelogs/484.txt | 9 +++++ 5 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 src/fdroid/fastlane/metadata/android/en/changelogs/484.txt diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMedia.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMedia.java index 14461db4..9c789698 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMedia.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMedia.java @@ -186,14 +186,24 @@ public class FragmentMedia extends Fragment { @Override public void onLoadFailed(@Nullable Drawable errorDrawable) { scheduleStartPostponedTransition(binding.mediaPicture); - Toasty.error(requireActivity(), getString(R.string.toast_error_media), Toasty.LENGTH_SHORT).show(); - binding.loadRemote.setVisibility(View.VISIBLE); - binding.loadRemote.setOnClickListener(v -> { + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); + boolean autofetch = sharedpreferences.getBoolean(getString(R.string.SET_FETCH_REMOTE_MEDIA), false); + if (autofetch) { binding.loadRemote.setVisibility(View.GONE); binding.loader.setVisibility(View.GONE); Glide.with(requireActivity()) .load(attachment.remote_url).into(binding.mediaPicture); - }); + } else { + Toasty.error(requireActivity(), getString(R.string.toast_error_media), Toasty.LENGTH_SHORT).show(); + binding.loadRemote.setVisibility(View.VISIBLE); + binding.loadRemote.setOnClickListener(v -> { + binding.loadRemote.setVisibility(View.GONE); + binding.loader.setVisibility(View.GONE); + Glide.with(requireActivity()) + .load(attachment.remote_url).into(binding.mediaPicture); + }); + } + } @Override @@ -259,13 +269,21 @@ public class FragmentMedia extends Fragment { @Override public void onPlayerError(@NonNull PlaybackException error) { Player.Listener.super.onPlayerError(error); - Toasty.error(requireActivity(), getString(R.string.toast_error_media), Toasty.LENGTH_SHORT).show(); - binding.loadRemote.setVisibility(View.VISIBLE); - binding.loadRemote.setOnClickListener(v -> { + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); + boolean autofetch = sharedpreferences.getBoolean(getString(R.string.SET_FETCH_REMOTE_MEDIA), false); + if (autofetch) { binding.loadRemote.setVisibility(View.GONE); binding.loader.setVisibility(View.GONE); loadVideo(attachment.remote_url, type); - }); + } else { + Toasty.error(requireActivity(), getString(R.string.toast_error_media), Toasty.LENGTH_SHORT).show(); + binding.loadRemote.setVisibility(View.VISIBLE); + binding.loadRemote.setOnClickListener(v -> { + binding.loadRemote.setVisibility(View.GONE); + binding.loader.setVisibility(View.GONE); + loadVideo(attachment.remote_url, type); + }); + } } }); diff --git a/app/src/main/res/layouts/mastodon/values/strings.xml b/app/src/main/res/layouts/mastodon/values/strings.xml index 78554f9e..714050d2 100644 --- a/app/src/main/res/layouts/mastodon/values/strings.xml +++ b/app/src/main/res/layouts/mastodon/values/strings.xml @@ -2,4 +2,5 @@ + Automatically fetch remote media when they are not available \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ba966313..6acb19fb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1127,6 +1127,8 @@ SET_DISPLAY_ALL_NOTIFICATIONS_TYPE SET_EXCLUDED_NOTIFICATIONS_TYPE SET_EXPAND_MEDIA + SET_FETCH_REMOTE_MEDIA + SET_GROUP_REBLOGS SET_BOOST_ORIGINAL_DATE SET_TRUNCATE_LINKS diff --git a/app/src/main/res/xml/pref_timelines.xml b/app/src/main/res/xml/pref_timelines.xml index d205ddaa..9ebc9db5 100644 --- a/app/src/main/res/xml/pref_timelines.xml +++ b/app/src/main/res/xml/pref_timelines.xml @@ -25,6 +25,12 @@ app:key="@string/SET_EXPAND_MEDIA" app:singleLineTitle="false" app:title="@string/expand_image" /> +