Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/android-library.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMario Đanić <mario.danic@gmail.com>2017-04-20 23:46:05 +0300
committerGitHub <noreply@github.com>2017-04-20 23:46:05 +0300
commitd3dc3e277b8bf5b390ffd7c7aa650d9d7adf74b6 (patch)
tree7a00af1a282f1cdf68af69ccba680c80e51cb61d
parent57f13ba591603ac23d3c10f7dede8dda46706adf (diff)
parent41a44e803a02df4cc62c54cdfa175fe357a343b2 (diff)
Merge pull request #57 from nextcloud/externalLinks1.0.15
External links
-rw-r--r--src/com/owncloud/android/lib/common/ExternalLink.java51
-rw-r--r--src/com/owncloud/android/lib/common/ExternalLinkType.java5
-rw-r--r--src/com/owncloud/android/lib/common/accounts/ExternalLinksOperation.java156
-rw-r--r--src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java3
-rw-r--r--src/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.java21
-rw-r--r--src/com/owncloud/android/lib/resources/status/OCCapability.java10
6 files changed, 245 insertions, 1 deletions
diff --git a/src/com/owncloud/android/lib/common/ExternalLink.java b/src/com/owncloud/android/lib/common/ExternalLink.java
new file mode 100644
index 00000000..b77239b0
--- /dev/null
+++ b/src/com/owncloud/android/lib/common/ExternalLink.java
@@ -0,0 +1,51 @@
+/**
+ * Nextcloud Android client application
+ *
+ * @author Tobias Kaminsky
+ * Copyright (C) 2017 Nextcloud GmbH.
+ * <p>
+ * 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.
+ * <p>
+ * 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.
+ * <p>
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.owncloud.android.lib.common;
+
+import org.parceler.Parcel;
+
+/**
+ * Quota data model
+ */
+
+@Parcel
+public class ExternalLink {
+ public Integer id;
+ public String iconUrl;
+ public String language;
+ public ExternalLinkType type;
+ public String name;
+ public String url;
+
+ public ExternalLink() {
+
+ }
+
+ public ExternalLink(Integer id, String iconUrl, String language, ExternalLinkType type, String name, String url) {
+ this.id = id;
+ this.iconUrl = iconUrl;
+ this.language = language;
+ this.type = type;
+ this.name = name;
+ this.url = url;
+ }
+}
+
diff --git a/src/com/owncloud/android/lib/common/ExternalLinkType.java b/src/com/owncloud/android/lib/common/ExternalLinkType.java
new file mode 100644
index 00000000..68e4c19a
--- /dev/null
+++ b/src/com/owncloud/android/lib/common/ExternalLinkType.java
@@ -0,0 +1,5 @@
+package com.owncloud.android.lib.common;
+
+public enum ExternalLinkType {
+ LINK, SETTINGS, QUOTA, UNKNOWN
+}
diff --git a/src/com/owncloud/android/lib/common/accounts/ExternalLinksOperation.java b/src/com/owncloud/android/lib/common/accounts/ExternalLinksOperation.java
new file mode 100644
index 00000000..bc7e1bfd
--- /dev/null
+++ b/src/com/owncloud/android/lib/common/accounts/ExternalLinksOperation.java
@@ -0,0 +1,156 @@
+/**
+ * Nextcloud Android client application
+ *
+ * @author Tobias Kaminsky
+ * Copyright (C) 2017 Nextcloud GmbH.
+ * <p>
+ * 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.
+ * <p>
+ * 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.
+ * <p>
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.owncloud.android.lib.common.accounts;
+
+import com.owncloud.android.lib.common.ExternalLink;
+import com.owncloud.android.lib.common.ExternalLinkType;
+import com.owncloud.android.lib.common.OwnCloudClient;
+import com.owncloud.android.lib.common.operations.RemoteOperation;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.lib.resources.status.GetRemoteCapabilitiesOperation;
+import com.owncloud.android.lib.resources.status.OCCapability;
+
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+
+/**
+ * gets external links provided by 'external' app
+ */
+
+public class ExternalLinksOperation extends RemoteOperation {
+
+ private static final String TAG = ExternalLinksOperation.class.getSimpleName();
+
+ // OCS Route
+ private static final String OCS_ROUTE_EXTERNAL_LINKS = "/ocs/v2.php/apps/external/api/v1";
+
+ // JSON Node names
+ private static final String NODE_OCS = "ocs";
+ private static final String NODE_DATA = "data";
+ private static final String NODE_ID = "id";
+ private static final String NODE_ICON = "icon";
+ private static final String NODE_LANGUAGE = "lang";
+ private static final String NODE_TYPE = "type";
+ private static final String NODE_NAME = "name";
+ private static final String NODE_URL = "url";
+
+
+ @Override
+ protected RemoteOperationResult run(OwnCloudClient client) {
+ RemoteOperationResult result = null;
+ int status = -1;
+ GetMethod get = null;
+ String ocsUrl = client.getBaseUri() + OCS_ROUTE_EXTERNAL_LINKS;
+
+ try {
+ // check capabilities
+ RemoteOperation getCapabilities = new GetRemoteCapabilitiesOperation();
+ RemoteOperationResult capabilitiesResult = getCapabilities.execute(client);
+ OCCapability capability = (OCCapability) capabilitiesResult.getData().get(0);
+
+ if (capability.getExternalLinks().isTrue()) {
+
+ get = new GetMethod(ocsUrl);
+ get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
+ get.setQueryString(new NameValuePair[]{new NameValuePair("format", "json")});
+ status = client.executeMethod(get);
+
+ if (isSuccess(status)) {
+ String response = get.getResponseBodyAsString();
+ Log_OC.d(TAG, "Successful response: " + response);
+
+ // parse
+ JSONArray links = new JSONObject(response).getJSONObject(NODE_OCS).getJSONArray(NODE_DATA);
+
+ ArrayList<Object> resultLinks = new ArrayList<>();
+
+ for (int i = 0; i < links.length(); i++) {
+ JSONObject link = links.getJSONObject(i);
+
+ if (link != null) {
+ Integer id = link.getInt(NODE_ID);
+ String iconUrl = link.getString(NODE_ICON);
+ String language = link.getString(NODE_LANGUAGE);
+
+ ExternalLinkType type;
+ switch (link.getString(NODE_TYPE)) {
+ case "link":
+ type = ExternalLinkType.LINK;
+ break;
+ case "settings":
+ type = ExternalLinkType.SETTINGS;
+ break;
+ case "quota":
+ type = ExternalLinkType.QUOTA;
+ break;
+ default:
+ type = ExternalLinkType.UNKNOWN;
+ break;
+ }
+
+
+ String name = link.getString(NODE_NAME);
+ String url = link.getString(NODE_URL);
+
+ resultLinks.add(new ExternalLink(id, iconUrl, language, type, name, url));
+ }
+ }
+
+ result = new RemoteOperationResult(true, status, get.getResponseHeaders());
+ result.setData(resultLinks);
+
+ } else {
+ result = new RemoteOperationResult(false, status, get.getResponseHeaders());
+ String response = get.getResponseBodyAsString();
+ Log_OC.e(TAG, "Failed response while getting external links ");
+ if (response != null) {
+ Log_OC.e(TAG, "*** status code: " + status + " ; response message: " + response);
+ } else {
+ Log_OC.e(TAG, "*** status code: " + status);
+ }
+ }
+ } else {
+ result = new RemoteOperationResult(RemoteOperationResult.ResultCode.NOT_AVAILABLE);
+ Log_OC.d(TAG, "External links disabled");
+ }
+
+ } catch (Exception e) {
+ result = new RemoteOperationResult(e);
+ Log_OC.e(TAG, "Exception while getting external links ", e);
+ } finally {
+ if (get != null) {
+ get.releaseConnection();
+ }
+ }
+
+ return result;
+ }
+
+ private boolean isSuccess(int status) {
+ return (status == HttpStatus.SC_OK);
+ }
+}
diff --git a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java
index d0d348d7..99f94911 100644
--- a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java
+++ b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java
@@ -117,7 +117,8 @@ public class RemoteOperationResult implements Serializable {
INVALID_CHARACTER_DETECT_IN_SERVER,
DELAYED_FOR_WIFI,
DELAYED_FOR_CHARGING,
- LOCAL_FILE_NOT_FOUND
+ LOCAL_FILE_NOT_FOUND,
+ NOT_AVAILABLE
}
private boolean mSuccess = false;
diff --git a/src/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.java b/src/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.java
index 5439878d..cf84489a 100644
--- a/src/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.java
+++ b/src/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.java
@@ -121,6 +121,11 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation {
private static final String PROPERTY_ICONS = "icons";
private static final String PROPERTY_RICH_STRINGS = "rich-strings";
+ // v1 external
+ private static final String NODE_EXTERNAL_LINKS = "external";
+ private static final String NODE_EXTERNAL_LINKS_V1 = "v1";
+ private static final String NODE_EXTERNAL_LINKS_SITES = "sites";
+
/**
* Constructor
*
@@ -292,6 +297,22 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation {
}
}
+ if (respCapabilities.has(NODE_EXTERNAL_LINKS)) {
+ JSONObject respExternalLinks = respCapabilities.getJSONObject(NODE_EXTERNAL_LINKS);
+
+ if (respExternalLinks.has(NODE_EXTERNAL_LINKS_V1)) {
+ JSONArray respExternalLinksV1 = respExternalLinks.getJSONArray(NODE_EXTERNAL_LINKS_V1);
+
+ String element = (String) respExternalLinksV1.get(0);
+
+ if (element.equalsIgnoreCase(NODE_EXTERNAL_LINKS_SITES)) {
+ capability.setExternalLinks(CapabilityBooleanType.TRUE);
+ } else {
+ capability.setExternalLinks(CapabilityBooleanType.FALSE);
+ }
+ }
+ }
+
}
// Result
data.add(capability);
diff --git a/src/com/owncloud/android/lib/resources/status/OCCapability.java b/src/com/owncloud/android/lib/resources/status/OCCapability.java
index b36d3e46..b2f8b95f 100644
--- a/src/com/owncloud/android/lib/resources/status/OCCapability.java
+++ b/src/com/owncloud/android/lib/resources/status/OCCapability.java
@@ -76,6 +76,8 @@ public class OCCapability {
private CapabilityBooleanType mSupportsNotificationsV1;
private CapabilityBooleanType mSupportsNotificationsV2;
+ private CapabilityBooleanType mExternalLinks;
+
public OCCapability(){
mId = 0;
mAccountName = "";
@@ -113,6 +115,8 @@ public class OCCapability {
mSupportsNotificationsV1 = CapabilityBooleanType.UNKNOWN;
mSupportsNotificationsV2 = CapabilityBooleanType.UNKNOWN;
+
+ mExternalLinks = CapabilityBooleanType.UNKNOWN;
}
@@ -370,6 +374,12 @@ public class OCCapability {
this.mFilesFileDrop = mFilesFileDrop;
}
+ public CapabilityBooleanType getExternalLinks() {
+ return mExternalLinks;
+ }
+ public void setExternalLinks(CapabilityBooleanType mExternalLinks) {
+ this.mExternalLinks = mExternalLinks;
+ }
}