Search in sources :

Example 1 with AnkiStatsTaskHandler

use of com.ichi2.anki.stats.AnkiStatsTaskHandler in project AnkiChinaAndroid by ankichinateam.

the class Statistics method loadData.

public void loadData(Collection col) {
    Timber.d("onCollectionLoaded():%s", getAnkiActivity());
    if (getAnkiActivity() == null || col == null) {
        return;
    }
    mDropDownDecks = col.getDecks().allSorted();
    mActionBarSpinner.setAdapter(new DeckDropDownAdapter(getContext(), mDropDownDecks, R.layout.dropdown_deck_selected_item_static, this));
    // Setup Task Handler
    mTaskHandler = new AnkiStatsTaskHandler(col);
    // Dirty way to get text size from a TextView with current style, change if possible
    float size = new TextView(getContext()).getTextSize();
    mTaskHandler.setmStandardTextSize(size);
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    // Set up the ViewPager with the sections adapter.
    mViewPager.setAdapter(new StatsPagerAdapter(getChildFragmentManager()));
    mSlidingTabLayout = mRoot.findViewById(R.id.sliding_tabs);
    // Fixes #8984: scroll to position 0 in RTL layouts
    ViewTreeObserver tabObserver = mSlidingTabLayout.getViewTreeObserver();
    tabObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        // Note: we can't use a lambda as we use 'this' to refer to the class.
        @Override
        public void onGlobalLayout() {
            // we need this here: If we select tab 0 before in an RTL context the layout has been drawn,
            // then it doesn't perform a scroll animation and selects the wrong element
            mSlidingTabLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            mSlidingTabLayout.selectTab(mSlidingTabLayout.getTabAt(0));
        }
    });
    // Prepare options menu only after loading everything
    getAnkiActivity().supportInvalidateOptionsMenu();
    // initMenu(mToolbar.getMenu());
    mViewPager.getAdapter().notifyDataSetChanged();
    // Default to libanki's selected deck
    selectDeckById(col.getDecks().selected());
}
Also used : TextView(android.widget.TextView) AnkiStatsTaskHandler(com.ichi2.anki.stats.AnkiStatsTaskHandler) ViewTreeObserver(android.view.ViewTreeObserver) DeckDropDownAdapter(com.ichi2.anki.widgets.DeckDropDownAdapter)

Aggregations

ViewTreeObserver (android.view.ViewTreeObserver)1 TextView (android.widget.TextView)1 AnkiStatsTaskHandler (com.ichi2.anki.stats.AnkiStatsTaskHandler)1 DeckDropDownAdapter (com.ichi2.anki.widgets.DeckDropDownAdapter)1