[Android] Simplify browsers sorting activation
Geoffrey Métais
git at videolan.org
Wed Jul 12 14:27:15 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jul 12 14:26:37 2017 +0200| [4c853f71138ea57790c7f044a7892b52a29c51bd] | committer: Geoffrey Métais
Simplify browsers sorting activation
> https://code.videolan.org/videolan/vlc-android/commit/4c853f71138ea57790c7f044a7892b52a29c51bd
---
vlc-android/src/org/videolan/vlc/gui/MainActivity.java | 15 +++++----------
.../org/videolan/vlc/gui/browser/BaseBrowserAdapter.java | 15 ++++-----------
.../org/videolan/vlc/gui/browser/BaseBrowserFragment.java | 13 +++++++------
.../org/videolan/vlc/gui/browser/FileBrowserFragment.java | 4 ++++
.../org/videolan/vlc/gui/browser/FilePickerFragment.java | 4 +++-
.../videolan/vlc/gui/browser/NetworkBrowserFragment.java | 4 ++++
.../videolan/vlc/gui/browser/StorageBrowserFragment.java | 4 ++++
7 files changed, 31 insertions(+), 28 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 676f757e4..8faf123d6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -497,22 +497,17 @@ public class MainActivity extends AudioPlayerContainerActivity implements Filter
if (menu == null)
return false;
Fragment current = getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder);
- MenuItem item;
+ 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)
- || (current instanceof BaseBrowserFragment && ((BaseBrowserFragment) current).isRootDirectory())
- || (current instanceof StorageBrowserFragment) ){
- item = menu.findItem(R.id.ml_menu_sortby);
- if (item == null)
- return false;
+ if (current == null || !(current instanceof ISortable)
+ || (current instanceof BaseBrowserFragment && !((BaseBrowserFragment)current).isSortEnabled())) {
item.setEnabled(false);
item.setVisible(false);
} else {
ISortable sortable = (ISortable) current;
item = menu.findItem(R.id.ml_menu_sortby);
- if (item == null)
- return false;
item.setEnabled(true);
item.setVisible(true);
item = menu.findItem(R.id.ml_menu_sortby_name);
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
index bacafb698..d01f997df 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -241,15 +241,11 @@ public class BaseBrowserAdapter extends BaseQueuedAdapter<ArrayList<MediaLibrary
return hasPendingUpdates() ? super.peekLast() : mMediaList;
}
- public void addItem(MediaLibraryItem item, boolean top){
+ public void addItem(MediaLibraryItem item, boolean top) {
addItem(item, top, -1);
}
- void addItem(MediaLibraryItem item, int position){
- addItem(item, false, position);
- }
-
- void addItem(MediaLibraryItem item, boolean top, int positionTo){
+ void addItem(MediaLibraryItem item, boolean top, int positionTo) {
int position;
ArrayList<MediaLibraryItem> list = new ArrayList<>(peekLast());
if (positionTo != -1)
@@ -270,7 +266,7 @@ public class BaseBrowserAdapter extends BaseQueuedAdapter<ArrayList<MediaLibrary
mTop = top;
}
- public void addAll(ArrayList<? extends MediaLibraryItem> mediaList){
+ public void addAll(ArrayList<? extends MediaLibraryItem> mediaList) {
update((ArrayList<MediaLibraryItem>) mediaList);
}
@@ -376,10 +372,7 @@ public class BaseBrowserAdapter extends BaseQueuedAdapter<ArrayList<MediaLibrary
VLCApplication.runBackground(new Runnable() {
@Override
public void run() {
- if ((detectMoves || (!items.isEmpty() && sMediaComparator.sortBy != SORT_DEFAULT))
- && !fragment.isRootDirectory()
- && !(fragment instanceof StorageBrowserFragment)
- && !(fragment instanceof FilePickerFragment))
+ if (detectMoves || (fragment.isSortEnabled() && sMediaComparator.sortBy != SORT_DEFAULT))
Collections.sort(items, sMediaComparator);
final DiffUtil.DiffResult result = DiffUtil.calculateDiff(new MediaItemDiffCallback(mMediaList, items), detectMoves);
for (MediaLibraryItem item : items) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index 07849e12d..f9394c9b4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -117,6 +117,9 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
protected abstract Fragment createFragment();
protected abstract void browseRoot();
protected abstract String getCategoryTitle();
+ public boolean isSortEnabled() {
+ return false;
+ }
private Handler mBrowserHandler;
@@ -181,7 +184,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
- if (mediaList != null && !mediaList.isEmpty())
+ if (!Util.isListEmpty(mediaList))
mAdapter.addAll(mediaList);
else if (!(this instanceof NetworkBrowserFragment))
refresh();
@@ -377,13 +380,11 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
@Override
public void refresh() {
- if ((this instanceof NetworkBrowserFragment && mRoot) || this instanceof FilePickerFragment
- || this instanceof StorageBrowserFragment)
- mAdapter.clear();
- else {
+ if (isSortEnabled()) {
refreshList = new ArrayList<>();
refreshing = true;
- }
+ } else
+ mAdapter.clear();
mBrowserHandler.removeCallbacksAndMessages(null);
mHandler.sendEmptyMessageDelayed(BrowserFragmentHandler.MSG_SHOW_LOADING, 300);
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
index e8d072391..938a7bd8d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
@@ -59,6 +59,10 @@ public class FileBrowserFragment<T extends BaseBrowserAdapter> extends BaseBrows
ROOT = AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY;
}
+ public boolean isSortEnabled() {
+ return !mRoot;
+ }
+
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/FilePickerFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/FilePickerFragment.java
index 015d899f7..0293234d1 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/FilePickerFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/FilePickerFragment.java
@@ -50,7 +50,9 @@ public class FilePickerFragment extends FileBrowserFragment {
return new FilePickerFragment();
}
- public FilePickerFragment(){}
+ public boolean isSortEnabled() {
+ return false;
+ }
@Override
public void onCreate(Bundle bundle) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
index 38a5d7848..781d0b43b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
@@ -57,6 +57,10 @@ public class NetworkBrowserFragment extends BaseBrowserFragment {
mAdapter = new BaseBrowserAdapter(this);
}
+ public boolean isSortEnabled() {
+ return !mRoot;
+ }
+
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java
index 13652c9ab..6f025644c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java
@@ -62,6 +62,10 @@ public class StorageBrowserFragment extends FileBrowserFragment implements Entry
ROOT = AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY;
}
+ public boolean isSortEnabled() {
+ return false;
+ }
+
@Override
protected Fragment createFragment() {
return new StorageBrowserFragment();
More information about the Android
mailing list