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

Add playlist display in video player

* Icon is temporary
parent 2876fba7
......@@ -7,6 +7,7 @@
android:id="@+id/player_overlay_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/playlist_toggle"
android:gravity="center_horizontal"
android:layout_marginTop="@dimen/tv_overscan_vertical"
android:layout_gravity="top"
......@@ -20,4 +21,12 @@
android:shadowDx="3"
android:shadowDy="3"
android:shadowRadius="1.5" />
<ImageView
android:id="@+id/playlist_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/ic_playlist"
android:visibility="gone"/>
</RelativeLayout>
......@@ -121,6 +121,14 @@
<include layout="@layout/player_hud"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/video_playlist"
android:layout_width="480dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/rounded_corners"
android:visibility="gone"/>
</RelativeLayout>
</RelativeLayout>
......@@ -33,4 +33,11 @@
android:textColor="#ffffff"
android:textSize="15sp"
tools:ignore="true" />
<ImageView
android:id="@+id/playlist_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_playlist"
android:visibility="gone"/>
</LinearLayout>
......@@ -205,6 +205,9 @@
<item name="ic_audiodelay">@drawable/ic_audiodelay_w</item>
<item name="ic_subtitledelay">@drawable/ic_subtitledelay_w</item>
<item name="list_subtitle">@color/grey400</item>
<item name="list_title_last">@color/list_title_last</item>
<item name="list_title">@color/bt_list_title</item>
</style>
<style name="ActionBar" parent="Widget.AppCompat.Light.ActionBar">
......
......@@ -70,7 +70,7 @@ import org.videolan.vlc.gui.view.AudioMediaSwitcher.AudioMediaSwitcherListener;
import java.util.ArrayList;
import java.util.List;
public class AudioPlayer extends PlaybackServiceFragment implements PlaybackService.Callback, View.OnClickListener {
public class AudioPlayer extends PlaybackServiceFragment implements PlaybackService.Callback, View.OnClickListener, PlaylistAdapter.IPlayer {
public static final String TAG = "VLC/AudioPlayer";
private ProgressBar mProgressBar;
......
......@@ -26,6 +26,7 @@ package org.videolan.vlc.gui.audio;
import android.content.Context;
import android.databinding.DataBindingUtil;
import android.os.Message;
import android.support.annotation.MainThread;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
......@@ -46,14 +47,18 @@ import java.util.List;
public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHolder> implements SwipeDragHelperAdapter{
public interface IPlayer {
void onPopupMenu(View view, int position);
void updateList();
}
private static final String TAG = "VLC/PlaylistAdapter";
PlaybackService mService = null;
AudioPlayer mAudioPlayer;
IPlayer mAudioPlayer;
private ArrayList<MediaWrapper> mDataSet = new ArrayList<MediaWrapper>();
private int mCurrentIndex = 0;
public PlaylistAdapter(AudioPlayer audioPlayer) {
public PlaylistAdapter(IPlayer audioPlayer) {
mAudioPlayer = audioPlayer;
}
......@@ -102,6 +107,12 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
mDataSet.add(mw);
}
@MainThread
public void remove(int position) {
mDataSet.remove(position);
notifyItemRemoved(position);
}
public void clear(){
mDataSet.clear();
}
......@@ -124,6 +135,7 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
public void onItemDismiss(int position) {
if (mService == null)
return;
remove(position);
mService.remove(position);
}
......
......@@ -57,7 +57,10 @@ import android.support.v4.view.GestureDetectorCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.DisplayMetrics;
......@@ -103,9 +106,11 @@ import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.PlaybackServiceActivity;
import org.videolan.vlc.gui.audio.PlaylistAdapter;
import org.videolan.vlc.gui.browser.FilePickerActivity;
import org.videolan.vlc.gui.dialogs.AdvOptionsDialog;
import org.videolan.vlc.gui.helpers.OnRepeatListener;
import org.videolan.vlc.gui.helpers.SwipeDragItemTouchHelperCallback;
import org.videolan.vlc.gui.preferences.PreferencesActivity;
import org.videolan.vlc.interfaces.IDelayController;
import org.videolan.vlc.media.MediaDatabase;
......@@ -130,10 +135,11 @@ import java.io.StreamCorruptedException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.Callback,
GestureDetector.OnDoubleTapListener, IDelayController, LibVLC.HardwareAccelerationError,
PlaybackService.Client.Callback, PlaybackService.Callback {
PlaybackService.Client.Callback, PlaybackService.Callback, PlaylistAdapter.IPlayer, OnClickListener {
public final static String TAG = "VLC/VideoPlayerActivity";
......@@ -171,6 +177,10 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
private boolean mAskResume = true;
private GestureDetectorCompat mDetector = null;
private ImageView mPlaylistToggle;
private RecyclerView mPlaylist;
private PlaylistAdapter mPlaylistAdapter;
private static final int SURFACE_BEST_FIT = 0;
private static final int SURFACE_FIT_HORIZONTAL = 1;
private static final int SURFACE_FIT_VERTICAL = 2;
......@@ -366,6 +376,10 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
mTitle = (TextView) mActionBarView.findViewById(R.id.player_overlay_title);
mSysTime = (TextView) findViewById(R.id.player_overlay_systime);
mBattery = (TextView) findViewById(R.id.player_overlay_battery);
mPlaylistToggle = (ImageView) findViewById(R.id.playlist_toggle);
mPlaylist = (RecyclerView) findViewById(R.id.video_playlist);
mOverlayProgress = findViewById(R.id.progress_overlay);
RelativeLayout.LayoutParams layoutParams =
(RelativeLayout.LayoutParams)mOverlayProgress.getLayoutParams();
......@@ -527,6 +541,8 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
updateSeekable(mService.isSeekable());
updatePausable(mService.isPausable());
mTitle.setText(mService.getCurrentMediaWrapper().getTitle());
if (mPlaylist.getVisibility() == View.VISIBLE)
mPlaylistAdapter.setCurrentIndex(mService.getCurrentMediaPosition());
}
}
......@@ -725,7 +741,8 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
public void onSystemUiVisibilityChange(int visibility) {
if (visibility == mUiVisibility)
return;
if (visibility == View.SYSTEM_UI_FLAG_VISIBLE && !mShowing && !isFinishing()) {
if (visibility == View.SYSTEM_UI_FLAG_VISIBLE && !mShowing &&
!isFinishing() && mPlaylist.getVisibility() != View.VISIBLE) {
showOverlay();
}
mUiVisibility = visibility;
......@@ -1014,6 +1031,8 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
mLockBackButton = false;
mHandler.sendEmptyMessageDelayed(RESET_BACK_LOCK, 2000);
Toast.makeText(this, getString(R.string.back_quit_lock), Toast.LENGTH_SHORT).show();
} else if(mPlaylist.getVisibility() == View.VISIBLE) {
togglePlaylist();
} else if (mDelay != DelayState.OFF){
endDelaySetting();
} else if (BuildConfig.tv && mShowing && !mIsLocked) {
......@@ -1734,6 +1753,9 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
if (mDelay != DelayState.OFF){
endDelaySetting();
return true;
} else if(mPlaylist.getVisibility() == View.VISIBLE) {
togglePlaylist();
return true;
}
if (mDetector != null && mDetector.onTouchEvent(event))
return true;
......@@ -1768,7 +1790,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
// coef is the gradient's move to determine a neutral zone
float coef = Math.abs (y_changed / x_changed);
float xgesturesize = ((x_changed / screen.xdpi) * 2.54f);
float delta_y = Math.max(1f,((mInitTouchY - event.getRawY()) / screen.xdpi + 0.5f)*2f);
float delta_y = Math.max(1f, ((mInitTouchY - event.getRawY()) / screen.xdpi + 0.5f) * 2f);
/* Offset for Mouse Events */
int[] offset = new int[2];
......@@ -2020,6 +2042,73 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
popupMenu.show();
}
@Override
public void onPopupMenu(View anchor, final int position) {
PopupMenu popupMenu = new PopupMenu(this, anchor);
popupMenu.getMenuInflater().inflate(R.menu.audio_player, popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if(item.getItemId() == R.id.audio_player_mini_remove) {
if (mService != null) {
mPlaylistAdapter.remove(position);
mService.remove(position);
return true;
}
}
return false;
}
});
popupMenu.show();
}
@Override
public void updateList() {
int currentIndex = -1, oldCount = mPlaylistAdapter.getItemCount();
if (mService == null)
return;
final List<MediaWrapper> previousAudioList = mPlaylistAdapter.getMedias();
mPlaylistAdapter.clear();
final List<MediaWrapper> playlist = mService.getMedias();
final String currentItem = mService.getCurrentMediaLocation();
if (playlist != null) {
for (int i = 0; i < playlist.size(); i++) {
final MediaWrapper media = playlist.get(i);
if (currentItem != null && currentItem.equals(media.getLocation()))
currentIndex = i;
mPlaylistAdapter.add(media);
}
}
mPlaylistAdapter.setCurrentIndex(currentIndex);
int count = mPlaylistAdapter.getItemCount();
if (oldCount != count)
mPlaylistAdapter.notifyDataSetChanged();
else
mPlaylistAdapter.notifyItemRangeChanged(0, count);
final int selectionIndex = currentIndex;
if (!previousAudioList.equals(playlist))
mPlaylist.post(new Runnable() {
@Override
public void run() {
mPlaylistAdapter.setCurrentIndex(selectionIndex);
}
});
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.playlist_toggle:
togglePlaylist();
break;
}
}
private interface TrackSelectedListener {
boolean onTrackSelected(int trackID);
}
......@@ -2947,6 +3036,18 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
hideOverlay(false);
}
private void togglePlaylist() {
if (mPlaylist.getVisibility() == View.VISIBLE) {
mPlaylist.setVisibility(View.GONE);
mPlaylist.setOnClickListener(null);
return;
}
hideOverlay(true);
mPlaylist.setVisibility(View.VISIBLE);
mPlaylist.setAdapter(mPlaylistAdapter);
updateList();
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void createPresentation() {
if (mMediaRouter == null || mEnableCloneMode)
......@@ -3146,6 +3247,19 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
@Override
public void onConnected(PlaybackService service) {
mService = service;
if (mService.hasNext() || mService.hasPrevious()) {
mPlaylistAdapter = new PlaylistAdapter(this);
mPlaylistAdapter.setService(service);
final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mPlaylist.setLayoutManager(layoutManager);
mPlaylistToggle.setVisibility(View.VISIBLE);
mPlaylistToggle.setOnClickListener(VideoPlayerActivity.this);
ItemTouchHelper.Callback callback = new SwipeDragItemTouchHelperCallback(mPlaylistAdapter);
ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
touchHelper.attachToRecyclerView(mPlaylist);
}
mHandler.sendEmptyMessage(START_PLAYBACK);
}
......
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