Skip to content

Commit d6414c0

Browse files
committed
feat(okhttp-client): read folder operation
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 1123180 commit d6414c0

9 files changed

Lines changed: 76 additions & 42 deletions

File tree

app/src/androidTest/java/com/owncloud/android/AbstractOnServerIT.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,18 @@ private static boolean isFolder(RemoteFile file) {
131131
}
132132

133133
public static void deleteAllFilesOnServer() {
134-
var result = new ReadFolderRemoteOperation("/").execute(client);
134+
var result = new ReadFolderRemoteOperation("/").execute(nextcloudClient);
135135
assertTrue(result.getLogMessage(targetContext), result.isSuccess());
136136

137-
for (Object object : result.getData()) {
138-
RemoteFile remoteFile = (RemoteFile) object;
139-
137+
for (RemoteFile remoteFile : result.getResultData()) {
140138
if (!Objects.equals(remoteFile.getRemotePath(), "/")) {
141139
if (remoteFile.isEncrypted()) {
142140
ToggleEncryptionRemoteOperation operation = new ToggleEncryptionRemoteOperation(remoteFile.getLocalId(),
143141
remoteFile.getRemotePath(),
144142
false);
145143

146144
boolean operationResult = operation
147-
.execute(client)
145+
.execute(nextcloudClient)
148146
.isSuccess();
149147

150148
if (!operationResult && isFolder(remoteFile)) {

app/src/main/java/com/nextcloud/client/jobs/offlineOperations/OfflineOperationsWorker.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -280,17 +280,15 @@ class OfflineOperationsWorker(
280280
private fun getRemoteFile(remotePath: String): RemoteFile? {
281281
val mimeType = MimeTypeUtil.getMimeTypeFromPath(remotePath)
282282
val isFolder = MimeTypeUtil.isFolder(mimeType)
283-
val client = ClientFactoryImpl(context).create(user)
284-
val result = if (isFolder) {
285-
ReadFolderRemoteOperation(remotePath).execute(client)
286-
} else {
287-
ReadFileRemoteOperation(remotePath).execute(client)
288-
}
289283

290-
return if (result.isSuccess) {
291-
result.data[0] as? RemoteFile
284+
return if (isFolder) {
285+
val nextcloudClient = ClientFactoryImpl(context).createNextcloudClient(user)
286+
val result = ReadFolderRemoteOperation(remotePath).execute(nextcloudClient)
287+
if (result.isSuccess) result.resultData.getOrNull(0) else null
292288
} else {
293-
null
289+
val client = ClientFactoryImpl(context).create(user)
290+
val result = ReadFileRemoteOperation(remotePath).execute(client)
291+
if (result.isSuccess) result.data[0] as? RemoteFile else null
294292
}
295293
}
296294

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import android.util.Pair;
1717

1818
import com.nextcloud.client.account.User;
19+
import com.nextcloud.common.NextcloudClient;
1920
import com.nextcloud.utils.e2ee.E2ECounterHelper;
2021
import com.nextcloud.utils.e2ee.E2EVersionHelper;
2122
import com.nextcloud.utils.extensions.OCFileExtensionsKt;
@@ -30,6 +31,8 @@
3031
import com.owncloud.android.datamodel.e2e.v2.decrypted.DecryptedFile;
3132
import com.owncloud.android.datamodel.e2e.v2.decrypted.DecryptedFolderMetadataFile;
3233
import com.owncloud.android.lib.common.OwnCloudClient;
34+
import com.owncloud.android.lib.common.OwnCloudClientFactory;
35+
import com.owncloud.android.lib.common.accounts.AccountUtils;
3336
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
3437
import com.owncloud.android.lib.common.operations.RemoteOperation;
3538
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -208,8 +211,9 @@ private RemoteOperationResult encryptedCreateV1(OCFile parent, OwnCloudClient cl
208211
}
209212
}
210213

214+
NextcloudClient nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user, context);
211215
final var remoteFolderOperationResult = new ReadFolderRemoteOperation(encryptedRemotePath)
212-
.execute(client);
216+
.execute(nextcloudClient);
213217

214218
if (remoteFolderOperationResult.isSuccess() && remoteFolderOperationResult.getData().get(0) instanceof RemoteFile remoteFile) {
215219
createdRemoteFolder = remoteFile;
@@ -220,7 +224,7 @@ private RemoteOperationResult encryptedCreateV1(OCFile parent, OwnCloudClient cl
220224
newDir.getLocalId(),
221225
newDir.getRemotePath(),
222226
true)
223-
.execute(client);
227+
.execute(nextcloudClient);
224228

225229
if (!encryptionOperationResult.isSuccess()) {
226230
throw new RuntimeException("Error creating encrypted subfolder!");
@@ -360,8 +364,9 @@ private RemoteOperationResult encryptedCreateV2(OCFile parent, OwnCloudClient cl
360364
throw new RuntimeException("Could not unlock folder!");
361365
}
362366

367+
NextcloudClient nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user, context);
363368
final var remoteFolderOperationResult = new ReadFolderRemoteOperation(encryptedRemotePath)
364-
.execute(client);
369+
.execute(nextcloudClient);
365370

366371
if (remoteFolderOperationResult.isSuccess() && remoteFolderOperationResult.getData().get(0) instanceof RemoteFile remoteFile) {
367372
createdRemoteFolder = remoteFile;
@@ -372,7 +377,7 @@ private RemoteOperationResult encryptedCreateV2(OCFile parent, OwnCloudClient cl
372377
newDir.getLocalId(),
373378
newDir.getRemotePath(),
374379
true)
375-
.execute(client);
380+
.execute(nextcloudClient);
376381

377382
if (!encryptionOperationResult.isSuccess()) {
378383
throw new RuntimeException("Error creating encrypted subfolder!");
@@ -517,12 +522,17 @@ private RemoteOperationResult<?> normalCreate(OwnCloudClient client) {
517522
final var result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
518523

519524
if (result.isSuccess()) {
520-
final var remoteFolderOperationResult = new ReadFolderRemoteOperation(remotePath)
521-
.execute(client);
525+
try {
526+
NextcloudClient nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user, context);
527+
final var remoteFolderOperationResult = new ReadFolderRemoteOperation(remotePath)
528+
.execute(nextcloudClient);
522529

523-
if (remoteFolderOperationResult.isSuccess() &&
524-
remoteFolderOperationResult.getData().get(0) instanceof RemoteFile remoteFile) {
525-
createdRemoteFolder = remoteFile;
530+
if (remoteFolderOperationResult.isSuccess() &&
531+
remoteFolderOperationResult.getData().get(0) instanceof RemoteFile remoteFile) {
532+
createdRemoteFolder = remoteFile;
533+
}
534+
} catch (AccountUtils.AccountNotFoundException | NullPointerException e) {
535+
Log_OC.e(TAG, "Could not create NextcloudClient to read created folder " + remotePath, e);
526536
}
527537

528538
saveFolderInDB();

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
278278

279279
if (result.isSuccess()) {
280280
if (mRemoteFolderChanged) {
281-
result = fetchAndSyncRemoteFolder(client);
281+
result = fetchAndSyncRemoteFolder();
282282
} else {
283283
Log_OC.d(TAG, "💾 Remote folder is not changed, getting folder content from database");
284284
mChildren = fileDataStorageManager.getFolderContent(mLocalFolder, false);
@@ -461,9 +461,18 @@ private RemoteOperationResult checkForChanges(OwnCloudClient client) {
461461
return result;
462462
}
463463

464-
private RemoteOperationResult fetchAndSyncRemoteFolder(OwnCloudClient client) {
464+
private RemoteOperationResult fetchAndSyncRemoteFolder() {
465465
String remotePath = mLocalFolder.getRemotePath();
466-
RemoteOperationResult result = new ReadFolderRemoteOperation(remotePath).execute(client);
466+
467+
NextcloudClient nextcloudClient;
468+
try {
469+
nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user, mContext);
470+
} catch (AccountUtils.AccountNotFoundException | NullPointerException e) {
471+
Log_OC.e(TAG, "Could not create NextcloudClient to fetch " + remotePath, e);
472+
return new RemoteOperationResult<>(e);
473+
}
474+
475+
RemoteOperationResult result = new ReadFolderRemoteOperation(remotePath).execute(nextcloudClient);
467476
Log_OC.d(TAG, "⬇ eTag is changed or ignored, fetching folder: " + user.getAccountName() + remotePath);
468477

469478
if (result.isSuccess()) {

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
import com.nextcloud.client.account.User;
1818
import com.nextcloud.client.jobs.download.FileDownloadHelper;
1919
import com.nextcloud.client.jobs.folderDownload.FolderDownloadWorkerNotificationManager;
20+
import com.nextcloud.common.NextcloudClient;
2021
import com.nextcloud.utils.extensions.ExtensionsKt;
2122
import com.owncloud.android.datamodel.FileDataStorageManager;
2223
import com.owncloud.android.datamodel.OCFile;
2324
import com.owncloud.android.datamodel.e2e.v1.decrypted.DecryptedFolderMetadataFileV1;
2425
import com.owncloud.android.datamodel.e2e.v2.decrypted.DecryptedFolderMetadataFile;
2526
import com.owncloud.android.lib.common.OwnCloudClient;
27+
import com.owncloud.android.lib.common.OwnCloudClientFactory;
28+
import com.owncloud.android.lib.common.accounts.AccountUtils;
2629
import com.owncloud.android.lib.common.operations.OperationCancelledException;
2730
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
2831
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
@@ -146,13 +149,13 @@ protected RemoteOperationResult run(OwnCloudClient client) {
146149

147150
if (result.isSuccess()) {
148151
if (mRemoteFolderChanged || syncAll) {
149-
result = fetchAndSyncRemoteFolder(client);
152+
result = fetchAndSyncRemoteFolder();
150153
} else {
151154
prepareOpsFromLocalKnowledge();
152155
}
153156

154157
if (result.isSuccess()) {
155-
syncContents(client);
158+
syncContents();
156159
}
157160
}
158161

@@ -208,13 +211,21 @@ private RemoteOperationResult checkForChanges(OwnCloudClient client) throws Oper
208211
}
209212

210213

211-
private RemoteOperationResult fetchAndSyncRemoteFolder(OwnCloudClient client) throws OperationCancelledException {
214+
private RemoteOperationResult fetchAndSyncRemoteFolder() throws OperationCancelledException {
212215
if (mCancellationRequested.get()) {
213216
throw new OperationCancelledException();
214217
}
215218

219+
NextcloudClient nextcloudClient;
220+
try {
221+
nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user, mContext);
222+
} catch (AccountUtils.AccountNotFoundException | NullPointerException e) {
223+
Log_OC.e(TAG, "Could not create NextcloudClient to synchronize " + mRemotePath, e);
224+
return new RemoteOperationResult<>(e);
225+
}
226+
216227
ReadFolderRemoteOperation operation = new ReadFolderRemoteOperation(mRemotePath);
217-
var result = operation.execute(client);
228+
var result = operation.execute(nextcloudClient);
218229
Log_OC.d(TAG, "Synchronizing " + user.getAccountName() + mRemotePath);
219230
Log_OC.d(TAG, "Synchronizing remote id" + mLocalFolder.getRemoteId());
220231

@@ -442,21 +453,27 @@ private void prepareOpsFromLocalKnowledge() throws OperationCancelledException {
442453
}
443454
}
444455

445-
private void syncContents(OwnCloudClient client) throws OperationCancelledException {
456+
private void syncContents() throws OperationCancelledException {
446457
startDirectDownloads();
447458
startContentSynchronizations(mFilesToSyncContents);
448-
updateETag(client);
459+
updateETag();
449460
}
450461

451462
/**
452463
* Updates the eTag of the local folder after a successful synchronization.
453464
* This ensures that any changes to local files, which may alter the eTag, are correctly reflected.
454-
*
455-
* @param client the OwnCloudClient instance used to execute remote operations.
456465
*/
457-
private void updateETag(OwnCloudClient client) {
466+
private void updateETag() {
467+
NextcloudClient nextcloudClient;
468+
try {
469+
nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user, mContext);
470+
} catch (AccountUtils.AccountNotFoundException | NullPointerException e) {
471+
Log_OC.e(TAG, "Could not create NextcloudClient to update eTag of " + mRemotePath, e);
472+
return;
473+
}
474+
458475
ReadFolderRemoteOperation operation = new ReadFolderRemoteOperation(mRemotePath);
459-
final var result = operation.execute(client);
476+
final var result = operation.execute(nextcloudClient);
460477
if (!result.isSuccess()) {
461478
Log_OC.w(TAG, "Cannot update eTag, read folder operation is failed");
462479
return;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ class FolderEncryption(private val fragment: OCFileListFragment) {
4949
val publicKey = provider.getValue(user, EncryptionUtils.PUBLIC_KEY)
5050
val privateKey = provider.getValue(user, EncryptionUtils.PRIVATE_KEY)
5151
val client = fragment.clientFactory.create(user)
52+
val nextcloudClient = fragment.clientFactory.createNextcloudClient(user)
5253

5354
val result = ToggleEncryptionRemoteOperation(localId, remotePath, shouldBeEncrypted)
54-
.execute(client)
55+
.execute(nextcloudClient)
5556

5657
return@withContext when {
5758
result.isSuccess -> onToggleSuccess(

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ org.gradle.configuration-cache=true
2323
org.gradle.workers.max=4
2424

2525
# Needed for local libs
26-
# org.gradle.dependency.verification=off
27-
# systemProp.org.gradle.internal.publish.checksums.insecure=true
26+
org.gradle.dependency.verification=off
27+
systemProp.org.gradle.internal.publish.checksums.insecure=true
2828

2929
# Enabled parallel sync for Gradle 9.4+
3030
org.gradle.tooling.parallel=true

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ androidGifDrawableVersion = "1.2.32"
77
androidImageCropperVersion = "4.7.0"
88
androidLibraryVersion ="94372d7cbb8efe1c779ab8c2244a61510efafb28"
99
androidOpensslVersion = "3.5.6"
10-
androidPluginVersion = "9.3.2"
10+
androidPluginVersion = "9.4.0"
1111
androidsvgVersion = "1.4"
1212
androidxTestVersion = "1.7.0"
1313
annotationVersion = "1.10.0"

settings.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ dependencyResolutionManagement {
4343

4444
/*
4545
Needed for local android library
46+
47+
*/
48+
4649
includeBuild("../android_library") {
4750
dependencySubstitution {
4851
substitute(module("com.github.nextcloud:android-library"))
4952
.using(project(":library"))
5053
}
5154
}
52-
*/
53-
5455

5556
/*
5657
Needed for local android common library

0 commit comments

Comments
 (0)