Skip to content

Commit

Permalink
Better showing of folders
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Jul 4, 2024
1 parent d0c494a commit 3c04b36
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -106,6 +107,7 @@ public static class DialogOptions {
public GsCallback.a1<AlertDialog> neutralButtonCallback = null;
public GsCallback.a1<DialogInterface> dismissCallback = null;
public GsCallback.b2<CharSequence, CharSequence> searchFunction = GsSearchOrCustomTextDialog::standardSearch;
public @Nullable InputFilter searchInputFilter = null;

@ColorInt
public int textColor = 0xFF000000;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -254,7 +254,7 @@ public void restoreSavedInstanceState(final Bundle savedInstanceState) {
_dopt.listener.onFsViewerConfig(_dopt);
}
if (f.isDirectory() || isVirtualDirectory) {
loadFolder(f);
loadFolder(f, null);
}
}
}
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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: {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
});
Expand Down

0 comments on commit 3c04b36

Please sign in to comment.