diff --git a/CHANGES.md b/CHANGES.md
index dbb0bf51ce..d9ab78db82 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -17,6 +17,7 @@ Improvements 🙌:
- Drawer: move settings access and add sign out action (#2171)
- Filter room member (and banned users) by name (#2184)
- Implement "Jump to read receipt" and "Mention" actions on the room member profile screen
+ - Direct share (#2029)
- Add FAB to room members list (#2226)
- Add Sygnal API implementation to test is Push are correctly received
- Add PushGateway API implementation to test if Push are correctly received
diff --git a/vector/build.gradle b/vector/build.gradle
index 3b43aa12e1..00f3f26545 100644
--- a/vector/build.gradle
+++ b/vector/build.gradle
@@ -315,6 +315,7 @@ dependencies {
implementation "androidx.fragment:fragment-ktx:$fragment_version"
// Keep at 2.0.0-beta4 at the moment, as updating is breaking some UI
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
+ implementation "androidx.sharetarget:sharetarget:1.0.0"
implementation 'androidx.core:core-ktx:1.3.2'
implementation "org.threeten:threetenbp:1.4.0:no-tzdb"
diff --git a/vector/src/debug/res/xml/shortcuts.xml b/vector/src/debug/res/xml/shortcuts.xml
new file mode 100644
index 0000000000..100eac5691
--- /dev/null
+++ b/vector/src/debug/res/xml/shortcuts.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/vector/src/main/AndroidManifest.xml b/vector/src/main/AndroidManifest.xml
index c905f83113..bfd09a65dc 100644
--- a/vector/src/main/AndroidManifest.xml
+++ b/vector/src/main/AndroidManifest.xml
@@ -74,6 +74,10 @@
+
+
@@ -172,6 +176,10 @@
+
+
diff --git a/vector/src/main/java/im/vector/app/features/home/ShortcutCreator.kt b/vector/src/main/java/im/vector/app/features/home/ShortcutCreator.kt
index 171cc7b3d9..db396cf990 100644
--- a/vector/src/main/java/im/vector/app/features/home/ShortcutCreator.kt
+++ b/vector/src/main/java/im/vector/app/features/home/ShortcutCreator.kt
@@ -23,6 +23,7 @@ import androidx.annotation.WorkerThread
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.graphics.drawable.IconCompat
+import im.vector.app.BuildConfig
import im.vector.app.core.glide.GlideApp
import im.vector.app.core.utils.DimensionConverter
import im.vector.app.features.home.room.detail.RoomDetailActivity
@@ -33,6 +34,7 @@ import javax.inject.Inject
private val useAdaptiveIcon = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
private const val adaptiveIconSizeDp = 108
private const val adaptiveIconOuterSidesDp = 18
+private const val directShareCategory = BuildConfig.APPLICATION_ID + ".SHORTCUT_SHARE"
class ShortcutCreator @Inject constructor(
private val context: Context,
@@ -65,6 +67,10 @@ class ShortcutCreator @Inject constructor(
.setShortLabel(roomSummary.displayName)
.setIcon(bitmap?.toProfileImageIcon())
.setIntent(intent)
+
+ // Make it show up in the direct share menu
+ .setCategories(setOf(directShareCategory))
+
.build()
}
diff --git a/vector/src/main/java/im/vector/app/features/share/IncomingShareAction.kt b/vector/src/main/java/im/vector/app/features/share/IncomingShareAction.kt
index 4e2eb226bf..4e9f024b15 100644
--- a/vector/src/main/java/im/vector/app/features/share/IncomingShareAction.kt
+++ b/vector/src/main/java/im/vector/app/features/share/IncomingShareAction.kt
@@ -22,6 +22,7 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary
sealed class IncomingShareAction : VectorViewModelAction {
data class SelectRoom(val roomSummary: RoomSummary, val enableMultiSelect: Boolean) : IncomingShareAction()
object ShareToSelectedRooms : IncomingShareAction()
+ data class ShareToRoom(val roomSummary: RoomSummary) : IncomingShareAction()
data class ShareMedia(val keepOriginalSize: Boolean) : IncomingShareAction()
data class FilterWith(val filter: String) : IncomingShareAction()
data class UpdateSharedData(val sharedData: SharedData) : IncomingShareAction()
diff --git a/vector/src/main/java/im/vector/app/features/share/IncomingShareFragment.kt b/vector/src/main/java/im/vector/app/features/share/IncomingShareFragment.kt
index d46566d20e..92e383f8d1 100644
--- a/vector/src/main/java/im/vector/app/features/share/IncomingShareFragment.kt
+++ b/vector/src/main/java/im/vector/app/features/share/IncomingShareFragment.kt
@@ -71,6 +71,14 @@ class IncomingShareFragment @Inject constructor(
setupToolbar(incomingShareToolbar)
attachmentsHelper = AttachmentsHelper(requireContext(), this).register()
+ viewModel.observeViewEvents {
+ when (it) {
+ is IncomingShareViewEvents.ShareToRoom -> handleShareToRoom(it)
+ is IncomingShareViewEvents.EditMediaBeforeSending -> handleEditMediaBeforeSending(it)
+ is IncomingShareViewEvents.MultipleRoomsShareDone -> handleMultipleRoomsShareDone(it)
+ }.exhaustive
+ }
+
val intent = vectorBaseActivity.intent
val isShareManaged = when (intent?.action) {
Intent.ACTION_SEND -> {
@@ -78,6 +86,13 @@ class IncomingShareFragment @Inject constructor(
if (!isShareManaged) {
isShareManaged = handleTextShare(intent)
}
+
+ // Direct share
+ if (intent.hasExtra(Intent.EXTRA_SHORTCUT_ID)) {
+ val roomId = intent.getStringExtra(Intent.EXTRA_SHORTCUT_ID)!!
+ sessionHolder.getSafeActiveSession()?.getRoomSummary(roomId)?.let { viewModel.handle(IncomingShareAction.ShareToRoom(it)) }
+ }
+
isShareManaged
}
Intent.ACTION_SEND_MULTIPLE -> attachmentsHelper.handleShareIntent(requireContext(), intent)
@@ -101,13 +116,6 @@ class IncomingShareFragment @Inject constructor(
sendShareButton.setOnClickListener { _ ->
handleSendShare()
}
- viewModel.observeViewEvents {
- when (it) {
- is IncomingShareViewEvents.ShareToRoom -> handleShareToRoom(it)
- is IncomingShareViewEvents.EditMediaBeforeSending -> handleEditMediaBeforeSending(it)
- is IncomingShareViewEvents.MultipleRoomsShareDone -> handleMultipleRoomsShareDone(it)
- }.exhaustive
- }
}
private fun handleMultipleRoomsShareDone(viewEvent: IncomingShareViewEvents.MultipleRoomsShareDone) {
diff --git a/vector/src/main/java/im/vector/app/features/share/IncomingShareViewModel.kt b/vector/src/main/java/im/vector/app/features/share/IncomingShareViewModel.kt
index edf72ecf67..9014565e08 100644
--- a/vector/src/main/java/im/vector/app/features/share/IncomingShareViewModel.kt
+++ b/vector/src/main/java/im/vector/app/features/share/IncomingShareViewModel.kt
@@ -96,6 +96,7 @@ class IncomingShareViewModel @AssistedInject constructor(
when (action) {
is IncomingShareAction.SelectRoom -> handleSelectRoom(action)
is IncomingShareAction.ShareToSelectedRooms -> handleShareToSelectedRooms()
+ is IncomingShareAction.ShareToRoom -> handleShareToRoom(action)
is IncomingShareAction.ShareMedia -> handleShareMediaToSelectedRooms(action)
is IncomingShareAction.FilterWith -> handleFilter(action)
is IncomingShareAction.UpdateSharedData -> handleUpdateSharedData(action)
@@ -134,6 +135,11 @@ class IncomingShareViewModel @AssistedInject constructor(
}
}
+ private fun handleShareToRoom(action: IncomingShareAction.ShareToRoom) = withState { state ->
+ val sharedData = state.sharedData ?: return@withState
+ _viewEvents.post(IncomingShareViewEvents.ShareToRoom(action.roomSummary, sharedData, showAlert = false))
+ }
+
private fun handleShareMediaToSelectedRooms(action: IncomingShareAction.ShareMedia) = withState { state ->
(state.sharedData as? SharedData.Attachments)?.let {
shareAttachments(it.attachmentData, state.selectedRoomIds, proposeMediaEdition = false, compressMediaBeforeSending = !action.keepOriginalSize)
diff --git a/vector/src/release/res/xml/shortcuts.xml b/vector/src/release/res/xml/shortcuts.xml
new file mode 100644
index 0000000000..a005de24a2
--- /dev/null
+++ b/vector/src/release/res/xml/shortcuts.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file