use 12 or 24 hours format as appropriate
This commit is contained in:
parent
ecd384f1af
commit
32dc35b6c7
7 changed files with 27 additions and 23 deletions
|
@ -290,19 +290,19 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateStartDate() {
|
private fun updateStartDate() {
|
||||||
event_start_date.text = Formatter.getEventDate(applicationContext, mEventStartDateTime)
|
event_start_date.text = Formatter.getDate(applicationContext, mEventStartDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateStartTime() {
|
private fun updateStartTime() {
|
||||||
event_start_time.text = Formatter.getEventTime(mEventStartDateTime)
|
event_start_time.text = Formatter.getTime(this, mEventStartDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateEndDate() {
|
private fun updateEndDate() {
|
||||||
event_end_date.text = Formatter.getEventDate(applicationContext, mEventEndDateTime)
|
event_end_date.text = Formatter.getDate(applicationContext, mEventEndDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateEndTime() {
|
private fun updateEndTime() {
|
||||||
event_end_time.text = Formatter.getEventTime(mEventEndDateTime)
|
event_end_time.text = Formatter.getTime(this, mEventEndDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setupStartDate() {
|
fun setupStartDate() {
|
||||||
|
|
|
@ -51,7 +51,7 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
|
||||||
mTopDivider = activity.resources.getDrawable(R.drawable.divider)
|
mTopDivider = activity.resources.getDrawable(R.drawable.divider)
|
||||||
mOrangeColor = activity.resources.getColor(R.color.colorPrimary)
|
mOrangeColor = activity.resources.getColor(R.color.colorPrimary)
|
||||||
val mTodayCode = Formatter.getDayCodeFromTS(mNow)
|
val mTodayCode = Formatter.getDayCodeFromTS(mNow)
|
||||||
mTodayDate = Formatter.getEventDate(activity, mTodayCode)
|
mTodayDate = Formatter.getDate(activity, mTodayCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
||||||
|
@ -121,19 +121,19 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
|
||||||
itemView.apply {
|
itemView.apply {
|
||||||
event_item_title.text = item.title
|
event_item_title.text = item.title
|
||||||
event_item_description.text = item.description
|
event_item_description.text = item.description
|
||||||
event_item_start.text = Formatter.getTime(item.startTS)
|
event_item_start.text = Formatter.getTimeFromTS(context, item.startTS)
|
||||||
toggleItemSelection(this, markedItems.contains(pos), pos)
|
toggleItemSelection(this, markedItems.contains(pos), pos)
|
||||||
|
|
||||||
if (item.startTS == item.endTS) {
|
if (item.startTS == item.endTS) {
|
||||||
event_item_end.visibility = View.INVISIBLE
|
event_item_end.visibility = View.INVISIBLE
|
||||||
} else {
|
} else {
|
||||||
event_item_end.text = Formatter.getTime(item.endTS)
|
event_item_end.text = Formatter.getTimeFromTS(context, item.endTS)
|
||||||
event_item_end.visibility = View.VISIBLE
|
event_item_end.visibility = View.VISIBLE
|
||||||
|
|
||||||
val startCode = Formatter.getDayCodeFromTS(item.startTS)
|
val startCode = Formatter.getDayCodeFromTS(item.startTS)
|
||||||
val endCode = Formatter.getDayCodeFromTS(item.endTS)
|
val endCode = Formatter.getDayCodeFromTS(item.endTS)
|
||||||
if (startCode != endCode) {
|
if (startCode != endCode) {
|
||||||
event_item_end.append(" (${Formatter.getEventDate(context, endCode)})")
|
event_item_end.append(" (${Formatter.getDate(context, endCode)})")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,8 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
|
||||||
remoteView.apply {
|
remoteView.apply {
|
||||||
setTextViewText(R.id.event_item_title, item.title)
|
setTextViewText(R.id.event_item_title, item.title)
|
||||||
setTextViewText(R.id.event_item_description, item.description)
|
setTextViewText(R.id.event_item_description, item.description)
|
||||||
setTextViewText(R.id.event_item_start, Formatter.getTime(item.startTS))
|
setTextViewText(R.id.event_item_start, Formatter.getTimeFromTS(context, item.startTS))
|
||||||
setTextViewText(R.id.event_item_end, Formatter.getTime(item.endTS))
|
setTextViewText(R.id.event_item_end, Formatter.getTimeFromTS(context, item.endTS))
|
||||||
|
|
||||||
setInt(R.id.event_item_title, "setTextColor", textColor)
|
setInt(R.id.event_item_title, "setTextColor", textColor)
|
||||||
setInt(R.id.event_item_description, "setTextColor", textColor)
|
setInt(R.id.event_item_description, "setTextColor", textColor)
|
||||||
|
|
|
@ -50,18 +50,18 @@ class EventListWidgetAdapterOld(val context: Context, val mEvents: List<ListItem
|
||||||
viewHolder.apply {
|
viewHolder.apply {
|
||||||
title.text = item.title
|
title.text = item.title
|
||||||
description?.text = item.description
|
description?.text = item.description
|
||||||
start?.text = Formatter.getTime(item.startTS)
|
start?.text = Formatter.getTimeFromTS(context, item.startTS)
|
||||||
|
|
||||||
if (item.startTS == item.endTS) {
|
if (item.startTS == item.endTS) {
|
||||||
end?.visibility = View.INVISIBLE
|
end?.visibility = View.INVISIBLE
|
||||||
} else {
|
} else {
|
||||||
end?.text = Formatter.getTime(item.endTS)
|
end?.text = Formatter.getTimeFromTS(context, item.endTS)
|
||||||
end?.visibility = View.VISIBLE
|
end?.visibility = View.VISIBLE
|
||||||
|
|
||||||
val startCode = Formatter.getDayCodeFromTS(item.startTS)
|
val startCode = Formatter.getDayCodeFromTS(item.startTS)
|
||||||
val endCode = Formatter.getDayCodeFromTS(item.endTS)
|
val endCode = Formatter.getDayCodeFromTS(item.endTS)
|
||||||
if (startCode != endCode) {
|
if (startCode != endCode) {
|
||||||
end?.append(" (${Formatter.getEventDate(context, endCode)})")
|
end?.append(" (${Formatter.getDate(context, endCode)})")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,13 +93,13 @@ class EventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, val l
|
||||||
itemView.apply {
|
itemView.apply {
|
||||||
event_item_title.text = event.title
|
event_item_title.text = event.title
|
||||||
event_item_description.text = event.description
|
event_item_description.text = event.description
|
||||||
event_item_start.text = Formatter.getTime(event.startTS)
|
event_item_start.text = Formatter.getTimeFromTS(context, event.startTS)
|
||||||
toggleItemSelection(this, markedItems.contains(pos), pos)
|
toggleItemSelection(this, markedItems.contains(pos), pos)
|
||||||
|
|
||||||
if (event.startTS == event.endTS) {
|
if (event.startTS == event.endTS) {
|
||||||
event_item_end.visibility = View.INVISIBLE
|
event_item_end.visibility = View.INVISIBLE
|
||||||
} else {
|
} else {
|
||||||
event_item_end.text = Formatter.getTime(event.endTS)
|
event_item_end.text = Formatter.getTimeFromTS(context, event.endTS)
|
||||||
event_item_end.visibility = View.VISIBLE
|
event_item_end.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.simplemobiletools.calendar.helpers
|
package com.simplemobiletools.calendar.helpers
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.text.format.DateFormat
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import org.joda.time.DateTimeZone
|
import org.joda.time.DateTimeZone
|
||||||
|
@ -11,9 +12,10 @@ object Formatter {
|
||||||
val YEAR_PATTERN = "YYYY"
|
val YEAR_PATTERN = "YYYY"
|
||||||
private val DAY_PATTERN = "d"
|
private val DAY_PATTERN = "d"
|
||||||
private val DAY_OF_WEEK_PATTERN = "EEE"
|
private val DAY_OF_WEEK_PATTERN = "EEE"
|
||||||
private val EVENT_TIME_PATTERN = "HH:mm"
|
private val PATTERN_TIME_12 = "h:mm a"
|
||||||
|
private val PATTERN_TIME_24 = "k:mm"
|
||||||
|
|
||||||
fun getEventDate(context: Context, dayCode: String): String {
|
fun getDate(context: Context, dayCode: String): String {
|
||||||
val dateTime = getDateTimeFromCode(dayCode)
|
val dateTime = getDateTimeFromCode(dayCode)
|
||||||
val day = dateTime.toString(DAY_PATTERN)
|
val day = dateTime.toString(DAY_PATTERN)
|
||||||
val year = dateTime.toString(YEAR_PATTERN)
|
val year = dateTime.toString(YEAR_PATTERN)
|
||||||
|
@ -26,21 +28,21 @@ object Formatter {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDayTitle(context: Context, dayCode: String): String {
|
fun getDayTitle(context: Context, dayCode: String): String {
|
||||||
val date = getEventDate(context, dayCode)
|
val date = getDate(context, dayCode)
|
||||||
val dateTime = getDateTimeFromCode(dayCode)
|
val dateTime = getDateTimeFromCode(dayCode)
|
||||||
val day = dateTime.toString(DAY_OF_WEEK_PATTERN)
|
val day = dateTime.toString(DAY_OF_WEEK_PATTERN)
|
||||||
return "$date ($day)"
|
return "$date ($day)"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEventDate(context: Context, dateTime: DateTime) = getDayTitle(context, getDayCodeFromDateTime(dateTime))
|
fun getDate(context: Context, dateTime: DateTime) = getDayTitle(context, getDayCodeFromDateTime(dateTime))
|
||||||
|
|
||||||
fun getEventTime(dateTime: DateTime) = dateTime.toString(EVENT_TIME_PATTERN)
|
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)
|
||||||
|
|
||||||
fun getLocalDateTimeFromCode(dayCode: String) = DateTimeFormat.forPattern(DAYCODE_PATTERN).withZone(DateTimeZone.getDefault()).parseDateTime(dayCode)
|
fun getLocalDateTimeFromCode(dayCode: String) = DateTimeFormat.forPattern(DAYCODE_PATTERN).withZone(DateTimeZone.getDefault()).parseDateTime(dayCode)
|
||||||
|
|
||||||
fun getTime(ts: Int) = getEventTime(getDateTimeFromTS(ts))
|
fun getTimeFromTS(context: Context, ts: Int) = getTime(context, getDateTimeFromTS(ts))
|
||||||
|
|
||||||
fun getDayStartTS(dayCode: String) = (getLocalDateTimeFromCode(dayCode).millis / 1000).toInt()
|
fun getDayStartTS(dayCode: String) = (getLocalDateTimeFromCode(dayCode).millis / 1000).toInt()
|
||||||
|
|
||||||
|
@ -54,4 +56,6 @@ 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]
|
fun getMonthName(context: Context, id: Int) = context.resources.getStringArray(R.array.months)[id]
|
||||||
|
|
||||||
|
fun getTimePattern(context: Context) = if (DateFormat.is24HourFormat(context)) PATTERN_TIME_24 else PATTERN_TIME_12
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,8 @@ class NotificationReceiver : BroadcastReceiver() {
|
||||||
return
|
return
|
||||||
|
|
||||||
val pendingIntent = getPendingIntent(context, event)
|
val pendingIntent = getPendingIntent(context, event)
|
||||||
val startTime = Formatter.getTime(event.startTS)
|
val startTime = Formatter.getTimeFromTS(context, event.startTS)
|
||||||
val endTime = Formatter.getTime(event.endTS)
|
val endTime = Formatter.getTimeFromTS(context, event.endTS)
|
||||||
val title = event.title
|
val title = event.title
|
||||||
val notification = getNotification(context, pendingIntent, "${getEventTime(startTime, endTime)} $title")
|
val notification = getNotification(context, pendingIntent, "${getEventTime(startTime, endTime)} $title")
|
||||||
notificationManager.notify(id, notification)
|
notificationManager.notify(id, notification)
|
||||||
|
|
Loading…
Reference in a new issue