[Android] albums/songs: add PlayAll by clicking on separators
unknown
git at videolan.org
Sun May 18 21:01:08 CEST 2014
vlc-ports/android | branch: master | unknown <ZT5032 at GA002232D.user.par.gaselys.com> | Fri May 16 16:31:40 2014 +0200| [84007d24d89ef830cef8cacba00ec8548c2d4daa] | committer: Sébastien Toque
albums/songs: add PlayAll by clicking on separators
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=84007d24d89ef830cef8cacba00ec8548c2d4daa
---
.../vlc/gui/audio/AudioAlbumsSongsFragment.java | 8 ++----
.../vlc/gui/audio/AudioBrowserListAdapter.java | 26 ++++++++++++--------
2 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
index f1eb7e9..2f97715 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -316,16 +316,12 @@ public class AudioAlbumsSongsFragment extends SherlockFragment {
mSongsAdapter.clear();
Collections.sort(mediaList, MediaComparators.byAlbum);
- String lastAlbumName = new String();
for (int i = 0; i < mediaList.size(); ++i) {
Media media = mediaList.get(i);
+ mAlbumsAdapter.addSeparator(media.getArtist(), media);
mAlbumsAdapter.add(media.getAlbum(), null, media);
-
- if (!lastAlbumName.equals(media.getAlbum())) {
- mSongsAdapter.addSeparator(media.getAlbum());
- lastAlbumName = media.getAlbum();
- }
+ mSongsAdapter.addSeparator(media.getAlbum(), media);
mSongsAdapter.add(media.getTitle(), null, media);
}
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
index dc00a6d..e7f3f5c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
@@ -45,6 +45,7 @@ public class AudioBrowserListAdapter extends BaseAdapter {
// Key: the item title, value: ListItem of only media item (no separator).
private Map<String, ListItem> mMediaItemMap;
+ private Map<String, ListItem> mSeparatorItemMap;
// A list of all the list items: media items and separators.
private ArrayList<ListItem> mItems;
@@ -68,12 +69,10 @@ public class AudioBrowserListAdapter extends BaseAdapter {
public ArrayList<Media> mMediaList;
public boolean mIsSeparator;
- public ListItem(String title, String subTitle,
- Media media, boolean isSeparator) {
- if (!isSeparator) {
- mMediaList = new ArrayList<Media>();
+ public ListItem(String title, String subTitle, Media media, boolean isSeparator) {
+ mMediaList = new ArrayList<Media>();
+ if (media != null)
mMediaList.add(media);
- }
mTitle = title;
mSubTitle = subTitle;
mIsSeparator = isSeparator;
@@ -82,6 +81,7 @@ public class AudioBrowserListAdapter extends BaseAdapter {
public AudioBrowserListAdapter(Context context, int itemType) {
mMediaItemMap = new HashMap<String, ListItem>();
+ mSeparatorItemMap = new HashMap<String, ListItem>();
mItems = new ArrayList<ListItem>();
mContext = context;
if (itemType != ITEM_WITHOUT_COVER && itemType != ITEM_WITH_COVER)
@@ -128,9 +128,14 @@ public class AudioBrowserListAdapter extends BaseAdapter {
notifyDataSetChanged();
}
- public void addSeparator(String title) {
- ListItem item = new ListItem(title, null, null, true);
- mItems.add(item);
+ public void addSeparator(String title, Media media) {
+ if (mSeparatorItemMap.containsKey(title))
+ mSeparatorItemMap.get(title).mMediaList.add(media);
+ else {
+ ListItem item = new ListItem(title, null, media, true);
+ mSeparatorItemMap.put(title, item);
+ mItems.add(item);
+ }
notifyDataSetChanged();
}
@@ -159,6 +164,7 @@ public class AudioBrowserListAdapter extends BaseAdapter {
public void clear() {
mMediaItemMap.clear();
+ mSeparatorItemMap.clear();
mItems.clear();
notifyDataSetChanged();
}
@@ -319,7 +325,7 @@ public class AudioBrowserListAdapter extends BaseAdapter {
@Override
public boolean isEnabled(int position) {
- return !mItems.get(position).mIsSeparator;
+ return position < mItems.size() && mItems.get(position).mMediaList.size() > 0;
}
public ArrayList<Media> getMedia(int position) {
@@ -333,7 +339,7 @@ public class AudioBrowserListAdapter extends BaseAdapter {
public ArrayList<String> getLocations(int position) {
// Return all the media locations of a list item list.
ArrayList<String> locations = new ArrayList<String>();
- if (position < mItems.size() && !mItems.get(position).mIsSeparator) {
+ if (isEnabled(position)) {
ArrayList<Media> mediaList = mItems.get(position).mMediaList;
for (int i = 0; i < mediaList.size(); ++i)
locations.add(mediaList.get(i).getLocation());
More information about the Android
mailing list