mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 15:30:31 +05:30
Channel tab fixes
This commit is contained in:
parent
bfe16ddd27
commit
c8d8fdbe41
@ -44,7 +44,7 @@ class ChannelFragment : BaseFragment() {
|
||||
|
||||
private var onScrollEnd: () -> Unit = {}
|
||||
|
||||
val scope = CoroutineScope(Dispatchers.IO)
|
||||
private val scope = CoroutineScope(Dispatchers.IO)
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -115,11 +115,7 @@ class ChannelFragment : BaseFragment() {
|
||||
val shareData = ShareData(currentChannel = response.name)
|
||||
|
||||
onScrollEnd = {
|
||||
if (nextPage != null && !isLoading) {
|
||||
isLoading = true
|
||||
binding.channelRefresh.isRefreshing = true
|
||||
fetchChannelNextPage()
|
||||
}
|
||||
fetchChannelNextPage()
|
||||
}
|
||||
|
||||
// fetch and update the subscription status
|
||||
@ -197,6 +193,12 @@ class ChannelFragment : BaseFragment() {
|
||||
|
||||
binding.videos.setOnClickListener {
|
||||
binding.channelRecView.adapter = channelAdapter
|
||||
onScrollEnd = {
|
||||
fetchChannelNextPage()
|
||||
}
|
||||
binding.tabChips.children.forEach { child ->
|
||||
if (child != it) (child as Chip).isChecked = false
|
||||
}
|
||||
}
|
||||
|
||||
response.tabs?.firstOrNull { it.name == "Playlists" }?.let {
|
||||
@ -239,20 +241,11 @@ class ChannelFragment : BaseFragment() {
|
||||
binding.channelRecView.adapter = adapter
|
||||
}
|
||||
|
||||
var tabNextPage = response.nextpage
|
||||
onScrollEnd = {
|
||||
if (response.nextpage != null) {
|
||||
scope.launch {
|
||||
val newContent = try {
|
||||
RetrofitInstance.api.getChannelTab(tab.data, response.nextpage)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
}
|
||||
runOnUiThread {
|
||||
newContent?.content?.let {
|
||||
adapter.updateItems(it)
|
||||
}
|
||||
}
|
||||
tabNextPage?.let {
|
||||
fetchTabNextPage(it, tab, adapter) { nextPage ->
|
||||
tabNextPage = nextPage
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -262,12 +255,15 @@ class ChannelFragment : BaseFragment() {
|
||||
|
||||
private fun fetchChannelNextPage() {
|
||||
fun run() {
|
||||
if (nextPage == null || isLoading) return
|
||||
isLoading = true
|
||||
binding.channelRefresh.isRefreshing = true
|
||||
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
RetrofitInstance.api.getChannelNextPage(channelId!!, nextPage!!)
|
||||
} catch (e: IOException) {
|
||||
binding.channelRefresh.isRefreshing = false
|
||||
println(e)
|
||||
Log.e(TAG(), "IOException, you might not have internet connection")
|
||||
return@launchWhenCreated
|
||||
} catch (e: HttpException) {
|
||||
@ -283,4 +279,26 @@ class ChannelFragment : BaseFragment() {
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
private fun fetchTabNextPage(
|
||||
nextPage: String,
|
||||
tab: ChannelTab,
|
||||
adapter: SearchAdapter,
|
||||
onNewNextPage: (String?) -> Unit
|
||||
) {
|
||||
scope.launch {
|
||||
val newContent = try {
|
||||
RetrofitInstance.api.getChannelTab(tab.data ?: "", nextPage)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
}
|
||||
onNewNextPage.invoke(newContent?.nextpage)
|
||||
runOnUiThread {
|
||||
newContent?.content?.let {
|
||||
adapter.updateItems(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
@ -18,7 +19,10 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
android:padding="8dp" />
|
||||
android:paddingVertical="8dp"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="40dp"
|
||||
tools:ignore="RtlSymmetry" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/addToPlaylist"
|
||||
|
Loading…
x
Reference in New Issue
Block a user