diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationBottomSheet.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationBottomSheet.kt index 4ef0109227..e90ec99680 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/VerificationBottomSheet.kt @@ -24,7 +24,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment -import com.airbnb.mvrx.Mavericks import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import com.google.android.material.dialog.MaterialAlertDialogBuilder @@ -33,6 +32,7 @@ import im.vector.app.R import im.vector.app.core.extensions.commitTransaction import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.registerStartForActivityResult +import im.vector.app.core.extensions.toMvRxBundle import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment import im.vector.app.databinding.BottomSheetVerificationBinding @@ -178,36 +178,37 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment { - showFragment(VerificationEmojiCodeFragment::class, Bundle().apply { - putParcelable(Mavericks.KEY_ARG, VerificationArgs( - state.otherUserMxItem?.id ?: "", - // If it was outgoing it.transaction id would be null, but the pending request - // would be updated (from localId to txId) - state.pendingRequest.invoke()?.transactionId ?: state.transactionId)) - }) + showFragment( + VerificationEmojiCodeFragment::class, + VerificationArgs( + state.otherUserMxItem?.id ?: "", + // If it was outgoing it.transaction id would be null, but the pending request + // would be updated (from localId to txId) + state.pendingRequest.invoke()?.transactionId ?: state.transactionId + ) + ) } is VerificationTxState.Verified -> { - showFragment(VerificationConclusionFragment::class, Bundle().apply { - putParcelable(Mavericks.KEY_ARG, VerificationConclusionFragment.Args(true, null, state.isMe)) - }) + showFragment( + VerificationConclusionFragment::class, + VerificationConclusionFragment.Args(true, null, state.isMe) + ) } is VerificationTxState.Cancelled -> { - showFragment(VerificationConclusionFragment::class, Bundle().apply { - putParcelable(Mavericks.KEY_ARG, VerificationConclusionFragment.Args(false, state.sasTransactionState.cancelCode.value, state.isMe)) - }) + showFragment( + VerificationConclusionFragment::class, + VerificationConclusionFragment.Args(false, state.sasTransactionState.cancelCode.value, state.isMe) + ) } } @@ -254,29 +259,32 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment { - showFragment(VerificationQrScannedByOtherFragment::class, Bundle()) + showFragment(VerificationQrScannedByOtherFragment::class) return@withState } is VerificationTxState.Started, is VerificationTxState.WaitingOtherReciprocateConfirm -> { - showFragment(VerificationQRWaitingFragment::class, Bundle().apply { - putParcelable(Mavericks.KEY_ARG, VerificationQRWaitingFragment.Args( - isMe = state.isMe, - otherUserName = state.otherUserMxItem?.getBestName() ?: "" - )) - }) + showFragment( + VerificationQRWaitingFragment::class, + VerificationQRWaitingFragment.Args( + isMe = state.isMe, + otherUserName = state.otherUserMxItem?.getBestName() ?: "" + ) + ) return@withState } is VerificationTxState.Verified -> { - showFragment(VerificationConclusionFragment::class, Bundle().apply { - putParcelable(Mavericks.KEY_ARG, VerificationConclusionFragment.Args(true, null, state.isMe)) - }) + showFragment( + VerificationConclusionFragment::class, + VerificationConclusionFragment.Args(true, null, state.isMe) + ) return@withState } is VerificationTxState.Cancelled -> { - showFragment(VerificationConclusionFragment::class, Bundle().apply { - putParcelable(Mavericks.KEY_ARG, VerificationConclusionFragment.Args(false, state.qrTransactionState.cancelCode.value, state.isMe)) - }) + showFragment( + VerificationConclusionFragment::class, + VerificationConclusionFragment.Args(false, state.qrTransactionState.cancelCode.value, state.isMe) + ) return@withState } else -> Unit @@ -288,12 +296,14 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment, bundle: Bundle) { + private fun showFragment(fragmentClass: KClass, parcelable: Parcelable? = null) { if (childFragmentManager.findFragmentByTag(fragmentClass.simpleName) == null) { childFragmentManager.commitTransaction { replace(R.id.bottomSheetFragmentContainer, fragmentClass.java, - bundle, + parcelable?.toMvRxBundle(), fragmentClass.simpleName ) } @@ -342,37 +360,31 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment