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