From d7502ec27734b7deaf074f228c866d236b540598 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 19 Oct 2016 23:33:57 +0200 Subject: [PATCH] go back to yearly view on pressing Back from month view --- .../calendar/activities/MainActivity.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt index 2b11ba946..f540c61d3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt @@ -22,6 +22,8 @@ class MainActivity : SimpleActivity(), NavigationListener { private val PREFILLED_MONTHS = 73 private val PREFILLED_YEARS = 21 + private var mIsMonthSelected = false + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) @@ -71,7 +73,16 @@ class MainActivity : SimpleActivity(), NavigationListener { } } + override fun onBackPressed() { + if (mIsMonthSelected && mConfig.view == Constants.YEARLY_VIEW) { + updateView(Constants.YEARLY_VIEW) + } else { + super.onBackPressed() + } + } + private fun updateView(view: Int) { + mIsMonthSelected = view == Constants.MONTHLY_VIEW mConfig.view = view updateViewPager() Handler().postDelayed({ invalidateOptionsMenu() }, 500) @@ -152,5 +163,6 @@ class MainActivity : SimpleActivity(), NavigationListener { override fun goToDateTime(dateTime: DateTime) { fillMonthlyViewPager(Formatter.getDayCodeFromDateTime(dateTime)) + mIsMonthSelected = true } }