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