vars optimalization
This commit is contained in:
parent
e46aab8948
commit
7b82b60324
1 changed files with 6 additions and 10 deletions
|
@ -32,10 +32,6 @@ import info.nightscout.utils.LocaleHelper;
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
private static Logger log = LoggerFactory.getLogger(MainActivity.class);
|
private static Logger log = LoggerFactory.getLogger(MainActivity.class);
|
||||||
|
|
||||||
private Toolbar toolbar;
|
|
||||||
private SlidingTabLayout mTabs;
|
|
||||||
private ViewPager mPager;
|
|
||||||
private static TabPageAdapter pageAdapter;
|
|
||||||
private static KeepAliveReceiver keepAliveReceiver;
|
private static KeepAliveReceiver keepAliveReceiver;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,16 +46,15 @@ public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
// show version in toolbar
|
// show version in toolbar
|
||||||
try {
|
try {
|
||||||
setTitle(getString(R.string.app_name) + " v" + getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
|
setTitle(getString(R.string.app_name) + " " + getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
registerBus();
|
registerBus();
|
||||||
|
|
||||||
if (keepAliveReceiver == null) {
|
if (keepAliveReceiver == null) {
|
||||||
|
|
||||||
keepAliveReceiver = new KeepAliveReceiver();
|
keepAliveReceiver = new KeepAliveReceiver();
|
||||||
startService(new Intent(this, ExecutionService.class));
|
startService(new Intent(this, ExecutionService.class));
|
||||||
keepAliveReceiver.setAlarm(this);
|
keepAliveReceiver.setAlarm(this);
|
||||||
|
@ -76,17 +71,18 @@ public class MainActivity extends AppCompatActivity {
|
||||||
try { // activity may be destroyed
|
try { // activity may be destroyed
|
||||||
setUpTabs(true);
|
setUpTabs(true);
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpTabs(boolean switchToLast) {
|
private void setUpTabs(boolean switchToLast) {
|
||||||
pageAdapter = new TabPageAdapter(getSupportFragmentManager(), this);
|
TabPageAdapter pageAdapter = new TabPageAdapter(getSupportFragmentManager(), this);
|
||||||
for (PluginBase p : MainApp.getPluginsList()) {
|
for (PluginBase p : MainApp.getPluginsList()) {
|
||||||
pageAdapter.registerNewFragment(p);
|
pageAdapter.registerNewFragment(p);
|
||||||
}
|
}
|
||||||
mPager = (ViewPager) findViewById(R.id.pager);
|
ViewPager mPager = (ViewPager) findViewById(R.id.pager);
|
||||||
mPager.setAdapter(pageAdapter);
|
mPager.setAdapter(pageAdapter);
|
||||||
mTabs = (SlidingTabLayout) findViewById(R.id.tabs);
|
SlidingTabLayout mTabs = (SlidingTabLayout) findViewById(R.id.tabs);
|
||||||
mTabs.setViewPager(mPager);
|
mTabs.setViewPager(mPager);
|
||||||
if (switchToLast)
|
if (switchToLast)
|
||||||
mPager.setCurrentItem(pageAdapter.getCount() - 1, false);
|
mPager.setCurrentItem(pageAdapter.getCount() - 1, false);
|
||||||
|
|
Loading…
Reference in a new issue