Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit be075de6 authored by Mario Đanić's avatar Mario Đanić Committed by GitHub
Browse files

Merge branch 'master' into improveErrorFeedback

parents bd4517c1 37b86b2c
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ public class RemoteOperationResult implements Serializable {
    private Exception mException = null;
    private ResultCode mCode = ResultCode.UNKNOWN_ERROR;
    private String mRedirectedLocation;
    private String mAuthenticate;
    private ArrayList<String> mAuthenticateHeaders = new ArrayList<>();
    private String mLastPermanentLocation = null;

    private ArrayList<Object> mData;
@@ -199,7 +199,7 @@ public class RemoteOperationResult implements Serializable {
                    continue;
                }
                if ("www-authenticate".equals(current.getName().toLowerCase())) {
                    mAuthenticate = current.getValue();
                    mAuthenticateHeaders.add(current.getValue());
                    continue;
                }
            }
@@ -621,8 +621,8 @@ public class RemoteOperationResult implements Serializable {
        return (mRedirectedLocation != null && !(mRedirectedLocation.toLowerCase().startsWith("https://")));
    }

    public String getAuthenticateHeader() {
        return mAuthenticate;
    public ArrayList<String> getAuthenticateHeaders() {
        return mAuthenticateHeaders;
    }

    public String getLastPermanentLocation() {
+6 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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);
+11 −0
Original line number Diff line number Diff line
@@ -57,6 +57,9 @@ public class Activity {
    @SerializedName("object_name")
    public String objectName;

    @SerializedName("subject_rich")
    public RichElement richSubjectElement;

    public Date getDate() {
        return date;
    }
@@ -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;
    }
}
+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;
    }


}
+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;
    }
}
Loading