Allow hiding comments below custom threshold

This commit is contained in:
FooIbar committed 2023-10-31 00:44:32 +08:00
1 parent aafa750ca3
commit fdbca869a8
8 files changed
+43 -18

No files matched your search

@@ -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() }
@@ -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
}
}
@@ -1015,9 +1015,9 @@ class GalleryDetailScene : BaseScene() {
@SuppressLint("InflateParams")
@Composable
private fun GalleryDetailComment(commentsList: Array<GalleryComment>?) {
private fun GalleryDetailComment(commentsList: Array<GalleryComment>) {
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(
@@ -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),
@@ -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<Int>, 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<Int>, 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
@@ -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<Float> = 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(
@@ -335,6 +335,8 @@
<string name="settings_eh_show_gallery_pages_summary">在画廊列表中显示页数</string>
<string name="settings_eh_show_gallery_comments">显示画廊评论</string>
<string name="settings_eh_show_gallery_comments_summary">在画廊详情页中显示评论</string>
<string name="settings_eh_show_gallery_comment_threshold">评论分数阈值</string>
<string name="settings_eh_show_gallery_comment_threshold_summary">隐藏低于或等于此分数的评论(-101 禁用)</string>
<string name="settings_eh_show_tag_translations">显示标签翻译</string>
<string name="settings_eh_show_tag_translations_summary">显示翻译后的标签而非原始文字(需花费时间来下载数据文件)</string>
<string name="settings_eh_tag_translations_source">补充翻译(由 EhTagTranslation 提供)</string>
+2
View File
@@ -376,6 +376,8 @@
<string name="settings_eh_show_gallery_pages_summary">Display the number of pages in the gallery list</string>
<string name="settings_eh_show_gallery_comments">Show gallery comments</string>
<string name="settings_eh_show_gallery_comments_summary">Show comments on the gallery details page</string>
<string name="settings_eh_show_gallery_comment_threshold">Comment score threshold</string>
<string name="settings_eh_show_gallery_comment_threshold_summary">Hide comments at or below this score (-101 disables)</string>
<string name="settings_eh_show_tag_translations">Show tag translations</string>
<string name="settings_eh_show_tag_translations_summary">Show tag translations instead of the original text (It takes time to download the data file)</string>
<string name="settings_eh_tag_translations_source">Placeholder</string>