Improve sort button and hide if necessary

Signed-off-by: Joris Bodin <joris.bodin@infomaniak.com>
This commit is contained in:
Joris Bodin 2020-05-05 15:50:37 +02:00
parent 29f60460bb
commit 3bc3a86354
No known key found for this signature in database
GPG key ID: 3144433DBB0C5A21
6 changed files with 33 additions and 28 deletions

View file

@ -131,10 +131,12 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH; import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
import static com.owncloud.android.utils.DisplayUtils.openSortingOrderDialogFragment; 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_big_to_small_id;
import static com.owncloud.android.utils.FileSortOrder.sort_new_to_old_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_old_to_new_id;
import static com.owncloud.android.utils.FileSortOrder.sort_small_to_big_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. * 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(), menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(),
menuItemOrig.getTitle()); menuItemOrig.getTitle());
} }
mSortButton.setVisibility(View.VISIBLE);
} else if (menuItemAddRemoveValue == MenuItemAddRemove.ADD_GRID_AND_SORT) { } else if (menuItemAddRemoveValue == MenuItemAddRemove.ADD_GRID_AND_SORT) {
if (menu.findItem(R.id.action_switch_view) == null) { 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(), menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(),
menuItemOrig.getTitle()); menuItemOrig.getTitle());
} }
mSwitchGridViewButton.setVisibility(View.VISIBLE);
if (menu.findItem(R.id.action_sort) == null) { if (menu.findItem(R.id.action_sort) == null) {
menuItemOrig = mOriginalMenuItems.get(1); menuItemOrig = mOriginalMenuItems.get(1);
menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(), menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(),
menuItemOrig.getTitle()); menuItemOrig.getTitle());
} }
mSortButton.setVisibility(View.VISIBLE);
} else if (menuItemAddRemoveValue == MenuItemAddRemove.REMOVE_SEARCH) { } else if (menuItemAddRemoveValue == MenuItemAddRemove.REMOVE_SEARCH) {
menu.removeItem(R.id.action_search); menu.removeItem(R.id.action_search);
} else if (menuItemAddRemoveValue == MenuItemAddRemove.ADD_GRID_AND_SORT_WITH_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(), menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(),
menuItemOrig.getTitle()); menuItemOrig.getTitle());
} }
mSwitchGridViewButton.setVisibility(View.VISIBLE);
if (menu.findItem(R.id.action_sort) == null) { if (menu.findItem(R.id.action_sort) == null) {
menuItemOrig = mOriginalMenuItems.get(1); menuItemOrig = mOriginalMenuItems.get(1);
menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(), menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(),
menuItemOrig.getTitle()); menuItemOrig.getTitle());
} }
mSortButton.setVisibility(View.VISIBLE);
if (menu.findItem(R.id.action_search) == null) { if (menu.findItem(R.id.action_search) == null) {
menuItemOrig = mOriginalMenuItems.get(2); menuItemOrig = mOriginalMenuItems.get(2);
@ -815,10 +822,13 @@ public class OCFileListFragment extends ExtendedListFragment implements
} else if (menuItemAddRemoveValue == MenuItemAddRemove.REMOVE_SORT) { } else if (menuItemAddRemoveValue == MenuItemAddRemove.REMOVE_SORT) {
menu.removeItem(R.id.action_sort); menu.removeItem(R.id.action_sort);
menu.removeItem(R.id.action_search); menu.removeItem(R.id.action_search);
mSortButton.setVisibility(View.GONE);
} else if (menuItemAddRemoveValue == MenuItemAddRemove.REMOVE_GRID_AND_SORT) { } else if (menuItemAddRemoveValue == MenuItemAddRemove.REMOVE_GRID_AND_SORT) {
menu.removeItem(R.id.action_sort); menu.removeItem(R.id.action_sort);
menu.removeItem(R.id.action_switch_view); menu.removeItem(R.id.action_switch_view);
menu.removeItem(R.id.action_search); 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) { private void setSortButton(FileSortOrder sortOrder) {
int nameId; int nameId;
switch (sortOrder.name) { 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: case sort_new_to_old_id:
nameId = R.string.menu_item_sort_by_date_newest_first;
break;
case sort_old_to_new_id: case sort_old_to_new_id:
nameId = R.string.sort_by_date; nameId = R.string.menu_item_sort_by_date_oldest_first;
break; break;
case sort_big_to_small_id: case sort_big_to_small_id:
case sort_small_to_big_id: nameId = R.string.menu_item_sort_by_size_biggest_first;
nameId = R.string.sort_by_size;
break; 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: default:
nameId = R.string.sort_by_name; nameId = R.string.menu_item_sort_by_name_a_z;
break; break;
} }
mSortButton.setText(getString(nameId)); 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() { private void setGridSwitchButton() {

View file

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFF"
android:pathData="M20,12l-1.41,-1.41L13,16.17V4h-2v12.17l-5.58,-5.59L4,12l8,8 8,-8z" />
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M7.41,7.84L12,12.42l4.59,-4.58L18,9.25l-6,6 -6,-6z"/>
</vector>

View file

@ -45,12 +45,12 @@
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:contentDescription="@string/actionbar_sort" android:contentDescription="@string/actionbar_sort"
android:minWidth="0dp" android:minWidth="0dp"
android:text="@string/sort_by_name" android:text="@string/menu_item_sort_by_date_newest_first"
android:textAlignment="textStart" android:textAlignment="textStart"
android:textAllCaps="false" android:textAllCaps="false"
android:textColor="@color/fontAppbar" android:textColor="@color/fontAppbar"
android:textSize="14sp" android:textSize="14sp"
app:icon="@drawable/ic_arrow_up" app:icon="@drawable/ic_keyboard_arrow_down"
app:iconGravity="textEnd" app:iconGravity="textEnd"
app:iconSize="16dp" app:iconSize="16dp"
app:iconTint="@color/fontAppbar" app:iconTint="@color/fontAppbar"

View file

@ -633,9 +633,6 @@ Attention la suppression est irréversible.</string>
<string name="signup_with_provider">Se connecter avec un fournisseur</string> <string name="signup_with_provider">Se connecter avec un fournisseur</string>
<string name="single_sign_on_request_token" formatted="true">Autoriser %1$s à accéder à votre compte Nextcloud %2$s ?</string> <string name="single_sign_on_request_token" formatted="true">Autoriser %1$s à accéder à votre compte Nextcloud %2$s ?</string>
<string name="sort_by">Trier par</string> <string name="sort_by">Trier par</string>
<string name="sort_by_date">Date</string>
<string name="sort_by_name">Nom</string>
<string name="sort_by_size">Taille</string>
<string name="sort_by_modification_date_ascending">Le plus récent en premier</string> <string name="sort_by_modification_date_ascending">Le plus récent en premier</string>
<string name="sort_by_modification_date_descending">Le plus ancien en premier</string> <string name="sort_by_modification_date_descending">Le plus ancien en premier</string>
<string name="sort_by_name_ascending">A - Z</string> <string name="sort_by_name_ascending">A - Z</string>

View file

@ -11,9 +11,6 @@
<string name="actionbar_send_file">Send</string> <string name="actionbar_send_file">Send</string>
<string name="actionbar_sort">Sort</string> <string name="actionbar_sort">Sort</string>
<string name="sort_by">Sort by</string> <string name="sort_by">Sort by</string>
<string name="sort_by_date">Date</string>
<string name="sort_by_name">Name</string>
<string name="sort_by_size">Size</string>
<string name="menu_item_sort_by_name_a_z">A - Z</string> <string name="menu_item_sort_by_name_a_z">A - Z</string>
<string name="menu_item_sort_by_name_z_a">Z - A</string> <string name="menu_item_sort_by_name_z_a">Z - A</string>
<string name="menu_item_sort_by_date_newest_first">Newest first</string> <string name="menu_item_sort_by_date_newest_first">Newest first</string>