From eff150aebc66a4af7253d00f99767b95c9de4d26 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Sun, 11 Sep 2022 22:34:03 +0100 Subject: [PATCH] fixing crash when switching from the invitations screen to the conversation directory and back to the profile --- .../main/kotlin/app/dapk/st/home/HomeViewModel.kt | 12 +++++++++++- .../main/kotlin/app/dapk/st/profile/ProfileScreen.kt | 5 +++-- .../kotlin/app/dapk/st/profile/ProfileViewModel.kt | 12 ++++++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/features/home/src/main/kotlin/app/dapk/st/home/HomeViewModel.kt b/features/home/src/main/kotlin/app/dapk/st/home/HomeViewModel.kt index 334660b..56617f7 100644 --- a/features/home/src/main/kotlin/app/dapk/st/home/HomeViewModel.kt +++ b/features/home/src/main/kotlin/app/dapk/st/home/HomeViewModel.kt @@ -98,7 +98,17 @@ class HomeViewModel( fun changePage(page: Page) { state = when (val current = state) { Loading -> current - is SignedIn -> current.copy(page = page) + is SignedIn -> { + when (page) { + Page.Directory -> { + // do nothing + } + + Page.Profile -> profileViewModel.reset() + } + current.copy(page = page) + } + SignedOut -> current } } diff --git a/features/profile/src/main/kotlin/app/dapk/st/profile/ProfileScreen.kt b/features/profile/src/main/kotlin/app/dapk/st/profile/ProfileScreen.kt index af305b8..6d57470 100644 --- a/features/profile/src/main/kotlin/app/dapk/st/profile/ProfileScreen.kt +++ b/features/profile/src/main/kotlin/app/dapk/st/profile/ProfileScreen.kt @@ -7,10 +7,10 @@ import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.CircleShape -import androidx.compose.material3.* import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.CameraAlt import androidx.compose.material.icons.filled.Settings +import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -19,7 +19,6 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.dp import app.dapk.st.core.Lce import app.dapk.st.core.LifecycleEffect -import app.dapk.st.core.StartObserving import app.dapk.st.core.components.CenteredLoading import app.dapk.st.design.components.* import app.dapk.st.matrix.sync.InviteMeta @@ -43,6 +42,7 @@ fun ProfileScreen(viewModel: ProfileViewModel, onTopLevelBack: () -> Unit) { else -> viewModel.goTo(it) } } + Spider(currentPage = viewModel.state.page, onNavigate = onNavigate) { item(Page.Routes.profile) { ProfilePage(context, viewModel, it) @@ -146,6 +146,7 @@ private fun Invitations(viewModel: ProfileViewModel, invitations: Page.Invitatio } } } + is Lce.Error -> TODO() } } diff --git a/features/profile/src/main/kotlin/app/dapk/st/profile/ProfileViewModel.kt b/features/profile/src/main/kotlin/app/dapk/st/profile/ProfileViewModel.kt index ab7fb5b..bec102a 100644 --- a/features/profile/src/main/kotlin/app/dapk/st/profile/ProfileViewModel.kt +++ b/features/profile/src/main/kotlin/app/dapk/st/profile/ProfileViewModel.kt @@ -102,10 +102,6 @@ class ProfileViewModel( ) } - fun stop() { - syncingJob?.cancel() - } - @Suppress("UNCHECKED_CAST") private inline fun updatePageState(crossinline block: S.() -> S) { val page = state.page @@ -114,6 +110,14 @@ class ProfileViewModel( updateState { copy(page = (page as SpiderPage).copy(state = block(page.state))) } } + fun reset() { + updateState { ProfileScreenState(SpiderPage(Page.Routes.profile, "Profile", null, Page.Profile(Lce.Loading()), hasToolbar = false)) } + } + + fun stop() { + syncingJob?.cancel() + } + } fun DapkViewModel.launchCatching(block: suspend () -> T): LaunchCatching {