From 841a84aba01119f66c915d7b2582f5f1987f40a0 Mon Sep 17 00:00:00 2001 From: Evgenii Kozlov Date: Tue, 1 Sep 2020 18:48:44 +0300 Subject: [PATCH] Fix/apple emojis in block action toolbar preview (#764) --- CHANGELOG.md | 4 ++ .../modals/actions/PageBlockActionToolbar.kt | 42 ++++++++++++++++--- .../res/layout/item_block_page_preview.xml | 28 ++++++++----- .../page/editor/EditorTurnIntoTest.kt | 22 +++++----- 4 files changed, 69 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b564500508..0cb3c5d688 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ * Test flight for turn-into restrictions in edit-mode and multi-select mode (#376) +### Design & UX 🔳 + +* Apple emojis or uploaded image in block-action-toolbar link's preview (#630) + ### Fixes & tech 🚒 * Should not show toast when clicking on markup url (#698) diff --git a/app/src/main/java/com/agileburo/anytype/ui/page/modals/actions/PageBlockActionToolbar.kt b/app/src/main/java/com/agileburo/anytype/ui/page/modals/actions/PageBlockActionToolbar.kt index 79e3cd197e..4b8e8c224b 100644 --- a/app/src/main/java/com/agileburo/anytype/ui/page/modals/actions/PageBlockActionToolbar.kt +++ b/app/src/main/java/com/agileburo/anytype/ui/page/modals/actions/PageBlockActionToolbar.kt @@ -6,12 +6,17 @@ import android.widget.ImageView import android.widget.TextView import com.agileburo.anytype.R import com.agileburo.anytype.core_ui.features.page.BlockView +import com.agileburo.anytype.core_utils.ext.visible +import com.agileburo.anytype.emojifier.Emojifier +import com.bumptech.glide.Glide +import com.bumptech.glide.load.engine.DiskCacheStrategy class PageBlockActionToolbar : BlockActionToolbar() { lateinit var block: BlockView.Page lateinit var icon: ImageView - lateinit var emoji: TextView + lateinit var emoji: ImageView + lateinit var image: ImageView lateinit var title: TextView override fun onCreate(savedInstanceState: Bundle?) { @@ -23,16 +28,41 @@ class PageBlockActionToolbar : BlockActionToolbar() { override fun getBlock(): BlockView = block override fun initUi(view: View, colorView: ImageView?, backgroundView: ImageView?) { - icon = view.findViewById(R.id.pageIcon) - emoji = view.findViewById(R.id.emoji) + + image = view.findViewById(R.id.linkImage) + emoji = view.findViewById(R.id.linkEmoji) title = view.findViewById(R.id.pageTitle) title.text = if (block.text.isNullOrEmpty()) getString(R.string.untitled) else block.text + when { - block.emoji != null -> emoji.text = block.emoji - block.isEmpty -> icon.setImageResource(R.drawable.ic_block_empty_page) - else -> icon.setImageResource(R.drawable.ic_block_page_without_emoji) + block.emoji != null -> { + image.setImageDrawable(null) + Glide + .with(emoji) + .load(Emojifier.uri(block.emoji!!)) + .diskCacheStrategy(DiskCacheStrategy.ALL) + .into(emoji) + } + block.image != null -> { + image.visible() + Glide + .with(image) + .load(block.image) + .centerInside() + .circleCrop() + .into(image) + } + block.isEmpty -> { + icon.setImageResource(com.agileburo.anytype.core_ui.R.drawable.ic_block_empty_page) + image.setImageDrawable(null) + } + else -> { + icon.setImageResource(com.agileburo.anytype.core_ui.R.drawable.ic_block_page_without_emoji) + image.setImageDrawable(null) + } } + setConstraints() } } \ No newline at end of file diff --git a/core-ui/src/main/res/layout/item_block_page_preview.xml b/core-ui/src/main/res/layout/item_block_page_preview.xml index 2c5fdfcf74..04288b98a5 100644 --- a/core-ui/src/main/res/layout/item_block_page_preview.xml +++ b/core-ui/src/main/res/layout/item_block_page_preview.xml @@ -2,9 +2,13 @@ @@ -30,12 +34,16 @@ android:layout_gravity="center" android:contentDescription="@string/content_description_page_icon" /> - + + + @@ -46,8 +54,8 @@ android:layout_marginTop="3dp" android:layout_marginEnd="4dp" android:layout_marginBottom="3dp" - android:visibility="invisible" android:src="@drawable/ic_block_more" + android:visibility="invisible" android:contentDescription="@string/content_description_more_button" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" diff --git a/presentation/src/test/java/com/agileburo/anytype/presentation/page/editor/EditorTurnIntoTest.kt b/presentation/src/test/java/com/agileburo/anytype/presentation/page/editor/EditorTurnIntoTest.kt index 541f6f9116..3208a3c457 100644 --- a/presentation/src/test/java/com/agileburo/anytype/presentation/page/editor/EditorTurnIntoTest.kt +++ b/presentation/src/test/java/com/agileburo/anytype/presentation/page/editor/EditorTurnIntoTest.kt @@ -162,8 +162,8 @@ class EditorTurnIntoTest : EditorPresentationTestSetup() { // SETUP - val child = Block( - id = "CHILD", + val a = Block( + id = MockDataFactory.randomUuid(), fields = Block.Fields.empty(), children = emptyList(), content = Block.Content.Text( @@ -173,10 +173,10 @@ class EditorTurnIntoTest : EditorPresentationTestSetup() { ) ) - val parent = Block( - id = "PARENT", + val b = Block( + id = MockDataFactory.randomUuid(), fields = Block.Fields.empty(), - children = listOf(child.id), + children = emptyList(), content = Block.Content.Text( text = MockDataFactory.randomString(), marks = emptyList(), @@ -190,10 +190,10 @@ class EditorTurnIntoTest : EditorPresentationTestSetup() { content = Block.Content.Smart( type = Block.Content.Smart.Type.PAGE ), - children = listOf(parent.id) + children = listOf(a.id, b.id) ) - val document = listOf(page, parent, child) + val document = listOf(page, a, b) stubOpenDocument(document = document) stubInterceptEvents(InterceptEvents.Params(context = root)) @@ -204,10 +204,10 @@ class EditorTurnIntoTest : EditorPresentationTestSetup() { vm.apply { onStart(root) - onBlockFocusChanged(id = parent.id, hasFocus = true) + onBlockFocusChanged(id = a.id, hasFocus = true) onClickListener( ListenerType.LongClick( - target = child.id, + target = b.id, dimensions = BlockDimensions( MockDataFactory.randomInt(), MockDataFactory.randomInt(), @@ -219,7 +219,7 @@ class EditorTurnIntoTest : EditorPresentationTestSetup() { ) ) onActionMenuItemClicked( - id = child.id, + id = b.id, action = ActionItemType.TurnInto ) } @@ -244,7 +244,7 @@ class EditorTurnIntoTest : EditorPresentationTestSetup() { ) assertEquals( - expected = child.id, + expected = b.id, actual = result.target )