mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-01-09 19:10:30 +05:30
feat: show full upload date if description expanded
This commit is contained in:
parent
c8de2a3d67
commit
ac8736c41d
@ -131,40 +131,30 @@ class DescriptionLayout(
|
||||
private fun toggleDescription() {
|
||||
val streams = streams ?: return
|
||||
|
||||
val views = if (binding.descLinLayout.isVisible) {
|
||||
// show formatted short view count
|
||||
streams.views.formatShort()
|
||||
} else {
|
||||
// show exact view count
|
||||
"%,d".format(streams.views)
|
||||
}
|
||||
val date = TextUtils.formatRelativeDate(context, streams.uploaded ?: -1L)
|
||||
val viewInfo = context.getString(R.string.normal_views, views, TextUtils.SEPARATOR + date)
|
||||
if (binding.descLinLayout.isVisible) {
|
||||
// hide the description and chapters
|
||||
binding.playerDescriptionArrow.animate().rotation(
|
||||
0F
|
||||
).setDuration(ANIMATION_DURATION).start()
|
||||
|
||||
binding.playerDescription.isGone = true
|
||||
|
||||
binding.descLinLayout.isGone = true
|
||||
val isNewStateExpanded = binding.descLinLayout.isGone
|
||||
if (!isNewStateExpanded) {
|
||||
// show a short version of the view count and date
|
||||
val formattedDate = TextUtils.formatRelativeDate(context, streams.uploaded ?: -1L)
|
||||
binding.playerViewsInfo.text = context.getString(R.string.normal_views, streams.views.formatShort(), TextUtils.SEPARATOR + formattedDate)
|
||||
|
||||
// limit the title height to two lines
|
||||
binding.playerTitle.maxLines = 2
|
||||
} else {
|
||||
// show the description and chapters
|
||||
binding.playerDescriptionArrow.animate().rotation(
|
||||
180F
|
||||
).setDuration(ANIMATION_DURATION).start()
|
||||
|
||||
binding.playerDescription.isVisible = true
|
||||
binding.descLinLayout.isVisible = true
|
||||
// show the full view count and upload date
|
||||
val formattedDate = streams.uploadTimestamp?.let { TextUtils.localizeInstant(it) }.orEmpty()
|
||||
binding.playerViewsInfo.text = context.getString(R.string.normal_views, "%,d".format(streams.views), TextUtils.SEPARATOR + formattedDate)
|
||||
|
||||
// show the whole title
|
||||
binding.playerTitle.maxLines = Int.MAX_VALUE
|
||||
}
|
||||
binding.playerViewsInfo.text = viewInfo
|
||||
|
||||
binding.playerDescriptionArrow.animate()
|
||||
.rotation(if (isNewStateExpanded) 180F else 0F)
|
||||
.setDuration(ANIMATION_DURATION)
|
||||
.start()
|
||||
|
||||
binding.playerDescription.isVisible = isNewStateExpanded
|
||||
binding.descLinLayout.isVisible = isNewStateExpanded
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -9,7 +9,9 @@ import com.github.libretube.BuildConfig
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.extensions.formatShort
|
||||
import com.google.common.math.IntMath.pow
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.toJavaLocalDate
|
||||
import kotlinx.datetime.toLocalDateTime
|
||||
import java.time.Instant
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
@ -47,6 +49,12 @@ object TextUtils {
|
||||
return date.toJavaLocalDate().format(MEDIUM_DATE_FORMATTER)
|
||||
}
|
||||
|
||||
fun localizeInstant(instant: kotlinx.datetime.Instant): String {
|
||||
val date = instant.toLocalDateTime(TimeZone.currentSystemDefault()).date
|
||||
|
||||
return localizeDate(date)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get time in seconds from a YouTube video link.
|
||||
* @return Time in seconds
|
||||
|
Loading…
Reference in New Issue
Block a user