Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import androidx.annotation.NonNull;
Expand All @@ -67,6 +68,7 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
private Set<File> checkedFiles;
private ViewThemeUtils viewThemeUtils;
private boolean isWithinEncryptedFolder;
private final ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();

private static final int VIEWTYPE_ITEM = 0;
private static final int VIEWTYPE_FOOTER = 1;
Expand Down Expand Up @@ -372,7 +374,7 @@ public void swapDirectory(final File directory) {
mFiles.clear();
mFilesAll.clear();

Executors.newSingleThreadExecutor().execute(() -> {
singleThreadExecutor.execute(() -> {
// Load first page of folders
List<File> firstPage = FileHelper.INSTANCE.listDirectoryEntries(directory, currentOffset, PAGE_SIZE, true);

Expand Down Expand Up @@ -442,15 +444,25 @@ private void notifyItemRange(List<File> updatedList) {
});
}

private final Object filesLock = new Object();

@SuppressLint("NotifyDataSetChanged")
public void setSortOrder(FileSortOrder sortOrder) {
localFileListFragmentInterface.setLoading(true);
final Handler uiHandler = new Handler(Looper.getMainLooper());
Executors.newSingleThreadExecutor().execute(() -> {
preferences.setSortOrder(FileSortOrder.Type.localFileListView, sortOrder);
mFiles = sortOrder.sortLocalFiles(mFiles);
singleThreadExecutor.execute(() -> {
List<File> sortedCopy;
synchronized (filesLock) {
sortedCopy = new ArrayList<>(mFiles);
}

sortedCopy = sortOrder.sortLocalFiles(sortedCopy);

uiHandler.post(() -> {
List<File> finalSortedCopy = sortedCopy;
new Handler(Looper.getMainLooper()).post(() -> {
synchronized (filesLock) {
mFiles = finalSortedCopy;
mFilesAll = new ArrayList<>(finalSortedCopy);
}
notifyDataSetChanged();
localFileListFragmentInterface.setLoading(false);
});
Expand Down Expand Up @@ -591,4 +603,8 @@ public void setFiles(List<File> newFiles) {
notifyDataSetChanged();
localFileListFragmentInterface.setLoading(false);
}

public void cleanup() {
singleThreadExecutor.shutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -425,4 +425,10 @@ public interface ContainerActivity {
public void setupStoragePermissionWarningBanner() {
mAdapter.notifyDataSetChanged();
}

@Override
public void onDestroyView() {
mAdapter.cleanup();
super.onDestroyView();
}
}
Loading