mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-10 10:00:44 +09:00
DROID-955 Editor | Fix | Add proper way of navigation (#2917)
This commit is contained in:
parent
f045a5a3d5
commit
ed9542a2b5
3 changed files with 90 additions and 61 deletions
|
@ -11,17 +11,21 @@ import com.anytypeio.anytype.presentation.navigation.AppNavigation
|
|||
import com.anytypeio.anytype.presentation.navigation.AppNavigation.Command
|
||||
import timber.log.Timber
|
||||
|
||||
@Deprecated("Use NavigationRouter directly")
|
||||
abstract class NavigationFragment<BINDING : ViewBinding>(
|
||||
@LayoutRes private val layout: Int
|
||||
) : BaseFragment<BINDING>(layout) {
|
||||
|
||||
private val currentNavigationId by lazy { getNavigationId() }
|
||||
private val navigationRouter by lazy {
|
||||
NavigationRouter((requireActivity() as AppNavigation.Provider).nav())
|
||||
}
|
||||
|
||||
val navObserver = Observer<EventWrapper<Command>> { event ->
|
||||
event.getContentIfNotHandled()?.let {
|
||||
try {
|
||||
if (currentNavigationId == getNavigationId()) {
|
||||
throttle { navigate(it) }
|
||||
throttle { navigationRouter.navigate(it) }
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Navigation: $it")
|
||||
|
@ -31,61 +35,4 @@ abstract class NavigationFragment<BINDING : ViewBinding>(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun navigate(command: Command) {
|
||||
Timber.d("Navigate to $command")
|
||||
val navigation = (requireActivity() as AppNavigation.Provider).nav()
|
||||
|
||||
when (command) {
|
||||
is Command.StartSplashFromDesktop -> navigation.startSplashFromDesktop()
|
||||
is Command.StartDesktopFromLogin -> navigation.startDesktopFromLogin()
|
||||
is Command.StartDesktopFromSignUp -> navigation.startDesktopFromSignUp()
|
||||
is Command.StartDesktopFromSplash -> navigation.startDesktopFromSplash()
|
||||
is Command.OpenStartLoginScreen -> navigation.startLogin()
|
||||
is Command.OpenCreateAccount -> navigation.createProfile(command.invitationCode)
|
||||
is Command.ChoosePinCodeScreen -> navigation.choosePinCode()
|
||||
is Command.EnterKeyChainScreen -> navigation.enterKeychain()
|
||||
is Command.SelectAccountScreen -> navigation.chooseAccount()
|
||||
is Command.WorkspaceScreen -> navigation.workspace()
|
||||
is Command.InvitationCodeScreen -> navigation.enterInvitationCode()
|
||||
is Command.AboutAnalyticsScreen -> navigation.aboutAnalyticsScreen()
|
||||
is Command.ExitToInvitationCodeScreen -> navigation.exitToInvitationCodeScreen()
|
||||
is Command.SetupNewAccountScreen -> navigation.setupNewAccount()
|
||||
is Command.SetupSelectedAccountScreen -> navigation.setupSelectedAccount(command.id)
|
||||
is Command.ConfirmPinCodeScreen -> navigation.confirmPinCode(command.code)
|
||||
is Command.OpenSettings -> navigation.openSettings()
|
||||
is Command.OpenObject -> navigation.openDocument(command.id, command.editorSettings)
|
||||
is Command.OpenArchive -> navigation.openArchive(command.target)
|
||||
is Command.OpenObjectSet -> navigation.openObjectSet(
|
||||
command.target,
|
||||
command.isPopUpToDashboard
|
||||
)
|
||||
is Command.LaunchObjectSet -> navigation.launchObjectSet(command.target)
|
||||
is Command.LaunchDocument -> navigation.launchDocument(command.id)
|
||||
is Command.LaunchObjectFromSplash -> navigation.launchObjectFromSplash(command.target)
|
||||
is Command.LaunchObjectSetFromSplash -> navigation.launchObjectSetFromSplash(command.target)
|
||||
is Command.OpenDatabaseViewAddView -> navigation.openDatabaseViewAddView()
|
||||
is Command.OpenEditDatabase -> navigation.openEditDatabase()
|
||||
is Command.OpenKeychainScreen -> navigation.openKeychainScreen()
|
||||
is Command.OpenUserSettingsScreen -> navigation.openUserSettingsScreen()
|
||||
is Command.OpenContactsScreen -> navigation.openContacts()
|
||||
is Command.OpenSwitchDisplayView -> navigation.openSwitchDisplayView()
|
||||
is Command.OpenCustomizeDisplayView -> navigation.openCustomizeDisplayView()
|
||||
is Command.Exit -> navigation.exit()
|
||||
is Command.ExitToDesktop -> navigation.exitToDesktop()
|
||||
is Command.OpenDebugSettingsScreen -> navigation.openDebugSettings()
|
||||
is Command.OpenPageNavigationScreen -> navigation.openPageNavigation(command.target)
|
||||
is Command.ExitToDesktopAndOpenPage -> navigation.exitToDesktopAndOpenPage(command.pageId)
|
||||
is Command.OpenPageSearch -> navigation.openPageSearch()
|
||||
is Command.OpenUpdateAppScreen -> navigation.openUpdateAppScreen()
|
||||
is Command.DeletedAccountScreen -> navigation.deletedAccountScreen(command.deadline)
|
||||
is Command.OpenTemplates -> navigation.openTemplates(
|
||||
ctx = command.ctx,
|
||||
type = command.type,
|
||||
templates = command.templates
|
||||
)
|
||||
is Command.OpenLibrary -> navigation.openLibrary()
|
||||
else -> Timber.d("Nav command ignored: $command")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package com.anytypeio.anytype.ui.base
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.anytypeio.anytype.presentation.navigation.AppNavigation
|
||||
import timber.log.Timber
|
||||
|
||||
class NavigationRouter(
|
||||
private val navigation: AppNavigation
|
||||
) {
|
||||
fun navigate(command: AppNavigation.Command) {
|
||||
Timber.d("Navigate to $command")
|
||||
|
||||
when (command) {
|
||||
is AppNavigation.Command.StartSplashFromDesktop -> navigation.startSplashFromDesktop()
|
||||
is AppNavigation.Command.StartDesktopFromLogin -> navigation.startDesktopFromLogin()
|
||||
is AppNavigation.Command.StartDesktopFromSignUp -> navigation.startDesktopFromSignUp()
|
||||
is AppNavigation.Command.StartDesktopFromSplash -> navigation.startDesktopFromSplash()
|
||||
is AppNavigation.Command.OpenStartLoginScreen -> navigation.startLogin()
|
||||
is AppNavigation.Command.OpenCreateAccount -> navigation.createProfile(command.invitationCode)
|
||||
is AppNavigation.Command.ChoosePinCodeScreen -> navigation.choosePinCode()
|
||||
is AppNavigation.Command.EnterKeyChainScreen -> navigation.enterKeychain()
|
||||
is AppNavigation.Command.SelectAccountScreen -> navigation.chooseAccount()
|
||||
is AppNavigation.Command.WorkspaceScreen -> navigation.workspace()
|
||||
is AppNavigation.Command.InvitationCodeScreen -> navigation.enterInvitationCode()
|
||||
is AppNavigation.Command.AboutAnalyticsScreen -> navigation.aboutAnalyticsScreen()
|
||||
is AppNavigation.Command.ExitToInvitationCodeScreen -> navigation.exitToInvitationCodeScreen()
|
||||
is AppNavigation.Command.SetupNewAccountScreen -> navigation.setupNewAccount()
|
||||
is AppNavigation.Command.SetupSelectedAccountScreen -> navigation.setupSelectedAccount(
|
||||
command.id
|
||||
)
|
||||
is AppNavigation.Command.ConfirmPinCodeScreen -> navigation.confirmPinCode(command.code)
|
||||
is AppNavigation.Command.OpenSettings -> navigation.openSettings()
|
||||
is AppNavigation.Command.OpenObject -> navigation.openDocument(
|
||||
command.id,
|
||||
command.editorSettings
|
||||
)
|
||||
is AppNavigation.Command.OpenArchive -> navigation.openArchive(command.target)
|
||||
is AppNavigation.Command.OpenObjectSet -> navigation.openObjectSet(
|
||||
command.target,
|
||||
command.isPopUpToDashboard
|
||||
)
|
||||
is AppNavigation.Command.LaunchObjectSet -> navigation.launchObjectSet(command.target)
|
||||
is AppNavigation.Command.LaunchDocument -> navigation.launchDocument(command.id)
|
||||
is AppNavigation.Command.LaunchObjectFromSplash -> navigation.launchObjectFromSplash(
|
||||
command.target
|
||||
)
|
||||
is AppNavigation.Command.LaunchObjectSetFromSplash -> navigation.launchObjectSetFromSplash(
|
||||
command.target
|
||||
)
|
||||
is AppNavigation.Command.OpenDatabaseViewAddView -> navigation.openDatabaseViewAddView()
|
||||
is AppNavigation.Command.OpenEditDatabase -> navigation.openEditDatabase()
|
||||
is AppNavigation.Command.OpenKeychainScreen -> navigation.openKeychainScreen()
|
||||
is AppNavigation.Command.OpenUserSettingsScreen -> navigation.openUserSettingsScreen()
|
||||
is AppNavigation.Command.OpenContactsScreen -> navigation.openContacts()
|
||||
is AppNavigation.Command.OpenSwitchDisplayView -> navigation.openSwitchDisplayView()
|
||||
is AppNavigation.Command.OpenCustomizeDisplayView -> navigation.openCustomizeDisplayView()
|
||||
is AppNavigation.Command.Exit -> navigation.exit()
|
||||
is AppNavigation.Command.ExitToDesktop -> navigation.exitToDesktop()
|
||||
is AppNavigation.Command.OpenDebugSettingsScreen -> navigation.openDebugSettings()
|
||||
is AppNavigation.Command.OpenPageNavigationScreen -> navigation.openPageNavigation(
|
||||
command.target
|
||||
)
|
||||
is AppNavigation.Command.ExitToDesktopAndOpenPage -> navigation.exitToDesktopAndOpenPage(
|
||||
command.pageId
|
||||
)
|
||||
is AppNavigation.Command.OpenPageSearch -> navigation.openPageSearch()
|
||||
is AppNavigation.Command.OpenUpdateAppScreen -> navigation.openUpdateAppScreen()
|
||||
is AppNavigation.Command.DeletedAccountScreen -> navigation.deletedAccountScreen(command.deadline)
|
||||
is AppNavigation.Command.OpenTemplates -> navigation.openTemplates(
|
||||
ctx = command.ctx,
|
||||
type = command.type,
|
||||
templates = command.templates
|
||||
)
|
||||
is AppNavigation.Command.OpenLibrary -> navigation.openLibrary()
|
||||
else -> Timber.d("Nav command ignored: $command")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Fragment.navigation() = (requireActivity() as AppNavigation.Provider).nav()
|
|
@ -14,6 +14,7 @@ import com.anytypeio.anytype.core_utils.ext.subscribe
|
|||
import com.anytypeio.anytype.core_utils.ui.BaseComposeFragment
|
||||
import com.anytypeio.anytype.di.common.componentManager
|
||||
import com.anytypeio.anytype.presentation.search.Subscriptions
|
||||
import com.anytypeio.anytype.ui.base.navigation
|
||||
import com.anytypeio.anytype.ui.settings.typography
|
||||
import com.anytypeio.anytype.ui.widgets.collection.CollectionViewModel.Command
|
||||
import javax.inject.Inject
|
||||
|
@ -24,6 +25,8 @@ class CollectionFragment : BaseComposeFragment() {
|
|||
@Inject
|
||||
lateinit var factory: CollectionViewModel.Factory
|
||||
|
||||
val navigation get() = navigation()
|
||||
|
||||
private val vm by viewModels<CollectionViewModel> { factory }
|
||||
|
||||
override fun onCreateView(
|
||||
|
@ -56,14 +59,13 @@ class CollectionFragment : BaseComposeFragment() {
|
|||
}
|
||||
|
||||
private fun launchObjectSet(target: Id) {
|
||||
TODO("Not yet implemented")
|
||||
navigation.launchObjectSet(target)
|
||||
}
|
||||
|
||||
private fun launchDocument(id: Id) {
|
||||
TODO("Not yet implemented")
|
||||
navigation.launchDocument(id)
|
||||
}
|
||||
|
||||
|
||||
override fun onStop() {
|
||||
//vm.onStop(Subscriptions.SUBSCRIPTION_RECENT)
|
||||
vm.onStop(Subscriptions.SUBSCRIPTION_SETS)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue