Commit 13c689aa authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Add sort by filename option

parent f2e26e4c
......@@ -50,6 +50,7 @@ public class Medialibrary {
public final static int SORT_ARTIST = 7;
public final static int SORT_PLAYCOUNT = 8;
public final static int SORT_ALBUM = 9;
public final static int SORT_FILENAME = 10;
public static final int FLAG_MEDIA_UPDATED_AUDIO = 1 << 0;
public static final int FLAG_MEDIA_UPDATED_AUDIO_EMPTY = 1 << 1;
......
......@@ -36,6 +36,10 @@
android:orderInCategory="2"
android:id="@+id/ml_menu_sortby_name"
android:title="@string/sortby_name" />
<item
android:orderInCategory="2"
android:id="@+id/ml_menu_sortby_filename"
android:title="@string/sortby_filename" />
<item
android:orderInCategory="2"
android:id="@+id/ml_menu_sortby_artist_name"
......
......@@ -33,6 +33,9 @@
<item
android:id="@+id/ml_menu_sortby_name"
android:title="@string/sortby_name" />
<item
android:id="@+id/ml_menu_sortby_filename"
android:title="@string/sortby_filename" />
<item
android:id="@+id/ml_menu_sortby_length"
android:title="@string/sortby_length" />
......
......@@ -10,6 +10,9 @@
<item
android:id="@+id/ml_menu_sortby_name"
android:title="@string/sortby_name" />
<item
android:id="@+id/ml_menu_sortby_filename"
android:title="@string/sortby_filename" />
<item
android:id="@+id/ml_menu_sortby_length"
android:title="@string/sortby_length" />
......
......@@ -9,6 +9,8 @@
<string name="sortby">Sort by&#8230;</string>
<string name="sortby_name">Name</string>
<string name="sortby_name_desc">Name (desc)</string>
<string name="sortby_filename">File name</string>
<string name="sortby_filename_desc">File 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>
......
......@@ -289,6 +289,7 @@ public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeR
@Override
public void onUpdateFinished(RecyclerView.Adapter adapter) {
super.onUpdateFinished(adapter);
mFastScroller.setRecyclerView(getCurrentRV());
mSwipeRefreshLayout.setRefreshing(false);
if (mAlbumsAdapter.isEmpty()) mViewPager.setCurrentItem(1);
......
......@@ -65,7 +65,6 @@ import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.FileUtils;
import org.videolan.vlc.util.WeakHandler;
import org.videolan.vlc.util.WorkersKt;
import org.videolan.vlc.viewmodels.BaseModel;
import org.videolan.vlc.viewmodels.audio.AlbumProvider;
import org.videolan.vlc.viewmodels.audio.ArtistProvider;
import org.videolan.vlc.viewmodels.audio.AudioModel;
......@@ -498,6 +497,7 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
@Override
public void onUpdateFinished(RecyclerView.Adapter adapter) {
super.onUpdateFinished(adapter);
if (adapter == getCurrentAdapter()) {
if (!mMediaLibrary.isWorking()) mHandler.sendEmptyMessage(UNSET_REFRESHING);
mSwipeRefreshLayout.setEnabled(((LinearLayoutManager)getCurrentRV().getLayoutManager()).findFirstVisibleItemPosition() <= 0);
......
......@@ -24,6 +24,7 @@
package org.videolan.vlc.gui.audio;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
......@@ -175,4 +176,9 @@ public abstract class BaseAudioBrowser extends MediaBrowserFragment<AudioModel>
@Override
public void onCtxClick(View anchor, final int position, final MediaLibraryItem mediaItem) {}
@Override
public void onUpdateFinished(RecyclerView.Adapter adapter) {
UiTools.updateSortTitles(this);
}
}
......@@ -30,6 +30,7 @@ import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.ActionMode;
import android.view.ContextMenu;
......@@ -224,6 +225,7 @@ public abstract class MediaBrowserFragment<T extends BaseModel> extends Fragment
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.ml_menu_sortby).setVisible(getProvider().canSortByName());
menu.findItem(R.id.ml_menu_sortby_filename).setVisible(getProvider().canSortByFileNameName());
menu.findItem(R.id.ml_menu_sortby_artist_name).setVisible(getProvider().canSortByArtist());
menu.findItem(R.id.ml_menu_sortby_album_name).setVisible(getProvider().canSortByAlbum());
menu.findItem(R.id.ml_menu_sortby_length).setVisible(getProvider().canSortByDuration());
......@@ -238,6 +240,9 @@ public abstract class MediaBrowserFragment<T extends BaseModel> extends Fragment
case R.id.ml_menu_sortby_name:
sortBy(Medialibrary.SORT_ALPHA);
return true;
case R.id.ml_menu_sortby_filename:
sortBy(Medialibrary.SORT_FILENAME);
return true;
case R.id.ml_menu_sortby_length:
sortBy(Medialibrary.SORT_DURATION);
return true;
......@@ -268,9 +273,9 @@ public abstract class MediaBrowserFragment<T extends BaseModel> extends Fragment
}
public Menu getMenu() {
final AudioPlayerContainerActivity activity = (AudioPlayerContainerActivity) getActivity();
if (activity == null) return null;
return activity.getMenu();
final FragmentActivity activity = getActivity();
if (!(activity instanceof AudioPlayerContainerActivity)) return null;
return ((AudioPlayerContainerActivity)activity).getMenu();
}
......
......@@ -330,6 +330,8 @@ public class UiTools {
final boolean desc = model.getDesc();
MenuItem item = menu.findItem(R.id.ml_menu_sortby_name);
if (item != null) item.setTitle(sort == Medialibrary.SORT_ALPHA && !desc ? R.string.sortby_name_desc : R.string.sortby_name);
item = menu.findItem(R.id.ml_menu_sortby_filename);
if (item != null) item.setTitle(sort == Medialibrary.SORT_FILENAME && !desc ? R.string.sortby_filename_desc : R.string.sortby_filename);
item = menu.findItem(R.id.ml_menu_sortby_artist_name);
if (item != null) item.setTitle(sort == Medialibrary.SORT_ARTIST && !desc ? R.string.sortby_artist_name_desc : R.string.sortby_artist_name);
item = menu.findItem(R.id.ml_menu_sortby_album_name);
......
......@@ -161,6 +161,7 @@ interface RefreshModel {
fun <T : MediaLibraryItem> BaseModel<T>.canSortBy(sort: Int) = when(sort) {
Medialibrary.SORT_DEFAULT -> true
Medialibrary.SORT_ALPHA -> canSortByName()
Medialibrary.SORT_FILENAME -> canSortByFileNameName()
Medialibrary.SORT_DURATION -> canSortByDuration()
Medialibrary.SORT_INSERTIONDATE -> canSortByInsertionDate()
Medialibrary.SORT_LASTMODIFICATIONDATE -> canSortByLastModified()
......
......@@ -42,6 +42,7 @@ abstract class BaseModel<T : MediaLibraryItem> : ViewModel(), RefreshModel {
protected open val sortKey = this.javaClass.simpleName!!
open fun canSortByName() = true
open fun canSortByFileNameName() = false
open fun canSortByDuration() = false
open fun canSortByInsertionDate() = false
open fun canSortByLastModified() = false
......
......@@ -38,6 +38,7 @@ import org.videolan.vlc.util.Util
open class VideosProvider(private val group: String?, private val minGroupLen: Int, customSort : Int) : MedialibraryModel<MediaWrapper>(), MediaAddedCb {
override val sortKey = "${super.sortKey}_$group"
override fun canSortByFileNameName() = true
override fun canSortByDuration() = true
override fun canSortByLastModified() = true
private val res by lazy { VLCApplication.getAppResources() }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment