Search in sources :

Example 1 with CafeteriaDetailsSectionsPagerAdapter

use of de.tum.in.tumcampusapp.component.ui.cafeteria.details.CafeteriaDetailsSectionsPagerAdapter in project TumCampusApp by TCA-Team.

the class CafeteriaActivity method onItemSelected.

/**
 * Switch cafeteria if a new cafeteria has been selected
 *
 * @param parent the parent view
 * @param pos    index of the new selection
 * @param id     id of the selected item
 */
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
    Intent intent = getIntent();
    // check if Activity triggered from favoriteDish Notification
    if (intent != null && intent.getExtras() != null && intent.getExtras().containsKey(Const.MENSA_FOR_FAVORITEDISH)) {
        for (int i = 0; i < parent.getCount(); i++) {
            // get mensaId from extra to redirect the user to it.
            if (intent.getExtras().getInt(Const.MENSA_FOR_FAVORITEDISH) == mCafeterias.get(i).getId()) {
                mCafeteriaId = mCafeterias.get(i).getId();
                parent.setSelection(i);
                intent.removeExtra(Const.MENSA_FOR_FAVORITEDISH);
                break;
            }
        }
    } else {
        mCafeteriaId = mCafeterias.get(pos).getId();
    }
    CafeteriaDetailsSectionsPagerAdapter mSectionsPagerAdapter = new CafeteriaDetailsSectionsPagerAdapter(getSupportFragmentManager());
    // Create the adapter that will return a fragment for each of the primary sections of the app.
    // unset the adapter for updating
    mViewPager.setAdapter(null);
    mSectionsPagerAdapter.setCafeteriaId(this, mCafeteriaId);
    mViewPager.setAdapter(mSectionsPagerAdapter);
}
Also used : CafeteriaDetailsSectionsPagerAdapter(de.tum.in.tumcampusapp.component.ui.cafeteria.details.CafeteriaDetailsSectionsPagerAdapter) Intent(android.content.Intent)

Aggregations

Intent (android.content.Intent)1 CafeteriaDetailsSectionsPagerAdapter (de.tum.in.tumcampusapp.component.ui.cafeteria.details.CafeteriaDetailsSectionsPagerAdapter)1