Skip to content

Commit 45aa445

Browse files
Fix crash when minimizing the channel about tab
1 parent 507b3b4 commit 45aa445

File tree

6 files changed

+53
-300
lines changed

6 files changed

+53
-300
lines changed

app/src/main/java/org/schabi/newpipe/fragments/detail/BaseDescriptionFragment.java

Lines changed: 0 additions & 281 deletions
This file was deleted.

app/src/main/java/org/schabi/newpipe/fragments/list/channel/AboutChannelFragment.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import androidx.core.os.bundleOf
99
import androidx.fragment.app.Fragment
1010
import androidx.fragment.compose.content
1111
import org.schabi.newpipe.extractor.channel.ChannelInfo
12-
import org.schabi.newpipe.ktx.serializable
12+
import org.schabi.newpipe.ktx.parcelable
1313
import org.schabi.newpipe.ui.components.channel.AboutChannelSection
14+
import org.schabi.newpipe.ui.components.channel.ParcelableChannelInfo
1415
import org.schabi.newpipe.ui.theme.AppTheme
1516
import org.schabi.newpipe.util.KEY_INFO
1617

@@ -22,15 +23,15 @@ class AboutChannelFragment : Fragment() {
2223
) = content {
2324
AppTheme {
2425
Surface(color = MaterialTheme.colorScheme.background) {
25-
AboutChannelSection(requireArguments().serializable(KEY_INFO)!!)
26+
AboutChannelSection(requireArguments().parcelable(KEY_INFO)!!)
2627
}
2728
}
2829
}
2930

3031
companion object {
3132
@JvmStatic
3233
fun getInstance(channelInfo: ChannelInfo) = AboutChannelFragment().apply {
33-
arguments = bundleOf(KEY_INFO to channelInfo)
34+
arguments = bundleOf(KEY_INFO to ParcelableChannelInfo(channelInfo))
3435
}
3536
}
3637
}

app/src/main/java/org/schabi/newpipe/ktx/Bundle.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import android.os.Parcelable
55
import androidx.core.os.BundleCompat
66
import java.io.Serializable
77

8+
inline fun <reified T : Parcelable> Bundle.parcelable(key: String?): T? {
9+
return BundleCompat.getParcelable(this, key, T::class.java)
10+
}
11+
812
inline fun <reified T : Parcelable> Bundle.parcelableArrayList(key: String?): ArrayList<T>? {
913
return BundleCompat.getParcelableArrayList(this, key, T::class.java)
1014
}

app/src/main/java/org/schabi/newpipe/ui/components/channel/AboutChannelSection.kt

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import androidx.compose.ui.platform.LocalContext
1313
import androidx.compose.ui.tooling.preview.Preview
1414
import androidx.compose.ui.unit.dp
1515
import org.schabi.newpipe.R
16-
import org.schabi.newpipe.extractor.channel.ChannelInfo
16+
import org.schabi.newpipe.extractor.Image
17+
import org.schabi.newpipe.extractor.Image.ResolutionLevel
1718
import org.schabi.newpipe.ui.components.metadata.ImageMetadataItem
1819
import org.schabi.newpipe.ui.components.metadata.MetadataItem
1920
import org.schabi.newpipe.ui.components.metadata.TagsSection
@@ -22,35 +23,35 @@ import org.schabi.newpipe.util.Localization
2223
import org.schabi.newpipe.util.NO_SERVICE_ID
2324

2425
@Composable
25-
fun AboutChannelSection(channelInfo: ChannelInfo) {
26+
fun AboutChannelSection(channelInfo: ParcelableChannelInfo) {
2627
// This tab currently holds little information, so a lazy column isn't needed here.
2728
Column(
2829
modifier = Modifier.padding(12.dp),
2930
verticalArrangement = Arrangement.spacedBy(4.dp)
3031
) {
31-
val description = channelInfo.description
32-
if (!description.isNullOrEmpty()) {
32+
val (serviceId, description, count, avatars, banners, tags) = channelInfo
33+
34+
if (description.isNotEmpty()) {
3335
Text(text = description)
3436
}
3537

36-
val count = channelInfo.subscriberCount
3738
if (count != -1L) {
3839
MetadataItem(
3940
title = R.string.metadata_subscribers,
4041
value = Localization.shortCount(LocalContext.current, count)
4142
)
4243
}
4344

44-
if (channelInfo.avatars.isNotEmpty()) {
45-
ImageMetadataItem(R.string.metadata_avatars, channelInfo.avatars)
45+
if (avatars.isNotEmpty()) {
46+
ImageMetadataItem(R.string.metadata_avatars, avatars)
4647
}
4748

48-
if (channelInfo.banners.isNotEmpty()) {
49-
ImageMetadataItem(R.string.metadata_banners, channelInfo.banners)
49+
if (banners.isNotEmpty()) {
50+
ImageMetadataItem(R.string.metadata_banners, banners)
5051
}
5152

52-
if (channelInfo.tags.isNotEmpty()) {
53-
TagsSection(channelInfo.serviceId, channelInfo.tags)
53+
if (tags.isNotEmpty()) {
54+
TagsSection(serviceId, tags)
5455
}
5556
}
5657
}
@@ -59,9 +60,18 @@ fun AboutChannelSection(channelInfo: ChannelInfo) {
5960
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
6061
@Composable
6162
private fun AboutChannelSectionPreview() {
62-
val info = ChannelInfo(NO_SERVICE_ID, "", "", "", "")
63-
info.description = "This is an example description"
64-
info.subscriberCount = 10
63+
val images = listOf(
64+
Image("https://example.com/image_low.png", 16, 16, ResolutionLevel.LOW),
65+
Image("https://example.com/image_mid.png", 32, 32, ResolutionLevel.MEDIUM)
66+
)
67+
val info = ParcelableChannelInfo(
68+
serviceId = NO_SERVICE_ID,
69+
description = "This is an example description",
70+
subscriberCount = 10,
71+
avatars = images,
72+
banners = images,
73+
tags = listOf("Tag 1", "Tag 2")
74+
)
6575

6676
AppTheme {
6777
Surface(color = MaterialTheme.colorScheme.background) {

0 commit comments

Comments
 (0)