diff --git a/app/src/main/java/com/github/libretube/ui/views/DescriptionLayout.kt b/app/src/main/java/com/github/libretube/ui/views/DescriptionLayout.kt index dd27f5af1..733217a61 100644 --- a/app/src/main/java/com/github/libretube/ui/views/DescriptionLayout.kt +++ b/app/src/main/java/com/github/libretube/ui/views/DescriptionLayout.kt @@ -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 { diff --git a/app/src/main/java/com/github/libretube/util/TextUtils.kt b/app/src/main/java/com/github/libretube/util/TextUtils.kt index 1d00707b3..3de500a36 100644 --- a/app/src/main/java/com/github/libretube/util/TextUtils.kt +++ b/app/src/main/java/com/github/libretube/util/TextUtils.kt @@ -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