Commit 31e0cb20 authored by David Papazian's avatar David Papazian Committed by Geoffrey Métais

Add Album & Artist sort

Signed-off-by: default avatarGeoffrey Métais <geoffrey.metais@gmail.com>
parent f78ef697
...@@ -27,6 +27,16 @@ ...@@ -27,6 +27,16 @@
android:orderInCategory="2" android:orderInCategory="2"
android:id="@+id/ml_menu_sortby_name" android:id="@+id/ml_menu_sortby_name"
android:title="@string/sortby_name" /> android:title="@string/sortby_name" />
<item
android:orderInCategory="2"
android:id="@+id/ml_menu_sortby_artist_name"
android:title="@string/sortby_artist_name"
android:visible="false" />
<item
android:orderInCategory="2"
android:id="@+id/ml_menu_sortby_album_name"
android:title="@string/sortby_album_name"
android:visible="false" />
<item <item
android:orderInCategory="2" android:orderInCategory="2"
android:id="@+id/ml_menu_sortby_length" android:id="@+id/ml_menu_sortby_length"
......
...@@ -9,12 +9,16 @@ ...@@ -9,12 +9,16 @@
<string name="sortby">Sort by&#8230;</string> <string name="sortby">Sort by&#8230;</string>
<string name="sortby_name">Name</string> <string name="sortby_name">Name</string>
<string name="sortby_name_desc">Name (desc)</string> <string name="sortby_name_desc">Name (desc)</string>
<string name="sortby_artist_name">Artist name</string>
<string name="sortby_artist_name_desc">Artist name (desc)</string>
<string name="sortby_album_name">Album name</string>
<string name="sortby_album_name_desc">Album name (desc)</string>
<string name="sortby_length">Length</string> <string name="sortby_length">Length</string>
<string name="sortby_length_desc">Length (desc)</string> <string name="sortby_length_desc">Length (desc)</string>
<string name="sortby_date">Date</string> <string name="sortby_date">Date</string>
<string name="sortby_date_desc">Date (desc)</string> <string name="sortby_date_desc">Date (desc)</string>
<string name="sortby_number">Tracks</string> <string name="sortby_number">Nb tracks</string>
<string name="sortby_number_desc">Tracks (desc)</string> <string name="sortby_number_desc">Nb tracks (desc)</string>
<string name="searchable_hint">Search…</string> <string name="searchable_hint">Search…</string>
<string name="history">History</string> <string name="history">History</string>
...@@ -51,6 +55,7 @@ ...@@ -51,6 +55,7 @@
<string name="unknown_artist">Unknown Artist</string> <string name="unknown_artist">Unknown Artist</string>
<string name="unknown_album">Unknown Album</string> <string name="unknown_album">Unknown Album</string>
<string name="unknown_genre">Unknown Genre</string> <string name="unknown_genre">Unknown Genre</string>
<string name="unknown_number">Unknown number of Tracks</string>
<string name="songs">Songs</string> <string name="songs">Songs</string>
<plurals name="songs_quantity"> <plurals name="songs_quantity">
<item quantity="one">1 song</item> <item quantity="one">1 song</item>
......
...@@ -121,7 +121,7 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider ...@@ -121,7 +121,7 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
finish(); finish();
return; return;
} }
Permissions.checkReadStoragePermission(this, false); Permissions.checkReadStoragePermission(this, false);
/*** Start initializing the UI ***/ /*** Start initializing the UI ***/
......
...@@ -30,7 +30,6 @@ import android.support.v4.app.FragmentManager; ...@@ -30,7 +30,6 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
...@@ -42,7 +41,6 @@ import android.widget.Filter; ...@@ -42,7 +41,6 @@ import android.widget.Filter;
import org.videolan.medialibrary.Medialibrary; import org.videolan.medialibrary.Medialibrary;
import org.videolan.medialibrary.media.Album; import org.videolan.medialibrary.media.Album;
import org.videolan.medialibrary.media.Artist; import org.videolan.medialibrary.media.Artist;
import org.videolan.medialibrary.media.DummyItem;
import org.videolan.medialibrary.media.Genre; import org.videolan.medialibrary.media.Genre;
import org.videolan.medialibrary.media.MediaLibraryItem; import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper; import org.videolan.medialibrary.media.MediaWrapper;
...@@ -62,10 +60,6 @@ import org.videolan.vlc.util.FileUtils; ...@@ -62,10 +60,6 @@ import org.videolan.vlc.util.FileUtils;
import org.videolan.vlc.util.Util; import org.videolan.vlc.util.Util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import static org.videolan.vlc.R.string.albums;
public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeRefreshLayout.OnRefreshListener, TabLayout.OnTabSelectedListener { public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeRefreshLayout.OnRefreshListener, TabLayout.OnTabSelectedListener {
...@@ -95,6 +89,8 @@ public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeR ...@@ -95,6 +89,8 @@ public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeR
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (savedInstanceState == null)
AudioBrowserAdapter.sMediaComparator.setSortDefault();
mMediaLibrary = VLCApplication.getMLInstance(); mMediaLibrary = VLCApplication.getMLInstance();
mItem = (MediaLibraryItem) (savedInstanceState != null ? mItem = (MediaLibraryItem) (savedInstanceState != null ?
...@@ -124,9 +120,11 @@ public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeR ...@@ -124,9 +120,11 @@ public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeR
ContextMenuRecyclerView songsList = (ContextMenuRecyclerView) mViewPager.getChildAt(MODE_SONG); ContextMenuRecyclerView songsList = (ContextMenuRecyclerView) mViewPager.getChildAt(MODE_SONG);
mLists = new ContextMenuRecyclerView[]{albumsList, songsList}; mLists = new ContextMenuRecyclerView[]{albumsList, songsList};
String[] titles = new String[] {getString(albums), getString(R.string.songs)}; String[] titles = new String[] {getString(R.string.albums), getString(R.string.songs)};
mAlbumsAdapter = new AudioBrowserAdapter(getActivity(), MediaLibraryItem.TYPE_ALBUM, this, false); mAlbumsAdapter = new AudioBrowserAdapter(getActivity(), MediaLibraryItem.TYPE_ALBUM, this, true);
mSongsAdapter = new AudioBrowserAdapter(getActivity(), MediaLibraryItem.TYPE_MEDIA, this, false); mSongsAdapter = new AudioBrowserAdapter(getActivity(), MediaLibraryItem.TYPE_MEDIA, this, true);
mAlbumsAdapter.setParentAdapterType(mItem.getItemType());
mSongsAdapter.setParentAdapterType(mItem.getItemType());
mAdapters = new AudioBrowserAdapter[]{mAlbumsAdapter, mSongsAdapter}; mAdapters = new AudioBrowserAdapter[]{mAlbumsAdapter, mSongsAdapter};
songsList.setAdapter(mSongsAdapter); songsList.setAdapter(mSongsAdapter);
...@@ -297,20 +295,16 @@ public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeR ...@@ -297,20 +295,16 @@ public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeR
albums = Util.arrayToMediaArrayList(((Genre) mItem).getAlbums()); albums = Util.arrayToMediaArrayList(((Genre) mItem).getAlbums());
else else
return; return;
final LinkedList<MediaLibraryItem> songs = new LinkedList<>(); final ArrayList<MediaLibraryItem> songs = new ArrayList<>();
for (MediaLibraryItem album : albums) { for (MediaLibraryItem album : albums) {
String title = album.getTitle(); songs.addAll(Util.arrayToArrayList(album.getTracks()));
if (TextUtils.isEmpty(title))
title = getString(R.string.unknown_album);
songs.add(new DummyItem(title));
songs.addAll(Arrays.asList(album.getTracks()));
} }
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
mAlbumsAdapter.update(albums); mAlbumsAdapter.update(albums);
mSongsAdapter.update(new ArrayList<>(songs)); mSongsAdapter.update(new ArrayList<>(songs));
mFastScroller.setRecyclerView(mLists[mViewPager.getCurrentItem()]); mFastScroller.setRecyclerView(getCurrentRV());
mSwipeRefreshLayout.setRefreshing(false); mSwipeRefreshLayout.setRefreshing(false);
} }
}); });
......
...@@ -39,6 +39,7 @@ import android.widget.Filterable; ...@@ -39,6 +39,7 @@ import android.widget.Filterable;
import org.videolan.medialibrary.media.DummyItem; import org.videolan.medialibrary.media.DummyItem;
import org.videolan.medialibrary.media.MediaLibraryItem; import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.BR; import org.videolan.vlc.BR;
import org.videolan.vlc.R; import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication; import org.videolan.vlc.VLCApplication;
...@@ -71,6 +72,7 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud ...@@ -71,6 +72,7 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud
private IEventsHandler mIEventsHandler; private IEventsHandler mIEventsHandler;
private int mSelectionCount = 0; private int mSelectionCount = 0;
private int mType; private int mType;
private int mParentType = 0;
private BitmapDrawable mDefaultCover; private BitmapDrawable mDefaultCover;
public static MediaLibraryItemComparator sMediaComparator = new MediaLibraryItemComparator(MediaLibraryItemComparator.ADAPTER_AUDIO); public static MediaLibraryItemComparator sMediaComparator = new MediaLibraryItemComparator(MediaLibraryItemComparator.ADAPTER_AUDIO);
...@@ -87,6 +89,15 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud ...@@ -87,6 +89,15 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud
return mType; return mType;
} }
public void setParentAdapterType(int type) {
mParentType = type;
}
public int getParentAdapterType() {
return mParentType;
}
@Override @Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
...@@ -221,8 +232,7 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud ...@@ -221,8 +232,7 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud
if (TextUtils.isEmpty(item.getDescription())) if (TextUtils.isEmpty(item.getDescription()))
item.setDescription(mContext.getString(R.string.unknown_artist)); item.setDescription(mContext.getString(R.string.unknown_artist));
} }
} else if (generateSections) }
break;
} }
} }
...@@ -234,7 +244,7 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud ...@@ -234,7 +244,7 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud
return newList; return newList;
} }
private ArrayList<MediaLibraryItem> generateList(ArrayList<MediaLibraryItem> items, int sortby) { private ArrayList<MediaLibraryItem> generateSections(ArrayList<? extends MediaLibraryItem> items, int sortby) {
ArrayList<MediaLibraryItem> datalist = new ArrayList<>(); ArrayList<MediaLibraryItem> datalist = new ArrayList<>();
switch(sortby) { switch(sortby) {
case MediaLibraryItemComparator.SORT_BY_TITLE: case MediaLibraryItemComparator.SORT_BY_TITLE:
...@@ -252,6 +262,42 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud ...@@ -252,6 +262,42 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud
datalist.add(item); datalist.add(item);
} }
break; break;
case MediaLibraryItemComparator.SORT_BY_ARTIST:
String currentArtist = null;
for (MediaLibraryItem item : items) {
if (item.getItemType() == MediaLibraryItem.TYPE_DUMMY)
continue;
String artist = ((MediaWrapper)item).getArtist();
if (artist == null)
artist = "";
if (currentArtist == null || !TextUtils.equals(currentArtist, artist)) {
currentArtist = artist;
DummyItem sep = new DummyItem(TextUtils.isEmpty(currentArtist)
? mContext.getResources().getString(R.string.unknown_artist)
: currentArtist);
datalist.add(sep);
}
datalist.add(item);
}
break;
case MediaLibraryItemComparator.SORT_BY_ALBUM:
String currentAlbum = null;
for (MediaLibraryItem item : items) {
if (item.getItemType() == MediaLibraryItem.TYPE_DUMMY)
continue;
String album = ((MediaWrapper)item).getAlbum();
if (album == null)
album = "";
if (currentAlbum == null || !TextUtils.equals(currentAlbum, album)) {
currentAlbum = album;
DummyItem sep = new DummyItem(TextUtils.isEmpty(currentAlbum)
? mContext.getResources().getString(R.string.unknown_album)
: currentAlbum);
datalist.add(sep);
}
datalist.add(item);
}
break;
case MediaLibraryItemComparator.SORT_BY_LENGTH : case MediaLibraryItemComparator.SORT_BY_LENGTH :
String currentLengthCategory = null; String currentLengthCategory = null;
for (MediaLibraryItem item : items) { for (MediaLibraryItem item : items) {
...@@ -282,15 +328,16 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud ...@@ -282,15 +328,16 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud
} }
break; break;
case MediaLibraryItemComparator.SORT_BY_NUMBER : case MediaLibraryItemComparator.SORT_BY_NUMBER :
String currentNumber = null; int currentNumber = 0;
for (MediaLibraryItem item : items) { for (MediaLibraryItem item : items) {
if (item.getItemType() == MediaLibraryItem.TYPE_DUMMY) if (item.getItemType() == MediaLibraryItem.TYPE_DUMMY)
continue; continue;
int nb = MediaLibraryItemComparator.getTracksCount(item); int number = MediaLibraryItemComparator.getTracksCount(item);
String number = (nb == 0) ? "Unknown" : String.valueOf(nb); if (currentNumber != number) {
if (currentNumber == null || !TextUtils.equals(currentNumber, number)) {
currentNumber = number; currentNumber = number;
DummyItem sep = new DummyItem(currentNumber); DummyItem sep = new DummyItem(currentNumber == 0
? mContext.getResources().getString(R.string.unknown_number)
: mContext.getResources().getQuantityString(R.plurals.songs_quantity, currentNumber, currentNumber));
datalist.add(sep); datalist.add(sep);
} }
datalist.add(item); datalist.add(item);
...@@ -328,12 +375,12 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud ...@@ -328,12 +375,12 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud
mUpdateExecutor.execute(new Runnable() { mUpdateExecutor.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
final ArrayList<MediaLibraryItem> newListWithSections = prepareNewList(items); final ArrayList<MediaLibraryItem> newListWithSections = prepareNewList(items, mMakeSections);
final DiffUtil.DiffResult result = DiffUtil.calculateDiff(new MediaItemDiffCallback(mDataset, newListWithSections), detectMoves); final DiffUtil.DiffResult result = DiffUtil.calculateDiff(new MediaItemDiffCallback(mDataset, newListWithSections), detectMoves);
VLCApplication.runOnMainThread(new Runnable() { VLCApplication.runOnMainThread(new Runnable() {
@Override @Override
public void run() { public void run() {
addAll(newListWithSections, false); addAll(newListWithSections, true);
result.dispatchUpdatesTo(AudioBrowserAdapter.this); result.dispatchUpdatesTo(AudioBrowserAdapter.this);
processQueue(); processQueue();
} }
...@@ -347,12 +394,20 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud ...@@ -347,12 +394,20 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud
mIEventsHandler.onUpdateFinished(AudioBrowserAdapter.this); mIEventsHandler.onUpdateFinished(AudioBrowserAdapter.this);
} }
private ArrayList<MediaLibraryItem> prepareNewList(final ArrayList<MediaLibraryItem> items) { private ArrayList<MediaLibraryItem> prepareNewList(final ArrayList<MediaLibraryItem> items, boolean sections) {
ArrayList<MediaLibraryItem> newListWithSections; ArrayList<MediaLibraryItem> newListWithSections;
ArrayList<MediaLibraryItem> newList = removeSections(items); if (sections) {
Collections.sort(newList, sMediaComparator); if (sMediaComparator.sortBy == MediaLibraryItemComparator.SORT_DEFAULT) {
int realSortby = sMediaComparator.getRealSort(mType); newListWithSections = generateSections(items, MediaLibraryItemComparator.getDefaultSort(mType, mParentType));
newListWithSections = generateList(newList, realSortby); } else {
ArrayList<MediaLibraryItem> newList = removeSections(items);
Collections.sort(newList, sMediaComparator);
newListWithSections = generateSections(newList, sMediaComparator.getRealSort(mType, mParentType));
}
} else {
Collections.sort(items, sMediaComparator);
newListWithSections = new ArrayList<>(items);
}
return newListWithSections; return newListWithSections;
} }
...@@ -495,26 +550,24 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud ...@@ -495,26 +550,24 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud
return sMediaComparator.sortDirection; return sMediaComparator.sortDirection;
} }
int getDefaultSort(){
return MediaLibraryItemComparator.getDefaultSort(mType, mParentType);
}
int getDefaultDirection() {
return MediaLibraryItemComparator.getDefaultDirection(mType, mParentType);
}
boolean isSortAllowed(int sortby) {
return MediaLibraryItemComparator.isSortAllowed(mType, mParentType, sortby);
}
int getSortBy() { int getSortBy() {
return sMediaComparator.sortBy; return sMediaComparator.sortBy;
} }
void sortBy(int sortby, int direction) { void sortBy(int sortby, int direction) {
boolean sort; boolean sort = isSortAllowed(sortby);
switch (sortby){
case MediaLibraryItemComparator.SORT_BY_LENGTH:
sort = (mType == MediaLibraryItem.TYPE_ALBUM) || (mType == MediaLibraryItem.TYPE_MEDIA);
break;
case MediaLibraryItemComparator.SORT_BY_DATE:
sort = (mType == MediaLibraryItem.TYPE_ALBUM);
break;
case MediaLibraryItemComparator.SORT_BY_NUMBER:
sort = (mType == MediaLibraryItem.TYPE_ALBUM) || (mType == MediaLibraryItem.TYPE_PLAYLIST);
break;
default:
sort = true;
break;
}
if (sort) { if (sort) {
sMediaComparator.sortBy(sortby, direction); sMediaComparator.sortBy(sortby, direction);
update(mDataset, true); update(mDataset, true);
......
...@@ -829,18 +829,6 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre ...@@ -829,18 +829,6 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
mHandler.sendEmptyMessage(UPDATE_LIST); mHandler.sendEmptyMessage(UPDATE_LIST);
} }
@Override
public void sortBy(int sortby) {
int sortDirection = mAlbumsAdapter.getSortDirection();
int sortBy = mAlbumsAdapter.getSortBy();
if (sortby == sortBy)
sortDirection*=-1;
else
sortDirection = 1;
for (AudioBrowserAdapter adapter : mAdapters)
adapter.sortBy(sortby, sortDirection);
}
@Override @Override
public int sortDirection(int sortby) { public int sortDirection(int sortby) {
return getCurrentAdapter().sortDirection(sortby); return getCurrentAdapter().sortDirection(sortby);
......
...@@ -41,6 +41,7 @@ import org.videolan.vlc.gui.helpers.UiTools; ...@@ -41,6 +41,7 @@ import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.interfaces.Filterable; import org.videolan.vlc.interfaces.Filterable;
import org.videolan.vlc.interfaces.IEventsHandler; import org.videolan.vlc.interfaces.IEventsHandler;
import org.videolan.vlc.util.AndroidDevices; import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.MediaLibraryItemComparator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
...@@ -48,7 +49,7 @@ import java.util.List; ...@@ -48,7 +49,7 @@ import java.util.List;
public abstract class BaseAudioBrowser extends SortableFragment implements IEventsHandler, Filterable { public abstract class BaseAudioBrowser extends SortableFragment implements IEventsHandler, Filterable {
abstract protected AudioBrowserAdapter getCurrentAdapter(); abstract public AudioBrowserAdapter getCurrentAdapter();
public View mSearchButtonView; public View mSearchButtonView;
public ContentActivity mActivity; public ContentActivity mActivity;
protected AudioBrowserAdapter[] mAdapters; protected AudioBrowserAdapter[] mAdapters;
...@@ -62,14 +63,14 @@ public abstract class BaseAudioBrowser extends SortableFragment implements IEven ...@@ -62,14 +63,14 @@ public abstract class BaseAudioBrowser extends SortableFragment implements IEven
@Override @Override
public void onPrepareOptionsMenu(Menu menu) { public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu); super.onPrepareOptionsMenu(menu);
int type = getCurrentAdapter().getAdapterType(); AudioBrowserAdapter adapter = getCurrentAdapter();
boolean album = type == MediaLibraryItem.TYPE_ALBUM;
boolean songs = type == MediaLibraryItem.TYPE_MEDIA;
boolean playlist = type == MediaLibraryItem.TYPE_PLAYLIST;
menu.findItem(R.id.ml_menu_sortby_length).setVisible(album||playlist||songs);
menu.findItem(R.id.ml_menu_sortby_date).setVisible(album);
menu.findItem(R.id.ml_menu_sortby_number).setVisible(album||playlist);
menu.findItem(R.id.ml_menu_last_playlist).setVisible(true); menu.findItem(R.id.ml_menu_last_playlist).setVisible(true);
menu.findItem(R.id.ml_menu_sortby_name).setVisible(adapter.isSortAllowed(MediaLibraryItemComparator.SORT_BY_TITLE));
menu.findItem(R.id.ml_menu_sortby_artist_name).setVisible(adapter.isSortAllowed(MediaLibraryItemComparator.SORT_BY_ARTIST));
menu.findItem(R.id.ml_menu_sortby_album_name).setVisible(adapter.isSortAllowed(MediaLibraryItemComparator.SORT_BY_ALBUM));
menu.findItem(R.id.ml_menu_sortby_length).setVisible(adapter.isSortAllowed(MediaLibraryItemComparator.SORT_BY_LENGTH));
menu.findItem(R.id.ml_menu_sortby_date).setVisible(adapter.isSortAllowed(MediaLibraryItemComparator.SORT_BY_DATE));
menu.findItem(R.id.ml_menu_sortby_number).setVisible(adapter.isSortAllowed(MediaLibraryItemComparator.SORT_BY_NUMBER));
} }
@Override @Override
...@@ -208,15 +209,19 @@ public abstract class BaseAudioBrowser extends SortableFragment implements IEven ...@@ -208,15 +209,19 @@ public abstract class BaseAudioBrowser extends SortableFragment implements IEven
} }
@Override @Override
public void sortBy(int sortby) { public void sortBy(int newSortby) {
AudioBrowserAdapter adapter = mAdapters[0]; AudioBrowserAdapter adapter = mAdapters[0];
int sortDirection = adapter.getSortDirection(); int sortDirection = adapter.getSortDirection();
int sortBy = adapter.getSortBy(); int oldSortby = adapter.getSortBy();
if (sortby == sortBy) int delfaultSortby = getCurrentAdapter().getDefaultSort();
int defaultDirection = getCurrentAdapter().getDefaultDirection();
if (newSortby == oldSortby)
sortDirection*=-1; sortDirection*=-1;
else if (newSortby == delfaultSortby)
sortDirection = defaultDirection*-1;
else else
sortDirection = 1; sortDirection = 1;
for (AudioBrowserAdapter audioBrowserAdapter : mAdapters) for (AudioBrowserAdapter audioBrowserAdapter : mAdapters)
audioBrowserAdapter.sortBy(sortby, sortDirection); audioBrowserAdapter.sortBy(newSortby, sortDirection);
} }
} }
...@@ -29,8 +29,8 @@ import android.view.Menu; ...@@ -29,8 +29,8 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import org.videolan.vlc.R; import org.videolan.vlc.R;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.util.MediaLibraryItemComparator; import org.videolan.vlc.util.MediaLibraryItemComparator;
import org.videolan.vlc.util.Util;
public abstract class SortableFragment extends MediaBrowserFragment { public abstract class SortableFragment extends MediaBrowserFragment {
...@@ -39,7 +39,7 @@ public abstract class SortableFragment extends MediaBrowserFragment { ...@@ -39,7 +39,7 @@ public abstract class SortableFragment extends MediaBrowserFragment {
@Override @Override
public void onPrepareOptionsMenu(Menu menu) { public void onPrepareOptionsMenu(Menu menu) {
Util.updateSortTitles(this, menu); UiTools.updateSortTitles(this, menu);
super.onPrepareOptionsMenu(menu); super.onPrepareOptionsMenu(menu);
} }
...@@ -56,6 +56,14 @@ public abstract class SortableFragment extends MediaBrowserFragment { ...@@ -56,6 +56,14 @@ public abstract class SortableFragment extends MediaBrowserFragment {
sortBy(MediaLibraryItemComparator.SORT_BY_TITLE); sortBy(MediaLibraryItemComparator.SORT_BY_TITLE);
onPrepareOptionsMenu(mMenu); onPrepareOptionsMenu(mMenu);
return true; return true;
case R.id.ml_menu_sortby_artist_name:
sortBy(MediaLibraryItemComparator.SORT_BY_ARTIST);
onPrepareOptionsMenu(mMenu);
return true;
case R.id.ml_menu_sortby_album_name:
sortBy(MediaLibraryItemComparator.SORT_BY_ALBUM);
onPrepareOptionsMenu(mMenu);
return true;
case R.id.ml_menu_sortby_length: case R.id.ml_menu_sortby_length:
sortBy(MediaLibraryItemComparator.SORT_BY_LENGTH); sortBy(MediaLibraryItemComparator.SORT_BY_LENGTH);
onPrepareOptionsMenu(mMenu); onPrepareOptionsMenu(mMenu);
......
...@@ -50,6 +50,8 @@ import android.text.Html; ...@@ -50,6 +50,8 @@ import android.text.Html;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;