Improve time format of posts when using absolute time (#2413)
* Improve time format of posts when using absolute time * fix AbsoluteTimeFormatter, add tests * fix tests Co-authored-by: Conny Duck <k.pozniak@gmx.at>
This commit is contained in:
parent
216f094e98
commit
e0abcbfada
6 changed files with 127 additions and 61 deletions
|
|
@ -34,20 +34,16 @@ import com.keylesspalace.tusky.viewdata.PollViewData
|
|||
import com.keylesspalace.tusky.viewdata.buildDescription
|
||||
import com.keylesspalace.tusky.viewdata.calculatePercent
|
||||
import java.text.NumberFormat
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import kotlin.math.min
|
||||
|
||||
class StatusViewHelper(private val itemView: View) {
|
||||
private val absoluteTimeFormatter = AbsoluteTimeFormatter()
|
||||
|
||||
interface MediaPreviewListener {
|
||||
fun onViewMedia(v: View?, idx: Int)
|
||||
fun onContentHiddenChange(isShowing: Boolean)
|
||||
}
|
||||
|
||||
private val shortSdf = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
|
||||
private val longSdf = SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault())
|
||||
|
||||
fun setMediasPreview(
|
||||
statusDisplayOptions: StatusDisplayOptions,
|
||||
attachments: List<Attachment>,
|
||||
|
|
@ -295,7 +291,7 @@ class StatusViewHelper(private val itemView: View) {
|
|||
context.getString(R.string.poll_info_closed)
|
||||
} else {
|
||||
if (useAbsoluteTime) {
|
||||
context.getString(R.string.poll_info_time_absolute, getAbsoluteTime(poll.expiresAt))
|
||||
context.getString(R.string.poll_info_time_absolute, absoluteTimeFormatter.format(poll.expiresAt, false))
|
||||
} else {
|
||||
TimestampUtils.formatPollDuration(context, poll.expiresAt!!.time, timestamp)
|
||||
}
|
||||
|
|
@ -330,18 +326,6 @@ class StatusViewHelper(private val itemView: View) {
|
|||
}
|
||||
}
|
||||
|
||||
fun getAbsoluteTime(time: Date?): String {
|
||||
return if (time != null) {
|
||||
if (android.text.format.DateUtils.isToday(time.time)) {
|
||||
shortSdf.format(time)
|
||||
} else {
|
||||
longSdf.format(time)
|
||||
}
|
||||
} else {
|
||||
"??:??:??"
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val COLLAPSE_INPUT_FILTER = arrayOf<InputFilter>(SmartLengthInputFilter)
|
||||
val NO_INPUT_FILTER = arrayOfNulls<InputFilter>(0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue