Skip to content

Commit

Permalink
Changes to order of operations
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Dec 19, 2024
1 parent fb512ad commit d11981d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,12 @@ public void onViewCreated(final View root, final @Nullable Bundle savedInstanceS

_filesystemViewerAdapter = new GsFileBrowserListAdapter(_dopt, activity);
_recyclerList.setAdapter(_filesystemViewerAdapter);
onFsViewerDoUiUpdate(_filesystemViewerAdapter);

// Setup callbacks
_dopt.setSubtitle = _toolBar::setSubtitle;
_dopt.setTitle = _toolBar::setTitle;

_recyclerList.post(() -> onFsViewerDoUiUpdate(_filesystemViewerAdapter));
}

private int rcolor(@ColorRes int colorRes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.style.StrikethroughSpan;
import android.util.Log;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -140,7 +141,6 @@ public GsFileBrowserListAdapter(GsFileBrowserOptions.Options options, Context co
}

updateVirtualFolders();
loadFolder(_dopt.startFolder != null ? _dopt.startFolder : _dopt.rootFolder, null);
_filter = new StringFilter(this);
}

Expand Down Expand Up @@ -279,6 +279,7 @@ public void onAttachedToRecyclerView(@NonNull final RecyclerView view) {
super.onAttachedToRecyclerView(view);
_recyclerView = view;
_layoutManager = (LinearLayoutManager) view.getLayoutManager();
loadFolder(_dopt.startFolder != null ? _dopt.startFolder : _dopt.rootFolder, null);
}

public String formatFileDescription(final File file, String format) {
Expand Down Expand Up @@ -329,7 +330,7 @@ public void restoreSavedInstanceState(final Bundle savedInstanceState) {
}

public void reloadCurrentFolder() {
loadFolder(_currentFolder, null);
loadFolder(_currentFolder != null ? _currentFolder : _dopt.rootFolder, null);
}

public void setCurrentFolder(final File folder) {
Expand Down Expand Up @@ -642,7 +643,7 @@ public boolean scrollToAndFlash(final File file) {
private static final ExecutorService executorService = new ThreadPoolExecutor(0, 3, 60, TimeUnit.SECONDS, new SynchronousQueue<>());

private void loadFolder(final File folder, final File show) {
if (folder == null) {
if (folder == null || _recyclerView == null) {
return;
}

Expand All @@ -661,22 +662,21 @@ private void loadFolder(final File folder, final File show) {
_currentFolder = GsCollectionUtils.getOrDefault(_virtualMapping, folder, folder);
}

final File toShow = show == null ? _fileToShowAfterNextLoad : show;
_fileToShowAfterNextLoad = null;
if (_currentFolder != null) {
final File toShow = show == null ? _fileToShowAfterNextLoad : show;
_fileToShowAfterNextLoad = null;

try {
executorService.execute(() -> _loadFolder(folderChanged, toShow));
} catch (RejectedExecutionException ignored) { // during exit
try {
executorService.execute(() -> _loadFolder(folderChanged, toShow));
} catch (RejectedExecutionException err) { // during exit
Log.d(GsFileBrowserListAdapter.class.getName(), err.toString());
}
}
}

// This function is not called on the main thread
private synchronized void _loadFolder(final boolean folderChanged, final @Nullable File toShow) {

if (_recyclerView == null || _currentFolder == null) {
return;
}

final List<File> newData = new ArrayList<>();

// Make sure /storage/emulated/0 is browsable, even though filesystem says it's not accessible
Expand Down

0 comments on commit d11981d

Please sign in to comment.