mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 22:57:29 +00:00
Fix post video timeline issues
This commit is contained in:
parent
50fd282ab2
commit
a271ba5ab7
@ -1,6 +1,8 @@
|
|||||||
package awais.instagrabber.adapters.viewholder;
|
package awais.instagrabber.adapters.viewholder;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.view.GestureDetector;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@ -28,6 +30,14 @@ public class SliderVideoViewHolder extends SliderItemViewHolder {
|
|||||||
private final LayoutVideoPlayerWithThumbnailBinding binding;
|
private final LayoutVideoPlayerWithThumbnailBinding binding;
|
||||||
private final LayoutExoCustomControlsBinding controlsBinding;
|
private final LayoutExoCustomControlsBinding controlsBinding;
|
||||||
private final boolean loadVideoOnItemClick;
|
private final boolean loadVideoOnItemClick;
|
||||||
|
private final GestureDetector.OnGestureListener videoPlayerViewGestureListener = new GestureDetector.SimpleOnGestureListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onSingleTapConfirmed(final MotionEvent e) {
|
||||||
|
binding.playerView.performClick();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private VideoPlayerViewHelper videoPlayerViewHelper;
|
private VideoPlayerViewHelper videoPlayerViewHelper;
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@ -39,27 +49,25 @@ public class SliderVideoViewHolder extends SliderItemViewHolder {
|
|||||||
this.binding = binding;
|
this.binding = binding;
|
||||||
this.controlsBinding = controlsBinding;
|
this.controlsBinding = controlsBinding;
|
||||||
this.loadVideoOnItemClick = loadVideoOnItemClick;
|
this.loadVideoOnItemClick = loadVideoOnItemClick;
|
||||||
if (onVerticalDragListener != null) {
|
// if (onVerticalDragListener != null) {
|
||||||
final VerticalDragHelper thumbnailVerticalDragHelper = new VerticalDragHelper(binding.thumbnailParent);
|
// final VerticalDragHelper thumbnailVerticalDragHelper = new VerticalDragHelper(binding.thumbnailParent);
|
||||||
final VerticalDragHelper playerVerticalDragHelper = new VerticalDragHelper(binding.playerView);
|
// final VerticalDragHelper playerVerticalDragHelper = new VerticalDragHelper(binding.playerView);
|
||||||
thumbnailVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
|
// thumbnailVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
|
||||||
playerVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
|
// playerVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
|
||||||
binding.thumbnailParent.setOnTouchListener((v, event) -> {
|
// binding.thumbnailParent.setOnTouchListener((v, event) -> {
|
||||||
final boolean onDragTouch = thumbnailVerticalDragHelper.onDragTouch(event);
|
// final boolean onDragTouch = thumbnailVerticalDragHelper.onDragTouch(event);
|
||||||
if (onDragTouch) {
|
// if (onDragTouch) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
return thumbnailVerticalDragHelper.onGestureTouchEvent(event);
|
// return thumbnailVerticalDragHelper.onGestureTouchEvent(event);
|
||||||
});
|
// });
|
||||||
|
// }
|
||||||
|
final GestureDetector gestureDetector = new GestureDetector(itemView.getContext(), videoPlayerViewGestureListener);
|
||||||
binding.playerView.setOnTouchListener((v, event) -> {
|
binding.playerView.setOnTouchListener((v, event) -> {
|
||||||
final boolean onDragTouch = playerVerticalDragHelper.onDragTouch(event);
|
gestureDetector.onTouchEvent(event);
|
||||||
if (onDragTouch) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
return playerVerticalDragHelper.onGestureTouchEvent(event);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void bind(@NonNull final Media media,
|
public void bind(@NonNull final Media media,
|
||||||
final int position,
|
final int position,
|
||||||
@ -116,6 +124,7 @@ public class SliderVideoViewHolder extends SliderItemViewHolder {
|
|||||||
videoUrl = videoVersion.getUrl();
|
videoUrl = videoVersion.getUrl();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (videoUrl == null) return;
|
||||||
videoPlayerViewHelper = new VideoPlayerViewHelper(binding.getRoot().getContext(),
|
videoPlayerViewHelper = new VideoPlayerViewHelper(binding.getRoot().getContext(),
|
||||||
binding,
|
binding,
|
||||||
videoUrl,
|
videoUrl,
|
||||||
|
@ -57,9 +57,9 @@ public class VideoPlayerViewHelper implements Player.EventListener {
|
|||||||
private final DefaultDataSourceFactory dataSourceFactory;
|
private final DefaultDataSourceFactory dataSourceFactory;
|
||||||
private SimpleExoPlayer player;
|
private SimpleExoPlayer player;
|
||||||
private PopupMenu speedPopup;
|
private PopupMenu speedPopup;
|
||||||
private Runnable positionChecker;
|
private PositionCheckRunnable positionChecker;
|
||||||
|
private Handler positionUpdateHandler;
|
||||||
|
|
||||||
private final Handler positionUpdateHandler = new Handler();
|
|
||||||
private final Player.EventListener listener = new Player.EventListener() {
|
private final Player.EventListener listener = new Player.EventListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onPlaybackStateChanged(final int state) {
|
public void onPlaybackStateChanged(final int state) {
|
||||||
@ -79,6 +79,11 @@ public class VideoPlayerViewHelper implements Player.EventListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onPlayWhenReadyChanged(final boolean playWhenReady, final int reason) {
|
public void onPlayWhenReadyChanged(final boolean playWhenReady, final int reason) {
|
||||||
updatePlayPauseDrawable(playWhenReady);
|
updatePlayPauseDrawable(playWhenReady);
|
||||||
|
if (positionUpdateHandler == null || positionChecker == null) return;
|
||||||
|
if (playWhenReady) {
|
||||||
|
positionUpdateHandler.removeCallbacks(positionChecker);
|
||||||
|
positionUpdateHandler.postDelayed(positionChecker, INITIAL_DELAY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private final AudioListener audioListener = new AudioListener() {
|
private final AudioListener audioListener = new AudioListener() {
|
||||||
@ -191,6 +196,7 @@ public class VideoPlayerViewHelper implements Player.EventListener {
|
|||||||
player = new SimpleExoPlayer.Builder(context)
|
player = new SimpleExoPlayer.Builder(context)
|
||||||
.setLooper(Looper.getMainLooper())
|
.setLooper(Looper.getMainLooper())
|
||||||
.build();
|
.build();
|
||||||
|
positionUpdateHandler = new Handler();
|
||||||
positionChecker = new PositionCheckRunnable(positionUpdateHandler,
|
positionChecker = new PositionCheckRunnable(positionUpdateHandler,
|
||||||
player,
|
player,
|
||||||
controlsBinding.timeline,
|
controlsBinding.timeline,
|
||||||
@ -353,21 +359,29 @@ public class VideoPlayerViewHelper implements Player.EventListener {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
public void releasePlayer() {
|
public void releasePlayer() {
|
||||||
if (player == null) return;
|
if (player != null) {
|
||||||
player.release();
|
player.release();
|
||||||
player = null;
|
player = null;
|
||||||
if (positionUpdateHandler != null && positionChecker != null) {
|
}
|
||||||
|
if (positionUpdateHandler != null) {
|
||||||
|
if (positionChecker != null) {
|
||||||
positionUpdateHandler.removeCallbacks(positionChecker);
|
positionUpdateHandler.removeCallbacks(positionChecker);
|
||||||
|
positionChecker = null;
|
||||||
|
}
|
||||||
|
positionUpdateHandler = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause() {
|
public void pause() {
|
||||||
if (player == null) return;
|
if (player != null) {
|
||||||
player.pause();
|
player.pause();
|
||||||
if (positionUpdateHandler != null && positionChecker != null) {
|
}
|
||||||
|
if (positionUpdateHandler != null) {
|
||||||
|
if (positionChecker != null) {
|
||||||
positionUpdateHandler.removeCallbacks(positionChecker);
|
positionUpdateHandler.removeCallbacks(positionChecker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void resetTimeline() {
|
public void resetTimeline() {
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
@ -412,6 +426,7 @@ public class VideoPlayerViewHelper implements Player.EventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
if (positionUpdateHandler == null) return;
|
||||||
positionUpdateHandler.removeCallbacks(this);
|
positionUpdateHandler.removeCallbacks(this);
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
final long currentPosition = player.getCurrentPosition();
|
final long currentPosition = player.getCurrentPosition();
|
||||||
|
@ -79,7 +79,6 @@ import awais.instagrabber.adapters.SliderCallbackAdapter;
|
|||||||
import awais.instagrabber.adapters.SliderItemsAdapter;
|
import awais.instagrabber.adapters.SliderItemsAdapter;
|
||||||
import awais.instagrabber.adapters.viewholder.SliderVideoViewHolder;
|
import awais.instagrabber.adapters.viewholder.SliderVideoViewHolder;
|
||||||
import awais.instagrabber.customviews.SharedElementTransitionDialogFragment;
|
import awais.instagrabber.customviews.SharedElementTransitionDialogFragment;
|
||||||
import awais.instagrabber.customviews.VerticalDragHelper;
|
|
||||||
import awais.instagrabber.customviews.VerticalImageSpan;
|
import awais.instagrabber.customviews.VerticalImageSpan;
|
||||||
import awais.instagrabber.customviews.VideoPlayerCallbackAdapter;
|
import awais.instagrabber.customviews.VideoPlayerCallbackAdapter;
|
||||||
import awais.instagrabber.customviews.VideoPlayerViewHelper;
|
import awais.instagrabber.customviews.VideoPlayerViewHelper;
|
||||||
@ -143,6 +142,13 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment im
|
|||||||
// clear result
|
// clear result
|
||||||
backStackSavedStateResultLiveData.postValue(null);
|
backStackSavedStateResultLiveData.postValue(null);
|
||||||
};
|
};
|
||||||
|
private final GestureDetector.OnGestureListener videoPlayerViewGestureListener = new GestureDetector.SimpleOnGestureListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onSingleTapConfirmed(final MotionEvent e) {
|
||||||
|
binding.videoPost.playerView.performClick();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// private final VerticalDragHelper.OnVerticalDragListener onVerticalDragListener = new VerticalDragHelper.OnVerticalDragListener() {
|
// private final VerticalDragHelper.OnVerticalDragListener onVerticalDragListener = new VerticalDragHelper.OnVerticalDragListener() {
|
||||||
//
|
//
|
||||||
@ -1143,26 +1149,31 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment im
|
|||||||
addSharedElement(sharedMainPostElement, binding.videoPost.thumbnailParent);
|
addSharedElement(sharedMainPostElement, binding.videoPost.thumbnailParent);
|
||||||
}
|
}
|
||||||
binding.videoPost.root.setVisibility(View.VISIBLE);
|
binding.videoPost.root.setVisibility(View.VISIBLE);
|
||||||
final VerticalDragHelper thumbnailVerticalDragHelper = new VerticalDragHelper(binding.videoPost.thumbnailParent);
|
// final VerticalDragHelper thumbnailVerticalDragHelper = new VerticalDragHelper(binding.videoPost.thumbnailParent);
|
||||||
final VerticalDragHelper playerVerticalDragHelper = new VerticalDragHelper(binding.videoPost.playerView);
|
// final VerticalDragHelper playerVerticalDragHelper = new VerticalDragHelper(binding.videoPost.playerView);
|
||||||
// thumbnailVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
|
// thumbnailVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
|
||||||
// playerVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
|
// playerVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
|
||||||
enablePlayerControls(true);
|
enablePlayerControls(true);
|
||||||
binding.videoPost.thumbnailParent.setOnTouchListener((v, event) -> {
|
// binding.videoPost.thumbnailParent.setOnTouchListener((v, event) -> {
|
||||||
final boolean onDragTouch = thumbnailVerticalDragHelper.onDragTouch(event);
|
// final boolean onDragTouch = thumbnailVerticalDragHelper.onDragTouch(event);
|
||||||
if (onDragTouch) {
|
// if (onDragTouch) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
return thumbnailVerticalDragHelper.onGestureTouchEvent(event);
|
// return thumbnailVerticalDragHelper.onGestureTouchEvent(event);
|
||||||
});
|
// });
|
||||||
binding.videoPost.playerView.setOnTouchListener((v, event) -> {
|
// binding.videoPost.playerView.setOnTouchListener((v, event) -> {
|
||||||
final boolean onDragTouch = playerVerticalDragHelper.onDragTouch(event);
|
// final boolean onDragTouch = playerVerticalDragHelper.onDragTouch(event);
|
||||||
if (onDragTouch) {
|
// if (onDragTouch) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
return playerVerticalDragHelper.onGestureTouchEvent(event);
|
// return playerVerticalDragHelper.onGestureTouchEvent(event);
|
||||||
});
|
// });
|
||||||
binding.videoPost.playerView.setOnClickListener(v -> toggleDetails());
|
binding.videoPost.playerView.setOnClickListener(v -> toggleDetails());
|
||||||
|
final GestureDetector gestureDetector = new GestureDetector(context, videoPlayerViewGestureListener);
|
||||||
|
binding.videoPost.playerView.setOnTouchListener((v, event) -> {
|
||||||
|
gestureDetector.onTouchEvent(event);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
final float vol = settingsHelper.getBoolean(Constants.MUTED_VIDEOS) ? 0f : 1f;
|
final float vol = settingsHelper.getBoolean(Constants.MUTED_VIDEOS) ? 0f : 1f;
|
||||||
final VideoPlayerViewHelper.VideoPlayerCallback videoPlayerCallback = new VideoPlayerCallbackAdapter() {
|
final VideoPlayerViewHelper.VideoPlayerCallback videoPlayerCallback = new VideoPlayerCallbackAdapter() {
|
||||||
@Override
|
@Override
|
||||||
@ -1413,6 +1424,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment im
|
|||||||
binding.share.setVisibility(View.GONE);
|
binding.share.setVisibility(View.GONE);
|
||||||
binding.download.setVisibility(View.GONE);
|
binding.download.setVisibility(View.GONE);
|
||||||
binding.mediaCounter.setVisibility(View.GONE);
|
binding.mediaCounter.setVisibility(View.GONE);
|
||||||
|
binding.viewsCount.setVisibility(View.GONE);
|
||||||
final List<Integer> options = viewModel.getOptions().getValue();
|
final List<Integer> options = viewModel.getOptions().getValue();
|
||||||
if (options != null && !options.isEmpty()) {
|
if (options != null && !options.isEmpty()) {
|
||||||
binding.options.setVisibility(View.GONE);
|
binding.options.setVisibility(View.GONE);
|
||||||
@ -1455,6 +1467,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment im
|
|||||||
}
|
}
|
||||||
if (video) {
|
if (video) {
|
||||||
binding.playerControlsToggle.setVisibility(View.VISIBLE);
|
binding.playerControlsToggle.setVisibility(View.VISIBLE);
|
||||||
|
binding.viewsCount.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
if (wasControlsVisible) {
|
if (wasControlsVisible) {
|
||||||
showPlayerControls();
|
showPlayerControls();
|
||||||
|
Loading…
Reference in New Issue
Block a user