Browse Source

Initial work on v2 with activity

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 5 years ago
parent
commit
066f4c25aa
18 changed files with 52 additions and 37 deletions
  1. 5 1
      build.gradle
  2. 3 0
      src/main/java/com/nextcloud/client/network/ClientFactory.java
  3. 13 0
      src/main/java/com/nextcloud/client/network/ClientFactoryImpl.java
  4. 0 2
      src/main/java/com/owncloud/android/jobs/NotificationJob.java
  5. 2 1
      src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java
  6. 0 4
      src/main/java/com/owncloud/android/services/OperationsService.java
  7. 2 2
      src/main/java/com/owncloud/android/ui/activities/ActivitiesActivity.java
  8. 2 2
      src/main/java/com/owncloud/android/ui/activities/ActivitiesContract.java
  9. 2 2
      src/main/java/com/owncloud/android/ui/activities/ActivitiesPresenter.java
  10. 2 2
      src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesRepository.java
  11. 2 2
      src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesServiceApi.java
  12. 6 7
      src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesServiceApiImpl.java
  13. 2 2
      src/main/java/com/owncloud/android/ui/activities/data/activities/RemoteActivitiesRepository.java
  14. 0 1
      src/main/java/com/owncloud/android/ui/activities/data/files/FilesServiceApiImpl.java
  15. 0 1
      src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java
  16. 2 2
      src/main/java/com/owncloud/android/ui/adapter/ActivityAndVersionListAdapter.java
  17. 3 3
      src/main/java/com/owncloud/android/ui/adapter/ActivityListAdapter.java
  18. 6 3
      src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java

+ 5 - 1
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'

+ 3 - 0
src/main/java/com/nextcloud/client/network/ClientFactory.java

@@ -27,6 +27,7 @@ import android.app.Activity;
 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 @@ public interface ClientFactory {
 
     OwnCloudClient create(User user) throws CreationException;
 
+    NextcloudClient createNextcloudClient(User user) throws CreationException;
+
     @Deprecated
     OwnCloudClient create(Account account)
         throws OperationCanceledException, AuthenticatorException, IOException,

+ 13 - 0
src/main/java/com/nextcloud/client/network/ClientFactoryImpl.java

@@ -28,6 +28,7 @@ import android.content.Context;
 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 @@ class ClientFactoryImpl implements ClientFactory {
         }
     }
 
+    @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,

+ 0 - 2
src/main/java/com/owncloud/android/jobs/NotificationJob.java

@@ -253,7 +253,6 @@ public class NotificationJob extends Job {
             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 class NotificationJob extends Job {
                         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);

+ 2 - 1
src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java

@@ -30,6 +30,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 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 @@ public class DetectAuthenticationMethodOperation extends RemoteOperation {
         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);

+ 0 - 4
src/main/java/com/owncloud/android/services/OperationsService.java

@@ -51,7 +51,6 @@ import com.owncloud.android.lib.common.utils.Log_OC;
 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 @@ public class OperationsService extends Service {
                             mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
                                     getClientFor(ocAccount, mService);
 
-                            OwnCloudVersion version = accountManager.getServerVersion(mLastTarget.mAccount);
-                            mOwnCloudClient.setOwnCloudVersion(version);
-
                             mStorageManager = new FileDataStorageManager(
                                 mLastTarget.mAccount,
                                     mService.getContentResolver()

+ 2 - 2
src/main/java/com/owncloud/android/ui/activities/ActivitiesActivity.java

@@ -29,10 +29,10 @@ import android.widget.ProgressBar;
 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 class ActivitiesActivity extends FileActivity implements ActivityListInte
     }
 
     @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;

+ 2 - 2
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 @@ 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();

+ 2 - 2
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 class ActivitiesPresenter implements ActivitiesContract.ActionListener {
         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);

+ 2 - 2
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 @@ import androidx.annotation.NonNull;
  */
 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);
     }
 

+ 2 - 2
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 @@ import java.util.List;
 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);
     }
 

+ 6 - 7
src/main/java/com/owncloud/android/ui/activities/data/activities/ActivitiesServiceApiImpl.java

@@ -30,10 +30,10 @@ 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;
 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 @@ public class ActivitiesServiceApiImpl implements ActivitiesServiceApi {
         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 @@ public class ActivitiesServiceApiImpl implements ActivitiesServiceApi {
             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 @@ public class ActivitiesServiceApiImpl implements ActivitiesServiceApi {
                     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();
@@ -145,7 +144,7 @@ public class ActivitiesServiceApiImpl implements ActivitiesServiceApi {
         protected void onPostExecute(Boolean success) {
             super.onPostExecute(success);
             if (success) {
-                callback.onLoaded(activities, ownCloudClient, lastGiven);
+                callback.onLoaded(activities, client, lastGiven);
             } else {
                 callback.onError(errorMessage);
             }

+ 2 - 2
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 class RemoteActivitiesRepository implements ActivitiesRepository {
         activitiesServiceApi.getAllActivities(lastGiven,
                                               new ActivitiesServiceApi.ActivitiesServiceCallback<List<Object>>() {
             @Override
-            public void onLoaded(List<Object> activities, OwnCloudClient client, int lastGiven) {
+            public void onLoaded(List<Object> activities, NextcloudClient client, int lastGiven) {
                 callback.onActivitiesLoaded(activities, client, lastGiven);
             }
 

+ 0 - 1
src/main/java/com/owncloud/android/ui/activities/data/files/FilesServiceApiImpl.java

@@ -97,7 +97,6 @@ public class FilesServiceApiImpl implements FilesServiceApi {
             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);
 

+ 0 - 1
src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java

@@ -256,7 +256,6 @@ public class NotificationsActivity extends FileActivity implements Notifications
                 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);
                 }

+ 2 - 2
src/main/java/com/owncloud/android/ui/adapter/ActivityAndVersionListAdapter.java

@@ -32,9 +32,9 @@ import android.widget.ImageView;
 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 class ActivityAndVersionListAdapter extends ActivityListAdapter {
         this.versionListInterface = versionListInterface;
     }
 
-    public void setActivityAndVersionItems(List<Object> items, OwnCloudClient newClient, boolean clear) {
+    public void setActivityAndVersionItems(List<Object> items, NextcloudClient newClient, boolean clear) {
         if (client == null) {
             client = newClient;
         }

+ 3 - 3
src/main/java/com/owncloud/android/ui/adapter/ActivityListAdapter.java

@@ -52,11 +52,11 @@ import com.bumptech.glide.load.resource.file.FileToStreamDecoder;
 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<RecyclerView.ViewH
     private final ActivityListInterface activityListInterface;
     private final int px;
     private static final String TAG = ActivityListAdapter.class.getSimpleName();
-    protected OwnCloudClient client;
+    protected NextcloudClient client;
 
     protected Context context;
     private CurrentAccountProvider currentAccountProvider;
@@ -119,7 +119,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
         this.isDetailView = isDetailView;
     }
 
-    public void setActivityItems(List<Object> activityItems, OwnCloudClient client, boolean clear) {
+    public void setActivityItems(List<Object> activityItems, NextcloudClient client, boolean clear) {
         this.client = client;
         String sTime = "";
 

+ 6 - 3
src/main/java/com/owncloud/android/ui/fragment/FileDetailActivitiesFragment.java

@@ -42,6 +42,7 @@ import com.nextcloud.client.account.User;
 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 @@ public class FileDetailActivitiesFragment extends Fragment implements
         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 @@ public class FileDetailActivitiesFragment extends Fragment implements
                 }
 
                 Log_OC.d(TAG, "BEFORE getRemoteActivitiesOperation.execute");
-                final RemoteOperationResult result = getRemoteNotificationOperation.execute(ownCloudClient);
+                final RemoteOperationResult result = getRemoteNotificationOperation.execute(nextcloudClient);
 
                 ArrayList<Object> versions = null;
                 if (restoreFileVersionSupported) {
@@ -401,7 +404,7 @@ public class FileDetailActivitiesFragment extends Fragment implements
     }
 
     private void populateList(List<Object> activities, boolean clear) {
-        adapter.setActivityAndVersionItems(activities, ownCloudClient, clear);
+        adapter.setActivityAndVersionItems(activities, nextcloudClient, clear);
     }
 
     private void setEmptyContent(String headline, String message) {