Refactor: Extract RootScreen from MainActivity and fix reply message user

This commit refactors the UI composition logic by extracting it from `MainActivity` into a new, dedicated `RootScreen` composable. This improves the separation of concerns and simplifies `MainActivity`.

Additionally, a bug has been fixed where a replied-to message would incorrectly display the author of the parent message instead of its own author.

Key changes:
- Moved theme setup, permission handling, Long-Poll/Online service management, and navigation graph hosting into the new `RootScreen.kt`.
- `MainActivity` is now significantly simplified, delegating its UI composition to `RootScreen`.
- Corrected the user and group assignment for `replyMessage` in `MessagesRepositoryImpl` to ensure the correct author is displayed.
- Introduced `OnlineFriendsViewModel` to the `FriendsRoute` to separate the logic for online friends.
- Replaced `List` with a custom `ImmutableList` for `photoViewerInfo` state to improve Compose stability.
This commit is contained in:
2025-12-15 22:24:17 +03:00
parent dcbfd43896
commit 478639e427
7 changed files with 359 additions and 333 deletions
@@ -5,6 +5,7 @@ import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import dev.meloda.fast.friends.FriendsViewModel
import dev.meloda.fast.friends.FriendsViewModelImpl
import dev.meloda.fast.friends.OnlineFriendsViewModelImpl
import dev.meloda.fast.friends.presentation.FriendsRoute
import dev.meloda.fast.model.BaseError
import kotlinx.serialization.Serializable
@@ -20,14 +21,14 @@ fun NavGraphBuilder.friendsScreen(
onMessageClicked: (userId: Long) -> Unit,
onScrolledToTop: () -> Unit
) {
val friendsViewModel: FriendsViewModel = with(activity) {
getViewModel<FriendsViewModelImpl>()
}
val friendsViewModel: FriendsViewModel = activity.getViewModel<FriendsViewModelImpl>()
val onlineFriendsViewModel =
activity.getViewModel<OnlineFriendsViewModelImpl>()
composable<Friends> {
FriendsRoute(
activity = activity,
friendsViewModel = friendsViewModel,
onlineFriendsViewModel = onlineFriendsViewModel,
onError = onError,
onPhotoClicked = onPhotoClicked,
onMessageClicked = onMessageClicked,
@@ -1,6 +1,5 @@
package dev.meloda.fast.friends.presentation
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.FastOutLinearInEasing
import androidx.compose.animation.core.animateFloatAsState
@@ -54,17 +53,16 @@ import dev.meloda.fast.ui.theme.LocalHazeState
import dev.meloda.fast.ui.theme.LocalThemeConfig
import dev.meloda.fast.ui.util.ImmutableList
import kotlinx.coroutines.launch
import org.koin.androidx.viewmodel.ext.android.getViewModel
@OptIn(ExperimentalMaterial3Api::class, ExperimentalHazeMaterialsApi::class)
@Composable
fun FriendsRoute(
activity: AppCompatActivity,
friendsViewModel: FriendsViewModel,
onlineFriendsViewModel: OnlineFriendsViewModelImpl,
onError: (BaseError) -> Unit,
onPhotoClicked: (url: String) -> Unit,
onMessageClicked: (userid: Long) -> Unit,
onScrolledToTop: () -> Unit
onScrolledToTop: () -> Unit,
) {
val scope = rememberCoroutineScope()
val currentTheme = LocalThemeConfig.current
@@ -232,9 +230,7 @@ fun FriendsRoute(
modifier = Modifier.fillMaxSize(),
) { index ->
FriendsScreen(
viewModel = if (index == 0) friendsViewModel else with(activity) {
getViewModel<OnlineFriendsViewModelImpl>()
},
viewModel = if (index == 0) friendsViewModel else onlineFriendsViewModel,
orderType = orderType,
padding = padding,
tabIndex = index,