Skip to content

Commit 21e7896

Browse files
committed
refreshSharesForFolder in share details
Signed-off-by: alperozturk <alper_ozturk@proton.me>
1 parent 0ccc6fa commit 21e7896

4 files changed

Lines changed: 70 additions & 15 deletions

File tree

app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,16 @@ protected RemoteOperationResult run(OwnCloudClient client) {
265265
sendLocalBroadcast(EVENT_SINGLE_FOLDER_CONTENTS_SYNCED, mLocalFolder.getRemotePath(), result);
266266
}
267267

268-
if (result.isSuccess() && !mSyncFullAccount && !mOnlyFileMetadata) {
269-
final ArrayList<RemoteFile> remoteFiles = result.getData();
268+
if (result.isSuccess() && result.getData() != null && !mSyncFullAccount && !mOnlyFileMetadata) {
269+
final var remoteObject = result.getData();
270+
final ArrayList<RemoteFile> remoteFiles = new ArrayList<>();
271+
for (Object object: remoteObject) {
272+
if (object instanceof RemoteFile remoteFile) {
273+
remoteFiles.add(remoteFile);
274+
}
275+
}
276+
270277
fileDataStorageManager.saveSharesFromRemoteFile(remoteFiles);
271-
// refreshSharesForFolder(client); // share result is ignored
272278
}
273279

274280
if (!mSyncFullAccount) {
@@ -806,17 +812,6 @@ private void startContentSynchronizations(List<SynchronizeFileOperation> filesTo
806812
}
807813
}
808814

809-
/**
810-
* Syncs the Share resources for the files contained in the folder refreshed (children, not deeper descendants).
811-
*
812-
*
813-
* fetch in the details only for one file
814-
* @param client Handler of a session with an OC server.
815-
*/
816-
private void refreshSharesForFolder(OwnCloudClient client) {
817-
GetSharesForFileOperation operation = new GetSharesForFileOperation(mLocalFolder.getRemotePath(), true, true, fileDataStorageManager);
818-
operation.execute(client);
819-
}
820815

821816
/**
822817
* Sends a message to any application component interested in the progress of the synchronization.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
import com.owncloud.android.ui.adapter.ShareeListAdapterListener;
6161
import com.owncloud.android.ui.asynctasks.RetrieveHoverCardAsyncTask;
6262
import com.owncloud.android.ui.dialog.SharePasswordDialogFragment;
63+
import com.owncloud.android.ui.fragment.share.RemoteShareRepository;
64+
import com.owncloud.android.ui.fragment.share.ShareRepository;
6365
import com.owncloud.android.ui.fragment.util.FileDetailSharingFragmentHelper;
6466
import com.owncloud.android.ui.helpers.FileOperationsHelper;
6567
import com.owncloud.android.utils.ClipboardUtil;
@@ -149,6 +151,10 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
149151
if (fileActivity == null) {
150152
throw new IllegalArgumentException("FileActivity may not be null");
151153
}
154+
155+
fileDataStorageManager = fileActivity.getStorageManager();
156+
ShareRepository shareRepository = new RemoteShareRepository(fileActivity.getClientRepository(), fileActivity, fileDataStorageManager);
157+
shareRepository.refreshSharesForFolder(file.getParentRemotePath());
152158
}
153159

154160
@Override
@@ -164,7 +170,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
164170
binding = FileDetailsSharingFragmentBinding.inflate(inflater, container, false);
165171

166172
fileOperationsHelper = fileActivity.getFileOperationsHelper();
167-
fileDataStorageManager = fileActivity.getStorageManager();
168173

169174
AccountManager accountManager = AccountManager.get(requireContext());
170175
String userId = accountManager.getUserData(user.toPlatformAccount(),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Nextcloud - Android Client
3+
*
4+
* SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com>
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
package com.owncloud.android.ui.fragment.share
9+
10+
import androidx.lifecycle.LifecycleOwner
11+
import androidx.lifecycle.lifecycleScope
12+
import com.nextcloud.repository.ClientRepository
13+
import com.owncloud.android.datamodel.FileDataStorageManager
14+
import com.owncloud.android.lib.common.utils.Log_OC
15+
import com.owncloud.android.operations.GetSharesForFileOperation
16+
import kotlinx.coroutines.Dispatchers
17+
import kotlinx.coroutines.launch
18+
19+
class RemoteShareRepository(
20+
private val clientRepository: ClientRepository,
21+
lifecycleOwner: LifecycleOwner,
22+
private val fileDataStorageManager: FileDataStorageManager
23+
) : ShareRepository {
24+
private val tag = "RemoteShareRepository"
25+
private val scope = lifecycleOwner.lifecycleScope
26+
27+
override fun refreshSharesForFolder(remotePath: String) {
28+
scope.launch(Dispatchers.IO) {
29+
val client = clientRepository.getOwncloudClient() ?: return@launch
30+
val operation = GetSharesForFileOperation(remotePath, true, true, fileDataStorageManager)
31+
val result = operation.execute(client)
32+
33+
if (result.isSuccess) {
34+
Log_OC.d(tag, "Successfully refreshed shares for the specified remote path.");
35+
} else {
36+
Log_OC.w(
37+
tag,
38+
"Failed to refresh shares for the specified remote path. An error occurred during the operation."
39+
);
40+
}
41+
}
42+
}
43+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Nextcloud - Android Client
3+
*
4+
* SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com>
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
package com.owncloud.android.ui.fragment.share
9+
10+
interface ShareRepository {
11+
fun refreshSharesForFolder(remotePath: String)
12+
}

0 commit comments

Comments
 (0)