show the sorting menu button only at the Alarms tab

This commit is contained in:
tibbi 2021-04-19 15:55:10 +02:00
parent f5aef41a6e
commit b7fdedb939
2 changed files with 11 additions and 0 deletions

View File

@ -81,11 +81,17 @@ class MainActivity : SimpleActivity() {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu, menu)
menu.apply {
findItem(R.id.sort).isVisible = view_pager.currentItem == TAB_ALARM
updateMenuItemColors(this)
}
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.sort -> getViewPagerAdapter()?.showAlarmSortDialog()
R.id.settings -> launchSettings()
R.id.about -> launchAbout()
else -> return super.onOptionsItemSelected(item)
@ -133,6 +139,7 @@ class MainActivity : SimpleActivity() {
view_pager.adapter = ViewPagerAdapter(supportFragmentManager)
view_pager.onPageChangeListener {
main_tabs_holder.getTabAt(it)?.select()
invalidateOptionsMenu()
}
val tabToOpen = intent.getIntExtra(OPEN_TAB, config.lastUsedViewPagerPage)

View File

@ -38,6 +38,10 @@ class ViewPagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) {
else -> throw RuntimeException("Trying to fetch unknown fragment id $position")
}
fun showAlarmSortDialog() {
(fragments[TAB_ALARM] as? AlarmFragment)?.showSortingDialog()
}
fun updateClockTabAlarm() {
(fragments[TAB_CLOCK] as? ClockFragment)?.updateAlarm()
}