1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-3611 Navigation | Fix | Allow restoration of last opened space from loading state on splash screen (#2359)

This commit is contained in:
Evgenii Kozlov 2025-04-25 13:45:10 +02:00
parent 3b94345d5f
commit e0f34a3177
2 changed files with 15 additions and 1 deletions

View file

@ -38,6 +38,7 @@ import com.anytypeio.anytype.persistence.preferences.VaultPrefsSerializer
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import timber.log.Timber
class DefaultUserSettingsCache(
private val prefs: SharedPreferences,
@ -67,6 +68,7 @@ class DefaultUserSettingsCache(
)
override suspend fun setCurrentSpace(space: SpaceId) {
Timber.d("Setting current space in settings: ${space.id}")
prefs.edit()
.putString(CURRENT_SPACE_KEY, space.id)
.apply()
@ -81,6 +83,7 @@ class DefaultUserSettingsCache(
}
override suspend fun clearCurrentSpace() {
Timber.d("Clearing current space in settings")
prefs.edit()
.putString(CURRENT_SPACE_KEY, "")
.apply()
@ -300,6 +303,7 @@ class DefaultUserSettingsCache(
}
override suspend fun setLastOpenedObject(id: Id, space: SpaceId) {
Timber.d("Setting last opened object for space: ${space.id}")
context.spacePrefsStore.updateData { existingPreferences ->
val givenSpacePreference = existingPreferences
.preferences
@ -330,6 +334,7 @@ class DefaultUserSettingsCache(
}
override suspend fun clearLastOpenedObject(space: SpaceId) {
Timber.d("Clearing last opened object for space: ${space.id}")
context.spacePrefsStore.updateData { existingPreferences ->
val givenSpacePreference = existingPreferences
.preferences

View file

@ -20,6 +20,7 @@ import com.anytypeio.anytype.core_models.exceptions.AccountMigrationNeededExcept
import com.anytypeio.anytype.core_models.exceptions.NeedToUpdateApplicationException
import com.anytypeio.anytype.core_models.primitives.SpaceId
import com.anytypeio.anytype.core_models.primitives.TypeKey
import com.anytypeio.anytype.core_models.restrictions.SpaceStatus
import com.anytypeio.anytype.domain.auth.interactor.CheckAuthorizationStatus
import com.anytypeio.anytype.domain.auth.interactor.GetLastOpenedObject
import com.anytypeio.anytype.domain.auth.interactor.LaunchAccount
@ -41,6 +42,8 @@ import com.anytypeio.anytype.presentation.extension.sendAnalyticsObjectCreateEve
import com.anytypeio.anytype.presentation.search.ObjectSearchConstants
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterNot
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.launch
@ -364,16 +367,22 @@ class SplashViewModel(
Timber.d("proceedWithVaultNavigation deep link: $deeplink")
val space = getLastOpenedSpace.async(Unit).getOrNull()
if (space != null && spaceManager.getState() != SpaceManager.State.NoSpace) {
Timber.d("Got the last opened space from settings: ${space.id}")
spaceManager
.observe()
.take(1)
.flatMapLatest { config ->
spaceViews
.observe(SpaceId(config.space))
.filterNot { view ->
// Wait until the space view is no longer in a fully UNKNOWN state
view.spaceLocalStatus == SpaceStatus.UNKNOWN
&& view.spaceAccountStatus == SpaceStatus.UNKNOWN
}
.take(1)
}
.collect { view ->
if (view.isActive) {
if (view.isActive || view.isLoading) {
val chat = view.chatId
if (chat.isNullOrEmpty() || !ChatConfig.isChatAllowed(space.id)) {
commands.emit(