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())));
}
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;
}
}
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);
}
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;
}
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);
}
Aggregations