Compare commits
3 Commits
kvv_rename
...
kvvservice
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6325f312ea | ||
|
|
e0ed23dec5 | ||
|
|
bb85911324 |
@@ -115,10 +115,10 @@ public class ModulesList extends HTTPService {
|
||||
this.upgrade(success -> {
|
||||
if (this.mModules == null)
|
||||
this.mModules = success;
|
||||
else
|
||||
this.mModules.updateList(success);
|
||||
mListener.onModuleListChange();
|
||||
store();
|
||||
else if (this.mModules.updateList(success)) {
|
||||
mListener.onModuleListChange();
|
||||
store();
|
||||
}
|
||||
callback.onResponse(this.mModules);
|
||||
mQueue.next();
|
||||
}, error -> {
|
||||
|
||||
@@ -2,12 +2,16 @@ package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import com.google.android.gms.common.internal.Objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import de.sebse.fuplanner.tools.UtilsJson;
|
||||
|
||||
public class Announcement implements Serializable {
|
||||
public class Announcement implements UtilsJson.JsonConvertible {
|
||||
private final String id;
|
||||
private final String title;
|
||||
private final String body;
|
||||
@@ -24,6 +28,19 @@ public class Announcement implements Serializable {
|
||||
this.urls = urls;
|
||||
}
|
||||
|
||||
public Announcement(JSONObject json) throws JSONException {
|
||||
this.id = json.getString("id");
|
||||
this.title = json.getString("title");
|
||||
this.body = json.getString("body");
|
||||
this.createdBy = json.getString("createdBy");
|
||||
this.createdOn = json.getLong("createdOn");
|
||||
ArrayList<String> urls = new ArrayList<>();
|
||||
for (String url: UtilsJson.jsonArrayToIterableString(json.getJSONArray("urls"))) {
|
||||
urls.add(url);
|
||||
}
|
||||
this.urls = urls;
|
||||
}
|
||||
|
||||
public ArrayList<String> getUrls() {
|
||||
return urls;
|
||||
}
|
||||
@@ -63,4 +80,16 @@ public class Announcement implements Serializable {
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId(), getBody(), getCreatedBy(), getCreatedOn(), getTitle(), getUrls());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJSONObject() throws JSONException {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
json.put("title", title);
|
||||
json.put("body", body);
|
||||
json.put("createdBy", createdBy);
|
||||
json.put("createdOn", createdOn);
|
||||
json.put("urls", UtilsJson.collectionToJson(urls));
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,15 @@ package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import com.google.android.gms.common.internal.Objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import de.sebse.fuplanner.tools.UtilsJson;
|
||||
|
||||
public class Assignment implements Serializable {
|
||||
public class Assignment implements UtilsJson.JsonConvertible {
|
||||
private final String id;
|
||||
private final String title;
|
||||
private final long dueTime;
|
||||
@@ -59,4 +62,15 @@ public class Assignment implements Serializable {
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId(), getDueDate(), getInstructions(), getTitle(), getUrls());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJSONObject() throws JSONException {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
json.put("title", title);
|
||||
json.put("dueTime", dueTime);
|
||||
json.put("createdBy", UtilsJson.collectionToJson(urls));
|
||||
json.put("instructions", instructions);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,18 @@ package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import com.google.android.gms.common.internal.Objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import de.sebse.fuplanner.tools.ColorRGB;
|
||||
import de.sebse.fuplanner.tools.UtilsJson;
|
||||
|
||||
public class Event implements Serializable {
|
||||
public class Event implements UtilsJson.JsonConvertible {
|
||||
private final String siteId;
|
||||
private final String id;
|
||||
private final String type;
|
||||
@@ -120,4 +123,17 @@ public class Event implements Serializable {
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getId(), getType(), getStartDate(), getEndDate(), getTitle(), getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJSONObject() throws JSONException {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("siteId", siteId);
|
||||
json.put("id", id);
|
||||
json.put("type", type);
|
||||
json.put("title", title);
|
||||
json.put("duration", duration);
|
||||
json.put("firstTime", firstTime);
|
||||
json.put("location", location);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@ package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import com.google.android.gms.common.internal.Objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import de.sebse.fuplanner.tools.UtilsJson;
|
||||
|
||||
public class Grade implements Serializable {
|
||||
public class Grade implements UtilsJson.JsonConvertible {
|
||||
private final String itemName;
|
||||
private final double grade;
|
||||
private final double maxPoints;
|
||||
@@ -41,4 +43,13 @@ public class Grade implements Serializable {
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getItemName(), getPoints(), getMaxPoints());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJSONObject() throws JSONException {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("itemName", itemName);
|
||||
json.put("grade", grade);
|
||||
json.put("maxPoints", maxPoints);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import java.io.Serializable;
|
||||
import com.google.android.gms.common.internal.Objects;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import de.sebse.fuplanner.tools.UtilsJson;
|
||||
|
||||
public class Lecturer implements Serializable {
|
||||
public class Lecturer implements UtilsJson.JsonConvertible {
|
||||
private final String firstName;
|
||||
private final String surname;
|
||||
private final String mail;
|
||||
@@ -24,6 +29,13 @@ public class Lecturer implements Serializable {
|
||||
this.isResponsible = matcher.group(4).equals("true");
|
||||
}
|
||||
|
||||
public Lecturer(JSONObject json) throws JSONException {
|
||||
this.firstName = json.getString("firstName");
|
||||
this.surname = json.getString("surname");
|
||||
this.mail = json.getString("mail");
|
||||
this.isResponsible = json.getBoolean("isResponsible");
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
@@ -55,4 +67,19 @@ public class Lecturer implements Serializable {
|
||||
"\nSurname: "+getSurname()+
|
||||
"\nMail: "+getMail();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getFirstName(), getSurname(), getMail(), isResponsible());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJSONObject() throws JSONException {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("firstName", firstName);
|
||||
json.put("surname", surname);
|
||||
json.put("mail", mail);
|
||||
json.put("isResponsible", isResponsible);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,7 @@ import de.sebse.fuplanner.tools.logging.Logger;
|
||||
* Created by sebastian on 29.10.17.
|
||||
*/
|
||||
|
||||
public class LoginToken implements Serializable {
|
||||
static Logger log = new Logger("LoginToken");
|
||||
private static final String FILE_NAME = "LoginTokenSaving";
|
||||
|
||||
public class LoginToken {
|
||||
private final String username;
|
||||
private final String shibsessionKey;
|
||||
private final String shibsessionName;
|
||||
|
||||
@@ -2,14 +2,23 @@ package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.google.android.gms.common.internal.Objects;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -17,16 +26,22 @@ import java.util.LinkedHashSet;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import de.sebse.fuplanner.tools.UtilsJson;
|
||||
|
||||
import static de.sebse.fuplanner.tools.UtilsJson.collectionToJson;
|
||||
import static de.sebse.fuplanner.tools.UtilsJson.jsonArrayToIterableObject;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 29.10.17.
|
||||
*/
|
||||
|
||||
public class Modules implements Iterable<Modules.Module>, Serializable {
|
||||
public class Modules implements Iterable<Modules.Module> {
|
||||
private SortedListModule list;
|
||||
private final String mUsername;
|
||||
private long mLoadTime;
|
||||
//private transient Logger log = new Logger(this);
|
||||
private static final String FILE_NAME = "ModuleListSaving";
|
||||
private static final String FILE_NAME_TIMESTAMP = "ModuleListSavingTimestamp";
|
||||
|
||||
public Modules(String username) {
|
||||
this.mUsername = username;
|
||||
@@ -66,24 +81,54 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
||||
return this.list.get(index);
|
||||
}
|
||||
|
||||
public static Modules load(Context context) throws IOException, ClassNotFoundException {
|
||||
FileInputStream fis = context.openFileInput(FILE_NAME);
|
||||
ObjectInputStream is = new ObjectInputStream(fis);
|
||||
Object readObject = is.readObject();
|
||||
if (!(readObject instanceof Modules))
|
||||
return null;
|
||||
Modules modules = (Modules) readObject;
|
||||
is.close();
|
||||
fis.close();
|
||||
return modules;
|
||||
public static Modules load(Context context) throws IOException {
|
||||
String ret = "";
|
||||
InputStream inputStream = context.openFileInput(FILE_NAME);
|
||||
if (inputStream != null) {
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
|
||||
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
||||
String receiveString;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
while ((receiveString = bufferedReader.readLine()) != null) {
|
||||
stringBuilder.append(receiveString);
|
||||
}
|
||||
inputStream.close();
|
||||
ret = stringBuilder.toString();
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject json = new JSONObject(ret);
|
||||
Modules mod = new Modules(json.getString("username"));
|
||||
JSONArray arr = json.getJSONArray("modules");
|
||||
for (JSONObject jsonObject: jsonArrayToIterableObject(arr)) {
|
||||
mod.list.add(new Module(jsonObject));
|
||||
}
|
||||
FileInputStream ofi = context.openFileInput(FILE_NAME_TIMESTAMP);
|
||||
ObjectInputStream inputStream1 = new ObjectInputStream(ofi);
|
||||
mod.mLoadTime = inputStream1.readLong();
|
||||
return mod;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void save(Context context) throws IOException {
|
||||
FileOutputStream fos = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
|
||||
ObjectOutputStream os = new ObjectOutputStream(fos);
|
||||
os.writeObject(this);
|
||||
os.close();
|
||||
fos.close();
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("username", mUsername);
|
||||
json.put("modules", UtilsJson.collectionToJson(list));
|
||||
OutputStreamWriter osw = new OutputStreamWriter(context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE));
|
||||
osw.write(json.toString());
|
||||
osw.close();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
mLoadTime = System.currentTimeMillis();
|
||||
FileOutputStream ofo = context.openFileOutput(FILE_NAME_TIMESTAMP, Context.MODE_PRIVATE);
|
||||
ObjectOutputStream outputStream = new ObjectOutputStream(ofo);
|
||||
outputStream.writeLong(mLoadTime);
|
||||
}
|
||||
|
||||
public void delete(Context context) {
|
||||
@@ -94,27 +139,41 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
||||
return mUsername;
|
||||
}
|
||||
|
||||
public void updateList(Modules modules) {
|
||||
public boolean updateList(Modules modules) {
|
||||
SortedListModule old = this.list;
|
||||
this.list = modules.list;
|
||||
boolean isChanged = false;
|
||||
for (Module oldModule : old) {
|
||||
Module newModule = this.list.getById(oldModule.getID());
|
||||
if (newModule != null) {
|
||||
if (!isChanged && !hashEquals(oldModule, newModule))
|
||||
isChanged = true;
|
||||
newModule.announcements = oldModule.announcements;
|
||||
newModule.assignments = oldModule.assignments;
|
||||
newModule.events = oldModule.events;
|
||||
newModule.gradebook = oldModule.gradebook;
|
||||
newModule.resources = oldModule.resources;
|
||||
} else {
|
||||
isChanged = true;
|
||||
}
|
||||
}
|
||||
return isChanged;
|
||||
}
|
||||
|
||||
public class Module implements Serializable {
|
||||
private boolean hashEquals(Module o1, Module o2) {
|
||||
if (o1 == null && o2 == null)
|
||||
return true;
|
||||
else if (o1 == null || o2 == null)
|
||||
return false;
|
||||
else
|
||||
return o1.hashCode() == o2.hashCode();
|
||||
}
|
||||
|
||||
public static class Module implements UtilsJson.JsonConvertible {
|
||||
@Nullable public final Semester semester;
|
||||
@NotNull final HashSet<String> lvNumber;
|
||||
@NotNull public final String title;
|
||||
@NotNull
|
||||
public final ArrayList<Lecturer> lecturer;
|
||||
@NotNull public final ArrayList<Lecturer> lecturer;
|
||||
@Nullable public final String type;
|
||||
@Nullable public final String description;
|
||||
@NotNull private final String ID;
|
||||
@@ -124,6 +183,29 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
||||
@Nullable public ArrayList<Grade> gradebook;
|
||||
@Nullable public ArrayList<Resource> resources;
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(semester, lvNumber, title, lecturer, type, description, ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJSONObject() throws JSONException {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("semester", semester != null ? semester.toJSONObject() : null);
|
||||
json.put("lvNumber", collectionToJson(lvNumber));
|
||||
json.put("title", title);
|
||||
json.put("lecturer", collectionToJson(lecturer));
|
||||
json.put("type", type);
|
||||
json.put("description", description);
|
||||
json.put("ID", ID);
|
||||
json.put("announcements", collectionToJson(announcements));
|
||||
json.put("assignments", collectionToJson(assignments));
|
||||
json.put("events", collectionToJson(events));
|
||||
json.put("gradebook", collectionToJson(gradebook));
|
||||
json.put("resources", collectionToJson(resources));
|
||||
return json;
|
||||
}
|
||||
|
||||
public float getGradebookPercent(){
|
||||
float maxPoint = 0;
|
||||
float userPoint = 0;
|
||||
@@ -151,6 +233,71 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
||||
this.ID = ID;
|
||||
}
|
||||
|
||||
private Module(@NotNull JSONObject json) throws JSONException {
|
||||
HashSet<String> lv = new HashSet<>();
|
||||
for (String number: UtilsJson.jsonArrayToIterableString(json.getJSONArray("lvNumber"))) {
|
||||
lv.add(number);
|
||||
}
|
||||
LinkedHashSet<Lecturer> lecturer = new LinkedHashSet<>();
|
||||
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(json.getJSONArray("lecturer"))) {
|
||||
lecturer.add(new Lecturer(l));
|
||||
}
|
||||
JSONObject obj = json.optJSONObject("semester");
|
||||
|
||||
this.semester = obj != null ? new Semester(obj) : null;
|
||||
this.lvNumber = lv;
|
||||
this.title = json.getString("title");
|
||||
this.lecturer = new ArrayList<>(lecturer);
|
||||
this.type = json.getString("type");
|
||||
this.description = json.getString("description");
|
||||
this.ID = json.getString("ID");
|
||||
|
||||
JSONArray arr = json.optJSONArray("announcements");
|
||||
if (obj != null) {
|
||||
ArrayList<Announcement> announce = new ArrayList<>();
|
||||
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(arr)) {
|
||||
announce.add(new Announcement(l));
|
||||
}
|
||||
this.announcements = announce;
|
||||
}
|
||||
arr = json.optJSONArray("assignments");
|
||||
if (obj != null) {
|
||||
AssignmentList assign = new AssignmentList();
|
||||
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(arr)) {
|
||||
assign.add(new Assignment(l));
|
||||
}
|
||||
this.assignments = assign;
|
||||
}
|
||||
|
||||
arr = json.optJSONArray("events");
|
||||
if (obj != null) {
|
||||
EventList events = new EventList();
|
||||
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(arr)) {
|
||||
events.add(new Event(l));
|
||||
}
|
||||
this.events = events;
|
||||
}
|
||||
arr = json.optJSONArray("gradebook");
|
||||
if (obj != null) {
|
||||
ArrayList<Grade> grades = new ArrayList<>();
|
||||
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(arr)) {
|
||||
grades.add(new Grade(l));
|
||||
}
|
||||
this.gradebook = grades;
|
||||
}
|
||||
arr = json.optJSONArray("resources");
|
||||
if (obj != null) {
|
||||
ArrayList<Resource> res = new ArrayList<>();
|
||||
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(arr)) {
|
||||
if (l.getString("restype").equals("file"))
|
||||
res.add(new Resource.File(l));
|
||||
else
|
||||
res.add(new Resource.Folder(l));
|
||||
}
|
||||
this.resources = res;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getID() {
|
||||
return ID;
|
||||
|
||||
@@ -2,17 +2,20 @@ package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import com.google.android.gms.common.internal.Objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.tools.UtilsJson;
|
||||
import de.sebse.fuplanner.tools.ui.treeview.LayoutItemType;
|
||||
import de.sebse.fuplanner.tools.ui.treeview.TreeNode;
|
||||
|
||||
|
||||
public abstract class Resource implements Serializable {
|
||||
public abstract class Resource implements UtilsJson.JsonConvertible {
|
||||
|
||||
final String author;
|
||||
final long modifiedDate;
|
||||
@@ -62,6 +65,19 @@ public abstract class Resource implements Serializable {
|
||||
return Objects.hashCode(getAuthor(), getContainer(), getModifiedDate(), getTitle(), getUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJSONObject() throws JSONException {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("author", author);
|
||||
json.put("modifiedDate", modifiedDate);
|
||||
json.put("title", title);
|
||||
json.put("url", url);
|
||||
json.put("visible", visible);
|
||||
json.put("container", container);
|
||||
json.put("restype", "");
|
||||
return json;
|
||||
}
|
||||
|
||||
public static class File extends Resource implements LayoutItemType {
|
||||
private final String type;
|
||||
|
||||
@@ -91,6 +107,14 @@ public abstract class Resource implements Serializable {
|
||||
public @LayoutRes int getLayoutId() {
|
||||
return R.layout.item_file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJSONObject() throws JSONException {
|
||||
JSONObject json = super.toJSONObject();
|
||||
json.put("type", type);
|
||||
json.put("restype", "file");
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Folder extends Resource implements LayoutItemType {
|
||||
@@ -138,6 +162,14 @@ public abstract class Resource implements Serializable {
|
||||
public @LayoutRes int getLayoutId() {
|
||||
return R.layout.item_dir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJSONObject() throws JSONException {
|
||||
JSONObject json = super.toJSONObject();
|
||||
json.put("children", UtilsJson.collectionToJson(children));
|
||||
json.put("restype", "dir");
|
||||
return json;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import de.sebse.fuplanner.tools.Regex;
|
||||
import de.sebse.fuplanner.tools.UtilsJson;
|
||||
|
||||
public class Semester implements Serializable {
|
||||
public class Semester implements UtilsJson.JsonConvertible {
|
||||
public static final int SEM_WS = 1;
|
||||
public static final int SEM_SS = 2;
|
||||
private int type;
|
||||
@@ -17,25 +19,17 @@ public class Semester implements Serializable {
|
||||
}
|
||||
|
||||
public Semester(String semester_string) throws NoSuchFieldException {
|
||||
/*Semester sem = null;
|
||||
if (semester != null) {
|
||||
sem = new Semester(semester)
|
||||
semester = semester.replace("SS", "S");
|
||||
semester = semester.replaceAll("[0-9]{2}([0-9]{2})", "$1");
|
||||
}*/
|
||||
|
||||
|
||||
/*String s1type = Regex.regex("^(S|WS) ", a);
|
||||
int s1year = Integer.parseInt(Regex.regex("^(S|WS) ([0-9]{2})", a, 2));
|
||||
String s2type = Regex.regex("^(S|WS) ", b);
|
||||
int s2year = Integer.parseInt(Regex.regex("^(S|WS) ([0-9]{2})", b, 2));*/
|
||||
|
||||
String type = Regex.regex("^(SS|WS) ", semester_string);
|
||||
String year = Regex.regex("^(SS|WS) ([0-9]{2})", semester_string, 2);
|
||||
this.type = type.equals("SS") ? SEM_SS : SEM_WS;
|
||||
this.year = Integer.parseInt(year);
|
||||
}
|
||||
|
||||
public Semester(JSONObject json) throws JSONException {
|
||||
this.type = json.getInt("type");
|
||||
this.year = json.getInt("year");
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
@@ -52,4 +46,12 @@ public class Semester implements Serializable {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJSONObject() throws JSONException {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("type", type);
|
||||
json.put("year", year);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import de.sebse.fuplanner.tools.SortedList;
|
||||
|
||||
|
||||
@@ -3,12 +3,11 @@ package de.sebse.fuplanner.tools;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
public abstract class SortedList<T, I, F> implements Iterable<T>, Serializable {
|
||||
public abstract class SortedList<T, I, F> implements Iterable<T> {
|
||||
|
||||
private final ArrayList<T> internalList = new ArrayList<>();
|
||||
|
||||
|
||||
109
app/src/main/java/de/sebse/fuplanner/tools/UtilsJson.java
Normal file
109
app/src/main/java/de/sebse/fuplanner/tools/UtilsJson.java
Normal file
@@ -0,0 +1,109 @@
|
||||
package de.sebse.fuplanner.tools;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class UtilsJson {
|
||||
public static JSONArray collectionToJson(@Nullable HashSet<String> coll) {
|
||||
if (coll == null)
|
||||
return null;
|
||||
JSONArray arr = new JSONArray();
|
||||
for (String e: coll) {
|
||||
arr.put(e);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static <E extends JsonConvertible> JSONArray collectionToJson(@Nullable Collection<E> coll) throws JSONException {
|
||||
if (coll == null)
|
||||
return null;
|
||||
JSONArray arr = new JSONArray();
|
||||
for (E e: coll) {
|
||||
arr.put(e.toJSONObject());
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static JSONArray collectionToJson(@Nullable ArrayList<String> coll) throws JSONException {
|
||||
if (coll == null)
|
||||
return null;
|
||||
JSONArray arr = new JSONArray();
|
||||
for (String e: coll) {
|
||||
arr.put(e);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static <A extends JsonConvertible> JSONArray collectionToJson(@Nullable SortedList<A, ?, ?> coll) throws JSONException {
|
||||
if (coll == null)
|
||||
return null;
|
||||
JSONArray arr = new JSONArray();
|
||||
for (A e: coll) {
|
||||
arr.put(e.toJSONObject());
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static <T> Iterator<T> jsonArrayToIterator(JSONArray array, GetInterface<T> func) {
|
||||
return new Iterator<T>() {
|
||||
int size = array == null ? 0 : array.length();
|
||||
int pos = 0;
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return pos < size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
try {
|
||||
return func.get(array, pos++);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface GetInterface<T> {
|
||||
T get(JSONArray array, int index) throws JSONException;
|
||||
}
|
||||
|
||||
public static JsonIterable<JSONObject> jsonArrayToIterableObject(JSONArray array) {
|
||||
return new JsonIterable<>(array, JSONArray::getJSONObject);
|
||||
}
|
||||
|
||||
public static JsonIterable<String> jsonArrayToIterableString(JSONArray array) {
|
||||
return new JsonIterable<>(array, JSONArray::getString);
|
||||
}
|
||||
|
||||
public static class JsonIterable<T> implements Iterable<T> {
|
||||
private JSONArray array;
|
||||
private GetInterface<T> getInterface;
|
||||
|
||||
JsonIterable(JSONArray array, GetInterface<T> getInterface) {
|
||||
this.array = array;
|
||||
this.getInterface = getInterface;
|
||||
}
|
||||
@NonNull
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return UtilsJson.jsonArrayToIterator(array, getInterface);
|
||||
}
|
||||
}
|
||||
|
||||
public interface JsonConvertible {
|
||||
JSONObject toJSONObject() throws JSONException;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,12 +17,3 @@ org.gradle.jvmargs=-Xmx1536m
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
|
||||
systemProp.http.proxyHost=proxy1-3.biotronik.int
|
||||
systemProp.http.proxyPort=9090
|
||||
systemProp.http.proxyUser=Sebastian%20Seedorf
|
||||
systemProp.http.proxyPassword=1111ApoTheke
|
||||
systemProp.https.proxyHost=proxy1-3.biotronik.int
|
||||
systemProp.https.proxyPort=9090
|
||||
systemProp.https.proxyUser=Sebastian%20Seedorf
|
||||
systemProp.https.proxyPassword=1111ApoTheke
|
||||
Reference in New Issue
Block a user