mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
commit
94158448d5
14
app/src/main/java/com/github/libretube/obj/ChannelTabs.kt
Normal file
14
app/src/main/java/com/github/libretube/obj/ChannelTabs.kt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package com.github.libretube.obj
|
||||||
|
|
||||||
|
import androidx.annotation.IdRes
|
||||||
|
import com.github.libretube.R
|
||||||
|
|
||||||
|
sealed class ChannelTabs(
|
||||||
|
val identifierName: String,
|
||||||
|
@IdRes val chipId: Int
|
||||||
|
) {
|
||||||
|
object Playlists : ChannelTabs("playlists", R.id.playlists)
|
||||||
|
object Shorts : ChannelTabs("shorts", R.id.shorts)
|
||||||
|
object Livestreams : ChannelTabs("livestreams", R.id.livestreams)
|
||||||
|
object Channels : ChannelTabs("channels", R.id.channels)
|
||||||
|
}
|
@ -6,6 +6,7 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.core.view.children
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
@ -18,6 +19,7 @@ import com.github.libretube.enums.ShareObjectType
|
|||||||
import com.github.libretube.extensions.TAG
|
import com.github.libretube.extensions.TAG
|
||||||
import com.github.libretube.extensions.formatShort
|
import com.github.libretube.extensions.formatShort
|
||||||
import com.github.libretube.extensions.toID
|
import com.github.libretube.extensions.toID
|
||||||
|
import com.github.libretube.obj.ChannelTabs
|
||||||
import com.github.libretube.obj.ShareData
|
import com.github.libretube.obj.ShareData
|
||||||
import com.github.libretube.ui.adapters.SearchAdapter
|
import com.github.libretube.ui.adapters.SearchAdapter
|
||||||
import com.github.libretube.ui.adapters.VideosAdapter
|
import com.github.libretube.ui.adapters.VideosAdapter
|
||||||
@ -45,6 +47,13 @@ class ChannelFragment : BaseFragment() {
|
|||||||
|
|
||||||
private val scope = CoroutineScope(Dispatchers.IO)
|
private val scope = CoroutineScope(Dispatchers.IO)
|
||||||
|
|
||||||
|
val possibleTabs = listOf(
|
||||||
|
ChannelTabs.Channels,
|
||||||
|
ChannelTabs.Playlists,
|
||||||
|
ChannelTabs.Livestreams,
|
||||||
|
ChannelTabs.Shorts
|
||||||
|
)
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
arguments?.let {
|
arguments?.let {
|
||||||
@ -180,59 +189,41 @@ class ChannelFragment : BaseFragment() {
|
|||||||
binding.channelRecView.adapter = channelAdapter
|
binding.channelRecView.adapter = channelAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
setupTabs(response.tabs)
|
response.tabs?.let { setupTabs(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupTabs(tabs: List<ChannelTab>?) {
|
private fun setupTabs(tabs: List<ChannelTab>) {
|
||||||
tabs?.firstOrNull { it.name == "playlists" }?.let {
|
binding.tabChips.children.forEach { chip ->
|
||||||
binding.playlists.visibility = View.VISIBLE
|
val resourceTab = possibleTabs.firstOrNull { it.chipId == chip.id }
|
||||||
}
|
resourceTab?.let { resTab ->
|
||||||
|
if (tabs.any { it.name == resTab.identifierName }) chip.visibility = View.VISIBLE
|
||||||
tabs?.firstOrNull { it.name == "channels" }?.let {
|
}
|
||||||
binding.channels.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
|
|
||||||
tabs?.firstOrNull { it.name == "livestreams" }?.let {
|
|
||||||
binding.livestreams.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
|
|
||||||
tabs?.firstOrNull { it.name == "shorts" }?.let {
|
|
||||||
binding.shorts.visibility = View.VISIBLE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.tabChips.setOnCheckedStateChangeListener { _, _ ->
|
binding.tabChips.setOnCheckedStateChangeListener { _, _ ->
|
||||||
reactToTabChange(tabs)
|
when (binding.tabChips.checkedChipId) {
|
||||||
}
|
binding.videos.id -> {
|
||||||
}
|
binding.channelRecView.adapter = channelAdapter
|
||||||
|
onScrollEnd = {
|
||||||
private fun reactToTabChange(tabs: List<ChannelTab>?) {
|
fetchChannelNextPage()
|
||||||
when (binding.tabChips.checkedChipId) {
|
}
|
||||||
binding.videos.id -> {
|
}
|
||||||
binding.channelRecView.adapter = channelAdapter
|
else -> {
|
||||||
onScrollEnd = {
|
possibleTabs.first { binding.tabChips.checkedChipId == it.chipId }.let {
|
||||||
fetchChannelNextPage()
|
val tab = tabs.first { tab -> tab.name == it.identifierName }
|
||||||
|
loadTab(tab)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
binding.channels.id -> {
|
|
||||||
tabs?.first { it.name == "channels" }?.let { loadTab(it) }
|
|
||||||
}
|
|
||||||
binding.playlists.id -> {
|
|
||||||
tabs?.first { it.name == "playlists" }?.let { loadTab(it) }
|
|
||||||
}
|
|
||||||
binding.livestreams.id -> {
|
|
||||||
tabs?.first { it.name == "livestreams" }?.let { loadTab(it) }
|
|
||||||
}
|
|
||||||
binding.shorts.id -> {
|
|
||||||
tabs?.first { it.name == "shorts" }?.let { loadTab(it) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadTab(tab: ChannelTab) {
|
private fun loadTab(tab: ChannelTab) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
|
tab.data ?: return@launch
|
||||||
val response = try {
|
val response = try {
|
||||||
RetrofitInstance.api.getChannelTab(tab.data!!)
|
RetrofitInstance.api.getChannelTab(tab.data)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user