Browse Source

Add order capabilities to file browser

Resolves #919

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger 3 years ago
parent
commit
85b2cea618
30 changed files with 2154 additions and 315 deletions
  1. 0 305
      app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserController.java
  2. 339 0
      app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserController.kt
  3. 1 1
      app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserForAvatarController.java
  4. 1 1
      app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserForSharingController.java
  5. 198 0
      app/src/main/java/com/nextcloud/talk/ui/dialog/SortingOrderDialogFragment.java
  6. 28 0
      app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java
  7. 108 0
      app/src/main/java/com/nextcloud/talk/utils/FileSortOrder.java
  8. 52 0
      app/src/main/java/com/nextcloud/talk/utils/FileSortOrderByDate.java
  9. 63 0
      app/src/main/java/com/nextcloud/talk/utils/FileSortOrderByName.java
  10. 64 0
      app/src/main/java/com/nextcloud/talk/utils/FileSortOrderBySize.java
  11. 18 0
      app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java
  12. 188 0
      app/src/main/java/third_parties/daveKoeller/AlphanumComparator.java
  13. 502 0
      app/src/main/java/third_parties/daveKoeller/lgpl-2.1.txt
  14. 29 0
      app/src/main/res/drawable/borderless_btn.xml
  15. 25 0
      app/src/main/res/drawable/ic_alphabetical_asc.xml
  16. 26 0
      app/src/main/res/drawable/ic_alphabetical_desc.xml
  17. 25 0
      app/src/main/res/drawable/ic_keyboard_arrow_down.xml
  18. 25 0
      app/src/main/res/drawable/ic_modification_asc.xml
  19. 25 0
      app/src/main/res/drawable/ic_modification_desc.xml
  20. 25 0
      app/src/main/res/drawable/ic_size_asc.xml
  21. 25 0
      app/src/main/res/drawable/ic_size_desc.xml
  22. 54 6
      app/src/main/res/layout/controller_browser.xml
  23. 308 0
      app/src/main/res/layout/sorting_order_fragment.xml
  24. 1 0
      app/src/main/res/values-night/colors.xml
  25. 1 0
      app/src/main/res/values/colors.xml
  26. 1 0
      app/src/main/res/values/dimens.xml
  27. 9 0
      app/src/main/res/values/strings.xml
  28. 11 0
      app/src/main/res/values/styles.xml
  29. 1 1
      scripts/analysis/findbugs-results.txt
  30. 1 1
      scripts/analysis/lint-results.txt

+ 0 - 305
app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserController.java

@@ -1,305 +0,0 @@
-/*
- * Nextcloud Talk application
- *
- * @author Mario Danic
- * Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
- *
- * 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
- * the Free Software Foundation, either version 3 of the License, or
- * at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.nextcloud.talk.components.filebrowser.controllers;
-
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-
-import com.google.android.material.bottomnavigation.BottomNavigationItemView;
-import com.nextcloud.talk.R;
-import com.nextcloud.talk.application.NextcloudTalkApplication;
-import com.nextcloud.talk.components.filebrowser.adapters.items.BrowserFileItem;
-import com.nextcloud.talk.components.filebrowser.interfaces.ListingInterface;
-import com.nextcloud.talk.components.filebrowser.models.BrowserFile;
-import com.nextcloud.talk.components.filebrowser.models.DavResponse;
-import com.nextcloud.talk.components.filebrowser.operations.DavListing;
-import com.nextcloud.talk.components.filebrowser.operations.ListingAbstractClass;
-import com.nextcloud.talk.controllers.base.BaseController;
-import com.nextcloud.talk.interfaces.SelectionInterface;
-import com.nextcloud.talk.models.database.UserEntity;
-import com.nextcloud.talk.utils.bundle.BundleKeys;
-import com.nextcloud.talk.utils.database.user.UserUtils;
-
-import org.parceler.Parcel;
-import org.parceler.Parcels;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-
-import javax.inject.Inject;
-
-import androidx.annotation.NonNull;
-import androidx.recyclerview.widget.RecyclerView;
-import autodagger.AutoInjector;
-import butterknife.BindView;
-import butterknife.OnClick;
-import eu.davidea.flexibleadapter.FlexibleAdapter;
-import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
-import eu.davidea.flexibleadapter.items.AbstractFlexibleItem;
-import okhttp3.OkHttpClient;
-
-@AutoInjector(NextcloudTalkApplication.class)
-public abstract class BrowserController extends BaseController implements ListingInterface,
-        FlexibleAdapter.OnItemClickListener, SelectionInterface {
-    protected final Set<String> selectedPaths;
-    @Inject
-    UserUtils userUtils;
-    @BindView(R.id.recycler_view)
-    RecyclerView recyclerView;
-    @BindView(R.id.action_back)
-    BottomNavigationItemView backMenuItem;
-    @BindView(R.id.action_refresh)
-    BottomNavigationItemView actionRefreshMenuItem;
-    @Inject
-    Context context;
-    @Inject
-    OkHttpClient okHttpClient;
-
-    private MenuItem filesSelectionDoneMenuItem;
-    private RecyclerView.LayoutManager layoutManager;
-
-    private FlexibleAdapter<AbstractFlexibleItem> adapter;
-    private List<AbstractFlexibleItem> recyclerViewItems = new ArrayList<>();
-
-    private ListingAbstractClass listingAbstractClass;
-    private BrowserType browserType;
-    private String currentPath;
-    protected UserEntity activeUser;
-
-    public BrowserController(Bundle args) {
-        super(args);
-        setHasOptionsMenu(true);
-        NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this);
-        browserType = Parcels.unwrap(args.getParcelable(BundleKeys.INSTANCE.getKEY_BROWSER_TYPE()));
-        activeUser = Parcels.unwrap(args.getParcelable(BundleKeys.INSTANCE.getKEY_USER_ENTITY()));
-
-        currentPath = "/";
-        if (BrowserType.DAV_BROWSER.equals(browserType)) {
-            listingAbstractClass = new DavListing(this);
-        } else {
-            //listingAbstractClass = new LocalListing(this);
-        }
-
-        selectedPaths = Collections.synchronizedSet(new TreeSet<>());
-    }
-
-    @NonNull
-    @Override
-    protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
-        return inflater.inflate(R.layout.controller_browser, container, false);
-    }
-
-    @Override
-    protected void onViewBound(@NonNull View view) {
-        super.onViewBound(view);
-        if (adapter == null) {
-            adapter = new FlexibleAdapter<>(recyclerViewItems, context, false);
-        }
-
-        changeEnabledStatusForBarItems(true);
-        prepareViews();
-    }
-
-    abstract void onFileSelectionDone();
-
-    @Override
-    public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
-        super.onCreateOptionsMenu(menu, inflater);
-        inflater.inflate(R.menu.menu_share_files, menu);
-        filesSelectionDoneMenuItem = menu.findItem(R.id.files_selection_done);
-        filesSelectionDoneMenuItem.setVisible(selectedPaths.size() > 0);
-    }
-
-    @Override
-    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
-        if (item.getItemId() == R.id.files_selection_done) {
-            onFileSelectionDone();
-            return true;
-        }
-        return super.onOptionsItemSelected(item);
-    }
-
-    @Override
-    protected void onAttach(@NonNull View view) {
-        super.onAttach(view);
-        refreshCurrentPath();
-    }
-
-    @Override
-    public void onDestroy() {
-        super.onDestroy();
-        listingAbstractClass.tearDown();
-    }
-
-    @Override
-    protected String getTitle() {
-        return currentPath;
-    }
-
-    @OnClick(R.id.action_back)
-    void goBack() {
-        fetchPath(new File(currentPath).getParent());
-    }
-
-    @OnClick(R.id.action_refresh)
-    void refreshCurrentPath() {
-        fetchPath(currentPath);
-    }
-
-    @SuppressLint("RestrictedApi")
-    private void changeEnabledStatusForBarItems(boolean shouldBeEnabled) {
-        if (actionRefreshMenuItem != null) {
-            actionRefreshMenuItem.setEnabled(shouldBeEnabled);
-        }
-
-        if (backMenuItem != null) {
-            backMenuItem.setEnabled(shouldBeEnabled && !currentPath.equals("/"));
-        }
-    }
-
-    private void fetchPath(String path) {
-        listingAbstractClass.cancelAllJobs();
-        changeEnabledStatusForBarItems(false);
-
-        listingAbstractClass.getFiles(path, activeUser, BrowserType.DAV_BROWSER.equals(browserType) ? okHttpClient : null);
-    }
-
-    @Override
-    public void listingResult(DavResponse davResponse) {
-        adapter.clear();
-        List<AbstractFlexibleItem> fileBrowserItems = new ArrayList<>();
-        if (davResponse.getData() != null) {
-            final List<BrowserFile> objectList = (List<BrowserFile>) davResponse.getData();
-
-            currentPath = objectList.get(0).getPath();
-
-            if (getActivity() != null) {
-                getActivity().runOnUiThread(() -> setTitle());
-            }
-
-            for (int i = 1; i < objectList.size(); i++) {
-                fileBrowserItems.add(new BrowserFileItem(objectList.get(i), activeUser, this));
-            }
-        }
-
-        adapter.addItems(0, fileBrowserItems);
-
-        if (getActivity() != null) {
-            getActivity().runOnUiThread(() -> {
-                adapter.notifyDataSetChanged();
-                changeEnabledStatusForBarItems(true);
-
-            });
-        }
-    }
-
-    private boolean shouldPathBeSelectedDueToParent(String currentPath) {
-        if (selectedPaths.size() > 0) {
-            File file = new File(currentPath);
-            if (!file.getParent().equals("/")) {
-                while (file.getParent() != null) {
-                    String parent = file.getParent();
-                    if (new File(file.getParent()).getParent() != null) {
-                        parent += "/";
-                    }
-
-                    if (selectedPaths.contains(parent)) {
-                        return true;
-                    }
-
-                    file = new File(file.getParent());
-                }
-            }
-        }
-
-        return false;
-    }
-
-    private void checkAndRemoveAnySelectedParents(String currentPath) {
-        File file = new File(currentPath);
-        selectedPaths.remove(currentPath);
-        while (file.getParent() != null) {
-            selectedPaths.remove(file.getParent() + "/");
-            file = new File(file.getParent());
-        }
-
-        adapter.notifyDataSetChanged();
-    }
-
-    @Override
-    public boolean onItemClick(View view, int position) {
-        BrowserFile browserFile = ((BrowserFileItem) adapter.getItem(position)).getModel();
-        if ("inode/directory".equals((browserFile.getMimeType()))) {
-            fetchPath(browserFile.getPath());
-            return true;
-        }
-
-        return false;
-    }
-
-    private void prepareViews() {
-        if (getActivity() != null) {
-            layoutManager = new SmoothScrollLinearLayoutManager(getActivity());
-            recyclerView.setLayoutManager(layoutManager);
-            recyclerView.setHasFixedSize(true);
-            recyclerView.setAdapter(adapter);
-            adapter.addListener(this);
-        }
-    }
-
-    @SuppressLint("RestrictedApi")
-    @Override
-    public void toggleBrowserItemSelection(@NonNull String path) {
-        if (selectedPaths.contains(path) || shouldPathBeSelectedDueToParent(path)) {
-            checkAndRemoveAnySelectedParents(path);
-        } else {
-            // TOOD: if it's a folder, remove all the children we added manually
-            selectedPaths.add(path);
-        }
-
-        filesSelectionDoneMenuItem.setVisible(selectedPaths.size() > 0);
-    }
-
-    @Override
-    public boolean isPathSelected(@NonNull String path) {
-        return (selectedPaths.contains(path) || shouldPathBeSelectedDueToParent(path));
-    }
-
-    @Override
-    abstract public boolean shouldOnlySelectOneImageFile();
-
-    @Parcel
-    public enum BrowserType {
-        FILE_BROWSER,
-        DAV_BROWSER,
-    }
-}

+ 339 - 0
app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserController.kt

@@ -0,0 +1,339 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Mario Danic
+ * @author Andy Scherzinger
+ * Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
+ * Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.nextcloud.talk.components.filebrowser.controllers
+
+import android.annotation.SuppressLint
+import android.os.Bundle
+import android.util.Log
+import android.view.Menu
+import android.view.MenuInflater
+import android.view.MenuItem
+import android.view.View
+import androidx.fragment.app.DialogFragment
+import androidx.recyclerview.widget.RecyclerView
+import autodagger.AutoInjector
+import com.nextcloud.talk.R
+import com.nextcloud.talk.activities.MainActivity
+import com.nextcloud.talk.application.NextcloudTalkApplication
+import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
+import com.nextcloud.talk.components.filebrowser.adapters.items.BrowserFileItem
+import com.nextcloud.talk.components.filebrowser.interfaces.ListingInterface
+import com.nextcloud.talk.components.filebrowser.models.BrowserFile
+import com.nextcloud.talk.components.filebrowser.models.DavResponse
+import com.nextcloud.talk.components.filebrowser.operations.DavListing
+import com.nextcloud.talk.components.filebrowser.operations.ListingAbstractClass
+import com.nextcloud.talk.controllers.base.NewBaseController
+import com.nextcloud.talk.controllers.util.viewBinding
+import com.nextcloud.talk.databinding.ControllerBrowserBinding
+import com.nextcloud.talk.interfaces.SelectionInterface
+import com.nextcloud.talk.models.database.UserEntity
+import com.nextcloud.talk.ui.dialog.SortingOrderDialogFragment
+import com.nextcloud.talk.utils.DisplayUtils
+import com.nextcloud.talk.utils.FileSortOrder
+import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_BROWSER_TYPE
+import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY
+import com.nextcloud.talk.utils.database.user.UserUtils
+import eu.davidea.flexibleadapter.FlexibleAdapter
+import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager
+import eu.davidea.flexibleadapter.items.IFlexible
+import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener
+import okhttp3.OkHttpClient
+import org.parceler.Parcel
+import org.parceler.Parcels
+import java.io.File
+import java.util.ArrayList
+import java.util.Collections
+import java.util.TreeSet
+import javax.inject.Inject
+
+@AutoInjector(NextcloudTalkApplication::class)
+abstract class BrowserController(args: Bundle) :
+    NewBaseController(
+        R.layout.controller_browser,
+        args
+    ),
+    ListingInterface,
+    FlexibleAdapter.OnItemClickListener,
+    SelectionInterface {
+
+    private val binding: ControllerBrowserBinding by viewBinding(ControllerBrowserBinding::bind)
+
+    @JvmField
+    protected val selectedPaths: MutableSet<String>
+
+    @JvmField
+    @Inject
+    var userUtils: UserUtils? = null
+
+    @JvmField
+    @Inject
+    var okHttpClient: OkHttpClient? = null
+
+    @JvmField
+    protected var activeUser: UserEntity
+
+    private var filesSelectionDoneMenuItem: MenuItem? = null
+    private var layoutManager: RecyclerView.LayoutManager? = null
+    private var adapter: FlexibleAdapter<BrowserFileItem>? = null
+    private var recyclerViewItems: List<BrowserFileItem> = ArrayList()
+    private var listingAbstractClass: ListingAbstractClass? = null
+    private val browserType: BrowserType
+    private var currentPath: String
+
+    private var sortingChangeListener: OnPreferenceValueChangedListener<String>? = null
+
+    override fun onViewBound(view: View) {
+        super.onViewBound(view)
+        if (adapter == null) {
+            adapter = FlexibleAdapter(recyclerViewItems, context, false)
+        }
+
+        appPreferences!!.registerSortingChangeListener(
+            SortingChangeListener(this).also {
+                sortingChangeListener = it
+            }
+        )
+
+        changeEnabledStatusForBarItems(true)
+        prepareViews()
+    }
+
+    abstract fun onFileSelectionDone()
+    override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
+        super.onCreateOptionsMenu(menu, inflater)
+        inflater.inflate(R.menu.menu_share_files, menu)
+        filesSelectionDoneMenuItem = menu.findItem(R.id.files_selection_done)
+        filesSelectionDoneMenuItem?.isVisible = selectedPaths.size > 0
+    }
+
+    override fun onOptionsItemSelected(item: MenuItem): Boolean {
+        if (item.itemId == R.id.files_selection_done) {
+            onFileSelectionDone()
+            return true
+        }
+        return super.onOptionsItemSelected(item)
+    }
+
+    override fun onAttach(view: View) {
+        super.onAttach(view)
+
+        binding.bottomNavigation.menu.findItem(R.id.action_refresh)?.setOnMenuItemClickListener { refreshCurrentPath() }
+        binding.pathNavigation.menu.findItem(R.id.action_back)?.setOnMenuItemClickListener { goBack() }
+        binding.sortButton.setOnClickListener { changeSorting() }
+
+        binding.sortButton.setText(
+            DisplayUtils.getSortOrderStringId(FileSortOrder.getFileSortOrder(appPreferences?.sorting))
+        )
+
+        refreshCurrentPath()
+    }
+
+    fun changeSorting() {
+        val newFragment: DialogFragment = SortingOrderDialogFragment
+            .newInstance(FileSortOrder.getFileSortOrder(appPreferences?.sorting))
+        newFragment.show((activity as MainActivity?)!!.supportFragmentManager, "SortingOrderDialogFragment")
+    }
+
+    public override fun onDestroy() {
+        super.onDestroy()
+        listingAbstractClass!!.tearDown()
+    }
+
+    override val title: String
+        get() =
+            currentPath
+
+    fun goBack(): Boolean {
+        fetchPath(File(currentPath).parent)
+        return true
+    }
+
+    fun refreshCurrentPath(): Boolean {
+        fetchPath(currentPath)
+        return true
+    }
+
+    @SuppressLint("RestrictedApi")
+    private fun changeEnabledStatusForBarItems(shouldBeEnabled: Boolean) {
+        binding.bottomNavigation.menu.findItem(R.id.action_refresh)?.isEnabled = shouldBeEnabled
+        binding.pathNavigation.menu.findItem(R.id.action_back)?.isEnabled = shouldBeEnabled && currentPath != "/"
+    }
+
+    private fun fetchPath(path: String) {
+        listingAbstractClass!!.cancelAllJobs()
+        changeEnabledStatusForBarItems(false)
+        listingAbstractClass!!.getFiles(
+            path,
+            activeUser,
+            if (BrowserType.DAV_BROWSER == browserType) okHttpClient else null
+        )
+    }
+
+    override fun listingResult(davResponse: DavResponse) {
+        adapter!!.clear()
+        recyclerViewItems = ArrayList()
+        if (davResponse.getData() != null) {
+            val objectList = davResponse.getData() as List<BrowserFile>
+            currentPath = objectList[0].getPath()
+            if (activity != null) {
+                activity!!.runOnUiThread { setTitle() }
+            }
+            for (i in 1 until objectList.size) {
+                (recyclerViewItems as ArrayList<BrowserFileItem>).add(BrowserFileItem(objectList[i], activeUser, this))
+            }
+        }
+
+        FileSortOrder.getFileSortOrder(appPreferences?.sorting).sortCloudFiles(recyclerViewItems)
+
+        adapter!!.addItems(0, recyclerViewItems)
+        if (activity != null) {
+            activity!!.runOnUiThread {
+                adapter!!.notifyDataSetChanged()
+                changeEnabledStatusForBarItems(true)
+            }
+        }
+    }
+
+    private fun shouldPathBeSelectedDueToParent(currentPath: String): Boolean {
+        if (selectedPaths.size > 0) {
+            var file = File(currentPath)
+            if (file.parent != "/") {
+                while (file.parent != null) {
+                    var parent = file.parent!!
+                    if (File(file.parent!!).parent != null) {
+                        parent += "/"
+                    }
+                    if (selectedPaths.contains(parent)) {
+                        return true
+                    }
+                    file = File(file.parent!!)
+                }
+            }
+        }
+        return false
+    }
+
+    private fun checkAndRemoveAnySelectedParents(currentPath: String) {
+        var file = File(currentPath)
+        selectedPaths.remove(currentPath)
+        while (file.parent != null) {
+            selectedPaths.remove(file.parent!! + "/")
+            file = File(file.parent!!)
+        }
+        adapter!!.notifyDataSetChanged()
+    }
+
+    override fun onItemClick(view: View, position: Int): Boolean {
+        val browserFile = (adapter!!.getItem(position) as BrowserFileItem).model
+        if ("inode/directory" == browserFile.getMimeType()) {
+            fetchPath(browserFile.getPath())
+            return true
+        }
+        return false
+    }
+
+    private fun prepareViews() {
+        if (activity != null) {
+            layoutManager = SmoothScrollLinearLayoutManager(activity)
+            binding.recyclerView.layoutManager = layoutManager
+            binding.recyclerView.setHasFixedSize(true)
+            binding.recyclerView.adapter = adapter
+            adapter!!.fastScroller = binding.fastScrollerContainer.fastScroller
+            adapter!!.addListener(this)
+            binding.fastScrollerContainer.fastScroller.setBubbleTextCreator { position: Int ->
+                val abstractFlexibleItem: IFlexible<*> = adapter!!.getItem(position)!!
+                if (abstractFlexibleItem is BrowserFileItem) {
+                    return@setBubbleTextCreator (adapter!!.getItem(position) as BrowserFileItem)
+                        .model
+                        .getDisplayName()[0]
+                        .toString()
+                } else {
+                    return@setBubbleTextCreator ""
+                }
+            }
+        }
+    }
+
+    @SuppressLint("RestrictedApi")
+    override fun toggleBrowserItemSelection(path: String) {
+        if (selectedPaths.contains(path) || shouldPathBeSelectedDueToParent(path)) {
+            checkAndRemoveAnySelectedParents(path)
+        } else {
+            // TOOD: if it's a folder, remove all the children we added manually
+            selectedPaths.add(path)
+        }
+        filesSelectionDoneMenuItem?.isVisible = selectedPaths.size > 0
+    }
+
+    override fun isPathSelected(path: String): Boolean {
+        return selectedPaths.contains(path) || shouldPathBeSelectedDueToParent(path)
+    }
+
+    abstract override fun shouldOnlySelectOneImageFile(): Boolean
+
+    @Parcel
+    enum class BrowserType {
+        FILE_BROWSER, DAV_BROWSER
+    }
+
+    init {
+        setHasOptionsMenu(true)
+        sharedApplication!!.componentApplication.inject(this)
+        browserType = Parcels.unwrap(args.getParcelable(KEY_BROWSER_TYPE))
+        activeUser = Parcels.unwrap(args.getParcelable(KEY_USER_ENTITY))
+        currentPath = "/"
+        if (BrowserType.DAV_BROWSER == browserType) {
+            listingAbstractClass = DavListing(this)
+        } // else {
+        // listingAbstractClass = new LocalListing(this);
+        // }
+        selectedPaths = Collections.synchronizedSet(TreeSet())
+    }
+
+    @Suppress("Detekt.TooGenericExceptionCaught")
+    private class SortingChangeListener(private val browserController: BrowserController) :
+        OnPreferenceValueChangedListener<String> {
+        override fun onChanged(newValue: String) {
+            try {
+                val sortOrder = FileSortOrder.getFileSortOrder(newValue)
+
+                browserController.binding.sortButton.setText(DisplayUtils.getSortOrderStringId(sortOrder))
+                browserController.recyclerViewItems = sortOrder.sortCloudFiles(browserController.recyclerViewItems)
+
+                if (browserController.activity != null) {
+                    browserController.activity!!.runOnUiThread {
+                        browserController.adapter!!.updateDataSet(browserController.recyclerViewItems)
+                        browserController.changeEnabledStatusForBarItems(true)
+                    }
+                }
+            } catch (npe: NullPointerException) {
+                // view binding can be null
+                // since this is called asynchrously and UI might have been destroyed in the meantime
+                Log.i(BrowserController.TAG, "UI destroyed - view binding already gone")
+            }
+        }
+    }
+
+    companion object {
+        private const val TAG = "BrowserController"
+    }
+}

+ 1 - 1
app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserForAvatarController.java

@@ -41,7 +41,7 @@ public class BrowserForAvatarController extends BrowserController {
     }
 
     @Override
-    void onFileSelectionDone() {
+    public void onFileSelectionDone() {
         controller.handleAvatar(selectedPaths.iterator().next());
 
         getRouter().popCurrentController();

+ 1 - 1
app/src/main/java/com/nextcloud/talk/components/filebrowser/controllers/BrowserForSharingController.java

@@ -43,7 +43,7 @@ public class BrowserForSharingController extends BrowserController {
     }
 
     @Override
-    void onFileSelectionDone() {
+    public void onFileSelectionDone() {
         synchronized (selectedPaths) {
             Iterator<String> iterator = selectedPaths.iterator();
 

+ 198 - 0
app/src/main/java/com/nextcloud/talk/ui/dialog/SortingOrderDialogFragment.java

@@ -0,0 +1,198 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Andy Scherzinger
+ * Copyright (C) 2017-2021 Andy Scherzinger
+ * Copyright (C) 2017 Nextcloud
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.talk.ui.dialog;
+
+import android.annotation.SuppressLint;
+import android.app.Dialog;
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import com.google.android.material.button.MaterialButton;
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
+import com.nextcloud.talk.R;
+import com.nextcloud.talk.application.NextcloudTalkApplication;
+import com.nextcloud.talk.databinding.SortingOrderFragmentBinding;
+import com.nextcloud.talk.utils.FileSortOrder;
+import com.nextcloud.talk.utils.preferences.AppPreferences;
+
+import javax.inject.Inject;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.DialogFragment;
+import autodagger.AutoInjector;
+import kotlin.jvm.JvmField;
+
+/**
+ * Dialog to show and choose the sorting order for the file listing.
+ */
+@AutoInjector(NextcloudTalkApplication.class)
+public class SortingOrderDialogFragment extends DialogFragment implements View.OnClickListener {
+
+    private final static String TAG = SortingOrderDialogFragment.class.getSimpleName();
+
+    public static final String SORTING_ORDER_FRAGMENT = "SORTING_ORDER_FRAGMENT";
+    private static final String KEY_SORT_ORDER = "SORT_ORDER";
+
+    @Inject
+    @JvmField
+    AppPreferences appPreferences;
+
+    private SortingOrderFragmentBinding binding;
+    private View dialogView;
+
+    private View[] taggedViews;
+    private String currentSortOrderName;
+
+    public static SortingOrderDialogFragment newInstance(FileSortOrder sortOrder) {
+        SortingOrderDialogFragment dialogFragment = new SortingOrderDialogFragment();
+
+        Bundle args = new Bundle();
+        args.putString(KEY_SORT_ORDER, sortOrder.name);
+        dialogFragment.setArguments(args);
+
+        return dialogFragment;
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        // keep the state of the fragment on configuration changes
+        setRetainInstance(true);
+
+        if (getArguments() != null) {
+            currentSortOrderName = getArguments().getString(KEY_SORT_ORDER, FileSortOrder.sort_a_to_z.name);
+        }
+    }
+
+    @SuppressLint("InflateParams")
+    @NonNull
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        binding = SortingOrderFragmentBinding.inflate(LayoutInflater.from(requireContext()));
+        dialogView = binding.getRoot();
+
+        return new MaterialAlertDialogBuilder(requireContext()).setView(dialogView).create();
+    }
+
+    @Override
+    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+        return dialogView;
+    }
+
+    @Override
+    public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
+        super.onViewCreated(view, savedInstanceState);
+        NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this);
+
+        setupDialogElements();
+        setupListeners();
+    }
+
+    /**
+     * find all relevant UI elements and set their values.
+     */
+    private void setupDialogElements() {
+        binding.cancel.setTextColor(getResources().getColor(R.color.colorPrimary));
+
+        taggedViews = new View[12];
+        taggedViews[0] = binding.sortByNameAscending;
+        taggedViews[0].setTag(FileSortOrder.sort_a_to_z);
+        taggedViews[1] = binding.sortByNameAZText;
+        taggedViews[1].setTag(FileSortOrder.sort_a_to_z);
+        taggedViews[2] = binding.sortByNameDescending;
+        taggedViews[2].setTag(FileSortOrder.sort_z_to_a);
+        taggedViews[3] = binding.sortByNameZAText;
+        taggedViews[3].setTag(FileSortOrder.sort_z_to_a);
+        taggedViews[4] = binding.sortByModificationDateAscending;
+        taggedViews[4].setTag(FileSortOrder.sort_old_to_new);
+        taggedViews[5] = binding.sortByModificationDateOldestFirstText;
+        taggedViews[5].setTag(FileSortOrder.sort_old_to_new);
+        taggedViews[6] = binding.sortByModificationDateDescending;
+        taggedViews[6].setTag(FileSortOrder.sort_new_to_old);
+        taggedViews[7] = binding.sortByModificationDateNewestFirstText;
+        taggedViews[7].setTag(FileSortOrder.sort_new_to_old);
+        taggedViews[8] = binding.sortBySizeAscending;
+        taggedViews[8].setTag(FileSortOrder.sort_small_to_big);
+        taggedViews[9] = binding.sortBySizeSmallestFirstText;
+        taggedViews[9].setTag(FileSortOrder.sort_small_to_big);
+        taggedViews[10] = binding.sortBySizeDescending;
+        taggedViews[10].setTag(FileSortOrder.sort_big_to_small);
+        taggedViews[11] = binding.sortBySizeBiggestFirstText;
+        taggedViews[11].setTag(FileSortOrder.sort_big_to_small);
+
+        setupActiveOrderSelection();
+    }
+
+    /**
+     * tints the icon reflecting the actual sorting choice in the apps primary color.
+     */
+    private void setupActiveOrderSelection() {
+        final int color = getResources().getColor(R.color.colorPrimary);
+        Log.i("SortOrder", "currentSortOrderName="+currentSortOrderName);
+        for (View view : taggedViews) {
+            Log.i("SortOrder", ((FileSortOrder) view.getTag()).name);
+            if (!((FileSortOrder) view.getTag()).name.equals(currentSortOrderName)) {
+                continue;
+            }
+            if (view instanceof MaterialButton) {
+                ((MaterialButton) view).setIconTintResource(R.color.colorPrimary);
+            }
+            if (view instanceof TextView) {
+                ((TextView) view).setTextColor(color);
+                ((TextView) view).setTypeface(Typeface.DEFAULT_BOLD);
+            }
+        }
+    }
+
+    /**
+     * setup all listeners.
+     */
+    private void setupListeners() {
+        binding.cancel.setOnClickListener(view -> dismiss());
+
+        for (View view : taggedViews) {
+            Log.i("SortOrder", "view="+view.getTag().toString());
+            view.setOnClickListener(this);
+        }
+    }
+
+    @Override
+    public void onDestroyView() {
+        Log.d(TAG, "destroy SortingOrderDialogFragment view");
+        if (getDialog() != null && getRetainInstance()) {
+            getDialog().setDismissMessage(null);
+        }
+        binding = null;
+        super.onDestroyView();
+    }
+
+    @Override
+    public void onClick(View v) {
+        appPreferences.setSorting(((FileSortOrder) v.getTag()).name);
+        dismiss();
+    }
+}

+ 28 - 0
app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java

@@ -2,6 +2,8 @@
  * Nextcloud Talk application
  *
  * @author Mario Danic
+ * @author Andy Scherzinger
+ * Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
  * Copyright (C) 2017-2020 Mario Danic <mario@lovelyhq.com>
  *
  * This program is free software: you can redistribute it and/or modify
@@ -94,6 +96,7 @@ import androidx.annotation.ColorRes;
 import androidx.annotation.DrawableRes;
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
+import androidx.annotation.StringRes;
 import androidx.annotation.XmlRes;
 import androidx.appcompat.widget.AppCompatDrawableManager;
 import androidx.appcompat.widget.SearchView;
@@ -102,6 +105,13 @@ import androidx.core.graphics.ColorUtils;
 import androidx.core.graphics.drawable.DrawableCompat;
 import androidx.emoji.text.EmojiCompat;
 
+import static com.nextcloud.talk.utils.FileSortOrder.sort_a_to_z_id;
+import static com.nextcloud.talk.utils.FileSortOrder.sort_big_to_small_id;
+import static com.nextcloud.talk.utils.FileSortOrder.sort_new_to_old_id;
+import static com.nextcloud.talk.utils.FileSortOrder.sort_old_to_new_id;
+import static com.nextcloud.talk.utils.FileSortOrder.sort_small_to_big_id;
+import static com.nextcloud.talk.utils.FileSortOrder.sort_z_to_a_id;
+
 public class DisplayUtils {
 
     private static final String TAG = "DisplayUtils";
@@ -548,5 +558,23 @@ public class DisplayUtils {
                 .build();
         avatarImageView.setController(draweeController);
     }
+
+    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;
+        }
+    }
 }
 

+ 108 - 0
app/src/main/java/com/nextcloud/talk/utils/FileSortOrder.java

@@ -0,0 +1,108 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Sven R. Kunze
+ * @author Andy Scherzinger
+ * Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
+ * Copyright (C) 2017 Sven R. Kunze
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.talk.utils;
+
+import android.text.TextUtils;
+
+import com.nextcloud.talk.components.filebrowser.adapters.items.BrowserFileItem;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import androidx.annotation.Nullable;
+
+/**
+ * Sort order
+ */
+public class FileSortOrder {
+    public static final String sort_a_to_z_id = "sort_a_to_z";
+    public static final String sort_z_to_a_id = "sort_z_to_a";
+    public static final String sort_old_to_new_id = "sort_old_to_new";
+    public static final String sort_new_to_old_id = "sort_new_to_old";
+    public static final String sort_small_to_big_id = "sort_small_to_big";
+    public static final String sort_big_to_small_id = "sort_big_to_small";
+
+    public static final FileSortOrder sort_a_to_z = new FileSortOrderByName(sort_a_to_z_id, true);
+    public static final FileSortOrder sort_z_to_a = new FileSortOrderByName(sort_z_to_a_id, false);
+    public static final FileSortOrder sort_old_to_new = new FileSortOrderByDate(sort_old_to_new_id, true);
+    public static final FileSortOrder sort_new_to_old = new FileSortOrderByDate(sort_new_to_old_id, false);
+    public static final FileSortOrder sort_small_to_big = new FileSortOrderBySize(sort_small_to_big_id, true);
+    public static final FileSortOrder sort_big_to_small = new FileSortOrderBySize(sort_big_to_small_id, false);
+
+    public static final Map<String, FileSortOrder> sortOrders;
+
+    static {
+        HashMap<String, FileSortOrder> temp = new HashMap<>();
+        temp.put(sort_a_to_z.name, sort_a_to_z);
+        temp.put(sort_z_to_a.name, sort_z_to_a);
+        temp.put(sort_old_to_new.name, sort_old_to_new);
+        temp.put(sort_new_to_old.name, sort_new_to_old);
+        temp.put(sort_small_to_big.name, sort_small_to_big);
+        temp.put(sort_big_to_small.name, sort_big_to_small);
+
+        sortOrders = Collections.unmodifiableMap(temp);
+    }
+
+    public String name;
+    public boolean isAscending;
+
+    public FileSortOrder(String name, boolean ascending) {
+        this.name = name;
+        isAscending = ascending;
+    }
+
+    public static FileSortOrder getFileSortOrder(@Nullable String key) {
+        if (TextUtils.isEmpty(key) || !sortOrders.containsKey(key)) {
+            return sort_a_to_z;
+        } else {
+            return sortOrders.get(key);
+        }
+    }
+
+    public List<BrowserFileItem> sortCloudFiles(List<BrowserFileItem> files) {
+        return sortCloudFilesByFavourite(files);
+    }
+
+    /**
+     * Sorts list by Favourites.
+     *
+     * @param files files to sort
+     */
+    public static List<BrowserFileItem> sortCloudFilesByFavourite(List<BrowserFileItem> files) {
+        Collections.sort(files, (o1, o2) -> {
+            if (o1.getModel().isFavorite() && o2.getModel().isFavorite()) {
+                return 0;
+            } else if (o1.getModel().isFavorite()) {
+                return -1;
+            } else if (o2.getModel().isFavorite()) {
+                return 1;
+            }
+            return 0;
+        });
+
+        return files;
+    }
+}

+ 52 - 0
app/src/main/java/com/nextcloud/talk/utils/FileSortOrderByDate.java

@@ -0,0 +1,52 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Sven R. Kunze
+ * @author Andy Scherzinger
+ * Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
+ * Copyright (C) 2017 Sven R. Kunze
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.talk.utils;
+
+import com.nextcloud.talk.components.filebrowser.adapters.items.BrowserFileItem;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Created by srkunze on 28.08.17.
+ */
+public class FileSortOrderByDate extends FileSortOrder {
+
+    FileSortOrderByDate(String name, boolean ascending) {
+        super(name, ascending);
+    }
+
+    /**
+     * Sorts list by Date.
+     *
+     * @param files list of files to sort
+     */
+    public List<BrowserFileItem> sortCloudFiles(List<BrowserFileItem> files) {
+        final int multiplier = isAscending ? 1 : -1;
+
+        Collections.sort(files, (o1, o2) ->
+                multiplier * Long.compare(o1.getModel().getModifiedTimestamp(), o2.getModel().getModifiedTimestamp()));
+
+        return super.sortCloudFiles(files);
+    }
+}

+ 63 - 0
app/src/main/java/com/nextcloud/talk/utils/FileSortOrderByName.java

@@ -0,0 +1,63 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Sven R. Kunze
+ * @author Andy Scherzinger
+ * Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
+ * Copyright (C) 2017 Sven R. Kunze
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.talk.utils;
+
+import com.nextcloud.talk.components.filebrowser.adapters.items.BrowserFileItem;
+
+import java.util.Collections;
+import java.util.List;
+
+import third_parties.daveKoeller.AlphanumComparator;
+
+/**
+ * Created by srkunze on 28.08.17.
+ */
+public class FileSortOrderByName extends FileSortOrder {
+
+    FileSortOrderByName(String name, boolean ascending) {
+        super(name, ascending);
+    }
+
+    /**
+     * Sorts list by Name.
+     *
+     * @param files files to sort
+     */
+    @SuppressWarnings("Bx")
+    public List<BrowserFileItem> sortCloudFiles(List<BrowserFileItem> files) {
+        final int multiplier = isAscending ? 1 : -1;
+
+        Collections.sort(files, (o1, o2) -> {
+            if (!o1.getModel().isFile() && !o2.getModel().isFile()) {
+                return multiplier * new AlphanumComparator().compare(o1, o2);
+            } else if (!o1.getModel().isFile()) {
+                return -1;
+            } else if (!o2.getModel().isFile()) {
+                return 1;
+            }
+            return multiplier * new AlphanumComparator().compare(o1, o2);
+        });
+
+        return super.sortCloudFiles(files);
+    }
+}

+ 64 - 0
app/src/main/java/com/nextcloud/talk/utils/FileSortOrderBySize.java

@@ -0,0 +1,64 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Sven R. Kunze
+ * @author Andy Scherzinger
+ * Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
+ * Copyright (C) 2017 Sven R. Kunze
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.talk.utils;
+
+import com.nextcloud.talk.components.filebrowser.adapters.items.BrowserFileItem;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Sorts files by sizes
+ */
+public class FileSortOrderBySize extends FileSortOrder {
+
+    FileSortOrderBySize(String name, boolean ascending) {
+        super(name, ascending);
+    }
+
+    /**
+     * Sorts list by Size.
+     *
+     * @param files list of files to sort
+     */
+    public List<BrowserFileItem> sortCloudFiles(List<BrowserFileItem> files) {
+        final int multiplier = isAscending ? 1 : -1;
+
+        Collections.sort(files, (o1, o2) -> {
+            if (!o1.getModel().isFile() && !o2.getModel().isFile()) {
+                Long obj1 = o1.getModel().size;
+                return multiplier * obj1.compareTo(o2.getModel().getSize());
+            } else if (!o1.getModel().isFile()) {
+                return -1;
+
+            } else if (!o2.getModel().isFile()) {
+                return 1;
+            } else {
+                Long obj1 = o1.getModel().getSize();
+                return multiplier * obj1.compareTo(o2.getModel().getSize());
+            }
+        });
+
+        return super.sortCloudFiles(files);
+    }
+}

+ 18 - 0
app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java

@@ -2,7 +2,9 @@
  * Nextcloud Talk application
  *
  * @author Mario Danic
+ * @author Andy Scherzinger
  * @author Tim Krüger
+ * Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
  * Copyright (C) 2021 Tim Krüger <t@timkrueger.me>
  * Copyright (C) 2017 Mario Danic <mario@lovelyhq.com>
  *
@@ -23,6 +25,7 @@
 package com.nextcloud.talk.utils.preferences;
 
 import com.nextcloud.talk.R;
+import com.nextcloud.talk.utils.FileSortOrder;
 
 import net.orange_box.storebox.annotations.method.ClearMethod;
 import net.orange_box.storebox.annotations.method.DefaultValue;
@@ -316,6 +319,21 @@ public interface AppPreferences {
     @UnregisterChangeListenerMethod
     void unregisterReadPrivacyChangeListener(OnPreferenceValueChangedListener<Boolean> listener);
 
+    @KeyByResource(R.string.nc_file_browser_sort_by_key)
+    void setSorting(String value);
+
+    @KeyByResource(R.string.nc_file_browser_sort_by_key)
+    @DefaultValue(R.string.nc_file_browser_sort_by_default)
+    String getSorting();
+
+    @KeyByResource(R.string.nc_file_browser_sort_by_key)
+    @RegisterChangeListenerMethod
+    void registerSortingChangeListener(OnPreferenceValueChangedListener<String> listener);
+
+    @KeyByResource(R.string.nc_file_browser_sort_by_key)
+    @UnregisterChangeListenerMethod
+    void unregisterSortingChangeListener(OnPreferenceValueChangedListener<String> listener);
+
     @ClearMethod
     void clear();
 }

+ 188 - 0
app/src/main/java/third_parties/daveKoeller/AlphanumComparator.java

@@ -0,0 +1,188 @@
+/*
+ * The Alphanum Algorithm is an improved sorting algorithm for strings
+ * containing numbers.  Instead of sorting numbers in ASCII order like
+ * a standard sort, this algorithm sorts numbers in numeric order.
+ *
+ * The Alphanum Algorithm is discussed at http://www.DaveKoelle.com
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+package third_parties.daveKoeller;
+
+import java.io.File;
+import java.io.Serializable;
+import java.math.BigInteger;
+import java.text.Collator;
+import java.util.Comparator;
+
+/*
+ * This is an updated version with enhancements made by Daniel Migowski, Andre Bogus, and David Koelle
+ *  *
+ * To convert to use Templates (Java 1.5+):
+ * - Change "implements Comparator" to "implements Comparator<String>"
+ * - Change "compare(Object o1, Object o2)" to "compare(String s1, String s2)"
+ * - Remove the type checking and casting in compare().
+ *
+ * To use this class:
+ * Use the static "sort" method from the java.util.Collections class:
+ * Collections.sort(your list, new AlphanumComparator());
+ *
+ * Adapted to fit
+ * https://github.com/nextcloud/server/blob/9a4253ef7c34f9dc71a6a9f7828a10df769f0c32/tests/lib/NaturalSortTest.php
+ * by Tobias Kaminsky
+ */
+public class AlphanumComparator<T> implements Comparator<T>, Serializable {
+    private boolean isDigit(char ch) {
+        return ch >= 48 && ch <= 57;
+    }
+
+    private boolean isSpecialChar(char ch) {
+        return ch <= 47 || ch >= 58 && ch <= 64 || ch >= 91 && ch <= 96 || ch >= 123 && ch <= 126;
+    }
+
+    /**
+     * Length of string is passed in for improved efficiency (only need to calculate it once)
+     **/
+    private String getChunk(String string, int stringLength, int marker) {
+        StringBuilder chunk = new StringBuilder();
+        char c = string.charAt(marker);
+        chunk.append(c);
+        marker++;
+        if (isDigit(c)) {
+            while (marker < stringLength) {
+                c = string.charAt(marker);
+                if (!isDigit(c)) {
+                    break;
+                }
+                chunk.append(c);
+                marker++;
+            }
+        } else if (!isSpecialChar(c)) {
+            while (marker < stringLength) {
+                c = string.charAt(marker);
+                if (isDigit(c) || isSpecialChar(c)) {
+                    break;
+                }
+                chunk.append(c);
+                marker++;
+            }
+        }
+        return chunk.toString();
+    }
+
+    public int compare(File f1, File f2) {
+        String s1 = f1.getPath();
+        String s2 = f2.getPath();
+
+        return compare(s1, s2);
+    }
+
+    public int compare(T t1, T t2) {
+        return compare(t1.toString(), t2.toString());
+    }
+
+    public int compare(String s1, String s2) {
+        int thisMarker = 0;
+        int thatMarker = 0;
+        int s1Length = s1.length();
+        int s2Length = s2.length();
+
+        while (thisMarker < s1Length && thatMarker < s2Length) {
+            String thisChunk = getChunk(s1, s1Length, thisMarker);
+            thisMarker += thisChunk.length();
+
+            String thatChunk = getChunk(s2, s2Length, thatMarker);
+            thatMarker += thatChunk.length();
+
+            // If both chunks contain numeric characters, sort them numerically
+            int result = 0;
+            if (isDigit(thisChunk.charAt(0)) && isDigit(thatChunk.charAt(0))) {
+                // extract digits
+                int thisChunkZeroCount = 0;
+                boolean zero = true;
+                int countThis = 0;
+                while (countThis < (thisChunk.length()) && isDigit(thisChunk.charAt(countThis))) {
+                    if (zero) {
+                        if (Character.getNumericValue(thisChunk.charAt(countThis)) == 0) {
+                            thisChunkZeroCount++;
+                        } else {
+                            zero = false;
+                        }
+                    }
+                    countThis++;
+                }
+
+
+                int thatChunkZeroCount = 0;
+                int countThat = 0;
+                zero = true;
+                while (countThat < (thatChunk.length()) && isDigit(thatChunk.charAt(countThat))) {
+                    if (zero) {
+                        if (Character.getNumericValue(thatChunk.charAt(countThat)) == 0) {
+                            thatChunkZeroCount++;
+                        } else {
+                            zero = false;
+                        }
+                    }
+                    countThat++;
+                }
+
+                BigInteger thisChunkValue = new BigInteger(thisChunk.substring(0, countThis));
+                BigInteger thatChunkValue = new BigInteger(thatChunk.substring(0, countThat));
+
+                result = thisChunkValue.compareTo(thatChunkValue);
+
+                if (result == 0) {
+                    // value is equal, compare leading zeros
+                    result = Integer.compare(thisChunkZeroCount, thatChunkZeroCount);
+
+                    if (result != 0) {
+                        return result;
+                    }
+                } else {
+                    return result;
+                }
+            } else if (isSpecialChar(thisChunk.charAt(0)) && isSpecialChar(thatChunk.charAt(0))) {
+                for (int i = 0; i < thisChunk.length(); i++) {
+                    if (thisChunk.charAt(i) == '.' && thatChunk.charAt(i) != '.') {
+                        return -1;
+                    } else if (thatChunk.charAt(i) == '.' && thisChunk.charAt(i) != '.') {
+                        return 1;
+                    } else {
+                        result = thisChunk.charAt(i) - thatChunk.charAt(i);
+                        if (result != 0) {
+                            return result;
+                        }
+                    }
+                }
+            } else if (isSpecialChar(thisChunk.charAt(0)) && !isSpecialChar(thatChunk.charAt(0))) {
+                return -1;
+            } else if (!isSpecialChar(thisChunk.charAt(0)) && isSpecialChar(thatChunk.charAt(0))) {
+                return 1;
+            } else {
+                result = Collator.getInstance().compare(thisChunk, thatChunk);
+            }
+
+            if (result != 0) {
+                return result;
+            }
+        }
+
+        return s1Length - s2Length;
+    }
+}

+ 502 - 0
app/src/main/java/third_parties/daveKoeller/lgpl-2.1.txt

@@ -0,0 +1,502 @@
+                  GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL.  It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it.  You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+  When we speak of free software, we are referring to freedom of use,
+not price.  Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+  To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights.  These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  To protect each distributor, we want to make it very clear that
+there is no warranty for the free library.  Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+  Finally, software patents pose a constant threat to the existence of
+any free program.  We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder.  Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+  Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License.  This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License.  We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+  When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library.  The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom.  The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+  We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License.  It also provides other free software developers Less
+of an advantage over competing non-free programs.  These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries.  However, the Lesser license provides advantages in certain
+special circumstances.
+
+  For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard.  To achieve this, non-free programs must be
+allowed to use the library.  A more frequent case is that a free
+library does the same job as widely used non-free libraries.  In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+  In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software.  For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+  Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+                  GNU LESSER GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+  1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+  You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+  If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+  6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+  You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License.  You must supply a copy of this License.  If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License.  Also, you must do one
+of these things:
+
+    a) Accompany the work with the complete corresponding
+    machine-readable source code for the Library including whatever
+    changes were used in the work (which must be distributed under
+    Sections 1 and 2 above); and, if the work is an executable linked
+    with the Library, with the complete machine-readable "work that
+    uses the Library", as object code and/or source code, so that the
+    user can modify the Library and then relink to produce a modified
+    executable containing the modified Library.  (It is understood
+    that the user who changes the contents of definitions files in the
+    Library will not necessarily be able to recompile the application
+    to use the modified definitions.)
+
+    b) Use a suitable shared library mechanism for linking with the
+    Library.  A suitable mechanism is one that (1) uses at run time a
+    copy of the library already present on the user's computer system,
+    rather than copying library functions into the executable, and (2)
+    will operate properly with a modified version of the library, if
+    the user installs one, as long as the modified version is
+    interface-compatible with the version that the work was made with.
+
+    c) Accompany the work with a written offer, valid for at
+    least three years, to give the same user the materials
+    specified in Subsection 6a, above, for a charge no more
+    than the cost of performing this distribution.
+
+    d) If distribution of the work is made by offering access to copy
+    from a designated place, offer equivalent access to copy the above
+    specified materials from the same place.
+
+    e) Verify that the user has already received a copy of these
+    materials or that you have already sent this user a copy.
+
+  For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it.  However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+  It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system.  Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+  7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+    a) Accompany the combined library with a copy of the same work
+    based on the Library, uncombined with any other library
+    facilities.  This must be distributed under the terms of the
+    Sections above.
+
+    b) Give prominent notice with the combined library of the fact
+    that part of it is a work based on the Library, and explaining
+    where to find the accompanying uncombined form of the same work.
+
+  8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License.  Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License.  However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+  9. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Library or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+  10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+  11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded.  In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+  13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation.  If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+  14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission.  For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this.  Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+                            NO WARRANTY
+
+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
+
+           How to Apply These Terms to Your New Libraries
+
+  If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change.  You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+  To apply these terms, attach the following notices to the library.  It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the library's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the
+  library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+  <signature of Ty Coon>, 1 April 1990
+  Ty Coon, President of Vice
+
+That's all there is to it!

+ 29 - 0
app/src/main/res/drawable/borderless_btn.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Nextcloud Android client application
+
+  Copyright (C) 2017 Andy Scherzinger
+
+  This program is free software; you can redistribute it and/or
+  modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+  License as published by the Free Software Foundation; either
+  version 3 of the License, or any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+
+  You should have received a copy of the GNU Affero General Public
+  License along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item
+        android:state_enabled="false"
+        android:color="@color/disabled_text" />
+
+    <item
+        android:color="@color/colorAccent"/>
+        
+</selector>

+ 25 - 0
app/src/main/res/drawable/ic_alphabetical_asc.xml

@@ -0,0 +1,25 @@
+<!--
+    @author Google LLC
+    @author Andy Scherzinger
+    Copyright (C) 2018 Google LLC
+    Copyright (C) 2018 Andy Scherzinger
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path android:fillColor="#757575" android:pathData="M20.401,13.623L18.877,13.621L18.868,20.218L17.228,18.57L16.145,19.651L19.627,23.145L23.12,19.663L22.039,18.58L20.392,20.219L20.401,13.623ZM15.034,12.122L15.034,13.376L10.691,19.609L10.691,19.684L15.1,19.684L15.1,21.481L7.847,21.481L7.847,20.302L12.292,13.967L12.292,13.91L8.268,13.91L8.268,12.122L15.034,12.122ZM13.051,1.85L15.981,11.208L13.678,11.208L12.949,8.68L10.244,8.68L9.571,11.208L7.352,11.208L10.244,1.85L13.051,1.85ZM12.64,7.165L12.05,5.182L11.807,4.273L11.573,3.374L11.545,3.374L11.339,4.283L11.114,5.2L10.553,7.165L12.64,7.165Z" />
+</vector>

+ 26 - 0
app/src/main/res/drawable/ic_alphabetical_desc.xml

@@ -0,0 +1,26 @@
+<!--
+    @author Google LLC
+    @author Andy Scherzinger
+    Copyright (C) 2018 Google LLC
+    Copyright (C) 2018 Andy Scherzinger
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path android:fillColor="#757575" android:pathData="M10.244,12.122L7.352,21.481L9.571,21.481L10.244,18.953L12.949,18.953L13.678,21.481L15.981,21.481L13.051,12.122L10.244,12.122ZM11.545,13.647L11.573,13.647L11.807,14.546L12.05,15.454L12.64,17.437L10.553,17.437L11.114,15.473L11.339,14.555L11.545,13.647L11.545,13.647Z" />
+    <path android:fillColor="#757575" android:pathData="M20.401,13.623L18.877,13.621L18.868,20.218L17.228,18.57L16.145,19.651L19.627,23.145L23.12,19.663L22.039,18.58L20.392,20.219L20.401,13.623ZM15.034,1.85L15.034,3.104L10.691,9.337L10.691,9.412L15.1,9.412L15.1,11.209L7.847,11.209L7.847,10.03L12.292,3.694L12.292,3.638L8.268,3.638L8.268,1.85L15.034,1.85Z" />
+</vector>

+ 25 - 0
app/src/main/res/drawable/ic_keyboard_arrow_down.xml

@@ -0,0 +1,25 @@
+<!--
+    @author Google LLC
+    Copyright (C) 2018 Google LLC
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<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>

+ 25 - 0
app/src/main/res/drawable/ic_modification_asc.xml

@@ -0,0 +1,25 @@
+<!--
+    @author Google LLC
+    @author Andy Scherzinger
+    Copyright (C) 2018 Google LLC
+    Copyright (C) 2018 Andy Scherzinger
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path android:fillColor="#757575" android:pathData="M17.611,20.838L17.611,22.69L14.635,22.69L14.635,20.838L17.611,20.838ZM11.59,2.133C16.177,2.138 20.131,5.479 20.902,10L18.979,10C18.232,6.53 15.139,4.029 11.59,4.025C7.44,4.026 4.026,7.44 4.025,11.59C4.025,15.74 7.44,19.156 11.59,19.156C12.068,19.155 12.546,19.109 13.016,19.018L13.016,20.922C12.544,21 12.068,21.043 11.59,21.049C6.36,21.049 2.133,16.791 2.133,11.59C2.133,6.402 6.402,2.133 11.59,2.133ZM20.587,16.208L20.587,18.06L14.635,18.06L14.635,16.208L20.587,16.208ZM12.062,6.863L12.062,11.826L13.016,12.393L13.016,13.957L10.645,12.535L10.645,6.863L12.062,6.863ZM23.563,11.577L23.563,13.429L14.635,13.429L14.635,11.577L23.563,11.577Z" />
+</vector>

+ 25 - 0
app/src/main/res/drawable/ic_modification_desc.xml

@@ -0,0 +1,25 @@
+<!--
+    @author Google LLC
+    @author Andy Scherzinger
+    Copyright (C) 2018 Google LLC
+    Copyright (C) 2018 Andy Scherzinger
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path android:fillColor="#757575" android:pathData="M23.563,22.69L14.635,22.69L14.635,20.838L23.563,20.838L23.563,22.69ZM11.59,2.133C16.177,2.138 20.131,5.479 20.902,10L18.979,10C18.232,6.53 15.139,4.029 11.59,4.025C7.44,4.026 4.026,7.44 4.025,11.59C4.025,15.74 7.44,19.156 11.59,19.156C12.068,19.155 12.546,19.109 13.016,19.018L13.016,20.922C12.544,21 12.068,21.043 11.59,21.049C6.36,21.049 2.133,16.791 2.133,11.59C2.133,6.402 6.402,2.133 11.59,2.133ZM20.587,18.06L14.635,18.06L14.635,16.208L20.587,16.208L20.587,18.06ZM12.062,6.863L12.062,11.826L13.016,12.393L13.016,13.957L10.645,12.535L10.645,6.863L12.062,6.863ZM17.611,13.429L14.635,13.429L14.635,11.577L17.611,11.577L17.611,13.429Z" />
+</vector>

+ 25 - 0
app/src/main/res/drawable/ic_size_asc.xml

@@ -0,0 +1,25 @@
+<!--
+    @author Google LLC
+    @author Andy Scherzinger
+    Copyright (C) 2018 Google LLC
+    Copyright (C) 2018 Andy Scherzinger
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path android:fillColor="#757575" android:pathData="M23.564,22.69L14.635,22.69L14.635,20.838L23.564,20.838L23.564,22.69ZM10.412,1.805C15.122,1.81 19.145,5.333 19.773,10L17.869,10C17.257,6.376 14.087,3.697 10.412,3.695C6.262,3.695 2.846,7.11 2.846,11.26C2.846,11.26 2.846,11.26 2.846,11.261C2.846,15.411 6.261,18.826 10.411,18.826C10.412,18.826 10.412,18.826 10.412,18.826C11.301,18.822 12.182,18.661 13.016,18.352L13.016,20.338C12.17,20.586 11.293,20.714 10.412,20.719C5.224,20.719 0.955,16.45 0.955,11.262C0.955,11.261 0.955,11.26 0.955,11.26C0.956,6.073 5.225,1.805 10.412,1.805ZM20.587,18.06L14.635,18.06L14.635,16.208L20.587,16.208L20.587,18.06ZM10.412,5.588L10.412,11.26L6.402,15.27C8.191,17.058 10.881,17.4 13.016,16.297L13.016,10L15.941,10C15.712,8.993 15.207,8.036 14.42,7.252C13.313,6.136 11.859,5.588 10.412,5.588ZM17.611,13.43L14.635,13.43L14.635,11.578L17.611,11.578L17.611,13.43Z" />
+</vector>

+ 25 - 0
app/src/main/res/drawable/ic_size_desc.xml

@@ -0,0 +1,25 @@
+<!--
+    @author Google LLC
+    @author Andy Scherzinger
+    Copyright (C) 2018 Google LLC
+    Copyright (C) 2018 Andy Scherzinger
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path android:fillColor="#757575" android:pathData="M17.611,20.838l0,1.852l-2.976,0l0,-1.852l2.976,0Zm-7.199,-19.033c4.71,0.005 8.733,3.528 9.361,8.195l-1.904,0c-0.612,-3.624 -3.782,-6.303 -7.457,-6.305c-4.15,0 -7.566,3.415 -7.566,7.565c0,0 0,0 0,0.001c0,4.15 3.415,7.565 7.565,7.565c0.001,0 0.001,0 0.001,0c0.889,-0.004 1.77,-0.165 2.604,-0.474l0,1.986c-0.846,0.248 -1.723,0.376 -2.604,0.381c-5.188,0 -9.457,-4.269 -9.457,-9.457c0,-0.001 0,-0.002 0,-0.002c0.001,-5.187 4.27,-9.455 9.457,-9.455Zm10.175,14.403l0,1.852l-5.952,0l0,-1.852l5.952,0Zm-10.175,-10.62l0,5.672l-4.01,4.01c1.789,1.788 4.479,2.13 6.614,1.027l0,-6.297l2.925,0c-0.229,-1.007 -0.734,-1.964 -1.521,-2.748c-1.107,-1.116 -2.561,-1.664 -4.008,-1.664Zm13.151,5.989l0,1.852l-8.928,0l0,-1.852l8.928,0Z" />
+</vector>

+ 54 - 6
app/src/main/res/layout/controller_browser.xml

@@ -2,6 +2,8 @@
   ~ Nextcloud Talk application
   ~
   ~ @author Mario Danic
+  ~ @author Andy Scherzinger
+  ~ Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
   ~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
   ~
   ~ This program is free software: you can redistribute it and/or modify
@@ -26,25 +28,71 @@
     android:background="@color/bg_default"
     android:orientation="vertical">
 
-    <androidx.recyclerview.widget.RecyclerView
-        android:id="@+id/recycler_view"
+    <!-- sorting/layout bar -->
+    <RelativeLayout
+        android:id="@+id/sort_list_button_group"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_above="@id/bottom_navigation"
-        android:layout_below="@id/path_navigation"
-        tools:listitem="@layout/rv_item_browser_file" />
+        android:background="@color/appbar"
+        android:visibility="visible"
+        tools:visibility="visible">
+
+        <com.google.android.material.button.MaterialButton
+            android:id="@+id/sort_button"
+            style="@style/Nextcloud.Material.TextButton"
+            android:layout_width="wrap_content"
+            android:layout_height="@dimen/min_size_clickable_area"
+            android:layout_marginStart="7dp"
+            android:contentDescription=""
+            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" />
+
+        <com.google.android.material.button.MaterialButton
+            android:id="@+id/switch_grid_view_button"
+            style="@style/Widget.AppTheme.Button.IconButton"
+            android:layout_width="@dimen/min_size_clickable_area"
+            android:layout_height="@dimen/min_size_clickable_area"
+            android:layout_marginEnd="1dp"
+            android:contentDescription=""
+            android:layout_alignEnd="@+id/sort_button"
+            android:layout_alignParentEnd="true"
+            android:visibility="invisible"
+            app:cornerRadius="24dp"
+            app:icon="@drawable/ic_search_grey"
+            app:iconTint="@color/fontAppbar" />
+
+    </RelativeLayout>
 
     <com.google.android.material.bottomnavigation.BottomNavigationView
         android:id="@+id/path_navigation"
+        style="@style/BottomNavigationView"
         android:layout_width="match_parent"
         android:layout_height="64dp"
+        android:layout_below="@id/sort_list_button_group"
+        android:layout_marginTop="-1dp"
         android:background="@color/bg_default"
-        app:itemTextColor="@color/fg_default"
         app:itemIconTint="@color/fg_default"
+        app:itemTextColor="@color/fg_default"
         app:menu="@menu/file_browser_path" />
 
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/recycler_view"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_above="@id/bottom_navigation"
+        android:layout_below="@id/path_navigation"
+        tools:listitem="@layout/rv_item_browser_file" />
+
     <com.google.android.material.bottomnavigation.BottomNavigationView
         android:id="@+id/bottom_navigation"
+        style="@style/BottomNavigationView"
         android:layout_width="match_parent"
         android:layout_height="64dp"
         android:layout_alignParentBottom="true"

+ 308 - 0
app/src/main/res/layout/sorting_order_fragment.xml

@@ -0,0 +1,308 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+  Nextcloud Android client application
+
+  Copyright (C) 2017 Andy Scherzinger
+  Copyright (C) 2017 Nextcloud
+
+  This program is free software; you can redistribute it and/or
+  modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+  License as published by the Free Software Foundation; either
+  version 3 of the License, or any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+
+  You should have received a copy of the GNU Affero General Public
+  License along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:id="@+id/root"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:minWidth="300dp"
+    android:orientation="vertical">
+
+    <TextView
+        android:id="@+id/header"
+        style="@style/Base.DialogWindowTitle.AppCompat"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_margin="@dimen/standard_margin"
+        android:text="@string/nc_sort_by" />
+
+    <ScrollView
+        android:id="@+id/scrollableSortings"
+        android:layout_width="match_parent"
+        android:layout_height="0dp"
+        android:layout_weight="1">
+
+        <TableLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content">
+
+            <TableRow
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content">
+
+                <com.google.android.material.button.MaterialButton
+                    android:id="@+id/sortByNameAscending"
+                    style="@style/Widget.AppTheme.Button.IconButton"
+                    android:layout_width="@dimen/min_size_clickable_area"
+                    android:layout_height="@dimen/min_size_clickable_area"
+                    android:layout_gravity="center_vertical"
+                    android:background="@color/bg_default"
+                    android:contentDescription="@string/menu_item_sort_by_name_a_z"
+                    android:paddingStart="@dimen/standard_padding"
+                    android:paddingTop="@dimen/standard_half_padding"
+                    android:paddingEnd="@dimen/standard_half_padding"
+                    android:paddingBottom="@dimen/standard_half_padding"
+                    app:cornerRadius="@dimen/button_corner_radius"
+                    app:icon="@drawable/ic_alphabetical_asc"
+                    app:iconTint="@color/grey_600" />
+
+                <TextView
+                    android:id="@+id/sortByNameAZText"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center_vertical"
+                    android:layout_weight="1"
+                    android:ellipsize="middle"
+                    android:gravity="center_vertical"
+                    android:minHeight="@dimen/min_size_clickable_area"
+                    android:paddingStart="@dimen/zero"
+                    android:paddingTop="@dimen/standard_half_padding"
+                    android:paddingEnd="@dimen/standard_double_padding"
+                    android:paddingBottom="@dimen/standard_half_padding"
+                    android:singleLine="true"
+                    android:text="@string/menu_item_sort_by_name_a_z"
+                    android:textColor="@color/grey_600"
+                    android:textSize="@dimen/two_line_primary_text_size" />
+
+            </TableRow>
+
+            <TableRow
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content">
+
+                <com.google.android.material.button.MaterialButton
+                    android:id="@+id/sortByNameDescending"
+                    style="@style/Widget.AppTheme.Button.IconButton"
+                    android:layout_width="@dimen/min_size_clickable_area"
+                    android:layout_height="@dimen/min_size_clickable_area"
+                    android:layout_gravity="center_vertical"
+                    android:background="@color/bg_default"
+                    android:contentDescription="@string/menu_item_sort_by_name_z_a"
+                    android:paddingStart="@dimen/standard_padding"
+                    android:paddingTop="@dimen/standard_half_padding"
+                    android:paddingEnd="@dimen/standard_half_padding"
+                    android:paddingBottom="@dimen/standard_half_padding"
+                    app:cornerRadius="@dimen/button_corner_radius"
+                    app:icon="@drawable/ic_alphabetical_desc"
+                    app:iconTint="@color/grey_600" />
+
+                <TextView
+                    android:id="@+id/sortByNameZAText"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center_vertical"
+                    android:layout_weight="1"
+                    android:ellipsize="middle"
+                    android:gravity="center_vertical"
+                    android:minHeight="@dimen/min_size_clickable_area"
+                    android:paddingStart="@dimen/zero"
+                    android:paddingTop="@dimen/standard_half_padding"
+                    android:paddingEnd="@dimen/standard_double_padding"
+                    android:paddingBottom="@dimen/standard_half_padding"
+                    android:singleLine="true"
+                    android:text="@string/menu_item_sort_by_name_z_a"
+                    android:textColor="@color/grey_600"
+                    android:textSize="@dimen/two_line_primary_text_size" />
+
+            </TableRow>
+
+            <TableRow
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginTop="@dimen/standard_half_margin">
+
+                <com.google.android.material.button.MaterialButton
+                    android:id="@+id/sortByModificationDateDescending"
+                    style="@style/Widget.AppTheme.Button.IconButton"
+                    android:layout_width="@dimen/min_size_clickable_area"
+                    android:layout_height="@dimen/min_size_clickable_area"
+                    android:layout_gravity="center_vertical"
+                    android:background="@color/bg_default"
+                    android:contentDescription="@string/menu_item_sort_by_date_oldest_first"
+                    android:paddingStart="@dimen/standard_padding"
+                    android:paddingTop="@dimen/standard_half_padding"
+                    android:paddingEnd="@dimen/standard_half_padding"
+                    android:paddingBottom="@dimen/standard_half_padding"
+                    app:cornerRadius="@dimen/button_corner_radius"
+                    app:icon="@drawable/ic_modification_desc"
+                    app:iconTint="@color/grey_600" />
+
+                <TextView
+                    android:id="@+id/sortByModificationDateNewestFirstText"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center_vertical"
+                    android:layout_weight="1"
+                    android:ellipsize="middle"
+                    android:gravity="center_vertical"
+                    android:minHeight="@dimen/min_size_clickable_area"
+                    android:paddingStart="@dimen/zero"
+                    android:paddingTop="@dimen/standard_half_padding"
+                    android:paddingEnd="@dimen/standard_double_padding"
+                    android:paddingBottom="@dimen/standard_half_padding"
+                    android:singleLine="true"
+                    android:text="@string/menu_item_sort_by_date_newest_first"
+                    android:textColor="@color/grey_600"
+                    android:textSize="@dimen/two_line_primary_text_size" />
+
+            </TableRow>
+
+            <TableRow
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content">
+
+                <com.google.android.material.button.MaterialButton
+                    android:id="@+id/sortByModificationDateAscending"
+                    style="@style/Widget.AppTheme.Button.IconButton"
+                    android:layout_width="@dimen/min_size_clickable_area"
+                    android:layout_height="@dimen/min_size_clickable_area"
+                    android:layout_gravity="center_vertical"
+                    android:background="@color/bg_default"
+                    android:contentDescription="@string/menu_item_sort_by_date_newest_first"
+                    android:paddingStart="@dimen/standard_padding"
+                    android:paddingTop="@dimen/standard_half_padding"
+                    android:paddingEnd="@dimen/standard_half_padding"
+                    android:paddingBottom="@dimen/standard_half_padding"
+                    app:cornerRadius="@dimen/button_corner_radius"
+                    app:icon="@drawable/ic_modification_asc"
+                    app:iconTint="@color/grey_600" />
+
+                <TextView
+                    android:id="@+id/sortByModificationDateOldestFirstText"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center_vertical"
+                    android:layout_weight="1"
+                    android:ellipsize="middle"
+                    android:gravity="center_vertical"
+                    android:minHeight="@dimen/min_size_clickable_area"
+                    android:paddingStart="@dimen/zero"
+                    android:paddingTop="@dimen/standard_half_padding"
+                    android:paddingEnd="@dimen/standard_double_padding"
+                    android:paddingBottom="@dimen/standard_half_padding"
+                    android:singleLine="true"
+                    android:text="@string/menu_item_sort_by_date_oldest_first"
+                    android:textColor="@color/grey_600"
+                    android:textSize="@dimen/two_line_primary_text_size" />
+
+            </TableRow>
+
+            <TableRow
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+
+                android:layout_marginTop="@dimen/standard_half_margin">
+
+                <com.google.android.material.button.MaterialButton
+                    android:id="@+id/sortBySizeDescending"
+                    style="@style/Widget.AppTheme.Button.IconButton"
+                    android:layout_width="@dimen/min_size_clickable_area"
+                    android:layout_height="@dimen/min_size_clickable_area"
+                    android:layout_gravity="center_vertical"
+                    android:background="@color/bg_default"
+                    android:contentDescription="@string/menu_item_sort_by_size_biggest_first"
+                    android:paddingStart="@dimen/standard_padding"
+                    android:paddingTop="@dimen/standard_half_padding"
+                    android:paddingEnd="@dimen/standard_half_padding"
+                    android:paddingBottom="@dimen/standard_half_padding"
+                    app:cornerRadius="@dimen/button_corner_radius"
+                    app:icon="@drawable/ic_size_desc"
+                    app:iconTint="@color/grey_600" />
+
+                <TextView
+                    android:id="@+id/sortBySizeBiggestFirstText"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center_vertical"
+                    android:layout_weight="1"
+                    android:ellipsize="middle"
+                    android:gravity="center_vertical"
+                    android:minHeight="@dimen/min_size_clickable_area"
+                    android:paddingStart="@dimen/zero"
+                    android:paddingTop="@dimen/standard_half_padding"
+                    android:paddingEnd="@dimen/standard_double_padding"
+                    android:paddingBottom="@dimen/standard_half_padding"
+                    android:singleLine="true"
+                    android:text="@string/menu_item_sort_by_size_biggest_first"
+                    android:textColor="@color/grey_600"
+                    android:textSize="@dimen/two_line_primary_text_size" />
+
+            </TableRow>
+
+            <TableRow
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content">
+
+                <com.google.android.material.button.MaterialButton
+                    android:id="@+id/sortBySizeAscending"
+                    style="@style/Widget.AppTheme.Button.IconButton"
+                    android:layout_width="@dimen/min_size_clickable_area"
+                    android:layout_height="@dimen/min_size_clickable_area"
+                    android:layout_gravity="center_vertical"
+                    android:background="@color/bg_default"
+                    android:contentDescription="@string/menu_item_sort_by_size_smallest_first"
+                    android:paddingStart="@dimen/standard_padding"
+                    android:paddingTop="@dimen/standard_half_padding"
+                    android:paddingEnd="@dimen/standard_half_padding"
+                    android:paddingBottom="@dimen/standard_half_padding"
+                    app:cornerRadius="@dimen/button_corner_radius"
+                    app:icon="@drawable/ic_size_asc"
+                    app:iconTint="@color/grey_600" />
+
+                <TextView
+                    android:id="@+id/sortBySizeSmallestFirstText"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center_vertical"
+                    android:layout_weight="1"
+                    android:ellipsize="middle"
+                    android:gravity="center_vertical"
+                    android:minHeight="@dimen/min_size_clickable_area"
+                    android:paddingStart="@dimen/zero"
+                    android:paddingTop="@dimen/standard_half_padding"
+                    android:paddingEnd="@dimen/standard_double_padding"
+                    android:paddingBottom="@dimen/standard_half_padding"
+                    android:singleLine="true"
+                    android:text="@string/menu_item_sort_by_size_smallest_first"
+                    android:textColor="@color/grey_600"
+                    android:textSize="@dimen/two_line_primary_text_size" />
+
+            </TableRow>
+
+        </TableLayout>
+
+    </ScrollView>
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:gravity="end">
+
+        <com.google.android.material.button.MaterialButton
+            android:id="@+id/cancel"
+            style="@style/Button.Borderless"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:minHeight="@dimen/min_size_clickable_area"
+            android:text="@string/nc_cancel" />
+
+    </LinearLayout>
+
+</LinearLayout>

+ 1 - 0
app/src/main/res/values-night/colors.xml

@@ -27,6 +27,7 @@
     <color name="colorPrimary">#0082C9</color>
     <color name="colorPrimaryDark">#006AA3</color>
     <color name="colorAccent">@color/colorPrimary</color>
+    <color name="disabled_text">#ff6F6F6F</color>
 
     <!-- App bar -->
     <color name="appbar">#1E1E1E</color>

+ 1 - 0
app/src/main/res/values/colors.xml

@@ -25,6 +25,7 @@
     <color name="colorPrimary">#0082C9</color>
     <color name="colorPrimaryDark">#006AA3</color>
     <color name="colorAccent">@color/colorPrimary</color>
+    <color name="disabled_text">#ff888888</color>
     <color name="textColorOnPrimaryBackground">#ffffff</color> <!-- white/black depending on primary color -->
     <color name="nc_login_text_color">#B3FFFFFF</color>
 

+ 1 - 0
app/src/main/res/values/dimens.xml

@@ -62,4 +62,5 @@
 
     <dimen name="call_grid_item_min_height">180dp</dimen>
     <dimen name="call_controls_height">110dp</dimen>
+    <dimen name="zero">0dp</dimen>
 </resources>

+ 9 - 0
app/src/main/res/values/strings.xml

@@ -336,6 +336,15 @@
     <string name="nc_file_browser_refresh">Refresh</string>
     <string name="nc_last_modified">%1$s | Last modified: %2$s</string>
     <string name="nc_file_browser_reshare_forbidden">You are not allowed to re-share this file</string>
+    <string name="nc_sort_by">Sort by</string>
+    <string name="nc_file_browser_sort_by_key" translatable="false">file_browser_sort_by</string>
+    <string name="nc_file_browser_sort_by_default" translatable="false">sort_a_to_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_date_newest_first">Newest first</string>
+    <string name="menu_item_sort_by_date_oldest_first">Oldest first</string>
+    <string name="menu_item_sort_by_size_biggest_first">Biggest first</string>
+    <string name="menu_item_sort_by_size_smallest_first">Smallest first</string>
 
     <!-- Lobby -->
     <string name="nc_webinar">Webinar</string>

+ 11 - 0
app/src/main/res/values/styles.xml

@@ -55,6 +55,10 @@
         <item name="android:navigationBarColor">@color/grey950</item>
     </style>
 
+    <style name="BottomNavigationView" parent="@style/Widget.MaterialComponents.BottomNavigationView">
+        <item name="elevation">1dp</item>
+    </style>
+
     <style name="ErrorAppearance" parent="@android:style/TextAppearance">
         <item name="android:textColor">@color/nc_darkRed</item>
         <item name="android:textSize">12sp</item>
@@ -113,6 +117,13 @@
         <item name="iconPadding">0dp</item>
     </style>
 
+    <style name="Button.Borderless" parent="Widget.MaterialComponents.Button.TextButton">
+        <item name="android:textColor">@drawable/borderless_btn</item>
+        <item name="android:textAllCaps">false</item>
+        <item name="android:typeface">sans</item>
+        <item name="android:textStyle">bold</item>
+    </style>
+
     <style name="Widget.App.Login.TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
         <item name="colorControlActivated">@color/white</item>
         <item name="colorControlHighlight">@color/white</item>

+ 1 - 1
scripts/analysis/findbugs-results.txt

@@ -1 +1 @@
-599
+596

+ 1 - 1
scripts/analysis/lint-results.txt

@@ -1,2 +1,2 @@
 DO NOT TOUCH; GENERATED BY DRONE
-      <span class="mdl-layout-title">Lint Report: 3 errors and 266 warnings</span>
+      <span class="mdl-layout-title">Lint Report: 3 errors and 268 warnings</span>