Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2 with userInfo #4600

Open
wants to merge 2 commits into
base: v2withActivity
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ buildscript {
classpath 'gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:1.6.6'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.2.0"
classpath "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
}
}

Expand Down Expand Up @@ -60,7 +61,7 @@ ext {
daggerVersion = "2.25.2"
markwonVersion = "4.2.0"
prismVersion = "2.0.0"
androidLibraryVersion = "master-SNAPSHOT"
androidLibraryVersion = "v2-SNAPSHOT"

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

Expand Down Expand Up @@ -272,6 +273,9 @@ dependencies {
gplayImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
versionDevImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
qaImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
compileOnly 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2' // remove after entire switch to lib v2
implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.1' // remove after entire switch to lib v2
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.1.0-beta01'
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/nextcloud/client/network/ClientFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.net.Uri;

import com.nextcloud.client.account.User;
import com.nextcloud.common.NextcloudClient;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.accounts.AccountUtils;

Expand Down Expand Up @@ -55,6 +56,8 @@ class CreationException extends Exception {

OwnCloudClient create(User user) throws CreationException;

NextcloudClient createNextcloudClient(User user) throws CreationException;

@Deprecated
OwnCloudClient create(Account account)
throws OperationCanceledException, AuthenticatorException, IOException,
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/nextcloud/client/network/ClientFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.net.Uri;

import com.nextcloud.client.account.User;
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.accounts.AccountUtils;
Expand All @@ -54,6 +55,18 @@ public OwnCloudClient create(User user) throws CreationException {
}
}

@Override
public NextcloudClient createNextcloudClient(User user) throws CreationException {
try {
return OwnCloudClientFactory.createNextcloudClient(user.toPlatformAccount(), context);
} catch (OperationCanceledException |
AuthenticatorException |
IOException |
AccountUtils.AccountNotFoundException e) {
throw new CreationException(e);
}
}

@Override
public OwnCloudClient create(Account account)
throws OperationCanceledException, AuthenticatorException, IOException,
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
2 changes: 0 additions & 2 deletions src/main/java/com/owncloud/android/jobs/NotificationJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ private void fetchCompleteNotification(Account account, DecryptedPushMessage dec
OwnCloudAccount ocAccount = new OwnCloudAccount(currentAccount, context);
OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton()
.getClientFor(ocAccount, context);
client.setOwnCloudVersion(accountManager.getServerVersion(currentAccount));

RemoteOperationResult result = new GetNotificationRemoteOperation(decryptedPushMessage.nid)
.execute(client);
Expand Down Expand Up @@ -306,7 +305,6 @@ public void onReceive(Context context, Intent intent) {
OwnCloudAccount ocAccount = new OwnCloudAccount(currentAccount, context);
OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton()
.getClientFor(ocAccount, context);
client.setOwnCloudVersion(accountManager.getServerVersion(currentAccount));

String actionType = intent.getStringExtra(KEY_NOTIFICATION_ACTION_TYPE);
String actionLink = intent.getStringExtra(KEY_NOTIFICATION_ACTION_LINK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpStatus;

import java.util.ArrayList;
Expand Down Expand Up @@ -119,13 +120,13 @@ protected RemoteOperationResult run(OwnCloudClient client) {
Log_OC.d(TAG, "Authentication method found: " + authenticationMethodToString(authMethod));

if (authMethod != AuthenticationMethod.UNKNOWN) {
result = new RemoteOperationResult(true, result.getHttpCode(), result.getHttpPhrase(), null);
result = new RemoteOperationResult(true, result.getHttpCode(), result.getHttpPhrase(), new Header[0]);
}
ArrayList<Object> data = new ArrayList<>();
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is deprecated it should still work, so this just leads to an exception at runtime, so removing the method (leading to a compiler error) would be preferable imho.

What do you think @ezaquarii ?

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 @@ -51,7 +51,6 @@
import com.owncloud.android.lib.resources.files.RestoreFileVersionRemoteOperation;
import com.owncloud.android.lib.resources.files.model.FileVersion;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation;
import com.owncloud.android.operations.CheckCurrentCredentialsOperation;
import com.owncloud.android.operations.CopyFileOperation;
Expand Down Expand Up @@ -443,9 +442,6 @@ private void nextOperation() {
mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, mService);

OwnCloudVersion version = accountManager.getServerVersion(mLastTarget.mAccount);
mOwnCloudClient.setOwnCloudVersion(version);

mStorageManager = new FileDataStorageManager(
mLastTarget.mAccount,
mService.getContentResolver()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import android.widget.TextView;
import android.widget.Toast;

import com.nextcloud.common.NextcloudClient;
import com.owncloud.android.R;
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.utils.Log_OC;
import com.owncloud.android.lib.resources.activities.model.RichObject;
import com.owncloud.android.lib.resources.files.FileUtils;
Expand Down Expand Up @@ -238,7 +238,7 @@ public void onActivityClicked(RichObject richObject) {
}

@Override
public void showActivities(List<Object> activities, OwnCloudClient client, int lastGiven) {
public void showActivities(List<Object> activities, NextcloudClient client, int lastGiven) {
boolean clear = false;
if (this.lastGiven == UNDEFINED) {
clear = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
*/
package com.owncloud.android.ui.activities;

import com.nextcloud.common.NextcloudClient;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.ui.activity.BaseActivity;

import java.util.List;

public interface ActivitiesContract {

interface View {
void showActivities(List<Object> activities, OwnCloudClient client, int lastGiven);
void showActivities(List<Object> activities, NextcloudClient client, int lastGiven);
void showActivitiesLoadError(String error);
void showActivityDetailUI(OCFile ocFile);
void showActivityDetailUIIsNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package com.owncloud.android.ui.activities;

import com.nextcloud.common.NextcloudClient;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.ui.activities.data.activities.ActivitiesRepository;
import com.owncloud.android.ui.activities.data.files.FilesRepository;
import com.owncloud.android.ui.activity.BaseActivity;
Expand Down Expand Up @@ -51,7 +51,7 @@ public void loadActivities(int lastGiven) {
activitiesView.setProgressIndicatorState(true);
activitiesRepository.getActivities(lastGiven, new ActivitiesRepository.LoadActivitiesCallback() {
@Override
public void onActivitiesLoaded(List<Object> activities, OwnCloudClient client, int lastGiven) {
public void onActivitiesLoaded(List<Object> activities, NextcloudClient client, int lastGiven) {

if (!activityStopped) {
activitiesView.setProgressIndicatorState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package com.owncloud.android.ui.activities.data.activities;

import com.owncloud.android.lib.common.OwnCloudClient;
import com.nextcloud.common.NextcloudClient;

import java.util.List;

Expand All @@ -29,7 +29,7 @@
*/
public interface ActivitiesRepository {
interface LoadActivitiesCallback {
void onActivitiesLoaded(List<Object> activities, OwnCloudClient client, int lastGiven);
void onActivitiesLoaded(List<Object> activities, NextcloudClient client, int lastGiven);
void onActivitiesLoadedError(String error);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package com.owncloud.android.ui.activities.data.activities;

import com.owncloud.android.lib.common.OwnCloudClient;
import com.nextcloud.common.NextcloudClient;
import com.owncloud.android.lib.resources.activities.model.Activity;

import java.util.List;
Expand All @@ -31,7 +31,7 @@
public interface ActivitiesServiceApi {

interface ActivitiesServiceCallback<T> {
void onLoaded(T activities, OwnCloudClient client, int lastGiven);
void onLoaded(T activities, NextcloudClient client, int lastGiven);
void onError (String error);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@

import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.common.NextcloudClient;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
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.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
Expand Down Expand Up @@ -75,7 +75,7 @@ private static class GetActivityListTask extends AsyncTask<Void, Void, Boolean>
private UserAccountManager accountManager;
private int lastGiven;
private String errorMessage;
private OwnCloudClient ownCloudClient;
private NextcloudClient client;

private GetActivityListTask(Account account,
UserAccountManager accountManager,
Expand All @@ -95,9 +95,8 @@ protected Boolean doInBackground(Void... voids) {
OwnCloudAccount ocAccount;
try {
ocAccount = new OwnCloudAccount(account, context);
ownCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, MainApp.getAppContext());
ownCloudClient.setOwnCloudVersion(accountManager.getServerVersion(account));
client = OwnCloudClientManagerFactory.getDefaultSingleton().
getNextcloudClientFor(ocAccount, MainApp.getAppContext());

GetActivitiesRemoteOperation getRemoteActivitiesOperation;
if (lastGiven > 0) {
Expand All @@ -106,7 +105,7 @@ protected Boolean doInBackground(Void... voids) {
getRemoteActivitiesOperation = new GetActivitiesRemoteOperation();
}

final RemoteOperationResult result = getRemoteActivitiesOperation.execute(ownCloudClient);
final RemoteOperationResult result = getRemoteActivitiesOperation.execute(client);

if (result.isSuccess() && result.getData() != null) {
final ArrayList<Object> data = result.getData();
Expand Down Expand Up @@ -145,7 +144,7 @@ protected Boolean doInBackground(Void... voids) {
protected void onPostExecute(Boolean success) {
super.onPostExecute(success);
if (success) {
callback.onLoaded(activities, ownCloudClient, lastGiven);
callback.onLoaded(activities, client, lastGiven);
} else {
callback.onError(errorMessage);
}
Expand Down
Loading