feat: configurable comment indent amount (#839)

This commit is contained in:
Diego Beraldin 2024-05-12 13:41:36 +02:00 committed by GitHub
parent 7112c9f153
commit 236590c0f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
61 changed files with 201 additions and 142 deletions

View File

@ -24,7 +24,6 @@ internal class DefaultThemeRepository : ThemeRepository {
override val saveColor = MutableStateFlow<Color?>(null)
override val postLayout = MutableStateFlow<PostLayout>(PostLayout.Card)
override val commentBarTheme = MutableStateFlow<CommentBarTheme>(CommentBarTheme.Blue)
override val commentBarThickness = MutableStateFlow(1)
override fun changeUiTheme(value: UiTheme?) {
uiTheme.value = value
@ -129,8 +128,4 @@ internal class DefaultThemeRepository : ThemeRepository {
this += Color(0xFFFF0000)
}
}
override fun changeCommentBarThickness(value: Int) {
commentBarThickness.value = value
}
}

View File

@ -25,7 +25,6 @@ interface ThemeRepository {
val saveColor: StateFlow<Color?>
val postLayout: StateFlow<PostLayout>
val commentBarTheme: StateFlow<CommentBarTheme>
val commentBarThickness: StateFlow<Int>
fun changeUiTheme(value: UiTheme?)
@ -55,7 +54,6 @@ interface ThemeRepository {
fun changePostLayout(value: PostLayout)
fun changeCommentBarTheme(value: CommentBarTheme)
fun changeCommentBarThickness(value: Int)
fun getCommentBarColors(commentBarTheme: CommentBarTheme): List<Color>
}

View File

@ -40,8 +40,7 @@ import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.PostModel
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
private val barWidth = 1.25.dp
private const val INDENT_AMOUNT = 3
private val BAR_BASE_WIDTH_UNIT = 1.25.dp
private const val COMMENT_TEXT_SCALE_FACTOR = 0.97f
@Composable
@ -51,7 +50,8 @@ fun CommentCard(
voteFormat: VoteFormat = VoteFormat.Aggregated,
hideAuthor: Boolean = false,
hideCommunity: Boolean = true,
hideIndent: Boolean = false,
indentAmount: Int = 2,
barThickness: Int = 1,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
showScores: Boolean = true,
@ -77,11 +77,11 @@ fun CommentCard(
val themeRepository = remember { getThemeRepository() }
var commentHeight by remember { mutableStateOf(0f) }
val commentBarTheme by themeRepository.commentBarTheme.collectAsState()
val commentBarThickness by themeRepository.commentBarThickness.collectAsState()
val barColor = themeRepository.getCommentBarColor(
depth = comment.depth,
commentBarTheme = commentBarTheme,
)
val barWidth = BAR_BASE_WIDTH_UNIT * barThickness
Column(
modifier = modifier,
@ -91,12 +91,14 @@ fun CommentCard(
onClick = onClick ?: {},
onDoubleClick = onDoubleClick ?: {}
).padding(
start = if (hideIndent) 0.dp else (INDENT_AMOUNT * comment.depth).dp
start = indentAmount.takeIf { it > 0 }?.let {
(it * comment.depth).dp + Spacing.xxxs
} ?: 0.dp
),
) {
Column(
modifier = Modifier
.padding(start = barWidth)
.padding(start = barWidth + Spacing.xxs)
.fillMaxWidth()
.padding(
vertical = Spacing.xxs,
@ -176,14 +178,13 @@ fun CommentCard(
onOptionSelected = onOptionSelected,
)
}
if (!hideIndent && comment.depth > 0) {
val width = barWidth * commentBarThickness
if (indentAmount > 0 && comment.depth > 0) {
Box(
modifier = Modifier
.padding(top = Spacing.xxs)
.width(width)
.width(barWidth)
.height(commentHeight.toLocalDp())
.background(color = barColor, shape = RoundedCornerShape(width / 2))
.background(color = barColor, shape = RoundedCornerShape(barWidth / 2))
)
}
}

View File

@ -5,8 +5,8 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.sizeIn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowCircleDown
import androidx.compose.material.icons.filled.ArrowCircleUp
import androidx.compose.material.icons.filled.AddCircleOutline
import androidx.compose.material.icons.filled.RemoveCircleOutline
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
@ -33,7 +33,9 @@ fun SettingsIntValueRow(
verticalAlignment = Alignment.CenterVertically,
) {
Column(
modifier = Modifier.weight(1f),
modifier = Modifier
.weight(1f)
.padding(vertical = Spacing.s),
) {
Text(
text = title,
@ -52,7 +54,7 @@ fun SettingsIntValueRow(
verticalAlignment = Alignment.CenterVertically
) {
FeedbackButton(
imageVector = Icons.Default.ArrowCircleDown,
imageVector = Icons.Default.RemoveCircleOutline,
tintColor = MaterialTheme.colorScheme.secondary,
onClick = onDecrement,
)
@ -66,7 +68,7 @@ fun SettingsIntValueRow(
color = fullColor,
)
FeedbackButton(
imageVector = Icons.Default.ArrowCircleUp,
imageVector = Icons.Default.AddCircleOutline,
tintColor = MaterialTheme.colorScheme.secondary,
onClick = onIncrement,
)

View File

@ -1,82 +0,0 @@
package com.github.diegoberaldin.raccoonforlemmy.core.commonui.modals
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import cafe.adriel.voyager.core.screen.Screen
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.BottomSheetHeader
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
import com.github.diegoberaldin.raccoonforlemmy.core.navigation.di.getNavigationCoordinator
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenterEvent
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.di.getNotificationCenter
import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.onClick
class CommentBarThicknessBottomSheet(
private val values: List<Int> = listOf(
1,
2,
3,
),
) : Screen {
@Composable
override fun Content() {
val navigationCoordinator = remember { getNavigationCoordinator() }
val notificationCenter = remember { getNotificationCenter() }
Column(
modifier = Modifier
.windowInsetsPadding(WindowInsets.navigationBars)
.padding(
top = Spacing.s,
start = Spacing.s,
end = Spacing.s,
bottom = Spacing.m,
),
verticalArrangement = Arrangement.spacedBy(Spacing.s),
) {
BottomSheetHeader(LocalXmlStrings.current.settingsCommentBarThickness)
Column(
modifier = Modifier.fillMaxWidth().verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(Spacing.xxs),
) {
for (value in values) {
Row(
modifier = Modifier
.padding(
horizontal = Spacing.s,
vertical = Spacing.s,
)
.fillMaxWidth()
.onClick(
onClick = {
notificationCenter.send(
NotificationCenterEvent.ChangeCommentBarThickness(value)
)
navigationCoordinator.hideBottomSheet()
},
),
) {
Text(
text = value.toString(),
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onBackground,
)
}
}
}
}
}
}

View File

@ -17,6 +17,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import cafe.adriel.voyager.core.screen.Screen
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
@ -46,6 +47,7 @@ class SliderBottomSheet(
bottom = Spacing.m,
),
verticalArrangement = Arrangement.spacedBy(Spacing.s),
horizontalAlignment = Alignment.CenterHorizontally,
) {
BottomSheetHeader(LocalXmlStrings.current.settingsZombieModeScrollAmount)
var value by remember {

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">ناسب الحجم</string>
<string name="content_scale_fill_width">ملء العرض</string>
<string name="content_scale_fill_height">ملء الارتفاع</string>
<string name="settings_comment_indent_amount">عرض المسافة البادئة للتعليقات</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Съответства на размера</string>
<string name="content_scale_fill_width">Попълнете ширината</string>
<string name="content_scale_fill_height">Запълнете височината</string>
<string name="settings_comment_indent_amount">Ширина на отстъпа на коментарите</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Přizpůsobit velikost</string>
<string name="content_scale_fill_width">Vyplňte šířku</string>
<string name="content_scale_fill_height">Vyplňte výšku</string>
<string name="settings_comment_indent_amount">Šířka odsazení komentářů</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Tilpas størrelsen</string>
<string name="content_scale_fill_width">Fyld bredden</string>
<string name="content_scale_fill_height">Fyld højden</string>
<string name="settings_comment_indent_amount">Bredde på indrykning af kommentarer</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Passen Sie die Größe an</string>
<string name="content_scale_fill_width">Füllen Sie die Breite</string>
<string name="content_scale_fill_height">Füllen Sie die Höhe aus</string>
<string name="settings_comment_indent_amount">Breite der Einrückung von Kommentaren</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Ταιριάζει στο μέγεθος</string>
<string name="content_scale_fill_width">Γεμίστε το πλάτος</string>
<string name="content_scale_fill_height">Συμπληρώστε το ύψος</string>
<string name="settings_comment_indent_amount">Πλάτος εσοχής σχολίων</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Konveni la grandecon</string>
<string name="content_scale_fill_width">Plenigi la larĝon</string>
<string name="content_scale_fill_height">Plenigi la altecon</string>
<string name="settings_comment_indent_amount">Larĝeco de indentaĵo de komentoj</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Ajustar el tamaño</string>
<string name="content_scale_fill_width">Llenar el ancho</string>
<string name="content_scale_fill_height">Llenar la altura</string>
<string name="settings_comment_indent_amount">Ancho de indentación de los comentarios</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Sobivad suurusele</string>
<string name="content_scale_fill_width">Täida laius</string>
<string name="content_scale_fill_height">Täida kõrgus</string>
<string name="settings_comment_indent_amount">Kommentaaride taande laius</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Sopiva kokoon</string>
<string name="content_scale_fill_width">Täytä leveys</string>
<string name="content_scale_fill_height">Täytä korkeus</string>
<string name="settings_comment_indent_amount">Kommenttien sisennyksen leveys</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Ajuster la taille</string>
<string name="content_scale_fill_width">Remplissez la largeur</string>
<string name="content_scale_fill_height">Remplissez la hauteur</string>
<string name="settings_comment_indent_amount">Largeur d\'indentation des commentaires</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Fit an méid</string>
<string name="content_scale_fill_width">Líon isteach an leithead</string>
<string name="content_scale_fill_height">Líon an airde</string>
<string name="settings_comment_indent_amount">Leithead eangú na dtuairimí</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Odgovara veličini</string>
<string name="content_scale_fill_width">Ispunite širinu</string>
<string name="content_scale_fill_height">Ispunite visinu</string>
<string name="settings_comment_indent_amount">Širina uvlačenja komentara</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Illessze a méretet</string>
<string name="content_scale_fill_width">Töltse ki a szélességet</string>
<string name="content_scale_fill_height">Töltse ki a magasságot</string>
<string name="settings_comment_indent_amount">A megjegyzések behúzásának szélessége</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Adatta alla dimensione</string>
<string name="content_scale_fill_width">Adatta alla larghezza</string>
<string name="content_scale_fill_height">Adatta alla altezza</string>
<string name="settings_comment_indent_amount">Larghezza rientro dei commenti</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Atitinka dydį</string>
<string name="content_scale_fill_width">Užpildykite plotį</string>
<string name="content_scale_fill_height">Užpildykite aukštį</string>
<string name="settings_comment_indent_amount">Komentarų įtraukos plotis</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Atbilst izmēram</string>
<string name="content_scale_fill_width">Aizpildiet platumu</string>
<string name="content_scale_fill_height">Aizpildiet augstumu</string>
<string name="settings_comment_indent_amount">Komentāru atkāpes platums</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Waħħal id-daqs</string>
<string name="content_scale_fill_width">Imla l-wisa</string>
<string name="content_scale_fill_height">Imla l-għoli</string>
<string name="settings_comment_indent_amount">Wisa\' ta\' indentazzjoni tal-kummenti</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Pas de maat aan</string>
<string name="content_scale_fill_width">Vul de breedte</string>
<string name="content_scale_fill_height">Vul de hoogte</string>
<string name="settings_comment_indent_amount">Breedte van de inspringing van opmerkingen</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Passer størrelsen</string>
<string name="content_scale_fill_width">Fyll bredden</string>
<string name="content_scale_fill_height">Fyll høyden</string>
<string name="settings_comment_indent_amount">Bredde på innrykk av kommentarer</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Dopasuj rozmiar</string>
<string name="content_scale_fill_width">Wypełnij szerokość</string>
<string name="content_scale_fill_height">Wypełnij wysokość</string>
<string name="settings_comment_indent_amount">Szerokość wcięcia komentarzy</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Ajuste o tamanho</string>
<string name="content_scale_fill_width">Preencha a largura</string>
<string name="content_scale_fill_height">Preencha a altura</string>
<string name="settings_comment_indent_amount">Largura de recuo dos comentários</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Ajuste o tamanho</string>
<string name="content_scale_fill_width">Preencha a largura</string>
<string name="content_scale_fill_height">Preencha a altura</string>
<string name="settings_comment_indent_amount">Largura de recuo dos comentários</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Se potrivește mărimii</string>
<string name="content_scale_fill_width">Umpleți lățimea</string>
<string name="content_scale_fill_height">Umpleți înălțimea</string>
<string name="settings_comment_indent_amount">Lățimea indentării comentariilor</string>
</resources>

View File

@ -392,4 +392,5 @@
<string name="content_scale_fit">Подогнать размер</string>
<string name="content_scale_fill_width">Заполните ширину</string>
<string name="content_scale_fill_height">Заполните высоту</string>
<string name="settings_comment_indent_amount">Ширина отступа комментариев</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Passa storleken</string>
<string name="content_scale_fill_width">Fyll bredden</string>
<string name="content_scale_fill_height">Fyll höjden</string>
<string name="settings_comment_indent_amount">Bredd på indrag av kommentarer</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Prispôsobte sa veľkosti</string>
<string name="content_scale_fill_width">Vyplňte šírku</string>
<string name="content_scale_fill_height">Vyplňte výšku</string>
<string name="settings_comment_indent_amount">Šírka odsadenia komentárov</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Prilagodite velikost</string>
<string name="content_scale_fill_width">Izpolnite širino</string>
<string name="content_scale_fill_height">Izpolnite višino</string>
<string name="settings_comment_indent_amount">Širina zamika komentarjev</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Përshtatet me madhësinë</string>
<string name="content_scale_fill_width">Mbushni gjerësinë</string>
<string name="content_scale_fill_height">Mbushni lartësinë</string>
<string name="settings_comment_indent_amount">Gjerësia e dhëmbëzimit të komenteve</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Прилагодите величину</string>
<string name="content_scale_fill_width">Попуните ширину</string>
<string name="content_scale_fill_height">Попуните висину</string>
<string name="settings_comment_indent_amount">Ширина увлачења коментара</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">suli tu</string>
<string name="content_scale_fill_width">suli poka</string>
<string name="content_scale_fill_height">suli sewi</string>
<string name="settings_comment_indent_amount">suli poka pi toki lili</string>
</resources>

View File

@ -393,4 +393,5 @@
<string name="content_scale_fit">Boyutu sığdır</string>
<string name="content_scale_fill_width">Genişliği doldurun</string>
<string name="content_scale_fill_height">Yüksekliği doldurun</string>
<string name="settings_comment_indent_amount">Yorum girintisinin genişliği</string>
</resources>

View File

@ -392,4 +392,5 @@
<string name="content_scale_fit">Підходить за розміром</string>
<string name="content_scale_fill_width">Заповнити ширину</string>
<string name="content_scale_fill_height">Заповнити висоту</string>
<string name="settings_comment_indent_amount">Ширина відступу коментарів</string>
</resources>

View File

@ -401,4 +401,5 @@
<string name="content_scale_fit">Aspect fit</string>
<string name="content_scale_fill_width">Fill width</string>
<string name="content_scale_fill_height">Fill height</string>
<string name="settings_comment_indent_amount">Comment indentation amount</string>
</resources>

View File

@ -66,7 +66,6 @@ sealed interface NotificationCenterEvent {
data class UserBannedPost(val postId: Long, val user: UserModel) : NotificationCenterEvent
data class UserBannedComment(val commentId: Long, val user: UserModel) : NotificationCenterEvent
data class ChangeCommentBarTheme(val value: CommentBarTheme) : NotificationCenterEvent
data class ChangeCommentBarThickness(val value: Int) : NotificationCenterEvent
data class BlockActionSelected(
val userId: Long? = null,
val communityId: Long? = null,

View File

@ -61,4 +61,5 @@ data class SettingsModel(
val fadeReadPosts: Boolean = false,
val showUnreadComments: Boolean = false,
val enableButtonsToScrollBetweenComments: Boolean = false,
val commentIndentAmount: Int = 2,
)

View File

@ -63,6 +63,7 @@ private object KeyStoreKeys {
const val FADE_READ_POSTS = "fadeReadPosts"
const val ENABLE_BUTTONS_TO_SCROLL_BETWEEN_COMMENTS = "enableButtonsToScrollBetweenComments"
const val FULL_WIDTH_IMAGES = "fullWidthImages"
const val COMMENT_INDENT_AMOUNT = "commentIndentAmount"
}
internal class DefaultSettingsRepository(
@ -133,6 +134,7 @@ internal class DefaultSettingsRepository(
showScores = if (settings.showScores) 1L else 0L,
preferUserNicknames = if (settings.preferUserNicknames) 1L else 0L,
commentBarThickness = settings.commentBarThickness.toLong(),
commentIndentAmount = settings.commentIndentAmount.toLong(),
imageSourcePath = if (settings.imageSourcePath) 1L else 0L,
defaultExploreType = settings.defaultExploreType.toLong(),
defaultLanguageId = settings.defaultLanguageId,
@ -200,6 +202,7 @@ internal class DefaultSettingsRepository(
showScores = keyStore[KeyStoreKeys.SHOW_SCORES, true],
preferUserNicknames = keyStore[KeyStoreKeys.PREFER_USER_NICKNAMES, true],
commentBarThickness = keyStore[KeyStoreKeys.COMMENT_BAR_THICKNESS, 1],
commentIndentAmount = keyStore[KeyStoreKeys.COMMENT_INDENT_AMOUNT, 2],
imageSourcePath = keyStore[KeyStoreKeys.IMAGE_SOURCE_PATH, false],
defaultLanguageId = if (keyStore.containsKey(KeyStoreKeys.DEFAULT_LANGUAGE_ID)) {
keyStore[KeyStoreKeys.DEFAULT_LANGUAGE_ID, 0L]
@ -308,6 +311,7 @@ internal class DefaultSettingsRepository(
keyStore.save(KeyStoreKeys.SHOW_SCORES, settings.showScores)
keyStore.save(KeyStoreKeys.PREFER_USER_NICKNAMES, settings.preferUserNicknames)
keyStore.save(KeyStoreKeys.COMMENT_BAR_THICKNESS, settings.commentBarThickness)
keyStore.save(KeyStoreKeys.COMMENT_INDENT_AMOUNT, settings.commentIndentAmount)
keyStore.save(KeyStoreKeys.IMAGE_SOURCE_PATH, settings.imageSourcePath)
if (settings.defaultLanguageId != null) {
keyStore.save(KeyStoreKeys.DEFAULT_LANGUAGE_ID, settings.defaultLanguageId)
@ -378,6 +382,7 @@ internal class DefaultSettingsRepository(
showScores = if (settings.showScores) 1L else 0L,
preferUserNicknames = if (settings.preferUserNicknames) 1L else 0L,
commentBarThickness = settings.commentBarThickness.toLong(),
commentIndentAmount = settings.commentIndentAmount.toLong(),
imageSourcePath = if (settings.imageSourcePath) 1L else 0L,
defaultExploreType = settings.defaultExploreType.toLong(),
defaultLanguageId = settings.defaultLanguageId,
@ -460,6 +465,7 @@ private fun GetBy.toModel() = SettingsModel(
showScores = showScores == 1L,
preferUserNicknames = preferUserNicknames == 1L,
commentBarThickness = commentBarThickness.toInt(),
commentIndentAmount = commentIndentAmount.toInt(),
imageSourcePath = imageSourcePath == 1L,
defaultExploreType = defaultExploreType.toInt(),
defaultLanguageId = defaultLanguageId,

View File

@ -65,6 +65,7 @@ internal data class SerializableSettings(
val showScores: Boolean = true,
val preferUserNicknames: Boolean = true,
val commentBarThickness: Int = 1,
val commentIndentAmount: Int = 2,
val imageSourcePath: Boolean = false,
val defaultLanguageId: Long? = null,
val inboxBackgroundCheckPeriod: Duration? = null,
@ -127,6 +128,7 @@ internal fun SerializableSettings.toModel() = SettingsModel(
showScores = showScores,
preferUserNicknames = preferUserNicknames,
commentBarThickness = commentBarThickness,
commentIndentAmount = commentIndentAmount,
imageSourcePath = imageSourcePath,
defaultLanguageId = defaultLanguageId,
inboxBackgroundCheckPeriod = inboxBackgroundCheckPeriod,
@ -184,6 +186,7 @@ internal fun SettingsModel.toData() = SerializableSettings(
showScores = showScores,
preferUserNicknames = preferUserNicknames,
commentBarThickness = commentBarThickness,
commentIndentAmount= commentIndentAmount,
imageSourcePath = imageSourcePath,
defaultLanguageId = defaultLanguageId,
inboxBackgroundCheckPeriod = inboxBackgroundCheckPeriod,

View File

@ -49,7 +49,7 @@ CREATE TABLE SettingsEntity (
opaqueSystemBars INTEGER DEFAULT NULL,
showScores INTEGER NOT NULL DEFAULT 1,
preferUserNicknames INTEGER NOT NULL DEFAULT 1,
commentBarThickness INTEGER NOT NULL DEFAULT 0,
commentBarThickness INTEGER NOT NULL DEFAULT 1,
imageSourcePath INTEGER NOT NULL DEFAULT 0,
defaultExploreType INTEGER NOT NULL DEFAULT 2,
defaultLanguageId INTEGER DEFAULT NULL,
@ -58,6 +58,7 @@ CREATE TABLE SettingsEntity (
showUnreadComments INTEGER NOT NULL DEFAULT 0,
enableButtonsToScrollBetweenComments INTEGER NOT NULL DEFAULT 0,
fullWidthImages INTEGER NOT NULL DEFAULT 0,
commentIndentAmount INTEGER NOT NULL DEFAULT 2,
FOREIGN KEY (account_id) REFERENCES AccountEntity(id) ON DELETE CASCADE,
UNIQUE(account_id)
);
@ -121,6 +122,7 @@ INSERT OR IGNORE INTO SettingsEntity (
showUnreadComments,
enableButtonsToScrollBetweenComments,
fullWidthImages,
commentIndentAmount,
account_id
) VALUES (
?,
@ -180,6 +182,7 @@ INSERT OR IGNORE INTO SettingsEntity (
?,
?,
?,
?,
?
);
@ -241,7 +244,8 @@ SET theme = ?,
fadeReadPosts = ?,
showUnreadComments = ?,
enableButtonsToScrollBetweenComments = ?,
fullWidthImages = ?
fullWidthImages = ?,
commentIndentAmount = ?
WHERE account_id = ?;
getBy:
@ -303,6 +307,7 @@ SELECT
fadeReadPosts,
showUnreadComments,
enableButtonsToScrollBetweenComments,
fullWidthImages
fullWidthImages,
commentIndentAmount
FROM SettingsEntity
WHERE account_id = ?;

View File

@ -1,2 +1,2 @@
ALTER TABLE SettingsEntity
ADD COLUMN commentBarTheme INTEGER NOT NULL DEFAULT 0;
ADD COLUMN commentBarTheme INTEGER NOT NULL DEFAULT 1;

View File

@ -0,0 +1,2 @@
ALTER TABLE SettingsEntity
ADD COLUMN commentIndentAmount INTEGER NOT NULL DEFAULT 2;

View File

@ -124,7 +124,6 @@ fun App(onLoadingFinished: () -> Unit = {}) {
changeUiFontFamily(currentSettings.uiFontFamily.toUiFontFamily())
changeContentFontFamily(currentSettings.contentFontFamily.toUiFontFamily())
changeCommentBarTheme(currentSettings.commentBarTheme.toCommentBarTheme())
changeCommentBarThickness(currentSettings.commentBarThickness)
with(themeRepository) {
changeUpVoteColor(currentSettings.upVoteColor?.let { Color(it) })

View File

@ -16,12 +16,17 @@ interface ConfigureContentViewMviModel :
data class ChangePreferUserNicknames(val value: Boolean) : Intent
data class ChangeFullHeightImages(val value: Boolean) : Intent
data class ChangeFullWidthImages(val value: Boolean) : Intent
data object IncrementCommentBarThickness : Intent
data object DecrementCommentBarThickness : Intent
data object IncrementCommentIndentAmount : Intent
data object DecrementCommentIndentAmount : Intent
}
data class State(
val postLayout: PostLayout = PostLayout.Card,
val commentBarTheme: CommentBarTheme = CommentBarTheme.Blue,
val commentBarThickness: Int = 1,
val commentIndentAmount: Int = 2,
val contentFontScale: ContentFontScales = ContentFontScales(),
val contentFontFamily: UiFontFamily = UiFontFamily.Poppins,
val voteFormat: VoteFormat = VoteFormat.Aggregated,

View File

@ -39,9 +39,9 @@ import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.toReadableN
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.repository.ContentFontClass
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsHeader
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsIntValueRow
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsRow
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.lemmyui.SettingsSwitchRow
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.modals.CommentBarThicknessBottomSheet
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.modals.PostBodyMaxLinesBottomSheet
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.modals.PostLayoutBottomSheet
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.modals.VoteFormatBottomSheet
@ -230,13 +230,27 @@ class ConfigureContentViewScreen : Screen {
)
// comment bar thickness
SettingsRow(
SettingsIntValueRow(
title = LocalXmlStrings.current.settingsCommentBarThickness,
value = uiState.commentBarThickness.toString(),
onTap = rememberCallback {
val screen = CommentBarThicknessBottomSheet()
navigationCoordinator.showBottomSheet(screen)
}
value = uiState.commentBarThickness,
onIncrement = rememberCallback(model) {
model.reduce(ConfigureContentViewMviModel.Intent.IncrementCommentBarThickness)
},
onDecrement = rememberCallback(model) {
model.reduce(ConfigureContentViewMviModel.Intent.DecrementCommentBarThickness)
},
)
// comment indent amount
SettingsIntValueRow(
title = LocalXmlStrings.current.settingsCommentIndentAmount,
value = uiState.commentIndentAmount,
onIncrement = rememberCallback(model) {
model.reduce(ConfigureContentViewMviModel.Intent.IncrementCommentIndentAmount)
},
onDecrement = rememberCallback(model) {
model.reduce(ConfigureContentViewMviModel.Intent.DecrementCommentIndentAmount)
},
)
SettingsHeader(
@ -245,13 +259,17 @@ class ConfigureContentViewScreen : Screen {
)
// preview
ContentPreview(
modifier = Modifier.padding(top = Spacing.xxs),
postLayout = uiState.postLayout,
preferNicknames = uiState.preferUserNicknames,
showScores = uiState.voteFormat != VoteFormat.Hidden,
voteFormat = uiState.voteFormat,
fullHeightImage = uiState.fullHeightImages,
fullWidthImage = uiState.fullWidthImages,
)
commentBarThickness = uiState.commentBarThickness,
commentIndentAmount = uiState.commentIndentAmount,
)
Spacer(modifier = Modifier.height(Spacing.xxxl))
}

View File

@ -19,6 +19,9 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
private val COMMENT_BAR_THICKNESS_RANGE = 1..5
private val COMMENT_INDENT_AMOUNT_RANGE = 1..20
class ConfigureContentViewViewModel(
private val themeRepository: ThemeRepository,
private val settingsRepository: SettingsRepository,
@ -40,9 +43,6 @@ class ConfigureContentViewViewModel(
themeRepository.contentFontFamily.onEach { value ->
updateState { it.copy(contentFontFamily = value) }
}.launchIn(this)
themeRepository.commentBarThickness.onEach { value ->
updateState { it.copy(commentBarThickness = value) }
}.launchIn(this)
notificationCenter.subscribe(NotificationCenterEvent.ChangePostLayout::class)
.onEach { evt ->
@ -64,10 +64,6 @@ class ConfigureContentViewViewModel(
.onEach { evt ->
changeContentFontFamily(evt.value)
}.launchIn(this)
notificationCenter.subscribe(NotificationCenterEvent.ChangeCommentBarThickness::class)
.onEach { evt ->
changeCommentBarThickness(evt.value)
}.launchIn(this)
val settings = settingsRepository.currentSettings.value
updateState {
@ -77,6 +73,8 @@ class ConfigureContentViewViewModel(
fullWidthImages = settings.fullWidthImages,
postBodyMaxLines = settings.postBodyMaxLines,
preferUserNicknames = settings.preferUserNicknames,
commentBarThickness = settings.commentBarThickness,
commentIndentAmount = settings.commentIndentAmount,
)
}
}
@ -84,17 +82,43 @@ class ConfigureContentViewViewModel(
override fun reduce(intent: ConfigureContentViewMviModel.Intent) {
when (intent) {
is ConfigureContentViewMviModel.Intent.ChangeFullHeightImages -> changeFullHeightImages(
intent.value,
)
is ConfigureContentViewMviModel.Intent.ChangeFullHeightImages -> {
changeFullHeightImages(
intent.value,
)
}
is ConfigureContentViewMviModel.Intent.ChangeFullWidthImages -> changeFullWidthImages(
intent.value,
)
is ConfigureContentViewMviModel.Intent.ChangeFullWidthImages -> {
changeFullWidthImages(
intent.value,
)
}
is ConfigureContentViewMviModel.Intent.ChangePreferUserNicknames -> changePreferUserNicknames(
intent.value,
)
is ConfigureContentViewMviModel.Intent.ChangePreferUserNicknames -> {
changePreferUserNicknames(
intent.value,
)
}
ConfigureContentViewMviModel.Intent.IncrementCommentBarThickness -> {
val value = (uiState.value.commentBarThickness + 1).coerceIn(COMMENT_BAR_THICKNESS_RANGE)
changeCommentBarThickness(value)
}
ConfigureContentViewMviModel.Intent.DecrementCommentBarThickness -> {
val value = (uiState.value.commentBarThickness - 1).coerceIn(COMMENT_BAR_THICKNESS_RANGE)
changeCommentBarThickness(value)
}
ConfigureContentViewMviModel.Intent.IncrementCommentIndentAmount -> {
val value = (uiState.value.commentIndentAmount + 1).coerceIn(COMMENT_INDENT_AMOUNT_RANGE)
changeCommentIndentAmount(value)
}
ConfigureContentViewMviModel.Intent.DecrementCommentIndentAmount -> {
val value = (uiState.value.commentIndentAmount - 1).coerceIn(COMMENT_INDENT_AMOUNT_RANGE)
changeCommentIndentAmount(value)
}
}
}
@ -193,7 +217,7 @@ class ConfigureContentViewViewModel(
}
private fun changeCommentBarThickness(value: Int) {
themeRepository.changeCommentBarThickness(value)
updateState { it.copy(commentBarThickness = value) }
screenModelScope.launch(Dispatchers.IO) {
val settings = settingsRepository.currentSettings.value.copy(
commentBarThickness = value,
@ -202,6 +226,16 @@ class ConfigureContentViewViewModel(
}
}
private fun changeCommentIndentAmount(value: Int) {
updateState { it.copy(commentIndentAmount = value) }
screenModelScope.launch(Dispatchers.IO) {
val settings = settingsRepository.currentSettings.value.copy(
commentIndentAmount = value,
)
saveSettings(settings)
}
}
private suspend fun saveSettings(settings: SettingsModel) {
val accountId = accountRepository.getActive()?.id
settingsRepository.updateSettings(settings, accountId)

View File

@ -27,6 +27,8 @@ internal fun ContentPreview(
voteFormat: VoteFormat,
fullHeightImage: Boolean,
fullWidthImage : Boolean,
commentBarThickness: Int,
commentIndentAmount: Int,
) {
Column {
PostCard(
@ -53,6 +55,7 @@ internal fun ContentPreview(
voteFormat = voteFormat,
preferNicknames = preferNicknames,
showScores = showScores,
indentAmount = commentIndentAmount,
)
HorizontalDivider(
modifier = Modifier.padding(vertical = Spacing.xxxs),
@ -64,6 +67,20 @@ internal fun ContentPreview(
voteFormat = voteFormat,
preferNicknames = preferNicknames,
showScores = showScores,
barThickness = commentBarThickness,
indentAmount = commentIndentAmount,
)
HorizontalDivider(
modifier = Modifier.padding(vertical = Spacing.xxxs),
thickness = 0.25.dp
)
CommentCard(
comment = ContentPreviewData.comment3,
voteFormat = voteFormat,
preferNicknames = preferNicknames,
showScores = showScores,
barThickness = commentBarThickness,
indentAmount = commentIndentAmount,
)
}
}
@ -111,7 +128,7 @@ velit esse cillum dolore eu fugiat nulla pariatur.
upvotes = 2,
downvotes = 1,
score = 1,
comments = 1,
comments = 2,
)
val comment2 = CommentModel(
@ -128,4 +145,18 @@ velit esse cillum dolore eu fugiat nulla pariatur.
score = 1,
comments = 1,
)
val comment3 = CommentModel(
text = "Praesent sed congue leo, at hendrerit lorem.",
publishDate = "2024-01-03T12:00:00Z",
path = "0.1.2.3",
creator = UserModel(
name = "marysmith",
host = "example.com",
displayName = "Mary Smith",
),
upvotes = 1,
downvotes = -2,
score = -1,
comments = 0,
)
}

View File

@ -248,7 +248,7 @@ class CreateCommentScreen(
modifier = referenceModifier,
comment = originalComment,
preferNicknames = uiState.preferNicknames,
hideIndent = true,
indentAmount = 0,
voteFormat = uiState.voteFormat,
autoLoadImages = uiState.autoLoadImages,
showScores = uiState.showScores,

View File

@ -639,7 +639,7 @@ class ExploreScreen(
showScores = uiState.showScores,
showBot = true,
showExpandedIndicator = false,
hideIndent = true,
indentAmount = 0,
actionButtonsActive = uiState.isLogged,
onClick = {
detailOpener.openPostDetail(

View File

@ -91,7 +91,7 @@ fun ModdedCommentCard(
preferNicknames = preferNicknames,
showExpandedIndicator = false,
showBot = true,
hideIndent = true,
indentAmount = 0,
onClick = onOpen,
onOpenCreator = onOpenUser,
onUpVote = onUpVote,

View File

@ -397,7 +397,7 @@ object ProfileLoggedScreen : Tab {
showScores = uiState.showScores,
hideCommunity = false,
hideAuthor = true,
hideIndent = true,
indentAmount = 0,
onImageClick = rememberCallbackArgs { url ->
navigationCoordinator.pushScreen(
ZoomableImageScreen(

View File

@ -56,6 +56,8 @@ interface PostDetailMviModel :
val canFetchMore: Boolean = true,
val sortType: SortType = SortType.New,
val comments: List<CommentModel> = emptyList(),
val commentBarThickness: Int = 1,
val commentIndentAmount: Int = 2,
val currentUserId: Long? = null,
val swipeActionsEnabled: Boolean = true,
val doubleTapActionEnabled: Boolean = true,

View File

@ -986,6 +986,8 @@ class PostDetailScreen(
comment = comment,
isOp = comment.creator?.id == uiState.post.creator?.id,
showBot = true,
indentAmount = uiState.commentIndentAmount,
barThickness = uiState.commentBarThickness,
voteFormat = uiState.voteFormat,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,

View File

@ -110,6 +110,8 @@ class PostDetailViewModel(
actionsOnSwipeToEndComments = settings.actionsOnSwipeToEndComments,
showScores = settings.showScores,
enableButtonsToScrollBetweenComments = settings.enableButtonsToScrollBetweenComments,
commentBarThickness = settings.commentBarThickness,
commentIndentAmount = settings.commentIndentAmount,
)
}
}.launchIn(this)

View File

@ -384,7 +384,7 @@ class SavedItemsScreen : Screen {
preferNicknames = uiState.preferNicknames,
showScores = uiState.showScores,
showBot = true,
hideIndent = true,
indentAmount = 0,
onClick = {
detailOpener.openPostDetail(
post = PostModel(id = comment.postId),

View File

@ -910,7 +910,7 @@ class UserDetailScreen(
showScores = uiState.showScores,
hideCommunity = false,
hideAuthor = true,
hideIndent = true,
indentAmount = 0,
actionButtonsActive = uiState.isLogged,
onClick = {
detailOpener.openPostDetail(