fix: crash when refreshing channel page

This commit is contained in:
Bnyro 2024-06-10 14:22:41 +02:00
parent 9e04b52e4f
commit d477fd0d2c

View File

@ -56,9 +56,7 @@ class ChannelFragment : DynamicLayoutManagerFragment() {
private var nextPages = Array<String?>(5) { null } private var nextPages = Array<String?>(5) { null }
private var isAppBarFullyExpanded: Boolean = true private var isAppBarFullyExpanded: Boolean = true
private val tabList = mutableListOf( private val tabList = mutableListOf<ChannelTab>()
ChannelTab(VIDEOS_TAB_KEY, "")
)
private val tabNamesMap = mapOf( private val tabNamesMap = mapOf(
VIDEOS_TAB_KEY to R.string.videos, VIDEOS_TAB_KEY to R.string.videos,
@ -127,7 +125,7 @@ class ChannelFragment : DynamicLayoutManagerFragment() {
private fun fetchChannel() = lifecycleScope.launch { private fun fetchChannel() = lifecycleScope.launch {
isLoading = true isLoading = true
binding.channelRefresh.isRefreshing = true _binding?.channelRefresh?.isRefreshing = true
val response = try { val response = try {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
@ -237,11 +235,10 @@ class ChannelFragment : DynamicLayoutManagerFragment() {
response.relatedStreams.toMutableList(), response.relatedStreams.toMutableList(),
forceMode = VideosAdapter.Companion.LayoutMode.CHANNEL_ROW forceMode = VideosAdapter.Companion.LayoutMode.CHANNEL_ROW
) )
tabList.removeAll { tab -> tabList.clear()
tab.name != VIDEOS_TAB_KEY
} val tabs = listOf(ChannelTab(VIDEOS_TAB_KEY, "")) + response.tabs
tabList[0] = ChannelTab(getString(tabNamesMap[VIDEOS_TAB_KEY]!!), "") for (channelTab in tabs) {
response.tabs.forEach { channelTab ->
val tabName = tabNamesMap[channelTab.name]?.let { getString(it) } val tabName = tabNamesMap[channelTab.name]?.let { getString(it) }
?: channelTab.name.replaceFirstChar(Char::titlecase) ?: channelTab.name.replaceFirstChar(Char::titlecase)
tabList.add(ChannelTab(tabName, channelTab.data)) tabList.add(ChannelTab(tabName, channelTab.data))