[Android] Refactor delete UX in audio sections

Geoffrey Métais git at videolan.org
Wed Sep 5 18:41:09 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Sep  5 18:40:16 2018 +0200| [8921c4f6f1a084e2697b0d218984f347c462ff6c] | committer: Geoffrey Métais

Refactor delete UX in audio sections

TO DO: propagate to video and browsers

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

 .../src/org/videolan/vlc/gui/PlaylistActivity.java |  2 +-
 .../videolan/vlc/gui/audio/BaseAudioBrowser.java   | 51 +++++++++-------------
 .../src/org/videolan/vlc/gui/helpers/UiTools.java  | 15 +++++++
 vlc-android/src/org/videolan/vlc/util/Constants.kt |  3 +-
 4 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
index 9ed5ce122..7120bf06b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
@@ -201,7 +201,7 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
 
     @Override
     public void onCtxClick(View anchor, final int position, final MediaLibraryItem mediaItem) {
-        if (mActionMode == null) ContextSheetKt.showContext(this, this, position, mediaItem.getTitle(), Constants.CTX_PLAYLIST_FLAGS);
+        if (mActionMode == null) ContextSheetKt.showContext(this, this, position, mediaItem.getTitle(), Constants.CTX_PLAYLIST_ITEM_FLAGS);
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java b/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java
index f5ac460b1..5f506c797 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java
@@ -161,50 +161,29 @@ public abstract class BaseAudioBrowser extends MediaBrowserFragment<MLPagedModel
     }
 
     protected boolean removeItem(int position, AudioBrowserAdapter adapter, final MediaLibraryItem item) {
-        final MediaLibraryItem previous = position > 0 ? adapter.getItem(position-1) : null;
-        final MediaLibraryItem next = position < adapter.getItemCount()-1 ? adapter.getItem(position+1) : null;
-        final MLPagedModel model = getViewModel();
-        final String message;
-        final Runnable action;
-        final Runnable cancel;
-        final MediaLibraryItem separator = previous != null && previous.getItemType() == MediaLibraryItem.TYPE_DUMMY &&
-                (next == null || next.getItemType() == MediaLibraryItem.TYPE_DUMMY) ? previous : null;
-        if (separator != null) model.remove(separator);
-        model.remove(item);
-
+        final View view = getView();
+        if (view == null) return false;
         if (item.getItemType() == MediaLibraryItem.TYPE_PLAYLIST) {
-            cancel = null;
-            message = getString(R.string.playlist_deleted);
-            action = new Runnable() {
+            UiTools.snackerConfirm(getView(), "Delete " + item.getTitle() + "?", new Runnable() {
                 @Override
                 public void run() {
                     MediaUtils.INSTANCE.deletePlaylist((Playlist) item);
                 }
-            };
+            });
         } else if (item.getItemType() == MediaLibraryItem.TYPE_MEDIA) {
-            message = getString(R.string.file_deleted);
-            cancel = new Runnable() {
-                @Override
-                public void run() {
-                    model.refresh();
-                }
-            };
-            action = new Runnable() {
+            final Runnable deleteAction = new Runnable() {
                 @Override
                 public void run() {
-                    deleteMedia(item, true, cancel);
+                    deleteMedia(item, false, null);
                 }
             };
-            if (!checkWritePermission((MediaWrapper) item, new Runnable() {
+            UiTools.snackerConfirm(getView(), "Delete " + item.getTitle() + "?", new Runnable() {
                 @Override
                 public void run() {
-                    final View v = getView();
-                    if (v != null) UiTools.snackerWithCancel(getView(), message, action, cancel);
+                    if (checkWritePermission((MediaWrapper) item, deleteAction)) deleteAction.run();
                 }
-            })) return false;
+            });
         } else return false;
-        final View v = getView();
-        if (v != null) UiTools.snackerWithCancel(getView(), message, action, cancel);
         return true;
     }
 
@@ -230,7 +209,17 @@ public abstract class BaseAudioBrowser extends MediaBrowserFragment<MLPagedModel
 
     @Override
     public void onCtxClick(View anchor, final int position, MediaLibraryItem item) {
-        final int flags = item.getItemType() == MediaLibraryItem.TYPE_MEDIA ? Constants.CTX_TRACK_FLAGS : Constants.CTX_AUDIO_FLAGS;
+        final int flags;
+        switch (item.getItemType()) {
+            case MediaLibraryItem.TYPE_MEDIA:
+                flags = Constants.CTX_TRACK_FLAGS;
+                break;
+            case MediaLibraryItem.TYPE_PLAYLIST:
+                flags = Constants.CTX_PLAYLIST_FLAGS;
+                break;
+            default:
+                flags = Constants.CTX_AUDIO_FLAGS;
+        }
         if (mActionMode == null) ContextSheetKt.showContext(requireActivity(), this, position, item.getTitle(), flags);
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
index dee635598..0d45164da 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
@@ -121,6 +121,21 @@ public class UiTools {
         snack.show();
     }
 
+    /** Print an on-screen message to alert the user, with undo action */
+    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+    public static void snackerConfirm(@NonNull View view, @NonNull String message, @NonNull final Runnable action) {
+        final Snackbar snack = Snackbar.make(view, message, DELETE_DURATION)
+                .setAction(android.R.string.ok, new View.OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+                        action.run();
+                    }
+                });
+        if (AndroidUtil.isLolliPopOrLater)
+            snack.getView().setElevation(view.getResources().getDimensionPixelSize(R.dimen.audio_player_elevation));
+        snack.show();
+    }
+
     /** Print an on-screen message to alert the user, with undo action */
     public static void snackerWithCancel(@NonNull View view, @NonNull String message, @NonNull final Runnable action) {
         snackerWithCancel(view, message, action, null);
diff --git a/vlc-android/src/org/videolan/vlc/util/Constants.kt b/vlc-android/src/org/videolan/vlc/util/Constants.kt
index 973c61913..8fb153de1 100644
--- a/vlc-android/src/org/videolan/vlc/util/Constants.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Constants.kt
@@ -156,7 +156,8 @@ const val CTX_REMOVE_FROM_PLAYLIST = 1 shl 17
 const val CTX_VIDEO_FLAGS = CTX_APPEND or CTX_DELETE or CTX_DOWNLOAD_SUBTITLES or CTX_INFORMATION or CTX_PLAY_ALL or CTX_PLAY_AS_AUDIO
 const val CTX_TRACK_FLAGS = CTX_APPEND or CTX_PLAY_NEXT or CTX_DELETE or CTX_INFORMATION or CTX_PLAY_ALL or CTX_ADD_TO_PLAYLIST or CTX_SET_RINGTONE
 const val CTX_AUDIO_FLAGS = CTX_PLAY or CTX_APPEND or CTX_PLAY_NEXT or CTX_ADD_TO_PLAYLIST
-const val CTX_PLAYLIST_FLAGS = CTX_APPEND or CTX_PLAY_NEXT or CTX_ADD_TO_PLAYLIST or CTX_INFORMATION or CTX_DELETE or CTX_SET_RINGTONE
+const val CTX_PLAYLIST_FLAGS = CTX_AUDIO_FLAGS or CTX_DELETE
+const val CTX_PLAYLIST_ITEM_FLAGS = CTX_APPEND or CTX_PLAY_NEXT or CTX_ADD_TO_PLAYLIST or CTX_INFORMATION or CTX_DELETE or CTX_SET_RINGTONE
 const val CTX_VIDEO_GOUP_FLAGS = CTX_APPEND or CTX_PLAY
 
 // Database



More information about the Android mailing list