diff --git a/app/src/main/kotlin/com/hippo/ehviewer/Settings.kt b/app/src/main/kotlin/com/hippo/ehviewer/Settings.kt index 3b1f37012..089caf3a2 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/Settings.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/Settings.kt @@ -43,6 +43,7 @@ object Settings : DataStorePreferences(null) { var thumbResolution by intPref("thumb_resolution_2", 0) var readCacheSize by intPref("read_cache_size_2", 640) var launchPage by intPref("launch_page_2", 0) + var commentThreshold by intPref("comment_threshold", -101) var forceEhThumb by boolPref("force_eh_thumb", false) var showComments by boolPref("show_gallery_comments", true) var requestNews by boolPref("request_news", false).observed { updateWhenRequestNewsChanges() } diff --git a/app/src/main/kotlin/com/hippo/ehviewer/client/parser/GalleryDetailParser.kt b/app/src/main/kotlin/com/hippo/ehviewer/client/parser/GalleryDetailParser.kt index 20824a421..491ef4ea0 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/client/parser/GalleryDetailParser.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/client/parser/GalleryDetailParser.kt @@ -17,6 +17,7 @@ package com.hippo.ehviewer.client.parser import arrow.core.unzip import com.hippo.ehviewer.EhDB +import com.hippo.ehviewer.Settings import com.hippo.ehviewer.client.EhFilter import com.hippo.ehviewer.client.EhUtils import com.hippo.ehviewer.client.EhUtils.getCategory @@ -394,7 +395,7 @@ object GalleryDetailParser { // filter comment if (!comment.uploader) { val sEhFilter = EhFilter - if (sEhFilter.filterCommenter(comment.user!!) || sEhFilter.filterComment(comment.comment!!)) { + if (comment.score <= Settings.commentThreshold || sEhFilter.filterCommenter(comment.user!!) || sEhFilter.filterComment(comment.comment!!)) { return null } } diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt index 572b43caa..60b7a4f2f 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt @@ -1015,9 +1015,9 @@ class GalleryDetailScene : BaseScene() { @SuppressLint("InflateParams") @Composable - private fun GalleryDetailComment(commentsList: Array?) { + private fun GalleryDetailComment(commentsList: Array) { val maxShowCount = 2 - val commentText = if (commentsList.isNullOrEmpty()) { + val commentText = if (commentsList.isEmpty()) { stringResource(R.string.no_comments) } else if (commentsList.size <= maxShowCount) { stringResource(R.string.no_more_comments) @@ -1025,18 +1025,16 @@ class GalleryDetailScene : BaseScene() { stringResource(R.string.more_comment) } CrystalCard { - if (commentsList != null) { - val length = maxShowCount.coerceAtMost(commentsList.size) - for (i in 0 until length) { - val item = commentsList[i] - AndroidViewBinding(factory = ItemGalleryCommentBinding::inflate) { - card.setOnClickListener { onNavigateToCommentScene() } - user.text = item.user - user.setBackgroundColor(Color.TRANSPARENT) - time.text = ReadableTime.getTimeAgo(item.time) - comment.maxLines = 5 - comment.text = item.comment.orEmpty().parseAsHtml(imageGetter = CoilImageGetter(comment)) - } + val length = maxShowCount.coerceAtMost(commentsList.size) + for (i in 0 until length) { + val item = commentsList[i] + AndroidViewBinding(factory = ItemGalleryCommentBinding::inflate) { + card.setOnClickListener { onNavigateToCommentScene() } + user.text = item.user + user.setBackgroundColor(Color.TRANSPARENT) + time.text = ReadableTime.getTimeAgo(item.time) + comment.maxLines = 5 + comment.text = item.comment.orEmpty().parseAsHtml(imageGetter = CoilImageGetter(comment)) } } Box( diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/EhScreen.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/EhScreen.kt index eb02d4ba0..46b49219a 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/EhScreen.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/EhScreen.kt @@ -277,11 +277,22 @@ fun EhScreen() { summary = stringResource(id = R.string.settings_eh_show_gallery_pages_summary), value = Settings::showGalleryPages, ) + val showComments = Settings::showComments.observed SwitchPreference( title = stringResource(id = R.string.settings_eh_show_gallery_comments), summary = stringResource(id = R.string.settings_eh_show_gallery_comments_summary), - value = Settings::showComments, + value = showComments.rememberedAccessor, ) + AnimatedVisibility(visible = showComments.value) { + IntSliderPreference( + maxValue = 100, + minValue = -101, + showTicks = false, + title = stringResource(id = R.string.settings_eh_show_gallery_comment_threshold), + summary = stringResource(id = R.string.settings_eh_show_gallery_comment_threshold_summary), + value = Settings::commentThreshold, + ) + } if (EhTagDatabase.isTranslatable(context)) { SwitchPreference( title = stringResource(id = R.string.settings_eh_show_tag_translations), diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/PreferenceWidgets.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/PreferenceWidgets.kt index 40c226c53..707e36b87 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/PreferenceWidgets.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/PreferenceWidgets.kt @@ -95,10 +95,10 @@ fun SwitchPreference(title: String, summary: String? = null, value: KMutableProp } @Composable -fun IntSliderPreference(maxValue: Int, minValue: Int = 0, step: Int = maxValue - minValue - 1, title: String, summary: String? = null, value: KMutableProperty0, enabled: Boolean = true) { +fun IntSliderPreference(maxValue: Int, minValue: Int = 0, step: Int = maxValue - minValue - 1, showTicks: Boolean = true, title: String, summary: String? = null, value: KMutableProperty0, enabled: Boolean = true) { var v by remember { mutableIntStateOf(value.get()) } fun set(float: Float) = value.set(float.roundToInt().also { v = it }) - SliderPref(title = title, summary = summary, defaultValue = v.toFloat(), onValueChangeFinished = ::set, valueRange = minValue.toFloat()..maxValue.toFloat(), showValue = true, showInteger = true, steps = step, enabled = enabled) + SliderPref(title = title, summary = summary, defaultValue = v.toFloat(), onValueChangeFinished = ::set, valueRange = minValue.toFloat()..maxValue.toFloat(), showValue = true, showInteger = true, steps = step, showTicks = showTicks, enabled = enabled) } @Composable diff --git a/app/src/main/kotlin/com/jamal/composeprefs3/ui/prefs/SliderPref.kt b/app/src/main/kotlin/com/jamal/composeprefs3/ui/prefs/SliderPref.kt index d2a87b39d..45030e0db 100644 --- a/app/src/main/kotlin/com/jamal/composeprefs3/ui/prefs/SliderPref.kt +++ b/app/src/main/kotlin/com/jamal/composeprefs3/ui/prefs/SliderPref.kt @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Slider +import androidx.compose.material3.SliderDefaults import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -30,6 +31,7 @@ fun SliderPref( valueRange: ClosedFloatingPointRange = 0f..1f, showValue: Boolean = false, showInteger: Boolean = false, + showTicks: Boolean = true, steps: Int = 0, textColor: Color = MaterialTheme.colorScheme.onBackground, enabled: Boolean = true, @@ -61,6 +63,14 @@ fun SliderPref( steps = steps, onValueChangeFinished = { onValueChangeFinished?.invoke(value) }, enabled = enabled, + colors = if (showTicks) { + SliderDefaults.colors() + } else { + SliderDefaults.colors( + activeTickColor = Color.Transparent, + inactiveTickColor = Color.Transparent, + ) + }, ) if (showValue) { Text( diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index f87cf5439..2c91a1c95 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -335,6 +335,8 @@ 在画廊列表中显示页数 显示画廊评论 在画廊详情页中显示评论 + 评论分数阈值 + 隐藏低于或等于此分数的评论(-101 禁用) 显示标签翻译 显示翻译后的标签而非原始文字(需花费时间来下载数据文件) 补充翻译(由 EhTagTranslation 提供) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2998d520d..a8076c5aa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -376,6 +376,8 @@ Display the number of pages in the gallery list Show gallery comments Show comments on the gallery details page + Comment score threshold + Hide comments at or below this score (-101 disables) Show tag translations Show tag translations instead of the original text (It takes time to download the data file) Placeholder