[Android] Refine sort option display

Geoffrey Métais git at videolan.org
Tue Mar 24 15:28:37 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Mar 24 15:28:08 2015 +0100| [8ee475a70328279f5b6b252fc7c8920696f75fe4] | committer: Geoffrey Métais

Refine sort option display

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=8ee475a70328279f5b6b252fc7c8920696f75fe4
---

 vlc-android/res/values/strings.xml                         |    2 ++
 vlc-android/src/org/videolan/vlc/gui/MainActivity.java     |   12 ++++++++++++
 .../src/org/videolan/vlc/gui/video/VideoGridFragment.java  |    5 +++++
 .../src/org/videolan/vlc/gui/video/VideoListAdapter.java   |    7 +++++++
 vlc-android/src/org/videolan/vlc/interfaces/ISortable.java |    1 +
 5 files changed, 27 insertions(+)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 9ef83ec..e11a44f 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -9,7 +9,9 @@
     <string name="other">Other</string>
     <string name="sortby">Sort by…</string>
     <string name="sortby_name">Name</string>
+    <string name="sortby_name_desc">Name (desc)</string>
     <string name="sortby_length">Length</string>
+    <string name="sortby_length_desc">Length (desc)</string>
     <string name="searchable_hint">Search…</string>
     <string name="history">History</string>
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index ae01914..9e12197 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -487,8 +487,19 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
             menu.findItem(R.id.ml_menu_sortby).setVisible(false);
         }
         else {
+            ISortable sortable = (ISortable) current;
             menu.findItem(R.id.ml_menu_sortby).setEnabled(true);
             menu.findItem(R.id.ml_menu_sortby).setVisible(true);
+            MenuItem item = menu.findItem(R.id.ml_menu_sortby_name);
+                if (sortable.sortDirection(VideoListAdapter.SORT_BY_TITLE) == 1)
+                    item.setTitle(R.string.sortby_name_desc);
+                else
+                    item.setTitle(R.string.sortby_name);
+            item = menu.findItem(R.id.ml_menu_sortby_length);
+                if (sortable.sortDirection(VideoListAdapter.SORT_BY_LENGTH) == 1)
+                    item.setTitle(R.string.sortby_length_desc);
+                else
+                    item.setTitle(R.string.sortby_length);
         }
 
         boolean networkSave = current instanceof NetworkFragment && !((NetworkFragment)current).isRootDirectory();
@@ -532,6 +543,7 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
                     ((ISortable) current).sortBy(item.getItemId() == R.id.ml_menu_sortby_name
                     ? VideoListAdapter.SORT_BY_TITLE
                     : VideoListAdapter.SORT_BY_LENGTH);
+                supportInvalidateOptionsMenu();
                 break;
             case R.id.ml_menu_equalizer:
                 showSecondaryFragment("equalizer");
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 8d1e5c7..31d9080 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -492,6 +492,11 @@ public class VideoGridFragment extends BrowserFragment implements ISortable, IVi
         mVideoAdapter.sortBy(sortby);
     }
 
+    @Override
+    public int sortDirection(int sortby) {
+        return mVideoAdapter.sortDirection(sortby);
+    }
+
     public void setItemToUpdate(MediaWrapper item) {
         mItemToUpdate = item;
         mHandler.sendEmptyMessage(VideoListHandler.UPDATE_ITEM);
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index c10911a..9a1548e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -89,6 +89,13 @@ public class VideoListAdapter extends ArrayAdapter<MediaWrapper>
             notifyDataSetChanged();
     }
 
+    public int sortDirection(int sortby) {
+        if (sortby == mSortBy)
+            return  mSortDirection;
+        else
+            return -1;
+    }
+
     public void sortBy(int sortby) {
         switch (sortby) {
             case SORT_BY_TITLE:
diff --git a/vlc-android/src/org/videolan/vlc/interfaces/ISortable.java b/vlc-android/src/org/videolan/vlc/interfaces/ISortable.java
index 9f29e92..0103572 100644
--- a/vlc-android/src/org/videolan/vlc/interfaces/ISortable.java
+++ b/vlc-android/src/org/videolan/vlc/interfaces/ISortable.java
@@ -22,4 +22,5 @@ package org.videolan.vlc.interfaces;
 
 public interface ISortable {
     public void sortBy(int sortby);
+    public int sortDirection(int sortby);
 }



More information about the Android mailing list