Search in sources :

Example 1 with TransportController

use of de.tum.in.tumcampusapp.component.ui.transportation.TransportController in project TumCampusApp by TCA-Team.

the class MVVWidget method onDeleted.

@Override
public void onDeleted(Context context, int[] appWidgetIds) {
    if (transportManager == null) {
        transportManager = new TransportController(context);
    }
    // When the user deletes the widget, delete the associated setting from the database.
    for (int appWidgetId : appWidgetIds) {
        transportManager.deleteWidget(appWidgetId);
    }
    transportManager = null;
    super.onDeleted(context, appWidgetIds);
}
Also used : TransportController(de.tum.in.tumcampusapp.component.ui.transportation.TransportController)

Example 2 with TransportController

use of de.tum.in.tumcampusapp.component.ui.transportation.TransportController in project TumCampusApp by TCA-Team.

the class MVVWidget method onReceive.

@Override
public void onReceive(@NonNull Context context, @NonNull Intent intent) {
    if (transportManager == null) {
        transportManager = new TransportController(context);
    }
    String action = intent.getAction();
    if (action == null || action.equals(MVVWidget.BROADCAST_RELOAD_ALL)) {
        updateAppWidgets(context, AppWidgetManager.getInstance(context), getActiveWidgetIds(context));
    } else if (action.equals(MVVWidget.BROADCAST_RELOAD_ALL_ALARM)) {
        planUpdates(context);
        updateAppWidgets(context, AppWidgetManager.getInstance(context), getActiveWidgetIds(context));
    } else if (action.equals(MVVWidget.MVV_WIDGET_FORCE_RELOAD)) {
        int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
        if (appWidgetId >= 0) {
            updateAppWidget(context, AppWidgetManager.getInstance(context), appWidgetId, true);
        }
    }
    super.onReceive(context, intent);
}
Also used : TransportController(de.tum.in.tumcampusapp.component.ui.transportation.TransportController)

Example 3 with TransportController

use of de.tum.in.tumcampusapp.component.ui.transportation.TransportController in project TumCampusApp by TCA-Team.

the class MVVWidgetConfigureActivity method saveAndReturn.

/**
 * Saves the selection to the database, triggers a widget update and closes this activity
 */
private void saveAndReturn() {
    // save the settings
    TransportController transportManager = new TransportController(this);
    transportManager.addWidget(appWidgetId, this.widgetDepartures);
    // update alarms
    MVVWidget.setAlarm(this);
    // update widget
    Intent reloadIntent = new Intent(this, MVVWidget.class);
    reloadIntent.setAction(MVVWidget.MVV_WIDGET_FORCE_RELOAD);
    reloadIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    sendBroadcast(reloadIntent);
    // return to widget
    Intent resultValue = new Intent();
    resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    setResult(RESULT_OK, resultValue);
    finish();
}
Also used : Intent(android.content.Intent) TransportController(de.tum.in.tumcampusapp.component.ui.transportation.TransportController)

Example 4 with TransportController

use of de.tum.in.tumcampusapp.component.ui.transportation.TransportController in project TumCampusApp by TCA-Team.

the class MVVWidgetConfigureActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Setup cancel button
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_action_cancel);
    // Get appWidgetId from intent
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    if (extras != null) {
        appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
    }
    TransportController tm = new TransportController(this);
    this.widgetDepartures = tm.getWidget(appWidgetId);
    Switch autoReloadSwitch = findViewById(R.id.mvv_widget_auto_reload);
    autoReloadSwitch.setChecked(this.widgetDepartures.getAutoReload());
    autoReloadSwitch.setOnCheckedChangeListener((compoundButton, checked) -> widgetDepartures.setAutoReload(checked));
    // TODO add handling for use location
    listViewResults = findViewById(R.id.activity_transport_listview_result);
    listViewResults.setOnItemClickListener(this);
    // Initialize stations adapter
    List<Recent> recentStations = recentsDao.getAll(RecentsDao.STATIONS);
    adapterStations = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, TransportController.getRecentStations(recentStations));
    if (adapterStations.getCount() == 0) {
        openSearch();
    } else {
        listViewResults.setAdapter(adapterStations);
        listViewResults.requestFocus();
    }
}
Also used : Recent(de.tum.in.tumcampusapp.component.other.general.model.Recent) Switch(android.widget.Switch) Bundle(android.os.Bundle) Intent(android.content.Intent) TransportController(de.tum.in.tumcampusapp.component.ui.transportation.TransportController)

Example 5 with TransportController

use of de.tum.in.tumcampusapp.component.ui.transportation.TransportController 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)

Aggregations

TransportController (de.tum.in.tumcampusapp.component.ui.transportation.TransportController)6 Intent (android.content.Intent)2 Bundle (android.os.Bundle)1 Switch (android.widget.Switch)1 AccessTokenManager (de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager)1 Recent (de.tum.in.tumcampusapp.component.other.general.model.Recent)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 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 Card (de.tum.in.tumcampusapp.component.ui.overview.card.Card)1 ArrayList (java.util.ArrayList)1