Loading src/com/owncloud/android/lib/resources/activities/GetRemoteActivitiesOperation.java +6 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ package com.owncloud.android.lib.resources.activities; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; Loading @@ -37,6 +38,8 @@ 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.activities.models.Activity; import com.owncloud.android.lib.resources.activities.models.RichElement; import com.owncloud.android.lib.resources.activities.models.RichElementTypeAdapter; import com.owncloud.android.lib.resources.status.OwnCloudVersion; import org.apache.commons.httpclient.HttpStatus; Loading Loading @@ -118,7 +121,9 @@ public class GetRemoteActivitiesOperation extends RemoteOperation{ JsonObject jo = (JsonObject)jsonParser.parse(response); JsonArray jsonDataArray = jo.getAsJsonObject(NODE_OCS).getAsJsonArray(NODE_DATA); Gson gson = new Gson(); Gson gson = new GsonBuilder() .registerTypeAdapter(RichElement.class,new RichElementTypeAdapter())//Add TypeAdapter to parse RichElement .create(); Type listType = new TypeToken<List<Activity>>(){}.getType(); return gson.fromJson(jsonDataArray, listType); Loading src/com/owncloud/android/lib/resources/activities/models/Activity.java +11 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,9 @@ public class Activity { @SerializedName("object_name") public String objectName; @SerializedName("subject_rich") public RichElement richSubjectElement; public Date getDate() { return date; } Loading Loading @@ -169,4 +172,12 @@ public class Activity { public void setObjectName(String objectName) { this.objectName = objectName; } public RichElement getRichSubjectElement() { return richSubjectElement; } public void setRichSubjectElement(RichElement richSubjectElement) { this.richSubjectElement = richSubjectElement; } } src/com/owncloud/android/lib/resources/activities/models/RichElement.java 0 → 100644 +57 −0 Original line number Diff line number Diff line /* Nextcloud Android Library is available under MIT license * Copyright (C) 2017 Alejandro Bautista * * @author Alejandro Bautista * * 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 java.util.ArrayList; /** * RichElement Data Model */ public class RichElement { public String richSubject; ArrayList<RichObject> richObjectList = new ArrayList<>(); public String getRichSubject() { return richSubject; } public void setRichSubject(String richSubject) { this.richSubject = richSubject; } public ArrayList<RichObject> getRichObjectList() { return richObjectList; } public void setRichObjectList(ArrayList<RichObject> richObjectList) { this.richObjectList = richObjectList; } } src/com/owncloud/android/lib/resources/activities/models/RichElementTypeAdapter.java 0 → 100644 +103 −0 Original line number Diff line number Diff line /* Nextcloud Android Library is available under MIT license * Copyright (C) 2017 Alejandro Bautista * * @author Alejandro Bautista * * 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; /** * RichElement Parser */ public class RichElementTypeAdapter extends TypeAdapter<RichElement> { @Override public void write(JsonWriter out, RichElement value) throws IOException { } @Override public RichElement read(JsonReader in) throws IOException { RichElement richElement = new RichElement(); in.beginArray(); int count = 0; while (in.hasNext()) { if (count == 0) { richElement.setRichSubject(in.nextString()); } else { in.beginObject(); read(richElement, in); in.endObject(); } count++; } in.endArray(); return richElement; } private void read(RichElement richElement, JsonReader in) throws IOException { while (in.hasNext()) { String name = in.nextName(); if (name != null && !name.isEmpty()) { richElement.getRichObjectList().add(readObject(name,in)); } } } RichObject readObject(String tag,JsonReader in) throws IOException { in.beginObject(); RichObject richObject = new RichObject(); richObject.setTag(tag); while (in.hasNext()) { String name = in.nextName(); if ("type".contentEquals(name)) richObject.setType(in.nextString()); else if ("id".contentEquals(name)) { richObject.setId(in.nextString()); }else if ("name".contentEquals(name)) richObject.setName(in.nextString()); else if ("path".contentEquals(name)) richObject.setPath(in.nextString()); else if ("link".contentEquals(name)) richObject.setLink(in.nextString()); else if ("server".contentEquals(name)) richObject.setLink(in.nextString()); } in.endObject(); return richObject; } } src/com/owncloud/android/lib/resources/activities/models/RichObject.java 0 → 100644 +88 −0 Original line number Diff line number Diff line /* Nextcloud Android Library is available under MIT license * Copyright (C) 2017 Alejandro Bautista * * @author Alejandro Bautista * * 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; /** * RichObject Data Model */ public class RichObject { String type; String id; String name; String path; String link; String tag; public String getType() { return type; } public void setType(String type) { this.type = type; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPath() { return path; } public void setPath(String path) { this.path = path; } public String getLink() { return link; } public void setLink(String link) { this.link = link; } public String getTag() { return tag; } public void setTag(String tag) { this.tag = tag; } } Loading
src/com/owncloud/android/lib/resources/activities/GetRemoteActivitiesOperation.java +6 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ package com.owncloud.android.lib.resources.activities; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; Loading @@ -37,6 +38,8 @@ 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.activities.models.Activity; import com.owncloud.android.lib.resources.activities.models.RichElement; import com.owncloud.android.lib.resources.activities.models.RichElementTypeAdapter; import com.owncloud.android.lib.resources.status.OwnCloudVersion; import org.apache.commons.httpclient.HttpStatus; Loading Loading @@ -118,7 +121,9 @@ public class GetRemoteActivitiesOperation extends RemoteOperation{ JsonObject jo = (JsonObject)jsonParser.parse(response); JsonArray jsonDataArray = jo.getAsJsonObject(NODE_OCS).getAsJsonArray(NODE_DATA); Gson gson = new Gson(); Gson gson = new GsonBuilder() .registerTypeAdapter(RichElement.class,new RichElementTypeAdapter())//Add TypeAdapter to parse RichElement .create(); Type listType = new TypeToken<List<Activity>>(){}.getType(); return gson.fromJson(jsonDataArray, listType); Loading
src/com/owncloud/android/lib/resources/activities/models/Activity.java +11 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,9 @@ public class Activity { @SerializedName("object_name") public String objectName; @SerializedName("subject_rich") public RichElement richSubjectElement; public Date getDate() { return date; } Loading Loading @@ -169,4 +172,12 @@ public class Activity { public void setObjectName(String objectName) { this.objectName = objectName; } public RichElement getRichSubjectElement() { return richSubjectElement; } public void setRichSubjectElement(RichElement richSubjectElement) { this.richSubjectElement = richSubjectElement; } }
src/com/owncloud/android/lib/resources/activities/models/RichElement.java 0 → 100644 +57 −0 Original line number Diff line number Diff line /* Nextcloud Android Library is available under MIT license * Copyright (C) 2017 Alejandro Bautista * * @author Alejandro Bautista * * 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 java.util.ArrayList; /** * RichElement Data Model */ public class RichElement { public String richSubject; ArrayList<RichObject> richObjectList = new ArrayList<>(); public String getRichSubject() { return richSubject; } public void setRichSubject(String richSubject) { this.richSubject = richSubject; } public ArrayList<RichObject> getRichObjectList() { return richObjectList; } public void setRichObjectList(ArrayList<RichObject> richObjectList) { this.richObjectList = richObjectList; } }
src/com/owncloud/android/lib/resources/activities/models/RichElementTypeAdapter.java 0 → 100644 +103 −0 Original line number Diff line number Diff line /* Nextcloud Android Library is available under MIT license * Copyright (C) 2017 Alejandro Bautista * * @author Alejandro Bautista * * 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; /** * RichElement Parser */ public class RichElementTypeAdapter extends TypeAdapter<RichElement> { @Override public void write(JsonWriter out, RichElement value) throws IOException { } @Override public RichElement read(JsonReader in) throws IOException { RichElement richElement = new RichElement(); in.beginArray(); int count = 0; while (in.hasNext()) { if (count == 0) { richElement.setRichSubject(in.nextString()); } else { in.beginObject(); read(richElement, in); in.endObject(); } count++; } in.endArray(); return richElement; } private void read(RichElement richElement, JsonReader in) throws IOException { while (in.hasNext()) { String name = in.nextName(); if (name != null && !name.isEmpty()) { richElement.getRichObjectList().add(readObject(name,in)); } } } RichObject readObject(String tag,JsonReader in) throws IOException { in.beginObject(); RichObject richObject = new RichObject(); richObject.setTag(tag); while (in.hasNext()) { String name = in.nextName(); if ("type".contentEquals(name)) richObject.setType(in.nextString()); else if ("id".contentEquals(name)) { richObject.setId(in.nextString()); }else if ("name".contentEquals(name)) richObject.setName(in.nextString()); else if ("path".contentEquals(name)) richObject.setPath(in.nextString()); else if ("link".contentEquals(name)) richObject.setLink(in.nextString()); else if ("server".contentEquals(name)) richObject.setLink(in.nextString()); } in.endObject(); return richObject; } }
src/com/owncloud/android/lib/resources/activities/models/RichObject.java 0 → 100644 +88 −0 Original line number Diff line number Diff line /* Nextcloud Android Library is available under MIT license * Copyright (C) 2017 Alejandro Bautista * * @author Alejandro Bautista * * 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; /** * RichObject Data Model */ public class RichObject { String type; String id; String name; String path; String link; String tag; public String getType() { return type; } public void setType(String type) { this.type = type; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPath() { return path; } public void setPath(String path) { this.path = path; } public String getLink() { return link; } public void setLink(String link) { this.link = link; } public String getTag() { return tag; } public void setTag(String tag) { this.tag = tag; } }