Implement direct share

Stephen Paul Weber created

Change summary

src/cheogram/res/xml/shortcuts.xml                                 | 7 
src/main/AndroidManifest.xml                                       | 1 
src/main/java/eu/siacs/conversations/services/ShortcutService.java | 3 
src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java     | 8 
4 files changed, 19 insertions(+)

Detailed changes

src/cheogram/res/xml/shortcuts.xml 🔗

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
+	<share-target android:targetClass="eu.siacs.conversations.ui.ShareWithActivity">
+		<data android:mimeType="*/*" />
+		<category android:name="com.cheogram.android.SHARE_TARGET" />
+	</share-target>
+</shortcuts>

src/main/AndroidManifest.xml 🔗

@@ -198,6 +198,7 @@
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
+            <meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />
         </activity>
         <activity
             android:name=".ui.ConversationsActivity"

src/main/java/eu/siacs/conversations/services/ShortcutService.java 🔗

@@ -18,6 +18,7 @@ import androidx.core.graphics.drawable.IconCompat;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Set;
 
 import eu.siacs.conversations.Config;
 import eu.siacs.conversations.entities.Account;
@@ -99,6 +100,7 @@ public class ShortcutService {
                         .setIntent(getShortcutIntent(contact))
                         .setIcon(IconCompat.createWithBitmap(xmppConnectionService.getAvatarService().getRoundedShortcut(contact)))
                         .setIsConversation()
+                        .setCategories(Set.of("com.cheogram.android.SHARE_TARGET"))
                         .build();
     }
 
@@ -108,6 +110,7 @@ public class ShortcutService {
                         .setIntent(getShortcutIntent(mucOptions))
                         .setIcon(IconCompat.createWithBitmap(xmppConnectionService.getAvatarService().getRoundedShortcut(mucOptions)))
                         .setIsConversation()
+                        .setCategories(Set.of("com.cheogram.android.SHARE_TARGET"))
                         .build();
     }
 

src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java 🔗

@@ -165,6 +165,14 @@ public class ShareWithActivity extends XmppActivity
             final ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
             this.share.uris = uris == null ? new ArrayList<>() : uris;
         }
+        final var shortcutId = intent.getStringExtra(Intent.EXTRA_SHORTCUT_ID);
+        if (shortcutId != null) {
+            final var index = shortcutId.indexOf('#');
+            if (index >= 0) {
+                this.share.account = shortcutId.substring(0, index);
+                this.share.contact = shortcutId.substring(index+1);
+            }
+        }
         if (xmppConnectionServiceBound) {
             xmppConnectionService.populateWithOrderedConversations(
                     mConversations, this.share.uris.isEmpty(), false);