use of de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria 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);
}
use of de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria in project TumCampusApp by TCA-Team.
the class CafeteriaActivity method setCurrentSelectedCafeteria.
private void setCurrentSelectedCafeteria(Spinner spinner) {
int selIndex = -1;
for (int i = 0; i < mCafeterias.size(); i++) {
Cafeteria c = mCafeterias.get(i);
if (mCafeteriaId == -1 || mCafeteriaId == c.getId()) {
mCafeteriaId = c.getId();
selIndex = i;
break;
}
}
if (selIndex > -1) {
spinner.setSelection(selIndex);
}
}
use of de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria in project TumCampusApp by TCA-Team.
the class CafeteriaActivity method onStart.
/**
* Setup action bar navigation (to switch between cafeterias)
*/
@Override
protected void onStart() {
super.onStart();
// Adapter for drop-down navigation
ArrayAdapter<Cafeteria> adapterCafeterias = new ArrayAdapter<Cafeteria>(this, R.layout.simple_spinner_item_actionbar, android.R.id.text1, mCafeterias) {
final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(LAYOUT_INFLATER_SERVICE);
@Override
public View getDropDownView(int position, View convertView, @NonNull ViewGroup parent) {
View v = inflater.inflate(R.layout.simple_spinner_dropdown_item_actionbar, parent, false);
Cafeteria c = getItem(position);
// Set name
TextView name = v.findViewById(android.R.id.text1);
// Set address
TextView address = v.findViewById(android.R.id.text2);
// Set distance
TextView dist = v.findViewById(R.id.distance);
if (c != null) {
name.setText(c.getName());
address.setText(c.getAddress());
dist.setText(Utils.formatDist(c.getDistance()));
}
return v;
}
};
Spinner spinner = findViewById(R.id.spinnerToolbar);
spinner.setAdapter(adapterCafeterias);
spinner.setOnItemSelectedListener(this);
Location currLocation = new LocationManager(this).getCurrentOrNextLocation();
Flowable<List<Cafeteria>> cafeterias = cafeteriaViewModel.getAllCafeterias(currLocation);
mDisposable.add(cafeterias.subscribe(it -> {
validateList(it);
mCafeterias.clear();
mCafeterias.addAll(it);
adapterCafeterias.notifyDataSetChanged();
setCurrentSelectedCafeteria(spinner);
}, throwable -> Utils.logwithTag("CafeteriaActivity", throwable.getMessage())));
}
Aggregations