Notification click implemented
This commit is contained in:
@@ -31,7 +31,9 @@
|
||||
android:theme="@style/FUTheme">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name">
|
||||
android:label="@string/app_name"
|
||||
android:clearTaskOnLaunch="true"
|
||||
android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<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.canteen.DaySwitcherFragment;
|
||||
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.types.Canteen;
|
||||
import de.sebse.fuplanner.services.canteen.types.CanteenListener;
|
||||
@@ -65,15 +66,15 @@ public class MainActivity extends AppCompatActivity
|
||||
ModulesFragment.OnModulesFragmentInteractionListener,
|
||||
CanteensFragment.OnCanteensFragmentInteractionListener {
|
||||
|
||||
private static final int FRAGMENT_NONE = -1;
|
||||
private static final int FRAGMENT_STARTUP = 0;
|
||||
private static final int FRAGMENT_MODULES = 1;
|
||||
private static final int FRAGMENT_MODULES_DETAILS = 2;
|
||||
private static final int FRAGMENT_SCHEDULE = 4;
|
||||
private static final int FRAGMENT_CANTEENS = 5;
|
||||
private static final int FRAGMENT_CANTEENS_DETAILS = 6;
|
||||
private static final int FRAGMENT_PREFERENCES = 7;
|
||||
private static final int FRAGMENT_NEWS = 8;
|
||||
public static final int FRAGMENT_NONE = -1;
|
||||
public static final int FRAGMENT_STARTUP = 0;
|
||||
public static final int FRAGMENT_MODULES = 1;
|
||||
public static final int FRAGMENT_MODULES_DETAILS = 2;
|
||||
public static final int FRAGMENT_SCHEDULE = 4;
|
||||
public static final int FRAGMENT_CANTEENS = 5;
|
||||
public static final int FRAGMENT_CANTEENS_DETAILS = 6;
|
||||
public static final int FRAGMENT_PREFERENCES = 7;
|
||||
public static final int FRAGMENT_NEWS = 8;
|
||||
|
||||
private static final String ARG_FRAGMENT_PAGE = "fragment_page";
|
||||
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);
|
||||
int desiredPage = getDefaultFragmentAfterLogin();
|
||||
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);
|
||||
desiredData = savedInstanceState.getString(ARG_FRAGMENT_STATUS, desiredData);
|
||||
}
|
||||
@@ -396,9 +406,6 @@ public class MainActivity extends AppCompatActivity
|
||||
case FRAGMENT_MODULES:
|
||||
fragment = ModulesFragment.newInstance();
|
||||
break;
|
||||
/*case FRAGMENT_LOGIN:
|
||||
fragment = LoginFragment.newInstance();
|
||||
break;*/
|
||||
case FRAGMENT_SCHEDULE:
|
||||
fragment = ScheduleFragment.newInstance();
|
||||
break;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package de.sebse.fuplanner.fragments.moddetails;
|
||||
|
||||
class ModulePart {
|
||||
public class ModulePart {
|
||||
static final int DESCRIPTION = 0;
|
||||
static final int OVERVIEW = 1;
|
||||
static final int ANNOUNCEMENT = 2;
|
||||
static final int ASSIGNMENT = 3;
|
||||
static final int EVENT = 4;
|
||||
static final int GRADEBOOK = 5;
|
||||
static final int RESOURCES = 6;
|
||||
public static final int ANNOUNCEMENT = 2;
|
||||
public static final int ASSIGNMENT = 3;
|
||||
public static final int EVENT = 4;
|
||||
public static final int GRADEBOOK = 5;
|
||||
public static final int RESOURCES = 6;
|
||||
static final int LECTURERS = 7;
|
||||
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 de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.fragments.moddetails.ModulePart;
|
||||
import de.sebse.fuplanner.services.kvv.KVV;
|
||||
import de.sebse.fuplanner.services.kvv.KVVListener;
|
||||
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.logging.Logger;
|
||||
|
||||
import static de.sebse.fuplanner.MainActivity.FRAGMENT_MODULES_DETAILS;
|
||||
import static de.sebse.fuplanner.MainActivity.FRAGMENT_STARTUP;
|
||||
|
||||
public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
private KVV mKVV;
|
||||
private Logger log = new Logger(this);
|
||||
@@ -96,14 +100,19 @@ public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
mKVV.modules().details().recv(module, success1 -> {
|
||||
if (success1.second) {
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
@@ -127,24 +136,25 @@ public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
for (T old: oldList) {
|
||||
obsoletes.add(old);
|
||||
}
|
||||
String targetData = moduleId+"."+ModulePart.getPageByPart(modulePart);
|
||||
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));
|
||||
CustomNotificationManager.sendNotification(getContext(), getContext().getString(updateRes, title), titleInterface.get(newEntry), FRAGMENT_MODULES_DETAILS, targetData);
|
||||
}
|
||||
obsoletes.remove(oldEntry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
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) {
|
||||
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 {
|
||||
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 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.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user