Notification click implemented
This commit is contained in:
@@ -31,7 +31,9 @@
|
|||||||
android:theme="@style/FUTheme">
|
android:theme="@style/FUTheme">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:label="@string/app_name">
|
android:label="@string/app_name"
|
||||||
|
android:clearTaskOnLaunch="true"
|
||||||
|
android:launchMode="singleTop">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import de.sebse.fuplanner.fragments.ScheduleFragment;
|
|||||||
import de.sebse.fuplanner.fragments.StartupFragment;
|
import de.sebse.fuplanner.fragments.StartupFragment;
|
||||||
import de.sebse.fuplanner.fragments.canteen.DaySwitcherFragment;
|
import de.sebse.fuplanner.fragments.canteen.DaySwitcherFragment;
|
||||||
import de.sebse.fuplanner.fragments.moddetails.ModDetailFragment;
|
import de.sebse.fuplanner.fragments.moddetails.ModDetailFragment;
|
||||||
|
import de.sebse.fuplanner.fragments.moddetails.ModulePart;
|
||||||
import de.sebse.fuplanner.services.canteen.CanteenBrowser;
|
import de.sebse.fuplanner.services.canteen.CanteenBrowser;
|
||||||
import de.sebse.fuplanner.services.canteen.types.Canteen;
|
import de.sebse.fuplanner.services.canteen.types.Canteen;
|
||||||
import de.sebse.fuplanner.services.canteen.types.CanteenListener;
|
import de.sebse.fuplanner.services.canteen.types.CanteenListener;
|
||||||
@@ -65,15 +66,15 @@ public class MainActivity extends AppCompatActivity
|
|||||||
ModulesFragment.OnModulesFragmentInteractionListener,
|
ModulesFragment.OnModulesFragmentInteractionListener,
|
||||||
CanteensFragment.OnCanteensFragmentInteractionListener {
|
CanteensFragment.OnCanteensFragmentInteractionListener {
|
||||||
|
|
||||||
private static final int FRAGMENT_NONE = -1;
|
public static final int FRAGMENT_NONE = -1;
|
||||||
private static final int FRAGMENT_STARTUP = 0;
|
public static final int FRAGMENT_STARTUP = 0;
|
||||||
private static final int FRAGMENT_MODULES = 1;
|
public static final int FRAGMENT_MODULES = 1;
|
||||||
private static final int FRAGMENT_MODULES_DETAILS = 2;
|
public static final int FRAGMENT_MODULES_DETAILS = 2;
|
||||||
private static final int FRAGMENT_SCHEDULE = 4;
|
public static final int FRAGMENT_SCHEDULE = 4;
|
||||||
private static final int FRAGMENT_CANTEENS = 5;
|
public static final int FRAGMENT_CANTEENS = 5;
|
||||||
private static final int FRAGMENT_CANTEENS_DETAILS = 6;
|
public static final int FRAGMENT_CANTEENS_DETAILS = 6;
|
||||||
private static final int FRAGMENT_PREFERENCES = 7;
|
public static final int FRAGMENT_PREFERENCES = 7;
|
||||||
private static final int FRAGMENT_NEWS = 8;
|
public static final int FRAGMENT_NEWS = 8;
|
||||||
|
|
||||||
private static final String ARG_FRAGMENT_PAGE = "fragment_page";
|
private static final String ARG_FRAGMENT_PAGE = "fragment_page";
|
||||||
private static final String ARG_FRAGMENT_STATUS = "fragment_status";
|
private static final String ARG_FRAGMENT_STATUS = "fragment_status";
|
||||||
@@ -102,7 +103,16 @@ public class MainActivity extends AppCompatActivity
|
|||||||
mAccountManager = new CustomAccountManager(AccountManager.get(this), () -> MainActivity.this);
|
mAccountManager = new CustomAccountManager(AccountManager.get(this), () -> MainActivity.this);
|
||||||
int desiredPage = getDefaultFragmentAfterLogin();
|
int desiredPage = getDefaultFragmentAfterLogin();
|
||||||
String desiredData = "";
|
String desiredData = "";
|
||||||
if (savedInstanceState != null) {
|
Intent intent = getIntent();
|
||||||
|
if (intent != null) {
|
||||||
|
if (CustomNotificationManager.NOTIFICATION_TYPE_NAVIGATE.equals(intent.getStringExtra(CustomNotificationManager.NOTIFICATION_INTENT))) {
|
||||||
|
int page = intent.getIntExtra(CustomNotificationManager.NOTIFICATION_PAGE, 0);
|
||||||
|
if (page == FRAGMENT_STARTUP || page == FRAGMENT_NONE)
|
||||||
|
page = getDefaultFragmentAfterLogin();
|
||||||
|
desiredPage = page;
|
||||||
|
desiredData = intent.getStringExtra(CustomNotificationManager.NOTIFICATION_DATA);
|
||||||
|
}
|
||||||
|
} else if (savedInstanceState != null) {
|
||||||
desiredPage = savedInstanceState.getInt(ARG_FRAGMENT_PAGE, desiredPage);
|
desiredPage = savedInstanceState.getInt(ARG_FRAGMENT_PAGE, desiredPage);
|
||||||
desiredData = savedInstanceState.getString(ARG_FRAGMENT_STATUS, desiredData);
|
desiredData = savedInstanceState.getString(ARG_FRAGMENT_STATUS, desiredData);
|
||||||
}
|
}
|
||||||
@@ -396,9 +406,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
case FRAGMENT_MODULES:
|
case FRAGMENT_MODULES:
|
||||||
fragment = ModulesFragment.newInstance();
|
fragment = ModulesFragment.newInstance();
|
||||||
break;
|
break;
|
||||||
/*case FRAGMENT_LOGIN:
|
|
||||||
fragment = LoginFragment.newInstance();
|
|
||||||
break;*/
|
|
||||||
case FRAGMENT_SCHEDULE:
|
case FRAGMENT_SCHEDULE:
|
||||||
fragment = ScheduleFragment.newInstance();
|
fragment = ScheduleFragment.newInstance();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package de.sebse.fuplanner.fragments.moddetails;
|
package de.sebse.fuplanner.fragments.moddetails;
|
||||||
|
|
||||||
class ModulePart {
|
public class ModulePart {
|
||||||
static final int DESCRIPTION = 0;
|
static final int DESCRIPTION = 0;
|
||||||
static final int OVERVIEW = 1;
|
static final int OVERVIEW = 1;
|
||||||
static final int ANNOUNCEMENT = 2;
|
public static final int ANNOUNCEMENT = 2;
|
||||||
static final int ASSIGNMENT = 3;
|
public static final int ASSIGNMENT = 3;
|
||||||
static final int EVENT = 4;
|
public static final int EVENT = 4;
|
||||||
static final int GRADEBOOK = 5;
|
public static final int GRADEBOOK = 5;
|
||||||
static final int RESOURCES = 6;
|
public static final int RESOURCES = 6;
|
||||||
static final int LECTURERS = 7;
|
static final int LECTURERS = 7;
|
||||||
private static final int[] pages = new int[]{OVERVIEW, ANNOUNCEMENT, ASSIGNMENT, GRADEBOOK, RESOURCES, EVENT};
|
private static final int[] pages = new int[]{OVERVIEW, ANNOUNCEMENT, ASSIGNMENT, GRADEBOOK, RESOURCES, EVENT};
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.util.Iterator;
|
|||||||
|
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
|
import de.sebse.fuplanner.fragments.moddetails.ModulePart;
|
||||||
import de.sebse.fuplanner.services.kvv.KVV;
|
import de.sebse.fuplanner.services.kvv.KVV;
|
||||||
import de.sebse.fuplanner.services.kvv.KVVListener;
|
import de.sebse.fuplanner.services.kvv.KVVListener;
|
||||||
import de.sebse.fuplanner.services.kvv.types.Announcement;
|
import de.sebse.fuplanner.services.kvv.types.Announcement;
|
||||||
@@ -28,6 +29,9 @@ import de.sebse.fuplanner.tools.NewAsyncQueue;
|
|||||||
import de.sebse.fuplanner.tools.UtilsDate;
|
import de.sebse.fuplanner.tools.UtilsDate;
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
|
import static de.sebse.fuplanner.MainActivity.FRAGMENT_MODULES_DETAILS;
|
||||||
|
import static de.sebse.fuplanner.MainActivity.FRAGMENT_STARTUP;
|
||||||
|
|
||||||
public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||||
private KVV mKVV;
|
private KVV mKVV;
|
||||||
private Logger log = new Logger(this);
|
private Logger log = new Logger(this);
|
||||||
@@ -96,14 +100,19 @@ public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
mKVV.modules().details().recv(module, success1 -> {
|
mKVV.modules().details().recv(module, success1 -> {
|
||||||
if (success1.second) {
|
if (success1.second) {
|
||||||
sendNotifications(announcements, module.announcements, module.title, Announcement::getTitle, Announcement::getId,
|
sendNotifications(announcements, module.announcements, module.title, Announcement::getTitle, Announcement::getId,
|
||||||
|
module.getID(), ModulePart.ANNOUNCEMENT,
|
||||||
R.string.announcement_updated, R.string.announcement_added, R.string.announcement_removed);
|
R.string.announcement_updated, R.string.announcement_added, R.string.announcement_removed);
|
||||||
sendNotifications(assignments, module.assignments, module.title, Assignment::getTitle, Assignment::getId,
|
sendNotifications(assignments, module.assignments, module.title, Assignment::getTitle, Assignment::getId,
|
||||||
|
module.getID(), ModulePart.ASSIGNMENT,
|
||||||
R.string.assignment_updated, R.string.assignment_added, R.string.assignment_removed);
|
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 -> String.valueOf(event.getStartDate())+event.getType(),
|
sendNotifications(events, module.events, module.title, evt -> evt.getTitle()+" - "+UtilsDate.getModifiedDate(evt.getStartDate()), event -> String.valueOf(event.getStartDate())+event.getType(),
|
||||||
|
module.getID(), ModulePart.EVENT,
|
||||||
R.string.event_updated, R.string.event_added, R.string.event_removed);
|
R.string.event_updated, R.string.event_added, R.string.event_removed);
|
||||||
sendNotifications(gradebook, module.gradebook, module.title, Grade::getItemName, Grade::getItemName,
|
sendNotifications(gradebook, module.gradebook, module.title, Grade::getItemName, Grade::getItemName,
|
||||||
|
module.getID(), ModulePart.GRADEBOOK,
|
||||||
R.string.gradebook_updated, R.string.gradebook_added, R.string.gradebook_removed);
|
R.string.gradebook_updated, R.string.gradebook_added, R.string.gradebook_removed);
|
||||||
sendNotifications(resources, module.resources, module.title, Resource::getTitle, Resource::getUrl,
|
sendNotifications(resources, module.resources, module.title, Resource::getTitle, Resource::getUrl,
|
||||||
|
module.getID(), ModulePart.RESOURCES,
|
||||||
R.string.resource_updated, R.string.resource_added, R.string.resource_removed);
|
R.string.resource_updated, R.string.resource_added, R.string.resource_removed);
|
||||||
mQueue.next();
|
mQueue.next();
|
||||||
}
|
}
|
||||||
@@ -119,7 +128,7 @@ public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
private <T> void sendNotifications(Iterable<T> oldList, Iterable<T> newList, String title, StringInterface<T> titleInterface, StringInterface<T> idInterface, String moduleId, int modulePart, @StringRes int updateRes, @StringRes int addRes, @StringRes int removeRes) {
|
||||||
if (oldList == null || newList == null) {
|
if (oldList == null || newList == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -127,24 +136,25 @@ public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
for (T old: oldList) {
|
for (T old: oldList) {
|
||||||
obsoletes.add(old);
|
obsoletes.add(old);
|
||||||
}
|
}
|
||||||
|
String targetData = moduleId+"."+ModulePart.getPageByPart(modulePart);
|
||||||
for (T newEntry: newList) {
|
for (T newEntry: newList) {
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (T oldEntry: oldList) {
|
for (T oldEntry: oldList) {
|
||||||
if (idInterface.get(newEntry).equals(idInterface.get(oldEntry))) {
|
if (idInterface.get(newEntry).equals(idInterface.get(oldEntry))) {
|
||||||
found = true;
|
found = true;
|
||||||
if (newEntry.hashCode() != oldEntry.hashCode()) {
|
if (newEntry.hashCode() != oldEntry.hashCode()) {
|
||||||
CustomNotificationManager.sendNotification(getContext(), getContext().getString(updateRes, title), titleInterface.get(newEntry));
|
CustomNotificationManager.sendNotification(getContext(), getContext().getString(updateRes, title), titleInterface.get(newEntry), FRAGMENT_MODULES_DETAILS, targetData);
|
||||||
}
|
}
|
||||||
obsoletes.remove(oldEntry);
|
obsoletes.remove(oldEntry);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
CustomNotificationManager.sendNotification(getContext(), getContext().getString(addRes, title), titleInterface.get(newEntry));
|
CustomNotificationManager.sendNotification(getContext(), getContext().getString(addRes, title), titleInterface.get(newEntry), FRAGMENT_STARTUP, targetData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (T oldEntry: obsoletes) {
|
for (T oldEntry: obsoletes) {
|
||||||
CustomNotificationManager.sendNotification(getContext(), getContext().getString(removeRes, title), titleInterface.get(oldEntry));
|
CustomNotificationManager.sendNotification(getContext(), getContext().getString(removeRes, title), titleInterface.get(oldEntry), FRAGMENT_STARTUP, targetData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,20 @@ import de.sebse.fuplanner.R;
|
|||||||
|
|
||||||
public class CustomNotificationManager {
|
public class CustomNotificationManager {
|
||||||
private static final String CHANNEL_ID = "fuplanner-default";
|
private static final String CHANNEL_ID = "fuplanner-default";
|
||||||
|
public static final String NOTIFICATION_INTENT = "notification-intent";
|
||||||
|
public static final String NOTIFICATION_PAGE = "notification-page";
|
||||||
|
public static final String NOTIFICATION_DATA = "notification-data";
|
||||||
|
public static final String NOTIFICATION_TYPE_NAVIGATE = "navigate";
|
||||||
|
|
||||||
//public static ArrayList<Integer> passedNotifications = new ArrayList<>();
|
//public static ArrayList<Integer> passedNotifications = new ArrayList<>();
|
||||||
|
|
||||||
public static void sendNotification(Context context, String textTitle, String textContent) {
|
public static void sendNotification(Context context, String textTitle, String textContent, int page, String data) {
|
||||||
Intent intent = new Intent(context, MainActivity.class);
|
Intent intent = new Intent(context, MainActivity.class);
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
intent.putExtra(NOTIFICATION_INTENT, NOTIFICATION_TYPE_NAVIGATE);
|
||||||
|
intent.putExtra(NOTIFICATION_PAGE, page);
|
||||||
|
intent.putExtra(NOTIFICATION_DATA, data);
|
||||||
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
|
|
||||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
|
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
|
||||||
|
|||||||
Reference in New Issue
Block a user