fix subscriptions

This commit is contained in:
Bnyro 2022-07-21 17:11:17 +02:00
parent cd43515277
commit e3f538422e
3 changed files with 47 additions and 8 deletions

View File

@ -19,8 +19,17 @@ class SubscriptionAdapter(
) : RecyclerView.Adapter<SubscriptionViewHolder>() { ) : RecyclerView.Adapter<SubscriptionViewHolder>() {
private val TAG = "SubscriptionAdapter" private val TAG = "SubscriptionAdapter"
var i = 0
override fun getItemCount(): Int { override fun getItemCount(): Int {
return videoFeed.size return i
}
fun updateItems() {
i += 10
if (i > videoFeed.size) {
i = videoFeed.size
}
notifyDataSetChanged()
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SubscriptionViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SubscriptionViewHolder {

View File

@ -85,6 +85,20 @@ class SubscriptionsFragment : Fragment() {
binding.subFeed.visibility = View.VISIBLE binding.subFeed.visibility = View.VISIBLE
} }
} }
binding.scrollviewSub.viewTreeObserver
.addOnScrollChangedListener {
if (binding.scrollviewSub.getChildAt(0).bottom
== (binding.scrollviewSub.height + binding.scrollviewSub.scrollY)
) {
// scroll view is at bottom
if (isLoaded) {
binding.subRefresh.isRefreshing = true
subscriptionAdapter?.updateItems()
binding.subRefresh.isRefreshing = false
}
}
}
} else { } else {
binding.subRefresh.isEnabled = false binding.subRefresh.isEnabled = false
} }
@ -108,6 +122,7 @@ class SubscriptionsFragment : Fragment() {
if (response.isNotEmpty()) { if (response.isNotEmpty()) {
subscriptionAdapter = SubscriptionAdapter(response, childFragmentManager) subscriptionAdapter = SubscriptionAdapter(response, childFragmentManager)
feedRecView.adapter = subscriptionAdapter feedRecView.adapter = subscriptionAdapter
subscriptionAdapter?.updateItems()
} else { } else {
runOnUiThread { runOnUiThread {
with(binding.boogh) { with(binding.boogh) {

View File

@ -94,18 +94,33 @@
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
<androidx.recyclerview.widget.RecyclerView <RelativeLayout
android:id="@+id/sub_channels"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:nestedScrollingEnabled="false" android:descendantFocusability="blocksDescendants">
android:visibility="gone" />
<androidx.recyclerview.widget.RecyclerView
<androidx.recyclerview.widget.RecyclerView android:visibility="gone"
android:id="@+id/sub_feed" android:id="@+id/sub_channels"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:nestedScrollingEnabled="false" /> android:descendantFocusability="blocksDescendants">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/sub_feed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false" />
</RelativeLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
</com.github.libretube.views.CustomSwipeToRefresh> </com.github.libretube.views.CustomSwipeToRefresh>