use of de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager in project TumCampusApp by TCA-Team.
the class MensaWidget method onUpdate.
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// There may be multiple widgets active, so update all of them
this.appWidgetManager = appWidgetManager;
for (int appWidgetId : appWidgetIds) {
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.mensa_widget);
// set the header for the Widget layout
CafeteriaManager mensaManager = new CafeteriaManager(context);
CafeteriaLocalRepository localRepository = CafeteriaLocalRepository.INSTANCE;
localRepository.setDb(TcaDb.getInstance(context));
Flowable<Cafeteria> cafeteria = localRepository.getCafeteria(mensaManager.getBestMatchMensaId(context));
cafeteria.map(cafeteria1 -> cafeteria1.getName() + " " + DateUtils.getDateTimeString(new Date())).subscribe(mensaName -> rv.setTextViewText(R.id.mensa_widget_header, mensaName));
// set the header on click to open the mensa activity
Intent mensaIntent = new Intent(context, CafeteriaActivity.class);
mensaIntent.putExtra(Const.CAFETERIA_ID, mensaManager.getBestMatchMensaId(context));
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, mensaIntent, 0);
rv.setOnClickPendingIntent(R.id.mensa_widget_header_container, pendingIntent);
// set the adapter for the list view in the mensaWidget
Intent intent = new Intent(context, MensaWidgetService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
// appWidgetIds[i],
rv.setRemoteAdapter(R.id.food_item, intent);
rv.setEmptyView(R.id.empty_view, R.id.empty_view);
appWidgetManager.updateAppWidget(appWidgetId, rv);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
use of de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager in project TumCampusApp by TCA-Team.
the class CardManager method update.
/**
* Refreshes or initialises all cards.
* WARNING: Must not be called from UI thread.
* <p/>
* HOW TO ADD A NEW CARD:
* 1. Let the manager class implement {@link Card.ProvidesCard}
* 2. Create a new class extending {@link Card}
* 3. Implement the getCardView method in this class
* 4. Create a new instance of this card in the
* {@link Card.ProvidesCard#onRequestCard(Context)} method of the manager
* 5. Add this card to the CardManager by calling {@link Card#apply()} from
* {@link Card.ProvidesCard#onRequestCard(Context)}
* 6. Add an instance of the manager class to the managers list below
*/
public static synchronized void update(Context context) {
// Use temporary array to avoid that the main thread is trying to access an empty array
newCards.clear();
new NoInternetCard(context).apply();
new LoginPromtCard(context).apply();
new SupportCard(context).apply();
new EduroamCard(context).apply();
new EduroamFixCard(context).apply();
Collection<Card.ProvidesCard> managers = new ArrayList<>();
// Add those managers only if valid access token is available
if (new AccessTokenManager(context).hasValidAccessToken()) {
managers.add(new CalendarController(context));
managers.add(new TuitionFeeManager());
managers.add(new ChatRoomController(context));
}
// Those don't need TUMOnline access
managers.add(new CafeteriaManager(context));
managers.add(new TransportController(context));
managers.add(new NewsController(context));
for (Card.ProvidesCard manager : managers) {
manager.onRequestCard(context);
}
// Always append the restore card at the end of our list
new RestoreCard(context).apply();
shouldRefresh = false;
}
use of de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager in project TumCampusApp by TCA-Team.
the class MensaRemoteViewFactory method onCreate.
@Override
public void onCreate() {
CafeteriaManager mensaManager = new CafeteriaManager(applicationContext);
Map<String, List<CafeteriaMenu>> menus = mensaManager.getBestMatchMensaInfo(applicationContext).blockingFirst();
mensaMenu = menus.get(menus.keySet().iterator().next());
}
Aggregations