Loading src/com/owncloud/android/lib/resources/activities/GetActivitiesRemoteOperation.java +22 −7 Original line number Diff line number Diff line Loading @@ -40,12 +40,14 @@ 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; import com.owncloud.android.lib.resources.activities.model.RichElementTypeAdapter; import com.owncloud.android.lib.resources.activities.models.PreviewObject; import com.owncloud.android.lib.resources.activities.models.PreviewObjectAdapter; import com.owncloud.android.lib.resources.status.OwnCloudVersion; 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 org.json.JSONException; import java.lang.reflect.Type; import java.util.ArrayList; Loading @@ -63,7 +65,6 @@ public class GetActivitiesRemoteOperation extends RemoteOperation { // OCS Routes private static final String OCS_ROUTE_V12_AND_UP = "/ocs/v2.php/apps/activity/api/v2/activity"; private static final String OCS_ROUTE_PRE_V12 = "/ocs/v1.php/cloud/activity"; private static final String FORMAT_JSON = "?format=json"; // JSON Node names private static final String NODE_OCS = "ocs"; Loading Loading @@ -104,9 +105,7 @@ public class GetActivitiesRemoteOperation extends RemoteOperation { // add filter for fileId, if available if (!fileId.isEmpty()) { url = url + "/filter" + FORMAT_JSON + "&sort=desc&object_type=files&object_id=" + fileId; } else if (nextUrl.isEmpty()){ url = url + FORMAT_JSON; url = url + "/filter"; } Log_OC.d(TAG, "URL: " + url); Loading @@ -115,6 +114,21 @@ public class GetActivitiesRemoteOperation extends RemoteOperation { get = new GetMethod(url); get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); ArrayList<NameValuePair> parameters = new ArrayList<>(); parameters.add(new NameValuePair("format", "json")); if (client.getOwnCloudVersion().compareTo(OwnCloudVersion.nextcloud_12) >= 0) { parameters.add(new NameValuePair("previews", "true")); } if (!fileId.isEmpty()) { parameters.add(new NameValuePair("sort", "desc")); parameters.add(new NameValuePair("object_type", "files")); parameters.add(new NameValuePair("object_id", fileId)); } get.setQueryString(parameters.toArray(new NameValuePair[]{})); status = client.executeMethod(get); String response = get.getResponseBodyAsString(); Loading Loading @@ -169,13 +183,14 @@ public class GetActivitiesRemoteOperation extends RemoteOperation { return !nextUrl.isEmpty(); } private ArrayList<Activity> parseResult(String response) throws JSONException { private ArrayList<Activity> parseResult(String response) { JsonParser jsonParser = new JsonParser(); JsonObject jo = (JsonObject)jsonParser.parse(response); JsonArray jsonDataArray = jo.getAsJsonObject(NODE_OCS).getAsJsonArray(NODE_DATA); Gson gson = new GsonBuilder() .registerTypeAdapter(RichElement.class,new RichElementTypeAdapter())//Add TypeAdapter to parse RichElement .registerTypeAdapter(RichElement.class, new RichElementTypeAdapter()) .registerTypeAdapter(PreviewObject.class, new PreviewObjectAdapter()) .create(); Type listType = new TypeToken<List<Activity>>(){}.getType(); Loading src/com/owncloud/android/lib/resources/activities/model/Activity.java +18 −2 Original line number Diff line number Diff line Loading @@ -26,8 +26,12 @@ package com.owncloud.android.lib.resources.activities.model; import com.google.gson.annotations.SerializedName; import com.owncloud.android.lib.resources.activities.models.PreviewObject; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; /** * Activity Data Model Loading @@ -46,7 +50,6 @@ public class Activity { @SerializedName("affecteduser") public String affectedUser; public String subject; public String message; public String icon; public String link; Loading @@ -56,7 +59,8 @@ public class Activity { public String objectId; @SerializedName("object_name") public String objectName; public List<PreviewObject> previews; public Map<Integer, String> objects; @SerializedName("subject_rich") public RichElement richSubjectElement; Loading Loading @@ -180,4 +184,16 @@ public class Activity { public void setRichSubjectElement(RichElement richSubjectElement) { this.richSubjectElement = richSubjectElement; } public List<PreviewObject> getPreviews() { return previews; } public void setPreviews(ArrayList<PreviewObject> previews) { this.previews = previews; } public Map<Integer, String> getObjects() { return objects; } } src/com/owncloud/android/lib/resources/activities/model/RichElement.java +2 −2 Original line number Diff line number Diff line Loading @@ -33,8 +33,8 @@ import java.util.ArrayList; public class RichElement { public String richSubject; ArrayList<RichObject> richObjectList = new ArrayList<>(); private String richSubject; private ArrayList<RichObject> richObjectList = new ArrayList<>(); public String getRichSubject() { Loading src/com/owncloud/android/lib/resources/activities/models/PreviewObject.java 0 → 100644 +88 −0 Original line number Diff line number Diff line /* Nextcloud Android Library is available under MIT license * Copyright (C) 2017 Joas Schilling * * @author Joas Schilling * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ package com.owncloud.android.lib.resources.activities.models; /** * PreviewObject Data Model */ public class PreviewObject { private int fileId; private String source; private String link; private Boolean isMimeTypeIcon; private String mimeType; private String view; public String getLink() { return link; } public void setLink(String link) { this.link = link; } public String getSource() { return source; } public void setSource(String source) { this.source = source; } public Boolean isMimeTypeIcon() { return isMimeTypeIcon; } public void setMimeTypeIcon(Boolean mimeTypeIcon) { isMimeTypeIcon = mimeTypeIcon; } public String getMimeType() { return mimeType; } public void setMimeType(String mimeType) { this.mimeType = mimeType; } public int getFileId() { return fileId; } public void setFileId(int fileId) { this.fileId = fileId; } public String getView() { return view; } public void setView(String view) { this.view = view; } } src/com/owncloud/android/lib/resources/activities/models/PreviewObjectAdapter.java 0 → 100644 +103 −0 Original line number Diff line number Diff line /* Nextcloud Android Library is available under MIT license * Copyright (C) 2017 Joas Schilling * * @author Joas Schilling * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ package com.owncloud.android.lib.resources.activities.models; import com.google.gson.TypeAdapter; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; /** * PreviewList Parser */ public class PreviewObjectAdapter extends TypeAdapter<PreviewObject> { @Override public void write(JsonWriter out, PreviewObject value) { // not needed } @Override public PreviewObject read(JsonReader in) throws IOException { PreviewObject preview = new PreviewObject(); in.beginObject(); while (in.hasNext()) { String name = in.peek().toString(); if (!name.isEmpty()) { preview = readObject(in); } } in.endObject(); return preview; } private PreviewObject readObject(JsonReader in) throws IOException { String tag; PreviewObject preview = new PreviewObject(); do { tag = in.nextName(); switch (tag) { case "source": preview.setSource(in.nextString()); break; case "link": preview.setLink(in.nextString()); break; case "isMimeTypeIcon": preview.setMimeTypeIcon(in.nextBoolean()); break; case "mimeType": preview.setMimeType(in.nextString()); break; case "fileId": preview.setFileId(in.nextInt()); break; case "view": preview.setView(in.nextString()); break; default: // do nothing break; } } while (in.hasNext()); return preview; } } Loading
src/com/owncloud/android/lib/resources/activities/GetActivitiesRemoteOperation.java +22 −7 Original line number Diff line number Diff line Loading @@ -40,12 +40,14 @@ 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; import com.owncloud.android.lib.resources.activities.model.RichElementTypeAdapter; import com.owncloud.android.lib.resources.activities.models.PreviewObject; import com.owncloud.android.lib.resources.activities.models.PreviewObjectAdapter; import com.owncloud.android.lib.resources.status.OwnCloudVersion; 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 org.json.JSONException; import java.lang.reflect.Type; import java.util.ArrayList; Loading @@ -63,7 +65,6 @@ public class GetActivitiesRemoteOperation extends RemoteOperation { // OCS Routes private static final String OCS_ROUTE_V12_AND_UP = "/ocs/v2.php/apps/activity/api/v2/activity"; private static final String OCS_ROUTE_PRE_V12 = "/ocs/v1.php/cloud/activity"; private static final String FORMAT_JSON = "?format=json"; // JSON Node names private static final String NODE_OCS = "ocs"; Loading Loading @@ -104,9 +105,7 @@ public class GetActivitiesRemoteOperation extends RemoteOperation { // add filter for fileId, if available if (!fileId.isEmpty()) { url = url + "/filter" + FORMAT_JSON + "&sort=desc&object_type=files&object_id=" + fileId; } else if (nextUrl.isEmpty()){ url = url + FORMAT_JSON; url = url + "/filter"; } Log_OC.d(TAG, "URL: " + url); Loading @@ -115,6 +114,21 @@ public class GetActivitiesRemoteOperation extends RemoteOperation { get = new GetMethod(url); get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); ArrayList<NameValuePair> parameters = new ArrayList<>(); parameters.add(new NameValuePair("format", "json")); if (client.getOwnCloudVersion().compareTo(OwnCloudVersion.nextcloud_12) >= 0) { parameters.add(new NameValuePair("previews", "true")); } if (!fileId.isEmpty()) { parameters.add(new NameValuePair("sort", "desc")); parameters.add(new NameValuePair("object_type", "files")); parameters.add(new NameValuePair("object_id", fileId)); } get.setQueryString(parameters.toArray(new NameValuePair[]{})); status = client.executeMethod(get); String response = get.getResponseBodyAsString(); Loading Loading @@ -169,13 +183,14 @@ public class GetActivitiesRemoteOperation extends RemoteOperation { return !nextUrl.isEmpty(); } private ArrayList<Activity> parseResult(String response) throws JSONException { private ArrayList<Activity> parseResult(String response) { JsonParser jsonParser = new JsonParser(); JsonObject jo = (JsonObject)jsonParser.parse(response); JsonArray jsonDataArray = jo.getAsJsonObject(NODE_OCS).getAsJsonArray(NODE_DATA); Gson gson = new GsonBuilder() .registerTypeAdapter(RichElement.class,new RichElementTypeAdapter())//Add TypeAdapter to parse RichElement .registerTypeAdapter(RichElement.class, new RichElementTypeAdapter()) .registerTypeAdapter(PreviewObject.class, new PreviewObjectAdapter()) .create(); Type listType = new TypeToken<List<Activity>>(){}.getType(); Loading
src/com/owncloud/android/lib/resources/activities/model/Activity.java +18 −2 Original line number Diff line number Diff line Loading @@ -26,8 +26,12 @@ package com.owncloud.android.lib.resources.activities.model; import com.google.gson.annotations.SerializedName; import com.owncloud.android.lib.resources.activities.models.PreviewObject; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; /** * Activity Data Model Loading @@ -46,7 +50,6 @@ public class Activity { @SerializedName("affecteduser") public String affectedUser; public String subject; public String message; public String icon; public String link; Loading @@ -56,7 +59,8 @@ public class Activity { public String objectId; @SerializedName("object_name") public String objectName; public List<PreviewObject> previews; public Map<Integer, String> objects; @SerializedName("subject_rich") public RichElement richSubjectElement; Loading Loading @@ -180,4 +184,16 @@ public class Activity { public void setRichSubjectElement(RichElement richSubjectElement) { this.richSubjectElement = richSubjectElement; } public List<PreviewObject> getPreviews() { return previews; } public void setPreviews(ArrayList<PreviewObject> previews) { this.previews = previews; } public Map<Integer, String> getObjects() { return objects; } }
src/com/owncloud/android/lib/resources/activities/model/RichElement.java +2 −2 Original line number Diff line number Diff line Loading @@ -33,8 +33,8 @@ import java.util.ArrayList; public class RichElement { public String richSubject; ArrayList<RichObject> richObjectList = new ArrayList<>(); private String richSubject; private ArrayList<RichObject> richObjectList = new ArrayList<>(); public String getRichSubject() { Loading
src/com/owncloud/android/lib/resources/activities/models/PreviewObject.java 0 → 100644 +88 −0 Original line number Diff line number Diff line /* Nextcloud Android Library is available under MIT license * Copyright (C) 2017 Joas Schilling * * @author Joas Schilling * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ package com.owncloud.android.lib.resources.activities.models; /** * PreviewObject Data Model */ public class PreviewObject { private int fileId; private String source; private String link; private Boolean isMimeTypeIcon; private String mimeType; private String view; public String getLink() { return link; } public void setLink(String link) { this.link = link; } public String getSource() { return source; } public void setSource(String source) { this.source = source; } public Boolean isMimeTypeIcon() { return isMimeTypeIcon; } public void setMimeTypeIcon(Boolean mimeTypeIcon) { isMimeTypeIcon = mimeTypeIcon; } public String getMimeType() { return mimeType; } public void setMimeType(String mimeType) { this.mimeType = mimeType; } public int getFileId() { return fileId; } public void setFileId(int fileId) { this.fileId = fileId; } public String getView() { return view; } public void setView(String view) { this.view = view; } }
src/com/owncloud/android/lib/resources/activities/models/PreviewObjectAdapter.java 0 → 100644 +103 −0 Original line number Diff line number Diff line /* Nextcloud Android Library is available under MIT license * Copyright (C) 2017 Joas Schilling * * @author Joas Schilling * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ package com.owncloud.android.lib.resources.activities.models; import com.google.gson.TypeAdapter; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; /** * PreviewList Parser */ public class PreviewObjectAdapter extends TypeAdapter<PreviewObject> { @Override public void write(JsonWriter out, PreviewObject value) { // not needed } @Override public PreviewObject read(JsonReader in) throws IOException { PreviewObject preview = new PreviewObject(); in.beginObject(); while (in.hasNext()) { String name = in.peek().toString(); if (!name.isEmpty()) { preview = readObject(in); } } in.endObject(); return preview; } private PreviewObject readObject(JsonReader in) throws IOException { String tag; PreviewObject preview = new PreviewObject(); do { tag = in.nextName(); switch (tag) { case "source": preview.setSource(in.nextString()); break; case "link": preview.setLink(in.nextString()); break; case "isMimeTypeIcon": preview.setMimeTypeIcon(in.nextBoolean()); break; case "mimeType": preview.setMimeType(in.nextString()); break; case "fileId": preview.setFileId(in.nextInt()); break; case "view": preview.setView(in.nextString()); break; default: // do nothing break; } } while (in.hasNext()); return preview; } }