Use isShort to display the shorts label

This commit is contained in:
Bnyro 2023-01-21 11:03:24 +01:00
parent 089e72b0c7
commit cf5ef1292f
5 changed files with 9 additions and 12 deletions

View File

@ -66,7 +66,7 @@ class PlaylistAdapter(
videoInfo.text = streamItem.uploaderName
channelImage.visibility = View.GONE
thumbnailDuration.setFormattedDuration(streamItem.duration!!)
thumbnailDuration.setFormattedDuration(streamItem.duration!!, streamItem.isShort)
ImageHelper.loadImage(streamItem.thumbnail, thumbnail)
root.setOnClickListener {
NavigationHelper.navigateVideo(root.context, streamItem.url, playlistId)

View File

@ -83,7 +83,7 @@ class SearchAdapter(
private fun bindWatch(item: ContentItem, binding: VideoRowBinding) {
binding.apply {
ImageHelper.loadImage(item.thumbnail, thumbnail)
thumbnailDuration.setFormattedDuration(item.duration!!)
thumbnailDuration.setFormattedDuration(item.duration!!, item.isShort)
ImageHelper.loadImage(item.uploaderAvatar, channelImage)
videoTitle.text = item.title
val viewsString = if (item.views?.toInt() != -1) item.views.formatShort() else ""

View File

@ -133,7 +133,7 @@ class VideosAdapter(
TextUtils.SEPARATOR + video.uploaded?.let {
DateUtils.getRelativeTimeSpanString(it)
}
video.duration?.let { thumbnailDuration.setFormattedDuration(it) }
video.duration?.let { thumbnailDuration.setFormattedDuration(it, video.isShort) }
channelImage.setOnClickListener {
NavigationHelper.navigateChannel(root.context, video.uploaderUrl)
}

View File

@ -43,7 +43,7 @@ class WatchHistoryAdapter(
videoTitle.text = video.title
channelName.text = video.uploader
videoInfo.text = video.uploadDate
thumbnailDuration.setFormattedDuration(video.duration!!)
thumbnailDuration.setFormattedDuration(video.duration!!, null)
ImageHelper.loadImage(video.thumbnailUrl, thumbnail)
ImageHelper.loadImage(video.uploaderAvatar, channelImage)

View File

@ -4,13 +4,10 @@ import android.text.format.DateUtils
import android.widget.TextView
import com.github.libretube.R
fun TextView.setFormattedDuration(duration: Long) {
val text = if (duration < 0L) {
this.context.getString(R.string.live)
} else if (duration in 0L..60L) {
this.context.getString(R.string.yt_shorts)
} else {
DateUtils.formatElapsedTime(duration)
fun TextView.setFormattedDuration(duration: Long, isShort: Boolean?) {
this.text = when {
isShort == true -> context.getString(R.string.yt_shorts)
duration < 0L -> context.getString(R.string.live)
else -> DateUtils.formatElapsedTime(duration)
}
this.text = text
}