diff --git a/src/androidTest/kotlin/com/nextcloud/lib/resources/users/GetActivitiesRemoteOperationTest.kt b/src/androidTest/kotlin/com/nextcloud/lib/resources/users/GetActivitiesRemoteOperationTest.kt
new file mode 100644
index 000000000..133c38798
--- /dev/null
+++ b/src/androidTest/kotlin/com/nextcloud/lib/resources/users/GetActivitiesRemoteOperationTest.kt
@@ -0,0 +1,44 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Tobias Kaminsky
+ * Copyright (C) 2019 Tobias Kaminsky
+ * Copyright (C) 2019 Nextcloud GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+package com.nextcloud.lib.resources.users
+
+import com.owncloud.android.AbstractIT
+import com.owncloud.android.lib.resources.activities.GetActivitiesRemoteOperation
+import com.owncloud.android.lib.resources.activities.model.Activity
+import org.junit.Assert.assertTrue
+import org.junit.Test
+import java.util.*
+
+class GetActivitiesRemoteOperationTest : AbstractIT() {
+ @Test
+ fun getActivities() {
+ val result = GetActivitiesRemoteOperation().execute(nextcloudClient)
+ assertTrue(result.isSuccess)
+
+ val activities = result.data[0] as ArrayList
+ val lastGiven = result.data[1] as Integer;
+
+ assertTrue(activities.isNotEmpty())
+ assertTrue(lastGiven > 0)
+ }
+}
diff --git a/src/androidTest/kotlin/com/nextcloud/lib/resources/users/GetUserInfoRemoteOperationTest.kt b/src/androidTest/kotlin/com/nextcloud/lib/resources/users/GetUserInfoRemoteOperationTest.kt
index 74e58b32e..6032c523d 100644
--- a/src/androidTest/kotlin/com/nextcloud/lib/resources/users/GetUserInfoRemoteOperationTest.kt
+++ b/src/androidTest/kotlin/com/nextcloud/lib/resources/users/GetUserInfoRemoteOperationTest.kt
@@ -29,9 +29,9 @@ package com.nextcloud.lib.resources.users
import androidx.test.platform.app.InstrumentationRegistry
import com.owncloud.android.AbstractIT
+import com.owncloud.android.lib.common.OwnCloudBasicCredentials
import com.owncloud.android.lib.common.UserInfo
import com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation
-import okhttp3.Credentials
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
@@ -40,27 +40,27 @@ import org.junit.Test
class GetUserInfoRemoteOperationTest : AbstractIT() {
@Test
fun testGetUserNoQuota() {
- nextcloudClient.credentials = Credentials.basic("user1", "user1")
- val userInfoResult = GetUserInfoRemoteOperation().execute(nextcloudClient)
+ client.credentials = OwnCloudBasicCredentials("user1", "user1")
+ val userInfoResult = GetUserInfoRemoteOperation().execute(client)
assertTrue(userInfoResult.isSuccess)
-
val userInfo = userInfoResult.data[0] as UserInfo
- assertEquals("User One", userInfo.displayName)
- assertEquals("user1", userInfo.id)
+
+ assertEquals("User One", userInfo.getDisplayName())
+ assertEquals("user1", userInfo.getId())
assertEquals(GetUserInfoRemoteOperation.SPACE_UNLIMITED,
- userInfo.quota?.quota)
+ userInfo.getQuota().getQuota())
}
@Test
fun testGetUser1GbQuota() {
- nextcloudClient.credentials = Credentials.basic("user2", "user2")
- val userInfoResult = GetUserInfoRemoteOperation().execute(nextcloudClient)
+ client.credentials = OwnCloudBasicCredentials("user2", "user2")
+ val userInfoResult = GetUserInfoRemoteOperation().execute(client)
assertTrue(userInfoResult.isSuccess)
-
val userInfo = userInfoResult.data[0] as UserInfo
- assertEquals("User Two", userInfo.displayName)
- assertEquals("user2", userInfo.id)
- assertEquals(1073741824L, userInfo.quota?.quota)
+
+ assertEquals("User Two", userInfo.getDisplayName())
+ assertEquals("user2", userInfo.getId())
+ assertEquals(1073741824, userInfo.getQuota().getQuota())
}
@After
@@ -70,6 +70,6 @@ class GetUserInfoRemoteOperationTest : AbstractIT() {
val loginName = arguments.getString("TEST_SERVER_USERNAME")
val password = arguments.getString("TEST_SERVER_PASSWORD")
- nextcloudClient.credentials = Credentials.basic(loginName, password)
+ client.credentials = OwnCloudBasicCredentials(loginName, password)
}
}
diff --git a/src/main/java/com/owncloud/android/lib/resources/activities/GetActivitiesRemoteOperation.java b/src/main/java/com/owncloud/android/lib/resources/activities/GetActivitiesRemoteOperation.java
index fc60dfecc..abd58d830 100644
--- a/src/main/java/com/owncloud/android/lib/resources/activities/GetActivitiesRemoteOperation.java
+++ b/src/main/java/com/owncloud/android/lib/resources/activities/GetActivitiesRemoteOperation.java
@@ -34,6 +34,8 @@
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
+import com.nextcloud.common.NextcloudClient;
+import com.nextcloud.operations.GetMethod;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -48,11 +50,11 @@
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.httpclient.methods.GetMethod;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
/**
@@ -94,12 +96,80 @@ public GetActivitiesRemoteOperation(int lastGiven) {
}
@Override
- protected RemoteOperationResult run(OwnCloudClient client) {
+ protected RemoteOperationResult run(NextcloudClient client) {
RemoteOperationResult result;
int status;
GetMethod get = null;
ArrayList activities;
String url = client.getBaseUri() + OCS_ROUTE_V12_AND_UP;
+
+ // add filter for fileId, if available
+ if (!fileId.isEmpty()) {
+ url = url + "/filter";
+ }
+
+ Log_OC.d(TAG, "URL: " + url);
+
+ try {
+ get = new GetMethod(url, true);
+
+ HashMap parameters = new HashMap<>();
+ parameters.put("format", "json");
+ parameters.put("previews", "true");
+
+ if (lastGiven != -1) {
+ parameters.put("since", String.valueOf(lastGiven));
+ }
+
+ if (!fileId.isEmpty()) {
+ parameters.put("sort", "desc");
+ parameters.put("object_type", "files");
+ parameters.put("object_id", fileId);
+ }
+
+ get.setQueryString(parameters);
+
+ status = client.execute(get);
+ String response = get.getResponseBodyAsString();
+
+ String nextPageHeader = get.response.header("X-Activity-Last-Given");
+ if (nextPageHeader != null) {
+ lastGiven = Integer.parseInt(nextPageHeader);
+ } else {
+ lastGiven = -1;
+ }
+
+ if (isSuccess(status)) {
+ Log_OC.d(TAG, "Successful response: " + response);
+ result = new RemoteOperationResult(true, get);
+ // Parse the response
+ activities = parseResult(response);
+
+ ArrayList