fix crash when clicking channel

This commit is contained in:
Bnyro 2022-11-26 18:25:07 +01:00
parent f1e16191b7
commit ee4581f2e3
3 changed files with 26 additions and 12 deletions

View File

@ -58,8 +58,10 @@ class CommentsAdapter(
val comment = comments[position]
holder.binding.apply {
if (isRepliesAdapter) {
root.scaleX = 0.9f
root.scaleY = 0.9f
root.scaleX = REPLIES_ADAPTER_SCALE
root.scaleY = REPLIES_ADAPTER_SCALE
commentorImage.scaleX = REPLIES_ADAPTER_SCALE
commentorImage.scaleY = REPLIES_ADAPTER_SCALE
}
commentInfos.text = comment.author.toString() + TextUtils.SEPARATOR + comment.commentedTime.toString()
@ -81,8 +83,7 @@ class CommentsAdapter(
}
repliesRecView.layoutManager = LinearLayoutManager(root.context)
lateinit var repliesAdapter: CommentsAdapter
repliesAdapter = CommentsAdapter(
val repliesAdapter = CommentsAdapter(
videoId,
mutableListOf(),
true
@ -103,8 +104,8 @@ class CommentsAdapter(
}
private fun showMoreReplies(nextPage: String, showMoreBtn: Button, repliesAdapter: CommentsAdapter) {
when {
repliesAdapter.itemCount.equals(0) -> {
when (repliesAdapter.itemCount) {
0 -> {
fetchReplies(nextPage) {
repliesAdapter.updateItems(it.comments)
if (repliesPage.nextpage == null) {
@ -112,9 +113,9 @@ class CommentsAdapter(
return@fetchReplies
}
showMoreBtn.visibility = View.VISIBLE
showMoreBtn.setOnClickListener {
showMoreBtn.setOnClickListener { view ->
if (repliesPage.nextpage == null) {
it.visibility = View.GONE
view.visibility = View.GONE
return@setOnClickListener
}
fetchReplies(
@ -152,4 +153,8 @@ class CommentsAdapter(
isLoading = false
}
}
companion object {
private const val REPLIES_ADAPTER_SCALE = 0.9f
}
}

View File

@ -2,6 +2,7 @@ package com.github.libretube.util
import android.app.NotificationManager
import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
@ -22,7 +23,7 @@ object NavigationHelper {
) {
if (channelId == null) return
val activity = context as MainActivity
val activity = unwrap(context)
val bundle = bundleOf(IntentData.channelId to channelId)
activity.navController.navigate(R.id.channelFragment, bundle)
try {
@ -36,6 +37,14 @@ object NavigationHelper {
}
}
private fun unwrap(context: Context): MainActivity {
var correctContext: Context? = context
while (correctContext !is MainActivity && correctContext is ContextWrapper) {
correctContext = correctContext.baseContext
}
return correctContext as MainActivity
}
fun navigateVideo(
context: Context,
videoId: String?,
@ -64,7 +73,7 @@ object NavigationHelper {
) {
if (playlistId == null) return
val activity = context as MainActivity
val activity = unwrap(context)
val bundle = Bundle()
bundle.putString(IntentData.playlistId, playlistId)
bundle.putSerializable(IntentData.playlistType, playlistType)

View File

@ -12,8 +12,8 @@
android:layout_marginTop="10dp"
android:animateLayoutChanges="true"
android:orientation="vertical"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:paddingStart="15dp"
android:paddingEnd="15dp"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout