Skip to content
Snippets Groups Projects
Commit fba1d969 authored by Pierre Nicolas's avatar Pierre Nicolas :joy:
Browse files

chatview: add timestampToDate util method

Change-Id: I2817c9f1322bdc016b11c998f48ff0d1783a275b
parent b82d30d1
No related branches found
No related tags found
No related merge requests found
......@@ -72,6 +72,39 @@ object TextUtils {
return timeStr.out().toString().uppercase(Locale.getDefault())
}
/**
* Converts a timestamp into a date.
* May returns terms like 'Today' or 'Yesterday'. In all other cases, the complete date.
*/
fun timestampToDate(context: Context, formatter: Formatter, timestamp: Long): String {
(formatter.out() as? StringBuilder)?.setLength(0)
fun isYesterday(timestamp: Long): Boolean {
return DateUtils.isToday(timestamp + DateUtils.DAY_IN_MILLIS)
}
if (DateUtils.isToday(timestamp)) return context.getString(R.string.today).uppercase()
else if (isYesterday(timestamp)) return context.getString(R.string.yesterday).uppercase()
val timeStr: Formatter =
DateUtils.formatDateRange(
context, formatter, timestamp, timestamp,
DateUtils.FORMAT_SHOW_DATE or
DateUtils.FORMAT_NO_YEAR or DateUtils.FORMAT_ABBREV_MONTH
)
return timeStr.out().toString().uppercase(Locale.getDefault())
}
/**
* Converts a timestamp into a time. Don't display the date.
* Example of the output format = 11:32 A.M.
*/
fun timestampToTime(context: Context, formatter: Formatter, timestamp: Long): String {
(formatter.out() as? StringBuilder)?.setLength(0)
return DateUtils // Example of the format in the message = 11:32 A.M.
.formatDateRange(context, formatter, timestamp, timestamp, DateUtils.FORMAT_SHOW_TIME)
.out().toString().uppercase(Locale.getDefault())
}
fun getReadableFileTransferStatus(context: Context, transferStatus: InteractionStatus): String {
return when (transferStatus) {
InteractionStatus.TRANSFER_CREATED -> context.getString(R.string.file_transfer_status_created)
......
......@@ -344,6 +344,9 @@ along with this program; if not, write to the Free Software
<string name="conversation_contact_banned">%1$s was banned</string>
<string name="conversation_search_hint">Search conversation</string>
<string name="today">Today</string>
<string name="yesterday">Yesterday</string>
<!-- Contacts -->
<string name="add_call_contact_number_to_contacts">Add %1$s?</string>
<string name="prompt_new_password">New password</string>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment