diff --git a/app/src/main/java/net/gsantner/markor/activity/MainActivity.java b/app/src/main/java/net/gsantner/markor/activity/MainActivity.java index 1eeb2f3f72..0428e9b261 100644 --- a/app/src/main/java/net/gsantner/markor/activity/MainActivity.java +++ b/app/src/main/java/net/gsantner/markor/activity/MainActivity.java @@ -310,9 +310,8 @@ public void onClickFab(final View view) { private void newItemCallback(final File file) { if (file.isFile()) { DocumentActivity.launch(MainActivity.this, file, false, null); - } else if (file.isDirectory()) { - _notebook.getAdapter().showFile(file); } + _notebook.getAdapter().showFile(file); } @Override diff --git a/app/src/main/java/net/gsantner/opoc/frontend/GsSearchOrCustomTextDialog.java b/app/src/main/java/net/gsantner/opoc/frontend/GsSearchOrCustomTextDialog.java index c0f438a842..4c9c11bb46 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/GsSearchOrCustomTextDialog.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/GsSearchOrCustomTextDialog.java @@ -18,6 +18,7 @@ import android.graphics.Color; import android.graphics.Typeface; import android.os.Build; +import android.text.InputFilter; import android.text.InputType; import android.text.Spannable; import android.text.SpannableString; @@ -106,6 +107,7 @@ public static class DialogOptions { public GsCallback.a1 neutralButtonCallback = null; public GsCallback.a1 dismissCallback = null; public GsCallback.b2 searchFunction = GsSearchOrCustomTextDialog::standardSearch; + public @Nullable InputFilter searchInputFilter = null; @ColorInt public int textColor = 0xFF000000; @@ -276,6 +278,10 @@ public static void showMultiChoiceDialogWithSearchFilterUI(final Activity activi if (dopt.isSearchEnabled) { mainLayout.addView(searchView); + + if (dopt.searchInputFilter != null) { + searchEditText.setFilters(new InputFilter[]{dopt.searchInputFilter}); + } } final ListView listView = new ListView(activity); diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java index 70ba248cd4..e3d716ac5e 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java @@ -227,7 +227,8 @@ private void showNewDirDialog() { dopt.titleText = _dopt.newDirButtonText; dopt.textColor = rcolor(_dopt.primaryTextColor); dopt.searchHintText = android.R.string.untitled; - dopt.callback = (name) -> _filesystemViewerAdapter.createDirectoryHere(name, true); + dopt.searchInputFilter = GsContextUtils.instance.makeFilenameInputFilter(); + dopt.callback = name -> _filesystemViewerAdapter.createDirectoryHere(name); GsSearchOrCustomTextDialog.showMultiChoiceDialogWithSearchFilterUI(activity, dopt); } 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 44c9bef98f..614784bffa 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 @@ -123,7 +123,7 @@ public GsFileBrowserListAdapter(GsFileBrowserOptions.Options options, Context co _dopt.titleTextColor = _dopt.primaryTextColor; } - loadFolder(_dopt.startFolder != null ? _dopt.startFolder : _dopt.rootFolder); + loadFolder(_dopt.startFolder != null ? _dopt.startFolder : _dopt.rootFolder, null); } @NonNull @@ -254,7 +254,7 @@ public void restoreSavedInstanceState(final Bundle savedInstanceState) { _dopt.listener.onFsViewerConfig(_dopt); } if (f.isDirectory() || isVirtualDirectory) { - loadFolder(f); + loadFolder(f, null); } } } @@ -265,12 +265,12 @@ public void restoreSavedInstanceState(final Bundle savedInstanceState) { } public void reloadCurrentFolder() { - loadFolder(_currentFolder); + loadFolder(_currentFolder, null); } public void setCurrentFolder(final File folder) { if (folder != null && !folder.equals(_currentFolder)) { - loadFolder(folder); + loadFolder(folder, GsFileUtils.isChild(_currentFolder, folder) ? folder : null); } } @@ -362,23 +362,21 @@ public void onClick(View view) { if (areItemsSelected()) { // There are 1 or more items selected yet if (!toggleSelection(data) && file != null && file.isDirectory()) { - loadFolder(file); + loadFolder(file, null); } } else if (file != null) { // No pre-selection - if (file.isDirectory()) { - loadFolder(file); + if (file.isDirectory() || isVirtualStorage(file)) { + loadFolder(file, _currentFolder); } else if (file.isFile()) { _dopt.listener.onFsViewerSelected(_dopt.requestId, file, null); - } else if (isVirtualStorage(file)) { - loadFolder(file); } } } return; } case R.id.ui__filesystem_dialog__home: { - loadFolder(_dopt.rootFolder); + loadFolder(_dopt.rootFolder, _currentFolder); return; } case R.id.ui__filesystem_dialog__button_ok: { @@ -394,14 +392,14 @@ public void onClick(View view) { public void toggleSelectionAll() { for (int i = 0; i < _adapterDataFiltered.size(); i++) { - TagContainer data = new TagContainer(_adapterDataFiltered.get(i), i); + final TagContainer data = new TagContainer(_adapterDataFiltered.get(i), i); toggleSelection(data); } } public void selectAll() { for (int i = 0; i < _adapterDataFiltered.size(); i++) { - TagContainer data = new TagContainer(_adapterDataFiltered.get(i), i); + final 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; @@ -481,7 +479,7 @@ public boolean goUp() { final String absolutePath = _currentFolder.getAbsolutePath(); if (_currentFolder != null && _currentFolder.getParentFile() != null && !_currentFolder.getParentFile().getAbsolutePath().equals(absolutePath)) { unselectAll(); - loadFolder(_currentFolder.getParentFile()); + loadFolder(_currentFolder.getParentFile(), _currentFolder); return true; } return false; @@ -510,7 +508,7 @@ public boolean onLongClick(final View view) { return false; } - public File createDirectoryHere(final CharSequence name, final boolean show) { + public File createDirectoryHere(final CharSequence name) { if (name == null || _currentFolder == null || !_currentFolder.canWrite()) { return null; } @@ -524,11 +522,7 @@ public File createDirectoryHere(final CharSequence name, final boolean show) { try { final File file = new File(_currentFolder, trimmed); if (file.exists() || file.mkdir()) { - if (show) { - showFile(file); - } else { - reloadCurrentFolder(); - } + loadFolder(_currentFolder, file); return file; } } catch (SecurityException ignored) { @@ -597,10 +591,6 @@ public int getFilePosition(final File file) { private static final ExecutorService executorService = new ThreadPoolExecutor(0, 3, 60, TimeUnit.SECONDS, new SynchronousQueue<>()); - private void loadFolder(final File folder) { - loadFolder(folder, _currentFolder); - } - private void loadFolder(final File folder, final @Nullable File toShow) { final boolean folderChanged = !folder.equals(_currentFolder); if (folderChanged && _currentFolder != null && _layoutManager != null) { @@ -720,12 +710,16 @@ private void loadFolder(final File folder, final @Nullable File toShow) { _recyclerView.post(() -> showAndFlash(toShow)); } }); + } else if (toShow != null && _adapterData.contains(toShow)) { + _recyclerView.post(() -> showAndFlash(toShow)); } if (_dopt.listener != null) { _dopt.listener.onFsViewerDoUiUpdate(GsFileBrowserListAdapter.this); } }); + } else if (toShow != null && _adapterData.contains(toShow)) { + showAndFlash(toShow); } } });