mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
Use Kotlinx Serialization with channel information.
This commit is contained in:
parent
ef103284af
commit
371fbcd643
@ -1,17 +1,17 @@
|
||||
package com.github.libretube.api.obj
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Serializable
|
||||
data class Channel(
|
||||
var id: String? = null,
|
||||
var name: String? = null,
|
||||
var avatarUrl: String? = null,
|
||||
var bannerUrl: String? = null,
|
||||
var description: String? = null,
|
||||
var nextpage: String? = null,
|
||||
var subscriberCount: Long = 0,
|
||||
var verified: Boolean = false,
|
||||
var relatedStreams: List<StreamItem>? = listOf(),
|
||||
var tabs: List<ChannelTab>? = listOf()
|
||||
val id: String,
|
||||
val name: String,
|
||||
val avatarUrl: String,
|
||||
val bannerUrl: String,
|
||||
val description: String,
|
||||
val nextpage: String? = null,
|
||||
val subscriberCount: Long = 0,
|
||||
val verified: Boolean = false,
|
||||
val relatedStreams: List<StreamItem> = emptyList(),
|
||||
val tabs: List<ChannelTab> = emptyList()
|
||||
)
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.github.libretube.api.obj
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Serializable
|
||||
data class ChannelTab(
|
||||
val name: String? = null,
|
||||
val data: String? = null
|
||||
val name: String,
|
||||
val data: String
|
||||
)
|
||||
|
@ -1,6 +1,9 @@
|
||||
package com.github.libretube.api.obj
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ChannelTabResponse(
|
||||
val content: List<ContentItem> = listOf(),
|
||||
val content: List<ContentItem> = emptyList(),
|
||||
val nextpage: String? = null
|
||||
)
|
||||
|
@ -4,9 +4,9 @@ import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ContentItem(
|
||||
val url: String? = null,
|
||||
val type: String? = null,
|
||||
val thumbnail: String? = null,
|
||||
val url: String,
|
||||
val type: String,
|
||||
val thumbnail: String,
|
||||
val uploaderName: String? = null,
|
||||
val uploaded: Long? = null,
|
||||
val shortDescription: String? = null,
|
||||
|
@ -98,7 +98,7 @@ class SearchAdapter(
|
||||
root.setOnClickListener {
|
||||
NavigationHelper.navigateVideo(root.context, item.url)
|
||||
}
|
||||
val videoId = item.url!!.toID()
|
||||
val videoId = item.url.toID()
|
||||
val videoName = item.title!!
|
||||
root.setOnLongClickListener {
|
||||
VideoOptionsBottomSheet(videoId, videoName)
|
||||
@ -135,12 +135,12 @@ class SearchAdapter(
|
||||
}
|
||||
|
||||
root.setOnLongClickListener {
|
||||
ChannelOptionsBottomSheet(item.url!!.toID(), item.name)
|
||||
ChannelOptionsBottomSheet(item.url.toID(), item.name)
|
||||
.show((root.context as BaseActivity).supportFragmentManager)
|
||||
true
|
||||
}
|
||||
|
||||
binding.searchSubButton.setupSubscriptionButton(item.url?.toID(), item.name?.toID())
|
||||
binding.searchSubButton.setupSubscriptionButton(item.url.toID(), item.name?.toID())
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ class SearchAdapter(
|
||||
}
|
||||
deletePlaylist.visibility = View.GONE
|
||||
root.setOnLongClickListener {
|
||||
val playlistId = item.url!!.toID()
|
||||
val playlistId = item.url.toID()
|
||||
val playlistName = item.name!!
|
||||
PlaylistOptionsBottomSheet(playlistId, playlistName, PlaylistType.PUBLIC)
|
||||
.show(
|
||||
|
@ -142,7 +142,7 @@ class ChannelFragment : BaseFragment() {
|
||||
|
||||
binding.channelShare.setOnClickListener {
|
||||
val shareDialog = ShareDialog(
|
||||
response.id!!.toID(),
|
||||
response.id.toID(),
|
||||
ShareObjectType.CHANNEL,
|
||||
shareData
|
||||
)
|
||||
@ -169,10 +169,10 @@ class ChannelFragment : BaseFragment() {
|
||||
R.string.subscribers,
|
||||
response.subscriberCount.formatShort()
|
||||
)
|
||||
if (response.description?.trim() == "") {
|
||||
if (response.description.isBlank()) {
|
||||
binding.channelDescription.visibility = View.GONE
|
||||
} else {
|
||||
binding.channelDescription.text = response.description?.trim()
|
||||
binding.channelDescription.text = response.description.trim()
|
||||
}
|
||||
|
||||
binding.channelDescription.setOnClickListener {
|
||||
@ -186,13 +186,13 @@ class ChannelFragment : BaseFragment() {
|
||||
|
||||
// recyclerview of the videos by the channel
|
||||
channelAdapter = VideosAdapter(
|
||||
response.relatedStreams.orEmpty().toMutableList(),
|
||||
response.relatedStreams.toMutableList(),
|
||||
forceMode = VideosAdapter.Companion.ForceMode.CHANNEL
|
||||
)
|
||||
binding.channelRecView.adapter = channelAdapter
|
||||
}
|
||||
|
||||
response.tabs?.let { setupTabs(it) }
|
||||
setupTabs(response.tabs)
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,16 +230,13 @@ class ChannelFragment : BaseFragment() {
|
||||
|
||||
private fun loadTab(tab: ChannelTab) {
|
||||
scope.launch {
|
||||
tab.data ?: return@launch
|
||||
val response = try {
|
||||
RetrofitInstance.api.getChannelTab(tab.data)
|
||||
} catch (e: Exception) {
|
||||
return@launch
|
||||
}
|
||||
|
||||
val adapter = SearchAdapter(
|
||||
response.content.toMutableList()
|
||||
)
|
||||
val adapter = SearchAdapter(response.content.toMutableList())
|
||||
|
||||
runOnUiThread {
|
||||
binding.channelRecView.adapter = adapter
|
||||
@ -275,7 +272,7 @@ class ChannelFragment : BaseFragment() {
|
||||
return@launchWhenCreated
|
||||
}
|
||||
nextPage = response.nextpage
|
||||
channelAdapter?.insertItems(response.relatedStreams.orEmpty())
|
||||
channelAdapter?.insertItems(response.relatedStreams)
|
||||
isLoading = false
|
||||
binding.channelRefresh.isRefreshing = false
|
||||
}
|
||||
@ -291,9 +288,9 @@ class ChannelFragment : BaseFragment() {
|
||||
) {
|
||||
scope.launch {
|
||||
val newContent = try {
|
||||
RetrofitInstance.api.getChannelTab(tab.data ?: "", nextPage)
|
||||
RetrofitInstance.api.getChannelTab(tab.data, nextPage)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Log.e(TAG(), "Exception: $e")
|
||||
null
|
||||
}
|
||||
onNewNextPage.invoke(newContent?.nextpage)
|
||||
|
@ -20,7 +20,7 @@ import kotlinx.coroutines.runBlocking
|
||||
*/
|
||||
class ChannelOptionsBottomSheet(
|
||||
private val channelId: String,
|
||||
private val channelName: String?
|
||||
channelName: String?
|
||||
) : BaseBottomSheet() {
|
||||
private val shareData = ShareData(currentChannel = channelName)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@ -44,7 +44,7 @@ class ChannelOptionsBottomSheet(
|
||||
val channel = runBlocking {
|
||||
RetrofitInstance.api.getChannel(channelId)
|
||||
}
|
||||
channel.relatedStreams?.firstOrNull()?.url?.toID()?.let {
|
||||
channel.relatedStreams.firstOrNull()?.url?.toID()?.let {
|
||||
NavigationHelper.navigateVideo(
|
||||
requireContext(),
|
||||
it,
|
||||
@ -60,7 +60,7 @@ class ChannelOptionsBottomSheet(
|
||||
val channel = runBlocking {
|
||||
RetrofitInstance.api.getChannel(channelId)
|
||||
}
|
||||
channel.relatedStreams?.firstOrNull()?.url?.toID()?.let {
|
||||
channel.relatedStreams.firstOrNull()?.url?.toID()?.let {
|
||||
BackgroundHelper.playOnBackground(
|
||||
requireContext(),
|
||||
videoId = it,
|
||||
|
@ -147,7 +147,7 @@ object PlayingQueue {
|
||||
scope.launch {
|
||||
while (channelNextPage != null) {
|
||||
RetrofitInstance.api.getChannelNextPage(channelId, nextPage!!).apply {
|
||||
add(*relatedStreams.orEmpty().toTypedArray())
|
||||
add(*relatedStreams.toTypedArray())
|
||||
channelNextPage = this.nextpage
|
||||
}
|
||||
}
|
||||
@ -158,7 +158,7 @@ object PlayingQueue {
|
||||
scope.launch {
|
||||
runCatching {
|
||||
val channel = RetrofitInstance.api.getChannel(channelId)
|
||||
add(*channel.relatedStreams.orEmpty().toTypedArray())
|
||||
add(*channel.relatedStreams.toTypedArray())
|
||||
updateCurrent(newCurrentStream)
|
||||
if (channel.nextpage == null) return@launch
|
||||
fetchMoreFromChannel(channelId, channel.nextpage)
|
||||
|
Loading…
x
Reference in New Issue
Block a user