Search in sources :

Example 1 with EventsByWeekFragmentPagerAdapter

use of com.thebluealliance.androidclient.adapters.EventsByWeekFragmentPagerAdapter in project the-blue-alliance-android by the-blue-alliance.

the class EventsByWeekFragment method getIndexForWeek.

/**
 * Finds the index in the adapter of the given week.
 * If the week is skipped over, return the next week (assumes sorted adapter items)
 *
 * @return Adapter index containing the week, -1 if not found
 */
private int getIndexForWeek(int week) {
    Preconditions.checkState(mViewPager.getAdapter() instanceof EventsByWeekFragmentPagerAdapter, "EventsByWeekFragment must use EventsByWeekFragmentPagerAdapter");
    List<EventWeekTab> tabs = ((EventsByWeekFragmentPagerAdapter) mViewPager.getAdapter()).getTabs();
    for (int i = 0; i < tabs.size(); i++) {
        if (tabs.get(i).getWeek() >= week) {
            return i;
        }
    }
    return -1;
}
Also used : EventsByWeekFragmentPagerAdapter(com.thebluealliance.androidclient.adapters.EventsByWeekFragmentPagerAdapter) EventWeekTab(com.thebluealliance.androidclient.models.EventWeekTab) AndroidEntryPoint(dagger.hilt.android.AndroidEntryPoint)

Example 2 with EventsByWeekFragmentPagerAdapter

use of com.thebluealliance.androidclient.adapters.EventsByWeekFragmentPagerAdapter in project the-blue-alliance-android by the-blue-alliance.

the class EventsByWeekFragment method updateLabels.

public void updateLabels(List<EventWeekTab> labels) {
    if (getView() != null) {
        getView().findViewById(R.id.tabs_progress).setVisibility(View.GONE);
    }
    mFragmentAdapter = new EventsByWeekFragmentPagerAdapter(getChildFragmentManager(), mYear, labels);
    mFragmentBinder.setAdapter(mFragmentAdapter);
    mViewPager.setAdapter(mFragmentAdapter);
    mTabs.setViewPager(mViewPager);
    if (mPagerState != null) {
        mViewPager.onRestoreInstanceState(mPagerState);
        mFragmentAdapter.restoreState(mAdapterState, ClassLoader.getSystemClassLoader());
    } else if (mSelectedTab != -1) {
        mViewPager.setCurrentItem(mSelectedTab);
        mFragmentBinder.onPageSelected(mSelectedTab);
    } else {
        setPagerWeek();
        mViewPager.setCurrentItem(mSelectedTab);
        mFragmentBinder.onPageSelected(mSelectedTab);
    }
    mFragmentAdapter.setAutoBindOnceAtPosition(mViewPager.getCurrentItem(), true);
}
Also used : EventsByWeekFragmentPagerAdapter(com.thebluealliance.androidclient.adapters.EventsByWeekFragmentPagerAdapter)

Aggregations

EventsByWeekFragmentPagerAdapter (com.thebluealliance.androidclient.adapters.EventsByWeekFragmentPagerAdapter)2 EventWeekTab (com.thebluealliance.androidclient.models.EventWeekTab)1 AndroidEntryPoint (dagger.hilt.android.AndroidEntryPoint)1