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 } }