use selected hour format at weekly view
This commit is contained in:
parent
e92d0f9bf6
commit
b7bcfe8d28
3 changed files with 21 additions and 8 deletions
|
@ -49,6 +49,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
|||
private var mStoredBackgroundColor = 0
|
||||
private var mStoredPrimaryColor = 0
|
||||
private var mStoredIsSundayFirst = false
|
||||
private var mStoredUse24HourFormat = false
|
||||
private var mShouldFilterBeVisible = false
|
||||
|
||||
private var mDefaultWeeklyPage = 0
|
||||
|
@ -82,8 +83,11 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
|||
mStoredPrimaryColor = config.primaryColor
|
||||
mStoredBackgroundColor = config.backgroundColor
|
||||
|
||||
if (mStoredIsSundayFirst != config.isSundayFirst && config.storedView == WEEKLY_VIEW)
|
||||
fillWeeklyViewPager()
|
||||
if (config.storedView == WEEKLY_VIEW) {
|
||||
if (mStoredIsSundayFirst != config.isSundayFirst || mStoredUse24HourFormat != config.use24hourFormat) {
|
||||
fillWeeklyViewPager()
|
||||
}
|
||||
}
|
||||
|
||||
updateWidgets()
|
||||
updateTextColors(calendar_coordinator)
|
||||
|
@ -95,6 +99,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
|||
mStoredIsSundayFirst = config.isSundayFirst
|
||||
mStoredBackgroundColor = config.backgroundColor
|
||||
mStoredPrimaryColor = config.primaryColor
|
||||
mStoredUse24HourFormat = config.use24hourFormat
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
@ -288,10 +293,11 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
|||
main_weekly_scrollview.beVisible()
|
||||
|
||||
week_view_hours_holder.removeAllViews()
|
||||
val hourDateTime = DateTime().withTime(0, 0, 0, 0)
|
||||
for (i in 1..23) {
|
||||
val value = i.toString()
|
||||
val formattedHours = Formatter.getHours(this, hourDateTime.withHourOfDay(i))
|
||||
(layoutInflater.inflate(R.layout.weekly_view_hour_textview, null, false) as TextView).apply {
|
||||
text = if (value.length == 2) value else "0$value"
|
||||
text = formattedHours
|
||||
setTextColor(mStoredTextColor)
|
||||
week_view_hours_holder.addView(this)
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@ object Formatter {
|
|||
private val PATTERN_TIME_12 = "hh:mm a"
|
||||
private val PATTERN_TIME_24 = "HH:mm"
|
||||
|
||||
private val PATTERN_HOURS_12 = "h a"
|
||||
private val PATTERN_HOURS_24 = "HH"
|
||||
|
||||
fun getDateFromCode(context: Context, dayCode: String, shortMonth: Boolean = false): String {
|
||||
val dateTime = getDateTimeFromCode(dayCode)
|
||||
val day = dateTime.toString(DAY_PATTERN)
|
||||
|
@ -23,7 +26,7 @@ object Formatter {
|
|||
val monthIndex = Integer.valueOf(dayCode.substring(4, 6))!!
|
||||
var month = getMonthName(context, monthIndex)
|
||||
if (shortMonth)
|
||||
month = month.substring(0, Math.min(month.length, 3))
|
||||
month = month.substring(0, Math.min(month.length, 3))
|
||||
var date = "$month $day"
|
||||
if (year != DateTime().toString(YEAR_PATTERN))
|
||||
date += " $year"
|
||||
|
@ -42,6 +45,8 @@ object Formatter {
|
|||
|
||||
fun getDate(context: Context, dateTime: DateTime, addDayOfWeek: Boolean = true) = getDayTitle(context, getDayCodeFromDateTime(dateTime), addDayOfWeek)
|
||||
|
||||
fun getHours(context: Context, dateTime: DateTime) = dateTime.toString(getHourPattern(context))
|
||||
|
||||
fun getTime(context: Context, dateTime: DateTime) = dateTime.toString(getTimePattern(context))
|
||||
|
||||
fun getDateTimeFromCode(dayCode: String) = DateTimeFormat.forPattern(DAYCODE_PATTERN).withZone(DateTimeZone.UTC).parseDateTime(dayCode)
|
||||
|
@ -63,5 +68,7 @@ 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 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
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="bottom"
|
||||
android:gravity="bottom|center_horizontal"
|
||||
android:minHeight="@dimen/weekly_view_row_height"
|
||||
android:paddingLeft="@dimen/medium_margin"
|
||||
android:paddingRight="@dimen/medium_margin"
|
||||
android:paddingLeft="@dimen/small_margin"
|
||||
android:paddingRight="@dimen/small_margin"
|
||||
android:textSize="@dimen/normal_text_size"/>
|
||||
|
|
Loading…
Reference in a new issue