channel fragment load more memory leak

This commit is contained in:
rimthekid 2022-02-05 19:40:29 +04:00
parent fdca8cb0af
commit e70a49033a
4 changed files with 16 additions and 10 deletions

View File

@ -14,6 +14,7 @@
android:theme="@style/Theme.LibreTube" android:theme="@style/Theme.LibreTube"
android:name=".myApp" android:name=".myApp"
android:networkSecurityConfig="@xml/network_security_config" android:networkSecurityConfig="@xml/network_security_config"
android:largeHeap="true"
> >
<activity <activity
android:name=".Player" android:name=".Player"
@ -25,6 +26,7 @@
android:name=".MainActivity" android:name=".MainActivity"
android:exported="true" android:exported="true"
android:configChanges="orientation|screenSize" android:configChanges="orientation|screenSize"
android:hardwareAccelerated="true"
> >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

View File

@ -14,6 +14,7 @@ import android.widget.TextView
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView 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
@ -35,7 +36,7 @@ class ChannelFragment : Fragment() {
// TODO: Rename and change types of parameters // TODO: Rename and change types of parameters
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 lateinit var nextPage: String
lateinit var channelAdapter: ChannelAdapter lateinit var channelAdapter: ChannelAdapter
@ -58,8 +59,8 @@ class ChannelFragment : Fragment() {
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
recyclerView = view.findViewById(R.id.channel_recView) val recyclerView = view.findViewById<RecyclerView>(R.id.channel_recView)
recyclerView.layoutManager = GridLayoutManager(view.context, 1) recyclerView.layoutManager = LinearLayoutManager(context)
fetchChannel(view) fetchChannel(view)
@ -88,7 +89,7 @@ class ChannelFragment : Fragment() {
Picasso.get().load(response.bannerUrl).into(bannerImage) Picasso.get().load(response.bannerUrl).into(bannerImage)
Picasso.get().load(response.avatarUrl).into(channelImage) Picasso.get().load(response.avatarUrl).into(channelImage)
channelAdapter = ChannelAdapter(response.relatedStreams!!.toMutableList()) channelAdapter = ChannelAdapter(response.relatedStreams!!.toMutableList())
recyclerView.adapter = channelAdapter view.findViewById<RecyclerView>(R.id.channel_recView).adapter = channelAdapter
val scrollView = view.findViewById<ScrollView>(R.id.channel_scrollView) val scrollView = view.findViewById<ScrollView>(R.id.channel_scrollView)
scrollView.viewTreeObserver scrollView.viewTreeObserver
@ -96,8 +97,8 @@ class ChannelFragment : Fragment() {
if (scrollView.getChildAt(0).bottom if (scrollView.getChildAt(0).bottom
== (scrollView.height + scrollView.scrollY)) { == (scrollView.height + scrollView.scrollY)) {
//scroll view is at bottom //scroll view is at bottom
println("suck a dick: "+channel_id+"?nextpage="+nextPage) //todo find a better solution to load more videos in channel
fetchNextPage() //fetchNextPage()
} else { } else {
//scroll view is not at bottom //scroll view is not at bottom
@ -122,10 +123,8 @@ class ChannelFragment : Fragment() {
return@launchWhenCreated return@launchWhenCreated
} }
nextPage = response.nextpage!! nextPage = response.nextpage!!
runOnUiThread { channelAdapter.updateItems(response.relatedStreams!!)
channelAdapter.updateItems(response.relatedStreams!!)
}
} }
} }
run() run()

View File

@ -107,4 +107,9 @@ class Home : 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.recview)?.adapter=null
super.onDestroyView()
}
} }

View File

@ -22,7 +22,7 @@ class ChannelAdapter(private val videoFeed: MutableList<StreamItem>): RecyclerVi
} }
fun updateItems(newItems: List<StreamItem>){ fun updateItems(newItems: List<StreamItem>){
videoFeed.addAll(newItems) videoFeed.addAll(newItems)
println("suck another dick: "+newItems[0].title) //println("suck another dick: "+newItems[0].title)
notifyDataSetChanged() notifyDataSetChanged()
} }