use selected hour format at weekly view
This commit is contained in:
parent
e92d0f9bf6
commit
b7bcfe8d28
|
@ -49,6 +49,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
||||||
private var mStoredBackgroundColor = 0
|
private var mStoredBackgroundColor = 0
|
||||||
private var mStoredPrimaryColor = 0
|
private var mStoredPrimaryColor = 0
|
||||||
private var mStoredIsSundayFirst = false
|
private var mStoredIsSundayFirst = false
|
||||||
|
private var mStoredUse24HourFormat = false
|
||||||
private var mShouldFilterBeVisible = false
|
private var mShouldFilterBeVisible = false
|
||||||
|
|
||||||
private var mDefaultWeeklyPage = 0
|
private var mDefaultWeeklyPage = 0
|
||||||
|
@ -82,8 +83,11 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
||||||
mStoredPrimaryColor = config.primaryColor
|
mStoredPrimaryColor = config.primaryColor
|
||||||
mStoredBackgroundColor = config.backgroundColor
|
mStoredBackgroundColor = config.backgroundColor
|
||||||
|
|
||||||
if (mStoredIsSundayFirst != config.isSundayFirst && config.storedView == WEEKLY_VIEW)
|
if (config.storedView == WEEKLY_VIEW) {
|
||||||
|
if (mStoredIsSundayFirst != config.isSundayFirst || mStoredUse24HourFormat != config.use24hourFormat) {
|
||||||
fillWeeklyViewPager()
|
fillWeeklyViewPager()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateWidgets()
|
updateWidgets()
|
||||||
updateTextColors(calendar_coordinator)
|
updateTextColors(calendar_coordinator)
|
||||||
|
@ -95,6 +99,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
||||||
mStoredIsSundayFirst = config.isSundayFirst
|
mStoredIsSundayFirst = config.isSundayFirst
|
||||||
mStoredBackgroundColor = config.backgroundColor
|
mStoredBackgroundColor = config.backgroundColor
|
||||||
mStoredPrimaryColor = config.primaryColor
|
mStoredPrimaryColor = config.primaryColor
|
||||||
|
mStoredUse24HourFormat = config.use24hourFormat
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
@ -288,10 +293,11 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
||||||
main_weekly_scrollview.beVisible()
|
main_weekly_scrollview.beVisible()
|
||||||
|
|
||||||
week_view_hours_holder.removeAllViews()
|
week_view_hours_holder.removeAllViews()
|
||||||
|
val hourDateTime = DateTime().withTime(0, 0, 0, 0)
|
||||||
for (i in 1..23) {
|
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 {
|
(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)
|
setTextColor(mStoredTextColor)
|
||||||
week_view_hours_holder.addView(this)
|
week_view_hours_holder.addView(this)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,9 @@ object Formatter {
|
||||||
private val PATTERN_TIME_12 = "hh:mm a"
|
private val PATTERN_TIME_12 = "hh:mm a"
|
||||||
private val PATTERN_TIME_24 = "HH:mm"
|
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 {
|
fun getDateFromCode(context: Context, dayCode: String, shortMonth: Boolean = false): String {
|
||||||
val dateTime = getDateTimeFromCode(dayCode)
|
val dateTime = getDateTimeFromCode(dayCode)
|
||||||
val day = dateTime.toString(DAY_PATTERN)
|
val day = dateTime.toString(DAY_PATTERN)
|
||||||
|
@ -42,6 +45,8 @@ object Formatter {
|
||||||
|
|
||||||
fun getDate(context: Context, dateTime: DateTime, addDayOfWeek: Boolean = true) = getDayTitle(context, getDayCodeFromDateTime(dateTime), addDayOfWeek)
|
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 getTime(context: Context, dateTime: DateTime) = dateTime.toString(getTimePattern(context))
|
||||||
|
|
||||||
fun getDateTimeFromCode(dayCode: String) = DateTimeFormat.forPattern(DAYCODE_PATTERN).withZone(DateTimeZone.UTC).parseDateTime(dayCode)
|
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
|
// 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 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
|
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"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="bottom"
|
android:gravity="bottom|center_horizontal"
|
||||||
android:minHeight="@dimen/weekly_view_row_height"
|
android:minHeight="@dimen/weekly_view_row_height"
|
||||||
android:paddingLeft="@dimen/medium_margin"
|
android:paddingLeft="@dimen/small_margin"
|
||||||
android:paddingRight="@dimen/medium_margin"
|
android:paddingRight="@dimen/small_margin"
|
||||||
android:textSize="@dimen/normal_text_size"/>
|
android:textSize="@dimen/normal_text_size"/>
|
||||||
|
|
Loading…
Reference in New Issue