From 3fd76e1e2a1d60d9b686787d9727ea443577a699 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Thu, 4 Mar 2021 09:34:58 +0100 Subject: [PATCH] Use v2 for user info, also switched to typed response Signed-off-by: tobiasKaminsky --- .../nextcloud/client/EndToEndRandomIT.java | 12 +++---- .../account/UserAccountManagerImpl.java | 11 ++++--- .../authentication/AuthenticatorActivity.java | 13 +++----- .../AuthenticatorAsyncTask.java | 31 +++++++++++-------- .../operations/GetUserProfileOperation.java | 11 +++---- .../operations/RefreshFolderOperation.java | 29 +++++++++++------ .../operations/common/SyncOperation.java | 27 +++++++++++----- .../android/ui/activity/DrawerActivity.java | 25 +++++++++++++-- .../android/ui/activity/UserInfoActivity.java | 21 ++++++++++--- .../asynctasks/RetrieveStatusAsyncTask.java | 6 ++-- .../dialog/ChooseTemplateDialogFragment.java | 13 ++++---- .../dialog/SetupEncryptionDialogFragment.java | 8 ++--- 12 files changed, 130 insertions(+), 77 deletions(-) diff --git a/src/androidTest/java/com/nextcloud/client/EndToEndRandomIT.java b/src/androidTest/java/com/nextcloud/client/EndToEndRandomIT.java index e683540f8a..35a7edc544 100644 --- a/src/androidTest/java/com/nextcloud/client/EndToEndRandomIT.java +++ b/src/androidTest/java/com/nextcloud/client/EndToEndRandomIT.java @@ -32,6 +32,7 @@ import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.lib.ocs.responses.PrivateKey; import com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation; import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation; import com.owncloud.android.lib.resources.status.OCCapability; @@ -56,7 +57,6 @@ import org.junit.Test; import java.io.File; import java.io.IOException; import java.security.KeyPair; -import java.security.PrivateKey; import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -504,14 +504,14 @@ public class EndToEndRandomIT extends AbstractOnServerIT { EncryptionUtils.PUBLIC_KEY, publicKeyFromServer); - GetPrivateKeyOperation privateKeyOperation = new GetPrivateKeyOperation(); - RemoteOperationResult privateKeyResult = privateKeyOperation.execute(account, targetContext); + RemoteOperationResult privateKeyResult = new GetPrivateKeyOperation().execute(account, + targetContext); assertTrue(privateKeyResult.isSuccess()); - String privateKey = (String) privateKeyResult.getData().get(0); + PrivateKey privateKey = privateKeyResult.getResultData(); String mnemonic = generateMnemonicString(); - String decryptedPrivateKey = EncryptionUtils.decryptPrivateKey(privateKey, mnemonic); + String decryptedPrivateKey = EncryptionUtils.decryptPrivateKey(privateKey.getKey(), mnemonic); arbitraryDataProvider.storeOrUpdateKeyValue(account.name, EncryptionUtils.PRIVATE_KEY, decryptedPrivateKey); @@ -544,7 +544,7 @@ public class EndToEndRandomIT extends AbstractOnServerIT { throw new Exception("failed to send CSR", result.getException()); } - PrivateKey privateKey = keyPair.getPrivate(); + java.security.PrivateKey privateKey = keyPair.getPrivate(); String privateKeyString = EncryptionUtils.encodeBytesToBase64String(privateKey.getEncoded()); String privatePemKeyString = EncryptionUtils.privateKeyToPEM(privateKey); String encryptedPrivateKey = EncryptionUtils.encryptPrivateKey(privatePemKeyString, diff --git a/src/main/java/com/nextcloud/client/account/UserAccountManagerImpl.java b/src/main/java/com/nextcloud/client/account/UserAccountManagerImpl.java index 7937162985..21e08d09e4 100644 --- a/src/main/java/com/nextcloud/client/account/UserAccountManagerImpl.java +++ b/src/main/java/com/nextcloud/client/account/UserAccountManagerImpl.java @@ -31,13 +31,13 @@ import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.text.TextUtils; +import com.nextcloud.common.NextcloudClient; import com.nextcloud.java.util.Optional; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.datamodel.ArbitraryDataProvider; import com.owncloud.android.datamodel.OCFile; 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.UserInfo; import com.owncloud.android.lib.common.accounts.AccountUtils; @@ -361,13 +361,14 @@ public class UserAccountManagerImpl implements UserAccountManager { // add userId try { OwnCloudAccount ocAccount = new OwnCloudAccount(account, context); - OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton() - .getClientFor(ocAccount, context); + NextcloudClient nextcloudClient = OwnCloudClientManagerFactory + .getDefaultSingleton() + .getNextcloudClientFor(ocAccount, context); - RemoteOperationResult result = remoteUserNameOperation.execute(client); + RemoteOperationResult result = remoteUserNameOperation.execute(nextcloudClient); if (result.isSuccess()) { - UserInfo userInfo = (UserInfo) result.getData().get(0); + UserInfo userInfo = result.getResultData(); userId = userInfo.id; displayName = userInfo.displayName; } else { diff --git a/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java index 87c57562c8..c8bc8786b7 100644 --- a/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -124,7 +124,6 @@ import com.owncloud.android.utils.ErrorMessageAdapter; import com.owncloud.android.utils.PermissionUtil; import com.owncloud.android.utils.theme.ThemeDrawableUtils; import com.owncloud.android.utils.theme.ThemeToolbarUtils; -import com.owncloud.android.utils.theme.ThemeUtils; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -133,7 +132,6 @@ import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; -import java.util.ArrayList; import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -835,7 +833,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } } - private void onGetUserNameFinish(RemoteOperationResult result) { + private void onGetUserNameFinish(RemoteOperationResult result) { mWaitingForOpId = Long.MAX_VALUE; if (result.isSuccess()) { boolean success = false; @@ -1105,7 +1103,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity * @param result Result of the operation. */ @Override - public void onAuthenticatorTaskCallback(RemoteOperationResult result) { + public void onAuthenticatorTaskCallback(RemoteOperationResult result) { mWaitingForOpId = Long.MAX_VALUE; dismissWaitingDialog(); mAsyncTask = null; @@ -1230,7 +1228,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity */ @SuppressFBWarnings("DMI") @SuppressLint("TrulyRandom") - protected boolean createAccount(RemoteOperationResult authResult) { + protected boolean createAccount(RemoteOperationResult authResult) { String accountType = MainApp.getAccountType(this); // create and save new ownCloud account @@ -1281,13 +1279,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mAccountMgr.setUserData(mAccount, Constants.KEY_OC_VERSION, mServerInfo.mVersion.getVersion()); mAccountMgr.setUserData(mAccount, Constants.KEY_OC_BASE_URL, mServerInfo.mBaseUrl); - ArrayList authResultData = authResult.getData(); - if (authResultData == null || authResultData.size() == 0) { + UserInfo userInfo = authResult.getResultData(); + if (userInfo == null) { Log_OC.e(this, "Could not read user data!"); return false; } - UserInfo userInfo = (UserInfo) authResultData.get(0); mAccountMgr.setUserData(mAccount, Constants.KEY_DISPLAY_NAME, userInfo.getDisplayName()); mAccountMgr.setUserData(mAccount, Constants.KEY_USER_ID, userInfo.getId()); mAccountMgr.setUserData(mAccount, diff --git a/src/main/java/com/owncloud/android/authentication/AuthenticatorAsyncTask.java b/src/main/java/com/owncloud/android/authentication/AuthenticatorAsyncTask.java index 071c64a258..210f598569 100644 --- a/src/main/java/com/owncloud/android/authentication/AuthenticatorAsyncTask.java +++ b/src/main/java/com/owncloud/android/authentication/AuthenticatorAsyncTask.java @@ -24,9 +24,11 @@ import android.content.Context; import android.net.Uri; import android.os.AsyncTask; +import com.nextcloud.common.NextcloudClient; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClientFactory; import com.owncloud.android.lib.common.OwnCloudCredentials; +import com.owncloud.android.lib.common.UserInfo; import com.owncloud.android.lib.common.network.RedirectionPath; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation; @@ -40,7 +42,7 @@ import static com.owncloud.android.datamodel.OCFile.ROOT_PATH; /** * Async Task to verify the credentials of a user */ -public class AuthenticatorAsyncTask extends AsyncTask { +public class AuthenticatorAsyncTask extends AsyncTask> { private static final boolean SUCCESS_IF_ABSENT = false; @@ -49,21 +51,26 @@ public class AuthenticatorAsyncTask extends AsyncTask(activity.getApplicationContext()); - mListener = new WeakReference<>((OnAuthenticatorTaskListener)activity); + mListener = new WeakReference<>((OnAuthenticatorTaskListener) activity); } @Override - protected RemoteOperationResult doInBackground(Object... params) { + protected RemoteOperationResult doInBackground(Object... params) { - RemoteOperationResult result; + RemoteOperationResult result; if (params != null && params.length == 2 && mWeakContext.get() != null) { - String url = (String)params[0]; + String url = (String) params[0]; Context context = mWeakContext.get(); - OwnCloudCredentials credentials = (OwnCloudCredentials)params[1]; + OwnCloudCredentials credentials = (OwnCloudCredentials) params[1]; // Client Uri uri = Uri.parse(url); OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(uri, context, true); + NextcloudClient nextcloudClient = OwnCloudClientFactory.createNextcloudClient(uri, + credentials.getUsername(), + credentials.toOkHttpCredentials(), + context, + true); client.setCredentials(credentials); // Operation - try credentials @@ -79,7 +86,7 @@ public class AuthenticatorAsyncTask extends AsyncTask result) { - if (result!= null) - { + if (result != null) { OnAuthenticatorTaskListener listener = mListener.get(); - if (listener!= null) - { + if (listener != null) { listener.onAuthenticatorTaskCallback(result); } } @@ -106,6 +111,6 @@ public class AuthenticatorAsyncTask extends AsyncTask result); } } diff --git a/src/main/java/com/owncloud/android/operations/GetUserProfileOperation.java b/src/main/java/com/owncloud/android/operations/GetUserProfileOperation.java index d999016011..6da900c322 100644 --- a/src/main/java/com/owncloud/android/operations/GetUserProfileOperation.java +++ b/src/main/java/com/owncloud/android/operations/GetUserProfileOperation.java @@ -22,8 +22,8 @@ package com.owncloud.android.operations; import android.accounts.Account; import android.accounts.AccountManager; +import com.nextcloud.common.NextcloudClient; import com.owncloud.android.MainApp; -import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.UserInfo; import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -44,21 +44,20 @@ public class GetUserProfileOperation extends SyncOperation { * * Stored account is implicit in {@link #getStorageManager()}. * - * @return Result of the operation. If successful, includes an instance of + * @return Result of the operation. If successful, includes an instance of * {@link String} with the display name retrieved from the server. * Call {@link RemoteOperationResult#getData()}.get(0) to get it. */ @Override - protected RemoteOperationResult run(OwnCloudClient client) { + public RemoteOperationResult run(NextcloudClient client) { // get display name - GetUserInfoRemoteOperation getDisplayName = new GetUserInfoRemoteOperation(); - RemoteOperationResult result = getDisplayName.execute(client); + RemoteOperationResult result = new GetUserInfoRemoteOperation().execute(client); if (result.isSuccess()) { // store display name with account data AccountManager accountManager = AccountManager.get(MainApp.getAppContext()); - UserInfo userInfo = (UserInfo) result.getData().get(0); + UserInfo userInfo = result.getResultData(); Account storedAccount = getStorageManager().getAccount(); accountManager.setUserData(storedAccount, AccountUtils.Constants.KEY_DISPLAY_NAME, userInfo.getDisplayName()); } diff --git a/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java b/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java index ee06688cc6..488ac8cd74 100644 --- a/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java +++ b/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java @@ -34,6 +34,7 @@ import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.DirectEditing; import com.owncloud.android.lib.common.OwnCloudClient; 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.RemoteOperationResult; @@ -278,12 +279,18 @@ public class RefreshFolderOperation extends RemoteOperation { } private void updateUserProfile() { - GetUserProfileOperation update = new GetUserProfileOperation(); - RemoteOperationResult result = update.execute(mStorageManager, mContext); - if (!result.isSuccess()) { - Log_OC.w(TAG, "Couldn't update user profile from server"); - } else { - Log_OC.i(TAG, "Got display name: " + result.getData().get(0)); + try { + NextcloudClient nextcloudClient = OwnCloudClientFactory.createNextcloudClient(mAccount, mContext); + + RemoteOperationResult result = new GetUserProfileOperation().execute(nextcloudClient, + mStorageManager); + if (!result.isSuccess()) { + Log_OC.w(TAG, "Couldn't update user profile from server"); + } else { + Log_OC.i(TAG, "Got display name: " + result.getResultData()); + } + } catch (AccountUtils.AccountNotFoundException e) { + Log_OC.e(this, "Error updating profile", e); } } @@ -308,10 +315,11 @@ public class RefreshFolderOperation extends RemoteOperation { } private void updateDirectEditing(ArbitraryDataProvider arbitraryDataProvider, String newDirectEditingEtag) { - RemoteOperationResult result = new DirectEditingObtainRemoteOperation().execute(mAccount, mContext); + RemoteOperationResult result = new DirectEditingObtainRemoteOperation().execute(mAccount, + mContext); if (result.isSuccess()) { - DirectEditing directEditing = (DirectEditing) result.getSingleData(); + DirectEditing directEditing = result.getResultData(); String json = new Gson().toJson(directEditing); arbitraryDataProvider.storeOrUpdateKeyValue(mAccount.name, ArbitraryDataProvider.DIRECT_EDITING, json); } else { @@ -333,10 +341,11 @@ public class RefreshFolderOperation extends RemoteOperation { return; } - RemoteOperationResult result = new GetPredefinedStatusesRemoteOperation().execute(client); + RemoteOperationResult> result = + new GetPredefinedStatusesRemoteOperation().execute(client); if (result.isSuccess()) { - ArrayList predefinedStatuses = (ArrayList) result.getSingleData(); + ArrayList predefinedStatuses = result.getResultData(); String json = new Gson().toJson(predefinedStatuses); arbitraryDataProvider.storeOrUpdateKeyValue(mAccount.name, ArbitraryDataProvider.PREDEFINED_STATUS, json); } else { diff --git a/src/main/java/com/owncloud/android/operations/common/SyncOperation.java b/src/main/java/com/owncloud/android/operations/common/SyncOperation.java index 57096daf52..a7810b60ac 100644 --- a/src/main/java/com/owncloud/android/operations/common/SyncOperation.java +++ b/src/main/java/com/owncloud/android/operations/common/SyncOperation.java @@ -23,17 +23,19 @@ package com.owncloud.android.operations.common; 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.OnRemoteOperationListener; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import androidx.annotation.NonNull; + /** - * Operation which execution involves both interactions with an ownCloud server and - * with local data in the device. - * + * 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 SyncOperation extends RemoteOperation { @@ -74,16 +76,25 @@ public abstract class SyncOperation extends RemoteOperation { * peration. * @param storageManager * @return Result of the operation. - */ - public RemoteOperationResult execute(OwnCloudClient client, + */ + public RemoteOperationResult execute(OwnCloudClient client, FileDataStorageManager storageManager) { if (storageManager == null) { throw new IllegalArgumentException("Trying to execute a sync operation with a " + - "NULL storage manager"); + "NULL storage manager"); } this.storageManager = storageManager; - return super.execute(client); - } + return super.execute(client); + } + + public RemoteOperationResult execute(@NonNull NextcloudClient client, FileDataStorageManager storageManager) { + if (storageManager == null) { + throw new IllegalArgumentException("Trying to execute a sync operation with a NULL storage manager"); + } + this.storageManager = storageManager; + + return run(client); + } /** diff --git a/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index 7ddb8606b0..f8189eddd1 100644 --- a/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -27,6 +27,8 @@ package com.owncloud.android.ui.activity; +import android.accounts.AuthenticatorException; +import android.accounts.OperationCanceledException; import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -55,6 +57,7 @@ import com.nextcloud.client.di.Injectable; import com.nextcloud.client.network.ClientFactory; import com.nextcloud.client.onboarding.FirstRunActivity; import com.nextcloud.client.preferences.AppPreferences; +import com.nextcloud.common.NextcloudClient; import com.nextcloud.java.util.Optional; import com.nextcloud.ui.ChooseAccountDialogFragment; import com.owncloud.android.MainApp; @@ -66,6 +69,7 @@ import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.ExternalLink; import com.owncloud.android.lib.common.ExternalLinkType; +import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; import com.owncloud.android.lib.common.Quota; import com.owncloud.android.lib.common.UserInfo; import com.owncloud.android.lib.common.accounts.ExternalLinksOperation; @@ -99,6 +103,7 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import org.parceler.Parcels; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -731,10 +736,24 @@ public abstract class DrawerActivity extends ToolbarActivity } final Context context = MainApp.getAppContext(); - RemoteOperationResult result = new GetUserInfoRemoteOperation().execute(user.toPlatformAccount(), context); + 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 (result.isSuccess() && result.getData() != null) { - final UserInfo userInfo = (UserInfo) result.getData().get(0); + if (nextcloudClient == null) { + return; + } + + RemoteOperationResult result = new GetUserInfoRemoteOperation().execute(nextcloudClient); + + if (result.isSuccess() && result.getResultData() != null) { + final UserInfo userInfo = result.getResultData(); final Quota quota = userInfo.getQuota(); if (quota != null) { diff --git a/src/main/java/com/owncloud/android/ui/activity/UserInfoActivity.java b/src/main/java/com/owncloud/android/ui/activity/UserInfoActivity.java index ef0a5d435e..84854b68aa 100644 --- a/src/main/java/com/owncloud/android/ui/activity/UserInfoActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/UserInfoActivity.java @@ -48,10 +48,12 @@ import com.bumptech.glide.request.target.SimpleTarget; import com.nextcloud.client.account.User; import com.nextcloud.client.di.Injectable; import com.nextcloud.client.preferences.AppPreferences; +import com.nextcloud.common.NextcloudClient; import com.owncloud.android.R; import com.owncloud.android.databinding.UserInfoLayoutBinding; +import com.owncloud.android.lib.common.OwnCloudClientFactory; import com.owncloud.android.lib.common.UserInfo; -import com.owncloud.android.lib.common.operations.RemoteOperation; +import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation; @@ -318,12 +320,21 @@ public class UserInfoActivity extends DrawerActivity implements Injectable { private void fetchAndSetData() { Thread t = new Thread(() -> { - RemoteOperation getRemoteUserInfoOperation = new GetUserInfoRemoteOperation(); - RemoteOperationResult result = getRemoteUserInfoOperation.execute(user.toPlatformAccount(), this); + NextcloudClient nextcloudClient; + + try { + nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user.toPlatformAccount(), + this); + } catch (AccountUtils.AccountNotFoundException e) { + Log_OC.e(this, "Error retrieving user info", e); + return; + } + + RemoteOperationResult result = new GetUserInfoRemoteOperation().execute(nextcloudClient); if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) { - if (result.isSuccess() && result.getData() != null) { - userInfo = (UserInfo) result.getData().get(0); + if (result.isSuccess() && result.getResultData() != null) { + userInfo = result.getResultData(); runOnUiThread(() -> populateUserInfoUi(userInfo)); } else { diff --git a/src/main/java/com/owncloud/android/ui/asynctasks/RetrieveStatusAsyncTask.java b/src/main/java/com/owncloud/android/ui/asynctasks/RetrieveStatusAsyncTask.java index 3038835c38..4d5745f31f 100644 --- a/src/main/java/com/owncloud/android/ui/asynctasks/RetrieveStatusAsyncTask.java +++ b/src/main/java/com/owncloud/android/ui/asynctasks/RetrieveStatusAsyncTask.java @@ -53,10 +53,11 @@ public class RetrieveStatusAsyncTask extends AsyncTask { protected com.owncloud.android.lib.resources.users.Status doInBackground(Void... voids) { try { NextcloudClient client = clientFactory.createNextcloudClient(user); - RemoteOperationResult result = new GetStatusRemoteOperation().execute(client); + RemoteOperationResult result = + new GetStatusRemoteOperation().execute(client); if (result.isSuccess()) { - return (com.owncloud.android.lib.resources.users.Status) result.getSingleData(); + return result.getResultData(); } else { return new com.owncloud.android.lib.resources.users.Status(StatusType.OFFLINE, "", "", -1); } @@ -72,6 +73,5 @@ public class RetrieveStatusAsyncTask extends AsyncTask { if (fragment != null && fragment.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) { fragment.setStatus(status, fragment.requireContext()); } - } } diff --git a/src/main/java/com/owncloud/android/ui/dialog/ChooseTemplateDialogFragment.java b/src/main/java/com/owncloud/android/ui/dialog/ChooseTemplateDialogFragment.java index 5630c23e24..70e6d1c1fe 100644 --- a/src/main/java/com/owncloud/android/ui/dialog/ChooseTemplateDialogFragment.java +++ b/src/main/java/com/owncloud/android/ui/dialog/ChooseTemplateDialogFragment.java @@ -307,7 +307,7 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements View try { OwnCloudClient client = clientFactory.create(user); - RemoteOperationResult result = + RemoteOperationResult result = new DirectEditingCreateFileRemoteOperation(path, creator.getEditor(), creator.getId(), @@ -339,7 +339,7 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements View storageManager.saveFile(temp); file = storageManager.getFileByPath(path); - return result.getData().get(0).toString(); + return result.getResultData(); } catch (ClientFactory.CreationException e) { Log_OC.e(TAG, "Error creating file from template!", e); @@ -392,15 +392,16 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements View try { OwnCloudClient client = clientFactory.create(user); - RemoteOperationResult result = new DirectEditingObtainListOfTemplatesRemoteOperation(creator.getEditor(), - creator.getId()) - .execute(client); + RemoteOperationResult result = + new DirectEditingObtainListOfTemplatesRemoteOperation(creator.getEditor(), + creator.getId()) + .execute(client); if (!result.isSuccess()) { return new TemplateList(); } - return (TemplateList) result.getSingleData(); + return result.getResultData(); } catch (ClientFactory.CreationException e) { Log_OC.e(TAG, "Could not fetch template", e); diff --git a/src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.java b/src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.java index c2ed437811..dca88ccc58 100644 --- a/src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.java +++ b/src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.java @@ -258,19 +258,19 @@ public class SetupEncryptionDialogFragment extends DialogFragment { String publicKeyFromServer = (String) publicKeyResult.getData().get(0); arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), EncryptionUtils.PUBLIC_KEY, - publicKeyFromServer); + publicKeyFromServer); } else { return null; } - GetPrivateKeyOperation privateKeyOperation = new GetPrivateKeyOperation(); - RemoteOperationResult privateKeyResult = privateKeyOperation.execute(user.toPlatformAccount(), getContext()); + RemoteOperationResult privateKeyResult = + new GetPrivateKeyOperation().execute(user.toPlatformAccount(), getContext()); if (privateKeyResult.isSuccess()) { Log_OC.d(TAG, "private key successful downloaded for " + user.getAccountName()); keyResult = KEY_EXISTING_USED; - return (String) privateKeyResult.getData().get(0); + return privateKeyResult.getResultData().getKey(); } else { return null; }