Commit 48fbbb5b authored by Nicolas Pomepuy's avatar Nicolas Pomepuy Committed by Geoffrey Métais

Split list interface between item action events and list events

parent 595a155b
......@@ -259,20 +259,6 @@ public class HistoryFragment extends MediaBrowserFragment<HistoryModel> implemen
@Override
public void onCtxClick(View v, int position, MediaLibraryItem item) {}
@Override
public void onRemove(int position, @NotNull MediaLibraryItem item) {
}
@Override
public void onMove(int position, @NotNull MediaLibraryItem item) {
}
@Override
public void onStartDrag(@NotNull RecyclerView.ViewHolder viewHolder) {
}
@Override
public void onUpdateFinished(RecyclerView.Adapter adapter) {
......
......@@ -59,6 +59,7 @@ import org.videolan.vlc.gui.helpers.FloatingActionButtonBehavior;
import org.videolan.vlc.gui.helpers.SwipeDragItemTouchHelperCallback;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.interfaces.IEventsHandler;
import org.videolan.vlc.interfaces.IListEventsHandler;
import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.media.PlaylistManager;
import org.videolan.vlc.util.AndroidDevices;
......@@ -88,7 +89,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import kotlinx.coroutines.Job;
public class PlaylistActivity extends AudioPlayerContainerActivity implements IEventsHandler, ActionMode.Callback, View.OnClickListener, CtxActionReceiver {
public class PlaylistActivity extends AudioPlayerContainerActivity implements IEventsHandler, IListEventsHandler, ActionMode.Callback, View.OnClickListener, CtxActionReceiver {
public final static String TAG = "VLC/PlaylistActivity";
public final static String TAG_FAB_VISIBILITY = "FAB";
......@@ -128,7 +129,7 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
}
}
});
mAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_MEDIA, this,false, true);
mAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_MEDIA, this, this, false, true);
mItemTouchHelper = new ItemTouchHelper(new SwipeDragItemTouchHelperCallback(mAdapter));
mItemTouchHelper.attachToRecyclerView(mBinding.songs);
......
......@@ -111,13 +111,6 @@ class PlaylistFragment : BaseAudioBrowser(), Observer<PagedList<MediaLibraryItem
} else super.onClick(v, position, item)
}
override fun onRemove(position: Int, item: MediaLibraryItem) {
}
override fun onMove(position: Int, item: MediaLibraryItem) {
}
override fun onRefresh() {
activity?.reloadLibrary()
......
......@@ -43,6 +43,7 @@ import org.videolan.vlc.gui.helpers.ImageLoaderKt;
import org.videolan.vlc.gui.helpers.SelectorViewHolder;
import org.videolan.vlc.gui.view.FastScroller;
import org.videolan.vlc.interfaces.IEventsHandler;
import org.videolan.vlc.interfaces.IListEventsHandler;
import org.videolan.vlc.interfaces.SwipeDragHelperAdapter;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.Util;
......@@ -66,19 +67,19 @@ public class AudioBrowserAdapter extends PagedListAdapter<MediaLibraryItem, Audi
private static final int UPDATE_PAYLOAD = 1;
private final IEventsHandler mIEventsHandler;
private final boolean mCanBeReordered;
private final IListEventsHandler mListEventsHandler;
private MultiSelectHelper<MediaLibraryItem> multiSelectHelper;
private final int mType;
private final boolean mHasSections;
private final BitmapDrawable mDefaultCover;
public AudioBrowserAdapter(int type, IEventsHandler eventsHandler, boolean sections, boolean canBeReordered) {
public AudioBrowserAdapter(int type, IEventsHandler eventsHandler, IListEventsHandler listEventsHandler, boolean sections, boolean canBeReordered) {
super(DIFF_CALLBACK);
multiSelectHelper = new MultiSelectHelper<>(this, Constants.UPDATE_SELECTION);
mIEventsHandler = eventsHandler;
mType = type;
mHasSections = sections;
mCanBeReordered = canBeReordered;
mListEventsHandler = listEventsHandler;
Context ctx = null;
if (eventsHandler instanceof Context) ctx = (Context) eventsHandler;
else if (eventsHandler instanceof Fragment) ctx = ((Fragment)eventsHandler).getContext();
......@@ -86,7 +87,7 @@ public class AudioBrowserAdapter extends PagedListAdapter<MediaLibraryItem, Audi
}
public AudioBrowserAdapter(int type, IEventsHandler eventsHandler) {
this(type, eventsHandler, true, false);
this(type, eventsHandler, null, true, false);
}
@NonNull
......@@ -105,7 +106,7 @@ public class AudioBrowserAdapter extends PagedListAdapter<MediaLibraryItem, Audi
final boolean isSelected = multiSelectHelper.isSelected(position);
holder.setCoverlay(isSelected);
holder.selectView(isSelected);
holder.setCanBeReordered(mCanBeReordered);
holder.setCanBeReordered(mListEventsHandler != null);
holder.binding.executePendingBindings();
}
......@@ -123,7 +124,7 @@ public class AudioBrowserAdapter extends PagedListAdapter<MediaLibraryItem, Audi
final boolean isSelected = multiSelectHelper.isSelected(position);
holder.setCoverlay(isSelected);
holder.selectView(isSelected);
holder.setCanBeReordered(mCanBeReordered);
holder.setCanBeReordered(mListEventsHandler != null);
}
}
}
......@@ -193,13 +194,13 @@ public class AudioBrowserAdapter extends PagedListAdapter<MediaLibraryItem, Audi
@Override
public void onItemMoved(int dragFrom, int dragTo) {
final MediaLibraryItem item = getItem(dragFrom);
mIEventsHandler.onMove(dragTo, item);
mListEventsHandler.onMove(dragTo, item);
}
@Override
public void onItemDismiss(int position) {
final MediaLibraryItem item = getItem(position);
mIEventsHandler.onRemove(position, item);
mListEventsHandler.onRemove(position, item);
}
public class MediaItemViewHolder extends SelectorViewHolder<AudioBrowserItemBinding> implements View.OnFocusChangeListener {
......@@ -224,14 +225,14 @@ public class AudioBrowserAdapter extends PagedListAdapter<MediaLibraryItem, Audi
onTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (!mCanBeReordered) {
if (mListEventsHandler == null) {
return false;
}
if (multiSelectHelper.getSelectionCount() != 0) {
return false;
}
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
mIEventsHandler.onStartDrag(MediaItemViewHolder.this);
mListEventsHandler.onStartDrag(MediaItemViewHolder.this);
return true;
}
return false;
......
......@@ -31,7 +31,6 @@ import android.view.View;
import com.google.android.material.tabs.TabLayout;
import org.jetbrains.annotations.NotNull;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.R;
......@@ -280,20 +279,6 @@ public abstract class BaseAudioBrowser extends MediaBrowserFragment<MLPagedModel
if (mActionMode == null) ContextSheetKt.showContext(requireActivity(), this, position, item.getTitle(), flags);
}
@Override
public void onRemove(int position, @NotNull MediaLibraryItem item) {
}
@Override
public void onMove(int position, @NotNull MediaLibraryItem item) {
}
@Override
public void onStartDrag(@NotNull RecyclerView.ViewHolder viewHolder) {
}
@Override
public void onUpdateFinished(RecyclerView.Adapter adapter) {
......
......@@ -435,17 +435,6 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
}
}
override fun onRemove(position: Int, item: MediaLibraryItem) {
}
override fun onMove(position: Int, item: MediaLibraryItem) {
}
override fun onStartDrag(viewHolder: RecyclerView.ViewHolder) {
}
override fun onCtxAction(position: Int, option: Int) {
if (adapter.getItem(position) !is MediaWrapper) return
......
......@@ -31,7 +31,6 @@ import android.text.TextUtils
import android.view.View
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.RecyclerView
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import org.videolan.medialibrary.media.MediaLibraryItem
......@@ -88,18 +87,6 @@ class FilePickerFragment : FileBrowserFragment() {
}
override fun onRemove(position: Int, item: MediaLibraryItem) {
}
override fun onMove(position: Int, item: MediaLibraryItem) {
}
override fun onStartDrag(viewHolder: RecyclerView.ViewHolder) {
}
private fun pickFile(mw: MediaWrapper) {
val i = Intent(Intent.ACTION_PICK)
i.putExtra(EXTRA_MRL, mw.location)
......
......@@ -39,9 +39,6 @@ import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProviders
import kotlinx.coroutines.*
import androidx.recyclerview.widget.RecyclerView
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.launch
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.medialibrary.interfaces.EntryPointsEventsCb
import org.videolan.medialibrary.media.MediaLibraryItem
......@@ -196,17 +193,6 @@ class StorageBrowserFragment : FileBrowserFragment(), EntryPointsEventsCb, Corou
}
}
override fun onRemove(position: Int, item: MediaLibraryItem) {
}
override fun onMove(position: Int, item: MediaLibraryItem) {
}
override fun onStartDrag(viewHolder: RecyclerView.ViewHolder) {
}
internal fun processEvent(cbp: CheckBox, mrl: String) {
cbp.isEnabled = false
......
......@@ -37,7 +37,6 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import org.jetbrains.annotations.NotNull;
import org.videolan.medialibrary.Medialibrary;
import org.videolan.medialibrary.media.Folder;
import org.videolan.medialibrary.media.MediaLibraryItem;
......@@ -414,20 +413,6 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosModel> impleme
ContextSheetKt.showContext(requireActivity(), this, position, item.getTitle(), flags);
}
@Override
public void onRemove(int position, @NotNull MediaLibraryItem item) {
}
@Override
public void onMove(int position, @NotNull MediaLibraryItem item) {
}
@Override
public void onStartDrag(@NotNull RecyclerView.ViewHolder viewHolder) {
}
@Override
public void onUpdateFinished(RecyclerView.Adapter adapter) {
......
......@@ -10,7 +10,4 @@ interface IEventsHandler {
fun onImageClick(v: View, position: Int, item: MediaLibraryItem)
fun onCtxClick(v: View, position: Int, item: MediaLibraryItem)
fun onUpdateFinished(adapter: RecyclerView.Adapter<*>)
fun onRemove(position: Int, item: MediaLibraryItem)
fun onMove(position: Int, item: MediaLibraryItem)
fun onStartDrag(viewHolder:RecyclerView.ViewHolder )
}
package org.videolan.vlc.interfaces
import androidx.recyclerview.widget.RecyclerView
import org.videolan.medialibrary.media.MediaLibraryItem
interface IListEventsHandler {
fun onRemove(position: Int, item: MediaLibraryItem)
fun onMove(position: Int, item: MediaLibraryItem)
fun onStartDrag(viewHolder: RecyclerView.ViewHolder )
}
\ No newline at end of file
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