mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-01-06 01:20:29 +05:30
channel load more problem
This commit is contained in:
parent
c81fea96cc
commit
a9f4401dc4
@ -33,6 +33,8 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
|
||||||
|
|
||||||
implementation 'androidx.appcompat:appcompat:1.4.1'
|
implementation 'androidx.appcompat:appcompat:1.4.1'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||||
implementation 'com.google.android.material:material:1.6.0-alpha02'
|
implementation 'com.google.android.material:material:1.6.0-alpha02'
|
||||||
|
@ -19,6 +19,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import com.github.libretube.adapters.ChannelAdapter
|
import com.github.libretube.adapters.ChannelAdapter
|
||||||
import com.github.libretube.adapters.TrendingAdapter
|
import com.github.libretube.adapters.TrendingAdapter
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
|
import leakcanary.AppWatcher
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.URLEncoder
|
import java.net.URLEncoder
|
||||||
@ -30,7 +31,7 @@ class ChannelFragment : Fragment() {
|
|||||||
private var channel_id: String? = null
|
private var channel_id: String? = null
|
||||||
private val TAG = "ChannelFragment"
|
private val TAG = "ChannelFragment"
|
||||||
//lateinit var recyclerView: RecyclerView
|
//lateinit var recyclerView: RecyclerView
|
||||||
lateinit var nextPage: String
|
var nextPage: String? =null
|
||||||
lateinit var channelAdapter: ChannelAdapter
|
lateinit var channelAdapter: ChannelAdapter
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@ -46,10 +47,13 @@ class ChannelFragment : Fragment() {
|
|||||||
): View? {
|
): View? {
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
return inflater.inflate(R.layout.fragment_channel, container, false)
|
return inflater.inflate(R.layout.fragment_channel, container, false)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
channel_id = channel_id!!.replace("/channel/","")
|
channel_id = channel_id!!.replace("/channel/","")
|
||||||
view.findViewById<TextView>(R.id.channel_name).text=channel_id
|
view.findViewById<TextView>(R.id.channel_name).text=channel_id
|
||||||
val recyclerView = view.findViewById<RecyclerView>(R.id.channel_recView)
|
val recyclerView = view.findViewById<RecyclerView>(R.id.channel_recView)
|
||||||
@ -83,7 +87,7 @@ class ChannelFragment : Fragment() {
|
|||||||
Picasso.get().load(response.avatarUrl).into(channelImage)
|
Picasso.get().load(response.avatarUrl).into(channelImage)
|
||||||
channelAdapter = ChannelAdapter(response.relatedStreams!!.toMutableList())
|
channelAdapter = ChannelAdapter(response.relatedStreams!!.toMutableList())
|
||||||
view.findViewById<RecyclerView>(R.id.channel_recView).adapter = channelAdapter
|
view.findViewById<RecyclerView>(R.id.channel_recView).adapter = channelAdapter
|
||||||
|
AppWatcher.objectWatcher.watch(channelAdapter, "View was detached")
|
||||||
val scrollView = view.findViewById<ScrollView>(R.id.channel_scrollView)
|
val scrollView = view.findViewById<ScrollView>(R.id.channel_scrollView)
|
||||||
scrollView.viewTreeObserver
|
scrollView.viewTreeObserver
|
||||||
.addOnScrollChangedListener {
|
.addOnScrollChangedListener {
|
||||||
@ -91,7 +95,8 @@ class ChannelFragment : Fragment() {
|
|||||||
== (scrollView.height + scrollView.scrollY)) {
|
== (scrollView.height + scrollView.scrollY)) {
|
||||||
//scroll view is at bottom
|
//scroll view is at bottom
|
||||||
//todo find a better solution to load more videos in channel
|
//todo find a better solution to load more videos in channel
|
||||||
//fetchNextPage()
|
if(nextPage!=null){
|
||||||
|
fetchNextPage()}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//scroll view is not at bottom
|
//scroll view is not at bottom
|
||||||
@ -104,9 +109,10 @@ class ChannelFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
private fun fetchNextPage(){
|
private fun fetchNextPage(){
|
||||||
fun run() {
|
fun run() {
|
||||||
|
|
||||||
lifecycleScope.launchWhenCreated {
|
lifecycleScope.launchWhenCreated {
|
||||||
val response = try {
|
val response = try {
|
||||||
RetrofitInstance.api.getChannelNextPage(channel_id!!,nextPage)
|
RetrofitInstance.api.getChannelNextPage(channel_id!!,nextPage!!)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
println(e)
|
println(e)
|
||||||
Log.e(TAG, "IOException, you might not have internet connection")
|
Log.e(TAG, "IOException, you might not have internet connection")
|
||||||
@ -115,7 +121,8 @@ class ChannelFragment : Fragment() {
|
|||||||
Log.e(TAG, "HttpException, unexpected response,"+e.response())
|
Log.e(TAG, "HttpException, unexpected response,"+e.response())
|
||||||
return@launchWhenCreated
|
return@launchWhenCreated
|
||||||
}
|
}
|
||||||
nextPage = response.nextpage!!
|
println("dafaq")
|
||||||
|
nextPage = response.nextpage
|
||||||
channelAdapter.updateItems(response.relatedStreams!!)
|
channelAdapter.updateItems(response.relatedStreams!!)
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -127,4 +134,9 @@ class ChannelFragment : Fragment() {
|
|||||||
if (!isAdded) return // Fragment not attached to an Activity
|
if (!isAdded) return // Fragment not attached to an Activity
|
||||||
activity?.runOnUiThread(action)
|
activity?.runOnUiThread(action)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView() {
|
||||||
|
view?.findViewById<RecyclerView>(R.id.channel_recView)?.adapter=null
|
||||||
|
super.onDestroyView()
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user