Search in sources :

Example 1 with CafeteriaManager

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);
}
Also used : RemoteViews(android.widget.RemoteViews) Context(android.content.Context) R(de.tum.in.tumcampusapp.R) DateUtils(de.tum.in.tumcampusapp.utils.DateUtils) AppWidgetProvider(android.appwidget.AppWidgetProvider) Date(java.util.Date) Uri(android.net.Uri) Const(de.tum.in.tumcampusapp.utils.Const) Intent(android.content.Intent) CafeteriaLocalRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository) PendingIntent(android.app.PendingIntent) CafeteriaManager(de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager) AppWidgetManager(android.appwidget.AppWidgetManager) Flowable(io.reactivex.Flowable) CafeteriaActivity(de.tum.in.tumcampusapp.component.ui.cafeteria.activity.CafeteriaActivity) TcaDb(de.tum.in.tumcampusapp.database.TcaDb) MensaWidgetService(de.tum.in.tumcampusapp.service.MensaWidgetService) Cafeteria(de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria) RemoteViews(android.widget.RemoteViews) CafeteriaManager(de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) CafeteriaLocalRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository) Cafeteria(de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria) Date(java.util.Date)

Example 2 with CafeteriaManager

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;
}
Also used : CalendarController(de.tum.in.tumcampusapp.component.tumui.calendar.CalendarController) CafeteriaManager(de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager) AccessTokenManager(de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager) EduroamFixCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamFixCard) LoginPromtCard(de.tum.in.tumcampusapp.component.ui.onboarding.LoginPromtCard) ArrayList(java.util.ArrayList) NewsController(de.tum.in.tumcampusapp.component.ui.news.NewsController) Card(de.tum.in.tumcampusapp.component.ui.overview.card.Card) LoginPromtCard(de.tum.in.tumcampusapp.component.ui.onboarding.LoginPromtCard) EduroamFixCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamFixCard) EduroamCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamCard) EduroamCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamCard) TuitionFeeManager(de.tum.in.tumcampusapp.component.tumui.tutionfees.TuitionFeeManager) TransportController(de.tum.in.tumcampusapp.component.ui.transportation.TransportController) ChatRoomController(de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController)

Example 3 with CafeteriaManager

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());
}
Also used : CafeteriaManager(de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager) List(java.util.List)

Aggregations

CafeteriaManager (de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager)3 PendingIntent (android.app.PendingIntent)1 AppWidgetManager (android.appwidget.AppWidgetManager)1 AppWidgetProvider (android.appwidget.AppWidgetProvider)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 RemoteViews (android.widget.RemoteViews)1 R (de.tum.in.tumcampusapp.R)1 AccessTokenManager (de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager)1 CalendarController (de.tum.in.tumcampusapp.component.tumui.calendar.CalendarController)1 TuitionFeeManager (de.tum.in.tumcampusapp.component.tumui.tutionfees.TuitionFeeManager)1 CafeteriaActivity (de.tum.in.tumcampusapp.component.ui.cafeteria.activity.CafeteriaActivity)1 Cafeteria (de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria)1 CafeteriaLocalRepository (de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository)1 ChatRoomController (de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController)1 EduroamCard (de.tum.in.tumcampusapp.component.ui.eduroam.EduroamCard)1 EduroamFixCard (de.tum.in.tumcampusapp.component.ui.eduroam.EduroamFixCard)1 NewsController (de.tum.in.tumcampusapp.component.ui.news.NewsController)1 LoginPromtCard (de.tum.in.tumcampusapp.component.ui.onboarding.LoginPromtCard)1