[Android] Snackbars now use Runnable for cancel action

Geoffrey Métais git at videolan.org
Wed Jan 6 18:35:58 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jan  6 17:38:57 2016 +0100| [274531c78fa4b6b0c9eade8e8e5639f398a929d2] | committer: Geoffrey Métais

Snackbars now use Runnable for cancel action

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

 vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java | 6 +++---
 vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java       | 9 ++-------
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
index ae83b6e..8157bbe 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
@@ -162,16 +162,16 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
         String message = String.format(VLCApplication.getAppResources().getString(R.string.remove_playlist_item), media.getTitle());
         if (mAudioPlayer instanceof Fragment){
             View v = ((Fragment) mAudioPlayer).getView();
-            View.OnClickListener cancelAction = new View.OnClickListener() {
+            Runnable cancelAction = new Runnable() {
                 @Override
-                public void onClick(View v) {
+                public void run() {
                     mDataSet.add(position, media);
                     mOriginalDataSet.add(position, media);
                     notifyItemInserted(position);
                     mService.insertItem(position, media);
                 }
             };
-            UiTools.snackerWithCancel(v, message, cancelAction);
+            UiTools.snackerWithCancel(v, message, null, cancelAction);
         } else if (mAudioPlayer instanceof Context){
             Toast.makeText((Context) mAudioPlayer, message, Toast.LENGTH_SHORT).show();
         }
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 8fe6ed0..bfd973f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
@@ -65,12 +65,7 @@ public class UiTools {
     }
 
     /** Print an on-screen message to alert the user, with undo action */
-    public static void snackerWithCancel(@NonNull View view, @NonNull String message, @NonNull final View.OnClickListener cancelAction) {
-        snackerWithCancel(view, message, null, cancelAction);
-    }
-
-    /** 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, @Nullable final View.OnClickListener cancelAction) {
+    public static void snackerWithCancel(@NonNull View view, @NonNull String message, @NonNull final Runnable action, @Nullable final Runnable cancelAction) {
         Snackbar.make(view, message, DELETE_DURATION)
                 .setAction(android.R.string.cancel, new View.OnClickListener() {
                     @Override
@@ -78,7 +73,7 @@ public class UiTools {
                         if (action != null)
                             sHandler.removeCallbacks(action);
                         if (cancelAction != null)
-                            cancelAction.onClick(v);
+                            cancelAction.run();
                     }
                 })
                 .show();



More information about the Android mailing list