diff --git a/app/src/main/java/org/schabi/newpipe/ui/components/channel/AboutChannelSection.kt b/app/src/main/java/org/schabi/newpipe/ui/components/channel/AboutChannelSection.kt index 8fa3ca7c568..15c7d44469f 100644 --- a/app/src/main/java/org/schabi/newpipe/ui/components/channel/AboutChannelSection.kt +++ b/app/src/main/java/org/schabi/newpipe/ui/components/channel/AboutChannelSection.kt @@ -16,10 +16,10 @@ import org.schabi.newpipe.R import org.schabi.newpipe.extractor.channel.ChannelInfo import org.schabi.newpipe.ui.components.metadata.ImageMetadataItem import org.schabi.newpipe.ui.components.metadata.MetadataItem +import org.schabi.newpipe.ui.components.metadata.TagsSection import org.schabi.newpipe.ui.theme.AppTheme import org.schabi.newpipe.util.Localization import org.schabi.newpipe.util.NO_SERVICE_ID -import org.schabi.newpipe.util.image.ImageStrategy @Composable fun AboutChannelSection(channelInfo: ChannelInfo) { @@ -41,12 +41,12 @@ fun AboutChannelSection(channelInfo: ChannelInfo) { ) } - ImageStrategy.choosePreferredImage(channelInfo.avatars)?.let { - ImageMetadataItem(R.string.metadata_avatars, channelInfo.avatars, it) + if (channelInfo.avatars.isNotEmpty()) { + ImageMetadataItem(R.string.metadata_avatars, channelInfo.avatars) } - ImageStrategy.choosePreferredImage(channelInfo.banners)?.let { - ImageMetadataItem(R.string.metadata_banners, channelInfo.banners, it) + if (channelInfo.banners.isNotEmpty()) { + ImageMetadataItem(R.string.metadata_banners, channelInfo.banners) } if (channelInfo.tags.isNotEmpty()) { diff --git a/app/src/main/java/org/schabi/newpipe/ui/components/metadata/ImageMetadataItem.kt b/app/src/main/java/org/schabi/newpipe/ui/components/metadata/ImageMetadataItem.kt index 3df8c8cb196..66cd5c5bd7f 100644 --- a/app/src/main/java/org/schabi/newpipe/ui/components/metadata/ImageMetadataItem.kt +++ b/app/src/main/java/org/schabi/newpipe/ui/components/metadata/ImageMetadataItem.kt @@ -26,22 +26,16 @@ import org.schabi.newpipe.util.image.ImageStrategy import org.schabi.newpipe.util.image.PreferredImageQuality @Composable -fun ImageMetadataItem( - @StringRes title: Int, - images: List, - preferredUrl: String? = ImageStrategy.choosePreferredImage(images) -) { +fun ImageMetadataItem(@StringRes title: Int, images: List) { val context = LocalContext.current - val imageLinks = remember { convertImagesToLinks(context, images, preferredUrl) } + val imageLinks = remember(images) { convertImagesToLinks(context, images) } MetadataItem(title = title, value = imageLinks) } -private fun convertImagesToLinks( - context: Context, - images: List, - preferredUrl: String? -): AnnotatedString { +private fun convertImagesToLinks(context: Context, images: List): AnnotatedString { + val preferredUrl = ImageStrategy.choosePreferredImage(images) + fun imageSizeToText(size: Int): String { return if (size == Image.HEIGHT_UNKNOWN) context.getString(R.string.question_mark) else size.toString() diff --git a/app/src/main/java/org/schabi/newpipe/ui/components/video/VideoDescriptionSection.kt b/app/src/main/java/org/schabi/newpipe/ui/components/video/VideoDescriptionSection.kt index 1d0903c8647..62d4c1dc563 100644 --- a/app/src/main/java/org/schabi/newpipe/ui/components/video/VideoDescriptionSection.kt +++ b/app/src/main/java/org/schabi/newpipe/ui/components/video/VideoDescriptionSection.kt @@ -58,7 +58,6 @@ import org.schabi.newpipe.ui.components.metadata.TagsSection import org.schabi.newpipe.ui.theme.AppTheme import org.schabi.newpipe.util.Localization import org.schabi.newpipe.util.NO_SERVICE_ID -import org.schabi.newpipe.util.image.ImageStrategy import java.time.OffsetDateTime @OptIn(ExperimentalMaterial3Api::class) @@ -161,12 +160,10 @@ fun VideoDescriptionSection(streamInfo: StreamInfo) { } } - if (streamInfo.ageLimit != StreamExtractor.NO_AGE_LIMIT) { + val ageLimit = streamInfo.ageLimit + if (ageLimit != StreamExtractor.NO_AGE_LIMIT) { item { - MetadataItem( - title = R.string.metadata_age_limit, - value = streamInfo.ageLimit.toString() - ) + MetadataItem(title = R.string.metadata_age_limit, value = ageLimit.toString()) } } @@ -214,9 +211,9 @@ private fun LazyListScope.metadataItem(@StringRes title: Int, value: String) { } private fun LazyListScope.imageMetadataItem(@StringRes title: Int, images: List) { - ImageStrategy.choosePreferredImage(images)?.let { + if (images.isNotEmpty()) { item { - ImageMetadataItem(title, images, it) + ImageMetadataItem(title, images) } } }