Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per folder sort order #2499

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

harshad1
Copy link
Collaborator

@harshad1 harshad1 commented Jan 4, 2025

In this PR I add per-folder sort support. This addresses #2435

Sample use cases:

I always want downloads to be sorted by time
I don't want folders to be first in my 'projects' folder

@@ -85,7 +87,7 @@ public boolean isPreferViewMode() {
}

public void setNotebookDirectory(final File file) {
setString(R.string.pref_key__notebook_directory, Document.getPath(file));
setString(R.string.pref_key__notebook_directory, GsFileUtils.getPath(file));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this routine to GsFileUtils

@@ -88,6 +88,7 @@ public static class DialogOptions {
public List<? extends CharSequence> data = null;
public List<? extends CharSequence> highlightData = null;
public List<Integer> iconsForData;
public Collection<Integer> radioSet = null;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows us to have radio buttons in the dialog

@@ -340,31 +355,10 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
_cu.tintMenuItems(menu, true, Color.WHITE);
_cu.setSubMenuIconsVisibility(menu, true);

MenuItem item;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this moved from menu to dialog

@@ -663,6 +664,10 @@ private void loadFolder(final File folder, final File show) {
_currentFolder = GsCollectionUtils.getOrDefault(_virtualMapping, folder, folder);
}

if (folderChanged) {
_dopt.listener.onFsViewerFolderChange(_currentFolder);
Copy link
Collaborator Author

@harshad1 harshad1 Jan 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new callback which is called right before a folder is (re)loaded

app:showAsAction="always">

<menu>
<group
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these moved to dialog

if (GsTextUtils.isNullOrEmpty(path) || json == null) {
sortOrder.sortByType = getFileBrowserSortByType();
sortOrder.reverse = isFileBrowserSortReverse();
sortOrder.folderFirst = isFileBrowserSortFolderFirst();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fall back to global if this folder does not have a custom setting

@harshad1
Copy link
Collaborator Author

harshad1 commented Jan 5, 2025

image

  • New sort menu is a dialog
  • Note that GsSearchOrCustomTextDialog now supports one or more options being radio buttons!
  • Checking 'Save' means that the sort settings will be local to this folder. Unchecking means that they will be applied globally.
  • I need a better word than 'save'

public boolean isMultiSelectEnabled = false;
public Collection<Integer> preSelected = null; // Indices of pre-selected items
public Collection<Integer> radioIndices = null; // Only one item can be selected among these
public boolean showCountInOkButton = true;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just collected the multi-select related options to one place

} else {
listAdapter._selectedItems.clear();
listAdapter._selectedItems.removeAll(listAdapter._filteredItems);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Select all adds and removes all visible options now

@@ -1070,43 +1090,4 @@ public void setFormatShareAsLink(final boolean asLink) {
public boolean getFormatShareAsLink() {
return getBool(R.string.pref_key__format_share_as_link, true);
}

private static String mapToJsonString(final Map<String, String> map) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved these to GsTextUtils

public Collection<Integer> preSelected = null; // Indices of pre-selected items
public boolean showSelectAllButton = true;
public boolean showCountInOkButton = true;
public GsCallback.a1<Set<Integer>> selectionChangedCallback = null;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows us to add a lot of dynamic functionality into the dialog. In this PR I have used it to implement Radio buttons


final MenuItem sortItem = _fragmentMenu.findItem(R.id.action_sort);
if (sortItem != null) {
_cu.tintDrawable(sortItem.getIcon(), _dopt.sortOrder.isFolderLocal ? GsFileBrowserListAdapter.FAVOURITE_COLOR : Color.WHITE);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Highlight the sort icon when the folder has a custom sort. This is a little visual hint

// Set new sort order to folder or global as needed
_appSettings.setFolderSortOrder(order.isFolderLocal ? currentFolder : null, _dopt.sortOrder);

_dopt.sortOrder = order;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO - this should be first line in the callback

@harshad1 harshad1 changed the title WIP: Per folder sort order Per folder sort order Jan 11, 2025
@harshad1
Copy link
Collaborator Author

output

Here we see:

  1. The dialog
  2. Hint that the folder order is saved (icon colour)
  3. Radio buttons
  4. Dynamic dialog - unchecking the 'Folder local' order reverts to global
  5. The functionality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants