From 066f4c25aa42dbd6adf3374a06aaf4031c3e0cea Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 29 Nov 2019 10:12:13 +0100 Subject: [PATCH 1/5] Initial work on v2 with activity Signed-off-by: tobiasKaminsky --- build.gradle | 6 +++++- .../com/nextcloud/client/network/ClientFactory.java | 3 +++ .../nextcloud/client/network/ClientFactoryImpl.java | 13 +++++++++++++ .../com/owncloud/android/jobs/NotificationJob.java | 2 -- .../DetectAuthenticationMethodOperation.java | 3 ++- .../android/services/OperationsService.java | 4 ---- .../android/ui/activities/ActivitiesActivity.java | 4 ++-- .../android/ui/activities/ActivitiesContract.java | 4 ++-- .../android/ui/activities/ActivitiesPresenter.java | 4 ++-- .../data/activities/ActivitiesRepository.java | 4 ++-- .../data/activities/ActivitiesServiceApi.java | 4 ++-- .../data/activities/ActivitiesServiceApiImpl.java | 13 ++++++------- .../data/activities/RemoteActivitiesRepository.java | 4 ++-- .../activities/data/files/FilesServiceApiImpl.java | 1 - .../android/ui/activity/NotificationsActivity.java | 1 - .../ui/adapter/ActivityAndVersionListAdapter.java | 4 ++-- .../android/ui/adapter/ActivityListAdapter.java | 6 +++--- .../ui/fragment/FileDetailActivitiesFragment.java | 9 ++++++--- 18 files changed, 52 insertions(+), 37 deletions(-) diff --git a/build.gradle b/build.gradle index 3e2939739373..3b1786f10a01 100644 --- a/build.gradle +++ b/build.gradle @@ -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.2" + classpath "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2 } } @@ -60,7 +61,7 @@ ext { daggerVersion = "2.25.2" markwonVersion = "4.2.0" prismVersion = "2.0.0" - androidLibraryVersion = "master-SNAPSHOT" + androidLibraryVersion = "v2withActivity-SNAPSHOT" travisBuild = System.getenv("TRAVIS") == "true" @@ -273,6 +274,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' diff --git a/src/main/java/com/nextcloud/client/network/ClientFactory.java b/src/main/java/com/nextcloud/client/network/ClientFactory.java index 9f8694bab25f..af0779b5d963 100644 --- a/src/main/java/com/nextcloud/client/network/ClientFactory.java +++ b/src/main/java/com/nextcloud/client/network/ClientFactory.java @@ -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; @@ -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, diff --git a/src/main/java/com/nextcloud/client/network/ClientFactoryImpl.java b/src/main/java/com/nextcloud/client/network/ClientFactoryImpl.java index ff88a8487f9b..7aa1f8eb4bd9 100644 --- a/src/main/java/com/nextcloud/client/network/ClientFactoryImpl.java +++ b/src/main/java/com/nextcloud/client/network/ClientFactoryImpl.java @@ -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; @@ -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, diff --git a/src/main/java/com/owncloud/android/jobs/NotificationJob.java b/src/main/java/com/owncloud/android/jobs/NotificationJob.java index 6407d1dbe512..353e08148696 100644 --- a/src/main/java/com/owncloud/android/jobs/NotificationJob.java +++ b/src/main/java/com/owncloud/android/jobs/NotificationJob.java @@ -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); @@ -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); diff --git a/src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java b/src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java index 9e43670b9c83..c15c8f8fef2d 100644 --- a/src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java +++ b/src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java @@ -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; @@ -119,7 +120,7 @@ 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 data = new ArrayList<>(); data.add(authMethod); diff --git a/src/main/java/com/owncloud/android/services/OperationsService.java b/src/main/java/com/owncloud/android/services/OperationsService.java index cb2c71bd9350..9e13fd7c420d 100644 --- a/src/main/java/com/owncloud/android/services/OperationsService.java +++ b/src/main/java/com/owncloud/android/services/OperationsService.java @@ -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; @@ -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() diff --git a/src/main/java/com/owncloud/android/ui/activities/ActivitiesActivity.java b/src/main/java/com/owncloud/android/ui/activities/ActivitiesActivity.java index 42293e87492b..43687338e778 100644 --- a/src/main/java/com/owncloud/android/ui/activities/ActivitiesActivity.java +++ b/src/main/java/com/owncloud/android/ui/activities/ActivitiesActivity.java @@ -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; @@ -238,7 +238,7 @@ public void onActivityClicked(RichObject richObject) { } @Override - public void showActivities(List activities, OwnCloudClient client, int lastGiven) { + public void showActivities(List activities, NextcloudClient client, int lastGiven) { boolean clear = false; if (this.lastGiven == UNDEFINED) { clear = true; diff --git a/src/main/java/com/owncloud/android/ui/activities/ActivitiesContract.java b/src/main/java/com/owncloud/android/ui/activities/ActivitiesContract.java index ccc005411b23..8ab3b55eda37 100644 --- a/src/main/java/com/owncloud/android/ui/activities/ActivitiesContract.java +++ b/src/main/java/com/owncloud/android/ui/activities/ActivitiesContract.java @@ -18,8 +18,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.activity.BaseActivity; import java.util.List; @@ -27,7 +27,7 @@ public interface ActivitiesContract { interface View { - void showActivities(List activities, OwnCloudClient client, int lastGiven); + void showActivities(List activities, NextcloudClient client, int lastGiven); void showActivitiesLoadError(String error); void showActivityDetailUI(OCFile ocFile); void showActivityDetailUIIsNull(); diff --git a/src/main/java/com/owncloud/android/ui/activities/ActivitiesPresenter.java b/src/main/java/com/owncloud/android/ui/activities/ActivitiesPresenter.java index fc75b82a4f0e..bab61e165f0e 100644 --- a/src/main/java/com/owncloud/android/ui/activities/ActivitiesPresenter.java +++ b/src/main/java/com/owncloud/android/ui/activities/ActivitiesPresenter.java @@ -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; @@ -51,7 +51,7 @@ public void loadActivities(int lastGiven) { activitiesView.setProgressIndicatorState(true); activitiesRepository.getActivities(lastGiven, new ActivitiesRepository.LoadActivitiesCallback() { @Override - public void onActivitiesLoaded(List activities, OwnCloudClient client, int lastGiven) { + public void onActivitiesLoaded(List activities, NextcloudClient client, int lastGiven) { if (!activityStopped) { activitiesView.setProgressIndicatorState(false); diff --git a/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesRepository.java b/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesRepository.java index eaa8d980a11d..e8c54e9e74ab 100644 --- a/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesRepository.java +++ b/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesRepository.java @@ -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; @@ -29,7 +29,7 @@ */ public interface ActivitiesRepository { interface LoadActivitiesCallback { - void onActivitiesLoaded(List activities, OwnCloudClient client, int lastGiven); + void onActivitiesLoaded(List activities, NextcloudClient client, int lastGiven); void onActivitiesLoadedError(String error); } diff --git a/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesServiceApi.java b/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesServiceApi.java index 55cb665844a7..419a5c0ba884 100644 --- a/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesServiceApi.java +++ b/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesServiceApi.java @@ -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; @@ -31,7 +31,7 @@ public interface ActivitiesServiceApi { interface ActivitiesServiceCallback { - void onLoaded(T activities, OwnCloudClient client, int lastGiven); + void onLoaded(T activities, NextcloudClient client, int lastGiven); void onError (String error); } diff --git a/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesServiceApiImpl.java b/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesServiceApiImpl.java index 360c2458881e..987f0c2320fc 100644 --- a/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesServiceApiImpl.java +++ b/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesServiceApiImpl.java @@ -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; @@ -75,7 +75,7 @@ private static class GetActivityListTask extends AsyncTask private UserAccountManager accountManager; private int lastGiven; private String errorMessage; - private OwnCloudClient ownCloudClient; + private NextcloudClient client; private GetActivityListTask(Account account, UserAccountManager accountManager, @@ -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) { @@ -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 data = result.getData(); @@ -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); } diff --git a/src/main/java/com/owncloud/android/ui/activities/data/activities/RemoteActivitiesRepository.java b/src/main/java/com/owncloud/android/ui/activities/data/activities/RemoteActivitiesRepository.java index 2e2fac0d5b18..524c8dbcf730 100644 --- a/src/main/java/com/owncloud/android/ui/activities/data/activities/RemoteActivitiesRepository.java +++ b/src/main/java/com/owncloud/android/ui/activities/data/activities/RemoteActivitiesRepository.java @@ -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; @@ -38,7 +38,7 @@ public void getActivities(int lastGiven, @NonNull LoadActivitiesCallback callbac activitiesServiceApi.getAllActivities(lastGiven, new ActivitiesServiceApi.ActivitiesServiceCallback>() { @Override - public void onLoaded(List activities, OwnCloudClient client, int lastGiven) { + public void onLoaded(List activities, NextcloudClient client, int lastGiven) { callback.onActivitiesLoaded(activities, client, lastGiven); } diff --git a/src/main/java/com/owncloud/android/ui/activities/data/files/FilesServiceApiImpl.java b/src/main/java/com/owncloud/android/ui/activities/data/files/FilesServiceApiImpl.java index 8492a0751a4f..8f2fd0ba0986 100644 --- a/src/main/java/com/owncloud/android/ui/activities/data/files/FilesServiceApiImpl.java +++ b/src/main/java/com/owncloud/android/ui/activities/data/files/FilesServiceApiImpl.java @@ -97,7 +97,6 @@ protected Boolean doInBackground(Void... voids) { final Context context = MainApp.getAppContext(); try { OwnCloudClient ownCloudClient = clientFactory.create(user); - ownCloudClient.setOwnCloudVersion(user.getServer().getVersion()); // always update file as it could be an old state saved in database RemoteOperationResult resultRemoteFileOp = new ReadFileRemoteOperation(fileUrl).execute(ownCloudClient); diff --git a/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java b/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java index 261d12497aee..8203139a6d5c 100644 --- a/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java @@ -256,7 +256,6 @@ private void fetchAndSetData() { try { User user = optionalUser.get(); client = clientFactory.create(user); - client.setOwnCloudVersion(user.getServer().getVersion()); } catch (ClientFactory.CreationException e) { Log_OC.e(TAG, "Error initializing client", e); } diff --git a/src/main/java/com/owncloud/android/ui/adapter/ActivityAndVersionListAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/ActivityAndVersionListAdapter.java index 161450ac759c..1f96921bdecf 100644 --- a/src/main/java/com/owncloud/android/ui/adapter/ActivityAndVersionListAdapter.java +++ b/src/main/java/com/owncloud/android/ui/adapter/ActivityAndVersionListAdapter.java @@ -32,9 +32,9 @@ import android.widget.TextView; import com.nextcloud.client.account.CurrentAccountProvider; +import com.nextcloud.common.NextcloudClient; import com.owncloud.android.R; import com.owncloud.android.datamodel.FileDataStorageManager; -import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.resources.activities.model.Activity; import com.owncloud.android.lib.resources.files.model.FileVersion; import com.owncloud.android.lib.resources.status.OCCapability; @@ -69,7 +69,7 @@ public ActivityAndVersionListAdapter( this.versionListInterface = versionListInterface; } - public void setActivityAndVersionItems(List items, OwnCloudClient newClient, boolean clear) { + public void setActivityAndVersionItems(List items, NextcloudClient newClient, boolean clear) { if (client == null) { client = newClient; } diff --git a/src/main/java/com/owncloud/android/ui/adapter/ActivityListAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/ActivityListAdapter.java index 018dd33fb24d..fa48e990a66e 100644 --- a/src/main/java/com/owncloud/android/ui/adapter/ActivityListAdapter.java +++ b/src/main/java/com/owncloud/android/ui/adapter/ActivityListAdapter.java @@ -52,11 +52,11 @@ import com.caverock.androidsvg.SVG; import com.nextcloud.client.account.CurrentAccountProvider; import com.nextcloud.client.network.ClientFactory; +import com.nextcloud.common.NextcloudClient; import com.owncloud.android.MainApp; 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.Activity; import com.owncloud.android.lib.resources.activities.model.RichElement; @@ -91,7 +91,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter activityItems, OwnCloudClient client, boolean clear) { + public void setActivityItems(List activityItems, NextcloudClient client, boolean clear) { this.client = client; String sTime = ""; diff --git a/src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java b/src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java index ce4d1e37c202..1a495b0fb8b3 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java @@ -42,6 +42,7 @@ import com.nextcloud.client.account.UserAccountManager; import com.nextcloud.client.di.Injectable; import com.nextcloud.client.network.ClientFactory; +import com.nextcloud.common.NextcloudClient; import com.owncloud.android.R; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; @@ -99,6 +100,7 @@ public class FileDetailActivitiesFragment extends Fragment implements private ActivityAndVersionListAdapter adapter; private Unbinder unbinder; private OwnCloudClient ownCloudClient; + private NextcloudClient nextcloudClient; private OCFile file; private Account account; @@ -313,7 +315,8 @@ private void fetchAndSetData(int lastGiven) { Thread t = new Thread(() -> { try { ownCloudClient = clientFactory.create(user); - ownCloudClient.setOwnCloudVersion(user.getServer().getVersion()); + nextcloudClient = clientFactory.createNextcloudClient(user); + isLoadingActivities = true; GetActivitiesRemoteOperation getRemoteNotificationOperation; @@ -325,7 +328,7 @@ private void fetchAndSetData(int lastGiven) { } Log_OC.d(TAG, "BEFORE getRemoteActivitiesOperation.execute"); - final RemoteOperationResult result = getRemoteNotificationOperation.execute(ownCloudClient); + final RemoteOperationResult result = getRemoteNotificationOperation.execute(nextcloudClient); ArrayList versions = null; if (restoreFileVersionSupported) { @@ -401,7 +404,7 @@ public void markCommentsAsRead() { } private void populateList(List activities, boolean clear) { - adapter.setActivityAndVersionItems(activities, ownCloudClient, clear); + adapter.setActivityAndVersionItems(activities, nextcloudClient, clear); } private void setEmptyContent(String headline, String message) { From e5cd5ffcd6541bf25f10505f7d3f50cda4ce574a Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Mon, 2 Dec 2019 10:07:20 +0100 Subject: [PATCH 2/5] =?UTF-8?q?use=20nextcloudClient.execute(=E2=80=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tobiasKaminsky --- .../android/ui/fragment/FileDetailActivitiesFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java b/src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java index 1a495b0fb8b3..5d55620882e6 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java @@ -328,7 +328,7 @@ private void fetchAndSetData(int lastGiven) { } Log_OC.d(TAG, "BEFORE getRemoteActivitiesOperation.execute"); - final RemoteOperationResult result = getRemoteNotificationOperation.execute(nextcloudClient); + final RemoteOperationResult result = nextcloudClient.execute(getRemoteNotificationOperation); ArrayList versions = null; if (restoreFileVersionSupported) { From 8b61e740571bd2f7c973c7864f2fc433b2004e72 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Wed, 4 Dec 2019 08:01:32 +0100 Subject: [PATCH 3/5] remove unneeded accountManager Signed-off-by: tobiasKaminsky --- .../owncloud/android/services/OperationsService.java | 11 ++--------- .../data/activities/ActivitiesServiceApiImpl.java | 8 +------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/owncloud/android/services/OperationsService.java b/src/main/java/com/owncloud/android/services/OperationsService.java index 9e13fd7c420d..19cca43f3d7e 100644 --- a/src/main/java/com/owncloud/android/services/OperationsService.java +++ b/src/main/java/com/owncloud/android/services/OperationsService.java @@ -37,7 +37,6 @@ import android.text.TextUtils; import android.util.Pair; -import com.nextcloud.client.account.UserAccountManager; import com.owncloud.android.MainApp; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; @@ -75,8 +74,6 @@ import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentMap; -import javax.inject.Inject; - import dagger.android.AndroidInjection; public class OperationsService extends Service { @@ -136,8 +133,6 @@ public class OperationsService extends Service { private ConcurrentMap> mUndispatchedFinishedOperations = new ConcurrentHashMap<>(); - @Inject UserAccountManager accountManager; - private static class Target { public Uri mServerUrl; public Account mAccount; @@ -163,7 +158,7 @@ public void onCreate() { HandlerThread thread = new HandlerThread("Operations thread", Process.THREAD_PRIORITY_BACKGROUND); thread.start(); - mOperationsHandler = new ServiceHandler(thread.getLooper(), this, accountManager); + mOperationsHandler = new ServiceHandler(thread.getLooper(), this); mOperationsBinder = new OperationsServiceBinder(mOperationsHandler); // Separated worker thread for download of folders (WIP) @@ -399,16 +394,14 @@ private static class ServiceHandler extends Handler { private Target mLastTarget; private OwnCloudClient mOwnCloudClient; private FileDataStorageManager mStorageManager; - private UserAccountManager accountManager; - public ServiceHandler(Looper looper, OperationsService service, UserAccountManager accountManager) { + public ServiceHandler(Looper looper, OperationsService service) { super(looper); if (service == null) { throw new IllegalArgumentException("Received invalid NULL in parameter 'service'"); } mService = service; - this.accountManager = accountManager; } @Override diff --git a/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesServiceApiImpl.java b/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesServiceApiImpl.java index 987f0c2320fc..8492c655699c 100644 --- a/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesServiceApiImpl.java +++ b/src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesServiceApiImpl.java @@ -28,7 +28,6 @@ import android.content.Context; import android.os.AsyncTask; -import com.nextcloud.client.account.User; import com.nextcloud.client.account.UserAccountManager; import com.nextcloud.common.NextcloudClient; import com.owncloud.android.MainApp; @@ -59,9 +58,7 @@ public ActivitiesServiceApiImpl(UserAccountManager accountManager) { @Override public void getAllActivities(int lastGiven, ActivitiesServiceCallback> callback) { - User user = accountManager.getUser(); - GetActivityListTask getActivityListTask = new GetActivityListTask(user.toPlatformAccount(), - accountManager, + GetActivityListTask getActivityListTask = new GetActivityListTask(accountManager.getUser().toPlatformAccount(), lastGiven, callback); getActivityListTask.execute(); @@ -72,17 +69,14 @@ private static class GetActivityListTask extends AsyncTask private final ActivitiesServiceCallback> callback; private List activities; private Account account; - private UserAccountManager accountManager; private int lastGiven; private String errorMessage; private NextcloudClient client; private GetActivityListTask(Account account, - UserAccountManager accountManager, int lastGiven, ActivitiesServiceCallback> callback) { this.account = account; - this.accountManager = accountManager; this.lastGiven = lastGiven; this.callback = callback; activities = new ArrayList<>(); From 6eb4ac7c47665f6d4f61283d65d83ada8d519f9e Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Wed, 11 Dec 2019 11:20:46 +0100 Subject: [PATCH 4/5] revert to master snapshot Signed-off-by: tobiasKaminsky --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 3b1786f10a01..1fb495c1b3d0 100644 --- a/build.gradle +++ b/build.gradle @@ -61,7 +61,7 @@ ext { daggerVersion = "2.25.2" markwonVersion = "4.2.0" prismVersion = "2.0.0" - androidLibraryVersion = "v2withActivity-SNAPSHOT" + androidLibraryVersion = "master-SNAPSHOT" travisBuild = System.getenv("TRAVIS") == "true" From a2357181ab11cc9b76e68a8e16ec60fb4889e2f0 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Thu, 12 Dec 2019 07:13:29 +0100 Subject: [PATCH 5/5] fix tests Signed-off-by: tobiasKaminsky --- .../activities/ActivitiesPresenterTest.java | 88 +++++++++---------- .../RemoteActivitiesRepositoryTest.java | 8 +- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/test/java/com/owncloud/android/ui/activities/ActivitiesPresenterTest.java b/src/test/java/com/owncloud/android/ui/activities/ActivitiesPresenterTest.java index dd2915095ce6..712be8f150f3 100644 --- a/src/test/java/com/owncloud/android/ui/activities/ActivitiesPresenterTest.java +++ b/src/test/java/com/owncloud/android/ui/activities/ActivitiesPresenterTest.java @@ -18,8 +18,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.lib.resources.activities.model.Activity; import com.owncloud.android.ui.activities.data.activities.ActivitiesRepository; import com.owncloud.android.ui.activities.data.files.FilesRepository; @@ -41,30 +41,30 @@ public class ActivitiesPresenterTest { @Mock - private FilesRepository mFileRepository; + private FilesRepository filesRepository; @Mock - private ActivitiesContract.View mView; + private ActivitiesContract.View view; @Mock - private ActivitiesRepository mActivitiesRepository; + private ActivitiesRepository activitiesRepository; @Mock - private BaseActivity mBaseActivity; + private BaseActivity baseActivity; @Mock - private OwnCloudClient mOwnCloudClient; + private NextcloudClient nextcloudClient; @Mock - private OCFile mOCFile; + private OCFile ocFile; @Captor - private ArgumentCaptor mReadRemoteFilleCallbackCaptor; + private ArgumentCaptor readRemoteFileCallbackArgumentCaptor; @Captor - private ArgumentCaptor mLoadActivitiesCallbackCaptor; + private ArgumentCaptor loadActivitiesCallbackArgumentCaptor; - private ActivitiesPresenter mPresenter; + private ActivitiesPresenter activitiesPresenter; private List activitiesList; @@ -72,7 +72,7 @@ public class ActivitiesPresenterTest { @Before public void setupActivitiesPresenter() { MockitoAnnotations.initMocks(this); - mPresenter = new ActivitiesPresenter(mActivitiesRepository, mFileRepository, mView); + activitiesPresenter = new ActivitiesPresenter(activitiesRepository, filesRepository, view); activitiesList = new ArrayList<>(); activitiesList.add(new Activity()); @@ -81,83 +81,83 @@ public void setupActivitiesPresenter() { @Test public void loadActivitiesFromRepositoryIntoView() { // When loading activities from repository is requested from presenter... - mPresenter.loadActivities(-1); + activitiesPresenter.loadActivities(-1); // Progress indicator is shown in view - verify(mView).setProgressIndicatorState(eq(true)); + verify(view).setProgressIndicatorState(eq(true)); // Repository starts retrieving activities from server - verify(mActivitiesRepository).getActivities(eq(-1), mLoadActivitiesCallbackCaptor.capture()); + verify(activitiesRepository).getActivities(eq(-1), loadActivitiesCallbackArgumentCaptor.capture()); // Repository returns data - mLoadActivitiesCallbackCaptor.getValue().onActivitiesLoaded(activitiesList, mOwnCloudClient, -1); + loadActivitiesCallbackArgumentCaptor.getValue().onActivitiesLoaded(activitiesList, nextcloudClient, -1); // Progress indicator is hidden - verify(mView).setProgressIndicatorState(eq(false)); + verify(view).setProgressIndicatorState(eq(false)); // List of activities is shown in view. - verify(mView).showActivities(eq(activitiesList), eq(mOwnCloudClient), eq(-1)); + verify(view).showActivities(eq(activitiesList), eq(nextcloudClient), eq(-1)); } @Test public void loadActivitiesFromRepositoryShowError() { // When loading activities from repository is requested from presenter... - mPresenter.loadActivities(-1); + activitiesPresenter.loadActivities(-1); // Progress indicator is shown in view - verify(mView).setProgressIndicatorState(eq(true)); + verify(view).setProgressIndicatorState(eq(true)); // Repository starts retrieving activities from server - verify(mActivitiesRepository).getActivities(eq(-1), mLoadActivitiesCallbackCaptor.capture()); + verify(activitiesRepository).getActivities(eq(-1), loadActivitiesCallbackArgumentCaptor.capture()); // Repository returns data - mLoadActivitiesCallbackCaptor.getValue().onActivitiesLoadedError("error"); + loadActivitiesCallbackArgumentCaptor.getValue().onActivitiesLoadedError("error"); // Progress indicator is hidden - verify(mView).setProgressIndicatorState(eq(false)); + verify(view).setProgressIndicatorState(eq(false)); // Correct error is shown in view - verify(mView).showActivitiesLoadError(eq("error")); + verify(view).showActivitiesLoadError(eq("error")); } @Test public void loadRemoteFileFromRepositoryShowDetailUI() { // When retrieving remote file from repository... - mPresenter.openActivity("null", mBaseActivity); + activitiesPresenter.openActivity("null", baseActivity); // Progress indicator is shown in view - verify(mView).setProgressIndicatorState(eq(true)); + verify(view).setProgressIndicatorState(eq(true)); // Repository retrieves remote file - verify(mFileRepository).readRemoteFile(eq("null"), eq(mBaseActivity), - mReadRemoteFilleCallbackCaptor.capture()); + verify(filesRepository).readRemoteFile(eq("null"), eq(baseActivity), + readRemoteFileCallbackArgumentCaptor.capture()); // Repository returns valid file object - mReadRemoteFilleCallbackCaptor.getValue().onFileLoaded(mOCFile); + readRemoteFileCallbackArgumentCaptor.getValue().onFileLoaded(ocFile); // Progress indicator is hidden - verify(mView).setProgressIndicatorState(eq(false)); + verify(view).setProgressIndicatorState(eq(false)); // File detail UI is shown - verify(mView).showActivityDetailUI(eq(mOCFile)); + verify(view).showActivityDetailUI(eq(ocFile)); } @Test public void loadRemoteFileFromRepositoryShowEmptyFile() { // When retrieving remote file from repository... - mPresenter.openActivity("null", mBaseActivity); + activitiesPresenter.openActivity("null", baseActivity); // Progress indicator is shown in view - verify(mView).setProgressIndicatorState(eq(true)); + verify(view).setProgressIndicatorState(eq(true)); // Repository retrieves remote file - verify(mFileRepository).readRemoteFile(eq("null"), eq(mBaseActivity), - mReadRemoteFilleCallbackCaptor.capture()); + verify(filesRepository).readRemoteFile(eq("null"), eq(baseActivity), + readRemoteFileCallbackArgumentCaptor.capture()); // Repository returns an valid but Null value file object. - mReadRemoteFilleCallbackCaptor.getValue().onFileLoaded(null); + readRemoteFileCallbackArgumentCaptor.getValue().onFileLoaded(null); // Progress indicator is hidden - verify(mView).setProgressIndicatorState(eq(false)); + verify(view).setProgressIndicatorState(eq(false)); // Returned file is null. Inform user. - verify(mView).showActivityDetailUIIsNull(); + verify(view).showActivityDetailUIIsNull(); } @Test public void loadRemoteFileFromRepositoryShowError() { // When retrieving remote file from repository... - mPresenter.openActivity("null", mBaseActivity); + activitiesPresenter.openActivity("null", baseActivity); // Progress indicator is shown in view - verify(mView).setProgressIndicatorState(eq(true)); + verify(view).setProgressIndicatorState(eq(true)); // Repository retrieves remote file - verify(mFileRepository).readRemoteFile(eq("null"), eq(mBaseActivity), - mReadRemoteFilleCallbackCaptor.capture()); + verify(filesRepository).readRemoteFile(eq("null"), eq(baseActivity), + readRemoteFileCallbackArgumentCaptor.capture()); // Repository returns valid file object - mReadRemoteFilleCallbackCaptor.getValue().onFileLoadError("error"); + readRemoteFileCallbackArgumentCaptor.getValue().onFileLoadError("error"); // Progress indicator is hidden - verify(mView).setProgressIndicatorState(eq(false)); + verify(view).setProgressIndicatorState(eq(false)); // Error message is shown to the user. - verify(mView).showActivityDetailError(eq("error")); + verify(view).showActivityDetailError(eq("error")); } } diff --git a/src/test/java/com/owncloud/android/ui/activities/data/activities/RemoteActivitiesRepositoryTest.java b/src/test/java/com/owncloud/android/ui/activities/data/activities/RemoteActivitiesRepositoryTest.java index a7105c6b5485..3d5aa874a275 100644 --- a/src/test/java/com/owncloud/android/ui/activities/data/activities/RemoteActivitiesRepositoryTest.java +++ b/src/test/java/com/owncloud/android/ui/activities/data/activities/RemoteActivitiesRepositoryTest.java @@ -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 org.junit.Before; import org.junit.Test; @@ -42,7 +42,7 @@ public class RemoteActivitiesRepositoryTest { ActivitiesRepository.LoadActivitiesCallback mockedLoadActivitiesCallback; @Mock - OwnCloudClient ownCloudClient; + NextcloudClient nextcloudClient; @Captor private ArgumentCaptor activitiesServiceCallbackCaptor; @@ -62,8 +62,8 @@ public void setUpActivitiesRepository() { public void loadActivitiesReturnSuccess() { mActivitiesRepository.getActivities(-1, mockedLoadActivitiesCallback); verify(serviceApi).getAllActivities(eq(-1), activitiesServiceCallbackCaptor.capture()); - activitiesServiceCallbackCaptor.getValue().onLoaded(activitiesList, ownCloudClient, -1); - verify(mockedLoadActivitiesCallback).onActivitiesLoaded(eq(activitiesList), eq(ownCloudClient), eq(-1)); + activitiesServiceCallbackCaptor.getValue().onLoaded(activitiesList, nextcloudClient, -1); + verify(mockedLoadActivitiesCallback).onActivitiesLoaded(eq(activitiesList), eq(nextcloudClient), eq(-1)); } @Test