Notifications added
This commit is contained in:
@@ -7,8 +7,8 @@ android {
|
||||
applicationId "de.sebse.fuplanner"
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 28
|
||||
versionCode 16
|
||||
versionName "1.3.5"
|
||||
versionCode 19
|
||||
versionName "1.4"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
@@ -27,7 +27,6 @@ android {
|
||||
|
||||
|
||||
dependencies {
|
||||
//implementation "com.android.support:support-compat:28.0.0"
|
||||
implementation 'androidx.recyclerview:recyclerview:1.0.0'
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-beta02', {
|
||||
|
||||
@@ -11,13 +11,22 @@ import android.os.Bundle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.kvv.KVV;
|
||||
import de.sebse.fuplanner.services.kvv.KVVListener;
|
||||
import de.sebse.fuplanner.services.kvv.types.Announcement;
|
||||
import de.sebse.fuplanner.services.kvv.types.Assignment;
|
||||
import de.sebse.fuplanner.services.kvv.types.AssignmentList;
|
||||
import de.sebse.fuplanner.services.kvv.types.Event;
|
||||
import de.sebse.fuplanner.services.kvv.types.EventList;
|
||||
import de.sebse.fuplanner.services.kvv.types.Grade;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Resource;
|
||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
||||
import de.sebse.fuplanner.tools.CustomNotificationManager;
|
||||
import de.sebse.fuplanner.tools.NewAsyncQueue;
|
||||
import de.sebse.fuplanner.tools.UtilsDate;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
|
||||
public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
@@ -83,43 +92,24 @@ public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
while (iterator.hasNext()) {
|
||||
Modules.Module module = iterator.next();
|
||||
log.d("sync module", module.title);
|
||||
final ArrayList<Announcement> x = module.announcements;
|
||||
final ArrayList<Announcement> announcements = module.announcements;
|
||||
final AssignmentList assignments = module.assignments;
|
||||
final EventList events = module.events;
|
||||
final ArrayList<Grade> gradebook = module.gradebook;
|
||||
final ArrayList<Resource> resources = module.resources;
|
||||
mKVV.modules().details().recv(module, success1 -> {
|
||||
if (success1.second) {
|
||||
log.d("Sync Successful for Module '"+module.title+"'!");
|
||||
if (x != null && module.announcements != null && module.title.equals("Seminar: Künstliche Intelligenz - Autonome Fahrzeuge")) {
|
||||
for (Announcement newAnnounce: module.announcements) {
|
||||
boolean found = false;
|
||||
for (Announcement oldAnnounce: x) {
|
||||
if (newAnnounce.getId().equals(oldAnnounce.getId())) {
|
||||
found = true;
|
||||
if (newAnnounce.hashCode() != oldAnnounce.hashCode()) {
|
||||
CustomNotificationManager.sendNotification(getContext(), "Announcement Updated", newAnnounce.getTitle());
|
||||
}
|
||||
x.remove(oldAnnounce);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
CustomNotificationManager.sendNotification(getContext(), "Announcement Added", newAnnounce.getTitle());
|
||||
}
|
||||
}
|
||||
for (Announcement oldAnnounce: x) {
|
||||
CustomNotificationManager.sendNotification(getContext(), "Announcement Removed", oldAnnounce.getTitle());
|
||||
}
|
||||
}
|
||||
if (x != null)
|
||||
log.d("x", "length:", x.size(), x.hashCode());
|
||||
else
|
||||
log.d("x null");
|
||||
if (success1.first.announcements != null)
|
||||
log.d("success", "length:", success1.first.announcements.size(), success1.first.announcements.hashCode());
|
||||
else
|
||||
log.d("success null");
|
||||
if (module.announcements != null)
|
||||
log.d("module", "length:", module.announcements.size(), module.announcements.hashCode());
|
||||
else
|
||||
log.d("module null");
|
||||
sendNotifications(announcements, module.announcements, module.title, Announcement::getTitle, Announcement::getId,
|
||||
R.string.announcement_updated, R.string.announcement_added, R.string.announcement_removed);
|
||||
sendNotifications(assignments, module.assignments, module.title, Assignment::getTitle, Assignment::getId,
|
||||
R.string.assignment_updated, R.string.assignment_added, R.string.assignment_removed);
|
||||
sendNotifications(events, module.events, module.title, evt -> evt.getTitle()+" - "+UtilsDate.getModifiedDate(evt.getStartDate()), Event::getId,
|
||||
R.string.event_updated, R.string.event_added, R.string.event_removed);
|
||||
sendNotifications(gradebook, module.gradebook, module.title, Grade::getItemName, Grade::getItemName,
|
||||
R.string.gradebook_updated, R.string.gradebook_added, R.string.gradebook_removed);
|
||||
sendNotifications(resources, module.resources, module.title, Resource::getTitle, Resource::getUrl,
|
||||
R.string.resource_updated, R.string.resource_added, R.string.resource_removed);
|
||||
mQueue.next();
|
||||
}
|
||||
}, msg -> {
|
||||
@@ -134,4 +124,38 @@ public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
log.d("finished");
|
||||
});
|
||||
}
|
||||
|
||||
private <T> void sendNotifications(Iterable<T> oldList, Iterable<T> newList, String title, StringInterface<T> titleInterface, StringInterface<T> idInterface, @StringRes int updateRes, @StringRes int addRes, @StringRes int removeRes) {
|
||||
if (oldList == null || newList == null) {
|
||||
return;
|
||||
}
|
||||
ArrayList<T> obsoletes = new ArrayList<T>();
|
||||
for (T old: oldList) {
|
||||
obsoletes.add(old);
|
||||
}
|
||||
for (T newEntry: newList) {
|
||||
boolean found = false;
|
||||
for (T oldEntry: oldList) {
|
||||
if (idInterface.get(newEntry).equals(idInterface.get(oldEntry))) {
|
||||
found = true;
|
||||
if (newEntry.hashCode() != oldEntry.hashCode()) {
|
||||
CustomNotificationManager.sendNotification(getContext(), getContext().getString(updateRes, title), titleInterface.get(newEntry));
|
||||
}
|
||||
obsoletes.remove(oldEntry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
CustomNotificationManager.sendNotification(getContext(), getContext().getString(addRes, title), titleInterface.get(newEntry));
|
||||
}
|
||||
}
|
||||
for (T oldEntry: obsoletes) {
|
||||
CustomNotificationManager.sendNotification(getContext(), getContext().getString(removeRes, title), titleInterface.get(oldEntry));
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface StringInterface<T> {
|
||||
String get(T element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Assignment implements Serializable {
|
||||
this.instructions = instructions;
|
||||
}
|
||||
|
||||
private String getId() {
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@@ -93,4 +93,20 @@
|
||||
<string name="error_field_required">Pflichtfeld</string>
|
||||
<string name="kvv_sync">KVV-Synchronisation</string>
|
||||
<string name="channel_name">Neue Daten verfügbar</string>
|
||||
<string name="channel_description">Benachrichtigen, wenn neue Ankündigungen, Aufgaben, Noten oder Resourcen verfügbar sind</string>
|
||||
<string name="announcement_updated">Ankündigung aktualisiert: %1$s</string>
|
||||
<string name="assignment_updated">Aufgabe aktualisiert: %1$s</string>
|
||||
<string name="event_updated">Event aktualisiert: %1$s</string>
|
||||
<string name="gradebook_updated">Noteneintrag aktualisiert: %1$s</string>
|
||||
<string name="resource_updated">Ressource aktualisiert: %1$s</string>
|
||||
<string name="announcement_added">Neue Ankündigung: %1$s</string>
|
||||
<string name="assignment_added">Neue Aufgabe: %1$</string>
|
||||
<string name="event_added">Neues Event: %1$</string>
|
||||
<string name="gradebook_added">Neuer Noteneintrag: %1$</string>
|
||||
<string name="resource_added">Neue Ressource: %1$</string>
|
||||
<string name="announcement_removed">Ankündigung entfernt: %1$s</string>
|
||||
<string name="assignment_removed">Aufgabe entfernt: %1$s</string>
|
||||
<string name="event_removed">Event entfernt: %1$s</string>
|
||||
<string name="gradebook_removed">Noteneintrag entfernt: %1$s</string>
|
||||
<string name="resource_removed">Ressource entfernt: %1$s</string>
|
||||
</resources>
|
||||
@@ -102,4 +102,19 @@
|
||||
<string name="kvv_sync">KVV Synchronization</string>
|
||||
<string name="channel_name">New data available</string>
|
||||
<string name="channel_description">Notify when new announcements, assignments, grades or resources are available</string>
|
||||
<string name="announcement_updated">Announcement updated: %1$s</string>
|
||||
<string name="announcement_added">New announcement: %1$s</string>
|
||||
<string name="announcement_removed">Announcement removed: %1$s</string>
|
||||
<string name="assignment_updated">Assignment updated: %1$s</string>
|
||||
<string name="assignment_added">New assignment: %1$s</string>
|
||||
<string name="assignment_removed">Assignment removed: %1$s</string>
|
||||
<string name="event_updated">Event updated: %1$s</string>
|
||||
<string name="event_added">New event: %1$s</string>
|
||||
<string name="event_removed">Event removed: %1$s</string>
|
||||
<string name="gradebook_updated">Gradebook entry updated: %1$s</string>
|
||||
<string name="gradebook_added">New gradebook entry: %1$s</string>
|
||||
<string name="gradebook_removed">Gradebook entry removed: %1$s</string>
|
||||
<string name="resource_updated">Resource updated: %1$s</string>
|
||||
<string name="resource_added">New resource: %1$s</string>
|
||||
<string name="resource_removed">Resource removed: %1$s</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user