From 3bc3a86354811e1e35922644c995f6f4367ecbdb Mon Sep 17 00:00:00 2001 From: Joris Bodin Date: Tue, 5 May 2020 15:50:37 +0200 Subject: [PATCH] Improve sort button and hide if necessary Signed-off-by: Joris Bodin --- .../ui/fragment/OCFileListFragment.java | 33 ++++++++++++------- src/main/res/drawable/ic_arrow_down.xml | 9 ----- .../res/drawable/ic_keyboard_arrow_down.xml | 9 +++++ src/main/res/layout/list_fragment.xml | 4 +-- src/main/res/values-fr/strings.xml | 3 -- src/main/res/values/strings.xml | 3 -- 6 files changed, 33 insertions(+), 28 deletions(-) delete mode 100644 src/main/res/drawable/ic_arrow_down.xml create mode 100644 src/main/res/drawable/ic_keyboard_arrow_down.xml diff --git a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index 98ee8c5b9a..d662aa4f43 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -131,10 +131,12 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import static com.owncloud.android.datamodel.OCFile.ROOT_PATH; import static com.owncloud.android.utils.DisplayUtils.openSortingOrderDialogFragment; +import static com.owncloud.android.utils.FileSortOrder.sort_a_to_z_id; import static com.owncloud.android.utils.FileSortOrder.sort_big_to_small_id; import static com.owncloud.android.utils.FileSortOrder.sort_new_to_old_id; import static com.owncloud.android.utils.FileSortOrder.sort_old_to_new_id; import static com.owncloud.android.utils.FileSortOrder.sort_small_to_big_id; +import static com.owncloud.android.utils.FileSortOrder.sort_z_to_a_id; /** * A Fragment that lists all files and folders in a given path. @@ -779,6 +781,7 @@ public class OCFileListFragment extends ExtendedListFragment implements menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(), menuItemOrig.getTitle()); } + mSortButton.setVisibility(View.VISIBLE); } else if (menuItemAddRemoveValue == MenuItemAddRemove.ADD_GRID_AND_SORT) { if (menu.findItem(R.id.action_switch_view) == null) { @@ -786,12 +789,14 @@ public class OCFileListFragment extends ExtendedListFragment implements menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(), menuItemOrig.getTitle()); } + mSwitchGridViewButton.setVisibility(View.VISIBLE); if (menu.findItem(R.id.action_sort) == null) { menuItemOrig = mOriginalMenuItems.get(1); menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(), menuItemOrig.getTitle()); } + mSortButton.setVisibility(View.VISIBLE); } else if (menuItemAddRemoveValue == MenuItemAddRemove.REMOVE_SEARCH) { menu.removeItem(R.id.action_search); } else if (menuItemAddRemoveValue == MenuItemAddRemove.ADD_GRID_AND_SORT_WITH_SEARCH) { @@ -800,12 +805,14 @@ public class OCFileListFragment extends ExtendedListFragment implements menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(), menuItemOrig.getTitle()); } + mSwitchGridViewButton.setVisibility(View.VISIBLE); if (menu.findItem(R.id.action_sort) == null) { menuItemOrig = mOriginalMenuItems.get(1); menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(), menuItemOrig.getTitle()); } + mSortButton.setVisibility(View.VISIBLE); if (menu.findItem(R.id.action_search) == null) { menuItemOrig = mOriginalMenuItems.get(2); @@ -815,10 +822,13 @@ public class OCFileListFragment extends ExtendedListFragment implements } else if (menuItemAddRemoveValue == MenuItemAddRemove.REMOVE_SORT) { menu.removeItem(R.id.action_sort); menu.removeItem(R.id.action_search); + mSortButton.setVisibility(View.GONE); } else if (menuItemAddRemoveValue == MenuItemAddRemove.REMOVE_GRID_AND_SORT) { menu.removeItem(R.id.action_sort); menu.removeItem(R.id.action_switch_view); menu.removeItem(R.id.action_search); + mSortButton.setVisibility(View.GONE); + mSwitchGridViewButton.setVisibility(View.GONE); } } @@ -1317,26 +1327,27 @@ public class OCFileListFragment extends ExtendedListFragment implements private void setSortButton(FileSortOrder sortOrder) { int nameId; switch (sortOrder.name) { + case sort_z_to_a_id: + nameId = R.string.menu_item_sort_by_name_z_a; + break; case sort_new_to_old_id: + nameId = R.string.menu_item_sort_by_date_newest_first; + break; case sort_old_to_new_id: - nameId = R.string.sort_by_date; + nameId = R.string.menu_item_sort_by_date_oldest_first; break; case sort_big_to_small_id: - case sort_small_to_big_id: - nameId = R.string.sort_by_size; + nameId = R.string.menu_item_sort_by_size_biggest_first; break; + case sort_small_to_big_id: + nameId = R.string.menu_item_sort_by_size_smallest_first; + break; + case sort_a_to_z_id: default: - nameId = R.string.sort_by_name; + nameId = R.string.menu_item_sort_by_name_a_z; break; } mSortButton.setText(getString(nameId)); - Drawable icon; - if (sortOrder.isAscending) { - icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_arrow_down); - } else { - icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_arrow_up); - } - mSortButton.setIcon(icon); } private void setGridSwitchButton() { diff --git a/src/main/res/drawable/ic_arrow_down.xml b/src/main/res/drawable/ic_arrow_down.xml deleted file mode 100644 index 69f72ab5f3..0000000000 --- a/src/main/res/drawable/ic_arrow_down.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/src/main/res/drawable/ic_keyboard_arrow_down.xml b/src/main/res/drawable/ic_keyboard_arrow_down.xml new file mode 100644 index 0000000000..ad33063c80 --- /dev/null +++ b/src/main/res/drawable/ic_keyboard_arrow_down.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/main/res/layout/list_fragment.xml b/src/main/res/layout/list_fragment.xml index 91f47e0b06..6a36796da4 100644 --- a/src/main/res/layout/list_fragment.xml +++ b/src/main/res/layout/list_fragment.xml @@ -45,12 +45,12 @@ android:layout_marginStart="8dp" android:contentDescription="@string/actionbar_sort" android:minWidth="0dp" - android:text="@string/sort_by_name" + android:text="@string/menu_item_sort_by_date_newest_first" android:textAlignment="textStart" android:textAllCaps="false" android:textColor="@color/fontAppbar" android:textSize="14sp" - app:icon="@drawable/ic_arrow_up" + app:icon="@drawable/ic_keyboard_arrow_down" app:iconGravity="textEnd" app:iconSize="16dp" app:iconTint="@color/fontAppbar" diff --git a/src/main/res/values-fr/strings.xml b/src/main/res/values-fr/strings.xml index a9f6d6aeb6..0d7abab09e 100644 --- a/src/main/res/values-fr/strings.xml +++ b/src/main/res/values-fr/strings.xml @@ -633,9 +633,6 @@ Attention la suppression est irréversible. Se connecter avec un fournisseur Autoriser %1$s à accéder à votre compte Nextcloud %2$s ? Trier par - Date - Nom - Taille Le plus récent en premier Le plus ancien en premier A - Z diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 12781fc870..ae13f83977 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -11,9 +11,6 @@ Send Sort Sort by - Date - Name - Size A - Z Z - A Newest first