From 0ae7242e17c780d8af35f8acc55c4468b2bc4ce8 Mon Sep 17 00:00:00 2001 From: Constantin Wartenburger Date: Sun, 11 Oct 2020 21:09:36 +0200 Subject: [PATCH 1/4] Added direct share --- CHANGES.md | 1 + vector/src/main/AndroidManifest.xml | 4 +++ .../app/features/home/ShortcutCreator.kt | 5 ++++ .../app/features/share/IncomingShareAction.kt | 3 ++- .../features/share/IncomingShareFragment.kt | 25 +++++++++++++------ .../features/share/IncomingShareViewModel.kt | 16 ++++++++---- vector/src/main/res/xml/shortcuts.xml | 7 ++++++ 7 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 vector/src/main/res/xml/shortcuts.xml diff --git a/CHANGES.md b/CHANGES.md index 05d189ed12..d064cc5f39 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,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) Bugfix 🐛: - Improve support for image/audio/video/file selection with intent changes (#1376) diff --git a/vector/src/main/AndroidManifest.xml b/vector/src/main/AndroidManifest.xml index 3f178a3d20..723bf2f0e2 100644 --- a/vector/src/main/AndroidManifest.xml +++ b/vector/src/main/AndroidManifest.xml @@ -74,6 +74,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..1edfbff64f 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 @@ -33,6 +33,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 = "im.vector.app.SHORTCUT_SHARE" class ShortcutCreator @Inject constructor( private val context: Context, @@ -65,6 +66,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 eef4e32dff..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 @@ -16,12 +16,13 @@ package im.vector.app.features.share -import org.matrix.android.sdk.api.session.room.model.RoomSummary import im.vector.app.core.platform.VectorViewModelAction +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 5e776fb17a..c9a8ec51c2 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 @@ -19,6 +19,7 @@ package im.vector.app.features.share import android.app.Activity import android.content.ClipDescription import android.content.Intent +import android.os.Build import android.os.Bundle import android.view.View import android.widget.Toast @@ -71,13 +72,28 @@ 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 -> { + Intent.ACTION_SEND -> { var isShareManaged = attachmentsHelper.handleShareIntent(requireContext(), intent) if (!isShareManaged) { isShareManaged = handleTextShare(intent) } + + // Direct share + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && 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 +117,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 aa4d8ad03e..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 @@ -22,17 +22,17 @@ import com.airbnb.mvrx.ViewModelContext import com.jakewharton.rxrelay2.BehaviorRelay import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject -import org.matrix.android.sdk.api.query.QueryStringValue -import org.matrix.android.sdk.api.session.Session -import org.matrix.android.sdk.api.session.content.ContentAttachmentData -import org.matrix.android.sdk.api.session.room.model.Membership -import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.toggle import im.vector.app.core.platform.VectorViewModel import im.vector.app.features.attachments.isPreviewable import im.vector.app.features.attachments.toGroupedContentAttachmentData import im.vector.app.features.home.room.list.BreadcrumbsRoomComparator +import org.matrix.android.sdk.api.query.QueryStringValue +import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.content.ContentAttachmentData +import org.matrix.android.sdk.api.session.room.model.Membership +import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams import org.matrix.android.sdk.rx.rx import java.util.concurrent.TimeUnit @@ -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/main/res/xml/shortcuts.xml b/vector/src/main/res/xml/shortcuts.xml new file mode 100644 index 0000000000..a005de24a2 --- /dev/null +++ b/vector/src/main/res/xml/shortcuts.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file From 7e5ee8f951e098e1baad16308afad83ea86bdb72 Mon Sep 17 00:00:00 2001 From: Constantin Wartenburger Date: Sun, 11 Oct 2020 22:09:19 +0200 Subject: [PATCH 2/4] Made it backwards compatible --- vector/build.gradle | 1 + vector/src/main/AndroidManifest.xml | 4 ++++ 2 files changed, 5 insertions(+) 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/main/AndroidManifest.xml b/vector/src/main/AndroidManifest.xml index 723bf2f0e2..7810d4861e 100644 --- a/vector/src/main/AndroidManifest.xml +++ b/vector/src/main/AndroidManifest.xml @@ -176,6 +176,10 @@ + + From c0a540268465bc1e318977baea81b80b613369b0 Mon Sep 17 00:00:00 2001 From: Constantin Wartenburger Date: Mon, 12 Oct 2020 17:54:02 +0200 Subject: [PATCH 3/4] Removed version check --- .../java/im/vector/app/features/share/IncomingShareFragment.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 c9a8ec51c2..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 @@ -19,7 +19,6 @@ package im.vector.app.features.share import android.app.Activity import android.content.ClipDescription import android.content.Intent -import android.os.Build import android.os.Bundle import android.view.View import android.widget.Toast @@ -89,7 +88,7 @@ class IncomingShareFragment @Inject constructor( } // Direct share - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && intent.hasExtra(Intent.EXTRA_SHORTCUT_ID)) { + 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)) } } From 7bee558e01c222a69b8a6def412260b9aa67c7b3 Mon Sep 17 00:00:00 2001 From: Constantin Wartenburger Date: Tue, 13 Oct 2020 20:17:56 +0200 Subject: [PATCH 4/4] Using ApplicationId from BuildConfig --- vector/src/debug/res/xml/shortcuts.xml | 7 +++++++ .../java/im/vector/app/features/home/ShortcutCreator.kt | 3 ++- vector/src/{main => release}/res/xml/shortcuts.xml | 0 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 vector/src/debug/res/xml/shortcuts.xml rename vector/src/{main => release}/res/xml/shortcuts.xml (100%) 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/java/im/vector/app/features/home/ShortcutCreator.kt b/vector/src/main/java/im/vector/app/features/home/ShortcutCreator.kt index 1edfbff64f..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,7 +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 = "im.vector.app.SHORTCUT_SHARE" +private const val directShareCategory = BuildConfig.APPLICATION_ID + ".SHORTCUT_SHARE" class ShortcutCreator @Inject constructor( private val context: Context, diff --git a/vector/src/main/res/xml/shortcuts.xml b/vector/src/release/res/xml/shortcuts.xml similarity index 100% rename from vector/src/main/res/xml/shortcuts.xml rename to vector/src/release/res/xml/shortcuts.xml