refactor: save possible stream types to constant values

This commit is contained in:
Bnyro 2023-08-24 22:01:18 +02:00
parent f48f3f2fd3
commit b6cfa62d5d
5 changed files with 15 additions and 6 deletions

View File

@ -34,4 +34,10 @@ data class StreamItem(
duration = duration
)
}
companion object {
const val TYPE_STREAM = "stream"
const val TYPE_CHANNEL = "channel"
const val TYPE_PLAYLIST = "playlist"
}
}

View File

@ -22,7 +22,7 @@ data class WatchHistoryItem(
) {
fun toStreamItem() = StreamItem(
url = videoId,
type = "stream",
type = StreamItem.TYPE_STREAM,
title = title,
thumbnail = thumbnailUrl,
uploaderName = uploader,

View File

@ -6,6 +6,7 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import com.github.libretube.R
import com.github.libretube.api.obj.ContentItem
import com.github.libretube.api.obj.StreamItem
import com.github.libretube.databinding.ChannelRowBinding
import com.github.libretube.databinding.PlaylistsRowBinding
import com.github.libretube.databinding.VideoRowBinding
@ -65,9 +66,9 @@ class SearchAdapter(
override fun getItemViewType(position: Int): Int {
return when (currentList[position].type) {
"stream" -> 0
"channel" -> 1
"playlist" -> 2
StreamItem.TYPE_STREAM -> 0
StreamItem.TYPE_CHANNEL -> 1
StreamItem.TYPE_PLAYLIST -> 2
else -> 3
}
}

View File

@ -45,7 +45,7 @@ class VideosAdapter(
}
override fun getItemViewType(position: Int): Int {
return if (streamItems[position].type == "caught") CAUGHT_UP_TYPE else NORMAL_TYPE
return if (streamItems[position].type == CAUGHT_UP_STREAM_TYPE) CAUGHT_UP_TYPE else NORMAL_TYPE
}
fun updateItems() {
@ -231,5 +231,7 @@ class VideosAdapter(
private const val NORMAL_TYPE = 0
private const val CAUGHT_UP_TYPE = 1
const val CAUGHT_UP_STREAM_TYPE = "caught"
}
}

View File

@ -299,7 +299,7 @@ class SubscriptionsFragment : Fragment() {
(it.uploaded ?: 0L) / 1000 < lastCheckedFeedTime
}
if (caughtUpIndex > 0) {
sortedFeed.add(caughtUpIndex, StreamItem(type = "caught"))
sortedFeed.add(caughtUpIndex, StreamItem(type = VideosAdapter.CAUGHT_UP_STREAM_TYPE))
}
}