Rescource Clean Up

This commit is contained in:
Caesar2011
2018-08-02 17:23:53 +02:00
parent 13501308b3
commit 298608e4dc
5 changed files with 40 additions and 38 deletions

View File

@@ -20,12 +20,13 @@ class ModDetailAnnounceAdapter extends BaseExpandableListAdapter {
@Override
public String getChild(int groupPosition, int childPosititon) {
String s= this.getGroup(groupPosition).getBody();
StringBuilder s = new StringBuilder(this.getGroup(groupPosition).getBody());
ArrayList<String> urls = this.getGroup(groupPosition).getUrls();
for (int j =0; j<urls.size(); j++){
s += urls.get(j);
s.append("\n");
s.append(urls.get(j));
}
return s;
return s.toString();
}
@Override

View File

@@ -129,6 +129,14 @@ public class KVV {
getModulePart(modules -> modules.getGradebook(module, saveOnCallback(modules, callback, forceRefresh), errorOnCallback(error), forceRefresh));
}
public void getModuleResources(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback error) {
getModuleResources(module, callback, error, false);
}
public void getModuleResources(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback error, boolean forceRefresh) {
getModulePart(modules -> modules.getResources(module, saveOnCallback(modules, callback, forceRefresh), errorOnCallback(error), forceRefresh));
}
private void getModulePart(ModListFunction func) {

View File

@@ -24,7 +24,7 @@ import de.sebse.fuplanner.services.KVV.types.Lecturer;
import de.sebse.fuplanner.services.KVV.types.LoginToken;
import de.sebse.fuplanner.services.KVV.types.Modules;
import de.sebse.fuplanner.services.KVV.types.AssignmentList;
import de.sebse.fuplanner.services.KVV.types.Ressource;
import de.sebse.fuplanner.services.KVV.types.Resource;
import de.sebse.fuplanner.tools.AsyncQueue;
import de.sebse.fuplanner.services.KVV.types.EventList;
import de.sebse.fuplanner.tools.Regex;
@@ -121,7 +121,7 @@ class KVVModuleList extends HTTPService {
errorCallback.onError(new NetworkError(101103, 403, "Cannot parse module list!"));
return;
}
// Empty module may *may be* because token is invalid -> check
// Empty module *may be* because token is invalid -> check
if (modules.size() == 0)
testLogin(token, token -> callback.onResponse(modules), errorCallback);
else
@@ -175,7 +175,7 @@ class KVVModuleList extends HTTPService {
() -> this.getEvents(module, successCb, errorCb, forceRefresh),
() -> this.getAnnouncements(module, successCb, errorCb, forceRefresh),
() -> this.getGradebook(module, successCb, errorCb, forceRefresh),
() -> this.getRessourcen(module, successCb, errorCb, forceRefresh)
() -> this.getResources(module, successCb, errorCb, forceRefresh)
};
items.set(methods.length);
for (Runnable method: methods) {
@@ -245,7 +245,7 @@ class KVVModuleList extends HTTPService {
errorCallback.onError(new NetworkError(101202, 403, "Cannot parse announcements!"));
return;
}
// Empty announcements may *may be* because token is invalid -> check
// Empty announcements *may be* because token is invalid -> check
if (announcements.size() == 0)
testLogin(token, token -> callback.onResponse(announcements), errorCallback);
else
@@ -297,16 +297,11 @@ class KVVModuleList extends HTTPService {
long dueTime = site.getJSONObject("dueTime").getLong("time");
String gradebookItemName = site.optString("gradebookItemName", null);
String gradeScale = site.getString("gradeScale");
//PDFs links rausziehen
JSONArray attachments = site.getJSONArray("attachments");
ArrayList<String> urls = new ArrayList<>();
for (int j =0; j<attachments.length(); j++){
urls.add(attachments.getJSONObject(j).optString("url",null));
for (int j = 0; j<attachments.length(); j++){
urls.add(attachments.getJSONObject(j).getString("url"));
}
assignments.add(0, new Assignment(id, title, dueTime, gradebookItemName, gradeScale, urls, instructions));
}
} catch (JSONException e) {
@@ -314,7 +309,7 @@ class KVVModuleList extends HTTPService {
errorCallback.onError(new NetworkError(101302, 403, "Cannot parse announcements!"));
return;
}
// Empty assignments may *may be* because token is invalid -> check
// Empty assignments *may be* because token is invalid -> check
if (assignments.size() == 0)
testLogin(token, token -> callback.onResponse(assignments), errorCallback);
else
@@ -377,7 +372,7 @@ class KVVModuleList extends HTTPService {
return;
}
events.sort();
// Empty events may *may be* because token is invalid -> check
// Empty events *may be* because token is invalid -> check
if (events.size() == 0)
testLogin(token, token -> callback.onResponse(events), errorCallback);
else
@@ -439,23 +434,22 @@ class KVVModuleList extends HTTPService {
}
public void getRessourcen(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
public void getResources(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
queueModuleDetails.add(module.getID(), () -> {
if (module.ressource != null && !forceRefresh) {
if (module.resources != null && !forceRefresh) {
callback.onResponse(module);
queueModuleDetails.next(module.getID());
return;
}
getRessourcenUpgrade(module.getID(), success -> {
module.ressource = success;
getResourcesUpgrade(module.getID(), success -> {
module.resources = success;
callback.onResponse(module);
queueModuleDetails.next(module.getID());
}, queueModuleDetails.check(module.getID(), errorCallback));
});
}
private void getRessourcenUpgrade(String ID, final NetworkCallback<ArrayList<Ressource>> callback, final NetworkErrorCallback errorCallback) {
//log.d("Ressourcen Aufgerufen");
private void getResourcesUpgrade(String ID, final NetworkCallback<ArrayList<Resource>> callback, final NetworkErrorCallback errorCallback) {
if (token == null) {
errorCallback.onError(new NetworkError(101604, 500, "Currently running in offline mode!"));
return;
@@ -463,10 +457,10 @@ class KVVModuleList extends HTTPService {
get(String.format("https://kvv.imp.fu-berlin.de/direct/content/site/%s.json", ID ), token.getCookies(), response ->{
String body = response.getParsed();
if (body == null) {
errorCallback.onError(new NetworkError(101601, 403, "No Ressourcen retrieved!"));
errorCallback.onError(new NetworkError(101601, 403, "No resources retrieved!"));
return;
}
ArrayList<Ressource> ressourcen = new ArrayList<>();
ArrayList<Resource> resources = new ArrayList<>();
try {
JSONObject json = new JSONObject(body);
JSONArray sites = json.getJSONArray("content_collection");
@@ -477,24 +471,23 @@ class KVVModuleList extends HTTPService {
String title = site.getString("title");
long modifiedDate = site.getLong("modifiedDate");
String url = site.getString("url");
//log.d("Ressourcen:", author, title, modifiedDate, url);
ressourcen.add(new Ressource(author, title, modifiedDate, url));
resources.add(new Resource(author, title, modifiedDate, url));
}
} catch (JSONException e) {
e.printStackTrace();
errorCallback.onError(new NetworkError(101602, 403, "Cannot parse Ressourcen!"));
errorCallback.onError(new NetworkError(101602, 403, "Cannot parse resources!"));
return;
}
// Empty announcements may *may be* because token is invalid -> check
if (ressourcen.size() == 0)
testLogin(token, token -> callback.onResponse(ressourcen), errorCallback);
// Empty resources *may be* because token is invalid -> check
if (resources.size() == 0)
testLogin(token, token -> callback.onResponse(resources), errorCallback);
else
callback.onResponse(ressourcen);
callback.onResponse(resources);
callback.onResponse(ressourcen);
}, error -> errorCallback.onError(new NetworkError(101603, error.networkResponse.statusCode, "Cannot get Ressourcen for Ressourcen!")));
callback.onResponse(resources);
}, error -> errorCallback.onError(new NetworkError(101603, error.networkResponse.statusCode, "Cannot get resources!")));
}

View File

@@ -96,7 +96,7 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
newModule.assignments = oldModule.assignments;
newModule.events = oldModule.events;
newModule.gradebook = oldModule.gradebook;
newModule.ressource = oldModule.ressource;
newModule.resources = oldModule.resources;
}
}
}
@@ -113,7 +113,7 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
@Nullable public AssignmentList assignments;
@Nullable public EventList events;
@Nullable public ArrayList<Gradebook> gradebook;
public ArrayList<Ressource> ressource;
@Nullable public ArrayList<Resource> resources;
/*private Module() {
this(null, null, null, null, null);

View File

@@ -4,7 +4,7 @@ import java.io.Serializable;
public class Ressource implements Serializable {
public class Resource implements Serializable {
private final String author;
private final long modifiedDate;
@@ -12,7 +12,7 @@ public class Ressource implements Serializable {
private final String url;
public Ressource(String author, String title, long modifiedDate, String url) {
public Resource(String author, String title, long modifiedDate, String url) {
this.author = author;
this.title = title;
this.modifiedDate = modifiedDate;
@@ -37,7 +37,7 @@ public class Ressource implements Serializable {
@Override
public String toString() {
return "Ressource{" +
return "Resource{" +
"author='" + author + '\'' +
", modifiedDate=" + modifiedDate +
", title='" + title + '\'' +