diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt index d0d10beb31..7dde0edf32 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt @@ -18,6 +18,7 @@ package im.vector.app.features.home import android.content.Context import android.content.Intent +import android.net.Uri import android.os.Bundle import android.os.Parcelable import android.view.MenuItem @@ -365,14 +366,14 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable, UnknownDeviceDet } } - override fun navToMemberProfile(userId: String): Boolean { + override fun navToMemberProfile(userId: String, deepLink: Uri): Boolean { val listener = object : MatrixToBottomSheet.InteractionListener { override fun navigateToRoom(roomId: String) { navigator.openRoom(this@HomeActivity, roomId) } } // TODO check if there is already one?? - MatrixToBottomSheet.withUserId(userId, listener) + MatrixToBottomSheet.withLink(deepLink.toString(), listener) .show(supportFragmentManager, "HA#MatrixToBottomSheet") return true } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt index e289234e7a..3f5e476a5e 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt @@ -1460,7 +1460,7 @@ class RoomDetailFragment @Inject constructor( return false } - override fun navToMemberProfile(userId: String): Boolean { + override fun navToMemberProfile(userId: String, deepLink: Uri): Boolean { openRoomMemberProfile(userId) return true } diff --git a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheet.kt b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheet.kt index 41020ea404..69f30bb470 100644 --- a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheet.kt @@ -41,8 +41,7 @@ class MatrixToBottomSheet : VectorBaseBottomSheetDialogFragment() { @Parcelize data class MatrixToArgs( - val matrixToLink: String?, - val userId: String? + val matrixToLink: String ) : Parcelable @Inject lateinit var avatarRenderer: AvatarRenderer @@ -136,20 +135,7 @@ class MatrixToBottomSheet : VectorBaseBottomSheetDialogFragment() { return MatrixToBottomSheet().apply { arguments = Bundle().apply { putParcelable(MvRx.KEY_ARG, MatrixToBottomSheet.MatrixToArgs( - matrixToLink = matrixToLink, - userId = null - )) - } - interactionListener = listener - } - } - - fun withUserId(userId: String, listener: InteractionListener?): MatrixToBottomSheet { - return MatrixToBottomSheet().apply { - arguments = Bundle().apply { - putParcelable(MvRx.KEY_ARG, MatrixToBottomSheet.MatrixToArgs( - matrixToLink = null, - userId = userId + matrixToLink = matrixToLink )) } interactionListener = listener diff --git a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetState.kt b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetState.kt index 9ec2071a94..9b1ce9fea8 100644 --- a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetState.kt +++ b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetState.kt @@ -22,14 +22,12 @@ import com.airbnb.mvrx.Uninitialized import org.matrix.android.sdk.api.util.MatrixItem data class MatrixToBottomSheetState( - val userId: String? = null, - val deepLink: String? = null, + val deepLink: String, val matrixItem: Async = Uninitialized, val startChattingState: Async = Uninitialized ) : MvRxState { constructor(args: MatrixToBottomSheet.MatrixToArgs) : this( - userId = args.userId, deepLink = args.matrixToLink ) } diff --git a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetViewModel.kt b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetViewModel.kt index 79af3684b9..6e8a530c9a 100644 --- a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetViewModel.kt @@ -65,42 +65,20 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor( } private suspend fun resolveLink(initialState: MatrixToBottomSheetState) { - when { - initialState.deepLink != null -> { - val linkedId = PermalinkParser.parse(initialState.deepLink) - if (linkedId is PermalinkData.FallbackLink) { - setState { - copy( - matrixItem = Fail(IllegalArgumentException(stringProvider.getString(R.string.permalink_malformed))), - startChattingState = Uninitialized - ) - } - return - } - - when (linkedId) { - is PermalinkData.UserLink -> { - val user = resolveUser(linkedId.userId) - setState { - copy( - matrixItem = Success(user.toMatrixItem()), - startChattingState = Success(Unit) - ) - } - } - is PermalinkData.RoomLink -> { - // not yet supported - } - is PermalinkData.GroupLink -> { - // not yet supported - } - is PermalinkData.FallbackLink -> { - } - } + val permalinkData = PermalinkParser.parse(initialState.deepLink) + if (permalinkData is PermalinkData.FallbackLink) { + setState { + copy( + matrixItem = Fail(IllegalArgumentException(stringProvider.getString(R.string.permalink_malformed))), + startChattingState = Uninitialized + ) } - initialState.userId != null -> { - val user = resolveUser(initialState.userId) + return + } + when (permalinkData) { + is PermalinkData.UserLink -> { + val user = resolveUser(permalinkData.userId) setState { copy( matrixItem = Success(user.toMatrixItem()), @@ -108,13 +86,16 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor( ) } } - else -> { - setState { - copy( - matrixItem = Fail(IllegalArgumentException(stringProvider.getString(R.string.unexpected_error))), - startChattingState = Uninitialized - ) - } + is PermalinkData.RoomLink -> { + // not yet supported + _viewEvents.post(MatrixToViewEvents.Dismiss) + } + is PermalinkData.GroupLink -> { + // not yet supported + _viewEvents.post(MatrixToViewEvents.Dismiss) + } + is PermalinkData.FallbackLink -> { + _viewEvents.post(MatrixToViewEvents.Dismiss) } } } diff --git a/vector/src/main/java/im/vector/app/features/permalink/PermalinkHandler.kt b/vector/src/main/java/im/vector/app/features/permalink/PermalinkHandler.kt index 11c55f6a73..f1149d8990 100644 --- a/vector/src/main/java/im/vector/app/features/permalink/PermalinkHandler.kt +++ b/vector/src/main/java/im/vector/app/features/permalink/PermalinkHandler.kt @@ -63,13 +63,14 @@ class PermalinkHandler @Inject constructor(private val activeSessionHolder: Acti .subscribeOn(Schedulers.computation()) .observeOn(AndroidSchedulers.mainThread()) .flatMap { permalinkData -> - handlePermalink(permalinkData, context, navigationInterceptor, buildTask) + handlePermalink(permalinkData, deepLink, context, navigationInterceptor, buildTask) } .onErrorReturnItem(false) } private fun handlePermalink( permalinkData: PermalinkData, + rawLink: Uri, context: Context, navigationInterceptor: NavigationInterceptor?, buildTask: Boolean @@ -96,7 +97,7 @@ class PermalinkHandler @Inject constructor(private val activeSessionHolder: Acti Single.just(true) } is PermalinkData.UserLink -> { - if (navigationInterceptor?.navToMemberProfile(permalinkData.userId) != true) { + if (navigationInterceptor?.navToMemberProfile(permalinkData.userId, rawLink) != true) { navigator.openRoomMemberProfile(userId = permalinkData.userId, roomId = null, context = context, buildTask = buildTask) } Single.just(true) @@ -175,7 +176,7 @@ interface NavigationInterceptor { /** * Return true if the navigation has been intercepted */ - fun navToMemberProfile(userId: String): Boolean { + fun navToMemberProfile(userId: String, deepLink: Uri): Boolean { return false } } diff --git a/vector/src/main/java/im/vector/app/features/usercode/UserCodeActivity.kt b/vector/src/main/java/im/vector/app/features/usercode/UserCodeActivity.kt index d6279470ae..547e2d939f 100644 --- a/vector/src/main/java/im/vector/app/features/usercode/UserCodeActivity.kt +++ b/vector/src/main/java/im/vector/app/features/usercode/UserCodeActivity.kt @@ -71,7 +71,7 @@ class UserCodeActivity UserCodeState.Mode.SCAN -> showFragment(ScanUserCodeFragment::class, Bundle.EMPTY) is UserCodeState.Mode.RESULT -> { showFragment(ShowUserCodeFragment::class, Bundle.EMPTY) - MatrixToBottomSheet.withUserId(mode.matrixItem.id, this).show(supportFragmentManager, "MatrixToBottomSheet") + MatrixToBottomSheet.withLink(mode.rawLink, this).show(supportFragmentManager, "MatrixToBottomSheet") } } } diff --git a/vector/src/main/java/im/vector/app/features/usercode/UserCodeSharedViewModel.kt b/vector/src/main/java/im/vector/app/features/usercode/UserCodeSharedViewModel.kt index 98acab147e..45b6f0ee65 100644 --- a/vector/src/main/java/im/vector/app/features/usercode/UserCodeSharedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/usercode/UserCodeSharedViewModel.kt @@ -155,7 +155,7 @@ class UserCodeSharedViewModel @AssistedInject constructor( setState { copy( - mode = UserCodeState.Mode.RESULT(user.toMatrixItem()) + mode = UserCodeState.Mode.RESULT(user.toMatrixItem(), action.code) ) } } diff --git a/vector/src/main/java/im/vector/app/features/usercode/UserCodeState.kt b/vector/src/main/java/im/vector/app/features/usercode/UserCodeState.kt index fdcfa2cb5e..c26da7c0a4 100644 --- a/vector/src/main/java/im/vector/app/features/usercode/UserCodeState.kt +++ b/vector/src/main/java/im/vector/app/features/usercode/UserCodeState.kt @@ -28,7 +28,7 @@ data class UserCodeState( sealed class Mode { object SHOW : Mode() object SCAN : Mode() - data class RESULT(val matrixItem: MatrixItem) : Mode() + data class RESULT(val matrixItem: MatrixItem, val rawLink: String) : Mode() } constructor(args: UserCodeActivity.Args) : this(