improve media

Media3
Thomas 10 months ago
parent e18db746a0
commit b16ecbbe72

@ -196,6 +196,9 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
binding.mediaDescriptionTranslated.setText(translated);
binding.mediaDescriptionTranslated.setVisibility(View.VISIBLE);
binding.mediaDescription.setVisibility(View.GONE);
if(mCurrentFragment != null) {
mCurrentFragment.toggleController(false);
}
} else {
Toasty.error(MediaActivity.this, getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show();
}
@ -203,10 +206,16 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
});
if (attachments.get(mediaPosition - 1).translation != null) {
binding.mediaDescription.setVisibility(View.GONE);
if(mCurrentFragment != null) {
mCurrentFragment.toggleController(false);
}
binding.mediaDescriptionTranslated.setText(attachments.get(mediaPosition - 1).translation);
binding.mediaDescriptionTranslated.setVisibility(View.VISIBLE);
} else {
binding.mediaDescription.setVisibility(View.VISIBLE);
if(mCurrentFragment != null) {
mCurrentFragment.toggleController(true);
}
binding.mediaDescriptionTranslated.setVisibility(View.GONE);
}
}
@ -236,6 +245,9 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
binding.mediaDescriptionTranslated.setText(translated);
binding.mediaDescriptionTranslated.setVisibility(View.VISIBLE);
binding.mediaDescription.setVisibility(View.GONE);
if(mCurrentFragment != null) {
mCurrentFragment.toggleController(false);
}
} else {
Toasty.error(MediaActivity.this, getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show();
}
@ -244,14 +256,23 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
if (!fullscreen) {
if (attachments.get(position).translation != null) {
binding.mediaDescription.setVisibility(View.GONE);
if(mCurrentFragment != null) {
mCurrentFragment.toggleController(false);
}
binding.mediaDescriptionTranslated.setText(attachments.get(position).translation);
binding.mediaDescriptionTranslated.setVisibility(View.VISIBLE);
} else {
binding.mediaDescription.setVisibility(View.VISIBLE);
if(mCurrentFragment != null) {
mCurrentFragment.toggleController(true);
}
binding.mediaDescriptionTranslated.setVisibility(View.GONE);
}
} else {
binding.mediaDescription.setVisibility(View.GONE);
if(mCurrentFragment != null) {
mCurrentFragment.toggleController(false);
}
binding.mediaDescriptionTranslated.setVisibility(View.GONE);
}
}
@ -407,10 +428,16 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
binding.mediaDescription.setText(linkify(MediaActivity.this, description), TextView.BufferType.SPANNABLE);
if (attachments.get(binding.mediaViewpager.getCurrentItem()).translation != null) {
binding.mediaDescription.setVisibility(View.GONE);
if(mCurrentFragment != null) {
mCurrentFragment.toggleController(false);
}
binding.mediaDescriptionTranslated.setText(attachments.get(binding.mediaViewpager.getCurrentItem()).translation);
binding.mediaDescriptionTranslated.setVisibility(View.VISIBLE);
} else {
binding.mediaDescription.setVisibility(View.VISIBLE);
if(mCurrentFragment != null) {
mCurrentFragment.toggleController(true);
}
binding.mediaDescriptionTranslated.setVisibility(View.GONE);
}
} else {
@ -422,12 +449,18 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
}
binding.mediaDescriptionTranslated.setVisibility(View.GONE);
binding.mediaDescription.setVisibility(View.GONE);
if(mCurrentFragment != null) {
mCurrentFragment.toggleController(false);
}
}
} else {
binding.originalMessage.setVisibility(View.INVISIBLE);
binding.translate.setVisibility(View.GONE);
binding.mediaDescriptionTranslated.setVisibility(View.GONE);
binding.mediaDescription.setVisibility(View.GONE);
if(mCurrentFragment != null) {
mCurrentFragment.toggleController(false);
}
}
}
@ -476,6 +509,9 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
if (!fullscreen) {
showSystemUI();
binding.mediaDescription.setVisibility(View.VISIBLE);
if(mCurrentFragment != null) {
mCurrentFragment.toggleController(true);
}
binding.translate.setVisibility(View.VISIBLE);
if (mediaFromProfile) {
binding.originalMessage.setVisibility(View.VISIBLE);
@ -483,6 +519,9 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
} else {
hideSystemUI();
binding.mediaDescription.setVisibility(View.GONE);
if(mCurrentFragment != null) {
mCurrentFragment.toggleController(false);
}
binding.translate.setVisibility(View.GONE);
binding.originalMessage.setVisibility(View.INVISIBLE);
}

@ -22,6 +22,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -30,12 +31,14 @@ import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.OptIn;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.media3.common.MediaItem;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.Player;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.datasource.DataSource;
import androidx.media3.datasource.DefaultDataSource;
import androidx.media3.exoplayer.ExoPlayer;
@ -90,6 +93,15 @@ public class FragmentMedia extends Fragment {
}
@OptIn(markerClass = UnstableApi.class)
public void toggleController(boolean display) {
if(display) {
binding.controls.show();
} else {
binding.controls.hide();
}
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
@ -275,14 +287,6 @@ public class FragmentMedia extends Fragment {
player.setRepeatMode(Player.REPEAT_MODE_ONE);
binding.mediaVideo.setUseController(false);
}
binding.mediaVideo.setOnTouchListener((view, motionEvent) -> {
if (binding.controls.getVisibility() != View.VISIBLE) {
binding.controls.setVisibility(View.VISIBLE);
final Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(() -> binding.controls.setVisibility(View.GONE), 2000);
}
return false;
});
binding.mediaVideo.setPlayer(player);
binding.controls.setPlayer(player);
binding.loader.setVisibility(View.GONE);

@ -209,7 +209,6 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
private Status status;
private int flags;
private boolean humanInteraction;
private MediaSession mediaSession;
public static void hideKeyboard(Activity activity) {
if (activity != null && activity.getWindow() != null) {
activity.getWindow().getDecorView();
@ -1559,7 +1558,6 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
binding = null;
if (player != null) {
player.release();
mediaSession = null;
}
unregisterReceiver();
}
@ -1639,7 +1637,6 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
if (playInMinimized && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && player != null) {
isPlayInMinimized = true;
setRequestedOrientationCustom(initialOrientation);
mediaSession = new MediaSession.Builder(this, player).build();
PlayerControlView controlView = binding.doubleTapPlayerView.findViewById(R.id.exo_controller);
controlView.hide();
binding.doubleTapPlayerView.setControllerAutoShow(false);
@ -2225,7 +2222,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
if (fullScreenButton != null) {
fullScreenButton.setOnClickListener(v -> toggleFullScreen());
}
ImageButton playButton = controlView.findViewById(R.id.exo_play);
ImageButton playButton = controlView.findViewById(R.id.exo_play_pause);
if (playButton != null) {
playButton.setOnClickListener(v -> {
if (autoFullscreen && !fullScreenMode) {

@ -78,7 +78,7 @@
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="50dp"
app:show_timeout="2000" />
app:show_timeout="0" />
</FrameLayout>

@ -40,12 +40,9 @@
style="@style/ExoMediaButton.Previous" />
<ImageButton
android:id="@id/exo_play"
style="@style/ExoMediaButton.Play" />
<ImageButton
android:id="@id/exo_pause"
android:id="@id/exo_play_pause"
style="@style/ExoMediaButton.Pause" />

Loading…
Cancel
Save