Fix multi-selection in shared tab

Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com>
This commit is contained in:
ZetaTom 2023-07-04 14:26:11 +02:00 committed by Andy Scherzinger
parent f5c2d7e8ad
commit ad5379021f
3 changed files with 51 additions and 32 deletions

View file

@ -751,7 +751,15 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
}
}
// 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);
}
@ -1018,27 +1026,4 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
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));
}
}
}

View file

@ -1387,8 +1387,8 @@ public class OCFileListFragment extends ExtendedListFragment implements
}
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);
}

View file

@ -101,7 +101,6 @@ class SharedListFragment : OCFileListFragment(), Injectable {
isSharedWithSharee = partialFile.isSharedWithSharee
sharees = partialFile.sharees
}
adapter.replaceFileByRemotePath(savedFile, false)
savedFile
}
}
@ -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)
@ -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 {