From 9a10d98b1f686faf58385e6ad8460c1aeac1aa62 Mon Sep 17 00:00:00 2001 From: Li Guanglin <60415467+guanglinn@users.noreply.github.com> Date: Fri, 12 Jan 2024 03:05:43 +0800 Subject: [PATCH] FileBrowser: Add options to select all files (PR #2187 by @guanglinn) Co-authored-by: Gregor Santner Co-authored-by: Harshad Vedartham --- .../frontend/textview/HighlightingEditor.java | 2 +- .../filebrowser/GsFileBrowserFragment.java | 29 ++++++++++++++++--- .../filebrowser/GsFileBrowserListAdapter.java | 14 +++++++++ .../res/drawable/ic_check_circle_24dp.xml | 9 ++++++ .../main/res/drawable/ic_close_white_24dp.xml | 26 +++++++++++++++++ app/src/main/res/layout/main__activity.xml | 20 ++++++++++++- app/src/main/res/menu/filesystem__menu.xml | 17 ++++------- app/src/main/res/values/strings.xml | 1 + build.gradle | 2 +- 9 files changed, 101 insertions(+), 19 deletions(-) create mode 100644 app/src/main/res/drawable/ic_check_circle_24dp.xml create mode 100644 app/src/main/res/drawable/ic_close_white_24dp.xml diff --git a/app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java b/app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java index ae60ecbcf1..bc5230d9aa 100644 --- a/app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java +++ b/app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java @@ -466,7 +466,7 @@ static class LineNumbersDrawer { private final Paint _paint = new Paint(); private final int _defaultPaddingLeft; - private static final int LINE_NUMBER_PADDING_LEFT = 20; + private static final int LINE_NUMBER_PADDING_LEFT = 18; private static final int LINE_NUMBER_PADDING_RIGHT = 12; private final Rect _visibleArea = new Rect(); diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java index 105180b02b..275af85d14 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java @@ -27,6 +27,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; @@ -77,8 +78,10 @@ public static GsFileBrowserFragment newInstance() { //######################## private RecyclerView _recyclerList; - private SwipeRefreshLayout swipe; + private SwipeRefreshLayout _swipe; private TextView _emptyHint; + private TextView _topNavSubTitle; + private ImageView _topNavLeftActionButton; private GsFileBrowserListAdapter _filesystemViewerAdapter; private GsFileBrowserOptions.Options _dopt; @@ -101,8 +104,10 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat super.onViewCreated(root, savedInstanceState); Context context = getContext(); _recyclerList = root.findViewById(R.id.ui__filesystem_dialog__list); - swipe = root.findViewById(R.id.pull_to_refresh); + _swipe = root.findViewById(R.id.pull_to_refresh); _emptyHint = root.findViewById(R.id.empty_hint); + _topNavSubTitle = getActivity().findViewById(R.id.top_nav_sub_title); + _topNavLeftActionButton = getActivity().findViewById(R.id.top_nav_cancel); _appSettings = ApplicationObject.settings(); _cu = new MarkorContextUtils(root.getContext()); @@ -122,11 +127,14 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat _filesystemViewerAdapter.getFilter().filter(""); onFsViewerDoUiUpdate(_filesystemViewerAdapter); - swipe.setOnRefreshListener(() -> { + _swipe.setOnRefreshListener(() -> { + _filesystemViewerAdapter.unselectAll(); _filesystemViewerAdapter.reloadCurrentFolder(); - swipe.setRefreshing(false); + _swipe.setRefreshing(false); }); + _topNavLeftActionButton.setOnClickListener(v -> _filesystemViewerAdapter.unselectAll()); + if (FileSearchEngine.isSearchExecuting.get()) { FileSearchEngine.activity.set(new WeakReference<>(getActivity())); } @@ -203,11 +211,19 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) { } @Override + @SuppressLint("SetTextI18n") public void onFsViewerDoUiUpdate(GsFileBrowserListAdapter adapter) { if (_callback != null) { _callback.onFsViewerDoUiUpdate(adapter); } + // Count selected files + final int amountSelectedFiles = _filesystemViewerAdapter.getCurrentSelection().size(); + final boolean hasSelection = amountSelectedFiles > 0; + _topNavSubTitle.setText(hasSelection ? (getString(R.string.selected) + " " + amountSelectedFiles) : ""); + _topNavSubTitle.setVisibility(hasSelection ? View.VISIBLE : View.GONE); + _topNavLeftActionButton.setVisibility(hasSelection ? View.VISIBLE : View.GONE); + updateMenuItems(); _emptyHint.postDelayed(() -> _emptyHint.setVisibility(adapter.isCurrentFolderEmpty() ? View.VISIBLE : View.GONE), 200); _recyclerList.postDelayed(this::updateMenuItems, 1000); @@ -473,6 +489,11 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; } + case R.id.action_check_all: { + _filesystemViewerAdapter.selectAll(); + return true; + } + case R.id.action_share_files: { MarkorContextUtils s = new MarkorContextUtils(getContext()); s.shareStreamMultiple(getContext(), _filesystemViewerAdapter.getCurrentSelection(), "*/*"); diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java index 98ac60f2c7..23b660f1a7 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java @@ -370,6 +370,20 @@ public void toggleSelectionAll() { } } + public void selectAll() { + for (int i = 0; i < _adapterDataFiltered.size(); i++) { + TagContainer data = new TagContainer(_adapterDataFiltered.get(i), i); + if (!_currentSelection.contains(data.file)) { + if (data.file.isDirectory() && getCurrentFolder().getParentFile() != null && getCurrentFolder().getParentFile().equals(data.file)) { + continue; + } + _currentSelection.add(data.file); + notifyItemChanged(data.position); + } + } + _dopt.listener.onFsViewerDoUiUpdate(this); + } + public void unselectAll() { for (int i = 0; i < _adapterDataFiltered.size(); i++) { TagContainer data = new TagContainer(_adapterDataFiltered.get(i), i); diff --git a/app/src/main/res/drawable/ic_check_circle_24dp.xml b/app/src/main/res/drawable/ic_check_circle_24dp.xml new file mode 100644 index 0000000000..25d5692f54 --- /dev/null +++ b/app/src/main/res/drawable/ic_check_circle_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_close_white_24dp.xml b/app/src/main/res/drawable/ic_close_white_24dp.xml new file mode 100644 index 0000000000..6713dec36e --- /dev/null +++ b/app/src/main/res/drawable/ic_close_white_24dp.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/main__activity.xml b/app/src/main/res/layout/main__activity.xml index 4499ab653a..740ac727b1 100644 --- a/app/src/main/res/layout/main__activity.xml +++ b/app/src/main/res/layout/main__activity.xml @@ -31,7 +31,25 @@ android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" android:theme="@style/LightTextToolbarOverlay" - app:title="@string/app_name" /> + app:title="@string/app_name"> + + + + + diff --git a/app/src/main/res/menu/filesystem__menu.xml b/app/src/main/res/menu/filesystem__menu.xml index 7515919c41..3270b3a2d3 100644 --- a/app/src/main/res/menu/filesystem__menu.xml +++ b/app/src/main/res/menu/filesystem__menu.xml @@ -36,49 +36,42 @@ android:title="@string/rename" android:visible="false" app:showAsAction="always" /> - - - - - - - - - - - - + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 47e825e369..6657587164 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -63,6 +63,7 @@ work. If not, see . Last modified Select this folder Select + Select all Create Select entries One item selected diff --git a/build.gradle b/build.gradle index 8752c9112e..4896a72d0b 100644 --- a/build.gradle +++ b/build.gradle @@ -51,7 +51,7 @@ allprojects { task -> task.dependsOn copyRepoFiles } - tasks.matching {it instanceof Test}.all { // Enable unit test output, html+xml output + tasks.matching { it instanceof Test }.all { // Enable unit test output, html+xml output testLogging.events "passed", "skipped", "failed", "standardOut", "standardError" testLogging.showStandardStreams = true reports.junitXml.enabled = true