mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Refactoring following review
This commit is contained in:
parent
4f5632b916
commit
835a36986d
@ -18,6 +18,7 @@ package im.vector.app.features.home
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.view.MenuItem
|
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 {
|
val listener = object : MatrixToBottomSheet.InteractionListener {
|
||||||
override fun navigateToRoom(roomId: String) {
|
override fun navigateToRoom(roomId: String) {
|
||||||
navigator.openRoom(this@HomeActivity, roomId)
|
navigator.openRoom(this@HomeActivity, roomId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO check if there is already one??
|
// TODO check if there is already one??
|
||||||
MatrixToBottomSheet.withUserId(userId, listener)
|
MatrixToBottomSheet.withLink(deepLink.toString(), listener)
|
||||||
.show(supportFragmentManager, "HA#MatrixToBottomSheet")
|
.show(supportFragmentManager, "HA#MatrixToBottomSheet")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -1460,7 +1460,7 @@ class RoomDetailFragment @Inject constructor(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun navToMemberProfile(userId: String): Boolean {
|
override fun navToMemberProfile(userId: String, deepLink: Uri): Boolean {
|
||||||
openRoomMemberProfile(userId)
|
openRoomMemberProfile(userId)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,7 @@ class MatrixToBottomSheet : VectorBaseBottomSheetDialogFragment() {
|
|||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
data class MatrixToArgs(
|
data class MatrixToArgs(
|
||||||
val matrixToLink: String?,
|
val matrixToLink: String
|
||||||
val userId: String?
|
|
||||||
) : Parcelable
|
) : Parcelable
|
||||||
|
|
||||||
@Inject lateinit var avatarRenderer: AvatarRenderer
|
@Inject lateinit var avatarRenderer: AvatarRenderer
|
||||||
@ -136,20 +135,7 @@ class MatrixToBottomSheet : VectorBaseBottomSheetDialogFragment() {
|
|||||||
return MatrixToBottomSheet().apply {
|
return MatrixToBottomSheet().apply {
|
||||||
arguments = Bundle().apply {
|
arguments = Bundle().apply {
|
||||||
putParcelable(MvRx.KEY_ARG, MatrixToBottomSheet.MatrixToArgs(
|
putParcelable(MvRx.KEY_ARG, MatrixToBottomSheet.MatrixToArgs(
|
||||||
matrixToLink = matrixToLink,
|
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
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
interactionListener = listener
|
interactionListener = listener
|
||||||
|
@ -22,14 +22,12 @@ import com.airbnb.mvrx.Uninitialized
|
|||||||
import org.matrix.android.sdk.api.util.MatrixItem
|
import org.matrix.android.sdk.api.util.MatrixItem
|
||||||
|
|
||||||
data class MatrixToBottomSheetState(
|
data class MatrixToBottomSheetState(
|
||||||
val userId: String? = null,
|
val deepLink: String,
|
||||||
val deepLink: String? = null,
|
|
||||||
val matrixItem: Async<MatrixItem> = Uninitialized,
|
val matrixItem: Async<MatrixItem> = Uninitialized,
|
||||||
val startChattingState: Async<Unit> = Uninitialized
|
val startChattingState: Async<Unit> = Uninitialized
|
||||||
) : MvRxState {
|
) : MvRxState {
|
||||||
|
|
||||||
constructor(args: MatrixToBottomSheet.MatrixToArgs) : this(
|
constructor(args: MatrixToBottomSheet.MatrixToArgs) : this(
|
||||||
userId = args.userId,
|
|
||||||
deepLink = args.matrixToLink
|
deepLink = args.matrixToLink
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -65,42 +65,20 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun resolveLink(initialState: MatrixToBottomSheetState) {
|
private suspend fun resolveLink(initialState: MatrixToBottomSheetState) {
|
||||||
when {
|
val permalinkData = PermalinkParser.parse(initialState.deepLink)
|
||||||
initialState.deepLink != null -> {
|
if (permalinkData is PermalinkData.FallbackLink) {
|
||||||
val linkedId = PermalinkParser.parse(initialState.deepLink)
|
setState {
|
||||||
if (linkedId is PermalinkData.FallbackLink) {
|
copy(
|
||||||
setState {
|
matrixItem = Fail(IllegalArgumentException(stringProvider.getString(R.string.permalink_malformed))),
|
||||||
copy(
|
startChattingState = Uninitialized
|
||||||
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 -> {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
initialState.userId != null -> {
|
return
|
||||||
val user = resolveUser(initialState.userId)
|
}
|
||||||
|
|
||||||
|
when (permalinkData) {
|
||||||
|
is PermalinkData.UserLink -> {
|
||||||
|
val user = resolveUser(permalinkData.userId)
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
matrixItem = Success(user.toMatrixItem()),
|
matrixItem = Success(user.toMatrixItem()),
|
||||||
@ -108,13 +86,16 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
is PermalinkData.RoomLink -> {
|
||||||
setState {
|
// not yet supported
|
||||||
copy(
|
_viewEvents.post(MatrixToViewEvents.Dismiss)
|
||||||
matrixItem = Fail(IllegalArgumentException(stringProvider.getString(R.string.unexpected_error))),
|
}
|
||||||
startChattingState = Uninitialized
|
is PermalinkData.GroupLink -> {
|
||||||
)
|
// not yet supported
|
||||||
}
|
_viewEvents.post(MatrixToViewEvents.Dismiss)
|
||||||
|
}
|
||||||
|
is PermalinkData.FallbackLink -> {
|
||||||
|
_viewEvents.post(MatrixToViewEvents.Dismiss)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,13 +63,14 @@ class PermalinkHandler @Inject constructor(private val activeSessionHolder: Acti
|
|||||||
.subscribeOn(Schedulers.computation())
|
.subscribeOn(Schedulers.computation())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.flatMap { permalinkData ->
|
.flatMap { permalinkData ->
|
||||||
handlePermalink(permalinkData, context, navigationInterceptor, buildTask)
|
handlePermalink(permalinkData, deepLink, context, navigationInterceptor, buildTask)
|
||||||
}
|
}
|
||||||
.onErrorReturnItem(false)
|
.onErrorReturnItem(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handlePermalink(
|
private fun handlePermalink(
|
||||||
permalinkData: PermalinkData,
|
permalinkData: PermalinkData,
|
||||||
|
rawLink: Uri,
|
||||||
context: Context,
|
context: Context,
|
||||||
navigationInterceptor: NavigationInterceptor?,
|
navigationInterceptor: NavigationInterceptor?,
|
||||||
buildTask: Boolean
|
buildTask: Boolean
|
||||||
@ -96,7 +97,7 @@ class PermalinkHandler @Inject constructor(private val activeSessionHolder: Acti
|
|||||||
Single.just(true)
|
Single.just(true)
|
||||||
}
|
}
|
||||||
is PermalinkData.UserLink -> {
|
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)
|
navigator.openRoomMemberProfile(userId = permalinkData.userId, roomId = null, context = context, buildTask = buildTask)
|
||||||
}
|
}
|
||||||
Single.just(true)
|
Single.just(true)
|
||||||
@ -175,7 +176,7 @@ interface NavigationInterceptor {
|
|||||||
/**
|
/**
|
||||||
* Return true if the navigation has been intercepted
|
* Return true if the navigation has been intercepted
|
||||||
*/
|
*/
|
||||||
fun navToMemberProfile(userId: String): Boolean {
|
fun navToMemberProfile(userId: String, deepLink: Uri): Boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ class UserCodeActivity
|
|||||||
UserCodeState.Mode.SCAN -> showFragment(ScanUserCodeFragment::class, Bundle.EMPTY)
|
UserCodeState.Mode.SCAN -> showFragment(ScanUserCodeFragment::class, Bundle.EMPTY)
|
||||||
is UserCodeState.Mode.RESULT -> {
|
is UserCodeState.Mode.RESULT -> {
|
||||||
showFragment(ShowUserCodeFragment::class, Bundle.EMPTY)
|
showFragment(ShowUserCodeFragment::class, Bundle.EMPTY)
|
||||||
MatrixToBottomSheet.withUserId(mode.matrixItem.id, this).show(supportFragmentManager, "MatrixToBottomSheet")
|
MatrixToBottomSheet.withLink(mode.rawLink, this).show(supportFragmentManager, "MatrixToBottomSheet")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ class UserCodeSharedViewModel @AssistedInject constructor(
|
|||||||
|
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
mode = UserCodeState.Mode.RESULT(user.toMatrixItem())
|
mode = UserCodeState.Mode.RESULT(user.toMatrixItem(), action.code)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ data class UserCodeState(
|
|||||||
sealed class Mode {
|
sealed class Mode {
|
||||||
object SHOW : Mode()
|
object SHOW : Mode()
|
||||||
object SCAN : 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(
|
constructor(args: UserCodeActivity.Args) : this(
|
||||||
|
Loading…
Reference in New Issue
Block a user