From 73b4535f616805cda4f8ecd82eb864b6f49d6b1d Mon Sep 17 00:00:00 2001 From: konstantiniiv Date: Mon, 16 Dec 2024 21:03:57 +0100 Subject: [PATCH 1/2] DROID-3185 hide file block --- .../presentation/editor/render/DefaultBlockViewRenderer.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt index b172809f2f..7947c3aea5 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt @@ -9,6 +9,7 @@ import com.anytypeio.anytype.core_models.ObjectTypeIds.BOOKMARK import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.RelationLink import com.anytypeio.anytype.core_models.Relations +import com.anytypeio.anytype.core_models.SupportedLayouts import com.anytypeio.anytype.core_models.ThemeColor import com.anytypeio.anytype.core_models.ext.parseThemeTextColor import com.anytypeio.anytype.core_models.ext.textColor @@ -622,6 +623,11 @@ class DefaultBlockViewRenderer @Inject constructor( isPreviousBlockMedia = link is BlockView.LinkToObject.Default.Card } is Content.File -> { + val detail = details.details.getOrDefault(root.id, Block.Fields.empty()) + val obj = ObjectWrapper.Basic(detail.map) + if (SupportedLayouts.fileLayouts.contains(obj.layout)) { + return@forEach + } mCounter = 0 val blockDecorationScheme = buildNestedDecorationData( block = block, From 7d26acc7c16242e36821cf4921775341363592a9 Mon Sep 17 00:00:00 2001 From: konstantiniiv Date: Mon, 16 Dec 2024 21:13:09 +0100 Subject: [PATCH 2/2] DROID-3185 test --- .../editor/DefaultBlockViewRendererTest.kt | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/DefaultBlockViewRendererTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/DefaultBlockViewRendererTest.kt index 1647909a39..9259d1487f 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/DefaultBlockViewRendererTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/DefaultBlockViewRendererTest.kt @@ -5752,4 +5752,63 @@ class DefaultBlockViewRendererTest { assertEquals(expected = expected, actual = result) } //endregion + + @Test + fun `should not render file block in case of file layout`() { + + val file = StubFile( + backgroundColor = null, + state = Block.Content.File.State.DONE, + type = Block.Content.File.Type.FILE + ) + + val paragraph = StubParagraph() + + val page = StubSmartBlock(children = listOf(paragraph.id, file.id)) + + val details = mapOf(page.id to Block.Fields( + mapOf( + Relations.NAME to "file-name", + Relations.LAYOUT to Layout.FILE.code.toDouble() + ) + )) + + val blocks = listOf(page, paragraph, file) + + val map = blocks.asMap() + + wrapper = BlockViewRenderWrapper( + blocks = map, + renderer = renderer + ) + + val result = runBlocking { + wrapper.render( + root = page, + anchor = page.id, + focus = Editor.Focus.empty(), + indent = 0, + details = Block.Details(details) + ) + } + + val expected = listOf( + BlockView.Text.Paragraph( + indent = 0, + isFocused = false, + id = paragraph.id, + marks = emptyList(), + background = paragraph.parseThemeBackgroundColor(), + text = paragraph.content().text, + decorations = listOf( + BlockView.Decoration( + style = BlockView.Decoration.Style.None, + background = paragraph.parseThemeBackgroundColor() + ) + ), + ) + ) + + assertEquals(expected = expected, actual = result) + } } \ No newline at end of file