From fbc62294f9d053d11ea16645c5f5b79404752915 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 16 Jun 2023 10:14:17 +0200 Subject: [PATCH 1/3] wip Signed-off-by: tobiasKaminsky --- .../nextcloud/client/EndToEndRandomIT.java | 2 +- .../datamodel/FileDataStorageManagerIT.java | 2 +- .../com/owncloud/android/utils/PushUtils.java | 8 +- .../com/nextcloud/client/media/LoadUrlTask.kt | 4 +- .../authentication/AuthenticatorActivity.java | 14 ++- .../owncloud/android/datamodel/Template.kt | 49 -------- .../CreateFileFromTemplateOperation.java | 95 ---------------- .../android/files/FetchTemplateOperation.java | 106 ------------------ .../files/StreamMediaFileOperation.java | 91 --------------- .../CheckCurrentCredentialsOperation.java | 4 +- .../operations/CommentFileOperation.java | 63 ----------- .../DetectAuthenticationMethodOperation.java | 6 +- .../operations/DownloadFileOperation.java | 4 +- .../operations/GetCapabilitiesOperation.java | 13 ++- .../operations/GetServerInfoOperation.java | 3 +- .../operations/GetUserProfileOperation.java | 9 +- .../operations/RefreshFolderOperation.java | 7 +- .../operations/RemoveFileOperation.java | 4 +- .../RemoveRemoteEncryptedFileOperation.java | 4 +- .../RichDocumentsCreateAssetOperation.java | 91 --------------- .../operations/RichDocumentsUrlOperation.java | 98 ---------------- .../UpdateNoteForShareOperation.java | 12 +- .../operations/UpdateOCVersionOperation.java | 5 +- .../operations/UpdateShareInfoOperation.java | 4 +- .../UpdateSharePermissionsOperation.java | 4 +- .../UpdateShareViaLinkOperation.java | 3 +- .../operations/UploadFileOperation.java | 4 +- .../common/NextcloudSyncOperation.java | 44 ++++++++ .../operations/common/SyncOperation.java | 10 +- .../android/services/OperationsService.java | 14 ++- .../data/files/FilesServiceApiImpl.java | 16 +-- .../android/ui/activity/DrawerActivity.java | 35 +++--- .../activity/RichDocumentsEditorWebView.java | 4 +- .../android/ui/adapter/OCFileListAdapter.java | 15 +-- .../adapter/RichDocumentsTemplateAdapter.java | 8 +- .../ui/asynctasks/FetchRemoteFileTask.java | 16 +-- .../ui/asynctasks/GetRemoteFileTask.kt | 3 +- .../asynctasks/RichDocumentsLoadUrlTask.java | 5 +- ...seRichDocumentsTemplateDialogFragment.java | 32 +++--- .../FileDetailActivitiesFragment.java | 2 +- .../ui/fragment/GroupfolderListFragment.kt | 2 +- .../ui/fragment/OCFileListFragment.java | 13 ++- .../ui/fragment/OCFileListSearchAsyncTask.kt | 11 +- .../android/ui/fragment/SharedListFragment.kt | 5 +- .../ui/helpers/FileOperationsHelper.java | 4 +- .../ui/preview/PreviewMediaFragment.java | 3 +- settings.gradle | 5 + 47 files changed, 208 insertions(+), 748 deletions(-) delete mode 100644 app/src/main/java/com/owncloud/android/datamodel/Template.kt delete mode 100644 app/src/main/java/com/owncloud/android/files/CreateFileFromTemplateOperation.java delete mode 100644 app/src/main/java/com/owncloud/android/files/FetchTemplateOperation.java delete mode 100644 app/src/main/java/com/owncloud/android/files/StreamMediaFileOperation.java delete mode 100644 app/src/main/java/com/owncloud/android/operations/CommentFileOperation.java delete mode 100644 app/src/main/java/com/owncloud/android/operations/RichDocumentsCreateAssetOperation.java delete mode 100644 app/src/main/java/com/owncloud/android/operations/RichDocumentsUrlOperation.java create mode 100644 app/src/main/java/com/owncloud/android/operations/common/NextcloudSyncOperation.java diff --git a/app/src/androidTest/java/com/nextcloud/client/EndToEndRandomIT.java b/app/src/androidTest/java/com/nextcloud/client/EndToEndRandomIT.java index d78b3d2b3ffe..33fa44e3946a 100644 --- a/app/src/androidTest/java/com/nextcloud/client/EndToEndRandomIT.java +++ b/app/src/androidTest/java/com/nextcloud/client/EndToEndRandomIT.java @@ -111,7 +111,7 @@ public void before() throws IOException { if (capability.getVersion().equals(new OwnCloudVersion("0.0.0"))) { // fetch new one assertTrue(new GetCapabilitiesOperation(getStorageManager()) - .execute(client) + .execute(nextcloudClient) .isSuccess()); } // tests only for NC19+ diff --git a/app/src/androidTest/java/com/owncloud/android/datamodel/FileDataStorageManagerIT.java b/app/src/androidTest/java/com/owncloud/android/datamodel/FileDataStorageManagerIT.java index 67ad5238e148..4023290b9006 100644 --- a/app/src/androidTest/java/com/owncloud/android/datamodel/FileDataStorageManagerIT.java +++ b/app/src/androidTest/java/com/owncloud/android/datamodel/FileDataStorageManagerIT.java @@ -69,7 +69,7 @@ public void before() { assertEquals(0, sut.getAllFiles().size()); capability = (OCCapability) new GetCapabilitiesRemoteOperation(null) - .execute(client) + .execute(nextcloudClient) .getSingleData(); } diff --git a/app/src/gplay/java/com/owncloud/android/utils/PushUtils.java b/app/src/gplay/java/com/owncloud/android/utils/PushUtils.java index a6ce47396bb7..0cd494648497 100644 --- a/app/src/gplay/java/com/owncloud/android/utils/PushUtils.java +++ b/app/src/gplay/java/com/owncloud/android/utils/PushUtils.java @@ -44,7 +44,6 @@ import com.owncloud.android.lib.common.OwnCloudAccount; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; -import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.notifications.RegisterAccountDeviceForNotificationsOperation; @@ -150,11 +149,8 @@ private static void deleteRegistrationForAccount(Account account) { OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton(). getClientFor(ocAccount, context); - RemoteOperation unregisterAccountDeviceForNotificationsOperation = new - UnregisterAccountDeviceForNotificationsOperation(); - - RemoteOperationResult remoteOperationResult = unregisterAccountDeviceForNotificationsOperation. - execute(mClient); + RemoteOperationResult remoteOperationResult = new + UnregisterAccountDeviceForNotificationsOperation().execute(mClient); if (remoteOperationResult.getHttpCode() == HttpStatus.SC_ACCEPTED) { String arbitraryValue; diff --git a/app/src/main/java/com/nextcloud/client/media/LoadUrlTask.kt b/app/src/main/java/com/nextcloud/client/media/LoadUrlTask.kt index be44239c7f5c..a2a9741c02c2 100644 --- a/app/src/main/java/com/nextcloud/client/media/LoadUrlTask.kt +++ b/app/src/main/java/com/nextcloud/client/media/LoadUrlTask.kt @@ -23,8 +23,8 @@ package com.nextcloud.client.media import android.os.AsyncTask -import com.owncloud.android.files.StreamMediaFileOperation import com.owncloud.android.lib.common.OwnCloudClient +import com.owncloud.android.lib.resources.files.StreamMediaFileRemoteOperation internal class LoadUrlTask( private val client: OwnCloudClient, @@ -33,7 +33,7 @@ internal class LoadUrlTask( ) : AsyncTask() { override fun doInBackground(vararg args: Void): String? { - val operation = StreamMediaFileOperation(fileId) + val operation = StreamMediaFileRemoteOperation(fileId) val result = operation.execute(client) return when (result.isSuccess) { true -> result.data[0] as String diff --git a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java index 777b3214a323..fa28927cffff 100644 --- a/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -85,6 +85,7 @@ import com.nextcloud.client.onboarding.FirstRunActivity; import com.nextcloud.client.onboarding.OnboardingService; import com.nextcloud.client.preferences.AppPreferences; +import com.nextcloud.common.NextcloudClient; import com.nextcloud.java.util.Optional; import com.owncloud.android.MainApp; import com.owncloud.android.R; @@ -911,10 +912,12 @@ private void onGetServerInfoFinish(RemoteOperationResult result) { checkBasicAuthorization(webViewUser, webViewPassword); } else { new Thread(() -> { - OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mServerInfo.mBaseUrl), - this, - true); - RemoteOperationResult remoteOperationResult = new GetCapabilitiesRemoteOperation().execute(client); + NextcloudClient client = OwnCloudClientFactory.createNextcloudClient(Uri.parse(mServerInfo.mBaseUrl), + "", + "", + this, + true); + RemoteOperationResult remoteOperationResult = new GetCapabilitiesRemoteOperation().execute(client); if (remoteOperationResult.isSuccess() && remoteOperationResult.getData() != null && @@ -1223,7 +1226,8 @@ private void getUserCapabilitiesAndFinish() { Executors.newSingleThreadExecutor().execute(() -> { try { final FileDataStorageManager storageManager = new FileDataStorageManager(user.get(), getContentResolver()); - new GetCapabilitiesOperation(storageManager).execute(MainApp.getAppContext()); + NextcloudClient nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user.get(), this); + new GetCapabilitiesOperation(storageManager).execute(nextcloudClient); handler.post(this::endSuccess); } catch (Exception e) { Log_OC.e(TAG, "Failed to fetch capabilities", e); diff --git a/app/src/main/java/com/owncloud/android/datamodel/Template.kt b/app/src/main/java/com/owncloud/android/datamodel/Template.kt deleted file mode 100644 index 20e0508214ee..000000000000 --- a/app/src/main/java/com/owncloud/android/datamodel/Template.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2018 Tobias Kaminsky - * Copyright (C) 2018 Nextcloud GmbH. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.owncloud.android.datamodel - -import android.os.Parcelable -import kotlinx.parcelize.Parcelize - -/** - * Template for creating a file from it via RichDocuments app - */ -@Parcelize -data class Template( - val id: Long, - val name: String, - val thumbnailLink: String, - val type: Type, - val extension: String -) : Parcelable { - enum class Type { - DOCUMENT, SPREADSHEET, PRESENTATION, UNKNOWN; - - companion object { - @JvmStatic - fun parse(name: String) = try { - valueOf(name.uppercase()) - } catch (_: IllegalArgumentException) { - UNKNOWN - } - } - } -} diff --git a/app/src/main/java/com/owncloud/android/files/CreateFileFromTemplateOperation.java b/app/src/main/java/com/owncloud/android/files/CreateFileFromTemplateOperation.java deleted file mode 100644 index bb49f2eb9453..000000000000 --- a/app/src/main/java/com/owncloud/android/files/CreateFileFromTemplateOperation.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2018 Tobias Kaminsky - * Copyright (C) 2018 Nextcloud GmbH. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package com.owncloud.android.files; - -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.utils.Log_OC; - -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.Utf8PostMethod; -import org.json.JSONObject; - -import java.util.ArrayList; - -public class CreateFileFromTemplateOperation extends RemoteOperation { - private static final String TAG = CreateFileFromTemplateOperation.class.getSimpleName(); - private static final int SYNC_READ_TIMEOUT = 40000; - private static final int SYNC_CONNECTION_TIMEOUT = 5000; - private static final String NEW_FROM_TEMPLATE_URL = "/ocs/v2.php/apps/richdocuments/api/v1/templates/new"; - - private String path; - private long templateId; - - // JSON node names - private static final String NODE_OCS = "ocs"; - private static final String NODE_DATA = "data"; - private static final String JSON_FORMAT = "?format=json"; - - public CreateFileFromTemplateOperation(String path, long templateId) { - this.path = path; - this.templateId = templateId; - } - - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result; - Utf8PostMethod postMethod = null; - - try { - - postMethod = new Utf8PostMethod(client.getBaseUri() + NEW_FROM_TEMPLATE_URL + JSON_FORMAT); - postMethod.setParameter("path", path); - postMethod.setParameter("template", String.valueOf(templateId)); - - // remote request - postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - - int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); - - if (status == HttpStatus.SC_OK) { - String response = postMethod.getResponseBodyAsString(); - - // Parse the response - JSONObject respJSON = new JSONObject(response); - String url = respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA).getString("url"); - - ArrayList templateArray = new ArrayList<>(); - templateArray.add(url); - - result = new RemoteOperationResult(true, postMethod); - result.setData(templateArray); - } else { - result = new RemoteOperationResult(false, postMethod); - client.exhaustResponse(postMethod.getResponseBodyAsStream()); - } - } catch (Exception e) { - result = new RemoteOperationResult(e); - Log_OC.e(TAG, "Create file from template " + templateId + " failed: " + result.getLogMessage(), - result.getException()); - } finally { - if (postMethod != null) { - postMethod.releaseConnection(); - } - } - return result; - } -} diff --git a/app/src/main/java/com/owncloud/android/files/FetchTemplateOperation.java b/app/src/main/java/com/owncloud/android/files/FetchTemplateOperation.java deleted file mode 100644 index 67b4c18c7c87..000000000000 --- a/app/src/main/java/com/owncloud/android/files/FetchTemplateOperation.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2018 Tobias Kaminsky - * Copyright (C) 2018 Nextcloud GmbH. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package com.owncloud.android.files; - -import com.owncloud.android.datamodel.Template; -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.ui.dialog.ChooseRichDocumentsTemplateDialogFragment; - -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.GetMethod; -import org.json.JSONArray; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.Locale; - -public class FetchTemplateOperation extends RemoteOperation { - private static final String TAG = FetchTemplateOperation.class.getSimpleName(); - private static final int SYNC_READ_TIMEOUT = 40000; - private static final int SYNC_CONNECTION_TIMEOUT = 5000; - private static final String TEMPLATE_URL = "/ocs/v2.php/apps/richdocuments/api/v1/templates/"; - - private ChooseRichDocumentsTemplateDialogFragment.Type type; - - // JSON node names - private static final String NODE_OCS = "ocs"; - private static final String NODE_DATA = "data"; - private static final String JSON_FORMAT = "?format=json"; - - public FetchTemplateOperation(ChooseRichDocumentsTemplateDialogFragment.Type type) { - this.type = type; - } - - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result; - GetMethod getMethod = null; - - try { - - getMethod = new GetMethod(client.getBaseUri() + TEMPLATE_URL + type.toString().toLowerCase(Locale.ENGLISH) + - JSON_FORMAT); - - // remote request - getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - - int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); - - if (status == HttpStatus.SC_OK) { - String response = getMethod.getResponseBodyAsString(); - - // Parse the response - JSONObject respJSON = new JSONObject(response); - JSONArray templates = respJSON.getJSONObject(NODE_OCS).getJSONArray(NODE_DATA); - - ArrayList templateArray = new ArrayList<>(); - - for (int i = 0; i < templates.length(); i++) { - JSONObject templateObject = templates.getJSONObject(i); - - templateArray.add(new Template(templateObject.getLong("id"), - templateObject.getString("name"), - templateObject.optString("preview"), - Template.Type.parse(templateObject.getString("type") - .toUpperCase(Locale.ROOT)), - templateObject.getString("extension"))); - } - - result = new RemoteOperationResult(true, getMethod); - result.setData(templateArray); - } else { - result = new RemoteOperationResult(false, getMethod); - client.exhaustResponse(getMethod.getResponseBodyAsStream()); - } - } catch (Exception e) { - result = new RemoteOperationResult(e); - Log_OC.e(TAG, "Get templates for typ " + type + " failed: " + result.getLogMessage(), - result.getException()); - } finally { - if (getMethod != null) { - getMethod.releaseConnection(); - } - } - return result; - } -} diff --git a/app/src/main/java/com/owncloud/android/files/StreamMediaFileOperation.java b/app/src/main/java/com/owncloud/android/files/StreamMediaFileOperation.java deleted file mode 100644 index 30fe36d6191b..000000000000 --- a/app/src/main/java/com/owncloud/android/files/StreamMediaFileOperation.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2018 Tobias Kaminsky - * Copyright (C) 2018 Nextcloud GmbH. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package com.owncloud.android.files; - -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.utils.Log_OC; - -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.Utf8PostMethod; -import org.json.JSONObject; - -import java.util.ArrayList; - -public class StreamMediaFileOperation extends RemoteOperation { - private static final String TAG = StreamMediaFileOperation.class.getSimpleName(); - private static final int SYNC_READ_TIMEOUT = 40000; - private static final int SYNC_CONNECTION_TIMEOUT = 5000; - private static final String STREAM_MEDIA_URL = "/ocs/v2.php/apps/dav/api/v1/direct"; - - private final long fileID; - - // JSON node names - private static final String NODE_OCS = "ocs"; - private static final String NODE_DATA = "data"; - private static final String NODE_URL = "url"; - private static final String JSON_FORMAT = "?format=json"; - - public StreamMediaFileOperation(long fileID) { - this.fileID = fileID; - } - - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result; - Utf8PostMethod postMethod = null; - - try { - postMethod = new Utf8PostMethod(client.getBaseUri() + STREAM_MEDIA_URL + JSON_FORMAT); - postMethod.setParameter("fileId", String.valueOf(fileID)); - - // remote request - postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - - int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); - - if (status == HttpStatus.SC_OK) { - String response = postMethod.getResponseBodyAsString(); - - // Parse the response - JSONObject respJSON = new JSONObject(response); - String url = respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA).getString(NODE_URL); - - result = new RemoteOperationResult(true, postMethod); - ArrayList urlArray = new ArrayList<>(); - urlArray.add(url); - result.setData(urlArray); - } else { - result = new RemoteOperationResult(false, postMethod); - client.exhaustResponse(postMethod.getResponseBodyAsStream()); - } - } catch (Exception e) { - result = new RemoteOperationResult(e); - Log_OC.e(TAG, "Get stream url for file with id " + fileID + " failed: " + result.getLogMessage(), - result.getException()); - } finally { - if (postMethod != null) { - postMethod.releaseConnection(); - } - } - return result; - } -} diff --git a/app/src/main/java/com/owncloud/android/operations/CheckCurrentCredentialsOperation.java b/app/src/main/java/com/owncloud/android/operations/CheckCurrentCredentialsOperation.java index dc2e8695fd5f..d539150a3397 100644 --- a/app/src/main/java/com/owncloud/android/operations/CheckCurrentCredentialsOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/CheckCurrentCredentialsOperation.java @@ -24,7 +24,6 @@ import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation; import com.owncloud.android.operations.common.SyncOperation; @@ -52,8 +51,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { "Account to validate is not the account connected to!") ); } else { - RemoteOperation check = new ExistenceCheckRemoteOperation(OCFile.ROOT_PATH, false); - result = check.execute(client); + result = new ExistenceCheckRemoteOperation(OCFile.ROOT_PATH, false).execute(client); ArrayList data = new ArrayList<>(); data.add(user.toPlatformAccount()); result.setData(data); diff --git a/app/src/main/java/com/owncloud/android/operations/CommentFileOperation.java b/app/src/main/java/com/owncloud/android/operations/CommentFileOperation.java deleted file mode 100644 index 3878a5db4c70..000000000000 --- a/app/src/main/java/com/owncloud/android/operations/CommentFileOperation.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2018 Tobias Kaminsky - * Copyright (C) 2018 Nextcloud GmbH. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.owncloud.android.operations; - -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.lib.resources.comments.CommentFileRemoteOperation; - -/** - * Comment file - */ -public class CommentFileOperation extends RemoteOperation { - - private final String message; - private final long fileId; - - /** - * Constructor - * - * @param message Comment to store - */ - public CommentFileOperation(String message, long fileId) { - this.message = message; - this.fileId = fileId; - } - - /** - * Performs the operation. - * - * @param client Client object to communicate with the remote ownCloud server. - */ - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result = new CommentFileRemoteOperation(message, fileId).execute(client); - - if (!result.isSuccess()) { - Log_OC.e(this, "File with Id " + fileId + " could not be commented"); - } - - return result; - } -} diff --git a/app/src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java b/app/src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java index c15c8f8fef2d..61d420b0e342 100644 --- a/app/src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java @@ -25,7 +25,7 @@ import android.text.TextUtils; import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.RemoteOperation; +import com.owncloud.android.lib.common.operations.LegacyRemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation; @@ -46,7 +46,7 @@ * #onRemoteOperationFinish(RemoteOperation, RemoteOperationResult)} returns in * {@link RemoteOperationResult#getData()} a value of {@link AuthenticationMethod}. */ -public class DetectAuthenticationMethodOperation extends RemoteOperation { +public class DetectAuthenticationMethodOperation extends LegacyRemoteOperation { private static final String TAG = DetectAuthenticationMethodOperation.class.getSimpleName(); @@ -84,7 +84,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; AuthenticationMethod authMethod = AuthenticationMethod.UNKNOWN; - RemoteOperation operation = new ExistenceCheckRemoteOperation("", mContext, false); + LegacyRemoteOperation operation = new ExistenceCheckRemoteOperation("", mContext, false); client.clearCredentials(); client.setFollowRedirects(false); diff --git a/app/src/main/java/com/owncloud/android/operations/DownloadFileOperation.java b/app/src/main/java/com/owncloud/android/operations/DownloadFileOperation.java index ff1a682b5d52..488a6389cdb7 100644 --- a/app/src/main/java/com/owncloud/android/operations/DownloadFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/DownloadFileOperation.java @@ -31,8 +31,8 @@ import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; +import com.owncloud.android.lib.common.operations.LegacyRemoteOperation; import com.owncloud.android.lib.common.operations.OperationCancelledException; -import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.files.DownloadFileRemoteOperation; @@ -50,7 +50,7 @@ /** * Remote DownloadOperation performing the download of a file to an ownCloud server */ -public class DownloadFileOperation extends RemoteOperation { +public class DownloadFileOperation extends LegacyRemoteOperation { private static final String TAG = DownloadFileOperation.class.getSimpleName(); private User user; diff --git a/app/src/main/java/com/owncloud/android/operations/GetCapabilitiesOperation.java b/app/src/main/java/com/owncloud/android/operations/GetCapabilitiesOperation.java index 3957c7f1f81c..b85a5c08aa22 100644 --- a/app/src/main/java/com/owncloud/android/operations/GetCapabilitiesOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/GetCapabilitiesOperation.java @@ -19,25 +19,28 @@ */ package com.owncloud.android.operations; +import com.nextcloud.common.NextcloudClient; import com.owncloud.android.datamodel.FileDataStorageManager; -import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.status.GetCapabilitiesRemoteOperation; import com.owncloud.android.lib.resources.status.OCCapability; -import com.owncloud.android.operations.common.SyncOperation; +import com.owncloud.android.operations.common.NextcloudSyncOperation; import com.owncloud.android.utils.theme.CapabilityUtils; +import androidx.annotation.NonNull; + /** * Get and save capabilities from the server */ -public class GetCapabilitiesOperation extends SyncOperation { +public class GetCapabilitiesOperation extends NextcloudSyncOperation { public GetCapabilitiesOperation(FileDataStorageManager storageManager) { super(storageManager); } + @NonNull @Override - protected RemoteOperationResult run(OwnCloudClient client) { + public RemoteOperationResult run(@NonNull NextcloudClient client) { final FileDataStorageManager storageManager = getStorageManager(); OCCapability currentCapability = null; @@ -45,7 +48,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { currentCapability = storageManager.getCapability(storageManager.getUser().getAccountName()); } - RemoteOperationResult result = new GetCapabilitiesRemoteOperation(currentCapability).execute(client); + RemoteOperationResult result = new GetCapabilitiesRemoteOperation(currentCapability).execute(client); if (result.isSuccess() && result.getData() != null && result.getData().size() > 0) { diff --git a/app/src/main/java/com/owncloud/android/operations/GetServerInfoOperation.java b/app/src/main/java/com/owncloud/android/operations/GetServerInfoOperation.java index ed96f8aa1d39..f21c0092f0d6 100644 --- a/app/src/main/java/com/owncloud/android/operations/GetServerInfoOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/GetServerInfoOperation.java @@ -25,6 +25,7 @@ import com.owncloud.android.authentication.AuthenticatorUrlUtils; import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.common.operations.LegacyRemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; @@ -43,7 +44,7 @@ * and finds out what authentication method is needed to access files in it. */ -public class GetServerInfoOperation extends RemoteOperation { +public class GetServerInfoOperation extends LegacyRemoteOperation { private static final String TAG = GetServerInfoOperation.class.getSimpleName(); diff --git a/app/src/main/java/com/owncloud/android/operations/GetUserProfileOperation.java b/app/src/main/java/com/owncloud/android/operations/GetUserProfileOperation.java index 67e8507095cd..80accb42ba70 100644 --- a/app/src/main/java/com/owncloud/android/operations/GetUserProfileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/GetUserProfileOperation.java @@ -29,14 +29,16 @@ import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation; -import com.owncloud.android.operations.common.SyncOperation; +import com.owncloud.android.operations.common.NextcloudSyncOperation; + +import androidx.annotation.NonNull; /** * Get and save user's profile from the server. *

* Currently only retrieves the display name. */ -public class GetUserProfileOperation extends SyncOperation { +public class GetUserProfileOperation extends NextcloudSyncOperation { public GetUserProfileOperation(FileDataStorageManager storageManager) { super(storageManager); @@ -53,8 +55,9 @@ public GetUserProfileOperation(FileDataStorageManager storageManager) { * {@link String} with the display name retrieved from the server. * Call {@link RemoteOperationResult#getData()}.get(0) to get it. */ + @NonNull @Override - public RemoteOperationResult run(NextcloudClient client) { + public RemoteOperationResult run(@NonNull NextcloudClient client) { // get display name RemoteOperationResult result = new GetUserInfoRemoteOperation().execute(client); diff --git a/app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java b/app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java index b0a9749c1f3e..b4581fca3316 100644 --- a/app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java @@ -37,7 +37,7 @@ import com.owncloud.android.lib.common.OwnCloudClientFactory; import com.owncloud.android.lib.common.UserInfo; import com.owncloud.android.lib.common.accounts.AccountUtils; -import com.owncloud.android.lib.common.operations.RemoteOperation; +import com.owncloud.android.lib.common.operations.LegacyRemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.common.utils.Log_OC; @@ -47,6 +47,7 @@ import com.owncloud.android.lib.resources.shares.GetSharesForFileRemoteOperation; import com.owncloud.android.lib.resources.shares.OCShare; import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.lib.resources.status.OCCapability; import com.owncloud.android.lib.resources.users.GetPredefinedStatusesRemoteOperation; import com.owncloud.android.lib.resources.users.PredefinedStatus; import com.owncloud.android.syncadapter.FileSyncAdapter; @@ -79,7 +80,7 @@ * Does NOT enter in the child folders to synchronize their contents also. */ @SuppressWarnings("PMD.AvoidDuplicateLiterals") -public class RefreshFolderOperation extends RemoteOperation { +public class RefreshFolderOperation extends LegacyRemoteOperation { private static final String TAG = RefreshFolderOperation.class.getSimpleName(); @@ -301,7 +302,7 @@ private void updateCapabilities() { String oldDirectEditingEtag = arbitraryDataProvider.getValue(user, ArbitraryDataProvider.DIRECT_EDITING_ETAG); - RemoteOperationResult result = new GetCapabilitiesOperation(mStorageManager).execute(mContext); + RemoteOperationResult result = new GetCapabilitiesOperation(mStorageManager).execute(clientNew); if (result.isSuccess()) { String newDirectEditingEtag = mStorageManager.getCapability(user.getAccountName()).getDirectEditingEtag(); diff --git a/app/src/main/java/com/owncloud/android/operations/RemoveFileOperation.java b/app/src/main/java/com/owncloud/android/operations/RemoveFileOperation.java index e052aea4008f..9fc24f88fb1b 100644 --- a/app/src/main/java/com/owncloud/android/operations/RemoveFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/RemoveFileOperation.java @@ -29,7 +29,7 @@ import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.datamodel.ThumbnailsCacheManager; import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.RemoteOperation; +import com.owncloud.android.lib.common.operations.LegacyRemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation; @@ -92,7 +92,7 @@ public boolean isInBackground() { @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; - RemoteOperation operation; + LegacyRemoteOperation operation; if (MimeTypeUtil.isImage(fileToRemove.getMimeType())) { // store resized image diff --git a/app/src/main/java/com/owncloud/android/operations/RemoveRemoteEncryptedFileOperation.java b/app/src/main/java/com/owncloud/android/operations/RemoveRemoteEncryptedFileOperation.java index 4095a1ccb2c2..6a9e023a063d 100644 --- a/app/src/main/java/com/owncloud/android/operations/RemoveRemoteEncryptedFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/RemoveRemoteEncryptedFileOperation.java @@ -30,7 +30,7 @@ import com.owncloud.android.datamodel.DecryptedFolderMetadata; import com.owncloud.android.datamodel.EncryptedFolderMetadata; import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.RemoteOperation; +import com.owncloud.android.lib.common.operations.LegacyRemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.e2ee.GetMetadataRemoteOperation; @@ -57,7 +57,7 @@ /** * Remote operation performing the removal of a remote encrypted file or folder */ -public class RemoveRemoteEncryptedFileOperation extends RemoteOperation { +public class RemoveRemoteEncryptedFileOperation extends LegacyRemoteOperation { private static final String TAG = RemoveRemoteEncryptedFileOperation.class.getSimpleName(); private static final int REMOVE_READ_TIMEOUT = 30000; diff --git a/app/src/main/java/com/owncloud/android/operations/RichDocumentsCreateAssetOperation.java b/app/src/main/java/com/owncloud/android/operations/RichDocumentsCreateAssetOperation.java deleted file mode 100644 index 8b69d03399ae..000000000000 --- a/app/src/main/java/com/owncloud/android/operations/RichDocumentsCreateAssetOperation.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2018 Tobias Kaminsky - * Copyright (C) 2018 Nextcloud GmbH. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package com.owncloud.android.operations; - -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.utils.Log_OC; - -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.Utf8PostMethod; -import org.json.JSONObject; - -/** - * Create asset for RichDocuments app from file, which is already stored on Nextcloud server - */ - -public class RichDocumentsCreateAssetOperation extends RemoteOperation { - private static final String TAG = RichDocumentsCreateAssetOperation.class.getSimpleName(); - private static final int SYNC_READ_TIMEOUT = 40000; - private static final int SYNC_CONNECTION_TIMEOUT = 5000; - private static final String ASSET_URL = "/index.php/apps/richdocuments/assets"; - - private static final String NODE_URL = "url"; - private static final String PARAMETER_PATH = "path"; - private static final String PARAMETER_FORMAT = "format"; - private static final String PARAMETER_FORMAT_VALUE = "json"; - - private String path; - - public RichDocumentsCreateAssetOperation(String path) { - this.path = path; - } - - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result; - Utf8PostMethod postMethod = null; - - try { - postMethod = new Utf8PostMethod(client.getBaseUri() + ASSET_URL); - postMethod.setParameter(PARAMETER_PATH, path); - postMethod.setParameter(PARAMETER_FORMAT, PARAMETER_FORMAT_VALUE); - - // remote request - postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - - int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); - - if (status == HttpStatus.SC_OK) { - String response = postMethod.getResponseBodyAsString(); - - // Parse the response - JSONObject respJSON = new JSONObject(response); - String url = respJSON.getString(NODE_URL); - - result = new RemoteOperationResult(true, postMethod); - result.setSingleData(url); - } else { - result = new RemoteOperationResult(false, postMethod); - client.exhaustResponse(postMethod.getResponseBodyAsStream()); - } - } catch (Exception e) { - result = new RemoteOperationResult(e); - Log_OC.e(TAG, "Create asset for richdocuments with path " + path + " failed: " + result.getLogMessage(), - result.getException()); - } finally { - if (postMethod != null) { - postMethod.releaseConnection(); - } - } - return result; - } -} diff --git a/app/src/main/java/com/owncloud/android/operations/RichDocumentsUrlOperation.java b/app/src/main/java/com/owncloud/android/operations/RichDocumentsUrlOperation.java deleted file mode 100644 index 2fb2edcfa674..000000000000 --- a/app/src/main/java/com/owncloud/android/operations/RichDocumentsUrlOperation.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2018 Tobias Kaminsky - * Copyright (C) 2018 Nextcloud GmbH. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package com.owncloud.android.operations; - -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.utils.NextcloudServer; - -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.Utf8PostMethod; -import org.json.JSONObject; - -/** - * Edit a file with Richdocuments. Returns URL which can be shown in WebView. - */ -public class RichDocumentsUrlOperation extends RemoteOperation { - - /** - * TODO move to library - */ - - private static final String TAG = RichDocumentsUrlOperation.class.getSimpleName(); - private static final int SYNC_READ_TIMEOUT = 40000; - private static final int SYNC_CONNECTION_TIMEOUT = 5000; - private static final String DOCUMENT_URL = "/ocs/v2.php/apps/richdocuments/api/v1/document"; - private static final String FILE_ID = "fileId"; - - // JSON node names - private static final String NODE_OCS = "ocs"; - private static final String NODE_DATA = "data"; - private static final String NODE_URL = "url"; - private static final String JSON_FORMAT = "?format=json"; - - private final long fileId; - - public RichDocumentsUrlOperation(long fileID) { - this.fileId = fileID; - } - - @NextcloudServer(max = 18) - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result; - Utf8PostMethod postMethod = null; - - try { - postMethod = new Utf8PostMethod(client.getBaseUri() + DOCUMENT_URL + JSON_FORMAT); - postMethod.setParameter(FILE_ID, String.valueOf(fileId)); - - // remote request - postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - - int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); - - if (status == HttpStatus.SC_OK) { - String response = postMethod.getResponseBodyAsString(); - - // Parse the response - JSONObject respJSON = new JSONObject(response); - String url = respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA).getString(NODE_URL); - - result = new RemoteOperationResult(true, postMethod); - result.setSingleData(url); - } else { - result = new RemoteOperationResult(false, postMethod); - client.exhaustResponse(postMethod.getResponseBodyAsStream()); - } - } catch (Exception e) { - result = new RemoteOperationResult(e); - Log_OC.e(TAG, "Get rich document url for file with id " + fileId + " failed: " + result.getLogMessage(), - result.getException()); - } finally { - if (postMethod != null) { - postMethod.releaseConnection(); - } - } - return result; - } -} diff --git a/app/src/main/java/com/owncloud/android/operations/UpdateNoteForShareOperation.java b/app/src/main/java/com/owncloud/android/operations/UpdateNoteForShareOperation.java index 0f30e272de9f..b823ead47e8e 100644 --- a/app/src/main/java/com/owncloud/android/operations/UpdateNoteForShareOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/UpdateNoteForShareOperation.java @@ -23,13 +23,14 @@ import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.shares.GetShareRemoteOperation; import com.owncloud.android.lib.resources.shares.OCShare; import com.owncloud.android.lib.resources.shares.UpdateShareRemoteOperation; import com.owncloud.android.operations.common.SyncOperation; +import java.util.List; + /** * Updates a note of a private share. @@ -47,21 +48,20 @@ public UpdateNoteForShareOperation(long shareId, String note, FileDataStorageMan } @Override - protected RemoteOperationResult run(OwnCloudClient client) { + protected RemoteOperationResult> run(OwnCloudClient client) { OCShare share = getStorageManager().getShareById(shareId); if (share == null) { - return new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND); + return new RemoteOperationResult<>(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND); } UpdateShareRemoteOperation updateOperation = new UpdateShareRemoteOperation(share.getRemoteId()); updateOperation.setNote(note); - RemoteOperationResult result = updateOperation.execute(client); + RemoteOperationResult> result = updateOperation.execute(client); if (result.isSuccess()) { - RemoteOperation getShareOp = new GetShareRemoteOperation(share.getRemoteId()); - result = getShareOp.execute(client); + result = new GetShareRemoteOperation(share.getRemoteId()).execute(client); if (result.isSuccess()) { getStorageManager().saveShare((OCShare) result.getData().get(0)); } diff --git a/app/src/main/java/com/owncloud/android/operations/UpdateOCVersionOperation.java b/app/src/main/java/com/owncloud/android/operations/UpdateOCVersionOperation.java index 3357db2c87cb..5f38afa1f7ac 100644 --- a/app/src/main/java/com/owncloud/android/operations/UpdateOCVersionOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/UpdateOCVersionOperation.java @@ -20,14 +20,13 @@ package com.owncloud.android.operations; -import android.accounts.Account; import android.accounts.AccountManager; import android.content.Context; import com.nextcloud.client.account.User; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.accounts.AccountUtils.Constants; -import com.owncloud.android.lib.common.operations.RemoteOperation; +import com.owncloud.android.lib.common.operations.LegacyRemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.common.utils.Log_OC; @@ -42,7 +41,7 @@ /** * Remote operation that checks the version of an ownCloud server and stores it locally */ -public class UpdateOCVersionOperation extends RemoteOperation { +public class UpdateOCVersionOperation extends LegacyRemoteOperation { private static final String TAG = UpdateOCVersionOperation.class.getSimpleName(); diff --git a/app/src/main/java/com/owncloud/android/operations/UpdateShareInfoOperation.java b/app/src/main/java/com/owncloud/android/operations/UpdateShareInfoOperation.java index 580cfc7f2b56..e5b24620b886 100644 --- a/app/src/main/java/com/owncloud/android/operations/UpdateShareInfoOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/UpdateShareInfoOperation.java @@ -25,7 +25,6 @@ import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.shares.GetShareRemoteOperation; import com.owncloud.android.lib.resources.shares.OCShare; @@ -108,8 +107,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = updateOp.execute(client); if (result.isSuccess()) { - RemoteOperation getShareOp = new GetShareRemoteOperation(share.getRemoteId()); - result = getShareOp.execute(client); + result = new GetShareRemoteOperation(share.getRemoteId()).execute(client); //only update the share in storage if shareId is available //this will be triggered by editing existing share diff --git a/app/src/main/java/com/owncloud/android/operations/UpdateSharePermissionsOperation.java b/app/src/main/java/com/owncloud/android/operations/UpdateSharePermissionsOperation.java index bac5e9a89828..60fc4a6ee6c5 100644 --- a/app/src/main/java/com/owncloud/android/operations/UpdateSharePermissionsOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/UpdateSharePermissionsOperation.java @@ -25,7 +25,6 @@ import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.files.FileUtils; import com.owncloud.android.lib.resources.shares.GetShareRemoteOperation; @@ -79,8 +78,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = updateOp.execute(client); if (result.isSuccess()) { - RemoteOperation getShareOp = new GetShareRemoteOperation(share.getRemoteId()); - result = getShareOp.execute(client); + result = new GetShareRemoteOperation(share.getRemoteId()).execute(client); if (result.isSuccess()) { share = (OCShare) result.getData().get(0); // TODO check permissions are being saved diff --git a/app/src/main/java/com/owncloud/android/operations/UpdateShareViaLinkOperation.java b/app/src/main/java/com/owncloud/android/operations/UpdateShareViaLinkOperation.java index 3d6b5d6f6c61..101a0eb9c3bb 100644 --- a/app/src/main/java/com/owncloud/android/operations/UpdateShareViaLinkOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/UpdateShareViaLinkOperation.java @@ -61,8 +61,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { if (result.isSuccess()) { // Retrieve updated share / save directly with password? -> no; the password is not to be saved - RemoteOperation getShareOp = new GetShareRemoteOperation(publicShare.getRemoteId()); - result = getShareOp.execute(client); + result = new GetShareRemoteOperation(publicShare.getRemoteId()).execute(client); if (result.isSuccess()) { OCShare share = (OCShare) result.getData().get(0); getStorageManager().saveShare(share); diff --git a/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index d0ee77afc191..2f86e969d4ca 100644 --- a/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -46,6 +46,7 @@ import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; import com.owncloud.android.lib.common.network.ProgressiveDataTransfer; +import com.owncloud.android.lib.common.operations.LegacyRemoteOperation; import com.owncloud.android.lib.common.operations.OperationCancelledException; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -382,7 +383,6 @@ public Context getContext() { return mContext; } - @Override @SuppressWarnings("PMD.AvoidDuplicateLiterals") protected RemoteOperationResult run(OwnCloudClient client) { mCancellationRequested.set(false); @@ -1050,7 +1050,7 @@ private void handleSuccessfulUpload(File temporalFile, * will be uploaded. */ private RemoteOperationResult grantFolderExistence(String pathToGrant, OwnCloudClient client) { - RemoteOperation operation = new ExistenceCheckRemoteOperation(pathToGrant, false); + LegacyRemoteOperation operation = new ExistenceCheckRemoteOperation(pathToGrant, false); RemoteOperationResult result = operation.execute(client); if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND && mRemoteFolderToBeCreated) { SyncOperation syncOp = new CreateFolderOperation(pathToGrant, user, getContext(), getStorageManager()); diff --git a/app/src/main/java/com/owncloud/android/operations/common/NextcloudSyncOperation.java b/app/src/main/java/com/owncloud/android/operations/common/NextcloudSyncOperation.java new file mode 100644 index 000000000000..97932304ec77 --- /dev/null +++ b/app/src/main/java/com/owncloud/android/operations/common/NextcloudSyncOperation.java @@ -0,0 +1,44 @@ +/* + * ownCloud Android client application + * + * @author David A. Velasco + * Copyright (C) 2015 ownCloud Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.owncloud.android.operations.common; + +import com.owncloud.android.datamodel.FileDataStorageManager; +import com.owncloud.android.lib.common.operations.NextcloudRemoteOperation; + +import androidx.annotation.NonNull; + + +/** + * Operation which execution involves both interactions with an ownCloud server and with local data in the device. + *

+ * Provides methods to execute the operation both synchronously or asynchronously. + */ +public abstract class NextcloudSyncOperation extends NextcloudRemoteOperation { + private final FileDataStorageManager storageManager; + + public NextcloudSyncOperation(@NonNull FileDataStorageManager storageManager) { + this.storageManager = storageManager; + } + + public FileDataStorageManager getStorageManager() { + return this.storageManager; + } +} diff --git a/app/src/main/java/com/owncloud/android/operations/common/SyncOperation.java b/app/src/main/java/com/owncloud/android/operations/common/SyncOperation.java index 5fbd2c6cd347..babe01b278e2 100644 --- a/app/src/main/java/com/owncloud/android/operations/common/SyncOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/common/SyncOperation.java @@ -23,11 +23,10 @@ import android.content.Context; import android.os.Handler; -import com.nextcloud.common.NextcloudClient; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.common.operations.LegacyRemoteOperation; import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; -import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import androidx.annotation.NonNull; @@ -38,7 +37,8 @@ *

* Provides methods to execute the operation both synchronously or asynchronously. */ -public abstract class SyncOperation extends RemoteOperation { +@Deprecated +public abstract class SyncOperation extends LegacyRemoteOperation { private final FileDataStorageManager storageManager; public SyncOperation(@NonNull FileDataStorageManager storageManager) { @@ -64,10 +64,6 @@ public RemoteOperationResult execute(Context context) { return super.execute(this.storageManager.getUser(), context); } - public RemoteOperationResult execute(@NonNull NextcloudClient client) { - return run(client); - } - /** * Asynchronously executes the remote operation * diff --git a/app/src/main/java/com/owncloud/android/services/OperationsService.java b/app/src/main/java/com/owncloud/android/services/OperationsService.java index ce6ca4697eb2..caec4810e7cb 100644 --- a/app/src/main/java/com/owncloud/android/services/OperationsService.java +++ b/app/src/main/java/com/owncloud/android/services/OperationsService.java @@ -41,6 +41,7 @@ import com.nextcloud.client.account.User; import com.nextcloud.client.account.UserAccountManager; +import com.nextcloud.common.NextcloudClient; import com.nextcloud.java.util.Optional; import com.owncloud.android.MainApp; import com.owncloud.android.datamodel.FileDataStorageManager; @@ -48,6 +49,8 @@ import com.owncloud.android.lib.common.OwnCloudAccount; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; +import com.owncloud.android.lib.common.operations.LegacyRemoteOperation; +import com.owncloud.android.lib.common.operations.NextcloudRemoteOperation; import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -393,6 +396,7 @@ private static class ServiceHandler extends Handler { private RemoteOperation mCurrentOperation; private Target mLastTarget; private OwnCloudClient mOwnCloudClient; + private NextcloudClient nextcloudClient; public ServiceHandler(Looper looper, OperationsService service) { super(looper); @@ -436,10 +440,18 @@ private void nextOperation() { } mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton(). getClientFor(ocAccount, mService); + + nextcloudClient = OwnCloudClientManagerFactory + .getDefaultSingleton() + .getNextcloudClientFor(ocAccount, mService); } /// perform the operation - result = mCurrentOperation.execute(mOwnCloudClient); + if (mCurrentOperation instanceof LegacyRemoteOperation) { + result = ((LegacyRemoteOperation) mCurrentOperation).execute(mOwnCloudClient); + } else { + result = ((NextcloudRemoteOperation) mCurrentOperation).execute(nextcloudClient); + } } catch (AccountsException e) { if (mLastTarget.mAccount == null) { Log_OC.e(TAG, "Error while trying to get authorization for a NULL account", diff --git a/app/src/main/java/com/owncloud/android/ui/activities/data/files/FilesServiceApiImpl.java b/app/src/main/java/com/owncloud/android/ui/activities/data/files/FilesServiceApiImpl.java index 6f5f5d92aa86..992b75bc63ce 100644 --- a/app/src/main/java/com/owncloud/android/ui/activities/data/files/FilesServiceApiImpl.java +++ b/app/src/main/java/com/owncloud/android/ui/activities/data/files/FilesServiceApiImpl.java @@ -32,7 +32,7 @@ import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.RemoteOperation; +import com.owncloud.android.lib.common.operations.LegacyRemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation; @@ -106,13 +106,13 @@ protected Boolean doInBackground(Void... voids) { if (remoteOcFile.isFolder()) { // perform folder synchronization - RemoteOperation synchFolderOp = new RefreshFolderOperation(remoteOcFile, - System.currentTimeMillis(), - false, - true, - baseActivity.getStorageManager(), - baseActivity.getUser().orElseThrow(RuntimeException::new), - context); + LegacyRemoteOperation synchFolderOp = new RefreshFolderOperation(remoteOcFile, + System.currentTimeMillis(), + false, + true, + baseActivity.getStorageManager(), + baseActivity.getUser().orElseThrow(RuntimeException::new), + context); synchFolderOp.execute(ownCloudClient); } } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index 9e37e03e0e00..ba05ffcd0c0c 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -87,6 +87,7 @@ import com.owncloud.android.lib.common.Quota; import com.owncloud.android.lib.common.UserInfo; import com.owncloud.android.lib.common.accounts.ExternalLinksOperation; +import com.owncloud.android.lib.common.operations.NextcloudRemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; @@ -205,12 +206,25 @@ public abstract class DrawerActivity extends ToolbarActivity private ExternalLinksProvider externalLinksProvider; private ArbitraryDataProvider arbitraryDataProvider; + + private NextcloudClient nextcloudClient; @Inject AppPreferences preferences; @Inject ClientFactory clientFactory; + + public DrawerActivity() { + try { + User user = accountManager.getUser(); + nextcloudClient = OwnCloudClientManagerFactory + .getDefaultSingleton() + .getNextcloudClientFor(user.toOwnCloudAccount(), this); + } catch (OperationCanceledException | AuthenticatorException | IOException e) { + Log_OC.e(this, "Error creating account", e); + } + } /** * Initializes the drawer, its content and highlights the menu item with the given id. This method needs to be @@ -865,21 +879,6 @@ private void getAndDisplayUserQuota() { return; } - final Context context = MainApp.getAppContext(); - NextcloudClient nextcloudClient = null; - try { - nextcloudClient = OwnCloudClientManagerFactory - .getDefaultSingleton() - .getNextcloudClientFor(user.toOwnCloudAccount(), - context); - } catch (OperationCanceledException | AuthenticatorException | IOException e) { - Log_OC.e(this, "Error retrieving user quota", e); - } - - if (nextcloudClient == null) { - return; - } - RemoteOperationResult result = new GetUserInfoRemoteOperation().execute(nextcloudClient); if (result.isSuccess() && result.getResultData() != null) { @@ -1182,7 +1181,7 @@ public void fetchExternalLinks(final boolean force) { if ((getCapabilities() == null || getCapabilities().getAccountName().isEmpty()) && getStorageManager() != null) { GetCapabilitiesOperation getCapabilities = new GetCapabilitiesOperation(getStorageManager()); - getCapabilities.execute(getBaseContext()); + getCapabilities.execute(nextcloudClient); } User user = accountManager.getUser(); @@ -1201,8 +1200,8 @@ && getStorageManager() != null) { FileActivity.APP_OPENED_COUNT, "0"); Log_OC.d("ExternalLinks", "update via api"); - RemoteOperation getExternalLinksOperation = new ExternalLinksOperation(); - RemoteOperationResult result = getExternalLinksOperation.execute(user, this); + NextcloudRemoteOperation getExternalLinksOperation = new ExternalLinksOperation(); + RemoteOperationResult result = getExternalLinksOperation.execute(nextcloudClient); if (result.isSuccess() && result.getData() != null) { externalLinksProvider.deleteAllExternalLinks(); diff --git a/app/src/main/java/com/owncloud/android/ui/activity/RichDocumentsEditorWebView.java b/app/src/main/java/com/owncloud/android/ui/activity/RichDocumentsEditorWebView.java index 495445c6a0e4..d4ddbdbd4228 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/RichDocumentsEditorWebView.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/RichDocumentsEditorWebView.java @@ -40,7 +40,7 @@ import com.owncloud.android.lib.common.OwnCloudAccount; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.operations.RichDocumentsCreateAssetOperation; +import com.owncloud.android.lib.resources.files.RichDocumentsCreateAssetRemoteOperation; import com.owncloud.android.ui.asynctasks.PrintAsyncTask; import com.owncloud.android.ui.asynctasks.RichDocumentsLoadUrlTask; import com.owncloud.android.ui.fragment.OCFileListFragment; @@ -118,7 +118,7 @@ private void handleRemoteFile(Intent data) { new Thread(() -> { User user = currentAccountProvider.getUser(); - RichDocumentsCreateAssetOperation operation = new RichDocumentsCreateAssetOperation(file.getRemotePath()); + RichDocumentsCreateAssetRemoteOperation operation = new RichDocumentsCreateAssetRemoteOperation(file.getRemotePath()); RemoteOperationResult result = operation.execute(user, this); if (result.isSuccess()) { diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java index 92478acdcaf0..6fe0323ebd34 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java @@ -60,6 +60,7 @@ import com.owncloud.android.db.ProviderMeta; import com.owncloud.android.lib.common.OwnCloudClientFactory; import com.owncloud.android.lib.common.accounts.AccountUtils; +import com.owncloud.android.lib.common.operations.LegacyRemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.files.model.RemoteFile; @@ -822,13 +823,13 @@ private void parseVirtuals(List objects, SearchType searchType) { // also sync folder content if (ocFile.isFolder()) { long currentSyncTime = System.currentTimeMillis(); - RemoteOperation refreshFolderOperation = new RefreshFolderOperation(ocFile, - currentSyncTime, - true, - false, - mStorageManager, - user, - activity); + LegacyRemoteOperation refreshFolderOperation = new RefreshFolderOperation(ocFile, + currentSyncTime, + true, + false, + mStorageManager, + user, + activity); refreshFolderOperation.execute(user, activity); } } diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/RichDocumentsTemplateAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/RichDocumentsTemplateAdapter.java index 79dbf908b41c..f8feca290e79 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/RichDocumentsTemplateAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/RichDocumentsTemplateAdapter.java @@ -32,8 +32,8 @@ import com.nextcloud.client.network.ClientFactory; import com.owncloud.android.R; import com.owncloud.android.databinding.TemplateButtonBinding; -import com.owncloud.android.datamodel.Template; -import com.owncloud.android.ui.dialog.ChooseRichDocumentsTemplateDialogFragment; +import com.owncloud.android.lib.resources.files.RichDocumentsTemplateType; +import com.owncloud.android.lib.resources.files.Template; import com.owncloud.android.utils.NextcloudServer; import com.owncloud.android.utils.glide.CustomGlideStreamLoader; import com.owncloud.android.utils.theme.ViewThemeUtils; @@ -52,14 +52,14 @@ public class RichDocumentsTemplateAdapter extends RecyclerView.Adapter templateList = new ArrayList<>(); private ClickListener clickListener; private Context context; - private ChooseRichDocumentsTemplateDialogFragment.Type type; + private RichDocumentsTemplateType type; private CurrentAccountProvider currentAccountProvider; private ClientFactory clientFactory; private Template selectedTemplate; private ViewThemeUtils viewThemeUtils; public RichDocumentsTemplateAdapter( - ChooseRichDocumentsTemplateDialogFragment.Type type, + RichDocumentsTemplateType type, ClickListener clickListener, Context context, CurrentAccountProvider currentAccountProvider, diff --git a/app/src/main/java/com/owncloud/android/ui/asynctasks/FetchRemoteFileTask.java b/app/src/main/java/com/owncloud/android/ui/asynctasks/FetchRemoteFileTask.java index b4b9e8f76129..10a8e085e541 100644 --- a/app/src/main/java/com/owncloud/android/ui/asynctasks/FetchRemoteFileTask.java +++ b/app/src/main/java/com/owncloud/android/ui/asynctasks/FetchRemoteFileTask.java @@ -27,7 +27,7 @@ import com.owncloud.android.R; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; -import com.owncloud.android.lib.common.operations.RemoteOperation; +import com.owncloud.android.lib.common.operations.LegacyRemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation; import com.owncloud.android.lib.resources.files.SearchRemoteOperation; @@ -97,13 +97,13 @@ protected String doInBackground(Void... voids) { } long currentSyncTime = System.currentTimeMillis(); - RemoteOperation refreshFolderOperation = new RefreshFolderOperation(toSync, - currentSyncTime, - true, - true, - storageManager, - user, - fileDisplayActivity); + LegacyRemoteOperation refreshFolderOperation = new RefreshFolderOperation(toSync, + currentSyncTime, + true, + true, + storageManager, + user, + fileDisplayActivity); refreshFolderOperation.execute(user, fileDisplayActivity); fileDisplayActivity.setFile(ocFile); diff --git a/app/src/main/java/com/owncloud/android/ui/asynctasks/GetRemoteFileTask.kt b/app/src/main/java/com/owncloud/android/ui/asynctasks/GetRemoteFileTask.kt index 3120f07ce2d6..dc59a68016a7 100644 --- a/app/src/main/java/com/owncloud/android/ui/asynctasks/GetRemoteFileTask.kt +++ b/app/src/main/java/com/owncloud/android/ui/asynctasks/GetRemoteFileTask.kt @@ -24,7 +24,6 @@ import com.nextcloud.client.account.User import com.owncloud.android.datamodel.FileDataStorageManager import com.owncloud.android.datamodel.OCFile import com.owncloud.android.lib.common.OwnCloudClient -import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation import com.owncloud.android.lib.resources.files.model.RemoteFile import com.owncloud.android.operations.RefreshFolderOperation @@ -48,7 +47,7 @@ class GetRemoteFileTask( val remoteOcFile = storageManager.saveFileWithParent(temp, context) if (remoteOcFile.isFolder()) { // perform folder synchronization - val synchFolderOp: RemoteOperation = RefreshFolderOperation( + val synchFolderOp = RefreshFolderOperation( remoteOcFile, System.currentTimeMillis(), false, diff --git a/app/src/main/java/com/owncloud/android/ui/asynctasks/RichDocumentsLoadUrlTask.java b/app/src/main/java/com/owncloud/android/ui/asynctasks/RichDocumentsLoadUrlTask.java index d16b9ff13e50..2f9c7fdb82cc 100644 --- a/app/src/main/java/com/owncloud/android/ui/asynctasks/RichDocumentsLoadUrlTask.java +++ b/app/src/main/java/com/owncloud/android/ui/asynctasks/RichDocumentsLoadUrlTask.java @@ -21,13 +21,12 @@ */ package com.owncloud.android.ui.asynctasks; -import android.accounts.Account; import android.os.AsyncTask; import com.nextcloud.client.account.User; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.operations.RichDocumentsUrlOperation; +import com.owncloud.android.lib.resources.files.RichDocumentsUrlRemoteOperation; import com.owncloud.android.ui.activity.EditorWebView; import java.lang.ref.WeakReference; @@ -52,7 +51,7 @@ protected String doInBackground(Void... voids) { return ""; } - RemoteOperationResult result = new RichDocumentsUrlOperation(file.getLocalId()).execute(user, editorWebView); + RemoteOperationResult result = new RichDocumentsUrlRemoteOperation(file.getLocalId()).execute(user, editorWebView); if (!result.isSuccess()) { return ""; diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/ChooseRichDocumentsTemplateDialogFragment.java b/app/src/main/java/com/owncloud/android/ui/dialog/ChooseRichDocumentsTemplateDialogFragment.java index a8a6f800d2f4..381715e5f474 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/ChooseRichDocumentsTemplateDialogFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/dialog/ChooseRichDocumentsTemplateDialogFragment.java @@ -46,13 +46,14 @@ import com.owncloud.android.databinding.ChooseTemplateBinding; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; -import com.owncloud.android.datamodel.Template; -import com.owncloud.android.files.CreateFileFromTemplateOperation; -import com.owncloud.android.files.FetchTemplateOperation; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.lib.resources.files.CreateFileFromTemplateOperation; +import com.owncloud.android.lib.resources.files.FetchTemplateRemoteOperation; import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation; +import com.owncloud.android.lib.resources.files.RichDocumentsTemplateType; +import com.owncloud.android.lib.resources.files.Template; import com.owncloud.android.lib.resources.files.model.RemoteFile; import com.owncloud.android.ui.activity.ExternalSiteWebView; import com.owncloud.android.ui.activity.RichDocumentsEditorWebView; @@ -102,16 +103,13 @@ public class ChooseRichDocumentsTemplateDialogFragment extends DialogFragment im private Button positiveButton; private DialogFragment waitDialog; - public enum Type { - DOCUMENT, - SPREADSHEET, - PRESENTATION - } + ChooseTemplateBinding binding; @NextcloudServer(max = 18) // will be removed in favor of generic direct editing - public static ChooseRichDocumentsTemplateDialogFragment newInstance(OCFile parentFolder, Type type) { + public static ChooseRichDocumentsTemplateDialogFragment newInstance(OCFile parentFolder, + RichDocumentsTemplateType type) { ChooseRichDocumentsTemplateDialogFragment frag = new ChooseRichDocumentsTemplateDialogFragment(); Bundle args = new Bundle(); args.putParcelable(ARG_PARENT_FOLDER, parentFolder); @@ -175,7 +173,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { viewThemeUtils.material.colorTextInputLayout(binding.filenameContainer); - Type type = Type.valueOf(arguments.getString(ARG_TYPE)); + RichDocumentsTemplateType type = RichDocumentsTemplateType.valueOf(arguments.getString(ARG_TYPE)); new FetchTemplateTask(this, client).execute(type); binding.list.setHasFixedSize(true); @@ -217,12 +215,12 @@ public void afterTextChanged(Editable s) { return builder.create(); } - private int getTitle(Type type) { - if (type == Type.DOCUMENT) { + private int getTitle(RichDocumentsTemplateType type) { + if (type == RichDocumentsTemplateType.DOCUMENT) { return R.string.create_new_document; - } else if (type == Type.SPREADSHEET) { + } else if (type == RichDocumentsTemplateType.SPREADSHEET) { return R.string.create_new_spreadsheet; - } else if (type == Type.PRESENTATION) { + } else if (type == RichDocumentsTemplateType.PRESENTATION) { return R.string.create_new_presentation; } @@ -392,7 +390,7 @@ protected void onPostExecute(String url) { } } - private static class FetchTemplateTask extends AsyncTask> { + private static class FetchTemplateTask extends AsyncTask> { private OwnCloudClient client; private WeakReference chooseTemplateDialogFragmentWeakReference; @@ -403,8 +401,8 @@ private static class FetchTemplateTask extends AsyncTask doInBackground(Type... type) { - FetchTemplateOperation fetchTemplateOperation = new FetchTemplateOperation(type[0]); + protected List