settings to automatically fetch remote media when it fails (default: disabled)

This commit is contained in:
Thomas 2023-03-09 14:31:02 +01:00
parent 8c74343843
commit 68d9abea67
5 changed files with 44 additions and 8 deletions

View File

@ -186,6 +186,14 @@ public class FragmentMedia extends Fragment {
@Override @Override
public void onLoadFailed(@Nullable Drawable errorDrawable) { public void onLoadFailed(@Nullable Drawable errorDrawable) {
scheduleStartPostponedTransition(binding.mediaPicture); scheduleStartPostponedTransition(binding.mediaPicture);
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(); Toasty.error(requireActivity(), getString(R.string.toast_error_media), Toasty.LENGTH_SHORT).show();
binding.loadRemote.setVisibility(View.VISIBLE); binding.loadRemote.setVisibility(View.VISIBLE);
binding.loadRemote.setOnClickListener(v -> { binding.loadRemote.setOnClickListener(v -> {
@ -196,6 +204,8 @@ public class FragmentMedia extends Fragment {
}); });
} }
}
@Override @Override
public void onLoadCleared(@Nullable Drawable placeholder) { public void onLoadCleared(@Nullable Drawable placeholder) {
@ -259,6 +269,13 @@ public class FragmentMedia extends Fragment {
@Override @Override
public void onPlayerError(@NonNull PlaybackException error) { public void onPlayerError(@NonNull PlaybackException error) {
Player.Listener.super.onPlayerError(error); Player.Listener.super.onPlayerError(error);
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(); Toasty.error(requireActivity(), getString(R.string.toast_error_media), Toasty.LENGTH_SHORT).show();
binding.loadRemote.setVisibility(View.VISIBLE); binding.loadRemote.setVisibility(View.VISIBLE);
binding.loadRemote.setOnClickListener(v -> { binding.loadRemote.setOnClickListener(v -> {
@ -267,6 +284,7 @@ public class FragmentMedia extends Fragment {
loadVideo(attachment.remote_url, type); loadVideo(attachment.remote_url, type);
}); });
} }
}
}); });
} }

View File

@ -2,4 +2,5 @@
<resources> <resources>
<string name="fetch_remote_media">Automatically fetch remote media when they are not available</string>
</resources> </resources>

View File

@ -1127,6 +1127,8 @@
<string name="SET_DISPLAY_ALL_NOTIFICATIONS_TYPE" translatable="false">SET_DISPLAY_ALL_NOTIFICATIONS_TYPE</string> <string name="SET_DISPLAY_ALL_NOTIFICATIONS_TYPE" translatable="false">SET_DISPLAY_ALL_NOTIFICATIONS_TYPE</string>
<string name="SET_EXCLUDED_NOTIFICATIONS_TYPE" translatable="false">SET_EXCLUDED_NOTIFICATIONS_TYPE</string> <string name="SET_EXCLUDED_NOTIFICATIONS_TYPE" translatable="false">SET_EXCLUDED_NOTIFICATIONS_TYPE</string>
<string name="SET_EXPAND_MEDIA" translatable="false">SET_EXPAND_MEDIA</string> <string name="SET_EXPAND_MEDIA" translatable="false">SET_EXPAND_MEDIA</string>
<string name="SET_FETCH_REMOTE_MEDIA" translatable="false">SET_FETCH_REMOTE_MEDIA</string>
<string name="SET_GROUP_REBLOGS" translatable="false">SET_GROUP_REBLOGS</string> <string name="SET_GROUP_REBLOGS" translatable="false">SET_GROUP_REBLOGS</string>
<string name="SET_BOOST_ORIGINAL_DATE" translatable="false">SET_BOOST_ORIGINAL_DATE</string> <string name="SET_BOOST_ORIGINAL_DATE" translatable="false">SET_BOOST_ORIGINAL_DATE</string>
<string name="SET_TRUNCATE_LINKS" translatable="false">SET_TRUNCATE_LINKS</string> <string name="SET_TRUNCATE_LINKS" translatable="false">SET_TRUNCATE_LINKS</string>

View File

@ -25,6 +25,12 @@
app:key="@string/SET_EXPAND_MEDIA" app:key="@string/SET_EXPAND_MEDIA"
app:singleLineTitle="false" app:singleLineTitle="false"
app:title="@string/expand_image" /> app:title="@string/expand_image" />
<SwitchPreferenceCompat
android:defaultValue="false"
app:iconSpaceReserved="false"
app:key="@string/SET_FETCH_REMOTE_MEDIA"
app:singleLineTitle="false"
app:title="@string/fetch_remote_media" />
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="true" android:defaultValue="true"
app:iconSpaceReserved="false" app:iconSpaceReserved="false"

View File

@ -0,0 +1,9 @@
Added:
- Add a button to fetch remote media when it fails
- Add a settings to automatically fetch remote media when it fails (default: disabled)
Changed:
Fixed:
- Some settings not properly restored (multiple choices)