Skip to content

Commit

Permalink
v2: change userInfoRemoteOperation
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky committed Nov 29, 2019
1 parent 2d8c6b1 commit 787e266
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ ext {
daggerVersion = "2.25.2"
markwonVersion = "4.2.0"
prismVersion = "2.0.0"
androidLibraryVersion = "v2withActivity-SNAPSHOT"
androidLibraryVersion = "v2-SNAPSHOT"

travisBuild = System.getenv("TRAVIS") == "true"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -78,8 +79,9 @@ protected RemoteOperationResult doInBackground(Object... params) {

// Operation - get display name
if (result.isSuccess()) {
GetUserInfoRemoteOperation remoteUserNameOperation = new GetUserInfoRemoteOperation();
result = remoteUserNameOperation.execute(client);
NextcloudClient nextcloudClient = OwnCloudClientFactory.createNextcloudClient(uri, context, true);
nextcloudClient.setCredentials(credentials.toOkHttpCredentials());
result = new GetUserInfoRemoteOperation().execute(nextcloudClient);
}

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
data.add(authMethod);
result.setData(data);
return result; // same result instance, so that other errors
// can be handled by the caller transparently
// can be handled by the caller transparently
}

private String authenticationMethodToString(AuthenticationMethod value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
*/
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;
Expand All @@ -44,13 +44,28 @@ 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
@Deprecated
protected RemoteOperationResult run(OwnCloudClient client) {
throw new UnsupportedOperationException("Not used anymore");
}

/**
* Performs the operation.
* <p>
* Target user account is implicit in 'client'.
* <p>
* Stored account is implicit in {@link #getStorageManager()}.
*
* @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(NextcloudClient client) {
// get display name
GetUserInfoRemoteOperation getDisplayName = new GetUserInfoRemoteOperation();
RemoteOperationResult result = getDisplayName.execute(client);
Expand All @@ -59,9 +74,11 @@ protected RemoteOperationResult run(OwnCloudClient client) {
// store display name with account data
AccountManager accountManager = AccountManager.get(MainApp.getAppContext());
UserInfo userInfo = (UserInfo) result.getData().get(0);
Account storedAccount = getStorageManager().getAccount();
accountManager.setUserData(storedAccount, AccountUtils.Constants.KEY_DISPLAY_NAME, userInfo.getDisplayName());
accountManager.setUserData(getStorageManager().getAccount(),
AccountUtils.Constants.KEY_DISPLAY_NAME,
userInfo.getDisplayName());
}

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private void updateOCVersion(OwnCloudClient client) {

private void updateUserProfile() {
GetUserProfileOperation update = new GetUserProfileOperation();
RemoteOperationResult result = update.execute(mStorageManager, mContext);
RemoteOperationResult result = update.executeNextcloudClient(mStorageManager, mContext);
if (!result.isSuccess()) {
Log_OC.w(TAG, "Couldn't update user profile from server");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ public RemoteOperationResult execute(FileDataStorageManager storageManager, Cont
return super.execute(this.storageManager.getAccount(), context);
}

/**
* Synchronously executes the operation on the received Nextcloud account.
* <p>
* Do not call this method from the main thread.
* <p>
* This method should be used whenever a Nextcloud account is available, instead of {@link #execute(NetxcloudClient,
* com.owncloud.android.datamodel.FileDataStorageManager)}.
*
* @param storageManager
* @param context Android context for the component calling the method.
* @return Result of the operation.
*/
public RemoteOperationResult executeNextcloudClient(FileDataStorageManager storageManager, Context context) {
if (storageManager == null) {
throw new IllegalArgumentException("Trying to execute a sync operation with a " +
"NULL storage manager");
}
if (storageManager.getAccount() == null) {
throw new IllegalArgumentException("Trying to execute a sync operation with a " +
"storage manager for a NULL account");
}
this.storageManager = storageManager;
return super.executeNextcloudClient(this.storageManager.getAccount(), context);
}

/**
* Synchronously executes the remote operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,8 @@ public void run() {
}

final Context context = MainApp.getAppContext();
RemoteOperationResult result = new GetUserInfoRemoteOperation().execute(user.toPlatformAccount(), context);
RemoteOperationResult result = new GetUserInfoRemoteOperation().executeNextcloudClient(currentAccount,
context);

if (result.isSuccess() && result.getData() != null) {
final UserInfo userInfo = (UserInfo) result.getData().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
private void fetchAndSetData() {
Thread t = new Thread(() -> {
RemoteOperation getRemoteUserInfoOperation = new GetUserInfoRemoteOperation();
RemoteOperationResult result = getRemoteUserInfoOperation.execute(account, this);
RemoteOperationResult result = getRemoteUserInfoOperation.executeNextcloudClient(account, this);

if (result.isSuccess() && result.getData() != null) {
userInfo = (UserInfo) result.getData().get(0);
Expand Down

0 comments on commit 787e266

Please sign in to comment.