Button to load media from remote instance when it fails

fetch_indicator
Thomas 2 years ago
parent 7e2c9ab4a2
commit ca3142046b

@ -39,6 +39,7 @@ import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.upstream.DataSource;
@ -56,6 +57,7 @@ import app.fedilab.android.mastodon.client.entities.api.Attachment;
import app.fedilab.android.mastodon.helper.CacheDataSourceFactory;
import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.viewmodel.mastodon.TimelinesVM;
import es.dmoral.toasty.Toasty;
public class FragmentMedia extends Fragment {
@ -184,6 +186,14 @@ 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 -> {
binding.loadRemote.setVisibility(View.GONE);
binding.loader.setVisibility(View.GONE);
Glide.with(requireActivity())
.load(attachment.remote_url).into(binding.mediaPicture);
});
}
@Override
@ -245,6 +255,20 @@ public class FragmentMedia extends Fragment {
player.setMediaSource(videoSource);
player.prepare();
player.setPlayWhenReady(true);
player.addListener(new Player.Listener() {
@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 -> {
binding.loadRemote.setVisibility(View.GONE);
binding.loader.setVisibility(View.GONE);
loadVideo(attachment.remote_url, type);
});
}
});
}
@Override

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -65,5 +66,16 @@
android:layout_centerInParent="true"
android:visibility="gone" />
<com.google.android.material.button.MaterialButton
android:id="@+id/load_remote"
style="@style/Widget.Material3.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="@string/load_media_remotely"
android:visibility="gone"
tools:visibility="visible" />
</RelativeLayout>
</FrameLayout>

@ -1947,4 +1947,7 @@
<string name="updated_count">%d updated messages</string>
<string name="frequency_count_minutes">%d frequency (minutes)</string>
<string name="follows_you">Follows you</string>
<string name="load_media_remotely">Load media remotely</string>
<string name="toast_error_media">Media cannot be loaded!</string>
</resources>
Loading…
Cancel
Save