diff --git a/CHANGELOG.md b/CHANGELOG.md index 528c6b1702..d109188bcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change log for Android @Anytype app. +## Version 0.6.2 (WIP) + +### Fixes & tech 🚒 + +* Editor | Fix inconsistent toggle icon state (#2164) + ## Version 0.6.1 ### New features & enhancements 🚀 diff --git a/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/BlockViewDiffUtil.kt b/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/BlockViewDiffUtil.kt index 0611a5822e..3086b6f2af 100644 --- a/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/BlockViewDiffUtil.kt +++ b/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/BlockViewDiffUtil.kt @@ -116,6 +116,8 @@ class BlockViewDiffUtil( if (newBlock is BlockView.Text.Toggle && oldBlock is BlockView.Text.Toggle) { if (newBlock.isEmpty != oldBlock.isEmpty) changes.add(TOGGLE_EMPTY_STATE_CHANGED) + if (newBlock.toggled != oldBlock.toggled) + changes.add(TOGGLE_STATE_CHANGED) } if (newBlock is BlockView.Selectable && oldBlock is BlockView.Selectable) { @@ -257,6 +259,8 @@ class BlockViewDiffUtil( val isLatexChanged: Boolean get() = changes.contains(LATEX_CHANGED) + val isToggleStateChanged: Boolean get() = changes.contains(TOGGLE_STATE_CHANGED) + fun markupChanged() = changes.contains(MARKUP_CHANGED) fun textChanged() = changes.contains(TEXT_CHANGED) fun textColorChanged() = changes.contains(TEXT_COLOR_CHANGED) @@ -276,6 +280,7 @@ class BlockViewDiffUtil( const val BACKGROUND_COLOR_CHANGED = 6 const val INDENT_CHANGED = 7 const val TOGGLE_EMPTY_STATE_CHANGED = 8 + const val TOGGLE_STATE_CHANGED = 26 const val READ_WRITE_MODE_CHANGED = 9 const val SELECTION_CHANGED = 10 const val ALIGNMENT_CHANGED = 11 diff --git a/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/holders/text/Toggle.kt b/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/holders/text/Toggle.kt index 0db059133f..e3b4c37a37 100644 --- a/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/holders/text/Toggle.kt +++ b/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/holders/text/Toggle.kt @@ -139,6 +139,9 @@ class Toggle( payloads.forEach { payload -> if (payload.changes.contains(BlockViewDiffUtil.TOGGLE_EMPTY_STATE_CHANGED)) placeholder.isVisible = item.isEmpty + if (payload.isToggleStateChanged) { + toggle.rotation = if (item.toggled) EXPANDED_ROTATION else COLLAPSED_ROTATION + } } } diff --git a/core-ui/src/test/java/com/anytypeio/anytype/core_ui/BlockViewDiffUtilTest.kt b/core-ui/src/test/java/com/anytypeio/anytype/core_ui/BlockViewDiffUtilTest.kt index c5eb85ab44..504f572ec1 100644 --- a/core-ui/src/test/java/com/anytypeio/anytype/core_ui/BlockViewDiffUtilTest.kt +++ b/core-ui/src/test/java/com/anytypeio/anytype/core_ui/BlockViewDiffUtilTest.kt @@ -412,6 +412,43 @@ class BlockViewDiffUtilTest { ) } + @Test + fun `should detect toggle state change`() { + + val index = 0 + + val id = MockDataFactory.randomUuid() + + val text = MockDataFactory.randomString() + + val oldBlock = BlockView.Text.Toggle( + id = id, + text = text, + toggled = false + ) + + val newBlock: BlockView = oldBlock.copy( + toggled = true + ) + + val old = listOf(oldBlock) + + val new = listOf(newBlock) + + val diff = BlockViewDiffUtil(old = old, new = new) + + val payload = diff.getChangePayload(index, index) + + val expected = Payload( + changes = listOf(BlockViewDiffUtil.TOGGLE_STATE_CHANGED) + ) + + assertEquals( + expected = expected, + actual = payload + ) + } + @Test fun `should detect focus change for title block`() {