Search in sources :

Example 1 with Card

use of de.tum.in.tumcampusapp.component.ui.overview.card.Card in project TumCampusApp by TCA-Team.

the class CafeteriaManager method onRequestCard.

/**
 * Shows card for the best matching cafeteria.
 *
 * @param context Context
 * @see LocationManager#getCafeteria()
 */
@Override
public void onRequestCard(Context context) {
    // Choose which mensa should be shown
    int cafeteriaId = new LocationManager(context).getCafeteria();
    if (cafeteriaId == -1) {
        return;
    }
    CafeteriaMenuCard card = new CafeteriaMenuCard(context);
    compositeDisposable.add(createCafeteriaObservable(cafeteriaId).take(1).subscribe(cafeteria -> {
        card.setCardMenus(cafeteria.id, cafeteria.name, cafeteria.dateStr, de.tum.in.tumcampusapp.utils.DateUtils.getDate(cafeteria.dateStr), cafeteria.menus);
        card.apply();
    }, throwable -> Utils.log(throwable.getMessage())));
}
Also used : LocationManager(de.tum.in.tumcampusapp.component.other.locations.LocationManager) Context(android.content.Context) CafeteriaMenu(de.tum.in.tumcampusapp.component.ui.cafeteria.model.CafeteriaMenu) DateUtils(android.text.format.DateUtils) Date(java.util.Date) Card(de.tum.in.tumcampusapp.component.ui.overview.card.Card) HashMap(java.util.HashMap) TUMCabeClient(de.tum.in.tumcampusapp.api.app.TUMCabeClient) CafeteriaLocalRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository) CafeteriaMenuCard(de.tum.in.tumcampusapp.component.ui.cafeteria.CafeteriaMenuCard) CafeteriaViewModel(de.tum.in.tumcampusapp.component.ui.cafeteria.details.CafeteriaViewModel) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Calendar(java.util.Calendar) Flowable(io.reactivex.Flowable) Map(java.util.Map) Utils(de.tum.in.tumcampusapp.utils.Utils) TcaDb(de.tum.in.tumcampusapp.database.TcaDb) CafeteriaRemoteRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaRemoteRepository) Collections(java.util.Collections) LocationManager(de.tum.in.tumcampusapp.component.other.locations.LocationManager) CafeteriaMenuCard(de.tum.in.tumcampusapp.component.ui.cafeteria.CafeteriaMenuCard)

Example 2 with Card

use of de.tum.in.tumcampusapp.component.ui.overview.card.Card in project TumCampusApp by TCA-Team.

the class CardAdapter method validatePosition.

private int validatePosition(int fromPosition, int toPosition) {
    Card selectedCard = CardManager.getCard(fromPosition);
    Card cardAtPosition = CardManager.getCard(toPosition);
    // Restore card should stay at the bottom
    if (selectedCard instanceof RestoreCard) {
        return fromPosition;
    } else if (selectedCard instanceof SupportCard) {
        return fromPosition;
    }
    if (cardAtPosition instanceof SupportCard) {
        return toPosition + 1;
    } else if (cardAtPosition instanceof RestoreCard) {
        return toPosition - 1;
    } else {
        return toPosition;
    }
}
Also used : MVVCard(de.tum.in.tumcampusapp.component.ui.transportation.MVVCard) LoginPromtCard(de.tum.in.tumcampusapp.component.ui.onboarding.LoginPromtCard) EduroamFixCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamFixCard) NewsCard(de.tum.in.tumcampusapp.component.ui.news.NewsCard) TuitionFeesCard(de.tum.in.tumcampusapp.component.tumui.tutionfees.TuitionFeesCard) Card(de.tum.in.tumcampusapp.component.ui.overview.card.Card) ChatMessagesCard(de.tum.in.tumcampusapp.component.ui.chat.ChatMessagesCard) NextLectureCard(de.tum.in.tumcampusapp.component.tumui.calendar.NextLectureCard) EduroamCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamCard) CafeteriaMenuCard(de.tum.in.tumcampusapp.component.ui.cafeteria.CafeteriaMenuCard)

Example 3 with Card

use of de.tum.in.tumcampusapp.component.ui.overview.card.Card in project TumCampusApp by TCA-Team.

the class CardAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(Card.CardViewHolder viewHolder, int position) {
    Card card = CardManager.getCard(position);
    viewHolder.setCurrentCard(card);
    card.updateViewHolder(viewHolder);
}
Also used : MVVCard(de.tum.in.tumcampusapp.component.ui.transportation.MVVCard) LoginPromtCard(de.tum.in.tumcampusapp.component.ui.onboarding.LoginPromtCard) EduroamFixCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamFixCard) NewsCard(de.tum.in.tumcampusapp.component.ui.news.NewsCard) TuitionFeesCard(de.tum.in.tumcampusapp.component.tumui.tutionfees.TuitionFeesCard) Card(de.tum.in.tumcampusapp.component.ui.overview.card.Card) ChatMessagesCard(de.tum.in.tumcampusapp.component.ui.chat.ChatMessagesCard) NextLectureCard(de.tum.in.tumcampusapp.component.tumui.calendar.NextLectureCard) EduroamCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamCard) CafeteriaMenuCard(de.tum.in.tumcampusapp.component.ui.cafeteria.CafeteriaMenuCard)

Example 4 with Card

use of de.tum.in.tumcampusapp.component.ui.overview.card.Card 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 5 with Card

use of de.tum.in.tumcampusapp.component.ui.overview.card.Card in project TumCampusApp by TCA-Team.

the class CardAdapter method onItemMove.

@Override
public void onItemMove(int fromPosition, int toPosition) {
    toPosition = validatePosition(fromPosition, toPosition);
    Card card = CardManager.remove(fromPosition);
    CardManager.insert(toPosition, card);
    // Update card positions so they stay the same even when the app is closed
    for (int index = 0; index < CardManager.getCardCount(); index++) {
        CardManager.getCard(index).setPosition(index);
    }
    notifyItemMoved(fromPosition, toPosition);
}
Also used : MVVCard(de.tum.in.tumcampusapp.component.ui.transportation.MVVCard) LoginPromtCard(de.tum.in.tumcampusapp.component.ui.onboarding.LoginPromtCard) EduroamFixCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamFixCard) NewsCard(de.tum.in.tumcampusapp.component.ui.news.NewsCard) TuitionFeesCard(de.tum.in.tumcampusapp.component.tumui.tutionfees.TuitionFeesCard) Card(de.tum.in.tumcampusapp.component.ui.overview.card.Card) ChatMessagesCard(de.tum.in.tumcampusapp.component.ui.chat.ChatMessagesCard) NextLectureCard(de.tum.in.tumcampusapp.component.tumui.calendar.NextLectureCard) EduroamCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamCard) CafeteriaMenuCard(de.tum.in.tumcampusapp.component.ui.cafeteria.CafeteriaMenuCard)

Aggregations

Card (de.tum.in.tumcampusapp.component.ui.overview.card.Card)6 CafeteriaMenuCard (de.tum.in.tumcampusapp.component.ui.cafeteria.CafeteriaMenuCard)5 EduroamCard (de.tum.in.tumcampusapp.component.ui.eduroam.EduroamCard)5 EduroamFixCard (de.tum.in.tumcampusapp.component.ui.eduroam.EduroamFixCard)5 LoginPromtCard (de.tum.in.tumcampusapp.component.ui.onboarding.LoginPromtCard)5 NextLectureCard (de.tum.in.tumcampusapp.component.tumui.calendar.NextLectureCard)4 TuitionFeesCard (de.tum.in.tumcampusapp.component.tumui.tutionfees.TuitionFeesCard)4 ChatMessagesCard (de.tum.in.tumcampusapp.component.ui.chat.ChatMessagesCard)4 NewsCard (de.tum.in.tumcampusapp.component.ui.news.NewsCard)4 MVVCard (de.tum.in.tumcampusapp.component.ui.transportation.MVVCard)4 Context (android.content.Context)1 DateUtils (android.text.format.DateUtils)1 TUMCabeClient (de.tum.in.tumcampusapp.api.app.TUMCabeClient)1 AccessTokenManager (de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager)1 LocationManager (de.tum.in.tumcampusapp.component.other.locations.LocationManager)1 CalendarController (de.tum.in.tumcampusapp.component.tumui.calendar.CalendarController)1 TuitionFeeManager (de.tum.in.tumcampusapp.component.tumui.tutionfees.TuitionFeeManager)1 CafeteriaManager (de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager)1 CafeteriaViewModel (de.tum.in.tumcampusapp.component.ui.cafeteria.details.CafeteriaViewModel)1 CafeteriaMenu (de.tum.in.tumcampusapp.component.ui.cafeteria.model.CafeteriaMenu)1