mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-2907 Vault | Enhancement | Space-switcher navigation (#1636)
This commit is contained in:
parent
f921452c8d
commit
3898ca6c1e
15 changed files with 118 additions and 65 deletions
|
@ -179,7 +179,14 @@ class AllContentFragment : BaseComposeFragment() {
|
|||
dialog.show(childFragmentManager,null)
|
||||
},
|
||||
onBackClicked = vm::onBackClicked,
|
||||
moveToBin = vm::proceedWithMoveToBin
|
||||
moveToBin = vm::proceedWithMoveToBin,
|
||||
onBackLongClicked = {
|
||||
runCatching {
|
||||
findNavController().navigate(R.id.actionOpenSpaceSwitcher)
|
||||
}.onFailure {
|
||||
Timber.e(it, "Error while opening space switcher from all-content screen")
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -579,6 +579,19 @@ open class EditorFragment : NavigationFragment<FragmentEditorBinding>(R.layout.f
|
|||
.onEach { vm.onBackButtonPressed() }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
binding.bottomToolbar
|
||||
.binding
|
||||
.btnBack
|
||||
.longClicks(withHaptic = true)
|
||||
.onEach {
|
||||
runCatching {
|
||||
findNavController().navigate(R.id.actionOpenSpaceSwitcher)
|
||||
}.onFailure {
|
||||
Timber.e(it, "Error while opening space switcher from editor")
|
||||
}
|
||||
}
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
binding.bottomToolbar
|
||||
.searchClicks()
|
||||
.onEach { vm.onPageSearchClicked() }
|
||||
|
|
|
@ -89,6 +89,13 @@ class LibraryFragment : BaseComposeFragment() {
|
|||
}
|
||||
}
|
||||
dialog.show(childFragmentManager, "library-create-object-of-type-dialog")
|
||||
},
|
||||
onBackLongPressed = {
|
||||
runCatching {
|
||||
findNavController().navigate(R.id.actionOpenSpaceSwitcher)
|
||||
}.onFailure {
|
||||
Timber.e(it, "Error while opening space switcher from library")
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ fun LibraryScreen(
|
|||
configuration: LibraryConfiguration,
|
||||
viewModel: LibraryViewModel,
|
||||
onBackPressed: () -> Unit,
|
||||
onBackLongPressed: () -> Unit,
|
||||
onCreateObjectLongClicked: () -> Unit
|
||||
) {
|
||||
|
||||
|
@ -94,7 +95,8 @@ fun LibraryScreen(
|
|||
viewModel,
|
||||
modifier = Modifier.align(Alignment.BottomCenter),
|
||||
screenState = screenState,
|
||||
onCreateObjectLongClicked = onCreateObjectLongClicked
|
||||
onCreateObjectLongClicked = onCreateObjectLongClicked,
|
||||
onBackLongClicked = onBackLongPressed
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +145,8 @@ fun Menu(
|
|||
viewModel: LibraryViewModel,
|
||||
modifier: Modifier = Modifier,
|
||||
screenState: MutableState<ScreenState>,
|
||||
onCreateObjectLongClicked: () -> Unit = {}
|
||||
onCreateObjectLongClicked: () -> Unit = {},
|
||||
onBackLongClicked: () -> Unit
|
||||
) {
|
||||
val isImeVisible = WindowInsets.ime.getBottom(LocalDensity.current) > 0
|
||||
if (isImeVisible) return
|
||||
|
@ -156,6 +159,9 @@ fun Menu(
|
|||
viewModel.eventStream(LibraryEvent.BottomMenu.Back)
|
||||
}
|
||||
},
|
||||
backLongClick = {
|
||||
onBackLongClicked()
|
||||
},
|
||||
homeClick = { viewModel.eventStream(LibraryEvent.BottomMenu.Back) },
|
||||
searchClick = { viewModel.eventStream(LibraryEvent.BottomMenu.Search) },
|
||||
addDocClick = { viewModel.eventStream(LibraryEvent.BottomMenu.CreateObject) },
|
||||
|
|
|
@ -130,6 +130,7 @@ import javax.inject.Inject
|
|||
import kotlinx.coroutines.flow.filterNotNull
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import timber.log.Timber
|
||||
|
||||
open class ObjectSetFragment :
|
||||
NavigationFragment<FragmentObjectSetBinding>(R.layout.fragment_object_set),
|
||||
|
@ -297,6 +298,20 @@ open class ObjectSetFragment :
|
|||
subscribe(
|
||||
binding.bottomToolbar.backClicks().throttleFirst()
|
||||
) { vm.onBackButtonClicked() }
|
||||
|
||||
binding.bottomToolbar
|
||||
.binding
|
||||
.btnBack
|
||||
.longClicks(withHaptic = true)
|
||||
.onEach {
|
||||
runCatching {
|
||||
findNavController().navigate(R.id.actionOpenSpaceSwitcher)
|
||||
}.onFailure {
|
||||
Timber.e(it, "Error while opening space switcher from editor")
|
||||
}
|
||||
}
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
subscribe(
|
||||
binding.bottomToolbar.searchClicks().throttleFirst()
|
||||
) { vm.onSearchButtonClicked() }
|
||||
|
|
|
@ -92,6 +92,9 @@ class RemoteFilesManageFragment : BaseBottomSheetComposeFragment() {
|
|||
is CollectionViewModel.Command.Vault -> {
|
||||
// Do nothing.
|
||||
}
|
||||
is CollectionViewModel.Command.OpenSpaceSwitcher -> {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,10 +20,8 @@ import com.anytypeio.anytype.core_utils.ui.BaseBottomSheetComposeFragment
|
|||
import com.anytypeio.anytype.di.common.componentManager
|
||||
import com.anytypeio.anytype.presentation.spaces.Command
|
||||
import com.anytypeio.anytype.presentation.spaces.SelectSpaceViewModel
|
||||
import com.anytypeio.anytype.ui.settings.ProfileSettingsFragment
|
||||
import com.anytypeio.anytype.ui.settings.typography
|
||||
import javax.inject.Inject
|
||||
import timber.log.Timber
|
||||
|
||||
class SelectSpaceFragment : BaseBottomSheetComposeFragment() {
|
||||
|
||||
|
@ -58,12 +56,12 @@ class SelectSpaceFragment : BaseBottomSheetComposeFragment() {
|
|||
onAddClicked = throttledClick(
|
||||
onClick = { vm.onCreateSpaceClicked() }
|
||||
),
|
||||
onSettingsClicked = throttledClick(
|
||||
onClick = vm::onProfileSettingsClicked
|
||||
),
|
||||
onProfileClicked = throttledClick(
|
||||
onClick = vm::onProfileSettingsClicked
|
||||
)
|
||||
onSettingsClicked = {
|
||||
// Do nothing.
|
||||
},
|
||||
onProfileClicked = {
|
||||
// Do nothing.
|
||||
}
|
||||
)
|
||||
}
|
||||
LaunchedEffect(Unit) {
|
||||
|
@ -86,24 +84,9 @@ class SelectSpaceFragment : BaseBottomSheetComposeFragment() {
|
|||
findNavController().popBackStack()
|
||||
}
|
||||
is Command.SwitchToNewSpace -> {
|
||||
try {
|
||||
if (exitHomeWhenSpaceIsSelected == true) {
|
||||
findNavController().navigate(R.id.switchSpaceAction)
|
||||
} else {
|
||||
findNavController().popBackStack()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Navigation error")
|
||||
}
|
||||
}
|
||||
is Command.NavigateToProfileSettings -> {
|
||||
try {
|
||||
findNavController().navigate(
|
||||
R.id.profileScreen,
|
||||
bundleOf(ProfileSettingsFragment.SPACE_ID_KEY to command.space)
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Navigation error")
|
||||
runCatching {
|
||||
findNavController().popBackStack(R.id.vaultScreen, false)
|
||||
findNavController().navigate(R.id.actionOpenSpaceFromVault)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,8 @@ fun SelectSpaceScreen(
|
|||
LazyVerticalGrid(
|
||||
columns = GridCells.Fixed(count = 3),
|
||||
modifier = Modifier.padding(
|
||||
bottom = 16.dp
|
||||
bottom = 16.dp,
|
||||
top = 16.dp
|
||||
),
|
||||
contentPadding = PaddingValues(horizontal = 30.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(20.dp)
|
||||
|
|
|
@ -114,6 +114,13 @@ class CollectionFragment : BaseComposeFragment() {
|
|||
Timber.e(it, "Error while exiting to vault")
|
||||
}
|
||||
}
|
||||
is Command.OpenSpaceSwitcher -> {
|
||||
runCatching {
|
||||
findNavController().navigate(R.id.actionOpenSpaceSwitcher)
|
||||
}.onFailure {
|
||||
Timber.e(it, "Error while opening space switcher from full-screen widget")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -149,7 +149,8 @@ fun ScreenContent(
|
|||
addDocClick = { vm.onAddClicked(null) },
|
||||
onCreateObjectLongClicked = onCreateObjectLongClicked,
|
||||
onProfileClicked = vm::onProfileClicked,
|
||||
profileIcon = vm.icon.collectAsState().value
|
||||
profileIcon = vm.icon.collectAsState().value,
|
||||
backLongClick = vm::onBackLongClicked
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -612,7 +613,6 @@ fun CollectionScreen(
|
|||
onCreateObjectLongClicked = onCreateObjectLongClicked,
|
||||
onSearchClicked = onSearchClicked
|
||||
)
|
||||
|
||||
LaunchedEffect(state) {
|
||||
|
||||
if (state.showWidget && bottomSheetScaffoldState.bottomSheetState.isCollapsed) {
|
||||
|
@ -630,7 +630,6 @@ fun CollectionScreen(
|
|||
vm.omBottomSheet(it == BottomSheetValue.Expanded)
|
||||
}
|
||||
}
|
||||
|
||||
BackHandler {
|
||||
if (bottomSheetScaffoldState.bottomSheetState.isExpanded) {
|
||||
coroutineScope.launch {
|
||||
|
|
|
@ -74,6 +74,9 @@
|
|||
android:id="@+id/versionHistoryScreen"
|
||||
android:name="com.anytypeio.anytype.ui.history.VersionHistoryFragment"
|
||||
android:label="Object-Version_history-Screen"/>
|
||||
<action
|
||||
android:id="@+id/actionOpenSpaceSwitcher"
|
||||
app:destination="@id/selectSpaceScreen" />
|
||||
</navigation>
|
||||
|
||||
<include app:graph="@navigation/nav_editor_modal" />
|
||||
|
@ -141,6 +144,9 @@
|
|||
android:id="@+id/versionHistoryScreen"
|
||||
android:name="com.anytypeio.anytype.ui.history.VersionHistoryFragment"
|
||||
android:label="Set-Version_history-Screen"/>
|
||||
<action
|
||||
android:id="@+id/actionOpenSpaceSwitcher"
|
||||
app:destination="@id/selectSpaceScreen"/>
|
||||
</navigation>
|
||||
|
||||
<fragment
|
||||
|
@ -174,6 +180,9 @@
|
|||
app:destination="@id/vaultScreen"
|
||||
app:popUpTo="@id/vaultScreen"
|
||||
app:popUpToInclusive="true" />
|
||||
<action
|
||||
android:id="@+id/actionOpenSpaceSwitcher"
|
||||
app:destination="@id/selectSpaceScreen" />
|
||||
</fragment>
|
||||
|
||||
<dialog
|
||||
|
@ -413,6 +422,9 @@
|
|||
<action
|
||||
android:id="@+id/actionOpenGlobalSearch"
|
||||
app:destination="@id/globalSearchScreen" />
|
||||
<action
|
||||
android:id="@+id/actionOpenSpaceSwitcher"
|
||||
app:destination="@id/selectSpaceScreen"/>
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
|
|
|
@ -39,6 +39,7 @@ import com.anytypeio.anytype.presentation.profile.ProfileIconView
|
|||
fun BottomNavigationMenu(
|
||||
modifier: Modifier = Modifier,
|
||||
backClick: () -> Unit = {},
|
||||
backLongClick: () -> Unit = {},
|
||||
homeClick: () -> Unit = {},
|
||||
searchClick: () -> Unit = {},
|
||||
addDocClick: () -> Unit = {},
|
||||
|
@ -61,13 +62,20 @@ fun BottomNavigationMenu(
|
|||
horizontalArrangement = Arrangement.SpaceAround,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
MenuItem(BottomNavigationItem.BACK.res, onClick = backClick)
|
||||
MenuItem(
|
||||
BottomNavigationItem.ADD_DOC.res,
|
||||
res = BottomNavigationItem.BACK.res,
|
||||
onClick = backClick,
|
||||
onLongClick = backLongClick
|
||||
)
|
||||
MenuItem(
|
||||
res = BottomNavigationItem.ADD_DOC.res,
|
||||
onClick = addDocClick,
|
||||
onLongClick = onCreateObjectLongClicked
|
||||
)
|
||||
MenuItem(BottomNavigationItem.SEARCH.res, onClick = searchClick)
|
||||
MenuItem(
|
||||
res = BottomNavigationItem.SEARCH.res,
|
||||
onClick = searchClick
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -120,6 +120,7 @@ fun AllContentWrapperScreen(
|
|||
onAddDocClicked: () -> Unit,
|
||||
onCreateObjectLongClicked: () -> Unit,
|
||||
onBackClicked: () -> Unit,
|
||||
onBackLongClicked: () -> Unit,
|
||||
moveToBin: (UiContentItem.Item) -> Unit
|
||||
) {
|
||||
val lazyListState = rememberLazyListState()
|
||||
|
@ -161,6 +162,7 @@ fun AllContentWrapperScreen(
|
|||
onAddDocClicked = onAddDocClicked,
|
||||
onCreateObjectLongClicked = onCreateObjectLongClicked,
|
||||
onBackClicked = onBackClicked,
|
||||
onBackLongClicked = onBackLongClicked,
|
||||
moveToBin = moveToBin
|
||||
)
|
||||
}
|
||||
|
@ -186,6 +188,7 @@ fun AllContentMainScreen(
|
|||
onAddDocClicked: () -> Unit,
|
||||
onCreateObjectLongClicked: () -> Unit,
|
||||
onBackClicked: () -> Unit,
|
||||
onBackLongClicked: () -> Unit,
|
||||
moveToBin: (UiContentItem.Item) -> Unit
|
||||
) {
|
||||
var isSearchEmpty by remember { mutableStateOf(true) }
|
||||
|
@ -212,7 +215,8 @@ fun AllContentMainScreen(
|
|||
onGlobalSearchClicked = onGlobalSearchClicked,
|
||||
onAddDocClicked = onAddDocClicked,
|
||||
onCreateObjectLongClicked = onCreateObjectLongClicked,
|
||||
onBackClicked = onBackClicked
|
||||
onBackClicked = onBackClicked,
|
||||
onBackLongClicked = onBackLongClicked
|
||||
)
|
||||
}
|
||||
},
|
||||
|
@ -307,13 +311,15 @@ fun BottomMenu(
|
|||
onGlobalSearchClicked: () -> Unit,
|
||||
onAddDocClicked: () -> Unit,
|
||||
onCreateObjectLongClicked: () -> Unit,
|
||||
onBackClicked: () -> Unit
|
||||
onBackClicked: () -> Unit,
|
||||
onBackLongClicked: () -> Unit,
|
||||
) {
|
||||
val isImeVisible = WindowInsets.ime.getBottom(LocalDensity.current) > 0
|
||||
if (isImeVisible) return
|
||||
BottomNavigationMenu(
|
||||
modifier = modifier,
|
||||
backClick = onBackClicked,
|
||||
backLongClick = onBackLongClicked,
|
||||
onProfileClicked = onHomeClicked,
|
||||
searchClick = onGlobalSearchClicked,
|
||||
addDocClick = onAddDocClicked,
|
||||
|
@ -471,7 +477,8 @@ fun PreviewMainScreen() {
|
|||
onAddDocClicked = {},
|
||||
onCreateObjectLongClicked = {},
|
||||
onBackClicked = {},
|
||||
moveToBin = {}
|
||||
moveToBin = {},
|
||||
onBackLongClicked = {}
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ import com.anytypeio.anytype.domain.workspace.SpaceManager
|
|||
import com.anytypeio.anytype.presentation.BuildConfig
|
||||
import com.anytypeio.anytype.presentation.common.BaseViewModel
|
||||
import com.anytypeio.anytype.presentation.profile.ProfileIconView
|
||||
import com.anytypeio.anytype.presentation.profile.profileIcon
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
@ -34,7 +33,6 @@ import kotlinx.coroutines.flow.catch
|
|||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
|
@ -104,18 +102,9 @@ class SelectSpaceViewModel(
|
|||
jobs += viewModelScope.launch {
|
||||
combine(
|
||||
spaces,
|
||||
profile.map<ObjectWrapper.Basic, SelectSpaceView.Profile> { profile ->
|
||||
SelectSpaceView.Profile.Default(
|
||||
name = profile.name.orEmpty(),
|
||||
icon = profile.profileIcon(builder = urlBuilder)
|
||||
)
|
||||
}.onStart {
|
||||
emit(SelectSpaceView.Profile.Loading)
|
||||
},
|
||||
spaceManager.observe()
|
||||
) { spaces, profile: SelectSpaceView.Profile, config ->
|
||||
) { spaces, config ->
|
||||
buildList {
|
||||
add(profile)
|
||||
val spaceViews = spaces.mapNotNull { wrapper ->
|
||||
val space = wrapper.targetSpaceId
|
||||
if (space != null) {
|
||||
|
@ -201,16 +190,6 @@ class SelectSpaceViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
fun onProfileSettingsClicked() {
|
||||
viewModelScope.launch {
|
||||
commands.emit(
|
||||
Command.NavigateToProfileSettings(
|
||||
space = spaceManager.get()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun proceedWithUnsubscribing() {
|
||||
viewModelScope.launch {
|
||||
container.unsubscribe(
|
||||
|
@ -277,8 +256,7 @@ sealed class SelectSpaceView {
|
|||
}
|
||||
|
||||
sealed class Command {
|
||||
object CreateSpace : Command()
|
||||
object Dismiss : Command()
|
||||
object SwitchToNewSpace: Command()
|
||||
data class NavigateToProfileSettings(val space: Id) : Command()
|
||||
data object CreateSpace : Command()
|
||||
data object Dismiss : Command()
|
||||
data object SwitchToNewSpace: Command()
|
||||
}
|
|
@ -823,6 +823,12 @@ class CollectionViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
fun onBackLongClicked() {
|
||||
launch {
|
||||
commands.emit(Command.OpenSpaceSwitcher)
|
||||
}
|
||||
}
|
||||
|
||||
fun onSearchClicked(space: Id) {
|
||||
viewModelScope.sendEvent(
|
||||
analytics = analytics,
|
||||
|
@ -987,6 +993,7 @@ class CollectionViewModel(
|
|||
data class ToSearch(val space: Id) : Command()
|
||||
data object Vault : Command()
|
||||
data object Exit : Command()
|
||||
data object OpenSpaceSwitcher : Command()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue