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.RichSubject; import com.owncloud.android.lib.resources.activities.models.RichSubjectTypeAdapter; 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(RichSubject.class,new RichSubjectTypeAdapter())//Add TypeAdapter to parse RichSubject .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 RichSubject richSubject; public Date getDate() { return date; } Loading Loading @@ -169,4 +172,12 @@ public class Activity { public void setObjectName(String objectName) { this.objectName = objectName; } public RichSubject getRichSubject() { return richSubject; } public void setRichSubject(RichSubject richSubject) { this.richSubject = richSubject; } } src/com/owncloud/android/lib/resources/activities/models/RichObject.java 0 → 100644 +79 −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; 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; } } src/com/owncloud/android/lib/resources/activities/models/RichSubject.java 0 → 100644 +58 −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; /** * RichSubject Data Model */ public class RichSubject { 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/RichSubjectTypeAdapter.java 0 → 100644 +106 −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; /** * RichSubject Parser */ public class RichSubjectTypeAdapter extends TypeAdapter<RichSubject> { @Override public void write(JsonWriter out, RichSubject value) throws IOException { } @Override public RichSubject read(JsonReader in) throws IOException { RichSubject richSubject = new RichSubject(); in.beginArray(); int count = 0; while (in.hasNext()) { if (count == 0) { richSubject.setRichSubject(in.nextString()); } else { in.beginObject(); read(richSubject, in); in.endObject(); } count++; } in.endArray(); return richSubject; } private void read(RichSubject richSubject, JsonReader in) throws IOException { while (in.hasNext()) { String name = in.nextName(); if (name != null && !name.isEmpty()) { richSubject.getRichObjectList().add(readObject(in)); } } } RichObject readObject(JsonReader in) throws IOException { in.beginObject(); RichObject richObject = new RichObject(); 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; } } 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.RichSubject; import com.owncloud.android.lib.resources.activities.models.RichSubjectTypeAdapter; 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(RichSubject.class,new RichSubjectTypeAdapter())//Add TypeAdapter to parse RichSubject .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 RichSubject richSubject; public Date getDate() { return date; } Loading Loading @@ -169,4 +172,12 @@ public class Activity { public void setObjectName(String objectName) { this.objectName = objectName; } public RichSubject getRichSubject() { return richSubject; } public void setRichSubject(RichSubject richSubject) { this.richSubject = richSubject; } }
src/com/owncloud/android/lib/resources/activities/models/RichObject.java 0 → 100644 +79 −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; 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; } }
src/com/owncloud/android/lib/resources/activities/models/RichSubject.java 0 → 100644 +58 −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; /** * RichSubject Data Model */ public class RichSubject { 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/RichSubjectTypeAdapter.java 0 → 100644 +106 −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; /** * RichSubject Parser */ public class RichSubjectTypeAdapter extends TypeAdapter<RichSubject> { @Override public void write(JsonWriter out, RichSubject value) throws IOException { } @Override public RichSubject read(JsonReader in) throws IOException { RichSubject richSubject = new RichSubject(); in.beginArray(); int count = 0; while (in.hasNext()) { if (count == 0) { richSubject.setRichSubject(in.nextString()); } else { in.beginObject(); read(richSubject, in); in.endObject(); } count++; } in.endArray(); return richSubject; } private void read(RichSubject richSubject, JsonReader in) throws IOException { while (in.hasNext()) { String name = in.nextName(); if (name != null && !name.isEmpty()) { richSubject.getRichObjectList().add(readObject(in)); } } } RichObject readObject(JsonReader in) throws IOException { in.beginObject(); RichObject richObject = new RichObject(); 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; } }