mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +05:30
fix crash when clicking channel
This commit is contained in:
parent
f1e16191b7
commit
ee4581f2e3
@ -58,8 +58,10 @@ class CommentsAdapter(
|
|||||||
val comment = comments[position]
|
val comment = comments[position]
|
||||||
holder.binding.apply {
|
holder.binding.apply {
|
||||||
if (isRepliesAdapter) {
|
if (isRepliesAdapter) {
|
||||||
root.scaleX = 0.9f
|
root.scaleX = REPLIES_ADAPTER_SCALE
|
||||||
root.scaleY = 0.9f
|
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()
|
commentInfos.text = comment.author.toString() + TextUtils.SEPARATOR + comment.commentedTime.toString()
|
||||||
@ -81,8 +83,7 @@ class CommentsAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
repliesRecView.layoutManager = LinearLayoutManager(root.context)
|
repliesRecView.layoutManager = LinearLayoutManager(root.context)
|
||||||
lateinit var repliesAdapter: CommentsAdapter
|
val repliesAdapter = CommentsAdapter(
|
||||||
repliesAdapter = CommentsAdapter(
|
|
||||||
videoId,
|
videoId,
|
||||||
mutableListOf(),
|
mutableListOf(),
|
||||||
true
|
true
|
||||||
@ -103,8 +104,8 @@ class CommentsAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun showMoreReplies(nextPage: String, showMoreBtn: Button, repliesAdapter: CommentsAdapter) {
|
private fun showMoreReplies(nextPage: String, showMoreBtn: Button, repliesAdapter: CommentsAdapter) {
|
||||||
when {
|
when (repliesAdapter.itemCount) {
|
||||||
repliesAdapter.itemCount.equals(0) -> {
|
0 -> {
|
||||||
fetchReplies(nextPage) {
|
fetchReplies(nextPage) {
|
||||||
repliesAdapter.updateItems(it.comments)
|
repliesAdapter.updateItems(it.comments)
|
||||||
if (repliesPage.nextpage == null) {
|
if (repliesPage.nextpage == null) {
|
||||||
@ -112,9 +113,9 @@ class CommentsAdapter(
|
|||||||
return@fetchReplies
|
return@fetchReplies
|
||||||
}
|
}
|
||||||
showMoreBtn.visibility = View.VISIBLE
|
showMoreBtn.visibility = View.VISIBLE
|
||||||
showMoreBtn.setOnClickListener {
|
showMoreBtn.setOnClickListener { view ->
|
||||||
if (repliesPage.nextpage == null) {
|
if (repliesPage.nextpage == null) {
|
||||||
it.visibility = View.GONE
|
view.visibility = View.GONE
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
fetchReplies(
|
fetchReplies(
|
||||||
@ -152,4 +153,8 @@ class CommentsAdapter(
|
|||||||
isLoading = false
|
isLoading = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val REPLIES_ADAPTER_SCALE = 0.9f
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.github.libretube.util
|
|||||||
|
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.ContextWrapper
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@ -22,7 +23,7 @@ object NavigationHelper {
|
|||||||
) {
|
) {
|
||||||
if (channelId == null) return
|
if (channelId == null) return
|
||||||
|
|
||||||
val activity = context as MainActivity
|
val activity = unwrap(context)
|
||||||
val bundle = bundleOf(IntentData.channelId to channelId)
|
val bundle = bundleOf(IntentData.channelId to channelId)
|
||||||
activity.navController.navigate(R.id.channelFragment, bundle)
|
activity.navController.navigate(R.id.channelFragment, bundle)
|
||||||
try {
|
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(
|
fun navigateVideo(
|
||||||
context: Context,
|
context: Context,
|
||||||
videoId: String?,
|
videoId: String?,
|
||||||
@ -64,7 +73,7 @@ object NavigationHelper {
|
|||||||
) {
|
) {
|
||||||
if (playlistId == null) return
|
if (playlistId == null) return
|
||||||
|
|
||||||
val activity = context as MainActivity
|
val activity = unwrap(context)
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
bundle.putString(IntentData.playlistId, playlistId)
|
bundle.putString(IntentData.playlistId, playlistId)
|
||||||
bundle.putSerializable(IntentData.playlistType, playlistType)
|
bundle.putSerializable(IntentData.playlistType, playlistType)
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:animateLayoutChanges="true"
|
android:animateLayoutChanges="true"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingStart="20dp"
|
android:paddingStart="15dp"
|
||||||
android:paddingEnd="20dp"
|
android:paddingEnd="15dp"
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
Loading…
x
Reference in New Issue
Block a user