Commit e68ab515 authored by Geoffrey Métais's avatar Geoffrey Métais

Improve audio player gestures

See #613
parent 390a3898
......@@ -32,7 +32,6 @@ import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
......@@ -59,6 +58,7 @@ import org.videolan.vlc.ScanProgress;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.audio.AudioPlayer;
import org.videolan.vlc.gui.browser.StorageBrowserFragment;
import org.videolan.vlc.gui.helpers.BottomSheetBehavior;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.interfaces.IRefreshable;
import org.videolan.vlc.media.PlaylistManager;
......@@ -76,7 +76,7 @@ public class AudioPlayerContainerActivity extends BaseActivity {
protected AudioPlayer mAudioPlayer;
private FrameLayout mAudioPlayerContainer;
protected PlaybackService mService;
protected BottomSheetBehavior mBottomSheetBehavior;
public BottomSheetBehavior mBottomSheetBehavior;
protected View mFragmentContainer;
protected int mOriginalBottomPadding;
private View mScanProgressLayout;
......@@ -124,7 +124,7 @@ public class AudioPlayerContainerActivity extends BaseActivity {
private void initAudioPlayer() {
findViewById(R.id.audio_player_stub).setVisibility(View.VISIBLE);
mAudioPlayer = (AudioPlayer) getSupportFragmentManager().findFragmentById(R.id.audio_player);
mBottomSheetBehavior = BottomSheetBehavior.from(mAudioPlayerContainer);
mBottomSheetBehavior = (BottomSheetBehavior) BottomSheetBehavior.from(mAudioPlayerContainer);
mBottomSheetBehavior.setPeekHeight(getResources().getDimensionPixelSize(R.dimen.player_peek_height));
mBottomSheetBehavior.setBottomSheetCallback(mAudioPlayerBottomSheetCallback);
showTipViewIfNeeded(R.id.audio_player_tips, Constants.PREF_AUDIOPLAYER_TIPS_SHOWN);
......
......@@ -602,7 +602,9 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, PlaybackSe
private val mCoverMediaSwitcherListener = object : AudioMediaSwitcherListener {
override fun onMediaSwitching() {}
override fun onMediaSwitching() {
(activity as? AudioPlayerContainerActivity)?.mBottomSheetBehavior?.lock(true)
}
override fun onMediaSwitched(position: Int) {
service?.apply {
......@@ -611,6 +613,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, PlaybackSe
AudioMediaSwitcherListener.NEXT_MEDIA -> next()
}
}
(activity as? AudioPlayerContainerActivity)?.mBottomSheetBehavior?.lock(false)
}
override fun onTouchDown() {}
......
......@@ -9,6 +9,7 @@ import android.view.View;
public class BottomSheetBehavior<V extends View> extends android.support.design.widget.BottomSheetBehavior<V> {
public static final String TAG = "VLC/BottomSheetBehavior";
private boolean lock = false;
public BottomSheetBehavior() {}
......@@ -16,8 +17,13 @@ public class BottomSheetBehavior<V extends View> extends android.support.design.
super(context, attrs);
}
public void lock(boolean lock) {
this.lock = lock;
}
@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
if (lock) return false;
try {
return super.onInterceptTouchEvent(parent, child, event);
} catch (NullPointerException ignored) {
......@@ -28,6 +34,7 @@ public class BottomSheetBehavior<V extends View> extends android.support.design.
@Override
public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, V child, View target) {
if (lock) return;
try {
super.onStopNestedScroll(coordinatorLayout, child, target);
} catch (NullPointerException ignored) {
......@@ -37,6 +44,7 @@ public class BottomSheetBehavior<V extends View> extends android.support.design.
@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, V child, View target, int dx, int dy, int[] consumed) {
if (lock) return;
try {
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed);
} catch (NullPointerException ignored) {
......@@ -46,6 +54,7 @@ public class BottomSheetBehavior<V extends View> extends android.support.design.
@Override
public boolean onNestedPreFling(CoordinatorLayout coordinatorLayout, V child, View target, float velocityX, float velocityY) {
if (lock) return false;
try {
return super.onNestedPreFling(coordinatorLayout, child, target, velocityX, velocityY);
} catch (NullPointerException ignored) {
......@@ -56,6 +65,7 @@ public class BottomSheetBehavior<V extends View> extends android.support.design.
@Override
public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
if (lock) return false;
try {
return super.onTouchEvent(parent, child, event);
} catch (NullPointerException ignored) {
......
......@@ -147,10 +147,10 @@ public abstract class AudioMediaSwitcher extends FlingViewGroup {
mAudioMediaSwitcherListener = l;
}
public static interface AudioMediaSwitcherListener {
public final static int PREVIOUS_MEDIA = 1;
public final static int CURRENT_MEDIA = 2;
public final static int NEXT_MEDIA = 3;
public interface AudioMediaSwitcherListener {
int PREVIOUS_MEDIA = 1;
int CURRENT_MEDIA = 2;
int NEXT_MEDIA = 3;
void onMediaSwitching();
......
......@@ -226,16 +226,15 @@ public class FlingViewGroup extends ViewGroup {
break;
}
return true;
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (mViewSwitchListener != null) {
float progress = (float) l / (float) (getWidth() * (getChildCount() - 1));
if (l != mCurrentView * getWidth())
protected void onScrollChanged(int h, int v, int oldh, int oldv) {
super.onScrollChanged(h, v, oldh, oldv);
if (mViewSwitchListener != null && Math.abs(oldh-h) > Math.abs(oldv-v)) {
float progress = (float) h / (float) (getWidth() * (getChildCount() - 1));
if (h != mCurrentView * getWidth())
mViewSwitchListener.onSwitching(progress);
else
mViewSwitchListener.onSwitched(mCurrentView);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment