Search in sources :

Example 1 with Cafeteria

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);
}
Also used : RemoteViews(android.widget.RemoteViews) Context(android.content.Context) R(de.tum.in.tumcampusapp.R) DateUtils(de.tum.in.tumcampusapp.utils.DateUtils) AppWidgetProvider(android.appwidget.AppWidgetProvider) Date(java.util.Date) Uri(android.net.Uri) Const(de.tum.in.tumcampusapp.utils.Const) Intent(android.content.Intent) CafeteriaLocalRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository) PendingIntent(android.app.PendingIntent) CafeteriaManager(de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager) AppWidgetManager(android.appwidget.AppWidgetManager) Flowable(io.reactivex.Flowable) CafeteriaActivity(de.tum.in.tumcampusapp.component.ui.cafeteria.activity.CafeteriaActivity) TcaDb(de.tum.in.tumcampusapp.database.TcaDb) MensaWidgetService(de.tum.in.tumcampusapp.service.MensaWidgetService) Cafeteria(de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria) RemoteViews(android.widget.RemoteViews) CafeteriaManager(de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) CafeteriaLocalRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository) Cafeteria(de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria) Date(java.util.Date)

Example 2 with Cafeteria

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);
    }
}
Also used : Cafeteria(de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria)

Example 3 with Cafeteria

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())));
}
Also used : LocationManager(de.tum.in.tumcampusapp.component.other.locations.LocationManager) CafeteriaDetailsSectionFragment.menuToSpan(de.tum.in.tumcampusapp.component.ui.cafeteria.details.CafeteriaDetailsSectionFragment.menuToSpan) ActivityForDownloadingExternal(de.tum.in.tumcampusapp.component.other.generic.activity.ActivityForDownloadingExternal) Bundle(android.os.Bundle) ViewPager(android.support.v4.view.ViewPager) Intent(android.content.Intent) TUMCabeClient(de.tum.in.tumcampusapp.api.app.TUMCabeClient) NonNull(android.support.annotation.NonNull) CafeteriaDetailsSectionsPagerAdapter(de.tum.in.tumcampusapp.component.ui.cafeteria.details.CafeteriaDetailsSectionsPagerAdapter) CafeteriaViewModel(de.tum.in.tumcampusapp.component.ui.cafeteria.details.CafeteriaViewModel) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Flowable(io.reactivex.Flowable) Menu(android.view.Menu) View(android.view.View) AdapterView(android.widget.AdapterView) TcaDb(de.tum.in.tumcampusapp.database.TcaDb) CafeteriaRemoteRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaRemoteRepository) LocationManager(de.tum.in.tumcampusapp.component.other.locations.LocationManager) R(de.tum.in.tumcampusapp.R) LayoutInflater(android.view.LayoutInflater) Collection(java.util.Collection) Const(de.tum.in.tumcampusapp.utils.Const) CafeteriaLocalRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository) NetUtils(de.tum.in.tumcampusapp.utils.NetUtils) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) AlertDialog(android.app.AlertDialog) ArrayAdapter(android.widget.ArrayAdapter) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) TextView(android.widget.TextView) Utils(de.tum.in.tumcampusapp.utils.Utils) Location(android.location.Location) Cafeteria(de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) LayoutInflater(android.view.LayoutInflater) NonNull(android.support.annotation.NonNull) TextView(android.widget.TextView) ArrayList(java.util.ArrayList) List(java.util.List) Cafeteria(de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria) ArrayAdapter(android.widget.ArrayAdapter) Location(android.location.Location)

Aggregations

Cafeteria (de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria)3 Intent (android.content.Intent)2 R (de.tum.in.tumcampusapp.R)2 CafeteriaLocalRepository (de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository)2 TcaDb (de.tum.in.tumcampusapp.database.TcaDb)2 Const (de.tum.in.tumcampusapp.utils.Const)2 Flowable (io.reactivex.Flowable)2 AlertDialog (android.app.AlertDialog)1 PendingIntent (android.app.PendingIntent)1 AppWidgetManager (android.appwidget.AppWidgetManager)1 AppWidgetProvider (android.appwidget.AppWidgetProvider)1 Context (android.content.Context)1 Location (android.location.Location)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 ViewPager (android.support.v4.view.ViewPager)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1