[Android] Prevent NPE

Geoffrey Métais git at videolan.org
Mon May 29 15:33:01 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon May 29 09:14:01 2017 +0200| [5e8a6306cdf8516ccf5bf55ca340e7650a4751a0] | committer: Geoffrey Métais

Prevent NPE

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

 .../src/org/videolan/vlc/gui/HistoryFragment.java  | 29 ++++++++++++----------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
index 6c4f069a2..1279efc8f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.java
@@ -178,19 +178,22 @@ public class HistoryFragment extends MediaBrowserFragment implements IRefreshabl
 
     @Override
     public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
-        switch (item.getItemId()) {
-            case R.id.action_history_play:
-                MediaUtils.openList(getActivity(), mHistoryAdapter.getSelection(), 0);
-                break;
-            case R.id.action_history_append:
-                MediaUtils.appendMedia(getActivity(), mHistoryAdapter.getSelection());
-                break;
-            case R.id.action_history_info:
-                showInfoDialog(mHistoryAdapter.getSelection().get(0));
-                break;
-            default:
-                stopActionMode();
-                return false;
+        List<MediaWrapper> selection =  mHistoryAdapter.getSelection();
+        if (!selection.isEmpty()) {
+            switch (item.getItemId()) {
+                case R.id.action_history_play:
+                    MediaUtils.openList(getActivity(), selection, 0);
+                    break;
+                case R.id.action_history_append:
+                    MediaUtils.appendMedia(getActivity(), selection);
+                    break;
+                case R.id.action_history_info:
+                    showInfoDialog(selection.get(0));
+                    break;
+                default:
+                    stopActionMode();
+                    return false;
+            }
         }
         stopActionMode();
         return true;



More information about the Android mailing list