pref: 优化时间显示

This commit is contained in:
HuanCheng65 2022-06-15 16:20:14 +08:00
parent 5e478aaba9
commit 3bbc9f79c8
No known key found for this signature in database
GPG Key ID: E9031EF91A805148
2 changed files with 19 additions and 22 deletions

View File

@ -25,38 +25,34 @@ object DateTimeUtils {
} }
val currentCalendar = Calendar.getInstance() val currentCalendar = Calendar.getInstance()
return if (currentCalendar.after(calendar)) { return if (currentCalendar.after(calendar)) {
if (calendar.get(Calendar.YEAR) == currentCalendar.get(Calendar.YEAR)) { if (calendar.get(Calendar.YEAR) == currentCalendar.get(Calendar.YEAR) && calendar.get(
if (calendar.get(Calendar.MONTH) == currentCalendar.get(Calendar.MONTH)) { Calendar.MONTH
if (calendar.get(Calendar.DAY_OF_MONTH) == currentCalendar.get(Calendar.DAY_OF_MONTH)) { ) == currentCalendar.get(Calendar.MONTH)
if (calendar.get(Calendar.HOUR_OF_DAY) == currentCalendar.get(Calendar.HOUR_OF_DAY)) { ) {
if (calendar.get(Calendar.MINUTE) == currentCalendar.get(Calendar.MINUTE)) { if (calendar.get(Calendar.DAY_OF_MONTH) == currentCalendar.get(Calendar.DAY_OF_MONTH)) {
context.getString( if (calendar.get(Calendar.HOUR_OF_DAY) == currentCalendar.get(Calendar.HOUR_OF_DAY)) {
R.string.relative_date_second, if (calendar.get(Calendar.MINUTE) == currentCalendar.get(Calendar.MINUTE)) {
currentCalendar.get(Calendar.SECOND) - calendar.get(Calendar.SECOND) context.getString(
) R.string.relative_date_second,
} else { currentCalendar.get(Calendar.SECOND) - calendar.get(Calendar.SECOND)
context.getString( )
R.string.relative_date_minute,
currentCalendar.get(Calendar.MINUTE) - calendar.get(Calendar.MINUTE)
)
}
} else { } else {
context.getString( context.getString(
R.string.relative_date_hour, R.string.relative_date_minute,
currentCalendar.get(Calendar.HOUR_OF_DAY) - calendar.get(Calendar.HOUR_OF_DAY) currentCalendar.get(Calendar.MINUTE) - calendar.get(Calendar.MINUTE)
) )
} }
} else { } else {
context.getString( context.getString(
R.string.relative_date_month, R.string.relative_date_today,
currentCalendar.get(Calendar.DAY_OF_MONTH) - calendar.get(Calendar.DAY_OF_MONTH) calendar.format("HH:mm")
) )
} }
} else { } else {
calendar.format(context.getString(R.string.pattern_date_short)) calendar.format("MM-dd HH:mm")
} }
} else { } else {
calendar.format(context.getString(R.string.pattern_date_long)) calendar.format("yyyy-MM-dd HH:mm")
} }
} else { } else {
calendar.format(context.getString(R.string.relative_date_after)) calendar.format(context.getString(R.string.relative_date_after))

View File

@ -409,7 +409,7 @@
<string name="text_badge_history_forum">贴吧</string> <string name="text_badge_history_forum">贴吧</string>
<string name="title_history_thread">贴子记录</string> <string name="title_history_thread">贴子记录</string>
<string name="title_history_forum">经过贴吧</string> <string name="title_history_forum">经过贴吧</string>
<string name="tip_thread_item_thread">发布于 %1$s</string> <string name="tip_thread_item_thread">%1$s 来自 %2$s</string>
<string name="title_all_reply">全部</string> <string name="title_all_reply">全部</string>
<string name="title_thread_header">回复 %1$s</string> <string name="title_thread_header">回复 %1$s</string>
<string name="btn_agree_post">%1$s 赞</string> <string name="btn_agree_post">%1$s 赞</string>
@ -521,4 +521,5 @@
<string name="usage_webview_location_permission">用于向当前访问的网页提供你的位置信息,以便该网页向你提供相关服务。</string> <string name="usage_webview_location_permission">用于向当前访问的网页提供你的位置信息,以便该网页向你提供相关服务。</string>
<string name="title_hide_forum_intro_and_stat">精简吧页面</string> <string name="title_hide_forum_intro_and_stat">精简吧页面</string>
<string name="summary_hide_forum_intro_and_stat">开启后将隐藏吧页面的吧简介和数据(仍然可以通过“关于本吧”查看这些内容)</string> <string name="summary_hide_forum_intro_and_stat">开启后将隐藏吧页面的吧简介和数据(仍然可以通过“关于本吧”查看这些内容)</string>
<string name="relative_date_today">今天 %1$s</string>
</resources> </resources>