@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setupDrawer(); getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp); MetricsManager.register(getApplication()); mContext = this; if (mPreferences.useAutoSync()) { SyncScheduler.schedule(this, mPreferences.isRequiresCharging()); } Intent i = getIntent(); if (i != null) { mOpenChangelog = i.getBooleanExtra(EXTRA_FROM_NOTIFICATION, false); i.removeExtra(EXTRA_FROM_NOTIFICATION); } int filterId = Filters.TAB_ALL; if (savedInstanceState != null && !mOpenChangelog) { filterId = savedInstanceState.getInt("tab_id", Filters.TAB_ALL); AppLog.d("Restore tab: " + filterId); } mViewPager = (ViewPager) findViewById(R.id.viewpager); setupViewPager(mViewPager); mViewPager.setCurrentItem(filterId); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); mRefreshAnim = new MenuItemAnimation(this, R.anim.rotate); }
@Override public void onHelperAccountSelected(Account account, String authToken) { super.onHelperAccountSelected(account, authToken); if (UpgradeCheck.isNewVersion(mPreferences)) { requestRefresh(); } }
@Override protected void onPause() { super.onPause(); if (mSyncFinishedReceiverRegistered) { unregisterReceiver(mSyncFinishedReceiver); mSyncFinishedReceiverRegistered = false; } }
@Override protected void onResume() { IntentFilter filter = new IntentFilter(); filter.addAction(SyncAdapter.SYNC_PROGRESS); filter.addAction(SyncAdapter.SYNC_STOP); filter.addAction(GcmTaskService.SERVICE_ACTION_EXECUTE_TASK); registerReceiver(mSyncFinishedReceiver, filter); mSyncFinishedReceiverRegistered = true; super.onResume(); AppLog.d("Mark updates as viewed."); mPreferences.markViewed(true); notifySyncStop(); CrashManager.register(this, Util.getAppIdentifier(this), App.provide(this).crashListener()); }
@Override protected void onSaveInstanceState(Bundle outState) { outState.putInt("tab_id", mViewPager.getCurrentItem()); super.onSaveInstanceState(outState); }