diff --git a/app/src/main/java/de/sebse/fuplanner/services/KVV/KVVModuleList.java b/app/src/main/java/de/sebse/fuplanner/services/KVV/KVVModuleList.java index 8633aaa..a88264d 100644 --- a/app/src/main/java/de/sebse/fuplanner/services/KVV/KVVModuleList.java +++ b/app/src/main/java/de/sebse/fuplanner/services/KVV/KVVModuleList.java @@ -470,7 +470,16 @@ class KVVModuleList extends HTTPService { String title = site.getString("title"); long modifiedDate = site.getLong("modifiedDate"); 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) { @@ -478,14 +487,30 @@ class KVVModuleList extends HTTPService { errorCallback.onError(new NetworkError(101602, 403, "Cannot parse resources!")); return; } + + ArrayList 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 - if (resources.size() == 0) - testLogin(token, token -> callback.onResponse(resources), errorCallback); + if (root.size() == 0) + testLogin(token, token -> callback.onResponse(root), errorCallback); else - callback.onResponse(resources); + callback.onResponse(root); - - callback.onResponse(resources); }, error -> errorCallback.onError(new NetworkError(101603, error.networkResponse.statusCode, "Cannot get resources!"))); } diff --git a/app/src/main/java/de/sebse/fuplanner/services/KVV/types/Resource.java b/app/src/main/java/de/sebse/fuplanner/services/KVV/types/Resource.java index 32ea9db..5365f96 100644 --- a/app/src/main/java/de/sebse/fuplanner/services/KVV/types/Resource.java +++ b/app/src/main/java/de/sebse/fuplanner/services/KVV/types/Resource.java @@ -1,22 +1,26 @@ package de.sebse.fuplanner.services.KVV.types; import java.io.Serializable; +import java.util.ArrayList; +public abstract class Resource implements Serializable { -public class Resource implements Serializable { - - private final String author; - private final long modifiedDate; - private final String title; - private final String url; + protected final String author; + protected final long modifiedDate; + protected final String title; + protected final String url; + protected final boolean visible; + 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.title = title; this.modifiedDate = modifiedDate; this.url = url; + this.visible = visible; + this.container = container; } public String getAuthor() { @@ -35,16 +39,67 @@ public class Resource implements Serializable { return url; } - @Override - public String toString() { - return "Resource{" + - "author='" + author + '\'' + - ", modifiedDate=" + modifiedDate + - ", title='" + title + '\'' + - ", url='" + 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 + public String toString() { + return "Resource{" + + "author='" + author + '\'' + + ", modifiedDate=" + modifiedDate + + ", title='" + title + '\'' + + ", url='" + url + '\'' + + ", type='" + type + '\'' + + '}'; + } + } + + public static class Folder extends Resource{ + + private final ArrayList 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 + '\'' + + '}'; + } + } } + +