Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c2481a39 authored by Gabor Keszthelyi's avatar Gabor Keszthelyi Committed by Marten Gajda
Browse files

Fix ViewPager-TabLayout bug about loosing the tab icons. #643 (#656)

parent e39302a9
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -267,12 +267,7 @@ public class TaskListActivity extends BaseActivity implements TaskListFragment.C
        // Bind the tabs to the ViewPager
        mTabs = (TabLayout) findViewById(R.id.tabs);
        mTabs.setupWithViewPager(mViewPager);

        // set up the tab icons
        for (int i = 0, count = mPagerAdapter.getCount(); i < count; ++i)
        {
            mTabs.getTabAt(i).setIcon(mPagerAdapter.getTabIcon(i));
        }
        setupTabIcons();

        mViewPager.addOnPageChangeListener(new OnPageChangeListener()
        {
@@ -347,6 +342,15 @@ public class TaskListActivity extends BaseActivity implements TaskListFragment.C
    }


    private void setupTabIcons()
    {
        for (int i = 0, count = mPagerAdapter.getCount(); i < count; ++i)
        {
            mTabs.getTabAt(i).setIcon(mPagerAdapter.getTabIcon(i));
        }
    }


    @Override
    protected void onResume()
    {
@@ -528,6 +532,11 @@ public class TaskListActivity extends BaseActivity implements TaskListFragment.C
            Uri newTaskUri = intent.getData();
            displayIntent.setData(newTaskUri);
            onNewIntent(displayIntent);

            /* Icons have to be refreshed here because of some bug in ViewPager-TabLayout which causes them to disappear.
            See https://github.com/dmfs/opentasks/issues/643
            and https://stackoverflow.com/questions/42209046/tablayout-icons-disappear-after-viewpager-refresh */
            setupTabIcons();
        }
    }