mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
better handling of thumbnail duration
This commit is contained in:
parent
4940c0b35c
commit
221530d941
@ -1,7 +1,6 @@
|
||||
package com.github.libretube.adapters
|
||||
|
||||
import android.app.Activity
|
||||
import android.text.format.DateUtils
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@ -10,6 +9,7 @@ import androidx.fragment.app.FragmentManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.databinding.PlaylistRowBinding
|
||||
import com.github.libretube.dialogs.VideoOptionsDialog
|
||||
import com.github.libretube.extensions.setFormattedDuration
|
||||
import com.github.libretube.obj.PlaylistId
|
||||
import com.github.libretube.obj.StreamItem
|
||||
import com.github.libretube.preferences.PreferenceHelper
|
||||
@ -53,7 +53,7 @@ class PlaylistAdapter(
|
||||
holder.binding.apply {
|
||||
playlistTitle.text = streamItem.title
|
||||
playlistDescription.text = streamItem.uploaderName
|
||||
thumbnailDuration.text = DateUtils.formatElapsedTime(streamItem.duration!!)
|
||||
thumbnailDuration.setFormattedDuration(streamItem.duration!!)
|
||||
ConnectionHelper.loadImage(streamItem.thumbnail, playlistThumbnail)
|
||||
root.setOnClickListener {
|
||||
NavigationHelper.navigateVideo(root.context, streamItem.url, playlistId)
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.libretube.adapters
|
||||
|
||||
import android.text.format.DateUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -12,6 +11,7 @@ import com.github.libretube.databinding.PlaylistSearchRowBinding
|
||||
import com.github.libretube.databinding.VideoRowBinding
|
||||
import com.github.libretube.dialogs.PlaylistOptionsDialog
|
||||
import com.github.libretube.dialogs.VideoOptionsDialog
|
||||
import com.github.libretube.extensions.setFormattedDuration
|
||||
import com.github.libretube.obj.SearchItem
|
||||
import com.github.libretube.util.ConnectionHelper
|
||||
import com.github.libretube.util.NavigationHelper
|
||||
@ -80,12 +80,7 @@ class SearchAdapter(
|
||||
private fun bindWatch(item: SearchItem, binding: VideoRowBinding) {
|
||||
binding.apply {
|
||||
ConnectionHelper.loadImage(item.thumbnail, thumbnail)
|
||||
if (item.duration != -1L) {
|
||||
thumbnailDuration.text = DateUtils.formatElapsedTime(item.duration!!)
|
||||
} else {
|
||||
thumbnailDuration.text = root.context.getString(R.string.live)
|
||||
thumbnailDuration.setBackgroundColor(R.attr.colorPrimaryDark)
|
||||
}
|
||||
thumbnailDuration.setFormattedDuration(item.duration!!)
|
||||
ConnectionHelper.loadImage(item.uploaderAvatar, channelImage)
|
||||
videoTitle.text = item.title
|
||||
val viewsString = if (item.views?.toInt() != -1) item.views.formatShort() else ""
|
||||
|
@ -5,9 +5,9 @@ import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.databinding.TrendingRowBinding
|
||||
import com.github.libretube.dialogs.VideoOptionsDialog
|
||||
import com.github.libretube.extensions.setFormattedDuration
|
||||
import com.github.libretube.obj.StreamItem
|
||||
import com.github.libretube.util.ConnectionHelper
|
||||
import com.github.libretube.util.NavigationHelper
|
||||
@ -49,12 +49,7 @@ class TrendingAdapter(
|
||||
trending.uploaderName + " • " +
|
||||
trending.views.formatShort() + " • " +
|
||||
DateUtils.getRelativeTimeSpanString(trending.uploaded!!)
|
||||
if (trending.duration != -1L) {
|
||||
thumbnailDuration.text = DateUtils.formatElapsedTime(trending.duration!!)
|
||||
} else {
|
||||
thumbnailDuration.text = root.context.getString(R.string.live)
|
||||
thumbnailDuration.setBackgroundColor(R.attr.colorPrimaryDark)
|
||||
}
|
||||
thumbnailDuration.setFormattedDuration(trending.duration!!)
|
||||
channelImage.setOnClickListener {
|
||||
NavigationHelper.navigateChannel(root.context, trending.uploaderUrl)
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.github.libretube.adapters
|
||||
|
||||
import android.text.format.DateUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.databinding.WatchHistoryRowBinding
|
||||
import com.github.libretube.dialogs.VideoOptionsDialog
|
||||
import com.github.libretube.extensions.setFormattedDuration
|
||||
import com.github.libretube.obj.WatchHistoryItem
|
||||
import com.github.libretube.preferences.PreferenceHelper
|
||||
import com.github.libretube.util.ConnectionHelper
|
||||
@ -32,7 +32,7 @@ class WatchHistoryAdapter(
|
||||
videoTitle.text = video.title
|
||||
channelName.text = video.uploader
|
||||
videoInfo.text = video.uploadDate
|
||||
thumbnailDuration.text = DateUtils.formatElapsedTime(video.duration?.toLong()!!)
|
||||
thumbnailDuration.setFormattedDuration(video.duration!!)
|
||||
ConnectionHelper.loadImage(video.thumbnailUrl, thumbnail)
|
||||
ConnectionHelper.loadImage(video.uploaderAvatar, channelImage)
|
||||
|
||||
@ -55,7 +55,7 @@ class WatchHistoryAdapter(
|
||||
true
|
||||
}
|
||||
|
||||
watchProgress.setWatchProgressLength(video.videoId!!, video.duration.toLong())
|
||||
watchProgress.setWatchProgressLength(video.videoId!!, video.duration)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,14 @@
|
||||
package com.github.libretube.extensions
|
||||
|
||||
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!!.setBackgroundColor(R.attr.colorPrimaryDark)
|
||||
this.context.getString(R.string.live)
|
||||
} else if (duration == 0L) this!!.context.getString(R.string.yt_shorts)
|
||||
else DateUtils.formatElapsedTime(duration)
|
||||
this!!.text = text
|
||||
}
|
@ -15,7 +15,7 @@ data class Streams(
|
||||
val dash: String?,
|
||||
val lbryId: String?,
|
||||
val uploaderVerified: Boolean?,
|
||||
val duration: Int?,
|
||||
val duration: Long?,
|
||||
val views: Long?,
|
||||
val likes: Long?,
|
||||
val dislikes: Long?,
|
||||
|
@ -8,5 +8,5 @@ data class WatchHistoryItem(
|
||||
val uploaderUrl: String? = null,
|
||||
val uploaderAvatar: String? = null,
|
||||
val thumbnailUrl: String? = null,
|
||||
val duration: Int? = null
|
||||
val duration: Long? = null
|
||||
)
|
||||
|
@ -302,4 +302,5 @@
|
||||
<string name="break_reminder">Break reminder</string>
|
||||
<string name="take_a_break">Time to take a break</string>
|
||||
<string name="already_spent_time">You already spent %1$s minutes in the app, time to take a break.</string>
|
||||
<string name="yt_shorts">Shorts</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user