Skip to content

Commit 64b8778

Browse files
committed
listen completions of the remote operation
Signed-off-by: alperozturk <[email protected]>
1 parent 718b5e1 commit 64b8778

File tree

5 files changed

+46
-24
lines changed

5 files changed

+46
-24
lines changed

app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,13 +1769,29 @@ public void saveSharesFromRemoteFile(List<RemoteFile> shares) {
17691769
return;
17701770
}
17711771

1772-
final ArrayList<ContentProviderOperation> operations = prepareInsertSharesFromRemoteFile(shares);
1772+
// Prepare reset operations
1773+
Set<String> uniquePaths = new HashSet<>();
1774+
for (RemoteFile share : shares) {
1775+
uniquePaths.add(share.getRemotePath());
1776+
}
17731777

1774-
if (operations.isEmpty()) {
1775-
return;
1778+
ArrayList<ContentProviderOperation> resetOperations = new ArrayList<>();
1779+
for (String path : uniquePaths) {
1780+
resetShareFlagInAFile(path);
1781+
var removeOps = prepareRemoveSharesInFile(path, new ArrayList<>());
1782+
if (!removeOps.isEmpty()) {
1783+
resetOperations.addAll(removeOps);
1784+
}
1785+
}
1786+
if (!resetOperations.isEmpty()) {
1787+
applyBatch(resetOperations);
17761788
}
17771789

1778-
applyBatch(operations);
1790+
// Prepare insert operations
1791+
ArrayList<ContentProviderOperation> insertOperations = prepareInsertSharesFromRemoteFile(shares);
1792+
if (!insertOperations.isEmpty()) {
1793+
applyBatch(insertOperations);
1794+
}
17791795
}
17801796

17811797
/**
@@ -1798,7 +1814,7 @@ private ArrayList<ContentProviderOperation> prepareInsertSharesFromRemoteFile(It
17981814
contentValueList.addAll(contentValues);
17991815
}
18001816

1801-
final ArrayList<ContentProviderOperation> operations = new ArrayList<>();
1817+
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
18021818
for (ContentValues contentValues : contentValueList) {
18031819
operations.add(ContentProviderOperation
18041820
.newInsert(ProviderTableMeta.CONTENT_URI_SHARE)

app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
import androidx.fragment.app.Fragment;
8484
import androidx.recyclerview.widget.LinearLayoutManager;
8585
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
86+
import kotlin.Unit;
8687

8788
public class FileDetailSharingFragment extends Fragment implements ShareeListAdapterListener,
8889
DisplayUtils.AvatarGenerationListener,
@@ -154,15 +155,14 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
154155

155156
fileDataStorageManager = fileActivity.getStorageManager();
156157
ShareRepository shareRepository = new RemoteShareRepository(fileActivity.getClientRepository(), fileActivity, fileDataStorageManager);
157-
shareRepository.refreshSharesForFolder(file.getRemotePath());
158-
}
159-
160-
@Override
161-
public void onActivityCreated(Bundle savedInstanceState) {
162-
super.onActivityCreated(savedInstanceState);
163-
164-
refreshCapabilitiesFromDB();
165-
refreshSharesFromDB();
158+
shareRepository.refreshSharesForFile(file.getRemotePath(), () -> {
159+
refreshCapabilitiesFromDB();
160+
refreshSharesFromDB();
161+
return Unit.INSTANCE;
162+
}, () -> {
163+
DisplayUtils.showSnackMessage(getView(), R.string.error_fetching_sharees);
164+
return Unit.INSTANCE;
165+
});
166166
}
167167

168168
@Override
@@ -200,7 +200,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
200200
SharesType.EXTERNAL);
201201

202202
externalShareeListAdapter.setHasStableIds(true);
203-
203+
204204
binding.sharesListExternal.setAdapter(externalShareeListAdapter);
205205

206206
binding.sharesListExternal.setLayoutManager(new LinearLayoutManager(requireContext()));

app/src/main/java/com/owncloud/android/ui/fragment/share/RemoteShareRepository.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.owncloud.android.lib.common.utils.Log_OC
1515
import com.owncloud.android.operations.GetSharesForFileOperation
1616
import kotlinx.coroutines.Dispatchers
1717
import kotlinx.coroutines.launch
18+
import kotlinx.coroutines.withContext
1819

1920
class RemoteShareRepository(
2021
private val clientRepository: ClientRepository,
@@ -24,7 +25,7 @@ class RemoteShareRepository(
2425
private val tag = "RemoteShareRepository"
2526
private val scope = lifecycleOwner.lifecycleScope
2627

27-
override fun refreshSharesForFolder(remotePath: String) {
28+
override fun refreshSharesForFile(remotePath: String, onCompleted: () -> Unit, onError: () -> Unit) {
2829
scope.launch(Dispatchers.IO) {
2930
val client = clientRepository.getOwncloudClient() ?: return@launch
3031
val operation =
@@ -40,13 +41,17 @@ class RemoteShareRepository(
4041

4142
Log_OC.i(tag, "Remote path for the refresh shares: $remotePath")
4243

43-
if (result.isSuccess) {
44-
Log_OC.d(tag, "Successfully refreshed shares for the specified remote path.")
45-
} else {
46-
Log_OC.w(
47-
tag,
48-
"Failed to refresh shares for the specified remote path. An error occurred during the operation."
49-
)
44+
withContext(Dispatchers.Main) {
45+
if (result.isSuccess) {
46+
Log_OC.d(tag, "Successfully refreshed shares for the specified remote path.")
47+
onCompleted()
48+
} else {
49+
Log_OC.w(
50+
tag,
51+
"Failed to refresh shares for the specified remote path. An error occurred during the operation."
52+
)
53+
onError()
54+
}
5055
}
5156
}
5257
}

app/src/main/java/com/owncloud/android/ui/fragment/share/ShareRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
package com.owncloud.android.ui.fragment.share
99

1010
interface ShareRepository {
11-
fun refreshSharesForFolder(remotePath: String)
11+
fun refreshSharesForFile(remotePath: String, onCompleted: () -> Unit, onError: () -> Unit)
1212
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,7 @@
882882
<string name="create_new_folder">New folder</string>
883883
<string name="uploads_view_upload_status_virus_detected">Virus detected. Upload cannot be completed!</string>
884884
<string name="tags">Tags</string>
885+
<string name="error_fetching_sharees">Unable to fetch sharees.</string>
885886
<string name="sharee_add_failed">Adding sharee failed</string>
886887
<string name="sharee_already_added_to_file">Adding share failed. This file or folder has already been shared with this person or group.</string>
887888
<string name="unsharing_failed">Unsharing failed</string>

0 commit comments

Comments
 (0)