Skip to content

Commit 27992a2

Browse files
authored
DROID-3850 Editor | Fix | Embed block design fixes (#3085)
1 parent fe9b28b commit 27992a2

File tree

6 files changed

+114
-40
lines changed

6 files changed

+114
-40
lines changed

core-ui/src/main/java/com/anytypeio/anytype/core_ui/extensions/EmbedIconExt.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@ package com.anytypeio.anytype.core_ui.extensions
33
import androidx.annotation.DrawableRes
44
import com.anytypeio.anytype.core_ui.R
55

6+
/**
7+
* Determines if an embed can be opened in an external app or browser.
8+
*/
9+
fun String.canOpenEmbedExternally(): Boolean {
10+
return when (this) {
11+
// Video platforms
12+
"YouTube", "Vimeo", "Bilibili" -> true
13+
// Social media
14+
"Twitter", "Facebook", "Instagram", "Reddit", "Telegram" -> true
15+
// Audio platforms
16+
"SoundCloud", "Spotify" -> true
17+
// Maps
18+
"Google Maps", "OpenStreetMap" -> true
19+
// Design/collaboration tools
20+
"Miro", "Figma", "Sketchfab" -> true
21+
// Diagram/code tools that don't open externally on mobile
22+
"Mermaid", "Chart", "Excalidraw", "Kroki", "Graphviz",
23+
"CodePen", "GitHub Gist", "Draw.io" -> false
24+
// Images
25+
"Image" -> false
26+
else -> false
27+
}
28+
}
29+
630
/**
731
* Maps embed processor display name to its corresponding icon drawable resource.
832
* Returns the generic embed icon as a fallback if no specific icon is found.

core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/holders/placeholders/EmbedPlaceholder.kt

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.view.ViewConfiguration
55
import android.widget.FrameLayout
66
import com.anytypeio.anytype.core_ui.R
77
import com.anytypeio.anytype.core_ui.databinding.ItemBlockEmbedBinding
8+
import com.anytypeio.anytype.core_ui.extensions.canOpenEmbedExternally
89
import com.anytypeio.anytype.core_ui.extensions.toEmbedIconResource
910
import com.anytypeio.anytype.core_ui.extensions.veryLight
1011
import com.anytypeio.anytype.core_ui.features.editor.BlockViewDiffUtil
@@ -48,19 +49,40 @@ class EmbedPlaceholder(
4849
fun bind(item: BlockView.Embed, clicked: (ListenerType) -> Unit) {
4950
timber.log.Timber.d("EmbedPlaceholder: bind called with isSelected=${item.isSelected} for id=${item.id}")
5051
select(item.isSelected)
51-
binding.embedMessage.text = binding.root.context.getString(
52-
R.string.embed_content_not_available,
53-
item.processor
54-
)
52+
5553
val trimmedText = item.text.trim()
56-
if (trimmedText.isNotEmpty()) {
57-
binding.embedUrl.visible()
58-
binding.embedUrl.text = trimmedText
59-
} else {
60-
binding.embedUrl.gone()
54+
val canOpen = item.processor.canOpenEmbedExternally() && trimmedText.isNotEmpty()
55+
56+
// Determine the appropriate message based on state
57+
binding.embedTitle.text = when {
58+
trimmedText.isEmpty() -> {
59+
// No URL provided - embed is empty
60+
binding.root.context.getString(R.string.embed_is_empty, item.processor)
61+
}
62+
item.processor.canOpenEmbedExternally() -> {
63+
// Can be opened in external app or browser
64+
binding.root.context.getString(R.string.embed_opens_externally, item.processor)
65+
}
66+
else -> {
67+
// Not available on mobile (e.g., Mermaid, Chart, etc.)
68+
binding.root.context.getString(R.string.embed_content_not_available, item.processor)
69+
}
6170
}
71+
6272
// Set the embed icon based on processor type
6373
binding.embedIcon.setImageResource(item.processor.toEmbedIconResource())
74+
75+
// Show/hide Open button based on whether embed can be opened
76+
if (canOpen) {
77+
binding.openButton.visible()
78+
binding.openButton.setOnClickListener {
79+
clicked(ListenerType.Embed.Click(item))
80+
}
81+
} else {
82+
binding.openButton.gone()
83+
}
84+
85+
// Keep root clickable for selection mode
6486
binding.root.setOnClickListener {
6587
clicked(ListenerType.Embed.Click(item))
6688
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="rectangle">
4+
<solid android:color="@color/control_accent" />
5+
<corners android:radius="14dp" />
6+
</shape>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:state_pressed="true">
4+
<shape android:shape="rectangle">
5+
<solid android:color="@color/control_accent_80" />
6+
<corners android:radius="14dp" />
7+
</shape>
8+
</item>
9+
<item>
10+
<shape android:shape="rectangle">
11+
<solid android:color="@color/control_accent" />
12+
<corners android:radius="14dp" />
13+
</shape>
14+
</item>
15+
</selector>

core-ui/src/main/res/layout/item_block_embed.xml

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,50 +28,54 @@
2828
android:id="@+id/embedIcon"
2929
android:layout_width="@dimen/dp_48"
3030
android:layout_height="@dimen/dp_48"
31-
android:layout_marginEnd="16dp"
31+
android:layout_marginStart="16dp"
3232
android:scaleType="center"
3333
android:src="@drawable/ic_bookmark_placeholder"
34-
app:layout_constraintEnd_toEndOf="parent"
34+
app:layout_constraintStart_toStartOf="parent"
3535
app:layout_constraintTop_toTopOf="parent"
36-
tools:src="@drawable/ic_bookmark_placeholder" />
36+
app:layout_constraintBottom_toBottomOf="parent"
37+
tools:src="@drawable/ic_embed_figma" />
3738

3839
<TextView
39-
android:id="@+id/embedMessage"
40-
style="@style/TextView.ContentStyle.PreviewTitles.2.Medium"
40+
android:id="@+id/embedTitle"
41+
style="@style/TextView.ContentStyle.Relations.2"
4142
android:layout_width="0dp"
4243
android:layout_height="wrap_content"
43-
android:layout_marginStart="16dp"
44+
android:layout_marginStart="12dp"
4445
android:layout_marginEnd="12dp"
4546
android:ellipsize="end"
46-
android:maxLines="3"
47-
android:textColor="@color/text_primary"
48-
app:layout_constraintBottom_toTopOf="@+id/embedUrl"
49-
app:layout_constraintEnd_toStartOf="@+id/embedIcon"
50-
app:layout_constraintHorizontal_bias="0.5"
51-
app:layout_constraintStart_toStartOf="parent"
47+
android:maxLines="2"
48+
android:textColor="@color/text_secondary"
49+
app:layout_constraintBottom_toBottomOf="parent"
50+
app:layout_constraintEnd_toStartOf="@+id/openButton"
51+
app:layout_constraintStart_toEndOf="@+id/embedIcon"
5252
app:layout_constraintTop_toTopOf="parent"
53-
app:layout_constraintVertical_chainStyle="packed"
5453
app:layout_goneMarginEnd="@dimen/dp_16"
55-
tools:text="Figma embed. This content is not available on mobile" />
54+
tools:text="Figma embed. Opens in external app or browser" />
5655

57-
<TextView
58-
android:id="@+id/embedUrl"
59-
style="@style/TextView.ContentStyle.Relations.3"
60-
android:layout_width="0dp"
61-
android:layout_height="wrap_content"
62-
android:layout_marginStart="16dp"
63-
android:layout_marginTop="4dp"
64-
android:layout_marginEnd="12dp"
65-
android:ellipsize="middle"
66-
android:maxLines="1"
67-
android:textColor="@color/text_secondary"
56+
<androidx.appcompat.widget.AppCompatButton
57+
android:id="@+id/openButton"
58+
android:layout_width="wrap_content"
59+
android:layout_height="28dp"
60+
android:layout_marginEnd="16dp"
61+
android:background="@drawable/bg_embed_open_button_selector"
62+
android:fontFamily="@font/inter_medium"
63+
android:gravity="center"
64+
android:includeFontPadding="false"
65+
android:paddingStart="10dp"
66+
android:paddingTop="0dp"
67+
android:paddingEnd="10dp"
68+
android:paddingBottom="0dp"
69+
android:stateListAnimator="@null"
70+
android:text="@string/open"
71+
android:textAllCaps="false"
72+
android:textColor="@color/text_white"
73+
android:textSize="13sp"
74+
android:visibility="gone"
6875
app:layout_constraintBottom_toBottomOf="parent"
69-
app:layout_constraintEnd_toStartOf="@+id/embedIcon"
70-
app:layout_constraintHorizontal_bias="0.5"
71-
app:layout_constraintStart_toStartOf="parent"
72-
app:layout_constraintTop_toBottomOf="@+id/embedMessage"
73-
app:layout_goneMarginEnd="@dimen/dp_16"
74-
tools:text="https://figma.com/file/abc123..." />
76+
app:layout_constraintEnd_toEndOf="parent"
77+
app:layout_constraintTop_toTopOf="parent"
78+
tools:visibility="visible" />
7579

7680
</androidx.constraintlayout.widget.ConstraintLayout>
7781

localization/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,9 @@
940940
<string name="exiting_please_wait">Exiting... please wait</string>
941941
<string name="loading_please_wait">Loading... please wait</string>
942942
<string name="embed_content_not_available">%1$s embed. This content is not available on mobile</string>
943+
<string name="embed_is_empty">%1$s embed is empty</string>
944+
<string name="embed_opens_externally">%1$s embed. Opens in external app or browser</string>
945+
<string name="open">Open</string>
943946
<string name="personal">Default</string>
944947
<string name="create_space">Create space</string>
945948
<string name="create_chat">Create chat</string>

0 commit comments

Comments
 (0)