Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Commit

Permalink
Merge 4563f23 into 91db04b
Browse files Browse the repository at this point in the history
  • Loading branch information
d-Rickyy-b committed Feb 2, 2020
2 parents 91db04b + 4563f23 commit 0ecbf5a
Show file tree
Hide file tree
Showing 15 changed files with 420 additions and 136 deletions.
14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ android {
applicationId "de.aurora.mggvertretungsplan"
minSdkVersion 15
targetSdkVersion 28
versionCode 30
versionCode 31
versionName "3.2.2"
multiDexEnabled true

Expand Down Expand Up @@ -78,16 +78,16 @@ dependencies {
testImplementation 'org.mockito:mockito-core:2.8.47'

// Support libraries
implementation 'com.google.android.material:material:1.1.0-alpha02'
implementation 'com.google.android.material:material:1.1.0-rc02'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha01'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.preference:preference:1.1.0-alpha02'
implementation 'androidx.preference:preference:1.1.0'
implementation 'androidx.browser:browser:1.0.0'
implementation 'androidx.core:core:1.1.0-alpha03'
implementation 'androidx.core:core:1.2.0-rc01'

implementation "android.arch.work:work-runtime:1.0.0-beta01"
implementation "android.arch.work:work-runtime:1.0.1"

// Other libraries
implementation 'org.jsoup:jsoup:1.10.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public DateHeading(Date date) {
}

public String getWholeDate() {
SimpleDateFormat wholeDate = new SimpleDateFormat("EEEE, dd.MM.yyyy", Locale.GERMANY);
SimpleDateFormat wholeDate = new SimpleDateFormat("EEEE, dd.MM.yyyy", Locale.getDefault());
return wholeDate.format(date);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public int getTotalCancellations(String className) {
return cancellations;
}

public int getTotalDifferences(TimeTable savedTimeTable, String className) {
public TimeTable getTotalDifferences(TimeTable savedTimeTable, String className) {
Logger.d(TAG, "Getting differences of saved and downloaded timetable!");
int differences = 0;
TimeTable differencesTimeTable = new TimeTable();
Date currentDate = new Date();
ArrayList<TimeTableDay> savedDays = savedTimeTable.getAllDays();

Expand All @@ -106,22 +106,24 @@ public int getTotalDifferences(TimeTable savedTimeTable, String className) {
for (TimeTableDay saved_ttd : savedDays) {
if (ttd.isSameDay(saved_ttd)) {
Logger.d(TAG, String.format("Dates are the same - %s | %s", ttd.getDateString(), saved_ttd.getDateString()));
Logger.d(TAG, String.format("%s", ttd.getElements(className).toString()));
Logger.d(TAG, String.format("%s", saved_ttd.getElements(className).toString()));
differences += ttd.getDifferences(saved_ttd, className);
Logger.d(TAG, String.format("New TTD : %s", ttd.getElements(className).toString()));
Logger.d(TAG, String.format("Stored TTD: %s", saved_ttd.getElements(className).toString()));
differencesTimeTable.addDay(ttd.getDifferences(saved_ttd, className));
newDay = false;
break;
}
}

if (newDay) {
int dayDiffs = ttd.getElementsCount(className);
differences += dayDiffs;
Logger.d(TAG, String.format(Locale.GERMANY,"New Day found - %d cancellations for %s", dayDiffs, className));

differencesTimeTable.addDay(ttd.getTTDbyClass(className));
//TODO Bug - ALL elements are added regardless of the class
Logger.d(TAG, String.format(Locale.getDefault(),"New Day found - %d cancellations for %s", dayDiffs, className));
}
}

return differences;
return differencesTimeTable;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.aurora.mggvertretungsplan.datamodel;

import android.content.Context;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -11,6 +13,7 @@
import java.util.GregorianCalendar;
import java.util.Locale;

import de.aurora.mggvertretungsplan.R;
import de.aurora.mggvertretungsplan.util.Logger;

/**
Expand All @@ -28,8 +31,8 @@ public TimeTableDay(String date, String week, ArrayList<ArrayList<String>> timeT
this.week = new Week(week);
setDate(date);

for (ArrayList<String> zeile : timeTableDay_List) {
TimeTableElement timeTableElement = new TimeTableElement(zeile.get(0), zeile.get(1), zeile.get(2), zeile.get(3), zeile.get(4), zeile.get(5), zeile.get(6));
for (ArrayList<String> row : timeTableDay_List) {
TimeTableElement timeTableElement = new TimeTableElement(row.get(0), row.get(1), row.get(2), row.get(3), row.get(4), row.get(5), row.get(6));
addElement(timeTableElement);
}

Expand All @@ -39,9 +42,7 @@ public TimeTableDay(String date, String week, ArrayList<ArrayList<String>> timeT
public TimeTableDay(Date date, Week week, ArrayList<TimeTableElement> timeTableElements) {
this.date = date;
this.week = week;
for (TimeTableElement tte: timeTableElements) {
addElement(tte);
}
this.timeTableElements.addAll(timeTableElements);
}

public TimeTableDay(JSONObject jsonObject) {
Expand All @@ -64,6 +65,40 @@ public TimeTableDay(JSONObject jsonObject) {
}
}

public String getNotificationTitle(Context context) {
String formatString = context.getString(R.string.notification_title_dateformat);
SimpleDateFormat sdf = new SimpleDateFormat(formatString, Locale.getDefault());
return sdf.format(this.date);
}

public String getNotificationTicker(Context context) {
return context.getString(R.string.notification_ticker);
}

public String getNotificationText(Context context) {
StringBuilder sb = new StringBuilder();

//'{hr}. Std: {subj} {action}'
String formatString = "%s. Std: %s %s\n";
for (TimeTableElement tte: this.timeTableElements) {
String action = "";
switch (tte.getType()) {
case TimeTableElement.SUBSTITUTION:
action = context.getString(R.string.cardInfo_representation);
break;
case TimeTableElement.CANCELLATION:
action = context.getString(R.string.cardInfo_cancelled);
break;
case TimeTableElement.EMPTY:
continue;
}

sb.append(String.format(formatString, tte.getHour(), tte.getSubject(), action));
}

return sb.toString().trim();
}

private void addElement(TimeTableElement tte) {
int index = 0;
for (int i = 0; i < timeTableElements.size(); i++) {
Expand Down Expand Up @@ -94,7 +129,7 @@ public Date getDate() {
}

private void setDate(String date) {
SimpleDateFormat fullDateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY);
SimpleDateFormat fullDateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.getDefault());
int currentYear = new GregorianCalendar().get(GregorianCalendar.YEAR);

try {
Expand All @@ -110,21 +145,25 @@ private void setDate(String date) {
}

public String getDateString() {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY);
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.getDefault());
return dateFormat.format(date);
}

public String getFullDateString() {
SimpleDateFormat fullDateFormat = new SimpleDateFormat("EEEE, dd.MM.yyyy", Locale.GERMANY);
SimpleDateFormat fullDateFormat = new SimpleDateFormat("EEEE, dd.MM.yyyy", Locale.getDefault());
return fullDateFormat.format(date);
}

public TimeTableDay getTTDbyClass(String className) {
return new TimeTableDay(this.date, this.week, this.getElements(className));
}

public ArrayList<TimeTableElement> getElements(String className) {
ArrayList<TimeTableElement> elementsOfClass = new ArrayList<>();
Grade grade = new Grade(className);

for (TimeTableElement tte : timeTableElements) {
String elementClassName = tte.getClass_name();
String elementClassName = tte.getClassName();
// TODO Remove the "contains" part
if (grade.matches(elementClassName) || elementClassName.contains(className))
elementsOfClass.add(tte);
Expand Down Expand Up @@ -160,8 +199,13 @@ public int getElementsCount(String className) {
return getElements(className).size();
}

// Returns the number of differences between two lists
public int getDifferences(TimeTableDay ttd, String className) {
/**
* Calculates the differences between two TimeTableDays
* @param ttd The old/saved Timetable to be compared against
* @param className The name of the class to search for
* @return New TimeTableDay containing only the new elements for a certain class
*/
TimeTableDay getDifferences(TimeTableDay ttd, String className) {
ArrayList<TimeTableElement> savedElements = ttd.getElements(className);
ArrayList<TimeTableElement> newElements = this.getElements(className);

Expand All @@ -181,26 +225,26 @@ public int getDifferences(TimeTableDay ttd, String className) {
}

// Remove similar elements, which are contained in both lists
for (int i = 0; i < newElements.size(); i++) {
TimeTableElement element1 = newElements.get(i);
for (int j = 0; j < savedElements.size(); j++) {
TimeTableElement element2 = savedElements.get(j);

if (element1.getDiffAmount(element2) == 1) {
for (TimeTableElement tte1: newElements) {
for (TimeTableElement tte2: savedElements) {
if (tte1.getDiffAmount(tte2) == 1) {
// This else part catches elements where only one part (hour, subject, etc.) has changed
// Without it, every *change* of an existing element would be counted twice
savedElements.remove(j);
savedElements.remove(tte2);
break;
}
}
}

// savedElements now contains only those elements which are no longer in the TimeTable
// newElements now only contains those elements which are new (not saved yet) or have changed in a single part
int changesToOldCancellations = savedElements.size();
int newCancellations = newElements.size();
// Set the elements, which are no longer in the TimeTableDay to inactive, so they can be notified as "removed"
for (TimeTableElement tte: savedElements) {
tte.setActive(false);
}

return changesToOldCancellations + newCancellations;
// savedElements now contains only those elements which are no longer in the TimeTableDay
// newElements now only contains those elements which are new (not saved yet) or have changed in a single part
savedElements.addAll(newElements);
return new TimeTableDay(date, week, savedElements);
}

// Checks if this and the given day are at the same date
Expand All @@ -223,7 +267,7 @@ private void mergeConsecutiveCancellations() {
if (tte.getHour().length() <= 2 && tte2.getHour().length() <= 2 &&
tte.getHour_I() == (tte2.getHour_I() - 1)) {
if (tte.getType() == tte2.getType() &&
tte.getClass_name().equals(tte2.getClass_name()) &&
tte.getClassName().equals(tte2.getClassName()) &&
tte.getRoom().equals(tte2.getRoom()) &&
tte.getNewRoom().equals(tte2.getNewRoom()) &&
tte.getSubject().equals(tte2.getSubject()) &&
Expand All @@ -239,7 +283,7 @@ else if (tte.getInfo().isEmpty() || tte2.getInfo().isEmpty())
else
newInfo = String.format("%s - %s", tte.getInfo(), tte2.getInfo());

TimeTableElement replacement = new TimeTableElement(newTime, tte.getClass_name(), tte.getSubject(), tte.getNewSubject(), tte.getRoom(), tte.getNewRoom(), newInfo);
TimeTableElement replacement = new TimeTableElement(newTime, tte.getClassName(), tte.getSubject(), tte.getNewSubject(), tte.getRoom(), tte.getNewRoom(), newInfo);

timeTableElements.remove(tte);
timeTableElements.remove(tte2);
Expand Down

0 comments on commit 0ecbf5a

Please sign in to comment.