fix #154, properly update the actionbar title at yearly view

This commit is contained in:
tibbi 2017-04-22 12:56:21 +02:00
parent f63e7a5924
commit 00efe5b33a
2 changed files with 8 additions and 2 deletions

View File

@ -335,6 +335,10 @@ class MainActivity : SimpleActivity(), NavigationListener {
override fun onPageSelected(position: Int) {
invalidateOptionsMenu()
if (config.storedView == YEARLY_VIEW) {
val dateTime = Formatter.getDateTimeFromCode(codes[position])
title = "${getString(R.string.app_launcher_name)} - ${Formatter.getYear(dateTime)}"
}
}
})
currentItem = mDefaultMonthlyPage
@ -391,7 +395,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
override fun onPageSelected(position: Int) {
invalidateOptionsMenu()
setupActionbarTitle(weekTSs[position])
setupWeeklyActionbarTitle(weekTSs[position])
}
})
currentItem = mDefaultWeeklyPage
@ -419,7 +423,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
return weekTSs
}
private fun setupActionbarTitle(timestamp: Int) {
private fun setupWeeklyActionbarTitle(timestamp: Int) {
val startDateTime = Formatter.getDateTimeFromTS(timestamp)
val endDateTime = Formatter.getDateTimeFromTS(timestamp + WEEK_SECONDS)
val startMonthName = Formatter.getMonthName(this, startDateTime.monthOfYear)

View File

@ -67,6 +67,8 @@ object Formatter {
// use manually translated month names, as DateFormat and Joda have issues with a lot of languages
fun getMonthName(context: Context, id: Int) = context.resources.getStringArray(R.array.months)[id - 1]
fun getYear(dateTime: DateTime) = dateTime.toString(YEAR_PATTERN)
fun getHourPattern(context: Context) = if (context.config.use24hourFormat) PATTERN_HOURS_24 else PATTERN_HOURS_12
fun getTimePattern(context: Context) = if (context.config.use24hourFormat) PATTERN_TIME_24 else PATTERN_TIME_12