Эх сурвалжийг харах

Merge pull request #6192 from nextcloud/trashbinSort

change trashbin view to new layout
Tobias Kaminsky 5 жил өмнө
parent
commit
4b9319a38c

+ 2 - 29
src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -1284,7 +1284,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
             switchToListView();
             switchToListView();
         }
         }
 
 
-        setSortButton(preferences.getSortOrderByFolder(mFile));
+        mSortButton.setText(DisplayUtils.getSortOrderStringId(preferences.getSortOrderByFolder(mFile)));
         setGridSwitchButton();
         setGridSwitchButton();
 
 
         if (mHideFab) {
         if (mHideFab) {
@@ -1306,38 +1306,11 @@ public class OCFileListFragment extends ExtendedListFragment implements
         }
         }
     }
     }
 
 
-
     public void sortFiles(FileSortOrder sortOrder) {
     public void sortFiles(FileSortOrder sortOrder) {
-        setSortButton(sortOrder);
+        mSortButton.setText(DisplayUtils.getSortOrderStringId(sortOrder));
         mAdapter.setSortOrder(mFile, sortOrder);
         mAdapter.setSortOrder(mFile, sortOrder);
     }
     }
 
 
-    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.menu_item_sort_by_date_oldest_first;
-                break;
-            case sort_big_to_small_id:
-                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.menu_item_sort_by_name_a_z;
-                break;
-        }
-        mSortButton.setText(getString(nameId));
-    }
-
     private void setGridSwitchButton() {
     private void setGridSwitchButton() {
         if (isGridEnabled()) {
         if (isGridEnabled()) {
             mSwitchGridViewButton.setContentDescription(getString(R.string.action_switch_list_view));
             mSwitchGridViewButton.setContentDescription(getString(R.string.action_switch_list_view));

+ 14 - 8
src/main/java/com/owncloud/android/ui/trashbin/TrashbinActivity.java

@@ -32,6 +32,7 @@ import android.widget.ImageView;
 import android.widget.PopupMenu;
 import android.widget.PopupMenu;
 import android.widget.TextView;
 import android.widget.TextView;
 
 
+import com.google.android.material.button.MaterialButton;
 import com.google.android.material.snackbar.Snackbar;
 import com.google.android.material.snackbar.Snackbar;
 import com.nextcloud.client.account.CurrentAccountProvider;
 import com.nextcloud.client.account.CurrentAccountProvider;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.User;
@@ -46,6 +47,7 @@ import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.adapter.TrashbinListAdapter;
 import com.owncloud.android.ui.adapter.TrashbinListAdapter;
 import com.owncloud.android.ui.dialog.SortingOrderDialogFragment;
 import com.owncloud.android.ui.dialog.SortingOrderDialogFragment;
 import com.owncloud.android.ui.interfaces.TrashbinActivityInterface;
 import com.owncloud.android.ui.interfaces.TrashbinActivityInterface;
+import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.FileSortOrder;
 import com.owncloud.android.utils.FileSortOrder;
 import com.owncloud.android.utils.ThemeUtils;
 import com.owncloud.android.utils.ThemeUtils;
 
 
@@ -53,8 +55,6 @@ import java.util.List;
 
 
 import javax.inject.Inject;
 import javax.inject.Inject;
 
 
-import androidx.fragment.app.FragmentManager;
-import androidx.fragment.app.FragmentTransaction;
 import androidx.recyclerview.widget.LinearLayoutManager;
 import androidx.recyclerview.widget.LinearLayoutManager;
 import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
 import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
 import butterknife.BindString;
 import butterknife.BindString;
@@ -88,6 +88,9 @@ public class TrashbinActivity extends FileActivity implements
     @BindView(R.id.swipe_containing_list)
     @BindView(R.id.swipe_containing_list)
     public SwipeRefreshLayout swipeListRefreshLayout;
     public SwipeRefreshLayout swipeListRefreshLayout;
 
 
+    @BindView(R.id.sort_button)
+    public MaterialButton sortButton;
+
     @BindString(R.string.trashbin_empty_headline)
     @BindString(R.string.trashbin_empty_headline)
     public String noResultsHeadline;
     public String noResultsHeadline;
 
 
@@ -148,6 +151,13 @@ public class TrashbinActivity extends FileActivity implements
         ThemeUtils.colorSwipeRefreshLayout(this, swipeListRefreshLayout);
         ThemeUtils.colorSwipeRefreshLayout(this, swipeListRefreshLayout);
         swipeListRefreshLayout.setOnRefreshListener(this::loadFolder);
         swipeListRefreshLayout.setOnRefreshListener(this::loadFolder);
 
 
+        sortButton.setOnClickListener(l ->
+                                          openSortingOrderDialogFragment(getSupportFragmentManager(),
+                                                                         preferences.getSortOrderByType(
+                                                                             FileSortOrder.Type.trashBinView,
+                                                                             FileSortOrder.sort_new_to_old))
+                                     );
+
         loadFolder();
         loadFolder();
     }
     }
 
 
@@ -177,12 +187,7 @@ public class TrashbinActivity extends FileActivity implements
                     openDrawer();
                     openDrawer();
                 }
                 }
                 break;
                 break;
-            case R.id.action_sort: {
-                openSortingOrderDialogFragment(getSupportFragmentManager(),
-                                               preferences.getSortOrderByType(FileSortOrder.Type.trashBinView,
-                                                                              FileSortOrder.sort_new_to_old));
-                break;
-            }
+
             case R.id.action_empty_trashbin:
             case R.id.action_empty_trashbin:
                 trashbinPresenter.emptyTrashbin();
                 trashbinPresenter.emptyTrashbin();
                 break;
                 break;
@@ -259,6 +264,7 @@ public class TrashbinActivity extends FileActivity implements
 
 
     @Override
     @Override
     public void onSortingOrderChosen(FileSortOrder sortOrder) {
     public void onSortingOrderChosen(FileSortOrder sortOrder) {
+        sortButton.setText(DisplayUtils.getSortOrderStringId(sortOrder));
         trashbinListAdapter.setSortOrder(sortOrder);
         trashbinListAdapter.setSortOrder(sortOrder);
     }
     }
 
 

+ 24 - 0
src/main/java/com/owncloud/android/utils/DisplayUtils.java

@@ -102,6 +102,12 @@ import androidx.fragment.app.FragmentManager;
 import androidx.fragment.app.FragmentTransaction;
 import androidx.fragment.app.FragmentTransaction;
 
 
 import static com.owncloud.android.ui.dialog.SortingOrderDialogFragment.SORTING_ORDER_FRAGMENT;
 import static com.owncloud.android.ui.dialog.SortingOrderDialogFragment.SORTING_ORDER_FRAGMENT;
+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 helper class for UI/display related operations.
  * A helper class for UI/display related operations.
@@ -749,4 +755,22 @@ public final class DisplayUtils {
 
 
         SortingOrderDialogFragment.newInstance(sortOrder).show(fragmentTransaction, SORTING_ORDER_FRAGMENT);
         SortingOrderDialogFragment.newInstance(sortOrder).show(fragmentTransaction, SORTING_ORDER_FRAGMENT);
     }
     }
+
+    public static @StringRes int getSortOrderStringId(FileSortOrder sortOrder) {
+        switch (sortOrder.name) {
+            case sort_z_to_a_id:
+                return R.string.menu_item_sort_by_name_z_a;
+            case sort_new_to_old_id:
+                return R.string.menu_item_sort_by_date_newest_first;
+            case sort_old_to_new_id:
+                return R.string.menu_item_sort_by_date_oldest_first;
+            case sort_big_to_small_id:
+                return R.string.menu_item_sort_by_size_biggest_first;
+            case sort_small_to_big_id:
+                return R.string.menu_item_sort_by_size_smallest_first;
+            case sort_a_to_z_id:
+            default:
+                return R.string.menu_item_sort_by_name_a_z;
+        }
+    }
 }
 }

+ 41 - 6
src/main/res/layout/trashbin_activity.xml

@@ -20,6 +20,7 @@
   along with this program. If not, see <https://www.gnu.org/licenses/>.
   along with this program. If not, see <https://www.gnu.org/licenses/>.
 -->
 -->
 <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
 <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/drawer_layout"
     android:id="@+id/drawer_layout"
     android:layout_width="match_parent"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_height="match_parent"
@@ -30,33 +31,67 @@
     <!-- The main content view -->
     <!-- The main content view -->
     <RelativeLayout
     <RelativeLayout
         android:layout_width="match_parent"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:orientation="vertical">
+        android:layout_height="match_parent">
 
 
         <include layout="@layout/toolbar_standard" />
         <include layout="@layout/toolbar_standard" />
 
 
-        <FrameLayout
+        <androidx.coordinatorlayout.widget.CoordinatorLayout
+            android:id="@+id/list_fragment_layout"
             android:layout_width="match_parent"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:layout_height="match_parent"
             android:layout_below="@id/appbar">
             android:layout_below="@id/appbar">
 
 
+            <com.google.android.material.appbar.AppBarLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:background="@color/bg_default"
+                app:elevation="0dp">
+
+                <androidx.constraintlayout.widget.ConstraintLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    app:layout_scrollFlags="scroll|enterAlways|snap">
+
+                    <com.google.android.material.button.MaterialButton
+                        android:id="@+id/sort_button"
+                        style="@style/Widget.MaterialComponents.Button.TextButton"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:layout_marginStart="8dp"
+                        android:contentDescription="@string/actionbar_sort"
+                        android:minWidth="0dp"
+                        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_keyboard_arrow_down"
+                        app:iconGravity="textEnd"
+                        app:iconSize="16dp"
+                        app:iconTint="@color/fontAppbar"
+                        app:layout_constraintBottom_toBottomOf="parent"
+                        app:layout_constraintStart_toStartOf="parent"
+                        app:layout_constraintTop_toTopOf="parent" />
+                </androidx.constraintlayout.widget.ConstraintLayout>
+            </com.google.android.material.appbar.AppBarLayout>
+
             <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
             <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
                 android:id="@+id/swipe_containing_list"
                 android:id="@+id/swipe_containing_list"
                 android:layout_width="match_parent"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:layout_height="match_parent"
                 android:footerDividersEnabled="false"
                 android:footerDividersEnabled="false"
-                android:visibility="visible">
+                android:visibility="visible"
+                app:layout_behavior="@string/appbar_scrolling_view_behavior">
 
 
                 <com.owncloud.android.ui.EmptyRecyclerView
                 <com.owncloud.android.ui.EmptyRecyclerView
                     android:id="@android:id/list"
                     android:id="@android:id/list"
                     android:layout_width="match_parent"
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"/>
                     android:layout_height="match_parent"/>
-
             </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
             </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
 
 
             <include layout="@layout/empty_list"/>
             <include layout="@layout/empty_list"/>
 
 
-        </FrameLayout>
+        </androidx.coordinatorlayout.widget.CoordinatorLayout>
 
 
     </RelativeLayout>
     </RelativeLayout>
 
 

+ 3 - 11
src/main/res/menu/activity_trashbin.xml

@@ -5,17 +5,17 @@
   @author Tobias Kaminsky
   @author Tobias Kaminsky
   Copyright (C) 2018 Tobias Kaminsky
   Copyright (C) 2018 Tobias Kaminsky
   Copyright (C) 2018 Nextcloud GmbH.
   Copyright (C) 2018 Nextcloud GmbH.
- 
+
   This program is free software: you can redistribute it and/or modify
   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
   (at your option) any later version.
- 
+
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   GNU General Public License for more details.
   GNU General Public License for more details.
- 
+
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program. If not, see <https://www.gnu.org/licenses/>.
   along with this program. If not, see <https://www.gnu.org/licenses/>.
 -->
 -->
@@ -24,14 +24,6 @@
       xmlns:tools="http://schemas.android.com/tools"
       xmlns:tools="http://schemas.android.com/tools"
       tools:ignore="AppCompatResource">
       tools:ignore="AppCompatResource">
 
 
-    <item
-        android:id="@+id/action_sort"
-        android:contentDescription="@string/actionbar_sort"
-        android:icon="@drawable/ic_sort_variant"
-        android:orderInCategory="1"
-        android:title="@string/actionbar_sort"
-        app:showAsAction="never"/>
-
     <item
     <item
         android:id="@+id/action_empty_trashbin"
         android:id="@+id/action_empty_trashbin"
         android:contentDescription="@string/action_empty_trashbin"
         android:contentDescription="@string/action_empty_trashbin"