mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-09 12:08:47 +01:00
fix(navigation): remove further callbacks and use Serializable interface
This commit is contained in:
parent
9f59398ec6
commit
0f3935c7e0
@ -46,7 +46,6 @@ kotlin {
|
||||
implementation(libs.voyager.bottomsheet)
|
||||
implementation(libs.voyager.tab)
|
||||
implementation(libs.kamel)
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
|
||||
implementation(projects.coreUtils)
|
||||
implementation(projects.coreAppearance)
|
||||
|
@ -36,12 +36,11 @@ import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class CommunityInfoScreen(
|
||||
private val serialCommunity: String,
|
||||
private val community: CommunityModel,
|
||||
) : Screen {
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val community = remember { Json.decodeFromString<CommunityModel>(serialCommunity) }
|
||||
val model = rememberScreenModel { getCommunityInfoViewModel(community) }
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
|
@ -98,14 +98,13 @@ import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class CommunityDetailScreen(
|
||||
private val serialCommunity: String,
|
||||
private val community: CommunityModel,
|
||||
private val otherInstance: String = "",
|
||||
) : Screen {
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterialApi::class)
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val community = remember { Json.decodeFromString<CommunityModel>(serialCommunity) }
|
||||
val model = rememberScreenModel(community.id.toString() + otherInstance) {
|
||||
getCommunityDetailViewModel(
|
||||
community = community,
|
||||
@ -268,14 +267,14 @@ class CommunityDetailScreen(
|
||||
}
|
||||
Icon(
|
||||
modifier = Modifier.padding(
|
||||
top = Spacing.s,
|
||||
end = Spacing.s,
|
||||
).background(
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
shape = CircleShape,
|
||||
).padding(Spacing.s).align(Alignment.TopEnd).onClick {
|
||||
optionsExpanded = true
|
||||
},
|
||||
top = Spacing.s,
|
||||
end = Spacing.s,
|
||||
).background(
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
shape = CircleShape,
|
||||
).padding(Spacing.s).align(Alignment.TopEnd).onClick {
|
||||
optionsExpanded = true
|
||||
},
|
||||
imageVector = Icons.Rounded.MoreVert,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onPrimary,
|
||||
@ -297,9 +296,7 @@ class CommunityDetailScreen(
|
||||
).onClick {
|
||||
optionsExpanded = false
|
||||
bottomSheetNavigator.show(
|
||||
CommunityInfoScreen(
|
||||
serialCommunity = Json.encodeToString(community)
|
||||
),
|
||||
CommunityInfoScreen(community),
|
||||
)
|
||||
},
|
||||
text = stringResource(MR.strings.community_detail_info),
|
||||
@ -471,16 +468,12 @@ class CommunityDetailScreen(
|
||||
PostCard(
|
||||
modifier = Modifier.onClick {
|
||||
navigator?.push(
|
||||
PostDetailScreen(
|
||||
serialPost = Json.encodeToString(post),
|
||||
),
|
||||
PostDetailScreen(post),
|
||||
)
|
||||
},
|
||||
onOpenCreator = { user ->
|
||||
navigator?.push(
|
||||
UserDetailScreen(
|
||||
serialUser = Json.encodeToString(user),
|
||||
),
|
||||
UserDetailScreen(user),
|
||||
)
|
||||
},
|
||||
post = post,
|
||||
|
@ -148,7 +148,7 @@ class InstanceInfoScreen(
|
||||
modifier = Modifier.onClick {
|
||||
navigator?.push(
|
||||
CommunityDetailScreen(
|
||||
serialCommunity = Json.encodeToString(it),
|
||||
community = it,
|
||||
otherInstance = instanceName,
|
||||
),
|
||||
)
|
||||
|
@ -92,15 +92,12 @@ import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class PostDetailScreen(
|
||||
private val serialPost: String,
|
||||
private val post: PostModel,
|
||||
) : Screen {
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterialApi::class)
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val post = remember {
|
||||
Json.decodeFromString<PostModel>(serialPost)
|
||||
}
|
||||
val model = rememberScreenModel { getPostDetailViewModel(post) }
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
@ -244,16 +241,12 @@ class PostDetailScreen(
|
||||
creator = post.creator?.copy(avatar = null),
|
||||
onOpenCommunity = { community ->
|
||||
navigator?.push(
|
||||
CommunityDetailScreen(
|
||||
serialCommunity = Json.encodeToString(community),
|
||||
),
|
||||
CommunityDetailScreen(community),
|
||||
)
|
||||
},
|
||||
onOpenCreator = { user ->
|
||||
navigator?.push(
|
||||
UserDetailScreen(
|
||||
serialUser = Json.encodeToString(user),
|
||||
),
|
||||
UserDetailScreen(user),
|
||||
)
|
||||
},
|
||||
)
|
||||
|
@ -47,17 +47,14 @@ import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class UserDetailScreen(
|
||||
private val serialUser: String,
|
||||
private val user: UserModel,
|
||||
) : Screen {
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val user = remember { Json.decodeFromString<UserModel>(serialUser) }
|
||||
val model = rememberScreenModel(user.id.toString()) { getUserDetailViewModel(user) }
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
@ -131,24 +128,28 @@ class UserDetailScreen(
|
||||
verticalArrangement = Arrangement.spacedBy(Spacing.s),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
val postsScreen = remember {
|
||||
UserDetailPostsScreen(user, key)
|
||||
}
|
||||
val commentsScreen = remember {
|
||||
UserDetailCommentsScreen(user, key)
|
||||
}
|
||||
val screens = listOf(
|
||||
UserDetailPostsScreen(
|
||||
serialUser = Json.encodeToString(user),
|
||||
).apply {
|
||||
parentModel = model
|
||||
onSectionSelected = {
|
||||
model.reduce(UserDetailMviModel.Intent.SelectTab(it))
|
||||
}
|
||||
},
|
||||
UserDetailCommentsScreen(
|
||||
serialUser = Json.encodeToString(user),
|
||||
).apply {
|
||||
parentModel = model
|
||||
onSectionSelected = {
|
||||
model.reduce(UserDetailMviModel.Intent.SelectTab(it))
|
||||
}
|
||||
}
|
||||
postsScreen,
|
||||
commentsScreen,
|
||||
)
|
||||
LaunchedEffect(key) {
|
||||
notificationCenter.addObserver({
|
||||
(it as? UserDetailSection)?.also { section ->
|
||||
model.reduce(UserDetailMviModel.Intent.SelectTab(section))
|
||||
}
|
||||
}, key, postsScreen.key)
|
||||
notificationCenter.addObserver({
|
||||
(it as? UserDetailSection)?.also { section ->
|
||||
model.reduce(UserDetailMviModel.Intent.SelectTab(section))
|
||||
}
|
||||
}, key, commentsScreen.key)
|
||||
}
|
||||
TabNavigator(screens.first()) {
|
||||
CurrentScreen()
|
||||
|
||||
|
@ -27,7 +27,6 @@ import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
@ -51,26 +50,20 @@ import com.github.diegoberaldin.raccoonforlemmy.core.commonui.createcomment.Crea
|
||||
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.UserDetailSection
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.userdetail.UserDetailViewModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.di.getNotificationCenter
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.PostModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.SortType
|
||||
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
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
internal class UserDetailCommentsScreen(
|
||||
private val serialUser: String,
|
||||
private val user: UserModel,
|
||||
private val parentKey: String,
|
||||
) : Tab {
|
||||
|
||||
var onSectionSelected: ((UserDetailSection) -> Unit)? = null
|
||||
var parentModel: UserDetailViewModel? = null
|
||||
|
||||
override val options: TabOptions
|
||||
@Composable get() {
|
||||
return TabOptions(1u, "")
|
||||
@ -79,7 +72,6 @@ internal class UserDetailCommentsScreen(
|
||||
@OptIn(ExperimentalMaterialApi::class)
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val user = remember { Json.decodeFromString<UserModel>(serialUser) }
|
||||
val model = rememberScreenModel(
|
||||
user.id.toString(),
|
||||
) { getUserCommentsViewModel(user) }
|
||||
@ -88,17 +80,16 @@ internal class UserDetailCommentsScreen(
|
||||
val bottomSheetNavigator = LocalBottomSheetNavigator.current
|
||||
val notificationCenter = remember { getNotificationCenter() }
|
||||
DisposableEffect(key) {
|
||||
notificationCenter.addObserver({
|
||||
(it as? SortType)?.also { sortType ->
|
||||
model.reduce(UserCommentsMviModel.Intent.ChangeSort(sortType))
|
||||
}
|
||||
}, key, parentKey)
|
||||
onDispose {
|
||||
notificationCenter.removeObserver(key)
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(parentModel) {
|
||||
parentModel?.uiState?.map { it.sortType }?.distinctUntilChanged()?.onEach { sortType ->
|
||||
model.reduce(UserCommentsMviModel.Intent.ChangeSort(sortType))
|
||||
}?.launchIn(this)
|
||||
}
|
||||
|
||||
val pullRefreshState = rememberPullRefreshState(uiState.refreshing, {
|
||||
model.reduce(UserCommentsMviModel.Intent.Refresh)
|
||||
})
|
||||
@ -130,7 +121,9 @@ internal class UserDetailCommentsScreen(
|
||||
0 -> UserDetailSection.POSTS
|
||||
else -> UserDetailSection.COMMENTS
|
||||
}
|
||||
onSectionSelected?.invoke(section)
|
||||
notificationCenter.getObserver(key)?.also { obsever ->
|
||||
obsever.invoke(section)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
@ -56,25 +55,19 @@ import com.github.diegoberaldin.raccoonforlemmy.core.commonui.di.getUserPostsVie
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.image.ZoomableImageScreen
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.postdetail.PostDetailScreen
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.userdetail.UserDetailSection
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.userdetail.UserDetailViewModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.di.getNotificationCenter
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.SortType
|
||||
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
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
internal class UserDetailPostsScreen(
|
||||
private val serialUser: String,
|
||||
private val user: UserModel,
|
||||
private val parentKey: String,
|
||||
) : Tab {
|
||||
|
||||
var onSectionSelected: ((UserDetailSection) -> Unit)? = null
|
||||
var parentModel: UserDetailViewModel? = null
|
||||
|
||||
override val options: TabOptions
|
||||
@Composable get() {
|
||||
return TabOptions(0u, "")
|
||||
@ -83,7 +76,6 @@ internal class UserDetailPostsScreen(
|
||||
@OptIn(ExperimentalMaterialApi::class)
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val user = remember { Json.decodeFromString<UserModel>(serialUser) }
|
||||
val model = rememberScreenModel(
|
||||
user.id.toString(),
|
||||
) {
|
||||
@ -97,17 +89,17 @@ internal class UserDetailPostsScreen(
|
||||
val bottomSheetNavigator = LocalBottomSheetNavigator.current
|
||||
val notificationCenter = remember { getNotificationCenter() }
|
||||
DisposableEffect(key) {
|
||||
notificationCenter.addObserver({
|
||||
(it as? SortType)?.also { sortType ->
|
||||
model.reduce(UserPostsMviModel.Intent.ChangeSort(sortType))
|
||||
}
|
||||
}, key, parentKey)
|
||||
|
||||
onDispose {
|
||||
notificationCenter.removeObserver(key)
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(parentModel) {
|
||||
parentModel?.uiState?.map { it.sortType }?.distinctUntilChanged()?.onEach { sortType ->
|
||||
model.reduce(UserPostsMviModel.Intent.ChangeSort(sortType))
|
||||
}?.launchIn(this)
|
||||
}
|
||||
|
||||
val pullRefreshState = rememberPullRefreshState(uiState.refreshing, {
|
||||
model.reduce(UserPostsMviModel.Intent.Refresh)
|
||||
})
|
||||
@ -140,7 +132,9 @@ internal class UserDetailPostsScreen(
|
||||
0 -> UserDetailSection.POSTS
|
||||
else -> UserDetailSection.COMMENTS
|
||||
}
|
||||
onSectionSelected?.invoke(section)
|
||||
notificationCenter.getObserver(key)?.also { obsever ->
|
||||
obsever.invoke(section)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -214,9 +208,7 @@ internal class UserDetailPostsScreen(
|
||||
PostCard(
|
||||
modifier = Modifier.onClick {
|
||||
navigator?.push(
|
||||
PostDetailScreen(
|
||||
serialPost = Json.encodeToString(post),
|
||||
),
|
||||
PostDetailScreen(post),
|
||||
)
|
||||
},
|
||||
post = post,
|
||||
@ -247,9 +239,7 @@ internal class UserDetailPostsScreen(
|
||||
},
|
||||
onOpenCommunity = { community ->
|
||||
navigator?.push(
|
||||
CommunityDetailScreen(
|
||||
serialCommunity = Json.encodeToString(community),
|
||||
),
|
||||
CommunityDetailScreen(community),
|
||||
)
|
||||
},
|
||||
onReply = {
|
||||
|
@ -3,8 +3,6 @@ plugins {
|
||||
alias(libs.plugins.android.library)
|
||||
alias(libs.plugins.compose)
|
||||
alias(libs.plugins.native.cocoapods)
|
||||
alias(libs.plugins.ksp)
|
||||
alias(libs.plugins.kotlinx.serialization)
|
||||
}
|
||||
|
||||
@OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class)
|
||||
@ -38,9 +36,6 @@ kotlin {
|
||||
implementation(compose.runtime)
|
||||
implementation(compose.foundation)
|
||||
implementation(compose.materialIconsExtended)
|
||||
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
|
||||
implementation(projects.resources)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,3 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data
|
||||
|
||||
actual typealias JavaSerializable = java.io.Serializable
|
@ -1,8 +1,5 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class CommentModel(
|
||||
val id: Int = 0,
|
||||
val postId: Int = 0,
|
||||
@ -16,6 +13,6 @@ data class CommentModel(
|
||||
val comments: Int? = null,
|
||||
val path: String = "",
|
||||
val children: List<CommentModel>? = null,
|
||||
) {
|
||||
val depth: Int = (path.split(".").size - 1).coerceAtLeast(0)
|
||||
) : JavaSerializable {
|
||||
val depth: Int get() = (path.split(".").size - 1).coerceAtLeast(0)
|
||||
}
|
||||
|
@ -1,8 +1,5 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class CommunityModel(
|
||||
val id: Int = 0,
|
||||
val name: String = "",
|
||||
@ -14,4 +11,4 @@ data class CommunityModel(
|
||||
val subscribed: Boolean? = null,
|
||||
val instanceUrl: String = "",
|
||||
val nsfw: Boolean = false,
|
||||
)
|
||||
) : JavaSerializable
|
||||
|
@ -6,4 +6,4 @@ import kotlinx.serialization.Serializable
|
||||
data class MetadataModel(
|
||||
val title: String = "",
|
||||
val description: String = "",
|
||||
)
|
||||
): JavaSerializable
|
||||
|
@ -1,8 +1,5 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class PersonMentionModel(
|
||||
val id: Int = 0,
|
||||
val post: PostModel,
|
||||
@ -14,4 +11,4 @@ data class PersonMentionModel(
|
||||
val saved: Boolean,
|
||||
val isOwnPost: Boolean = false,
|
||||
val publishDate: String? = null,
|
||||
)
|
||||
) : JavaSerializable
|
||||
|
@ -1,8 +1,5 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class PostModel(
|
||||
val id: Int = 0,
|
||||
val title: String = "",
|
||||
@ -18,4 +15,4 @@ data class PostModel(
|
||||
val myVote: Int = 0,
|
||||
val publishDate: String? = null,
|
||||
val nsfw: Boolean = false,
|
||||
)
|
||||
) : JavaSerializable
|
||||
|
@ -11,4 +11,4 @@ data class UserModel(
|
||||
val host: String = "",
|
||||
val score: UserScoreModel? = null,
|
||||
val accountAge: String = "",
|
||||
)
|
||||
) : JavaSerializable
|
||||
|
@ -6,4 +6,4 @@ import kotlinx.serialization.Serializable
|
||||
data class UserScoreModel(
|
||||
val postScore: Int = 0,
|
||||
val commentScore: Int = 0,
|
||||
)
|
||||
) : JavaSerializable
|
@ -0,0 +1,3 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data
|
||||
|
||||
expect interface JavaSerializable
|
@ -0,0 +1,3 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data
|
||||
|
||||
actual interface JavaSerializable
|
@ -0,0 +1,3 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data
|
||||
|
||||
actual interface JavaSerializable
|
@ -47,7 +47,6 @@ kotlin {
|
||||
implementation(libs.voyager.tab)
|
||||
implementation(libs.voyager.bottomsheet)
|
||||
implementation(libs.kamel)
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
|
||||
implementation(projects.coreAppearance)
|
||||
implementation(projects.coreArchitecture)
|
||||
|
@ -209,25 +209,19 @@ class PostListScreen : Screen {
|
||||
PostCard(
|
||||
modifier = Modifier.onClick {
|
||||
navigator?.push(
|
||||
PostDetailScreen(
|
||||
serialPost = Json.encodeToString(post),
|
||||
),
|
||||
PostDetailScreen(post),
|
||||
)
|
||||
},
|
||||
post = post,
|
||||
blurNsfw = uiState.blurNsfw,
|
||||
onOpenCommunity = { community ->
|
||||
navigator?.push(
|
||||
CommunityDetailScreen(
|
||||
serialCommunity = Json.encodeToString(community),
|
||||
),
|
||||
CommunityDetailScreen(community),
|
||||
)
|
||||
},
|
||||
onOpenCreator = { user ->
|
||||
navigator?.push(
|
||||
UserDetailScreen(
|
||||
serialUser = Json.encodeToString(user),
|
||||
),
|
||||
UserDetailScreen(user),
|
||||
)
|
||||
},
|
||||
onUpVote = {
|
||||
|
@ -47,7 +47,6 @@ kotlin {
|
||||
implementation(libs.voyager.tab)
|
||||
implementation(libs.voyager.bottomsheet)
|
||||
implementation(libs.kamel)
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
|
||||
implementation(projects.resources)
|
||||
implementation(projects.coreArchitecture)
|
||||
|
@ -162,23 +162,17 @@ class InboxMentionsScreen : Tab {
|
||||
mention = mention,
|
||||
onOpenPost = { post ->
|
||||
navigator?.push(
|
||||
PostDetailScreen(
|
||||
serialPost = Json.encodeToString(post),
|
||||
),
|
||||
PostDetailScreen(post),
|
||||
)
|
||||
},
|
||||
onOpenCreator = { user ->
|
||||
navigator?.push(
|
||||
UserDetailScreen(
|
||||
serialUser = Json.encodeToString(user),
|
||||
),
|
||||
UserDetailScreen(user),
|
||||
)
|
||||
},
|
||||
onOpenCommunity = { community ->
|
||||
navigator?.push(
|
||||
CommunityDetailScreen(
|
||||
serialCommunity = Json.encodeToString(community),
|
||||
),
|
||||
CommunityDetailScreen(community),
|
||||
)
|
||||
},
|
||||
)
|
||||
|
@ -133,23 +133,17 @@ class InboxRepliesScreen : Tab {
|
||||
mention = mention,
|
||||
onOpenPost = { post ->
|
||||
navigator?.push(
|
||||
PostDetailScreen(
|
||||
serialPost = Json.encodeToString(post),
|
||||
),
|
||||
PostDetailScreen(post),
|
||||
)
|
||||
},
|
||||
onOpenCreator = { user ->
|
||||
navigator?.push(
|
||||
UserDetailScreen(
|
||||
serialUser = Json.encodeToString(user),
|
||||
),
|
||||
UserDetailScreen(user),
|
||||
)
|
||||
},
|
||||
onOpenCommunity = { community ->
|
||||
navigator?.push(
|
||||
CommunityDetailScreen(
|
||||
serialCommunity = Json.encodeToString(community),
|
||||
),
|
||||
CommunityDetailScreen(community),
|
||||
)
|
||||
},
|
||||
)
|
||||
|
@ -49,7 +49,6 @@ kotlin {
|
||||
implementation(libs.kamel)
|
||||
implementation(libs.ktor.cio)
|
||||
implementation(libs.kamel)
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
|
||||
implementation(projects.resources)
|
||||
implementation(projects.coreArchitecture)
|
||||
|
@ -5,9 +5,11 @@ import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import cafe.adriel.voyager.core.model.rememberScreenModel
|
||||
@ -18,6 +20,7 @@ import cafe.adriel.voyager.navigator.tab.TabNavigator
|
||||
import cafe.adriel.voyager.navigator.tab.TabOptions
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.di.getNotificationCenter
|
||||
import com.github.diegoberaldin.raccoonforlemmy.feature.profile.content.logged.comments.ProfileCommentsScreen
|
||||
import com.github.diegoberaldin.raccoonforlemmy.feature.profile.content.logged.posts.ProfilePostsScreen
|
||||
import com.github.diegoberaldin.raccoonforlemmy.feature.profile.content.logged.saved.ProfileSavedScreen
|
||||
@ -26,8 +29,6 @@ import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
internal object ProfileLoggedScreen : Tab {
|
||||
|
||||
@ -47,31 +48,39 @@ internal object ProfileLoggedScreen : Tab {
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val user = uiState.user
|
||||
if (user != null) {
|
||||
val screens = listOf(
|
||||
ProfilePostsScreen(
|
||||
serialUser = Json.encodeToString(user),
|
||||
).apply {
|
||||
onSectionSelected = {
|
||||
model.reduce(ProfileLoggedMviModel.Intent.SelectTab(it))
|
||||
}
|
||||
},
|
||||
ProfileCommentsScreen(
|
||||
serialUser = Json.encodeToString(user),
|
||||
).apply {
|
||||
onSectionSelected = {
|
||||
model.reduce(ProfileLoggedMviModel.Intent.SelectTab(it))
|
||||
}
|
||||
},
|
||||
ProfileSavedScreen(
|
||||
serialUser = Json.encodeToString(user),
|
||||
).apply {
|
||||
onSectionSelected = {
|
||||
model.reduce(ProfileLoggedMviModel.Intent.SelectTab(it))
|
||||
}
|
||||
},
|
||||
)
|
||||
val notificationCenter = remember { getNotificationCenter() }
|
||||
DisposableEffect(key) {
|
||||
onDispose {
|
||||
notificationCenter.removeObserver(key)
|
||||
}
|
||||
}
|
||||
|
||||
if (user != null) {
|
||||
val postsScreen = remember { ProfilePostsScreen(user) }
|
||||
val commentsScreen = remember { ProfileCommentsScreen(user) }
|
||||
val savedScreen = remember { ProfileSavedScreen(user) }
|
||||
LaunchedEffect(key) {
|
||||
notificationCenter.addObserver({
|
||||
(it as? ProfileLoggedSection)?.also { value ->
|
||||
model.reduce(ProfileLoggedMviModel.Intent.SelectTab(value))
|
||||
}
|
||||
}, key, postsScreen.key)
|
||||
notificationCenter.addObserver({
|
||||
(it as? ProfileLoggedSection)?.also { value ->
|
||||
model.reduce(ProfileLoggedMviModel.Intent.SelectTab(value))
|
||||
}
|
||||
}, key, commentsScreen.key)
|
||||
notificationCenter.addObserver({
|
||||
(it as? ProfileLoggedSection)?.also { value ->
|
||||
model.reduce(ProfileLoggedMviModel.Intent.SelectTab(value))
|
||||
}
|
||||
}, key, savedScreen.key)
|
||||
}
|
||||
val screens = listOf(
|
||||
postsScreen,
|
||||
commentsScreen,
|
||||
savedScreen,
|
||||
)
|
||||
TabNavigator(screens.first()) {
|
||||
CurrentScreen()
|
||||
val navigator = LocalTabNavigator.current
|
||||
|
@ -34,6 +34,7 @@ import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycl
|
||||
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.notifications.di.getNotificationCenter
|
||||
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.di.getProfileCommentsViewModel
|
||||
@ -42,11 +43,9 @@ import dev.icerock.moko.resources.compose.stringResource
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
internal class ProfileCommentsScreen(
|
||||
private val serialUser: String,
|
||||
private val user: UserModel,
|
||||
) : Tab {
|
||||
|
||||
var onSectionSelected: ((ProfileLoggedSection) -> Unit)? = null
|
||||
|
||||
override val options: TabOptions
|
||||
@Composable get() {
|
||||
return TabOptions(1u, "")
|
||||
@ -55,11 +54,10 @@ internal class ProfileCommentsScreen(
|
||||
@OptIn(ExperimentalMaterialApi::class)
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val user = remember { Json.decodeFromString<UserModel>(serialUser) }
|
||||
val model = rememberScreenModel { getProfileCommentsViewModel(user) }
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
|
||||
val notificationCenter = remember { getNotificationCenter() }
|
||||
val pullRefreshState = rememberPullRefreshState(uiState.refreshing, {
|
||||
model.reduce(ProfileCommentsMviModel.Intent.Refresh)
|
||||
})
|
||||
@ -94,7 +92,9 @@ internal class ProfileCommentsScreen(
|
||||
1 -> ProfileLoggedSection.COMMENTS
|
||||
else -> ProfileLoggedSection.SAVED
|
||||
}
|
||||
onSectionSelected?.invoke(section)
|
||||
notificationCenter.getObserver(key)?.also { observer ->
|
||||
observer.invoke(section)
|
||||
}
|
||||
},
|
||||
)
|
||||
Spacer(modifier = Modifier.height(Spacing.m))
|
||||
|
@ -39,20 +39,16 @@ import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.UserHea
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.di.getNavigationCoordinator
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.image.ZoomableImageScreen
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.postdetail.PostDetailScreen
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.di.getNotificationCenter
|
||||
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.di.getProfilePostsViewModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
internal class ProfilePostsScreen(
|
||||
private val serialUser: String,
|
||||
private val user: UserModel,
|
||||
) : Tab {
|
||||
|
||||
var onSectionSelected: ((ProfileLoggedSection) -> Unit)? = null
|
||||
|
||||
override val options: TabOptions
|
||||
@Composable get() {
|
||||
return TabOptions(0u, "")
|
||||
@ -61,7 +57,6 @@ internal class ProfilePostsScreen(
|
||||
@OptIn(ExperimentalMaterialApi::class)
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val user = remember { Json.decodeFromString<UserModel>(serialUser) }
|
||||
val model = rememberScreenModel {
|
||||
getProfilePostsViewModel(
|
||||
user = user,
|
||||
@ -70,7 +65,7 @@ internal class ProfilePostsScreen(
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigator = remember { getNavigationCoordinator().getRootNavigator() }
|
||||
|
||||
val notificationCenter = remember { getNotificationCenter() }
|
||||
val pullRefreshState = rememberPullRefreshState(uiState.refreshing, {
|
||||
model.reduce(ProfilePostsMviModel.Intent.Refresh)
|
||||
})
|
||||
@ -105,7 +100,9 @@ internal class ProfilePostsScreen(
|
||||
1 -> ProfileLoggedSection.COMMENTS
|
||||
else -> ProfileLoggedSection.SAVED
|
||||
}
|
||||
onSectionSelected?.invoke(section)
|
||||
notificationCenter.getObserver(key)?.also { observer ->
|
||||
observer.invoke(section)
|
||||
}
|
||||
},
|
||||
)
|
||||
Spacer(modifier = Modifier.height(Spacing.m))
|
||||
@ -115,17 +112,13 @@ internal class ProfilePostsScreen(
|
||||
ProfilePostCard(
|
||||
modifier = Modifier.onClick {
|
||||
navigator?.push(
|
||||
PostDetailScreen(
|
||||
serialPost = Json.encodeToString(post),
|
||||
),
|
||||
PostDetailScreen(post),
|
||||
)
|
||||
},
|
||||
post = post,
|
||||
onOpenCommunity = { community ->
|
||||
navigator?.push(
|
||||
CommunityDetailScreen(
|
||||
serialCommunity = Json.encodeToString(community),
|
||||
),
|
||||
CommunityDetailScreen(community),
|
||||
)
|
||||
},
|
||||
onImageClick = { url ->
|
||||
|
@ -37,6 +37,7 @@ import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.UserCou
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.UserHeader
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.di.getNavigationCoordinator
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.image.ZoomableImageScreen
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.di.getNotificationCenter
|
||||
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.posts.ProfilePostCard
|
||||
@ -44,15 +45,11 @@ import com.github.diegoberaldin.raccoonforlemmy.feature.profile.content.logged.p
|
||||
import com.github.diegoberaldin.raccoonforlemmy.feature.profile.di.getProfilePostsViewModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
internal class ProfileSavedScreen(
|
||||
private val serialUser: String,
|
||||
private val user: UserModel,
|
||||
) : Tab {
|
||||
|
||||
var onSectionSelected: ((ProfileLoggedSection) -> Unit)? = null
|
||||
|
||||
override val options: TabOptions
|
||||
@Composable get() {
|
||||
return TabOptions(0u, "")
|
||||
@ -61,7 +58,6 @@ internal class ProfileSavedScreen(
|
||||
@OptIn(ExperimentalMaterialApi::class)
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val user = remember { Json.decodeFromString<UserModel>(serialUser) }
|
||||
val model = rememberScreenModel {
|
||||
getProfilePostsViewModel(
|
||||
user = user,
|
||||
@ -71,7 +67,7 @@ internal class ProfileSavedScreen(
|
||||
model.bindToLifecycle(key)
|
||||
val uiState by model.uiState.collectAsState()
|
||||
val navigator = remember { getNavigationCoordinator().getRootNavigator() }
|
||||
|
||||
val notificationCenter = remember { getNotificationCenter() }
|
||||
val pullRefreshState = rememberPullRefreshState(uiState.refreshing, {
|
||||
model.reduce(ProfilePostsMviModel.Intent.Refresh)
|
||||
})
|
||||
@ -106,7 +102,9 @@ internal class ProfileSavedScreen(
|
||||
1 -> ProfileLoggedSection.COMMENTS
|
||||
else -> ProfileLoggedSection.SAVED
|
||||
}
|
||||
onSectionSelected?.invoke(section)
|
||||
notificationCenter.getObserver(key)?.also { observer ->
|
||||
observer.invoke(section)
|
||||
}
|
||||
},
|
||||
)
|
||||
Spacer(modifier = Modifier.height(Spacing.m))
|
||||
@ -117,9 +115,7 @@ internal class ProfileSavedScreen(
|
||||
post = post,
|
||||
onOpenCommunity = { community ->
|
||||
navigator?.push(
|
||||
CommunityDetailScreen(
|
||||
serialCommunity = Json.encodeToString(community),
|
||||
),
|
||||
CommunityDetailScreen(community),
|
||||
)
|
||||
},
|
||||
onImageClick = { url ->
|
||||
|
@ -47,7 +47,6 @@ kotlin {
|
||||
implementation(libs.voyager.tab)
|
||||
implementation(libs.voyager.bottomsheet)
|
||||
implementation(libs.kamel)
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
|
||||
implementation(projects.coreArchitecture)
|
||||
implementation(projects.coreAppearance)
|
||||
|
@ -170,9 +170,7 @@ class CommunityListScreen : Screen {
|
||||
CommunityItem(
|
||||
modifier = Modifier.fillMaxWidth().onClick {
|
||||
navigator?.push(
|
||||
CommunityDetailScreen(
|
||||
serialCommunity = Json.encodeToString(community),
|
||||
),
|
||||
CommunityDetailScreen(community),
|
||||
)
|
||||
},
|
||||
community = community,
|
||||
|
Loading…
x
Reference in New Issue
Block a user