Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multi-selection in shared tab #11788

Merged
merged 1 commit into from
Aug 12, 2023
Merged
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 @@ -751,7 +751,15 @@ private void parseShares(List<Object> objects) {
}
}

// create partial OCFile from OCShares
List<OCFile> files = OCShareToOCFileConverter.buildOCFilesFromShares(shares);

// set localPath of individual files iff present on device
for (OCFile file : files) {
FileStorageUtils.searchForLocalFileInDefaultPath(file, user.getAccountName());
}

mFiles.clear();
mFiles.addAll(files);
mStorageManager.saveShares(shares);
}
Expand Down Expand Up @@ -1018,27 +1026,4 @@ public int getFilesCount() {
public void notifyItemChanged(@NonNull OCFile file) {
notifyItemChanged(getItemPosition(file));
}

public void replaceFileByRemotePath(@NonNull OCFile newFile, boolean notify) {
final String remotePath = newFile.getRemotePath();
for (OCFile file : mFiles) {
if (file.getRemotePath().equals(remotePath)) {
final int index = mFiles.indexOf(file);
mFiles.set(index, newFile);
break;
}
}

for (OCFile file : mFilesAll) {
if (file.getRemotePath().equals(remotePath)) {
final int index = mFilesAll.indexOf(file);
mFilesAll.set(index, newFile);
break;
}
}

if (notify) {
notifyItemChanged(getItemPosition(newFile));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1387,8 +1387,8 @@ public void listDirectory(OCFile directory, OCFile file, boolean onlyOnDevice, b
}

public void updateOCFile(OCFile file) {
mAdapter.getFiles().remove(file);
mAdapter.getFiles().add(file);
List<OCFile> mFiles = mAdapter.getFiles();
mFiles.set(mFiles.indexOf(file), file);
mAdapter.notifyItemChanged(file);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class SharedListFragment : OCFileListFragment(), Injectable {
isSharedWithSharee = partialFile.isSharedWithSharee
sharees = partialFile.sharees
}
adapter.replaceFileByRemotePath(savedFile, false)
savedFile
}
}
Expand All @@ -120,6 +119,25 @@ class SharedListFragment : OCFileListFragment(), Injectable {
}
}

private fun fetchAllAndRun(partialFiles: MutableSet<OCFile>?, callback: (MutableSet<OCFile>?) -> Unit) {
lifecycleScope.launch {
isLoading = true
if (partialFiles != null) {
val files = partialFiles.toMutableSet().mapNotNull {partialFile ->
fetchFileData(partialFile).also {fetched ->
if (fetched == null) {
DisplayUtils.showSnackMessage(requireActivity(), R.string.error_retrieving_file)
}
}
}
isLoading = false
callback(files.toHashSet())
} else {
isLoading = false
}
}
}

override fun onShareIconClick(file: OCFile) {
fetchFileAndRun(file) { fetched ->
super.onShareIconClick(fetched)
Expand All @@ -145,16 +163,32 @@ class SharedListFragment : OCFileListFragment(), Injectable {
}

override fun onItemClicked(file: OCFile) {
fetchFileAndRun(file) { fetched ->
super.onItemClicked(fetched)
// if in multi select keep mock file
if (adapter.isMultiSelect()) {
super.onItemClicked(file)
} else {
fetchFileAndRun(file) { fetched ->
super.onItemClicked(fetched)
}
}
}

override fun onLongItemClicked(file: OCFile): Boolean {
fetchFileAndRun(file) { fetched ->
super.onLongItemClicked(fetched)
override fun onFileActionChosen(itemId: Int, checkedFiles: MutableSet<OCFile>?): Boolean {
// fetch all files and run selected action
if (itemId != R.id.action_select_all_action_menu && itemId != R.id.action_deselect_all_action_menu) {
fetchAllAndRun(checkedFiles) {files ->
exitSelectionMode()
super.onFileActionChosen(itemId, files)
}
return true
} else {
return super.onFileActionChosen(itemId, checkedFiles)
}
return true
}

override fun onRefresh() {
exitSelectionMode()
super.onRefresh()
}

companion object {
Expand Down
Loading