feat: configure comment bar width; prefer nicknames (#511)

This commit is contained in:
Diego Beraldin 2024-02-07 22:59:26 +01:00 committed by GitHub
parent cc81885754
commit 1557f29ece
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
108 changed files with 425 additions and 69 deletions

View File

@ -24,6 +24,7 @@ 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
@ -66,11 +67,11 @@ internal class DefaultThemeRepository : ThemeRepository {
customSeedColor.value = color
}
override fun changeUpvoteColor(color: Color?) {
override fun changeUpVoteColor(color: Color?) {
upVoteColor.value = color
}
override fun changeDownvoteColor(color: Color?) {
override fun changeDownVoteColor(color: Color?) {
downVoteColor.value = color
}
@ -128,4 +129,8 @@ internal class DefaultThemeRepository : ThemeRepository {
this += Color(0xFFFF0000)
}
}
override fun changeCommentBarThickness(value: Int) {
commentBarThickness.value = value
}
}

View File

@ -25,6 +25,7 @@ interface ThemeRepository {
val saveColor: StateFlow<Color?>
val postLayout: StateFlow<PostLayout>
val commentBarTheme: StateFlow<CommentBarTheme>
val commentBarThickness: StateFlow<Int>
fun changeUiTheme(value: UiTheme?)
@ -44,9 +45,9 @@ interface ThemeRepository {
fun changeCustomSeedColor(color: Color?)
fun changeUpvoteColor(color: Color?)
fun changeUpVoteColor(color: Color?)
fun changeDownvoteColor(color: Color?)
fun changeDownVoteColor(color: Color?)
fun changeReplyColor(color: Color?)
fun changeSaveColor(color: Color?)
@ -54,6 +55,7 @@ interface ThemeRepository {
fun changePostLayout(value: PostLayout)
fun changeCommentBarTheme(value: CommentBarTheme)
fun changeCommentBarThickness(value: Int)
fun getCommentBarColors(commentBarTheme: CommentBarTheme): List<Color>
}

View File

@ -34,6 +34,7 @@ fun CollapsedCommentCard(
modifier: Modifier = Modifier,
voteFormat: VoteFormat = VoteFormat.Aggregated,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
showScores: Boolean = true,
actionButtonsActive: Boolean = true,
isOp: Boolean = false,
@ -83,6 +84,7 @@ fun CollapsedCommentCard(
distinguished = comment.distinguished,
isOp = isOp,
autoLoadImages = autoLoadImages,
preferNicknames = preferNicknames,
onToggleExpanded = {
onToggleExpanded?.invoke()
},

View File

@ -50,6 +50,7 @@ fun CommentCard(
hideCommunity: Boolean = true,
hideIndent: Boolean = false,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
showScores: Boolean = true,
actionButtonsActive: Boolean = true,
isOp: Boolean = false,
@ -71,6 +72,7 @@ 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,
@ -103,6 +105,7 @@ fun CommentCard(
modifier = Modifier.padding(top = Spacing.xxs),
iconSize = IconSize.s,
autoLoadImages = autoLoadImages,
preferNicknames = preferNicknames,
creator = comment.creator.takeIf { !hideAuthor },
community = comment.community.takeIf { !hideCommunity },
indicatorExpanded = comment.expanded,
@ -170,7 +173,7 @@ fun CommentCard(
Box(
modifier = Modifier
.padding(top = Spacing.xxs)
.width(barWidth)
.width(barWidth * commentBarThickness)
.height(commentHeight.toLocalDp())
.background(color = barColor)
)

View File

@ -51,6 +51,7 @@ fun CommunityAndCreatorInfo(
iconSize: Dp = IconSize.l,
indicatorExpanded: Boolean? = null,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
community: CommunityModel? = null,
creator: UserModel? = null,
distinguished: Boolean = false,
@ -65,9 +66,9 @@ fun CommunityAndCreatorInfo(
onDoubleClick: (() -> Unit)? = null,
onLongClick: (() -> Unit)? = null,
) {
val communityName = community?.readableName.orEmpty()
val communityName = community?.readableName(preferNicknames).orEmpty()
val communityIcon = community?.icon.orEmpty()
val creatorName = creator?.readableName.orEmpty()
val creatorName = creator?.readableName(preferNicknames).orEmpty()
val creatorAvatar = creator?.avatar.orEmpty()
val fullColor = MaterialTheme.colorScheme.onBackground
val ancillaryColor = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.75f)

View File

@ -35,8 +35,8 @@ import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.onClick
import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.rememberCallback
import com.github.diegoberaldin.raccoonforlemmy.core.utils.getPrettyNumber
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.readableHandle
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.readableName
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.readableSimpleName
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
import dev.icerock.moko.resources.compose.stringResource
@ -45,6 +45,7 @@ fun CommunityHeader(
community: CommunityModel,
modifier: Modifier = Modifier,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
onOpenImage: ((String) -> Unit)? = null,
) {
Box(
@ -104,7 +105,7 @@ fun CommunityHeader(
} else {
PlaceholderImage(
size = IconSize.xxl,
title = community.readableName,
title = community.readableName(preferNicknames),
)
}
@ -113,13 +114,13 @@ fun CommunityHeader(
verticalArrangement = Arrangement.spacedBy(Spacing.s),
) {
Text(
text = community.readableName,
text = community.readableName(preferNicknames),
style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.onBackground,
)
if (community.readableSimpleName != community.readableName) {
if (community.readableHandle != community.readableName(preferNicknames)) {
Text(
text = community.readableSimpleName,
text = community.readableHandle,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.titleSmall,

View File

@ -41,8 +41,8 @@ import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.rememberCallb
import com.github.diegoberaldin.raccoonforlemmy.core.utils.toLocalDp
import com.github.diegoberaldin.raccoonforlemmy.core.utils.toLocalPixel
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.readableHandle
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.readableName
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.readableSimpleName
@Composable
fun CommunityItem(
@ -50,13 +50,14 @@ fun CommunityItem(
modifier: Modifier = Modifier,
small: Boolean = false,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
showSubscribers: Boolean = false,
showFavorite: Boolean = false,
options: List<Option> = emptyList(),
onOptionSelected: ((OptionId) -> Unit)? = null,
) {
val title = community.readableName
val communityName = community.readableSimpleName
val title = community.readableName(true)
val communityName = community.readableHandle
val communityIcon = community.icon.orEmpty()
val iconSize = if (small) IconSize.m else IconSize.l
val fullColor = MaterialTheme.colorScheme.onBackground
@ -81,7 +82,7 @@ fun CommunityItem(
} else {
PlaceholderImage(
size = iconSize,
title = community.name,
title = community.readableName(preferNicknames),
)
}

View File

@ -40,6 +40,7 @@ fun InboxCard(
mention: PersonMentionModel,
type: InboxCardType,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
showScores: Boolean = true,
voteFormat: VoteFormat = VoteFormat.Aggregated,
postLayout: PostLayout = PostLayout.Card,
@ -110,6 +111,7 @@ fun InboxCard(
creator = mention.creator,
community = mention.community,
autoLoadImages = autoLoadImages,
preferNicknames = preferNicknames,
date = mention.publishDate,
score = mention.score,
showScores = showScores,

View File

@ -54,6 +54,7 @@ import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.readableName
fun InboxReplySubtitle(
modifier: Modifier = Modifier,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
creator: UserModel? = null,
community: CommunityModel? = null,
iconSize: Dp = IconSize.s,
@ -85,9 +86,9 @@ fun InboxReplySubtitle(
Column(
modifier = modifier,
) {
val communityName = community?.readableName.orEmpty()
val communityName = community?.readableName(preferNicknames).orEmpty()
val communityIcon = community?.icon.orEmpty()
val creatorName = creator?.readableName.orEmpty()
val creatorName = creator?.readableName(preferNicknames).orEmpty()
val creatorAvatar = creator?.avatar.orEmpty()
if (communityName.isNotEmpty() || creatorName.isNotEmpty()) {
Row(

View File

@ -56,6 +56,7 @@ fun PostCard(
post: PostModel,
isFromModerator: Boolean = false,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
showScores: Boolean = true,
hideAuthor: Boolean = false,
postLayout: PostLayout = PostLayout.Card,
@ -111,6 +112,7 @@ fun PostCard(
limitBodyHeight = limitBodyHeight,
voteFormat = voteFormat,
autoLoadImages = autoLoadImages,
preferNicknames = preferNicknames,
showScores = showScores,
roundedCornerImage = postLayout == PostLayout.Card,
fullHeightImage = fullHeightImage,
@ -138,6 +140,7 @@ fun PostCard(
blurNsfw = blurNsfw,
voteFormat = voteFormat,
autoLoadImages = autoLoadImages,
preferNicknames = preferNicknames,
showScores = showScores,
actionButtonsActive = actionButtonsActive,
options = options,
@ -164,6 +167,7 @@ private fun CompactPost(
post: PostModel,
isFromModerator: Boolean = false,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
showScores: Boolean = true,
hideAuthor: Boolean,
blurNsfw: Boolean,
@ -212,6 +216,7 @@ private fun CompactPost(
onOpenCreator?.invoke(user, "")
},
autoLoadImages = autoLoadImages,
preferNicknames = preferNicknames,
onDoubleClick = onDoubleClick,
onLongClick = rememberCallback {
optionsMenuOpen.value = true
@ -298,6 +303,7 @@ private fun ExtendedPost(
post: PostModel,
isFromModerator: Boolean = false,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
showScores: Boolean = true,
hideAuthor: Boolean = false,
blurNsfw: Boolean = true,
@ -356,6 +362,7 @@ private fun ExtendedPost(
onOpenCreator?.invoke(user, "")
},
autoLoadImages = autoLoadImages,
preferNicknames = preferNicknames,
onDoubleClick = onDoubleClick,
onLongClick = rememberCallback {
optionsMenuOpen.value = true

View File

@ -39,8 +39,8 @@ import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.rememberCallb
import com.github.diegoberaldin.raccoonforlemmy.core.utils.datetime.prettifyDate
import com.github.diegoberaldin.raccoonforlemmy.core.utils.getPrettyNumber
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.readableHandle
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.readableName
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.readableSimpleName
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
import dev.icerock.moko.resources.compose.stringResource
@ -49,6 +49,7 @@ fun UserHeader(
user: UserModel,
modifier: Modifier = Modifier,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
onOpenImage: ((String) -> Unit)? = null,
) {
Box(
@ -113,13 +114,13 @@ fun UserHeader(
verticalArrangement = Arrangement.spacedBy(Spacing.s),
) {
Text(
text = user.readableName,
text = user.readableName(preferNicknames),
style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.onBackground,
)
if (user.readableSimpleName != user.readableName) {
if (user.readableHandle != user.readableName(preferNicknames)) {
Text(
text = user.readableSimpleName,
text = user.readableHandle,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.titleSmall,

View File

@ -36,14 +36,15 @@ import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.onClick
import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.rememberCallback
import com.github.diegoberaldin.raccoonforlemmy.core.utils.toLocalDp
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.readableHandle
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.readableName
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.readableSimpleName
@Composable
fun UserItem(
user: UserModel,
modifier: Modifier = Modifier,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
options: List<Option> = emptyList(),
onOptionSelected: ((OptionId) -> Unit)? = null,
) {
@ -73,13 +74,13 @@ fun UserItem(
} else {
PlaceholderImage(
size = iconSize,
title = user.readableName,
title = user.readableName(preferNicknames),
)
}
CustomizedContent {
Text(
text = user.readableSimpleName,
text = user.readableHandle,
style = MaterialTheme.typography.bodySmall,
color = fullColor,
)

View File

@ -0,0 +1,101 @@
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.Alignment
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.BottomSheetHandle
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
import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.rememberCallback
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
import dev.icerock.moko.resources.compose.stringResource
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),
) {
Column(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
) {
BottomSheetHandle()
Text(
modifier = Modifier.padding(
start = Spacing.s,
top = Spacing.s,
end = Spacing.s,
),
text = stringResource(MR.strings.settings_comment_bar_thickness),
style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.onBackground,
)
}
Column(
modifier = Modifier.fillMaxWidth().verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(Spacing.xxxs),
) {
for (value in values) {
Row(
modifier = Modifier
.padding(
horizontal = Spacing.s,
vertical = Spacing.s,
)
.fillMaxWidth()
.onClick(
onClick = rememberCallback {
notificationCenter.send(
NotificationCenterEvent.ChangeCommentBarThickness(value)
)
navigationCoordinator.hideBottomSheet()
},
),
) {
Text(
text = value.toString(),
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onBackground,
)
}
}
}
}
}
}

View File

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

View File

@ -50,4 +50,6 @@ data class SettingsModel(
val actionsOnSwipeToEndInbox: List<ActionOnSwipe> = ActionOnSwipe.DEFAULT_SWIPE_TO_END_INBOX,
val opaqueSystemBars: Boolean = false,
val showScores: Boolean = true,
val preferUserNicknames: Boolean = true,
val commentBarThickness: Int = 0,
)

View File

@ -50,6 +50,8 @@ private object KeyStoreKeys {
const val INFINITE_SCROLL_ENABLED = "infiniteScrollEnabled"
const val OPAQUE_SYSTEM_BARS = "opaqueSystemBars"
const val SHOW_SCORES = "showScores"
const val PREFER_USER_NICKNAMES = "preferUserNicknames"
const val COMMENT_BAR_THICKNESS = "commentBarThickness"
}
internal class DefaultSettingsRepository(
@ -115,6 +117,8 @@ internal class DefaultSettingsRepository(
.joinToString(","),
opaqueSystemBars = if (settings.opaqueSystemBars) 1L else 0L,
showScores = if (settings.showScores) 1L else 0L,
preferUserNicknames = if (settings.preferUserNicknames) 1L else 0L,
commentBarThickness = settings.commentBarThickness.toLong()
)
}
@ -161,6 +165,8 @@ internal class DefaultSettingsRepository(
infiniteScrollEnabled = keyStore[KeyStoreKeys.INFINITE_SCROLL_ENABLED, true],
opaqueSystemBars = keyStore[KeyStoreKeys.OPAQUE_SYSTEM_BARS, false],
showScores = keyStore[KeyStoreKeys.SHOW_SCORES, true],
preferUserNicknames = keyStore[KeyStoreKeys.PREFER_USER_NICKNAMES, true],
commentBarThickness = keyStore[KeyStoreKeys.COMMENT_BAR_THICKNESS, 0],
)
} else {
val entity = db.settingsQueries.getBy(accountId).executeAsOneOrNull()
@ -247,6 +253,8 @@ internal class DefaultSettingsRepository(
keyStore.save(KeyStoreKeys.INFINITE_SCROLL_ENABLED, settings.infiniteScrollEnabled)
keyStore.save(KeyStoreKeys.OPAQUE_SYSTEM_BARS, settings.opaqueSystemBars)
keyStore.save(KeyStoreKeys.SHOW_SCORES, settings.showScores)
keyStore.save(KeyStoreKeys.PREFER_USER_NICKNAMES, settings.preferUserNicknames)
keyStore.save(KeyStoreKeys.COMMENT_BAR_THICKNESS, settings.commentBarThickness)
} else {
db.settingsQueries.update(
theme = settings.theme?.toLong(),
@ -300,6 +308,8 @@ internal class DefaultSettingsRepository(
.joinToString(","),
opaqueSystemBars = if (settings.opaqueSystemBars) 1L else 0L,
showScores = if (settings.showScores) 1L else 0L,
preferUserNicknames = if (settings.preferUserNicknames) 1L else 0L,
commentBarThickness = settings.commentBarThickness.toLong(),
)
}
}
@ -367,4 +377,6 @@ private fun GetBy.toModel() = SettingsModel(
?: ActionOnSwipe.DEFAULT_SWIPE_TO_END_INBOX,
opaqueSystemBars = opaqueSystemBars == 1L,
showScores = showScores == 1L,
preferUserNicknames = preferUserNicknames == 1L,
commentBarThickness = commentBarThickness.toInt(),
)

View File

@ -45,6 +45,8 @@ CREATE TABLE SettingsEntity (
actionsOnSwipeToEndInbox TEXT DEFAULT NULL,
opaqueSystemBars INTEGER DEFAULT NULL,
showScores INTEGER NOT NULL DEFAULT 1,
preferUserNicknames INTEGER NOT NULL DEFAULT 1,
commentBarThickness INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY (account_id) REFERENCES AccountEntity(id) ON DELETE CASCADE,
UNIQUE(account_id)
);
@ -95,6 +97,8 @@ INSERT OR IGNORE INTO SettingsEntity (
actionsOnSwipeToEndInbox,
opaqueSystemBars,
showScores,
preferUserNicknames,
commentBarThickness,
account_id
) VALUES (
?,
@ -141,6 +145,8 @@ INSERT OR IGNORE INTO SettingsEntity (
?,
?,
?,
?,
?,
?
);
@ -189,7 +195,9 @@ SET theme = ?,
actionsOnSwipeToStartInbox = ?,
actionsOnSwipeToEndInbox = ?,
opaqueSystemBars = ?,
showScores = ?
showScores = ?,
preferUserNicknames = ?,
commentBarThickness = ?
WHERE account_id = ?;
getBy:
@ -238,6 +246,8 @@ SELECT
actionsOnSwipeToStartInbox,
actionsOnSwipeToEndInbox,
opaqueSystemBars,
showScores
showScores,
preferUserNicknames,
commentBarThickness
FROM SettingsEntity
WHERE account_id = ?;

View File

@ -0,0 +1,5 @@
ALTER TABLE SettingsEntity
ADD COLUMN preferUserNicknames INTEGER NOT NULL DEFAULT 1;
ALTER TABLE SettingsEntity
ADD COLUMN commentBarThickness INTEGER NOT NULL DEFAULT 1;

View File

@ -24,10 +24,15 @@ data class CommunityModel(
@Transient val favorite: Boolean = false,
)
val CommunityModel.readableName: String
get() = title.takeIf { it.isNotEmpty() }?.replace("&amp;", "&") ?: readableSimpleName
fun CommunityModel.readableName(preferNickname: Boolean): String {
return if (preferNickname) {
title.takeIf { it.isNotEmpty() }?.replace("&amp;", "&") ?: readableHandle
} else {
readableHandle
}
}
val CommunityModel.readableSimpleName: String
val CommunityModel.readableHandle: String
get() = buildString {
append(name)
if (host.isNotEmpty()) {

View File

@ -19,10 +19,15 @@ data class UserModel(
fun List<UserModel>.containsId(value: Int?): Boolean = any { it.id == value }
val UserModel.readableName: String
get() = displayName.takeIf { it.isNotEmpty() } ?: readableSimpleName
fun UserModel.readableName(preferNickname: Boolean): String {
return if (preferNickname) {
displayName.takeIf { it.isNotEmpty() } ?: readableHandle
} else {
readableHandle
}
}
val UserModel.readableSimpleName: String
val UserModel.readableHandle: String
get() = buildString {
append(name)
if (host.isNotEmpty()) {

View File

@ -48,6 +48,7 @@ interface ExploreMviModel :
val fullHeightImages: Boolean = true,
val voteFormat: VoteFormat = VoteFormat.Aggregated,
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val showScores: Boolean = true,
val availableSortTypes: List<SortType> = emptyList(),
val actionsOnSwipeToStartPosts: List<ActionOnSwipe> = emptyList(),

View File

@ -336,6 +336,7 @@ class ExploreScreen : Screen {
),
community = result.model,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
)
}
@ -445,6 +446,7 @@ class ExploreScreen : Screen {
fullHeightImage = uiState.fullHeightImages,
voteFormat = uiState.voteFormat,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
showScores = uiState.showScores,
blurNsfw = uiState.blurNsfw,
actionButtonsActive = uiState.isLogged,
@ -632,6 +634,7 @@ class ExploreScreen : Screen {
comment = result.model,
voteFormat = uiState.voteFormat,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
showScores = uiState.showScores,
hideIndent = true,
actionButtonsActive = uiState.isLogged,
@ -719,6 +722,7 @@ class ExploreScreen : Screen {
},
),
user = result.model,
preferNicknames = uiState.preferNicknames,
)
}
}

View File

@ -73,6 +73,7 @@ class ExploreViewModel(
blurNsfw = settings.blurNsfw,
voteFormat = settings.voteFormat,
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
fullHeightImages = settings.fullHeightImages,
swipeActionsEnabled = settings.enableSwipeActions,
doubleTapActionEnabled = settings.enableDoubleTapAction,

View File

@ -27,6 +27,7 @@ interface SettingsColorAndFontMviModel :
val replyColor: Color? = null,
val saveColor: Color? = null,
val commentBarTheme: CommentBarTheme = CommentBarTheme.Blue,
val commentBarThickness: Int = 1,
val uiFontScale: FontScale = FontScale.Normal,
val uiFontFamily: UiFontFamily = UiFontFamily.Poppins,
val contentFontScale: FontScale = FontScale.Normal,

View File

@ -41,6 +41,7 @@ import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
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.navigation.di.getNavigationCoordinator
import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.onClick
import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.rememberCallback
@ -214,6 +215,16 @@ class SettingsColorAndFontScreen : Screen {
}
)
// comment bar thickness
SettingsRow(
title = stringResource(MR.strings.settings_comment_bar_thickness),
value = uiState.commentBarThickness.toString(),
onTap = rememberCallback {
val screen = CommentBarThicknessBottomSheet()
navigationCoordinator.showBottomSheet(screen)
}
)
// font family
SettingsRow(
title = stringResource(MR.strings.settings_ui_font_family),

View File

@ -72,6 +72,9 @@ class SettingsColorAndFontViewModel(
themeRepository.commentBarTheme.onEach { value ->
mvi.updateState { it.copy(commentBarTheme = value) }
}.launchIn(this)
themeRepository.commentBarThickness.onEach { value ->
mvi.updateState { it.copy(commentBarThickness = value) }
}.launchIn(this)
identityRepository.isLogged.onEach { logged ->
mvi.updateState { it.copy(isLogged = logged ?: false) }
@ -100,6 +103,10 @@ class SettingsColorAndFontViewModel(
.onEach { evt ->
changeCommentBarTheme(evt.value)
}.launchIn(this)
notificationCenter.subscribe(NotificationCenterEvent.ChangeCommentBarThickness::class)
.onEach { evt ->
changeCommentBarThickness(evt.value)
}.launchIn(this)
notificationCenter.subscribe(NotificationCenterEvent.ChangeActionColor::class)
.onEach { evt ->
when (evt.actionType) {
@ -186,7 +193,7 @@ class SettingsColorAndFontViewModel(
}
private fun changeUpVoteColor(value: Color?) {
themeRepository.changeUpvoteColor(value)
themeRepository.changeUpVoteColor(value)
mvi.scope?.launch(Dispatchers.IO) {
val settings = settingsRepository.currentSettings.value.copy(
upVoteColor = value?.toArgb()
@ -196,7 +203,7 @@ class SettingsColorAndFontViewModel(
}
private fun changeDownVoteColor(value: Color?) {
themeRepository.changeDownvoteColor(value)
themeRepository.changeDownVoteColor(value)
mvi.scope?.launch(Dispatchers.IO) {
val settings = settingsRepository.currentSettings.value.copy(
downVoteColor = value?.toArgb()
@ -235,6 +242,16 @@ class SettingsColorAndFontViewModel(
}
}
private fun changeCommentBarThickness(value: Int) {
themeRepository.changeCommentBarThickness(value)
mvi.scope?.launch(Dispatchers.IO) {
val settings = settingsRepository.currentSettings.value.copy(
commentBarThickness = value
)
saveSettings(settings)
}
}
private suspend fun saveSettings(settings: SettingsModel) {
val accountId = accountRepository.getActive()?.id
settingsRepository.updateSettings(settings, accountId)

View File

@ -41,6 +41,7 @@ interface SettingsMviModel :
data class ChangeEdgeToEdge(val value: Boolean) : Intent
data class ChangePostBodyMaxLines(val value: Int) : Intent
data class ChangeInfiniteScrollDisabled(val value: Boolean) : Intent
data class ChangePreferUserNicknames(val value: Boolean) : Intent
}
data class UiState(
@ -74,6 +75,7 @@ interface SettingsMviModel :
val postBodyMaxLines: Int? = null,
val infiniteScrollDisabled: Boolean = false,
val opaqueSystemBars: Boolean = false,
val preferUserNicknames: Boolean = true,
)
sealed interface Effect

View File

@ -276,6 +276,17 @@ class SettingsScreen : Screen {
},
)
// prefer user nicknames
SettingsSwitchRow(
title = stringResource(MR.strings.settings_prefer_user_nicknames),
value = uiState.preferUserNicknames,
onValueChanged = rememberCallbackArgs(model) { value ->
model.reduce(
SettingsMviModel.Intent.ChangePreferUserNicknames(value)
)
},
)
// body max lines in full layout
if (uiState.postLayout == PostLayout.Full) {
SettingsRow(

View File

@ -156,6 +156,7 @@ class SettingsViewModel(
postBodyMaxLines = settings.postBodyMaxLines,
infiniteScrollDisabled = !settings.infiniteScrollEnabled,
opaqueSystemBars = settings.opaqueSystemBars,
preferUserNicknames = settings.preferUserNicknames,
)
}
}
@ -203,6 +204,8 @@ class SettingsViewModel(
is SettingsMviModel.Intent.ChangePostBodyMaxLines -> changePostBodyMaxLines(intent.value)
is SettingsMviModel.Intent.ChangeInfiniteScrollDisabled ->
changeInfiniteScrollDisabled(intent.value)
is SettingsMviModel.Intent.ChangePreferUserNicknames -> changePreferUserNicknames(intent.value)
}
}
@ -464,6 +467,16 @@ class SettingsViewModel(
}
}
private fun changePreferUserNicknames(value: Boolean) {
mvi.updateState { it.copy(preferUserNicknames = value) }
mvi.scope?.launch(Dispatchers.IO) {
val settings = settingsRepository.currentSettings.value.copy(
preferUserNicknames = value
)
saveSettings(settings)
}
}
private fun changePostBodyMaxLines(value: Int?) {
mvi.updateState { it.copy(postBodyMaxLines = value) }
mvi.scope?.launch(Dispatchers.IO) {

View File

@ -361,4 +361,6 @@
<string name="settings_user_manual">User manual</string>
<string name="settings_show_scores">Show scores</string>
<string name="settings_vote_format_hidden">Hidden</string>
<string name="settings_comment_bar_thickness">Comment bar thickness</string>
<string name="settings_prefer_user_nicknames">Prefer user nicknames</string>
</resources>

View File

@ -116,10 +116,11 @@ 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) })
changeDownvoteColor(currentSettings.downVoteColor?.let { Color(it) })
changeUpVoteColor(currentSettings.upVoteColor?.let { Color(it) })
changeDownVoteColor(currentSettings.downVoteColor?.let { Color(it) })
changeReplyColor(currentSettings.replyColor?.let { Color(it) })
changeSaveColor(currentSettings.saveColor?.let { Color(it) })
}
@ -153,8 +154,8 @@ fun App(onLoadingFinished: () -> Unit = {}) {
changeContentFontFamily(settings.contentFontFamily.toUiFontFamily())
with(themeRepository) {
changeUpvoteColor(settings.upVoteColor?.let { Color(it) })
changeDownvoteColor(settings.downVoteColor?.let { Color(it) })
changeUpVoteColor(settings.upVoteColor?.let { Color(it) })
changeDownVoteColor(settings.downVoteColor?.let { Color(it) })
changeReplyColor(settings.replyColor?.let { Color(it) })
changeSaveColor(settings.saveColor?.let { Color(it) })
}

View File

@ -44,6 +44,7 @@ interface InboxChatMviModel :
val otherUserAvatar: String? = null,
val messages: List<PrivateMessageModel> = emptyList(),
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val editedMessageId: Int? = null,
)

View File

@ -40,7 +40,12 @@ class InboxChatViewModel(
val auth = identityRepository.authToken.value.orEmpty()
settingsRepository.currentSettings.onEach { settings ->
mvi.updateState { it.copy(autoLoadImages = settings.autoLoadImages) }
mvi.updateState {
it.copy(
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
)
}
}.launchIn(this)
notificationCenter.subscribe(NotificationCenterEvent.Logout::class).onEach {
handleLogout()

View File

@ -59,6 +59,7 @@ interface CommunityDetailMviModel :
val fullHeightImages: Boolean = true,
val voteFormat: VoteFormat = VoteFormat.Aggregated,
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val showScores: Boolean = true,
val zombieModeActive: Boolean = false,
val moderators: List<UserModel> = emptyList(),

View File

@ -654,6 +654,7 @@ class CommunityDetailScreen(
fullHeightImage = uiState.fullHeightImages,
voteFormat = uiState.voteFormat,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
showScores = uiState.showScores,
actionButtonsActive = uiState.isLogged,
blurNsfw = when {

View File

@ -90,6 +90,7 @@ class CommunityDetailViewModel(
fullHeightImages = settings.fullHeightImages,
voteFormat = settings.voteFormat,
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
actionsOnSwipeToStartPosts = settings.actionsOnSwipeToStartPosts,
actionsOnSwipeToEndPosts = settings.actionsOnSwipeToEndPosts,
showScores = settings.showScores,

View File

@ -16,6 +16,7 @@ interface CommunityInfoMviModel :
data class UiState(
val community: CommunityModel = CommunityModel(),
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val moderators: List<UserModel> = emptyList(),
)

View File

@ -19,7 +19,6 @@ import androidx.compose.material.icons.filled.CalendarViewWeek
import androidx.compose.material.icons.filled.Group
import androidx.compose.material.icons.filled.Padding
import androidx.compose.material.icons.filled.Reply
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
@ -56,7 +55,7 @@ import org.koin.core.parameter.parametersOf
class CommunityInfoScreen(
private val communityId: Int,
) : Screen {
@OptIn(ExperimentalMaterial3Api::class)
@Composable
override fun Content() {
val model = getScreenModel<CommunityInfoMviModel>(
@ -89,7 +88,7 @@ class CommunityInfoScreen(
) {
Spacer(modifier = Modifier.weight(1f))
Text(
text = uiState.community.readableName,
text = uiState.community.readableName(uiState.preferNicknames),
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onBackground,
)

View File

@ -49,6 +49,7 @@ interface CreateCommentMviModel :
val loading: Boolean = false,
val section: CreatePostSection = CreatePostSection.Edit,
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val showScores: Boolean = true,
val currentInstance: String = "",
val currentUser: String = "",

View File

@ -348,6 +348,7 @@ class CreateCommentScreen(
CommentCard(
modifier = referenceModifier,
comment = originalComment,
preferNicknames = uiState.preferNicknames,
hideIndent = true,
voteFormat = uiState.voteFormat,
autoLoadImages = uiState.autoLoadImages,
@ -379,6 +380,7 @@ class CreateCommentScreen(
includeFullBody = true,
voteFormat = uiState.voteFormat,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
showScores = uiState.showScores,
options = buildList {
add(

View File

@ -72,6 +72,7 @@ class CreateCommentViewModel(
it.copy(
voteFormat = settings.voteFormat,
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
fullHeightImages = settings.fullHeightImages,
showScores = settings.showScores,
)

View File

@ -75,6 +75,7 @@ interface CreatePostMviModel :
val fullHeightImages: Boolean = true,
val voteFormat: VoteFormat = VoteFormat.Aggregated,
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val showScores: Boolean = true,
val currentInstance: String = "",
val currentUser: String = "",

View File

@ -533,6 +533,7 @@ class CreatePostScreen(
includeFullBody = true,
voteFormat = uiState.voteFormat,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
showScores = uiState.showScores,
)
}

View File

@ -51,6 +51,7 @@ class CreatePostViewModel(
it.copy(
voteFormat = settings.voteFormat,
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
fullHeightImages = settings.fullHeightImages,
showScores = settings.showScores,
)
@ -78,10 +79,11 @@ class CreatePostViewModel(
when (intent) {
is CreatePostMviModel.Intent.SetCommunity -> {
val community = intent.value
val preferNicknames = uiState.value.preferNicknames
mvi.updateState {
it.copy(
communityId = community.id,
communityInfo = community.readableName,
communityInfo = community.readableName(preferNicknames),
)
}
}

View File

@ -224,6 +224,7 @@ object ModalDrawerContent : Tab {
small = true,
showFavorite = true,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
)
}
}

View File

@ -6,7 +6,6 @@ import com.github.diegoberaldin.raccoonforlemmy.core.architecture.MviModel
import com.github.diegoberaldin.raccoonforlemmy.core.persistence.data.MultiCommunityModel
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
import dev.icerock.moko.resources.desc.StringDesc
@Stable
interface ModalDrawerMviModel :
@ -19,6 +18,7 @@ interface ModalDrawerMviModel :
data class UiState(
val user: UserModel? = null,
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val refreshing: Boolean = false,
val instance: String? = null,
val communities: List<CommunityModel> = emptyList(),

View File

@ -10,8 +10,6 @@ import com.github.diegoberaldin.raccoonforlemmy.domain.identity.repository.ApiCo
import com.github.diegoberaldin.raccoonforlemmy.domain.identity.repository.IdentityRepository
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.CommunityRepository
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.SiteRepository
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
import dev.icerock.moko.resources.desc.desc
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
@ -57,7 +55,12 @@ class ModalDrawerViewModel(
refresh()
}.launchIn(this)
settingsRepository.currentSettings.onEach { settings ->
mvi.updateState { it.copy(autoLoadImages = settings.autoLoadImages) }
mvi.updateState {
it.copy(
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
)
}
}.launchIn(this)
observeChangesInFavoriteCommunities()

View File

@ -23,6 +23,7 @@ interface InstanceInfoMviModel :
val canFetchMore: Boolean = true,
val refreshing: Boolean = false,
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val loading: Boolean = false,
val sortType: SortType = SortType.Active,
val communities: List<CommunityModel> = emptyList(),

View File

@ -219,6 +219,7 @@ class InstanceInfoScreen(
),
community = community,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
showSubscribers = true,
)
}

View File

@ -37,7 +37,12 @@ class InstanceInfoViewModel(
mvi.onStarted()
mvi.scope?.launch {
settingsRepository.currentSettings.onEach { settings ->
mvi.updateState { it.copy(autoLoadImages = settings.autoLoadImages) }
mvi.updateState {
it.copy(
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
)
}
}.launchIn(this)
notificationCenter.subscribe(NotificationCenterEvent.ChangeSortType::class)
.onEach { evt ->

View File

@ -15,6 +15,7 @@ interface ManageAccountsMviModel :
data class UiState(
val accounts: List<AccountModel> = emptyList(),
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
)
sealed interface Effect {

View File

@ -33,7 +33,12 @@ class ManageAccountsViewModel(
if (uiState.value.accounts.isEmpty()) {
mvi.scope?.launch {
settingsRepository.currentSettings.onEach { settings ->
mvi.updateState { it.copy(autoLoadImages = settings.autoLoadImages) }
mvi.updateState {
it.copy(
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
)
}
}.launchIn(this)
val accounts = accountRepository.getAll()

View File

@ -31,6 +31,7 @@ interface ManageBanMviModel :
val refreshing: Boolean = false,
val initial: Boolean = true,
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val bannedUsers: List<UserModel> = emptyList(),
val bannedCommunities: List<CommunityModel> = emptyList(),
val bannedInstances: List<InstanceModel> = emptyList(),

View File

@ -186,6 +186,7 @@ class ManageBanScreen : Screen {
UserItem(
user = user,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
options = buildList {
this += Option(
OptionId.Unban,
@ -234,6 +235,7 @@ class ManageBanScreen : Screen {
CommunityItem(
community = community,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
options = buildList {
this += Option(
OptionId.Unban,

View File

@ -28,7 +28,12 @@ class ManageBanViewModel(
mvi.onStarted()
mvi.scope?.launch {
settingsRepository.currentSettings.onEach { settings ->
mvi.updateState { it.copy(autoLoadImages = settings.autoLoadImages) }
mvi.updateState {
it.copy(
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
)
}
}.launchIn(this)
withContext(Dispatchers.IO) {

View File

@ -24,6 +24,7 @@ interface ManageSubscriptionsMviModel :
val multiCommunities: List<MultiCommunityModel> = emptyList(),
val communities: List<CommunityModel> = emptyList(),
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
)
sealed interface Effect

View File

@ -37,7 +37,12 @@ class ManageSubscriptionsViewModel(
mvi.onStarted()
mvi.scope?.launch {
settingsRepository.currentSettings.onEach { settings ->
mvi.updateState { it.copy(autoLoadImages = settings.autoLoadImages) }
mvi.updateState {
it.copy(
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
)
}
}.launchIn(this)
notificationCenter.subscribe(NotificationCenterEvent.MultiCommunityCreated::class)
.onEach { evt ->

View File

@ -32,6 +32,7 @@ interface InboxMentionsMviModel :
val swipeActionsEnabled: Boolean = true,
val postLayout: PostLayout = PostLayout.Card,
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val showScores: Boolean = true,
val voteFormat: VoteFormat = VoteFormat.Aggregated,
val actionsOnSwipeToStartInbox: List<ActionOnSwipe> = emptyList(),

View File

@ -227,6 +227,7 @@ class InboxMentionsScreen : Tab {
postLayout = uiState.postLayout,
type = InboxCardType.Mention,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
showScores = uiState.showScores,
voteFormat = uiState.voteFormat,
onOpenPost = rememberCallbackArgs { post ->

View File

@ -55,6 +55,7 @@ class InboxMentionsViewModel(
it.copy(
swipeActionsEnabled = settings.enableSwipeActions,
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
voteFormat = settings.voteFormat,
actionsOnSwipeToStartInbox = settings.actionsOnSwipeToStartInbox,
actionsOnSwipeToEndInbox = settings.actionsOnSwipeToEndInbox,

View File

@ -50,6 +50,7 @@ import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.readableName
internal fun ChatCard(
user: UserModel?,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
read: Boolean = true,
lastMessage: String,
lastMessageDate: String? = null,
@ -61,7 +62,7 @@ internal fun ChatCard(
) {
var optionsExpanded by remember { mutableStateOf(false) }
var optionsOffset by remember { mutableStateOf(Offset.Zero) }
val creatorName = user?.readableName.orEmpty()
val creatorName = user?.readableName(preferNicknames).orEmpty()
val creatorAvatar = user?.avatar.orEmpty()
val iconSize = IconSize.xl
val ancillaryColor = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.75f)

View File

@ -24,6 +24,7 @@ interface InboxMessagesMviModel :
val currentUserId: Int = 0,
val chats: List<PrivateMessageModel> = emptyList(),
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
)
sealed interface Effect {

View File

@ -44,7 +44,12 @@ class InboxMessagesViewModel(
}
}.launchIn(this)
settingsRepository.currentSettings.onEach { settings ->
mvi.updateState { it.copy(autoLoadImages = settings.autoLoadImages) }
mvi.updateState {
it.copy(
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
)
}
}.launchIn(this)
notificationCenter.subscribe(NotificationCenterEvent.Logout::class).onEach {
handleLogout()

View File

@ -20,6 +20,7 @@ interface ModlogMviModel :
val canFetchMore: Boolean = true,
val postLayout: PostLayout = PostLayout.Card,
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val items: List<ModlogItem> = emptyList(),
)

View File

@ -34,6 +34,7 @@ class ModlogViewModel(
mvi.updateState {
it.copy(
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
)
}
}

View File

@ -60,6 +60,7 @@ internal fun InnerModlogItem(
modifier: Modifier = Modifier,
reason: String? = null,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
date: String? = null,
moderator: UserModel? = null,
postLayout: PostLayout = PostLayout.Card,
@ -91,6 +92,7 @@ internal fun InnerModlogItem(
ModlogHeader(
creator = moderator,
autoLoadImages = autoLoadImages,
preferNicknames = preferNicknames,
onOpenCreator = onOpenUser,
)
CustomizedContent {
@ -130,10 +132,11 @@ private fun ModlogHeader(
modifier: Modifier = Modifier,
creator: UserModel? = null,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
iconSize: Dp = IconSize.s,
onOpenCreator: ((UserModel) -> Unit)? = null,
) {
val creatorName = creator?.readableName.orEmpty()
val creatorName = creator?.readableName(preferNicknames).orEmpty()
val creatorAvatar = creator?.avatar.orEmpty()
if (creatorName.isNotEmpty()) {
Row(

View File

@ -21,12 +21,14 @@ internal fun ModAddItem(
item: ModlogItem.ModAdd,
modifier: Modifier = Modifier,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
postLayout: PostLayout = PostLayout.Card,
onOpenUser: ((UserModel) -> Unit)? = null,
) {
InnerModlogItem(
modifier = modifier,
autoLoadImages = autoLoadImages,
preferNicknames = preferNicknames,
date = item.date,
postLayout = postLayout,
moderator = item.moderator,
@ -40,7 +42,7 @@ internal fun ModAddItem(
Text(
text = buildAnnotatedString {
withStyle(style = SpanStyle(fontWeight = FontWeight.SemiBold)) {
val name = item.user?.readableName.orEmpty()
val name = item.user?.readableName(preferNicknames).orEmpty()
append(name)
}
append(" ")

View File

@ -21,6 +21,7 @@ internal fun ModBanFromCommunityItem(
item: ModlogItem.ModBanFromCommunity,
modifier: Modifier = Modifier,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
postLayout: PostLayout = PostLayout.Card,
onOpenUser: ((UserModel) -> Unit)? = null,
) {
@ -40,7 +41,7 @@ internal fun ModBanFromCommunityItem(
Text(
text = buildAnnotatedString {
withStyle(style = SpanStyle(fontWeight = FontWeight.SemiBold)) {
val name = item.user?.readableName.orEmpty()
val name = item.user?.readableName(preferNicknames).orEmpty()
append(name)
}
append(" ")

View File

@ -20,12 +20,14 @@ internal fun ModFeaturePostItem(
item: ModlogItem.ModFeaturePost,
modifier: Modifier = Modifier,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
postLayout: PostLayout = PostLayout.Card,
onOpenUser: ((UserModel) -> Unit)? = null,
) {
InnerModlogItem(
modifier = modifier,
autoLoadImages = autoLoadImages,
preferNicknames = preferNicknames,
date = item.date,
postLayout = postLayout,
moderator = item.moderator,

View File

@ -20,12 +20,14 @@ internal fun ModLockPostItem(
item: ModlogItem.ModLockPost,
modifier: Modifier = Modifier,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
postLayout: PostLayout = PostLayout.Card,
onOpenUser: ((UserModel) -> Unit)? = null,
) {
InnerModlogItem(
modifier = modifier,
autoLoadImages = autoLoadImages,
preferNicknames = preferNicknames,
date = item.date,
postLayout = postLayout,
moderator = item.moderator,

View File

@ -20,12 +20,14 @@ internal fun ModRemoveCommentItem(
item: ModlogItem.ModRemoveComment,
modifier: Modifier = Modifier,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
postLayout: PostLayout = PostLayout.Card,
onOpenUser: ((UserModel) -> Unit)? = null,
) {
InnerModlogItem(
modifier = modifier,
autoLoadImages = autoLoadImages,
preferNicknames = preferNicknames,
date = item.date,
postLayout = postLayout,
moderator = item.moderator,

View File

@ -20,12 +20,14 @@ internal fun ModRemovePostItem(
item: ModlogItem.ModRemovePost,
modifier: Modifier = Modifier,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
postLayout: PostLayout = PostLayout.Card,
onOpenUser: ((UserModel) -> Unit)? = null,
) {
InnerModlogItem(
modifier = modifier,
autoLoadImages = autoLoadImages,
preferNicknames = preferNicknames,
date = item.date,
postLayout = postLayout,
moderator = item.moderator,

View File

@ -21,6 +21,7 @@ internal fun ModTransferCommunityItem(
item: ModlogItem.ModTransferCommunity,
modifier: Modifier = Modifier,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
postLayout: PostLayout = PostLayout.Card,
onOpenUser: ((UserModel) -> Unit)? = null,
) {
@ -42,7 +43,7 @@ internal fun ModTransferCommunityItem(
append(stringResource(MR.strings.modlog_item_community_transfer))
append(" ")
withStyle(style = SpanStyle(fontWeight = FontWeight.SemiBold)) {
val name = item.user?.readableName.orEmpty()
val name = item.user?.readableName(preferNicknames).orEmpty()
append(name)
}
},

View File

@ -42,6 +42,7 @@ interface MultiCommunityMviModel :
val fullHeightImages: Boolean = true,
val voteFormat: VoteFormat = VoteFormat.Aggregated,
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val showScores: Boolean = true,
val availableSortTypes: List<SortType> = emptyList(),
val actionsOnSwipeToStartPosts: List<ActionOnSwipe> = emptyList(),

View File

@ -383,7 +383,8 @@ class MultiCommunityScreen(
fullHeightImage = uiState.fullHeightImages,
voteFormat = uiState.voteFormat,
autoLoadImages = uiState.autoLoadImages,
showScores = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
showScores = uiState.showScores,
blurNsfw = uiState.blurNsfw,
onClick = rememberCallback {
model.reduce(MultiCommunityMviModel.Intent.MarkAsRead(post.id))

View File

@ -66,6 +66,7 @@ class MultiCommunityViewModel(
swipeActionsEnabled = settings.enableSwipeActions,
voteFormat = settings.voteFormat,
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
fullHeightImages = settings.fullHeightImages,
actionsOnSwipeToStartPosts = settings.actionsOnSwipeToStartPosts,
actionsOnSwipeToEndPosts = settings.actionsOnSwipeToEndPosts,

View File

@ -19,6 +19,7 @@ interface MultiCommunityEditorMviModel :
data class UiState(
val name: String = "",
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val nameError: StringDesc? = null,
val icon: String? = null,
val availableIcons: List<String> = emptyList(),

View File

@ -327,6 +327,7 @@ class MultiCommunityEditorScreen(
modifier = Modifier.fillMaxWidth()
.background(MaterialTheme.colorScheme.background),
community = community,
preferNicknames = uiState.preferNicknames,
)
Checkbox(
checked = selected,

View File

@ -40,7 +40,12 @@ class MultiCommunityEditorViewModel(
mvi.onStarted()
mvi.scope?.launch {
settingsRepository.currentSettings.onEach { settings ->
mvi.updateState { it.copy(autoLoadImages = settings.autoLoadImages) }
mvi.updateState {
it.copy(
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
)
}
}.launchIn(this)
}
if (communities.isEmpty()) {

View File

@ -43,6 +43,7 @@ interface ProfileLoggedMviModel :
val fullHeightImages: Boolean = true,
val voteFormat: VoteFormat = VoteFormat.Aggregated,
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val showScores: Boolean = true,
)

View File

@ -185,6 +185,7 @@ object ProfileLoggedScreen : Tab {
fullHeightImage = uiState.fullHeightImages,
voteFormat = uiState.voteFormat,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
showScores = uiState.showScores,
hideAuthor = true,
blurNsfw = false,

View File

@ -77,6 +77,7 @@ class ProfileLoggedViewModel(
it.copy(
voteFormat = settings.voteFormat,
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
fullHeightImages = settings.fullHeightImages,
showScores = settings.showScores,
)

View File

@ -57,6 +57,7 @@ interface PostDetailMviModel :
val fullHeightImages: Boolean = true,
val voteFormat: VoteFormat = VoteFormat.Aggregated,
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val showScores: Boolean = true,
val moderators: List<UserModel> = emptyList(),
val availableSortTypes: List<SortType> = emptyList(),

View File

@ -318,6 +318,7 @@ class PostDetailScreen(
includeFullBody = true,
voteFormat = uiState.voteFormat,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
showScores = uiState.showScores,
actionButtonsActive = uiState.isLogged,
blurNsfw = false,
@ -538,7 +539,7 @@ class PostDetailScreen(
if (community != null) {
val string = buildAnnotatedString {
withStyle(SpanStyle(textDecoration = TextDecoration.Underline)) {
append(community.readableName)
append(community.readableName(uiState.preferNicknames))
}
if (index < uiState.post.crossPosts.lastIndex) {
append(", ")
@ -706,6 +707,7 @@ class PostDetailScreen(
isOp = comment.creator?.id == uiState.post.creator?.id,
voteFormat = uiState.voteFormat,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
showScores = uiState.showScores,
actionButtonsActive = uiState.isLogged,
onToggleExpanded = rememberCallback(model) {

View File

@ -106,6 +106,7 @@ class PostDetailViewModel(
doubleTapActionEnabled = settings.enableDoubleTapAction,
voteFormat = settings.voteFormat,
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
fullHeightImages = settings.fullHeightImages,
actionsOnSwipeToStartComments = settings.actionsOnSwipeToStartComments,
actionsOnSwipeToEndComments = settings.actionsOnSwipeToEndComments,

View File

@ -51,6 +51,7 @@ interface PostListMviModel :
val fullHeightImages: Boolean = true,
val voteFormat: VoteFormat = VoteFormat.Aggregated,
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val showScores: Boolean = true,
val zombieModeActive: Boolean = false,
val availableSortTypes: List<SortType> = emptyList(),

View File

@ -425,6 +425,7 @@ class PostListScreen : Screen {
fullHeightImage = uiState.fullHeightImages,
voteFormat = uiState.voteFormat,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
showScores = uiState.showScores,
actionButtonsActive = uiState.isLogged,
blurNsfw = uiState.blurNsfw,
@ -595,9 +596,9 @@ class PostListScreen : Screen {
OptionId.Block -> {
val screen = BlockBottomSheet(
userName = post.creator?.readableName,
userName = post.creator?.readableName(uiState.preferNicknames),
userId = post.creator?.id,
communityName = post.community?.readableName,
communityName = post.community?.readableName(uiState.preferNicknames),
communityId = post.community?.id,
instanceName = post.community?.host,
instanceId = post.community?.instanceId,

View File

@ -84,6 +84,7 @@ class PostListViewModel(
doubleTapActionEnabled = settings.enableDoubleTapAction,
voteFormat = settings.voteFormat,
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
fullHeightImages = settings.fullHeightImages,
actionsOnSwipeToStartPosts = settings.actionsOnSwipeToStartPosts,
actionsOnSwipeToEndPosts = settings.actionsOnSwipeToEndPosts,

View File

@ -32,6 +32,7 @@ interface InboxRepliesMviModel :
val postLayout: PostLayout = PostLayout.Card,
val swipeActionsEnabled: Boolean = true,
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val showScores: Boolean = true,
val voteFormat: VoteFormat = VoteFormat.Aggregated,
val actionsOnSwipeToStartInbox: List<ActionOnSwipe> = emptyList(),

View File

@ -223,6 +223,7 @@ class InboxRepliesScreen : Tab {
postLayout = uiState.postLayout,
type = InboxCardType.Reply,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
showScores = uiState.showScores,
voteFormat = uiState.voteFormat,
onOpenPost = rememberCallbackArgs { post ->

View File

@ -58,6 +58,7 @@ class InboxRepliesViewModel(
it.copy(
swipeActionsEnabled = settings.enableSwipeActions,
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
voteFormat = settings.voteFormat,
actionsOnSwipeToStartInbox = settings.actionsOnSwipeToStartInbox,
actionsOnSwipeToEndInbox = settings.actionsOnSwipeToEndInbox,

View File

@ -34,6 +34,7 @@ interface ReportListMviModel :
val asyncInProgress: Boolean = false,
val swipeActionsEnabled: Boolean = true,
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val postLayout: PostLayout = PostLayout.Card,
val canFetchMore: Boolean = true,
val postReports: List<PostReportModel> = emptyList(),

View File

@ -263,6 +263,7 @@ class ReportListScreen(
report = report,
postLayout = uiState.postLayout,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
onOpen = rememberCallback {
detailOpener.openPostDetail(
post = PostModel(id = report.postId),
@ -367,6 +368,7 @@ class ReportListScreen(
report = report,
postLayout = uiState.postLayout,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
onOpen = rememberCallback {
detailOpener.openPostDetail(
post = PostModel(id = report.postId),

View File

@ -45,6 +45,7 @@ class ReportListViewModel(
mvi.updateState {
it.copy(
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
swipeActionsEnabled = settings.enableSwipeActions,
)
}

View File

@ -18,6 +18,7 @@ internal fun CommentReportCard(
modifier: Modifier = Modifier,
options: List<Option> = emptyList(),
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
onOpen: (() -> Unit)? = null,
onOpenImage: ((String) -> Unit)? = null,
onOptionSelected: ((OptionId) -> Unit)? = null,
@ -29,6 +30,7 @@ internal fun CommentReportCard(
creator = report.creator,
date = report.publishDate,
autoLoadImages = autoLoadImages,
preferNicknames = preferNicknames,
options = options,
onOptionSelected = onOptionSelected,
onOpen = onOpen,

View File

@ -61,6 +61,7 @@ internal fun InnerReportCard(
modifier: Modifier = Modifier,
reason: String,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
date: String? = null,
creator: UserModel? = null,
postLayout: PostLayout = PostLayout.Card,
@ -94,6 +95,7 @@ internal fun InnerReportCard(
creator = creator,
autoLoadImages = autoLoadImages,
onOpenCreator = onOpenCreator,
preferNicknames = preferNicknames,
)
CustomizedContent {
PostCardBody(
@ -132,10 +134,11 @@ private fun ReportHeader(
modifier: Modifier = Modifier,
creator: UserModel? = null,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
iconSize: Dp = IconSize.s,
onOpenCreator: ((UserModel) -> Unit)? = null,
) {
val creatorName = creator?.readableName.orEmpty()
val creatorName = creator?.readableName(preferNicknames).orEmpty()
val creatorAvatar = creator?.avatar.orEmpty()
if (creatorName.isNotEmpty()) {
Row(

View File

@ -34,6 +34,7 @@ internal fun PostReportCard(
postLayout: PostLayout = PostLayout.Card,
modifier: Modifier = Modifier,
autoLoadImages: Boolean = true,
preferNicknames: Boolean = true,
onOpen: (() -> Unit)? = null,
options: List<Option> = emptyList(),
onOptionSelected: ((OptionId) -> Unit)? = null,
@ -48,6 +49,7 @@ internal fun PostReportCard(
creator = report.creator,
date = report.publishDate,
autoLoadImages = autoLoadImages,
preferNicknames = preferNicknames,
options = options,
onOptionSelected = onOptionSelected,
onOpen = onOpen,

View File

@ -44,6 +44,7 @@ interface SavedItemsMviModel :
val fullHeightImages: Boolean = true,
val voteFormat: VoteFormat = VoteFormat.Aggregated,
val autoLoadImages: Boolean = true,
val preferNicknames: Boolean = true,
val showScores: Boolean = true,
val availableSortTypes: List<SortType> = emptyList(),
)

View File

@ -217,6 +217,7 @@ class SavedItemsScreen : Screen {
fullHeightImage = uiState.fullHeightImages,
voteFormat = uiState.voteFormat,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
showScores = uiState.showScores,
blurNsfw = uiState.blurNsfw,
onClick = rememberCallback {
@ -345,6 +346,7 @@ class SavedItemsScreen : Screen {
comment = comment,
voteFormat = uiState.voteFormat,
autoLoadImages = uiState.autoLoadImages,
preferNicknames = uiState.preferNicknames,
showScores = uiState.showScores,
hideIndent = true,
onClick = {

View File

@ -55,6 +55,7 @@ class SavedItemsViewModel(
it.copy(
voteFormat = settings.voteFormat,
autoLoadImages = settings.autoLoadImages,
preferNicknames = settings.preferUserNicknames,
fullHeightImages = settings.fullHeightImages,
showScores = settings.showScores,
)

Some files were not shown because too many files have changed in this diff Show More