[Android] Prevent IndexOutOfBoundsException
Geoffrey Métais
git at videolan.org
Tue Feb 14 18:54:41 CET 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb 14 18:42:44 2017 +0100| [201bdb04e5e4388fd2654b3968fb8d25a36472db] | committer: Geoffrey Métais
Prevent IndexOutOfBoundsException
> https://code.videolan.org/videolan/vlc-android/commit/201bdb04e5e4388fd2654b3968fb8d25a36472db
---
.../videolan/vlc/gui/audio/BaseAudioBrowser.java | 44 +++++++++---------
.../vlc/gui/browser/BaseBrowserFragment.java | 43 +++++++++--------
.../videolan/vlc/gui/video/VideoGridFragment.java | 54 +++++++++++-----------
3 files changed, 74 insertions(+), 67 deletions(-)
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 0b0d9ab..e5b00e2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.java
@@ -77,28 +77,30 @@ public abstract class BaseAudioBrowser extends MediaBrowserFragment implements I
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
List<MediaLibraryItem> list = getCurrentAdapter().getSelection();
- ArrayList<MediaWrapper> tracks = new ArrayList<>();
- for (MediaLibraryItem mediaItem : list)
- tracks.addAll(Arrays.asList(mediaItem.getTracks(mMediaLibrary)));
stopActionMode();
- switch (item.getItemId()) {
- case R.id.action_mode_audio_play:
- mService.load(tracks, 0);
- break;
- case R.id.action_mode_audio_append:
- mService.append(tracks);
- break;
- case R.id.action_mode_audio_add_playlist:
- UiTools.addToPlaylist(getActivity(), tracks);
- break;
- case R.id.action_mode_audio_info:
- showInfoDialog((MediaWrapper) list.get(0));
- break;
- case R.id.action_mode_audio_set_song:
- AudioUtil.setRingtone((MediaWrapper) list.get(0), getActivity());
- break;
- default:
- return false;
+ if (!list.isEmpty()) {
+ ArrayList<MediaWrapper> tracks = new ArrayList<>();
+ for (MediaLibraryItem mediaItem : list)
+ tracks.addAll(Arrays.asList(mediaItem.getTracks(mMediaLibrary)));
+ switch (item.getItemId()) {
+ case R.id.action_mode_audio_play:
+ mService.load(tracks, 0);
+ break;
+ case R.id.action_mode_audio_append:
+ mService.append(tracks);
+ break;
+ case R.id.action_mode_audio_add_playlist:
+ UiTools.addToPlaylist(getActivity(), tracks);
+ break;
+ case R.id.action_mode_audio_info:
+ showInfoDialog((MediaWrapper) list.get(0));
+ break;
+ case R.id.action_mode_audio_set_song:
+ AudioUtil.setRingtone((MediaWrapper) list.get(0), getActivity());
+ break;
+ default:
+ return false;
+ }
}
return true;
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index 628ce6c..980ab99 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -664,26 +664,29 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
- switch (item.getItemId()) {
- case R.id.action_mode_file_play:
- mService.load(mAdapter.getSelection(), 0);
- break;
- case R.id.action_mode_file_append:
- mService.append(mAdapter.getSelection());
- break;
- case R.id.action_mode_file_delete:
- for (MediaWrapper media : mAdapter.getSelection())
- deleteMedia(media, true);
- break;
- case R.id.action_mode_file_add_playlist:
- UiTools.addToPlaylist(getActivity(), mAdapter.getSelection());
- break;
- case R.id.action_mode_file_info:
- showMediaInfo(mAdapter.getSelection().get(0));
- break;
- default:
- stopActionMode();
- return false;
+ ArrayList<MediaWrapper> list = mAdapter.getSelection();
+ if (!list.isEmpty()) {
+ switch (item.getItemId()) {
+ case R.id.action_mode_file_play:
+ mService.load(list, 0);
+ break;
+ case R.id.action_mode_file_append:
+ mService.append(list);
+ break;
+ case R.id.action_mode_file_delete:
+ for (MediaWrapper media : list)
+ deleteMedia(media, true);
+ break;
+ case R.id.action_mode_file_add_playlist:
+ UiTools.addToPlaylist(getActivity(), list);
+ break;
+ case R.id.action_mode_file_info:
+ showMediaInfo(list.get(0));
+ break;
+ default:
+ stopActionMode();
+ return false;
+ }
}
stopActionMode();
return true;
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index 0d5704b..01ab04a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -528,32 +528,34 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
- switch (item.getItemId()) {
- case R.id.action_video_play:
- MediaUtils.openList(getActivity(), mVideoAdapter.getSelection(), 0);
- break;
- case R.id.action_video_append:
- MediaUtils.appendMedia(getActivity(), mVideoAdapter.getSelection());
- break;
- case R.id.action_video_info:
- showInfoDialog(mVideoAdapter.getSelection().get(0));
- break;
-// case R.id.action_video_delete:
-// for (int position : mVideoAdapter.getSelectedPositions())
-// removeVideo(position, mVideoAdapter.getItem(position));
-// break;
- case R.id.action_video_download_subtitles:
- MediaUtils.getSubs(getActivity(), mVideoAdapter.getSelection());
- break;
- case R.id.action_video_play_audio:
- List<MediaWrapper> list = mVideoAdapter.getSelection();
- for (MediaWrapper media : list)
- media.addFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
- MediaUtils.openList(getActivity(), list, 0);
- break;
- default:
- stopActionMode();
- return false;
+ List<MediaWrapper> list = mVideoAdapter.getSelection();
+ if (!list.isEmpty()) {
+ switch (item.getItemId()) {
+ case R.id.action_video_play:
+ MediaUtils.openList(getActivity(), list, 0);
+ break;
+ case R.id.action_video_append:
+ MediaUtils.appendMedia(getActivity(), list);
+ break;
+ case R.id.action_video_info:
+ showInfoDialog(list.get(0));
+ break;
+ // case R.id.action_video_delete:
+ // for (int position : mVideoAdapter.getSelectedPositions())
+ // removeVideo(position, mVideoAdapter.getItem(position));
+ // break;
+ case R.id.action_video_download_subtitles:
+ MediaUtils.getSubs(getActivity(), list);
+ break;
+ case R.id.action_video_play_audio:
+ for (MediaWrapper media : list)
+ media.addFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
+ MediaUtils.openList(getActivity(), list, 0);
+ break;
+ default:
+ stopActionMode();
+ return false;
+ }
}
stopActionMode();
return true;
More information about the Android
mailing list