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:
+5
-4
@@ -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,
|
||||
|
||||
+3
-7
@@ -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,
|
||||
|
||||
+3
@@ -1,5 +1,6 @@
|
||||
package dev.meloda.fast.messageshistory.model
|
||||
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import dev.meloda.fast.common.model.UiImage
|
||||
import dev.meloda.fast.model.api.domain.VkAttachment
|
||||
@@ -9,6 +10,7 @@ sealed class UiItem(
|
||||
open val cmId: Long
|
||||
) {
|
||||
|
||||
@Stable
|
||||
data class Message(
|
||||
override val id: Long,
|
||||
override val cmId: Long,
|
||||
@@ -35,6 +37,7 @@ sealed class UiItem(
|
||||
val replySummary: String?
|
||||
) : UiItem(id, cmId)
|
||||
|
||||
@Stable
|
||||
data class ActionMessage(
|
||||
override val id: Long,
|
||||
override val cmId: Long,
|
||||
|
||||
+3
-4
@@ -1,6 +1,5 @@
|
||||
package dev.meloda.fast.photoviewer.presentation
|
||||
|
||||
import android.content.Intent
|
||||
import android.widget.Toast
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.core.Animatable
|
||||
@@ -59,9 +58,9 @@ import dev.meloda.fast.photoviewer.model.PhotoViewScreenState
|
||||
import dev.meloda.fast.ui.R
|
||||
import dev.meloda.fast.ui.components.FullScreenDialog
|
||||
import dev.meloda.fast.ui.components.Loader
|
||||
import dev.meloda.fast.ui.util.ImmutableList
|
||||
import dev.meloda.fast.ui.util.getImage
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.androidx.compose.koinViewModel
|
||||
import java.net.URLEncoder
|
||||
@@ -69,7 +68,7 @@ import kotlin.math.abs
|
||||
|
||||
@Composable
|
||||
fun PhotoViewDialog(
|
||||
photoViewerInfo: Pair<List<String>, Int?>?,
|
||||
photoViewerInfo: Pair<ImmutableList<String>, Int?>?,
|
||||
modifier: Modifier = Modifier,
|
||||
onDismiss: () -> Unit
|
||||
) {
|
||||
@@ -85,7 +84,7 @@ fun PhotoViewDialog(
|
||||
arguments = PhotoViewArguments(
|
||||
imageUrls = photoViewerInfo.first.map {
|
||||
URLEncoder.encode(it, "utf-8")
|
||||
},
|
||||
}.toList(),
|
||||
selectedIndex = photoViewerInfo.second
|
||||
),
|
||||
applicationContext = applicationContext
|
||||
|
||||
Reference in New Issue
Block a user