Unfinished, unusable code
This commit is contained in:
@@ -115,10 +115,10 @@ public class ModulesList extends HTTPService {
|
|||||||
this.upgrade(success -> {
|
this.upgrade(success -> {
|
||||||
if (this.mModules == null)
|
if (this.mModules == null)
|
||||||
this.mModules = success;
|
this.mModules = success;
|
||||||
else
|
else if (this.mModules.updateList(success)) {
|
||||||
this.mModules.updateList(success);
|
|
||||||
mListener.onModuleListChange();
|
mListener.onModuleListChange();
|
||||||
store();
|
store();
|
||||||
|
}
|
||||||
callback.onResponse(this.mModules);
|
callback.onResponse(this.mModules);
|
||||||
mQueue.next();
|
mQueue.next();
|
||||||
}, error -> {
|
}, error -> {
|
||||||
|
|||||||
@@ -2,12 +2,15 @@ package de.sebse.fuplanner.services.kvv.types;
|
|||||||
|
|
||||||
import com.google.android.gms.common.internal.Objects;
|
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.ArrayList;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import de.sebse.fuplanner.tools.UtilsJson;
|
||||||
|
|
||||||
public class Announcement implements Serializable {
|
public class Announcement implements UtilsJson.JsonConvertable {
|
||||||
private final String id;
|
private final String id;
|
||||||
private final String title;
|
private final String title;
|
||||||
private final String body;
|
private final String body;
|
||||||
@@ -63,4 +66,16 @@ public class Announcement implements Serializable {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(getId(), getBody(), getCreatedBy(), getCreatedOn(), getTitle(), getUrls());
|
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,16 @@ package de.sebse.fuplanner.services.kvv.types;
|
|||||||
|
|
||||||
import com.google.android.gms.common.internal.Objects;
|
import com.google.android.gms.common.internal.Objects;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import de.sebse.fuplanner.tools.UtilsJson;
|
||||||
|
|
||||||
public class Assignment implements Serializable {
|
public class Assignment implements UtilsJson.JsonConvertable {
|
||||||
private final String id;
|
private final String id;
|
||||||
private final String title;
|
private final String title;
|
||||||
private final long dueTime;
|
private final long dueTime;
|
||||||
@@ -59,4 +63,15 @@ public class Assignment implements Serializable {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(getId(), getDueDate(), getInstructions(), getTitle(), getUrls());
|
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,6 +2,9 @@ package de.sebse.fuplanner.services.kvv.types;
|
|||||||
|
|
||||||
import com.google.android.gms.common.internal.Objects;
|
import com.google.android.gms.common.internal.Objects;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
@@ -9,8 +12,9 @@ import java.security.NoSuchAlgorithmException;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import de.sebse.fuplanner.tools.ColorRGB;
|
import de.sebse.fuplanner.tools.ColorRGB;
|
||||||
|
import de.sebse.fuplanner.tools.UtilsJson;
|
||||||
|
|
||||||
public class Event implements Serializable {
|
public class Event implements UtilsJson.JsonConvertable {
|
||||||
private final String siteId;
|
private final String siteId;
|
||||||
private final String id;
|
private final String id;
|
||||||
private final String type;
|
private final String type;
|
||||||
@@ -120,4 +124,17 @@ public class Event implements Serializable {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(getId(), getType(), getStartDate(), getEndDate(), getTitle(), getLocation());
|
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,15 @@ package de.sebse.fuplanner.services.kvv.types;
|
|||||||
|
|
||||||
import com.google.android.gms.common.internal.Objects;
|
import com.google.android.gms.common.internal.Objects;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import de.sebse.fuplanner.tools.UtilsJson;
|
||||||
|
|
||||||
public class Grade implements Serializable {
|
public class Grade implements UtilsJson.JsonConvertable {
|
||||||
private final String itemName;
|
private final String itemName;
|
||||||
private final double grade;
|
private final double grade;
|
||||||
private final double maxPoints;
|
private final double maxPoints;
|
||||||
@@ -41,4 +45,13 @@ public class Grade implements Serializable {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(getItemName(), getPoints(), getMaxPoints());
|
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;
|
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.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import de.sebse.fuplanner.tools.UtilsJson;
|
||||||
|
|
||||||
public class Lecturer implements Serializable {
|
public class Lecturer implements UtilsJson.JsonConvertable {
|
||||||
private final String firstName;
|
private final String firstName;
|
||||||
private final String surname;
|
private final String surname;
|
||||||
private final String mail;
|
private final String mail;
|
||||||
@@ -55,4 +60,19 @@ public class Lecturer implements Serializable {
|
|||||||
"\nSurname: "+getSurname()+
|
"\nSurname: "+getSurname()+
|
||||||
"\nMail: "+getMail();
|
"\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.
|
* Created by sebastian on 29.10.17.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class LoginToken implements Serializable {
|
public class LoginToken {
|
||||||
static Logger log = new Logger("LoginToken");
|
|
||||||
private static final String FILE_NAME = "LoginTokenSaving";
|
|
||||||
|
|
||||||
private final String username;
|
private final String username;
|
||||||
private final String shibsessionKey;
|
private final String shibsessionKey;
|
||||||
private final String shibsessionName;
|
private final String shibsessionName;
|
||||||
|
|||||||
@@ -2,14 +2,20 @@ package de.sebse.fuplanner.services.kvv.types;
|
|||||||
|
|
||||||
import android.content.Context;
|
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.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -17,16 +23,21 @@ import java.util.LinkedHashSet;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import de.sebse.fuplanner.tools.UtilsJson;
|
||||||
|
|
||||||
|
import static de.sebse.fuplanner.tools.UtilsJson.collectionToJson;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by sebastian on 29.10.17.
|
* 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 SortedListModule list;
|
||||||
private final String mUsername;
|
private final String mUsername;
|
||||||
|
private long mLoadTime;
|
||||||
//private transient Logger log = new Logger(this);
|
//private transient Logger log = new Logger(this);
|
||||||
private static final String FILE_NAME = "ModuleListSaving";
|
private static final String FILE_NAME = "ModuleListSaving";
|
||||||
|
private static final String FILE_NAME_TIMESTAMP = "ModuleListSavingTimestamp";
|
||||||
|
|
||||||
public Modules(String username) {
|
public Modules(String username) {
|
||||||
this.mUsername = username;
|
this.mUsername = username;
|
||||||
@@ -66,24 +77,51 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
return this.list.get(index);
|
return this.list.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Modules load(Context context) throws IOException, ClassNotFoundException {
|
public static Modules load(Context context) throws IOException {
|
||||||
FileInputStream fis = context.openFileInput(FILE_NAME);
|
String ret = "";
|
||||||
ObjectInputStream is = new ObjectInputStream(fis);
|
InputStream inputStream = context.openFileInput(FILE_NAME_TIMESTAMP);
|
||||||
Object readObject = is.readObject();
|
|
||||||
if (!(readObject instanceof Modules))
|
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 (int i = 0; i < arr.length(); i++) {
|
||||||
|
mod.list.add(Module.);
|
||||||
|
}
|
||||||
|
return mod
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
Modules modules = (Modules) readObject;
|
|
||||||
is.close();
|
|
||||||
fis.close();
|
|
||||||
return modules;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(Context context) throws IOException {
|
public void save(Context context) throws IOException {
|
||||||
FileOutputStream fos = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
|
JSONObject json = new JSONObject();
|
||||||
ObjectOutputStream os = new ObjectOutputStream(fos);
|
JSONArray jModules = new JSONArray();
|
||||||
os.writeObject(this);
|
try {
|
||||||
os.close();
|
json.put("username", mUsername);
|
||||||
fos.close();
|
json.put("modules", UtilsJson.collectionToJson(list));
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
mLoadTime = System.currentTimeMillis();
|
||||||
|
OutputStreamWriter osw = new OutputStreamWriter(context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE));
|
||||||
|
osw.write(json.toString());
|
||||||
|
osw.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(Context context) {
|
public void delete(Context context) {
|
||||||
@@ -94,27 +132,41 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
return mUsername;
|
return mUsername;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateList(Modules modules) {
|
public boolean updateList(Modules modules) {
|
||||||
SortedListModule old = this.list;
|
SortedListModule old = this.list;
|
||||||
this.list = modules.list;
|
this.list = modules.list;
|
||||||
|
boolean isChanged = false;
|
||||||
for (Module oldModule : old) {
|
for (Module oldModule : old) {
|
||||||
Module newModule = this.list.getById(oldModule.getID());
|
Module newModule = this.list.getById(oldModule.getID());
|
||||||
if (newModule != null) {
|
if (newModule != null) {
|
||||||
|
if (!isChanged && !hashEquals(oldModule, newModule))
|
||||||
|
isChanged = true;
|
||||||
newModule.announcements = oldModule.announcements;
|
newModule.announcements = oldModule.announcements;
|
||||||
newModule.assignments = oldModule.assignments;
|
newModule.assignments = oldModule.assignments;
|
||||||
newModule.events = oldModule.events;
|
newModule.events = oldModule.events;
|
||||||
newModule.gradebook = oldModule.gradebook;
|
newModule.gradebook = oldModule.gradebook;
|
||||||
newModule.resources = oldModule.resources;
|
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 class Module implements UtilsJson.JsonConvertable {
|
||||||
@Nullable public final Semester semester;
|
@Nullable public final Semester semester;
|
||||||
@NotNull final HashSet<String> lvNumber;
|
@NotNull final HashSet<String> lvNumber;
|
||||||
@NotNull public final String title;
|
@NotNull public final String title;
|
||||||
@NotNull
|
@NotNull public final ArrayList<Lecturer> lecturer;
|
||||||
public final ArrayList<Lecturer> lecturer;
|
|
||||||
@Nullable public final String type;
|
@Nullable public final String type;
|
||||||
@Nullable public final String description;
|
@Nullable public final String description;
|
||||||
@NotNull private final String ID;
|
@NotNull private final String ID;
|
||||||
@@ -124,6 +176,29 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
@Nullable public ArrayList<Grade> gradebook;
|
@Nullable public ArrayList<Grade> gradebook;
|
||||||
@Nullable public ArrayList<Resource> resources;
|
@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(){
|
public float getGradebookPercent(){
|
||||||
float maxPoint = 0;
|
float maxPoint = 0;
|
||||||
float userPoint = 0;
|
float userPoint = 0;
|
||||||
@@ -151,6 +226,27 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
this.ID = ID;
|
this.ID = ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Module(JSONObject json) throws JSONException {
|
||||||
|
HashSet hs = new HashSet<>();
|
||||||
|
Iterator<Object> it = UtilsJson.jsonArrayToIterator(json.getJSONArray("lvNumber"));
|
||||||
|
while (it.hasNext()) {
|
||||||
|
hs.
|
||||||
|
}
|
||||||
|
Module(new Semester(json.getJSONObject("semester")),
|
||||||
|
json.getString("lvNumber"),
|
||||||
|
json.getString("title"),
|
||||||
|
json.getJSONObject("lvNumber"),
|
||||||
|
|
||||||
|
json.getString("type"),
|
||||||
|
json.getString("description"),
|
||||||
|
json.getString("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));
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getID() {
|
public String getID() {
|
||||||
return ID;
|
return ID;
|
||||||
|
|||||||
@@ -2,17 +2,21 @@ package de.sebse.fuplanner.services.kvv.types;
|
|||||||
|
|
||||||
import com.google.android.gms.common.internal.Objects;
|
import com.google.android.gms.common.internal.Objects;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import de.sebse.fuplanner.R;
|
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.LayoutItemType;
|
||||||
import de.sebse.fuplanner.tools.ui.treeview.TreeNode;
|
import de.sebse.fuplanner.tools.ui.treeview.TreeNode;
|
||||||
|
|
||||||
|
|
||||||
public abstract class Resource implements Serializable {
|
public abstract class Resource implements UtilsJson.JsonConvertable {
|
||||||
|
|
||||||
final String author;
|
final String author;
|
||||||
final long modifiedDate;
|
final long modifiedDate;
|
||||||
@@ -62,6 +66,19 @@ public abstract class Resource implements Serializable {
|
|||||||
return Objects.hashCode(getAuthor(), getContainer(), getModifiedDate(), getTitle(), getUrl());
|
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 {
|
public static class File extends Resource implements LayoutItemType {
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
@@ -91,6 +108,14 @@ public abstract class Resource implements Serializable {
|
|||||||
public @LayoutRes int getLayoutId() {
|
public @LayoutRes int getLayoutId() {
|
||||||
return R.layout.item_file;
|
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 {
|
public static class Folder extends Resource implements LayoutItemType {
|
||||||
@@ -138,6 +163,14 @@ public abstract class Resource implements Serializable {
|
|||||||
public @LayoutRes int getLayoutId() {
|
public @LayoutRes int getLayoutId() {
|
||||||
return R.layout.item_dir;
|
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,15 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.types;
|
package de.sebse.fuplanner.services.kvv.types;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import de.sebse.fuplanner.tools.Regex;
|
import de.sebse.fuplanner.tools.Regex;
|
||||||
|
import de.sebse.fuplanner.tools.UtilsJson;
|
||||||
|
|
||||||
public class Semester implements Serializable {
|
public class Semester implements UtilsJson.JsonConvertable {
|
||||||
public static final int SEM_WS = 1;
|
public static final int SEM_WS = 1;
|
||||||
public static final int SEM_SS = 2;
|
public static final int SEM_SS = 2;
|
||||||
private int type;
|
private int type;
|
||||||
@@ -52,4 +56,12 @@ public class Semester implements Serializable {
|
|||||||
}
|
}
|
||||||
return false;
|
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;
|
package de.sebse.fuplanner.services.kvv.types;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import de.sebse.fuplanner.tools.SortedList;
|
import de.sebse.fuplanner.tools.SortedList;
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,11 @@ package de.sebse.fuplanner.tools;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
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<>();
|
private final ArrayList<T> internalList = new ArrayList<>();
|
||||||
|
|
||||||
|
|||||||
81
app/src/main/java/de/sebse/fuplanner/tools/UtilsJson.java
Normal file
81
app/src/main/java/de/sebse/fuplanner/tools/UtilsJson.java
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
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.Nullable;
|
||||||
|
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||||
|
import de.sebse.fuplanner.services.kvv.types.SortedListModule;
|
||||||
|
|
||||||
|
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 UtilsJson.JsonConvertable> 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 UtilsJson.JsonConvertable> 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 Iterator<Object> jsonArrayToIterator(JSONArray array) {
|
||||||
|
return new Iterator<Object>() {
|
||||||
|
int size = array == null ? 0 : array.length();
|
||||||
|
int pos = 0;
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return pos < size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object next() {
|
||||||
|
try {
|
||||||
|
return array.get(pos++);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface JsonConvertable {
|
||||||
|
JSONObject toJSONObject() throws JSONException;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user