1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-10 18:10:44 +09:00

Editor | Fix | Inconsistent toggle icon state (#2164)

This commit is contained in:
Evgenii Kozlov 2022-04-05 19:21:39 +03:00 committed by GitHub
parent 6a07179944
commit e5f50f14b5
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 0 deletions

View file

@ -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 🚀

View file

@ -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

View file

@ -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
}
}
}

View file

@ -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`() {