Video play button

Stephen Paul Weber created

Goes to the video url (usually embed url) instead of the whole webpage.

Change summary

src/cheogram/res/layout/link_description.xml                        | 64 
src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java |  7 
2 files changed, 49 insertions(+), 22 deletions(-)

Detailed changes

@@ -2,37 +2,57 @@
 <layout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto">
 
-    <LinearLayout
+    <RelativeLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:paddingHorizontal="10dp"
+        android:paddingHorizontal="4dp"
         android:paddingVertical="4dp"
-        android:background="@drawable/background_link_description"
-        android:orientation="vertical">
+        android:descendantFocusability="blocksDescendants"
+        android:background="@drawable/background_link_description">
 
-        <TextView
-            android:id="@+id/title"
-            android:layout_width="wrap_content"
+        <LinearLayout
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:maxLines="1"
-            android:textColor="?colorPrimary"
-            android:textAppearance="?textAppearanceTitleSmall" />
+            android:paddingHorizontal="6dp"
+            android:orientation="vertical">
 
-        <TextView
-            android:id="@+id/url"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:maxLines="1"
-            android:textColor="?colorOnSurface"
-            android:textAppearance="?textAppearanceLabelSmall" />
+            <TextView
+                android:id="@+id/title"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:maxLines="1"
+                android:textColor="?colorPrimary"
+                android:textAppearance="?textAppearanceTitleSmall" />
+
+            <TextView
+                android:id="@+id/url"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:maxLines="1"
+                android:textColor="?colorOnSurface"
+                android:textAppearance="?textAppearanceLabelSmall" />
+
+            <TextView
+                android:id="@+id/description"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textColor="?colorOnSurface"
+                android:textAppearance="?textAppearanceBodyMedium" />
+
+        </LinearLayout>
 
-        <TextView
-            android:id="@+id/description"
+        <ImageButton
+            android:id="@+id/play_button"
+            android:visibility="gone"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:textColor="?colorOnSurface"
-            android:textAppearance="?textAppearanceBodyMedium" />
+            android:layout_alignParentBottom="true"
+            android:layout_alignParentEnd="true"
+            android:focusable="false"
+            android:focusableInTouchMode="false"
+            android:background="?attr/selectableItemBackgroundBorderless"
+            android:src="@drawable/ic_play_circle_24dp" />
 
-    </LinearLayout>
+    </RelativeLayout>
 
 </layout>

src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java 🔗

@@ -1552,6 +1552,13 @@ public class MessageAdapter extends ArrayAdapter<Message> {
                         binding.title.setText(getItem(position).findChildContent("title", "https://ogp.me/ns#"));
                         binding.description.setText(getItem(position).findChildContent("description", "https://ogp.me/ns#"));
                         binding.url.setText(getItem(position).findChildContent("url", "https://ogp.me/ns#"));
+                        final var video = getItem(position).findChildContent("video", "https://ogp.me/ns#");
+                        if (video != null && video.length() > 0) {
+                            binding.playButton.setVisibility(View.VISIBLE);
+                            binding.playButton.setOnClickListener((v) -> {
+                                new FixedURLSpan(video).onClick(v);
+                            });
+                        }
                         return binding.getRoot();
                     }
                 });