[Android] Restore SavePlaylistDialog

Geoffrey Métais git at videolan.org
Wed Sep 5 17:50:07 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Sep  4 18:10:27 2018 +0200| [f0a57d16185e2ddb7537003a7407125cf3450478] | committer: Geoffrey Métais

Restore SavePlaylistDialog

> https://code.videolan.org/videolan/vlc-android/commit/f0a57d16185e2ddb7537003a7407125cf3450478
---

 vlc-android/res/layout/dialog_playlist.xml         |  1 +
 vlc-android/res/layout/simple_item.xml             |  8 +++--
 .../src/org/videolan/vlc/gui/SimpleAdapter.kt      | 16 ++++++----
 .../vlc/gui/browser/NetworkBrowserFragment.java    | 10 +-----
 .../vlc/gui/dialogs/SavePlaylistDialog.java        | 37 +++++++++-------------
 5 files changed, 32 insertions(+), 40 deletions(-)

diff --git a/vlc-android/res/layout/dialog_playlist.xml b/vlc-android/res/layout/dialog_playlist.xml
index 74ac47cf3..7aa2f057e 100644
--- a/vlc-android/res/layout/dialog_playlist.xml
+++ b/vlc-android/res/layout/dialog_playlist.xml
@@ -43,6 +43,7 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="@dimen/half_default_margin"
+        android:layout_marginStart="@dimen/half_default_margin"
         android:layout_below="@+id/dialog_playlist_cancel">
         <android.support.v7.widget.RecyclerView
             android:id="@android:id/list"
diff --git a/vlc-android/res/layout/simple_item.xml b/vlc-android/res/layout/simple_item.xml
index 5e5ca3996..956a168c8 100644
--- a/vlc-android/res/layout/simple_item.xml
+++ b/vlc-android/res/layout/simple_item.xml
@@ -2,6 +2,7 @@
 <layout xmlns:tools="http://schemas.android.com/tools">
     <data>
         <import type="org.videolan.medialibrary.media.MediaLibraryItem"/>
+        <import type="android.view.View"/>
         <variable
             name="item"
             type="MediaLibraryItem"/>
@@ -10,19 +11,22 @@
             type="android.graphics.drawable.BitmapDrawable"/>
         <variable
             name="handler"
-            type="org.videolan.vlc.gui.SimpleAdapter.FavoritesHandler" />
+            type="org.videolan.vlc.gui.SimpleAdapter.ClickHandler" />
     </data>
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:app="http://schemas.android.com/apk/res-auto"
         android:orientation="horizontal" android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:layout_marginTop="8dp"
+        android:layout_marginBottom="8dp"
         android:onClick="@{(v) -> handler.onClick(item)}">
 
         <ImageView
             android:layout_width="48dp"
             android:layout_height="48dp"
             android:src="@{cover}"
-            app:media="@{item}" />
+            app:media="@{item}"
+            android:visibility="@{item.artworkMrl == null ? View.GONE : View.VISIBLE, default=gone}"/>
         <TextView
             android:layout_width="match_parent"
             android:layout_height="match_parent"
diff --git a/vlc-android/src/org/videolan/vlc/gui/SimpleAdapter.kt b/vlc-android/src/org/videolan/vlc/gui/SimpleAdapter.kt
index 81a43eff1..91528ee12 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SimpleAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/SimpleAdapter.kt
@@ -8,21 +8,21 @@ import android.view.ViewGroup
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.vlc.databinding.SimpleItemBinding
 
-
-val cb = object : DiffUtil.ItemCallback<MediaLibraryItem>() {
+private val cb = object : DiffUtil.ItemCallback<MediaLibraryItem>() {
     override fun areItemsTheSame(oldItem: MediaLibraryItem, newItem: MediaLibraryItem) = oldItem == newItem
-
     override fun areContentsTheSame(oldItem: MediaLibraryItem, newItem: MediaLibraryItem) = true
 }
 
-class SimpleAdapter(val handler: FavoritesHandler) : ListAdapter<MediaLibraryItem, SimpleAdapter.ViewHolder>(cb) {
+class SimpleAdapter(val handler: ClickHandler) : ListAdapter<MediaLibraryItem, SimpleAdapter.ViewHolder>(cb) {
 
-    interface FavoritesHandler {
+    interface ClickHandler {
         fun onClick(item: MediaLibraryItem)
     }
 
+    private lateinit var inflater : LayoutInflater
+
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
-        val inflater = LayoutInflater.from(parent.context);
+        if (!this::inflater.isInitialized) inflater = LayoutInflater.from(parent.context)
         return ViewHolder(handler, SimpleItemBinding.inflate(inflater, parent, false))
     }
 
@@ -30,7 +30,9 @@ class SimpleAdapter(val handler: FavoritesHandler) : ListAdapter<MediaLibraryIte
         holder.binding.item = getItem(position)
     }
 
-    class ViewHolder(val handler: FavoritesHandler, val binding: SimpleItemBinding) : RecyclerView.ViewHolder(binding.root) {
+    fun isEmpty() = itemCount == 0
+
+    class ViewHolder(handler: ClickHandler, val binding: SimpleItemBinding) : RecyclerView.ViewHolder(binding.root) {
         init {
             binding.handler = handler
         }
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
index 084011ff1..fea917334 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
@@ -40,13 +40,10 @@ import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
 
-import org.jetbrains.annotations.NotNull;
-import org.videolan.medialibrary.media.MediaLibraryItem;
 import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.vlc.ExternalMonitor;
 import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
-import org.videolan.vlc.gui.SimpleAdapter;
 import org.videolan.vlc.gui.dialogs.NetworkServerDialog;
 import org.videolan.vlc.gui.dialogs.VlcLoginDialog;
 import org.videolan.vlc.util.Constants;
@@ -54,12 +51,7 @@ import org.videolan.vlc.util.Util;
 import org.videolan.vlc.util.WorkersKt;
 import org.videolan.vlc.viewmodels.browser.NetworkModel;
 
-public class NetworkBrowserFragment extends BaseBrowserFragment implements SimpleAdapter.FavoritesHandler {
-
-    @Override
-    public void onClick(@NotNull MediaLibraryItem item) {
-        browse((MediaWrapper) item, true);
-    }
+public class NetworkBrowserFragment extends BaseBrowserFragment {
 
     @Override
     public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
index 0e9458eac..2761c7d1b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
@@ -41,6 +41,7 @@ import android.widget.Button;
 import android.widget.EditText;
 import android.widget.TextView;
 
+import org.jetbrains.annotations.NotNull;
 import org.videolan.medialibrary.Medialibrary;
 import org.videolan.medialibrary.Tools;
 import org.videolan.medialibrary.media.MediaLibraryItem;
@@ -48,13 +49,13 @@ import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.medialibrary.media.Playlist;
 import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
-import org.videolan.vlc.gui.audio.AudioBrowserAdapter;
-import org.videolan.vlc.interfaces.IEventsHandler;
+import org.videolan.vlc.gui.SimpleAdapter;
 import org.videolan.vlc.util.WorkersKt;
 
+import java.util.Arrays;
 import java.util.LinkedList;
 
-public class SavePlaylistDialog extends DialogFragment implements View.OnClickListener, TextView.OnEditorActionListener, IEventsHandler {
+public class SavePlaylistDialog extends DialogFragment implements View.OnClickListener, TextView.OnEditorActionListener, SimpleAdapter.ClickHandler {
 
     public final static String TAG = "VLC/SavePlaylistDialog";
 
@@ -66,7 +67,7 @@ public class SavePlaylistDialog extends DialogFragment implements View.OnClickLi
     TextView mEmptyView;
     Button mSaveButton;
     Button mCancelButton;
-    AudioBrowserAdapter mAdapter;
+    SimpleAdapter mAdapter;
     MediaWrapper[] mTracks;
     MediaWrapper[] mNewTrack;
     Runnable mCallBack;
@@ -79,7 +80,7 @@ public class SavePlaylistDialog extends DialogFragment implements View.OnClickLi
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         mMedialibrary = VLCApplication.getMLInstance();
-        mAdapter = new AudioBrowserAdapter(MediaLibraryItem.TYPE_PLAYLIST, this, 0);
+        mAdapter = new SimpleAdapter(this);
         mTracks = (MediaWrapper[]) getArguments().getParcelableArray(KEY_TRACKS);
         mNewTrack = (MediaWrapper[]) getArguments().getParcelableArray(KEY_NEW_TRACKS);
     }
@@ -91,7 +92,7 @@ public class SavePlaylistDialog extends DialogFragment implements View.OnClickLi
     @NonNull
     @Override
     public Dialog onCreateDialog(Bundle savedInstanceState) {
-        AppCompatDialog dialog = new AppCompatDialog(getActivity(), getTheme());
+        final AppCompatDialog dialog = new AppCompatDialog(getActivity(), getTheme());
         dialog.setTitle(R.string.playlist_save);
         return dialog;
 
@@ -123,8 +124,8 @@ public class SavePlaylistDialog extends DialogFragment implements View.OnClickLi
         mEditText.setOnEditorActionListener(this);
         mListView.setLayoutManager(new LinearLayoutManager(view.getContext()));
         mListView.setAdapter(mAdapter);
-        //TODO new adapter
-//        mAdapter.update(new ArrayList<MediaLibraryItem>(Arrays.asList(mMedialibrary.getPlaylists())));
+        mAdapter.submitList(Arrays.<MediaLibraryItem>asList(mMedialibrary.getPlaylists()));
+        updateEmptyView();
     }
 
     void updateEmptyView() {
@@ -181,22 +182,14 @@ public class SavePlaylistDialog extends DialogFragment implements View.OnClickLi
         dismiss();
     }
 
+//    @Override
+//    public void onUpdateFinished(RecyclerView.Adapter adapter) {
+//        updateEmptyView();
+//    }
+
     @Override
-    public void onClick(View v, int position, MediaLibraryItem item) {
+    public void onClick(@NotNull MediaLibraryItem item) {
         mPlaylistId = item.getId();
         mEditText.setText(item.getTitle());
     }
-
-    @Override
-    public boolean onLongClick(View v, int position, MediaLibraryItem item) {
-        return false;
-    }
-
-    @Override
-    public void onCtxClick(View v, int position, MediaLibraryItem item) {}
-
-    @Override
-    public void onUpdateFinished(RecyclerView.Adapter adapter) {
-        updateEmptyView();
-    }
 }



More information about the Android mailing list