use of ua.napps.scorekeeper.counters.CountersFragment in project ScoreCounter by n-apps.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
isKeepScreenOn = LocalSettings.isKeepScreenOnEnabled();
if (savedInstanceState != null) {
currentDiceRoll = savedInstanceState.getInt(STATE_CURRENT_DICE_ROLL);
previousDiceRoll = savedInstanceState.getInt(STATE_PREVIOUS_DICE_ROLL);
}
boolean isLightTheme = LocalSettings.isLightTheme();
// If android Q override night mode settings from system default
if (Utilities.hasQ()) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
LocalSettings.saveDarkTheme((currentNightMode == Configuration.UI_MODE_NIGHT_YES));
} else {
AppCompatDelegate.setDefaultNightMode(isLightTheme ? AppCompatDelegate.MODE_NIGHT_NO : AppCompatDelegate.MODE_NIGHT_YES);
}
setContentView(R.layout.activity_main);
rateMyAppDialog = new RateMyAppDialog(this);
manager = getSupportFragmentManager();
bottomNavigationBar = findViewById(R.id.bottom_navigation);
bottomNavigationBar.setSelectedItemId(R.id.counters);
bottomNavigationBar.setOnItemSelectedListener(item -> {
switch(item.getItemId()) {
case R.id.counters:
switchFragment(TAGS[0]);
if (currentDiceRoll > 0) {
BadgeDrawable badge = bottomNavigationBar.getOrCreateBadge(R.id.dices);
badge.setVisible(true);
int primary = ContextCompat.getColor(this, R.color.colorSecondary);
badge.setBackgroundColor(primary);
badge.setNumber(currentDiceRoll);
} else {
hideDiceBadge();
}
bottomNavigationBar.setElevation(0);
break;
case R.id.dices:
switchFragment(TAGS[1]);
hideDiceBadge();
bottomNavigationBar.setElevation(0);
break;
case R.id.more:
switchFragment(TAGS[2]);
hideDiceBadge();
bottomNavigationBar.setElevation(20);
break;
}
return true;
});
bottomNavigationBar.setOnItemReselectedListener(item -> {
if (item.getItemId() == R.id.counters) {
if (currentFragment instanceof CountersFragment) {
((CountersFragment) currentFragment).scrollToTop();
}
}
});
switchFragment(TAGS[0]);
if (isLightTheme) {
ViewUtil.setLightStatusBar(this);
} else {
ViewUtil.clearLightStatusBar(this);
}
ViewUtil.setNavBarColor(this, isLightTheme);
applyKeepScreenOnIfNeeded();
}
Aggregations