use of de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaMenuManager in project TumCampusApp by TCA-Team.
the class DownloadService method downloadCafeterias.
private boolean downloadCafeterias(boolean force) {
CafeteriaMenuManager cmm = new CafeteriaMenuManager(this);
cmm.downloadFromExternal(this, force);
cafeteriaViewModel.getCafeteriasFromService(force);
return true;
}
use of de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaMenuManager in project TumCampusApp by TCA-Team.
the class FavoriteDishAlarmScheduler method onReceive.
/**
* Can either receive a date or a boolean cancelNotifications value. This way other activities
* can close the currently opened notifications and it is possible to schedule dates, where the
* alarm has to check for favorite dishes.
*
* @param context
* @param extra Extra can either be "cancelNotifications" or a date, when the alarm should check, if there are any
* favorite dishes at a given date.
*/
@Override
public void onReceive(Context context, Intent extra) {
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
cancelFoodNotifications(mNotificationManager);
if (extra.getBooleanExtra("cancelNotifications", false)) {
return;
}
String triggeredAt = extra.getStringExtra("triggeredAt");
Calendar triggeredCal = Calendar.getInstance();
triggeredCal.setTime(DateUtils.getDate(triggeredAt));
CafeteriaMenuManager cm = new CafeteriaMenuManager(context);
HashMap<Integer, HashSet<CafeteriaMenu>> scheduledNow = cm.getServedFavoritesAtDate(triggeredAt);
if (scheduledNow == null) {
Utils.log("FavoriteDishAlarmScheduler: Scheduled now is null, onReceived aborted");
return;
}
CafeteriaDao dao = TcaDb.getInstance(context).cafeteriaDao();
for (Integer mensaId : scheduledNow.keySet()) {
StringBuilder message = new StringBuilder();
int menuCount = 0;
for (CafeteriaMenu menu : scheduledNow.get(mensaId)) {
message.append(menu.getName()).append('\n');
menuCount++;
}
ACTIVE_NOTIFICATIONS.add(mensaId);
String mensaName = dao.getMensaNameFromId(mensaId);
Intent intent = new Intent(context, CafeteriaActivity.class);
intent.putExtra(Const.MENSA_FOR_FAVORITEDISH, mensaId);
PendingIntent pi = PendingIntent.getActivity(context, mensaId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, Const.NOTIFICATION_CHANNEL_CAFETERIA).setSmallIcon(R.drawable.ic_notification).setContentTitle(mensaName + (menuCount > 1 ? " (" + menuCount + ")" : "")).setStyle(new NotificationCompat.BigTextStyle().bigText(message.toString())).setContentText(message.toString()).setAutoCancel(true).setLargeIcon(Utils.getLargeIcon(context, R.drawable.ic_cutlery)).setContentIntent(pi).setDefaults(Notification.DEFAULT_SOUND).setAutoCancel(true);
mNotificationManager.notify(IDENTIFIER_STRING, mensaId, mBuilder.build());
}
}
Aggregations