Skip to content

Commit

Permalink
Show image tags even if image loading is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Sep 1, 2024
1 parent 2653787 commit 507b3b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Image>,
preferredUrl: String? = ImageStrategy.choosePreferredImage(images)
) {
fun ImageMetadataItem(@StringRes title: Int, images: List<Image>) {
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<Image>,
preferredUrl: String?
): AnnotatedString {
private fun convertImagesToLinks(context: Context, images: List<Image>): 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
}
}

Expand Down Expand Up @@ -214,9 +211,9 @@ private fun LazyListScope.metadataItem(@StringRes title: Int, value: String) {
}

private fun LazyListScope.imageMetadataItem(@StringRes title: Int, images: List<Image>) {
ImageStrategy.choosePreferredImage(images)?.let {
if (images.isNotEmpty()) {
item {
ImageMetadataItem(title, images, it)
ImageMetadataItem(title, images)
}
}
}
Expand Down

0 comments on commit 507b3b4

Please sign in to comment.