refactor(community): improve info bottom sheet

This commit is contained in:
Diego Beraldin 2023-08-14 10:00:21 +02:00
parent 205c800591
commit c264931ae5
18 changed files with 295 additions and 288 deletions

View File

@ -1,5 +1,6 @@
package com.github.diegoberaldin.raccoonforlemmy.core.commonui.di
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.communityInfo.CommunityInfoViewModel
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.communitydetail.CommunityDetailViewModel
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.postdetail.PostDetailViewModel
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.userdetail.UserDetailViewModel
@ -27,6 +28,14 @@ actual fun getCommunityDetailScreenViewModel(community: CommunityModel): Communi
return res
}
actual fun getCommunityInfoScreenViewModel(community: CommunityModel): CommunityInfoViewModel {
val res: CommunityInfoViewModel by inject(
clazz = CommunityInfoViewModel::class.java,
parameters = { parametersOf(community) },
)
return res
}
actual fun getUserDetailScreenViewModel(user: UserModel): UserDetailViewModel {
val res: UserDetailViewModel by inject(
clazz = UserDetailViewModel::class.java,

View File

@ -0,0 +1,16 @@
package com.github.diegoberaldin.raccoonforlemmy.core.commonui.communityInfo
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.MviModel
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel
interface CommunityInfoMviModel :
MviModel<CommunityInfoMviModel.Intent, CommunityInfoMviModel.UiState, CommunityInfoMviModel.Effect> {
sealed interface Intent
data class UiState(
val community: CommunityModel = CommunityModel(),
)
sealed interface Effect
}

View File

@ -5,27 +5,38 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.core.model.rememberScreenModel
import cafe.adriel.voyager.core.screen.Screen
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.di.getCommunityInfoScreenViewModel
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
import dev.icerock.moko.resources.compose.stringResource
class CommunityInfoScreen(
private val community: CommunityModel,
) : Screen {
@Composable
override fun Content() {
val model = rememberScreenModel { getCommunityInfoScreenViewModel(community) }
model.bindToLifecycle(key)
val uiState by model.uiState.collectAsState()
Column(
modifier = Modifier
.background(MaterialTheme.colorScheme.background)
@ -35,7 +46,8 @@ class CommunityInfoScreen(
end = Spacing.s,
bottom = Spacing.m,
)
.fillMaxHeight(0.9f),
.fillMaxHeight(0.9f)
.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(Spacing.s),
horizontalAlignment = Alignment.CenterHorizontally,
) {
@ -47,26 +59,33 @@ class CommunityInfoScreen(
),
)
Text(
text = stringResource(MR.strings.community_info_title),
style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.onBackground,
)
Text(
modifier = Modifier.padding(start = Spacing.s, top = Spacing.m),
modifier = Modifier.padding(start = Spacing.s, top = Spacing.s),
text = buildString {
append(community.name)
if (community.host.isNotEmpty()) {
append("@${community.host}")
append(uiState.community.name)
if (uiState.community.host.isNotEmpty()) {
append("@${uiState.community.host}")
}
},
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onBackground,
)
Text(
text = community.description,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onBackground,
)
Column(
modifier = Modifier
.verticalScroll(rememberScrollState())
.fillMaxSize()
.padding(
vertical = Spacing.m,
horizontal = Spacing.m,
),
) {
Text(
modifier = Modifier.fillMaxWidth(),
text = uiState.community.description,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onBackground,
)
}
}
}
}

View File

@ -0,0 +1,18 @@
package com.github.diegoberaldin.raccoonforlemmy.core.commonui.communityInfo
import cafe.adriel.voyager.core.model.ScreenModel
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.MviModel
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel
class CommunityInfoViewModel(
private val mvi: DefaultMviModel<CommunityInfoMviModel.Intent, CommunityInfoMviModel.UiState, CommunityInfoMviModel.Effect>,
private val community: CommunityModel,
) : ScreenModel,
MviModel<CommunityInfoMviModel.Intent, CommunityInfoMviModel.UiState, CommunityInfoMviModel.Effect> by mvi {
override fun onStarted() {
mvi.onStarted()
mvi.updateState { it.copy(community = community) }
}
}

View File

@ -169,20 +169,6 @@ class CommunityDetailScreen(
horizontalAlignment = Alignment.CenterHorizontally,
) {
Box {
Icon(
modifier = Modifier
.padding(Spacing.m)
.align(Alignment.TopEnd).onClick {
bottomSheetNavigator.show(
CommunityInfoScreen(
community = uiState.community,
),
)
},
imageVector = Icons.Default.Info,
contentDescription = null,
tint = MaterialTheme.colorScheme.onBackground,
)
val banner = community.banner.orEmpty()
if (banner.isNotEmpty()) {
val painterResource = asyncPainterResource(banner)
@ -197,6 +183,23 @@ class CommunityDetailScreen(
modifier = Modifier.fillMaxWidth().aspectRatio(2.5f),
)
}
Icon(
modifier = Modifier
.padding(
top = Spacing.s,
end = Spacing.s,
)
.align(Alignment.TopEnd).onClick {
bottomSheetNavigator.show(
CommunityInfoScreen(
community = uiState.community,
),
)
},
imageVector = Icons.Default.Info,
contentDescription = null,
tint = MaterialTheme.colorScheme.secondary,
)
}
Column(
modifier = Modifier.graphicsLayer(translationY = -(iconSize / 2).toLocalPixel()),

View File

@ -0,0 +1,92 @@
package com.github.diegoberaldin.raccoonforlemmy.core.commonui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.unit.dp
import com.github.diegoberaldin.racconforlemmy.core.utils.onClick
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.CornerSize
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
@Composable
fun SectionSelector(
modifier: Modifier = Modifier,
titles: List<String> = emptyList(),
currentSection: Int,
onSectionSelected: (Int) -> Unit,
) {
val highlightColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.1f)
Row(
modifier = modifier
.height(34.dp)
.padding(horizontal = Spacing.m)
.fillMaxWidth()
.border(
color = highlightColor,
width = 1.dp,
shape = RoundedCornerShape(CornerSize.m),
),
) {
titles.forEachIndexed { i, title ->
Box(
modifier = Modifier
.weight(1f)
.fillMaxHeight()
.padding(bottom = Spacing.xxs)
.onClick {
onSectionSelected(i)
}
.let {
if (currentSection == i) {
it.background(
color = highlightColor,
shape = when (i) {
0 -> RoundedCornerShape(
topStart = CornerSize.m,
bottomStart = CornerSize.m,
)
titles.lastIndex -> {
RoundedCornerShape(
topEnd = CornerSize.m,
bottomEnd = CornerSize.m,
)
}
else -> RectangleShape
},
)
} else {
it
}
},
contentAlignment = Alignment.Center,
) {
Text(
text = title,
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurface,
)
}
if (i < titles.lastIndex) {
Box(
modifier = Modifier.width(1.dp).fillMaxHeight()
.background(color = highlightColor),
)
}
}
}
}

View File

@ -1,6 +1,8 @@
package com.github.diegoberaldin.raccoonforlemmy.core.commonui.di
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.communityInfo.CommunityInfoMviModel
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.communityInfo.CommunityInfoViewModel
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.communitydetail.CommunityDetailMviModel
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.communitydetail.CommunityDetailViewModel
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.postdetail.PostDetailMviModel
@ -37,6 +39,12 @@ val commonUiModule = module {
hapticFeedback = get(),
)
}
factory { params ->
CommunityInfoViewModel(
mvi = DefaultMviModel(CommunityInfoMviModel.UiState()),
community = params[0],
)
}
factory {
UserDetailViewModel(
mvi = DefaultMviModel(UserDetailMviModel.UiState()),

View File

@ -1,5 +1,6 @@
package com.github.diegoberaldin.raccoonforlemmy.core.commonui.di
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.communityInfo.CommunityInfoViewModel
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.communitydetail.CommunityDetailViewModel
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.postdetail.PostDetailViewModel
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.userdetail.UserDetailViewModel
@ -9,10 +10,21 @@ 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
expect fun getPostDetailScreenViewModel(post: PostModel): PostDetailViewModel
expect fun getPostDetailScreenViewModel(
post: PostModel,
): PostDetailViewModel
expect fun getCommunityDetailScreenViewModel(community: CommunityModel): CommunityDetailViewModel
expect fun getUserDetailScreenViewModel(user: UserModel): UserDetailViewModel
expect fun getCommunityDetailScreenViewModel(
community: CommunityModel,
): CommunityDetailViewModel
expect fun getCommunityInfoScreenViewModel(
community: CommunityModel,
): CommunityInfoViewModel
expect fun getUserDetailScreenViewModel(
user: UserModel,
): UserDetailViewModel
expect fun getUserPostsViewModel(
user: UserModel,

View File

@ -1,104 +0,0 @@
package com.github.diegoberaldin.raccoonforlemmy.core.commonui.userdetail
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.github.diegoberaldin.racconforlemmy.core.utils.onClick
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.CornerSize
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
import dev.icerock.moko.resources.compose.stringResource
@Composable
internal fun SectionSelector(
modifier: Modifier = Modifier,
currentSection: UserDetailSection,
onSectionSelected: (UserDetailSection) -> Unit,
) {
val highlightColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.1f)
Row(
modifier = modifier
.height(34.dp)
.padding(horizontal = Spacing.m)
.fillMaxWidth()
.border(
color = highlightColor,
width = 1.dp,
shape = RoundedCornerShape(CornerSize.m),
),
) {
Box(
modifier = Modifier
.weight(1f)
.fillMaxHeight()
.padding(bottom = Spacing.xxs)
.onClick {
onSectionSelected(UserDetailSection.POSTS)
}
.let {
if (currentSection == UserDetailSection.POSTS) {
it.background(
color = highlightColor,
shape = RoundedCornerShape(
topStart = CornerSize.m,
bottomStart = CornerSize.m,
),
)
} else {
it
}
},
contentAlignment = Alignment.Center,
) {
Text(
text = stringResource(MR.strings.profile_section_posts),
style = MaterialTheme.typography.titleSmall,
)
}
Box(
modifier = Modifier.width(1.dp).fillMaxHeight()
.background(color = highlightColor),
)
Box(
modifier = Modifier
.weight(1f)
.fillMaxHeight()
.padding(bottom = Spacing.xxs)
.onClick {
onSectionSelected(UserDetailSection.COMMENTS)
}
.let {
if (currentSection == UserDetailSection.COMMENTS) {
it.background(
color = highlightColor,
shape = RoundedCornerShape(
topEnd = CornerSize.m,
bottomEnd = CornerSize.m,
),
)
} else {
it
}
},
contentAlignment = Alignment.Center,
) {
Text(
text = stringResource(MR.strings.profile_section_comments),
style = MaterialTheme.typography.titleSmall,
)
}
}
}

View File

@ -17,7 +17,6 @@ import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter

View File

@ -47,14 +47,16 @@ import cafe.adriel.voyager.core.screen.Screen
import com.github.diegoberaldin.racconforlemmy.core.utils.toLocalPixel
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SectionSelector
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.UserCounters
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.UserHeader
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.di.getUserCommentsViewModel
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.postdetail.CommentCard
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.userdetail.SectionSelector
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.userdetail.UserDetailSection
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.userdetail.UserDetailViewModel
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
import dev.icerock.moko.resources.compose.stringResource
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
@ -105,9 +107,17 @@ internal class UserDetailCommentsScreen(
user = uiState.user,
)
SectionSelector(
currentSection = UserDetailSection.COMMENTS,
titles = listOf(
stringResource(MR.strings.profile_section_posts),
stringResource(MR.strings.profile_section_comments),
),
currentSection = 1,
onSectionSelected = {
onSectionSelected(it)
val section = when (it) {
0 -> UserDetailSection.POSTS
else -> UserDetailSection.COMMENTS
}
onSectionSelected(section)
},
)
}

View File

@ -53,13 +53,15 @@ import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.communitydetail.CommunityDetailScreen
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.communitydetail.PostCard
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SectionSelector
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.UserCounters
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.UserHeader
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.di.getUserPostsViewModel
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.userdetail.SectionSelector
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.userdetail.UserDetailSection
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.userdetail.UserDetailViewModel
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
import dev.icerock.moko.resources.compose.stringResource
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
@ -116,9 +118,17 @@ internal class UserDetailPostsScreen(
)
Spacer(modifier = Modifier.height(Spacing.s))
SectionSelector(
currentSection = UserDetailSection.POSTS,
titles = listOf(
stringResource(MR.strings.profile_section_posts),
stringResource(MR.strings.profile_section_comments),
),
currentSection = 0,
onSectionSelected = {
onSectionSelected(it)
val section = when (it) {
0 -> UserDetailSection.POSTS
else -> UserDetailSection.COMMENTS
}
onSectionSelected(section)
},
)
}

View File

@ -1,5 +1,6 @@
package com.github.diegoberaldin.raccoonforlemmy.core.commonui.di
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.communityInfo.CommunityInfoViewModel
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.communitydetail.CommunityDetailViewModel
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.postdetail.PostDetailViewModel
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.userdetail.UserDetailViewModel
@ -18,6 +19,9 @@ actual fun getPostDetailScreenViewModel(post: PostModel): PostDetailViewModel =
actual fun getCommunityDetailScreenViewModel(community: CommunityModel): CommunityDetailViewModel =
PostDetailScreenViewModelHelper.getCommunityDetailModel(community)
actual fun getCommunityInfoScreenViewModel(community: CommunityModel): CommunityInfoViewModel =
PostDetailScreenViewModelHelper.getCommunityInfoModel(community)
actual fun getUserDetailScreenViewModel(user: UserModel): UserDetailViewModel =
PostDetailScreenViewModelHelper.getUserDetailModel(user)
@ -43,6 +47,13 @@ object PostDetailScreenViewModelHelper : KoinComponent {
return model
}
fun getCommunityInfoModel(community: CommunityModel): CommunityInfoViewModel {
val model: CommunityInfoViewModel by inject(
parameters = { parametersOf(community) },
)
return model
}
fun getUserDetailModel(user: UserModel): UserDetailViewModel {
val model: UserDetailViewModel by inject(
parameters = { parametersOf(user) },

View File

@ -1,133 +0,0 @@
package com.github.diegoberaldin.raccoonforlemmy.feature.profile.content.logged
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.github.diegoberaldin.racconforlemmy.core.utils.onClick
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.CornerSize
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
import dev.icerock.moko.resources.compose.stringResource
@Composable
internal fun SectionSelector(
modifier: Modifier = Modifier,
currentSection: ProfileLoggedSection,
onSectionSelected: (ProfileLoggedSection) -> Unit,
) {
val highlightColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.1f)
Row(
modifier = modifier
.height(34.dp)
.padding(horizontal = Spacing.m)
.fillMaxWidth()
.border(
color = highlightColor,
width = 1.dp,
shape = RoundedCornerShape(CornerSize.m),
),
) {
Box(
modifier = Modifier
.weight(1f)
.fillMaxHeight()
.padding(bottom = Spacing.xxs)
.onClick {
onSectionSelected(ProfileLoggedSection.POSTS)
}
.let {
if (currentSection == ProfileLoggedSection.POSTS) {
it.background(
color = highlightColor,
shape = RoundedCornerShape(
topStart = CornerSize.m,
bottomStart = CornerSize.m,
),
)
} else {
it
}
},
contentAlignment = Alignment.Center,
) {
Text(
text = stringResource(MR.strings.profile_section_posts),
style = MaterialTheme.typography.titleSmall,
)
}
Box(
modifier = Modifier.width(1.dp).fillMaxHeight()
.background(color = highlightColor),
)
Box(
modifier = Modifier
.weight(1f)
.fillMaxHeight()
.padding(bottom = Spacing.xxs)
.onClick {
onSectionSelected(ProfileLoggedSection.COMMENTS)
}
.let {
if (currentSection == ProfileLoggedSection.COMMENTS) {
it.background(
color = highlightColor,
)
} else {
it
}
},
contentAlignment = Alignment.Center,
) {
Text(
text = stringResource(MR.strings.profile_section_comments),
style = MaterialTheme.typography.titleSmall,
)
}
Box(
modifier = Modifier.width(1.dp).fillMaxHeight()
.background(color = highlightColor),
)
Box(
modifier = Modifier
.weight(1f)
.fillMaxHeight()
.padding(bottom = Spacing.xxs)
.onClick {
onSectionSelected(ProfileLoggedSection.SAVED)
}
.let {
if (currentSection == ProfileLoggedSection.SAVED) {
it.background(
color = highlightColor,
shape = RoundedCornerShape(
topEnd = CornerSize.m,
bottomEnd = CornerSize.m,
),
)
} else {
it
}
},
contentAlignment = Alignment.Center,
) {
Text(
text = stringResource(MR.strings.profile_section_saved),
style = MaterialTheme.typography.titleSmall,
)
}
}
}

View File

@ -29,12 +29,14 @@ import cafe.adriel.voyager.core.screen.Screen
import com.github.diegoberaldin.racconforlemmy.core.utils.toLocalPixel
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SectionSelector
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.UserCounters
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.UserHeader
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
import com.github.diegoberaldin.raccoonforlemmy.feature.profile.content.logged.ProfileLoggedSection
import com.github.diegoberaldin.raccoonforlemmy.feature.profile.content.logged.SectionSelector
import com.github.diegoberaldin.raccoonforlemmy.feature.profile.di.getProfileCommentsViewModel
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
import dev.icerock.moko.resources.compose.stringResource
internal class ProfileCommentsScreen(
private val modifier: Modifier = Modifier,
@ -70,9 +72,19 @@ internal class ProfileCommentsScreen(
)
Spacer(modifier = Modifier.height(Spacing.s))
SectionSelector(
currentSection = ProfileLoggedSection.COMMENTS,
titles = listOf(
stringResource(MR.strings.profile_section_posts),
stringResource(MR.strings.profile_section_comments),
stringResource(MR.strings.profile_section_saved),
),
currentSection = 1,
onSectionSelected = {
onSectionSelected(it)
val section = when (it) {
0 -> ProfileLoggedSection.POSTS
1 -> ProfileLoggedSection.COMMENTS
else -> ProfileLoggedSection.SAVED
}
onSectionSelected(section)
},
)
}

View File

@ -32,12 +32,14 @@ import com.github.diegoberaldin.racconforlemmy.core.utils.toLocalPixel
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.communitydetail.CommunityDetailScreen
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SectionSelector
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.UserCounters
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.UserHeader
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
import com.github.diegoberaldin.raccoonforlemmy.feature.profile.content.logged.ProfileLoggedSection
import com.github.diegoberaldin.raccoonforlemmy.feature.profile.content.logged.SectionSelector
import com.github.diegoberaldin.raccoonforlemmy.feature.profile.di.getProfilePostsViewModel
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
import dev.icerock.moko.resources.compose.stringResource
internal class ProfilePostsScreen(
private val modifier: Modifier = Modifier,
@ -78,9 +80,19 @@ internal class ProfilePostsScreen(
)
Spacer(modifier = Modifier.height(Spacing.s))
SectionSelector(
currentSection = ProfileLoggedSection.POSTS,
titles = listOf(
stringResource(MR.strings.profile_section_posts),
stringResource(MR.strings.profile_section_comments),
stringResource(MR.strings.profile_section_saved),
),
currentSection = 0,
onSectionSelected = {
onSectionSelected(it)
val section = when (it) {
0 -> ProfileLoggedSection.POSTS
1 -> ProfileLoggedSection.COMMENTS
else -> ProfileLoggedSection.SAVED
}
onSectionSelected(section)
},
)
}

View File

@ -30,14 +30,16 @@ import com.github.diegoberaldin.racconforlemmy.core.utils.toLocalPixel
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.communitydetail.CommunityDetailScreen
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.SectionSelector
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.UserCounters
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.UserHeader
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
import com.github.diegoberaldin.raccoonforlemmy.feature.profile.content.logged.ProfileLoggedSection
import com.github.diegoberaldin.raccoonforlemmy.feature.profile.content.logged.SectionSelector
import com.github.diegoberaldin.raccoonforlemmy.feature.profile.content.logged.posts.ProfilePostCard
import com.github.diegoberaldin.raccoonforlemmy.feature.profile.content.logged.posts.ProfilePostsMviModel
import com.github.diegoberaldin.raccoonforlemmy.feature.profile.di.getProfilePostsViewModel
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
import dev.icerock.moko.resources.compose.stringResource
internal class ProfileSavedScreen(
private val modifier: Modifier = Modifier,
@ -78,9 +80,19 @@ internal class ProfileSavedScreen(
user = user,
)
SectionSelector(
currentSection = ProfileLoggedSection.SAVED,
titles = listOf(
stringResource(MR.strings.profile_section_posts),
stringResource(MR.strings.profile_section_comments),
stringResource(MR.strings.profile_section_saved),
),
currentSection = 2,
onSectionSelected = {
onSectionSelected(it)
val section = when (it) {
0 -> ProfileLoggedSection.POSTS
1 -> ProfileLoggedSection.COMMENTS
else -> ProfileLoggedSection.SAVED
}
onSectionSelected(section)
},
)
}

View File

@ -76,5 +76,6 @@
<string name="community_button_subscribe">Subscribe</string>
<string name="community_button_subscribed">Subscribed</string>
<string name="community_button_pending">Pending</string>
<string name="community_info_title">Community info</string>
<string name="community_info_section_info">Info</string>
<string name="community_info_section_communities">Communities</string>
</resources>