use of org.wordpress.android.util.CoreEvents.MainViewPagerScrolled in project WordPress-Android by wordpress-mobile.
the class WPMainActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
ProfilingUtils.split("WPMainActivity.onCreate");
((WordPress) getApplication()).component().inject(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
mViewPager = (WPViewPager) findViewById(R.id.viewpager_main);
mViewPager.setOffscreenPageLimit(WPMainTabAdapter.NUM_TABS - 1);
mTabAdapter = new WPMainTabAdapter(getFragmentManager());
mViewPager.setAdapter(mTabAdapter);
mConnectionBar = (TextView) findViewById(R.id.connection_bar);
mConnectionBar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// slide out the bar on click, then re-check connection after a brief delay
AniUtils.animateBottomBar(mConnectionBar, false);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (!isFinishing()) {
checkConnection();
}
}
}, 2000);
}
});
mTabLayout = (WPMainTabLayout) findViewById(R.id.tab_layout);
mTabLayout.createTabs();
mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
// nop
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
//scroll the active fragment's contents to the top when user taps the current tab
Fragment fragment = mTabAdapter.getFragment(tab.getPosition());
if (fragment instanceof OnScrollToTopListener) {
((OnScrollToTopListener) fragment).onScrollToTop();
}
}
});
mAppBarElevation = getResources().getDimensionPixelSize(R.dimen.appbar_elevation);
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
AppPrefs.setMainTabIndex(position);
switch(position) {
case WPMainTabAdapter.TAB_MY_SITE:
setTabLayoutElevation(mAppBarElevation);
break;
case WPMainTabAdapter.TAB_READER:
setTabLayoutElevation(0);
break;
case WPMainTabAdapter.TAB_ME:
setTabLayoutElevation(mAppBarElevation);
break;
case WPMainTabAdapter.TAB_NOTIFS:
setTabLayoutElevation(mAppBarElevation);
Fragment fragment = mTabAdapter.getFragment(position);
if (fragment instanceof OnScrollToTopListener) {
((OnScrollToTopListener) fragment).onScrollToTop();
}
break;
}
trackLastVisibleTab(position, true);
}
@Override
public void onPageScrollStateChanged(int state) {
// noop
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
// animate its fab to match
if (position == WPMainTabAdapter.TAB_MY_SITE) {
EventBus.getDefault().post(new MainViewPagerScrolled(positionOffset));
}
}
});
if (savedInstanceState == null) {
if (FluxCUtils.isSignedInWPComOrHasWPOrgSite(mAccountStore, mSiteStore)) {
// open note detail if activity called from a push, otherwise return to the tab
// that was showing last time
boolean openedFromPush = (getIntent() != null && getIntent().getBooleanExtra(ARG_OPENED_FROM_PUSH, false));
if (openedFromPush) {
getIntent().putExtra(ARG_OPENED_FROM_PUSH, false);
if (getIntent().hasExtra(NotificationsPendingDraftsReceiver.POST_ID_EXTRA)) {
launchWithPostId(getIntent().getIntExtra(NotificationsPendingDraftsReceiver.POST_ID_EXTRA, 0), getIntent().getBooleanExtra(NotificationsPendingDraftsReceiver.IS_PAGE_EXTRA, false));
} else {
launchWithNoteId();
}
} else {
int position = AppPrefs.getMainTabIndex();
if (mTabAdapter.isValidPosition(position) && position != mViewPager.getCurrentItem()) {
mViewPager.setCurrentItem(position);
}
checkMagicLinkSignIn();
}
} else {
ActivityLauncher.showSignInForResult(this);
}
}
startService(new Intent(this, NotificationsScreenLockWatchService.class));
// ensure the deep linking activity is enabled. It may have been disabled elsewhere and failed to get re-enabled
WPActivityUtils.enableComponent(this, ReaderPostPagerActivity.class);
// monitor whether we're not the default app
trackDefaultApp();
}
Aggregations