mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 09:23:51 +03:00
Use v2 for user info, also switched to typed response
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
parent
b160958a95
commit
3fd76e1e2a
12 changed files with 130 additions and 77 deletions
|
@ -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.accounts.AccountUtils;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
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.e2ee.ToggleEncryptionRemoteOperation;
|
||||||
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation;
|
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation;
|
||||||
import com.owncloud.android.lib.resources.status.OCCapability;
|
import com.owncloud.android.lib.resources.status.OCCapability;
|
||||||
|
@ -56,7 +57,6 @@ import org.junit.Test;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
import java.security.PrivateKey;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -504,14 +504,14 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
|
||||||
EncryptionUtils.PUBLIC_KEY,
|
EncryptionUtils.PUBLIC_KEY,
|
||||||
publicKeyFromServer);
|
publicKeyFromServer);
|
||||||
|
|
||||||
GetPrivateKeyOperation privateKeyOperation = new GetPrivateKeyOperation();
|
RemoteOperationResult<PrivateKey> privateKeyResult = new GetPrivateKeyOperation().execute(account,
|
||||||
RemoteOperationResult privateKeyResult = privateKeyOperation.execute(account, targetContext);
|
targetContext);
|
||||||
assertTrue(privateKeyResult.isSuccess());
|
assertTrue(privateKeyResult.isSuccess());
|
||||||
|
|
||||||
String privateKey = (String) privateKeyResult.getData().get(0);
|
PrivateKey privateKey = privateKeyResult.getResultData();
|
||||||
|
|
||||||
String mnemonic = generateMnemonicString();
|
String mnemonic = generateMnemonicString();
|
||||||
String decryptedPrivateKey = EncryptionUtils.decryptPrivateKey(privateKey, mnemonic);
|
String decryptedPrivateKey = EncryptionUtils.decryptPrivateKey(privateKey.getKey(), mnemonic);
|
||||||
|
|
||||||
arbitraryDataProvider.storeOrUpdateKeyValue(account.name,
|
arbitraryDataProvider.storeOrUpdateKeyValue(account.name,
|
||||||
EncryptionUtils.PRIVATE_KEY, decryptedPrivateKey);
|
EncryptionUtils.PRIVATE_KEY, decryptedPrivateKey);
|
||||||
|
@ -544,7 +544,7 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
|
||||||
throw new Exception("failed to send CSR", result.getException());
|
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 privateKeyString = EncryptionUtils.encodeBytesToBase64String(privateKey.getEncoded());
|
||||||
String privatePemKeyString = EncryptionUtils.privateKeyToPEM(privateKey);
|
String privatePemKeyString = EncryptionUtils.privateKeyToPEM(privateKey);
|
||||||
String encryptedPrivateKey = EncryptionUtils.encryptPrivateKey(privatePemKeyString,
|
String encryptedPrivateKey = EncryptionUtils.encryptPrivateKey(privatePemKeyString,
|
||||||
|
|
|
@ -31,13 +31,13 @@ import android.content.SharedPreferences;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.nextcloud.common.NextcloudClient;
|
||||||
import com.nextcloud.java.util.Optional;
|
import com.nextcloud.java.util.Optional;
|
||||||
import com.owncloud.android.MainApp;
|
import com.owncloud.android.MainApp;
|
||||||
import com.owncloud.android.R;
|
import com.owncloud.android.R;
|
||||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||||
import com.owncloud.android.datamodel.OCFile;
|
import com.owncloud.android.datamodel.OCFile;
|
||||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
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.OwnCloudClientManagerFactory;
|
||||||
import com.owncloud.android.lib.common.UserInfo;
|
import com.owncloud.android.lib.common.UserInfo;
|
||||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||||
|
@ -361,13 +361,14 @@ public class UserAccountManagerImpl implements UserAccountManager {
|
||||||
// add userId
|
// add userId
|
||||||
try {
|
try {
|
||||||
OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
|
OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
|
||||||
OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton()
|
NextcloudClient nextcloudClient = OwnCloudClientManagerFactory
|
||||||
.getClientFor(ocAccount, context);
|
.getDefaultSingleton()
|
||||||
|
.getNextcloudClientFor(ocAccount, context);
|
||||||
|
|
||||||
RemoteOperationResult result = remoteUserNameOperation.execute(client);
|
RemoteOperationResult<UserInfo> result = remoteUserNameOperation.execute(nextcloudClient);
|
||||||
|
|
||||||
if (result.isSuccess()) {
|
if (result.isSuccess()) {
|
||||||
UserInfo userInfo = (UserInfo) result.getData().get(0);
|
UserInfo userInfo = result.getResultData();
|
||||||
userId = userInfo.id;
|
userId = userInfo.id;
|
||||||
displayName = userInfo.displayName;
|
displayName = userInfo.displayName;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -124,7 +124,6 @@ import com.owncloud.android.utils.ErrorMessageAdapter;
|
||||||
import com.owncloud.android.utils.PermissionUtil;
|
import com.owncloud.android.utils.PermissionUtil;
|
||||||
import com.owncloud.android.utils.theme.ThemeDrawableUtils;
|
import com.owncloud.android.utils.theme.ThemeDrawableUtils;
|
||||||
import com.owncloud.android.utils.theme.ThemeToolbarUtils;
|
import com.owncloud.android.utils.theme.ThemeToolbarUtils;
|
||||||
import com.owncloud.android.utils.theme.ThemeUtils;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -133,7 +132,6 @@ import java.security.cert.Certificate;
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.security.cert.CertificateFactory;
|
import java.security.cert.CertificateFactory;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -835,7 +833,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onGetUserNameFinish(RemoteOperationResult result) {
|
private void onGetUserNameFinish(RemoteOperationResult<UserInfo> result) {
|
||||||
mWaitingForOpId = Long.MAX_VALUE;
|
mWaitingForOpId = Long.MAX_VALUE;
|
||||||
if (result.isSuccess()) {
|
if (result.isSuccess()) {
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
@ -1105,7 +1103,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||||
* @param result Result of the operation.
|
* @param result Result of the operation.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onAuthenticatorTaskCallback(RemoteOperationResult result) {
|
public void onAuthenticatorTaskCallback(RemoteOperationResult<UserInfo> result) {
|
||||||
mWaitingForOpId = Long.MAX_VALUE;
|
mWaitingForOpId = Long.MAX_VALUE;
|
||||||
dismissWaitingDialog();
|
dismissWaitingDialog();
|
||||||
mAsyncTask = null;
|
mAsyncTask = null;
|
||||||
|
@ -1230,7 +1228,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||||
*/
|
*/
|
||||||
@SuppressFBWarnings("DMI")
|
@SuppressFBWarnings("DMI")
|
||||||
@SuppressLint("TrulyRandom")
|
@SuppressLint("TrulyRandom")
|
||||||
protected boolean createAccount(RemoteOperationResult authResult) {
|
protected boolean createAccount(RemoteOperationResult<UserInfo> authResult) {
|
||||||
String accountType = MainApp.getAccountType(this);
|
String accountType = MainApp.getAccountType(this);
|
||||||
|
|
||||||
// create and save new ownCloud account
|
// 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_VERSION, mServerInfo.mVersion.getVersion());
|
||||||
mAccountMgr.setUserData(mAccount, Constants.KEY_OC_BASE_URL, mServerInfo.mBaseUrl);
|
mAccountMgr.setUserData(mAccount, Constants.KEY_OC_BASE_URL, mServerInfo.mBaseUrl);
|
||||||
|
|
||||||
ArrayList<Object> authResultData = authResult.getData();
|
UserInfo userInfo = authResult.getResultData();
|
||||||
if (authResultData == null || authResultData.size() == 0) {
|
if (userInfo == null) {
|
||||||
Log_OC.e(this, "Could not read user data!");
|
Log_OC.e(this, "Could not read user data!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserInfo userInfo = (UserInfo) authResultData.get(0);
|
|
||||||
mAccountMgr.setUserData(mAccount, Constants.KEY_DISPLAY_NAME, userInfo.getDisplayName());
|
mAccountMgr.setUserData(mAccount, Constants.KEY_DISPLAY_NAME, userInfo.getDisplayName());
|
||||||
mAccountMgr.setUserData(mAccount, Constants.KEY_USER_ID, userInfo.getId());
|
mAccountMgr.setUserData(mAccount, Constants.KEY_USER_ID, userInfo.getId());
|
||||||
mAccountMgr.setUserData(mAccount,
|
mAccountMgr.setUserData(mAccount,
|
||||||
|
|
|
@ -24,9 +24,11 @@ import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
|
import com.nextcloud.common.NextcloudClient;
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
||||||
import com.owncloud.android.lib.common.OwnCloudCredentials;
|
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.network.RedirectionPath;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
|
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
|
* Async Task to verify the credentials of a user
|
||||||
*/
|
*/
|
||||||
public class AuthenticatorAsyncTask extends AsyncTask<Object, Void, RemoteOperationResult> {
|
public class AuthenticatorAsyncTask extends AsyncTask<Object, Void, RemoteOperationResult<UserInfo>> {
|
||||||
|
|
||||||
private static final boolean SUCCESS_IF_ABSENT = false;
|
private static final boolean SUCCESS_IF_ABSENT = false;
|
||||||
|
|
||||||
|
@ -53,9 +55,9 @@ public class AuthenticatorAsyncTask extends AsyncTask<Object, Void, RemoteOpera
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult doInBackground(Object... params) {
|
protected RemoteOperationResult<UserInfo> doInBackground(Object... params) {
|
||||||
|
|
||||||
RemoteOperationResult result;
|
RemoteOperationResult<UserInfo> result;
|
||||||
if (params != null && params.length == 2 && mWeakContext.get() != null) {
|
if (params != null && params.length == 2 && mWeakContext.get() != null) {
|
||||||
String url = (String) params[0];
|
String url = (String) params[0];
|
||||||
Context context = mWeakContext.get();
|
Context context = mWeakContext.get();
|
||||||
|
@ -64,6 +66,11 @@ public class AuthenticatorAsyncTask extends AsyncTask<Object, Void, RemoteOpera
|
||||||
// Client
|
// Client
|
||||||
Uri uri = Uri.parse(url);
|
Uri uri = Uri.parse(url);
|
||||||
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(uri, context, true);
|
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(uri, context, true);
|
||||||
|
NextcloudClient nextcloudClient = OwnCloudClientFactory.createNextcloudClient(uri,
|
||||||
|
credentials.getUsername(),
|
||||||
|
credentials.toOkHttpCredentials(),
|
||||||
|
context,
|
||||||
|
true);
|
||||||
client.setCredentials(credentials);
|
client.setCredentials(credentials);
|
||||||
|
|
||||||
// Operation - try credentials
|
// Operation - try credentials
|
||||||
|
@ -79,7 +86,7 @@ public class AuthenticatorAsyncTask extends AsyncTask<Object, Void, RemoteOpera
|
||||||
// Operation - get display name
|
// Operation - get display name
|
||||||
if (result.isSuccess()) {
|
if (result.isSuccess()) {
|
||||||
GetUserInfoRemoteOperation remoteUserNameOperation = new GetUserInfoRemoteOperation();
|
GetUserInfoRemoteOperation remoteUserNameOperation = new GetUserInfoRemoteOperation();
|
||||||
result = remoteUserNameOperation.execute(client);
|
result = remoteUserNameOperation.execute(nextcloudClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -90,13 +97,11 @@ public class AuthenticatorAsyncTask extends AsyncTask<Object, Void, RemoteOpera
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(RemoteOperationResult result) {
|
protected void onPostExecute(RemoteOperationResult<UserInfo> result) {
|
||||||
|
|
||||||
if (result!= null)
|
if (result != null) {
|
||||||
{
|
|
||||||
OnAuthenticatorTaskListener listener = mListener.get();
|
OnAuthenticatorTaskListener listener = mListener.get();
|
||||||
if (listener!= null)
|
if (listener != null) {
|
||||||
{
|
|
||||||
listener.onAuthenticatorTaskCallback(result);
|
listener.onAuthenticatorTaskCallback(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,6 +111,6 @@ public class AuthenticatorAsyncTask extends AsyncTask<Object, Void, RemoteOpera
|
||||||
*/
|
*/
|
||||||
public interface OnAuthenticatorTaskListener{
|
public interface OnAuthenticatorTaskListener{
|
||||||
|
|
||||||
void onAuthenticatorTaskCallback(RemoteOperationResult result);
|
void onAuthenticatorTaskCallback(RemoteOperationResult<UserInfo> result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,8 @@ package com.owncloud.android.operations;
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
|
|
||||||
|
import com.nextcloud.common.NextcloudClient;
|
||||||
import com.owncloud.android.MainApp;
|
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.UserInfo;
|
||||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
|
@ -49,16 +49,15 @@ public class GetUserProfileOperation extends SyncOperation {
|
||||||
* Call {@link RemoteOperationResult#getData()}.get(0) to get it.
|
* Call {@link RemoteOperationResult#getData()}.get(0) to get it.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
public RemoteOperationResult<UserInfo> run(NextcloudClient client) {
|
||||||
|
|
||||||
// get display name
|
// get display name
|
||||||
GetUserInfoRemoteOperation getDisplayName = new GetUserInfoRemoteOperation();
|
RemoteOperationResult<UserInfo> result = new GetUserInfoRemoteOperation().execute(client);
|
||||||
RemoteOperationResult result = getDisplayName.execute(client);
|
|
||||||
|
|
||||||
if (result.isSuccess()) {
|
if (result.isSuccess()) {
|
||||||
// store display name with account data
|
// store display name with account data
|
||||||
AccountManager accountManager = AccountManager.get(MainApp.getAppContext());
|
AccountManager accountManager = AccountManager.get(MainApp.getAppContext());
|
||||||
UserInfo userInfo = (UserInfo) result.getData().get(0);
|
UserInfo userInfo = result.getResultData();
|
||||||
Account storedAccount = getStorageManager().getAccount();
|
Account storedAccount = getStorageManager().getAccount();
|
||||||
accountManager.setUserData(storedAccount, AccountUtils.Constants.KEY_DISPLAY_NAME, userInfo.getDisplayName());
|
accountManager.setUserData(storedAccount, AccountUtils.Constants.KEY_DISPLAY_NAME, userInfo.getDisplayName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import com.owncloud.android.datamodel.OCFile;
|
||||||
import com.owncloud.android.lib.common.DirectEditing;
|
import com.owncloud.android.lib.common.DirectEditing;
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
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.accounts.AccountUtils;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
|
@ -278,12 +279,18 @@ public class RefreshFolderOperation extends RemoteOperation {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateUserProfile() {
|
private void updateUserProfile() {
|
||||||
GetUserProfileOperation update = new GetUserProfileOperation();
|
try {
|
||||||
RemoteOperationResult result = update.execute(mStorageManager, mContext);
|
NextcloudClient nextcloudClient = OwnCloudClientFactory.createNextcloudClient(mAccount, mContext);
|
||||||
|
|
||||||
|
RemoteOperationResult<UserInfo> result = new GetUserProfileOperation().execute(nextcloudClient,
|
||||||
|
mStorageManager);
|
||||||
if (!result.isSuccess()) {
|
if (!result.isSuccess()) {
|
||||||
Log_OC.w(TAG, "Couldn't update user profile from server");
|
Log_OC.w(TAG, "Couldn't update user profile from server");
|
||||||
} else {
|
} else {
|
||||||
Log_OC.i(TAG, "Got display name: " + result.getData().get(0));
|
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) {
|
private void updateDirectEditing(ArbitraryDataProvider arbitraryDataProvider, String newDirectEditingEtag) {
|
||||||
RemoteOperationResult result = new DirectEditingObtainRemoteOperation().execute(mAccount, mContext);
|
RemoteOperationResult<DirectEditing> result = new DirectEditingObtainRemoteOperation().execute(mAccount,
|
||||||
|
mContext);
|
||||||
|
|
||||||
if (result.isSuccess()) {
|
if (result.isSuccess()) {
|
||||||
DirectEditing directEditing = (DirectEditing) result.getSingleData();
|
DirectEditing directEditing = result.getResultData();
|
||||||
String json = new Gson().toJson(directEditing);
|
String json = new Gson().toJson(directEditing);
|
||||||
arbitraryDataProvider.storeOrUpdateKeyValue(mAccount.name, ArbitraryDataProvider.DIRECT_EDITING, json);
|
arbitraryDataProvider.storeOrUpdateKeyValue(mAccount.name, ArbitraryDataProvider.DIRECT_EDITING, json);
|
||||||
} else {
|
} else {
|
||||||
|
@ -333,10 +341,11 @@ public class RefreshFolderOperation extends RemoteOperation {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteOperationResult result = new GetPredefinedStatusesRemoteOperation().execute(client);
|
RemoteOperationResult<ArrayList<PredefinedStatus>> result =
|
||||||
|
new GetPredefinedStatusesRemoteOperation().execute(client);
|
||||||
|
|
||||||
if (result.isSuccess()) {
|
if (result.isSuccess()) {
|
||||||
ArrayList<PredefinedStatus> predefinedStatuses = (ArrayList<PredefinedStatus>) result.getSingleData();
|
ArrayList<PredefinedStatus> predefinedStatuses = result.getResultData();
|
||||||
String json = new Gson().toJson(predefinedStatuses);
|
String json = new Gson().toJson(predefinedStatuses);
|
||||||
arbitraryDataProvider.storeOrUpdateKeyValue(mAccount.name, ArbitraryDataProvider.PREDEFINED_STATUS, json);
|
arbitraryDataProvider.storeOrUpdateKeyValue(mAccount.name, ArbitraryDataProvider.PREDEFINED_STATUS, json);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -23,17 +23,19 @@ package com.owncloud.android.operations.common;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
|
||||||
|
import com.nextcloud.common.NextcloudClient;
|
||||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
|
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Operation which execution involves both interactions with an ownCloud server and
|
* Operation which execution involves both interactions with an ownCloud server and with local data in the device.
|
||||||
* with local data in the device.
|
* <p>
|
||||||
*
|
|
||||||
* Provides methods to execute the operation both synchronously or asynchronously.
|
* Provides methods to execute the operation both synchronously or asynchronously.
|
||||||
*/
|
*/
|
||||||
public abstract class SyncOperation extends RemoteOperation {
|
public abstract class SyncOperation extends RemoteOperation {
|
||||||
|
@ -85,6 +87,15 @@ public abstract class SyncOperation extends RemoteOperation {
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously executes the remote operation
|
* Asynchronously executes the remote operation
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
|
|
||||||
package com.owncloud.android.ui.activity;
|
package com.owncloud.android.ui.activity;
|
||||||
|
|
||||||
|
import android.accounts.AuthenticatorException;
|
||||||
|
import android.accounts.OperationCanceledException;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -55,6 +57,7 @@ import com.nextcloud.client.di.Injectable;
|
||||||
import com.nextcloud.client.network.ClientFactory;
|
import com.nextcloud.client.network.ClientFactory;
|
||||||
import com.nextcloud.client.onboarding.FirstRunActivity;
|
import com.nextcloud.client.onboarding.FirstRunActivity;
|
||||||
import com.nextcloud.client.preferences.AppPreferences;
|
import com.nextcloud.client.preferences.AppPreferences;
|
||||||
|
import com.nextcloud.common.NextcloudClient;
|
||||||
import com.nextcloud.java.util.Optional;
|
import com.nextcloud.java.util.Optional;
|
||||||
import com.nextcloud.ui.ChooseAccountDialogFragment;
|
import com.nextcloud.ui.ChooseAccountDialogFragment;
|
||||||
import com.owncloud.android.MainApp;
|
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.datamodel.OCFile;
|
||||||
import com.owncloud.android.lib.common.ExternalLink;
|
import com.owncloud.android.lib.common.ExternalLink;
|
||||||
import com.owncloud.android.lib.common.ExternalLinkType;
|
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.Quota;
|
||||||
import com.owncloud.android.lib.common.UserInfo;
|
import com.owncloud.android.lib.common.UserInfo;
|
||||||
import com.owncloud.android.lib.common.accounts.ExternalLinksOperation;
|
import com.owncloud.android.lib.common.accounts.ExternalLinksOperation;
|
||||||
|
@ -99,6 +103,7 @@ import org.greenrobot.eventbus.Subscribe;
|
||||||
import org.greenrobot.eventbus.ThreadMode;
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
import org.parceler.Parcels;
|
import org.parceler.Parcels;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -731,10 +736,24 @@ public abstract class DrawerActivity extends ToolbarActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
final Context context = MainApp.getAppContext();
|
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) {
|
if (nextcloudClient == null) {
|
||||||
final UserInfo userInfo = (UserInfo) result.getData().get(0);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RemoteOperationResult<UserInfo> result = new GetUserInfoRemoteOperation().execute(nextcloudClient);
|
||||||
|
|
||||||
|
if (result.isSuccess() && result.getResultData() != null) {
|
||||||
|
final UserInfo userInfo = result.getResultData();
|
||||||
final Quota quota = userInfo.getQuota();
|
final Quota quota = userInfo.getQuota();
|
||||||
|
|
||||||
if (quota != null) {
|
if (quota != null) {
|
||||||
|
|
|
@ -48,10 +48,12 @@ import com.bumptech.glide.request.target.SimpleTarget;
|
||||||
import com.nextcloud.client.account.User;
|
import com.nextcloud.client.account.User;
|
||||||
import com.nextcloud.client.di.Injectable;
|
import com.nextcloud.client.di.Injectable;
|
||||||
import com.nextcloud.client.preferences.AppPreferences;
|
import com.nextcloud.client.preferences.AppPreferences;
|
||||||
|
import com.nextcloud.common.NextcloudClient;
|
||||||
import com.owncloud.android.R;
|
import com.owncloud.android.R;
|
||||||
import com.owncloud.android.databinding.UserInfoLayoutBinding;
|
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.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.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
import com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation;
|
import com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation;
|
||||||
|
@ -318,12 +320,21 @@ public class UserInfoActivity extends DrawerActivity implements Injectable {
|
||||||
|
|
||||||
private void fetchAndSetData() {
|
private void fetchAndSetData() {
|
||||||
Thread t = new Thread(() -> {
|
Thread t = new Thread(() -> {
|
||||||
RemoteOperation getRemoteUserInfoOperation = new GetUserInfoRemoteOperation();
|
NextcloudClient nextcloudClient;
|
||||||
RemoteOperationResult result = getRemoteUserInfoOperation.execute(user.toPlatformAccount(), this);
|
|
||||||
|
try {
|
||||||
|
nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user.toPlatformAccount(),
|
||||||
|
this);
|
||||||
|
} catch (AccountUtils.AccountNotFoundException e) {
|
||||||
|
Log_OC.e(this, "Error retrieving user info", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RemoteOperationResult<UserInfo> result = new GetUserInfoRemoteOperation().execute(nextcloudClient);
|
||||||
|
|
||||||
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
|
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
|
||||||
if (result.isSuccess() && result.getData() != null) {
|
if (result.isSuccess() && result.getResultData() != null) {
|
||||||
userInfo = (UserInfo) result.getData().get(0);
|
userInfo = result.getResultData();
|
||||||
|
|
||||||
runOnUiThread(() -> populateUserInfoUi(userInfo));
|
runOnUiThread(() -> populateUserInfoUi(userInfo));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -53,10 +53,11 @@ public class RetrieveStatusAsyncTask extends AsyncTask<Void, Void, Status> {
|
||||||
protected com.owncloud.android.lib.resources.users.Status doInBackground(Void... voids) {
|
protected com.owncloud.android.lib.resources.users.Status doInBackground(Void... voids) {
|
||||||
try {
|
try {
|
||||||
NextcloudClient client = clientFactory.createNextcloudClient(user);
|
NextcloudClient client = clientFactory.createNextcloudClient(user);
|
||||||
RemoteOperationResult result = new GetStatusRemoteOperation().execute(client);
|
RemoteOperationResult<com.owncloud.android.lib.resources.users.Status> result =
|
||||||
|
new GetStatusRemoteOperation().execute(client);
|
||||||
|
|
||||||
if (result.isSuccess()) {
|
if (result.isSuccess()) {
|
||||||
return (com.owncloud.android.lib.resources.users.Status) result.getSingleData();
|
return result.getResultData();
|
||||||
} else {
|
} else {
|
||||||
return new com.owncloud.android.lib.resources.users.Status(StatusType.OFFLINE, "", "", -1);
|
return new com.owncloud.android.lib.resources.users.Status(StatusType.OFFLINE, "", "", -1);
|
||||||
}
|
}
|
||||||
|
@ -72,6 +73,5 @@ public class RetrieveStatusAsyncTask extends AsyncTask<Void, Void, Status> {
|
||||||
if (fragment != null && fragment.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
|
if (fragment != null && fragment.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
|
||||||
fragment.setStatus(status, fragment.requireContext());
|
fragment.setStatus(status, fragment.requireContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -307,7 +307,7 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements View
|
||||||
try {
|
try {
|
||||||
OwnCloudClient client = clientFactory.create(user);
|
OwnCloudClient client = clientFactory.create(user);
|
||||||
|
|
||||||
RemoteOperationResult result =
|
RemoteOperationResult<String> result =
|
||||||
new DirectEditingCreateFileRemoteOperation(path,
|
new DirectEditingCreateFileRemoteOperation(path,
|
||||||
creator.getEditor(),
|
creator.getEditor(),
|
||||||
creator.getId(),
|
creator.getId(),
|
||||||
|
@ -339,7 +339,7 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements View
|
||||||
storageManager.saveFile(temp);
|
storageManager.saveFile(temp);
|
||||||
file = storageManager.getFileByPath(path);
|
file = storageManager.getFileByPath(path);
|
||||||
|
|
||||||
return result.getData().get(0).toString();
|
return result.getResultData();
|
||||||
|
|
||||||
} catch (ClientFactory.CreationException e) {
|
} catch (ClientFactory.CreationException e) {
|
||||||
Log_OC.e(TAG, "Error creating file from template!", e);
|
Log_OC.e(TAG, "Error creating file from template!", e);
|
||||||
|
@ -392,7 +392,8 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements View
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OwnCloudClient client = clientFactory.create(user);
|
OwnCloudClient client = clientFactory.create(user);
|
||||||
RemoteOperationResult result = new DirectEditingObtainListOfTemplatesRemoteOperation(creator.getEditor(),
|
RemoteOperationResult<TemplateList> result =
|
||||||
|
new DirectEditingObtainListOfTemplatesRemoteOperation(creator.getEditor(),
|
||||||
creator.getId())
|
creator.getId())
|
||||||
.execute(client);
|
.execute(client);
|
||||||
|
|
||||||
|
@ -400,7 +401,7 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements View
|
||||||
return new TemplateList();
|
return new TemplateList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (TemplateList) result.getSingleData();
|
return result.getResultData();
|
||||||
} catch (ClientFactory.CreationException e) {
|
} catch (ClientFactory.CreationException e) {
|
||||||
Log_OC.e(TAG, "Could not fetch template", e);
|
Log_OC.e(TAG, "Could not fetch template", e);
|
||||||
|
|
||||||
|
|
|
@ -263,14 +263,14 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetPrivateKeyOperation privateKeyOperation = new GetPrivateKeyOperation();
|
RemoteOperationResult<com.owncloud.android.lib.ocs.responses.PrivateKey> privateKeyResult =
|
||||||
RemoteOperationResult privateKeyResult = privateKeyOperation.execute(user.toPlatformAccount(), getContext());
|
new GetPrivateKeyOperation().execute(user.toPlatformAccount(), getContext());
|
||||||
|
|
||||||
if (privateKeyResult.isSuccess()) {
|
if (privateKeyResult.isSuccess()) {
|
||||||
Log_OC.d(TAG, "private key successful downloaded for " + user.getAccountName());
|
Log_OC.d(TAG, "private key successful downloaded for " + user.getAccountName());
|
||||||
|
|
||||||
keyResult = KEY_EXISTING_USED;
|
keyResult = KEY_EXISTING_USED;
|
||||||
return (String) privateKeyResult.getData().get(0);
|
return privateKeyResult.getResultData().getKey();
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue