Merge pull request #6885 from Bnyro/master

feat: show full upload date if description expanded
This commit is contained in:
Bnyro 2024-12-18 16:19:27 +01:00 committed by GitHub
commit f2894ac986
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 26 deletions

View File

@ -131,40 +131,30 @@ class DescriptionLayout(
private fun toggleDescription() { private fun toggleDescription() {
val streams = streams ?: return val streams = streams ?: return
val views = if (binding.descLinLayout.isVisible) { val isNewStateExpanded = binding.descLinLayout.isGone
// show formatted short view count if (!isNewStateExpanded) {
streams.views.formatShort() // show a short version of the view count and date
} else { val formattedDate = TextUtils.formatRelativeDate(context, streams.uploaded ?: -1L)
// show exact view count binding.playerViewsInfo.text = context.getString(R.string.normal_views, streams.views.formatShort(), TextUtils.SEPARATOR + formattedDate)
"%,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
// limit the title height to two lines // limit the title height to two lines
binding.playerTitle.maxLines = 2 binding.playerTitle.maxLines = 2
} else { } else {
// show the description and chapters // show the full view count and upload date
binding.playerDescriptionArrow.animate().rotation( val formattedDate = streams.uploadTimestamp?.let { TextUtils.localizeInstant(it) }.orEmpty()
180F binding.playerViewsInfo.text = context.getString(R.string.normal_views, "%,d".format(streams.views), TextUtils.SEPARATOR + formattedDate)
).setDuration(ANIMATION_DURATION).start()
binding.playerDescription.isVisible = true
binding.descLinLayout.isVisible = true
// show the whole title // show the whole title
binding.playerTitle.maxLines = Int.MAX_VALUE 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 { companion object {

View File

@ -9,7 +9,9 @@ import com.github.libretube.BuildConfig
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.extensions.formatShort import com.github.libretube.extensions.formatShort
import com.google.common.math.IntMath.pow import com.google.common.math.IntMath.pow
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toJavaLocalDate import kotlinx.datetime.toJavaLocalDate
import kotlinx.datetime.toLocalDateTime
import java.time.Instant import java.time.Instant
import java.time.LocalDateTime import java.time.LocalDateTime
import java.time.ZoneId import java.time.ZoneId
@ -47,6 +49,12 @@ object TextUtils {
return date.toJavaLocalDate().format(MEDIUM_DATE_FORMATTER) 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. * Get time in seconds from a YouTube video link.
* @return Time in seconds * @return Time in seconds