Resource in KVV aktualliesiert

This commit is contained in:
Joshua
2018-09-16 17:13:22 +02:00
parent 7b4fd9dfab
commit 95cef20bb8
2 changed files with 101 additions and 21 deletions

View File

@@ -470,7 +470,16 @@ class KVVModuleList extends HTTPService {
String title = site.getString("title"); String title = site.getString("title");
long modifiedDate = site.getLong("modifiedDate"); long modifiedDate = site.getLong("modifiedDate");
String url = site.getString("url"); String url = site.getString("url");
resources.add(new Resource(author, title, modifiedDate, url)); boolean visible = site.getBoolean("visible");
String type = site.getString("type");
String container = site.getString("container");
if (type.equals("collection")){
resources.add(new Resource.Folder(author, title, modifiedDate, url, visible, container));
}
else {
resources.add(new Resource.File(author, title, modifiedDate, url, visible, container, type));
}
} }
} catch (JSONException e) { } catch (JSONException e) {
@@ -478,14 +487,30 @@ class KVVModuleList extends HTTPService {
errorCallback.onError(new NetworkError(101602, 403, "Cannot parse resources!")); errorCallback.onError(new NetworkError(101602, 403, "Cannot parse resources!"));
return; return;
} }
ArrayList<Resource> root = new ArrayList<>();
for (Resource res: resources) {//Verzeichnisstrucktur anlegen
if (!res.getContainer().equals("/content/group/")) {
if (res.getContainer().equals("/content/group/"+ID+"/")){//ist File im Hauptordner
root.add(res);
}
else{
for (Resource res2: resources) { // im Unterordner
if (res2.getUrl().endsWith(res.getContainer()) && res2 instanceof Resource.Folder){
((Resource.Folder) res2).add(res);//File bzw. Ordner anfügen
}
}
}
}
}
log.d(root);
// Empty resources *may be* because token is invalid -> check // Empty resources *may be* because token is invalid -> check
if (resources.size() == 0) if (root.size() == 0)
testLogin(token, token -> callback.onResponse(resources), errorCallback); testLogin(token, token -> callback.onResponse(root), errorCallback);
else else
callback.onResponse(resources); callback.onResponse(root);
callback.onResponse(resources);
}, error -> errorCallback.onError(new NetworkError(101603, error.networkResponse.statusCode, "Cannot get resources!"))); }, error -> errorCallback.onError(new NetworkError(101603, error.networkResponse.statusCode, "Cannot get resources!")));
} }

View File

@@ -1,22 +1,26 @@
package de.sebse.fuplanner.services.KVV.types; package de.sebse.fuplanner.services.KVV.types;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
public abstract class Resource implements Serializable {
public class Resource implements Serializable { protected final String author;
protected final long modifiedDate;
private final String author; protected final String title;
private final long modifiedDate; protected final String url;
private final String title; protected final boolean visible;
private final String url; protected final String container;
public Resource(String author, String title, long modifiedDate, String url) { public Resource(String author, String title, long modifiedDate, String url, boolean visible, String container) {
this.author = author; this.author = author;
this.title = title; this.title = title;
this.modifiedDate = modifiedDate; this.modifiedDate = modifiedDate;
this.url = url; this.url = url;
this.visible = visible;
this.container = container;
} }
public String getAuthor() { public String getAuthor() {
@@ -35,6 +39,24 @@ public class Resource implements Serializable {
return url; return url;
} }
public String getContainer() {
return container;
}
public boolean isVisible() {
return visible;
}
public static class File extends Resource {
private final String type;
public File(String author, String title, long modifiedDate, String url, boolean visible, String container, String type) {
super(author, title, modifiedDate, url, visible, container);
this.type = type;
}
@Override @Override
public String toString() { public String toString() {
return "Resource{" + return "Resource{" +
@@ -42,9 +64,42 @@ public class Resource implements Serializable {
", modifiedDate=" + modifiedDate + ", modifiedDate=" + modifiedDate +
", title='" + title + '\'' + ", title='" + title + '\'' +
", url='" + url + '\'' + ", url='" + url + '\'' +
", type='" + type + '\'' +
'}'; '}';
} }
}
public static class Folder extends Resource{
private final ArrayList<Resource> childs;
public Folder(String author, String title, long modifiedDate, String url, boolean visible, String container) {
super(author, title, modifiedDate, url, visible, container);
childs = new ArrayList<>();
}
public void add(Resource res){
childs.add(res);
}
public Resource get(int id){
return childs.get(id);
}
public int size(){
return childs.size();
}
@Override
public String toString() {
return "Resource{" +
"author='" + author + '\'' +
", modifiedDate=" + modifiedDate +
", title='" + title + '\'' +
", url='" + url + '\'' +
", childs='" + childs + '\'' +
'}';
}
}
} }