[Android] Sort enabled in Video directories
David Papazian
git at videolan.org
Tue Jul 18 16:14:01 CEST 2017
vlc-android | branch: master | David Papazian <david.papazian at metz.supelec.fr> | Tue Jul 18 15:26:26 2017 +0200| [0a174381a3c188d2834622f87ed13422f5572789] | committer: Geoffrey Métais
Sort enabled in Video directories
Signed-off-by: Geoffrey Métais <geoffrey.metais at gmail.com>
> https://code.videolan.org/videolan/vlc-android/commit/0a174381a3c188d2834622f87ed13422f5572789
---
vlc-android/res/menu/video_group.xml | 8 ++-
.../org/videolan/vlc/gui/SecondaryActivity.java | 63 ++++++++++++++++++++--
2 files changed, 66 insertions(+), 5 deletions(-)
diff --git a/vlc-android/res/menu/video_group.xml b/vlc-android/res/menu/video_group.xml
index 6534074a8..779cbae7a 100644
--- a/vlc-android/res/menu/video_group.xml
+++ b/vlc-android/res/menu/video_group.xml
@@ -13,9 +13,15 @@
<item
android:id="@+id/ml_menu_sortby_length"
android:title="@string/sortby_length" />
+ <item
+ android:id="@+id/ml_menu_sortby_date"
+ android:title="@string/sortby_date" />
+ <item
+ android:id="@+id/ml_menu_sortby_number"
+ android:title="@string/sortby_number" />
</menu>
</item>
- <item
+ <item
android:id="@+id/ml_menu_refresh"
android:icon="@drawable/ic_menu_refresh"
android:title="@string/refresh"
diff --git a/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java b/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java
index 5118d94bd..51f133464 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java
@@ -116,15 +116,70 @@ public class SecondaryActivity extends AudioPlayerContainerActivity {
}
@Override
- public boolean onOptionsItemSelected(MenuItem item) {
+ public boolean onPrepareOptionsMenu (Menu menu) {
+ super.onPrepareOptionsMenu(menu);
+ if (menu == null)
+ return false;
+ Fragment current = mFragment;
+ MenuItem item = menu.findItem(R.id.ml_menu_sortby);
+ if (item == null)
+ return false;
+ // Disable the sort option if we can't use it on the current fragment.
+ if (current == null || !(current instanceof ISortable)) {
+ item.setEnabled(false);
+ item.setVisible(false);
+ } else {
+ ISortable sortable = (ISortable) current;
+ item.setEnabled(true);
+ item.setVisible(true);
+ if (current instanceof VideoGridFragment) {
+ menu.findItem(R.id.ml_menu_sortby_length).setVisible(true);
+ menu.findItem(R.id.ml_menu_sortby_date).setVisible(true);
+ menu.findItem(R.id.ml_menu_sortby_number).setVisible(false);
+ } else {
+ menu.findItem(R.id.ml_menu_sortby_length).setVisible(false);
+ menu.findItem(R.id.ml_menu_sortby_date).setVisible(false);
+ menu.findItem(R.id.ml_menu_sortby_number).setVisible(false);
+ }
+ if (sortable.sortDirection(MediaLibraryItemComparator.SORT_BY_TITLE) == 1)
+ menu.findItem(R.id.ml_menu_sortby_name).setTitle(R.string.sortby_name_desc);
+ else
+ menu.findItem(R.id.ml_menu_sortby_name).setTitle(R.string.sortby_name);
+ if (sortable.sortDirection(MediaLibraryItemComparator.SORT_BY_LENGTH) == 1)
+ menu.findItem(R.id.ml_menu_sortby_length).setTitle(R.string.sortby_length_desc);
+ else
+ menu.findItem(R.id.ml_menu_sortby_length).setTitle(R.string.sortby_length);
+ if (sortable.sortDirection(MediaLibraryItemComparator.SORT_BY_DATE) == 1)
+ menu.findItem(R.id.ml_menu_sortby_date).setTitle(R.string.sortby_date_desc);
+ else
+ menu.findItem(R.id.ml_menu_sortby_date).setTitle(R.string.sortby_date);
+ if (sortable.sortDirection(MediaLibraryItemComparator.SORT_BY_NUMBER) == 1)
+ menu.findItem(R.id.ml_menu_sortby_number).setTitle(R.string.sortby_number_desc);
+ else
+ menu.findItem(R.id.ml_menu_sortby_number).setTitle(R.string.sortby_number);
+ }
+ return true;
+ }
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.ml_menu_sortby_name:
+ ((ISortable) mFragment).sortBy(MediaLibraryItemComparator.SORT_BY_TITLE);
+ supportInvalidateOptionsMenu();
+ break;
case R.id.ml_menu_sortby_length:
- ((ISortable) mFragment).sortBy(item.getItemId() == R.id.ml_menu_sortby_name
- ? MediaLibraryItemComparator.SORT_BY_TITLE
- : MediaLibraryItemComparator.SORT_BY_LENGTH);
+ ((ISortable) mFragment).sortBy(MediaLibraryItemComparator.SORT_BY_LENGTH);
+ supportInvalidateOptionsMenu();
+ break;
+ case R.id.ml_menu_sortby_date:
+ ((ISortable) mFragment).sortBy(MediaLibraryItemComparator.SORT_BY_DATE);
+ supportInvalidateOptionsMenu();
+ break;
+ case R.id.ml_menu_sortby_number:
+ ((ISortable) mFragment).sortBy(MediaLibraryItemComparator.SORT_BY_NUMBER);
+ supportInvalidateOptionsMenu();
break;
case R.id.ml_menu_refresh:
Medialibrary ml = VLCApplication.getMLInstance();
More information about the Android
mailing list