fix: 无图片 / 视频时仍占位

This commit is contained in:
HuanCheng65 2023-10-08 00:25:38 +08:00
parent 4139f1a3f9
commit af3ce0a9a2
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
1 changed files with 126 additions and 120 deletions

View File

@ -438,8 +438,8 @@ private fun ThreadMedia(
val mediaCount = remember(medias) { val mediaCount = remember(medias) {
medias.size medias.size
} }
val hasMedia = remember(mediaCount) { mediaCount > 0 } val hasPhoto = remember(mediaCount) { mediaCount > 0 }
val isSingleMedia = remember(mediaCount) { mediaCount == 1 } val isSinglePhoto = remember(mediaCount) { mediaCount == 1 }
val hideMedia = context.appPreferences.hideMedia val hideMedia = context.appPreferences.hideMedia
@ -450,131 +450,137 @@ private fun ThreadMedia(
else 0.5f else 0.5f
} }
Box(modifier = modifier) { val hasMedia = remember(hasPhoto, videoInfo) {
if (videoInfo != null) { hasPhoto || videoInfo != null
if (hideMedia) { }
MediaPlaceholder(
icon = { if (hasMedia) {
Icon( Box(modifier = modifier) {
imageVector = Icons.Rounded.OndemandVideo, if (videoInfo != null) {
contentDescription = stringResource(id = R.string.desc_video) if (hideMedia) {
) MediaPlaceholder(
}, icon = {
text = { Icon(
Text(text = stringResource(id = R.string.desc_video)) imageVector = Icons.Rounded.OndemandVideo,
}, contentDescription = stringResource(id = R.string.desc_video)
modifier = Modifier.fillMaxWidth()
)
} else {
val aspectRatio = remember(videoInfo) {
max(
videoInfo
.get { thumbnailWidth }
.toFloat() / videoInfo.get { thumbnailHeight },
16f / 9
)
}
Box(
modifier = Modifier.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null,
onClick = {}
)
) {
VideoPlayer(
videoUrl = videoInfo.get { videoUrl },
thumbnailUrl = videoInfo.get { thumbnailUrl },
modifier = Modifier
.fillMaxWidth(singleMediaFraction)
.aspectRatio(aspectRatio)
.clip(RoundedCornerShape(8.dp))
)
}
}
} else if (hasMedia) {
val mediaWidthFraction = remember(isSingleMedia, singleMediaFraction) {
if (isSingleMedia) singleMediaFraction else 1f
}
val mediaAspectRatio = remember(isSingleMedia) {
if (isSingleMedia) 2f else 3f
}
if (hideMedia) {
val photoViewData = remember(
medias, forumId, forumName, threadId
) {
getPhotoViewData(
medias = medias.map { it.get() },
forumId = forumId,
forumName = forumName,
threadId = threadId,
index = 0
)
}
MediaPlaceholder(
icon = {
Icon(
imageVector = if (isSingleMedia) Icons.Rounded.Photo else Icons.Rounded.PhotoLibrary,
contentDescription = stringResource(id = R.string.desc_photo)
)
},
text = {
Text(text = stringResource(id = R.string.btn_open_photos, mediaCount))
},
modifier = Modifier.fillMaxWidth(),
onClick = {
context.goToActivity<PhotoViewActivity> {
putExtra(
PhotoViewActivity.EXTRA_PHOTO_VIEW_DATA,
photoViewData
) )
} },
text = {
Text(text = stringResource(id = R.string.desc_video))
},
modifier = Modifier.fillMaxWidth()
)
} else {
val aspectRatio = remember(videoInfo) {
max(
videoInfo
.get { thumbnailWidth }
.toFloat() / videoInfo.get { thumbnailHeight },
16f / 9
)
} }
) Box(
} else { modifier = Modifier.clickable(
val showMediaCount = remember(medias) { min(medias.size, 3) } interactionSource = remember { MutableInteractionSource() },
val hasMoreMedia = remember(medias) { medias.size > 3 } indication = null,
val showMedias = remember(medias) { medias.subList(0, showMediaCount) } onClick = {}
Box { )
Row(
modifier = Modifier
.fillMaxWidth(mediaWidthFraction)
.aspectRatio(mediaAspectRatio)
.clip(RoundedCornerShape(8.dp)),
horizontalArrangement = Arrangement.spacedBy(4.dp)
) { ) {
showMedias.fastForEachIndexed { index, media -> VideoPlayer(
val photoViewData = remember( videoUrl = videoInfo.get { videoUrl },
index, medias, forumId, forumName, threadId thumbnailUrl = videoInfo.get { thumbnailUrl },
) { modifier = Modifier
getPhotoViewData( .fillMaxWidth(singleMediaFraction)
medias = medias.map { it.get() }, .aspectRatio(aspectRatio)
forumId = forumId, .clip(RoundedCornerShape(8.dp))
forumName = forumName, )
threadId = threadId, }
index = index }
} else if (hasPhoto) {
val mediaWidthFraction = remember(isSinglePhoto, singleMediaFraction) {
if (isSinglePhoto) singleMediaFraction else 1f
}
val mediaAspectRatio = remember(isSinglePhoto) {
if (isSinglePhoto) 2f else 3f
}
if (hideMedia) {
val photoViewData = remember(
medias, forumId, forumName, threadId
) {
getPhotoViewData(
medias = medias.map { it.get() },
forumId = forumId,
forumName = forumName,
threadId = threadId,
index = 0
)
}
MediaPlaceholder(
icon = {
Icon(
imageVector = if (isSinglePhoto) Icons.Rounded.Photo else Icons.Rounded.PhotoLibrary,
contentDescription = stringResource(id = R.string.desc_photo)
)
},
text = {
Text(text = stringResource(id = R.string.btn_open_photos, mediaCount))
},
modifier = Modifier.fillMaxWidth(),
onClick = {
context.goToActivity<PhotoViewActivity> {
putExtra(
PhotoViewActivity.EXTRA_PHOTO_VIEW_DATA,
photoViewData
) )
} }
NetworkImage( }
imageUri = remember(media) { media.url }, )
contentDescription = null, } else {
val showMediaCount = remember(medias) { min(medias.size, 3) }
val hasMoreMedia = remember(medias) { medias.size > 3 }
val showMedias = remember(medias) { medias.subList(0, showMediaCount) }
Box {
Row(
modifier = Modifier
.fillMaxWidth(mediaWidthFraction)
.aspectRatio(mediaAspectRatio)
.clip(RoundedCornerShape(8.dp)),
horizontalArrangement = Arrangement.spacedBy(4.dp)
) {
showMedias.fastForEachIndexed { index, media ->
val photoViewData = remember(
index, medias, forumId, forumName, threadId
) {
getPhotoViewData(
medias = medias.map { it.get() },
forumId = forumId,
forumName = forumName,
threadId = threadId,
index = index
)
}
NetworkImage(
imageUri = remember(media) { media.url },
contentDescription = null,
modifier = Modifier
.fillMaxHeight()
.weight(1f),
photoViewData = photoViewData,
contentScale = ContentScale.Crop,
enablePreview = true
)
}
}
if (hasMoreMedia) {
Badge(
icon = Icons.Rounded.PhotoSizeSelectActual,
text = "${medias.size}",
modifier = Modifier modifier = Modifier
.fillMaxHeight() .align(Alignment.BottomEnd)
.weight(1f), .padding(8.dp)
photoViewData = photoViewData,
contentScale = ContentScale.Crop,
enablePreview = true
) )
} }
} }
if (hasMoreMedia) {
Badge(
icon = Icons.Rounded.PhotoSizeSelectActual,
text = "${medias.size}",
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(8.dp)
)
}
} }
} }
} }
@ -826,7 +832,7 @@ fun FeedCard(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
onClickReply: (PostInfoList) -> Unit = {}, onClickReply: (PostInfoList) -> Unit = {},
onClickUser: (id: Long) -> Unit = {}, onClickUser: (id: Long) -> Unit = {},
onClickForum: (SimpleForum) -> Unit = {}, onClickForum: (name: String) -> Unit = {},
onClickOriginThread: (OriginThreadInfo) -> Unit = {}, onClickOriginThread: (OriginThreadInfo) -> Unit = {},
) { ) {
Card( Card(
@ -874,7 +880,7 @@ fun FeedCard(
ThreadForumInfo( ThreadForumInfo(
forumName = item.get { forum_name }, forumName = item.get { forum_name },
forumAvatar = null, forumAvatar = null,
onClick = {} onClick = { onClickForum(item.get { forum_name }) }
) )
}, },
action = { action = {