From b7091e85f81cb20f4d919e56ea6b8979de836ddc Mon Sep 17 00:00:00 2001 From: Mikhail Date: Mon, 18 Jul 2022 20:07:15 +0300 Subject: [PATCH] DROID-35 Editor | Enhancement | Use snackbar instead of toast (#2412) --- .githooks/commit-msg | 3 +-- .../anytype/ui/editor/EditorFragment.kt | 9 +++++++-- .../presentation/editor/EditorViewModel.kt | 16 +++++++++++----- .../anytype/presentation/editor/Snack.kt | 1 + 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.githooks/commit-msg b/.githooks/commit-msg index 9882e18d32..f152b43f6d 100755 --- a/.githooks/commit-msg +++ b/.githooks/commit-msg @@ -23,6 +23,5 @@ if [[ "$ISSUE_ID" != "DROID-"* ]]; then fi if [[ "$COMMIT_TEXT" != "DROID-"* ]]; then - echo "$ISSUE_ID " > "$COMMIT_MSG_FILE" - echo "$COMMIT_TEXT" >> "$COMMIT_MSG_FILE" + echo "$ISSUE_ID" "$COMMIT_TEXT" > "$COMMIT_MSG_FILE" fi \ No newline at end of file diff --git a/app/src/main/java/com/anytypeio/anytype/ui/editor/EditorFragment.kt b/app/src/main/java/com/anytypeio/anytype/ui/editor/EditorFragment.kt index 9500ba0e0e..c0b0433f7b 100644 --- a/app/src/main/java/com/anytypeio/anytype/ui/editor/EditorFragment.kt +++ b/app/src/main/java/com/anytypeio/anytype/ui/editor/EditorFragment.kt @@ -434,6 +434,11 @@ open class EditorFragment : NavigationFragment(R.layout.f .setAction(R.string.create_new_set) { vm.onCreateNewSetForType(snack.type) } .show() } + is Snack.UndoRedo -> { + Snackbar.make(requireView(), snack.message, Snackbar.LENGTH_SHORT).apply { + anchorView = binding.undoRedoToolbar + }.show() + } } } jobs += subscribe(vm.footers) { footer -> @@ -1255,7 +1260,7 @@ open class EditorFragment : NavigationFragment(R.layout.f iconView.setIcon(ObjectIcon.Basic.Emoji(emoji)) iconView.visible() } - !image.isNullOrBlank()-> { + !image.isNullOrBlank() -> { iconView.setIcon(ObjectIcon.Basic.Image(image)) iconView.visible() } @@ -1282,7 +1287,7 @@ open class EditorFragment : NavigationFragment(R.layout.f if (state.mainToolbar.isVisible) { binding.toolbar.visible() - binding.toolbar.state = when(state.mainToolbar.targetBlockType) { + binding.toolbar.state = when (state.mainToolbar.targetBlockType) { Main.TargetBlockType.Any -> BlockToolbarWidget.State.Any Main.TargetBlockType.Title -> BlockToolbarWidget.State.Title } diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/EditorViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/EditorViewModel.kt index cf5799ac38..c807c1ed5a 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/EditorViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/EditorViewModel.kt @@ -1936,11 +1936,11 @@ class EditorViewModel( fun onActionUndoClicked() { Timber.d("onActionUndoClicked, ") - viewModelScope.launch { + jobs += viewModelScope.launch { orchestrator.proxies.intents.send( Intent.Document.Undo( context = context, - onUndoExhausted = { sendToast("Nothing to undo.") } + onUndoExhausted = { sendSnack(Snack.UndoRedo("Nothing to undo.")) } ) ) } @@ -1948,11 +1948,11 @@ class EditorViewModel( fun onActionRedoClicked() { Timber.d("onActionRedoClicked, ") - viewModelScope.launch { + jobs += viewModelScope.launch { orchestrator.proxies.intents.send( Intent.Document.Redo( context = context, - onRedoExhausted = { sendToast("Nothing to redo.") } + onRedoExhausted = { sendSnack(Snack.UndoRedo("Nothing to redo.")) } ) ) } @@ -3886,11 +3886,17 @@ class EditorViewModel( } private fun sendToast(msg: String) { - viewModelScope.launch { + jobs += viewModelScope.launch { _toasts.emit(msg) } } + private fun sendSnack(snack: Snack) { + jobs += viewModelScope.launch { + snacks.emit(snack) + } + } + /** * Return true, when mention menu is closed, and we need absorb back button click */ diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/Snack.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/Snack.kt index 6dbc01760e..0b4c1f81b8 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/Snack.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/Snack.kt @@ -4,4 +4,5 @@ import com.anytypeio.anytype.core_models.Id sealed class Snack { data class ObjectSetNotFound(val type: Id) : Snack() + data class UndoRedo(val message: String) : Snack() } \ No newline at end of file