Browse Source

Fix post video timeline issues

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
a271ba5ab7
  1. 49
      app/src/main/java/awais/instagrabber/adapters/viewholder/SliderVideoViewHolder.java
  2. 37
      app/src/main/java/awais/instagrabber/customviews/VideoPlayerViewHelper.java
  3. 47
      app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java

49
app/src/main/java/awais/instagrabber/adapters/viewholder/SliderVideoViewHolder.java

@ -1,6 +1,8 @@
package awais.instagrabber.adapters.viewholder;
import android.annotation.SuppressLint;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
@ -28,6 +30,14 @@ public class SliderVideoViewHolder extends SliderItemViewHolder {
private final LayoutVideoPlayerWithThumbnailBinding binding;
private final LayoutExoCustomControlsBinding controlsBinding;
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;
@SuppressLint("ClickableViewAccessibility")
@ -39,26 +49,24 @@ public class SliderVideoViewHolder extends SliderItemViewHolder {
this.binding = binding;
this.controlsBinding = controlsBinding;
this.loadVideoOnItemClick = loadVideoOnItemClick;
if (onVerticalDragListener != null) {
final VerticalDragHelper thumbnailVerticalDragHelper = new VerticalDragHelper(binding.thumbnailParent);
final VerticalDragHelper playerVerticalDragHelper = new VerticalDragHelper(binding.playerView);
thumbnailVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
playerVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
binding.thumbnailParent.setOnTouchListener((v, event) -> {
final boolean onDragTouch = thumbnailVerticalDragHelper.onDragTouch(event);
if (onDragTouch) {
return true;
}
return thumbnailVerticalDragHelper.onGestureTouchEvent(event);
});
binding.playerView.setOnTouchListener((v, event) -> {
final boolean onDragTouch = playerVerticalDragHelper.onDragTouch(event);
if (onDragTouch) {
return true;
}
return playerVerticalDragHelper.onGestureTouchEvent(event);
});
}
// if (onVerticalDragListener != null) {
// final VerticalDragHelper thumbnailVerticalDragHelper = new VerticalDragHelper(binding.thumbnailParent);
// final VerticalDragHelper playerVerticalDragHelper = new VerticalDragHelper(binding.playerView);
// thumbnailVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
// playerVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
// binding.thumbnailParent.setOnTouchListener((v, event) -> {
// final boolean onDragTouch = thumbnailVerticalDragHelper.onDragTouch(event);
// if (onDragTouch) {
// return true;
// }
// return thumbnailVerticalDragHelper.onGestureTouchEvent(event);
// });
// }
final GestureDetector gestureDetector = new GestureDetector(itemView.getContext(), videoPlayerViewGestureListener);
binding.playerView.setOnTouchListener((v, event) -> {
gestureDetector.onTouchEvent(event);
return true;
});
}
public void bind(@NonNull final Media media,
@ -116,6 +124,7 @@ public class SliderVideoViewHolder extends SliderItemViewHolder {
videoUrl = videoVersion.getUrl();
}
}
if (videoUrl == null) return;
videoPlayerViewHelper = new VideoPlayerViewHelper(binding.getRoot().getContext(),
binding,
videoUrl,

37
app/src/main/java/awais/instagrabber/customviews/VideoPlayerViewHelper.java

@ -57,9 +57,9 @@ public class VideoPlayerViewHelper implements Player.EventListener {
private final DefaultDataSourceFactory dataSourceFactory;
private SimpleExoPlayer player;
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() {
@Override
public void onPlaybackStateChanged(final int state) {
@ -79,6 +79,11 @@ public class VideoPlayerViewHelper implements Player.EventListener {
@Override
public void onPlayWhenReadyChanged(final boolean playWhenReady, final int reason) {
updatePlayPauseDrawable(playWhenReady);
if (positionUpdateHandler == null || positionChecker == null) return;
if (playWhenReady) {
positionUpdateHandler.removeCallbacks(positionChecker);
positionUpdateHandler.postDelayed(positionChecker, INITIAL_DELAY);
}
}
};
private final AudioListener audioListener = new AudioListener() {
@ -191,6 +196,7 @@ public class VideoPlayerViewHelper implements Player.EventListener {
player = new SimpleExoPlayer.Builder(context)
.setLooper(Looper.getMainLooper())
.build();
positionUpdateHandler = new Handler();
positionChecker = new PositionCheckRunnable(positionUpdateHandler,
player,
controlsBinding.timeline,
@ -353,19 +359,27 @@ public class VideoPlayerViewHelper implements Player.EventListener {
// }
public void releasePlayer() {
if (player == null) return;
player.release();
player = null;
if (positionUpdateHandler != null && positionChecker != null) {
positionUpdateHandler.removeCallbacks(positionChecker);
if (player != null) {
player.release();
player = null;
}
if (positionUpdateHandler != null) {
if (positionChecker != null) {
positionUpdateHandler.removeCallbacks(positionChecker);
positionChecker = null;
}
positionUpdateHandler = null;
}
}
public void pause() {
if (player == null) return;
player.pause();
if (positionUpdateHandler != null && positionChecker != null) {
positionUpdateHandler.removeCallbacks(positionChecker);
if (player != null) {
player.pause();
}
if (positionUpdateHandler != null) {
if (positionChecker != null) {
positionUpdateHandler.removeCallbacks(positionChecker);
}
}
}
@ -412,6 +426,7 @@ public class VideoPlayerViewHelper implements Player.EventListener {
@Override
public void run() {
if (positionUpdateHandler == null) return;
positionUpdateHandler.removeCallbacks(this);
if (player == null) return;
final long currentPosition = player.getCurrentPosition();

47
app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java

@ -79,7 +79,6 @@ import awais.instagrabber.adapters.SliderCallbackAdapter;
import awais.instagrabber.adapters.SliderItemsAdapter;
import awais.instagrabber.adapters.viewholder.SliderVideoViewHolder;
import awais.instagrabber.customviews.SharedElementTransitionDialogFragment;
import awais.instagrabber.customviews.VerticalDragHelper;
import awais.instagrabber.customviews.VerticalImageSpan;
import awais.instagrabber.customviews.VideoPlayerCallbackAdapter;
import awais.instagrabber.customviews.VideoPlayerViewHelper;
@ -143,6 +142,13 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment im
// clear result
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() {
//
@ -253,7 +259,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment im
setStyle(DialogFragment.STYLE_NO_FRAME, R.style.PostViewV2Style);
viewModel = new ViewModelProvider(this).get(PostViewV2ViewModel.class);
captionState = settingsHelper.getBoolean(Constants.SHOW_CAPTIONS) ?
BottomSheetBehavior.STATE_COLLAPSED : BottomSheetBehavior.STATE_HIDDEN;
BottomSheetBehavior.STATE_COLLAPSED : BottomSheetBehavior.STATE_HIDDEN;
}
@Nullable
@ -1143,26 +1149,31 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment im
addSharedElement(sharedMainPostElement, binding.videoPost.thumbnailParent);
}
binding.videoPost.root.setVisibility(View.VISIBLE);
final VerticalDragHelper thumbnailVerticalDragHelper = new VerticalDragHelper(binding.videoPost.thumbnailParent);
final VerticalDragHelper playerVerticalDragHelper = new VerticalDragHelper(binding.videoPost.playerView);
// final VerticalDragHelper thumbnailVerticalDragHelper = new VerticalDragHelper(binding.videoPost.thumbnailParent);
// final VerticalDragHelper playerVerticalDragHelper = new VerticalDragHelper(binding.videoPost.playerView);
// thumbnailVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
// playerVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
enablePlayerControls(true);
binding.videoPost.thumbnailParent.setOnTouchListener((v, event) -> {
final boolean onDragTouch = thumbnailVerticalDragHelper.onDragTouch(event);
if (onDragTouch) {
return true;
}
return thumbnailVerticalDragHelper.onGestureTouchEvent(event);
});
// binding.videoPost.thumbnailParent.setOnTouchListener((v, event) -> {
// final boolean onDragTouch = thumbnailVerticalDragHelper.onDragTouch(event);
// if (onDragTouch) {
// return true;
// }
// return thumbnailVerticalDragHelper.onGestureTouchEvent(event);
// });
// binding.videoPost.playerView.setOnTouchListener((v, event) -> {
// final boolean onDragTouch = playerVerticalDragHelper.onDragTouch(event);
// if (onDragTouch) {
// return true;
// }
// return playerVerticalDragHelper.onGestureTouchEvent(event);
// });
binding.videoPost.playerView.setOnClickListener(v -> toggleDetails());
final GestureDetector gestureDetector = new GestureDetector(context, videoPlayerViewGestureListener);
binding.videoPost.playerView.setOnTouchListener((v, event) -> {
final boolean onDragTouch = playerVerticalDragHelper.onDragTouch(event);
if (onDragTouch) {
return true;
}
return playerVerticalDragHelper.onGestureTouchEvent(event);
gestureDetector.onTouchEvent(event);
return true;
});
binding.videoPost.playerView.setOnClickListener(v -> toggleDetails());
final float vol = settingsHelper.getBoolean(Constants.MUTED_VIDEOS) ? 0f : 1f;
final VideoPlayerViewHelper.VideoPlayerCallback videoPlayerCallback = new VideoPlayerCallbackAdapter() {
@Override
@ -1413,6 +1424,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment im
binding.share.setVisibility(View.GONE);
binding.download.setVisibility(View.GONE);
binding.mediaCounter.setVisibility(View.GONE);
binding.viewsCount.setVisibility(View.GONE);
final List<Integer> options = viewModel.getOptions().getValue();
if (options != null && !options.isEmpty()) {
binding.options.setVisibility(View.GONE);
@ -1455,6 +1467,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment im
}
if (video) {
binding.playerControlsToggle.setVisibility(View.VISIBLE);
binding.viewsCount.setVisibility(View.VISIBLE);
}
if (wasControlsVisible) {
showPlayerControls();

Loading…
Cancel
Save