mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 18:35:40 +03:00
Cleanup: Use extension, use setArguments() and avoid direct usage of Mavericks.KEY_ARG
This commit is contained in:
parent
d0f5a10c76
commit
292c09b176
1 changed files with 95 additions and 83 deletions
|
@ -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<BottomSheetV
|
|||
}
|
||||
|
||||
if (state.quadSHasBeenReset) {
|
||||
showFragment(VerificationConclusionFragment::class, Bundle().apply {
|
||||
putParcelable(Mavericks.KEY_ARG, VerificationConclusionFragment.Args(
|
||||
isSuccessFull = true,
|
||||
isMe = true,
|
||||
cancelReason = null
|
||||
))
|
||||
})
|
||||
showFragment(
|
||||
VerificationConclusionFragment::class,
|
||||
VerificationConclusionFragment.Args(
|
||||
isSuccessFull = true,
|
||||
isMe = true,
|
||||
cancelReason = null
|
||||
))
|
||||
return@withState
|
||||
}
|
||||
|
||||
if (state.userThinkItsNotHim) {
|
||||
views.otherUserNameText.text = getString(R.string.dialog_title_warning)
|
||||
showFragment(VerificationNotMeFragment::class, Bundle())
|
||||
showFragment(VerificationNotMeFragment::class)
|
||||
return@withState
|
||||
}
|
||||
|
||||
if (state.userWantsToCancel) {
|
||||
views.otherUserNameText.text = getString(R.string.are_you_sure)
|
||||
showFragment(VerificationCancelFragment::class, Bundle())
|
||||
showFragment(VerificationCancelFragment::class)
|
||||
return@withState
|
||||
}
|
||||
|
||||
if (state.selfVerificationMode && state.verifyingFrom4S) {
|
||||
showFragment(QuadSLoadingFragment::class, Bundle())
|
||||
showFragment(QuadSLoadingFragment::class)
|
||||
return@withState
|
||||
}
|
||||
if (state.selfVerificationMode && state.verifiedFromPrivateKeys) {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -229,23 +230,27 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetV
|
|||
is VerificationTxState.SendingMac,
|
||||
is VerificationTxState.MacSent,
|
||||
is VerificationTxState.Verifying -> {
|
||||
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<BottomSheetV
|
|||
|
||||
when (state.qrTransactionState) {
|
||||
is VerificationTxState.QrScannedByOther -> {
|
||||
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<BottomSheetV
|
|||
if (state.pendingRequest.invoke()?.cancelConclusion != null) {
|
||||
// The request has been declined, we should dismiss
|
||||
views.otherUserNameText.text = getString(R.string.verification_cancelled)
|
||||
showFragment(VerificationConclusionFragment::class, Bundle().apply {
|
||||
putParcelable(Mavericks.KEY_ARG, VerificationConclusionFragment.Args(
|
||||
false,
|
||||
state.pendingRequest.invoke()?.cancelConclusion?.value ?: CancelCode.User.value,
|
||||
state.isMe))
|
||||
})
|
||||
showFragment(
|
||||
VerificationConclusionFragment::class,
|
||||
VerificationConclusionFragment.Args(
|
||||
isSuccessFull = false,
|
||||
cancelReason = state.pendingRequest.invoke()?.cancelConclusion?.value ?: CancelCode.User.value,
|
||||
isMe = state.isMe
|
||||
)
|
||||
)
|
||||
return@withState
|
||||
}
|
||||
|
||||
|
@ -303,36 +313,44 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetV
|
|||
if (state.pendingRequest.invoke()?.isReady == true) {
|
||||
Timber.v("## SAS show bottom sheet for outgoing and ready request")
|
||||
// Show choose method fragment with waiting
|
||||
showFragment(VerificationChooseMethodFragment::class, Bundle().apply {
|
||||
putParcelable(Mavericks.KEY_ARG, VerificationArgs(state.otherUserMxItem?.id
|
||||
?: "", state.pendingRequest.invoke()?.transactionId))
|
||||
})
|
||||
showFragment(
|
||||
VerificationChooseMethodFragment::class,
|
||||
VerificationArgs(
|
||||
otherUserId = state.otherUserMxItem?.id ?: "",
|
||||
verificationId = state.pendingRequest.invoke()?.transactionId
|
||||
)
|
||||
)
|
||||
} else {
|
||||
// Stay on the start fragment
|
||||
showFragment(VerificationRequestFragment::class, Bundle().apply {
|
||||
putParcelable(Mavericks.KEY_ARG, VerificationArgs(
|
||||
state.otherUserMxItem?.id ?: "",
|
||||
state.pendingRequest.invoke()?.transactionId,
|
||||
state.roomId))
|
||||
})
|
||||
showFragment(
|
||||
VerificationRequestFragment::class,
|
||||
VerificationArgs(
|
||||
otherUserId = state.otherUserMxItem?.id ?: "",
|
||||
verificationId = state.pendingRequest.invoke()?.transactionId,
|
||||
verificationLocalId = state.roomId
|
||||
)
|
||||
)
|
||||
}
|
||||
} else if (state.pendingRequest.invoke()?.isIncoming == true) {
|
||||
Timber.v("## SAS show bottom sheet for Incoming request")
|
||||
// For incoming we can switch to choose method because ready is being sent or already sent
|
||||
showFragment(VerificationChooseMethodFragment::class, Bundle().apply {
|
||||
putParcelable(Mavericks.KEY_ARG, VerificationArgs(state.otherUserMxItem?.id
|
||||
?: "", state.pendingRequest.invoke()?.transactionId))
|
||||
})
|
||||
showFragment(
|
||||
VerificationChooseMethodFragment::class,
|
||||
VerificationArgs(
|
||||
otherUserId = state.otherUserMxItem?.id ?: "",
|
||||
verificationId = state.pendingRequest.invoke()?.transactionId
|
||||
)
|
||||
)
|
||||
}
|
||||
super.invalidate()
|
||||
}
|
||||
|
||||
private fun showFragment(fragmentClass: KClass<out Fragment>, bundle: Bundle) {
|
||||
private fun showFragment(fragmentClass: KClass<out Fragment>, 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<BottomSheetV
|
|||
companion object {
|
||||
fun withArgs(roomId: String?, otherUserId: String, transactionId: String? = null): VerificationBottomSheet {
|
||||
return VerificationBottomSheet().apply {
|
||||
arguments = Bundle().apply {
|
||||
putParcelable(Mavericks.KEY_ARG, VerificationArgs(
|
||||
otherUserId = otherUserId,
|
||||
roomId = roomId,
|
||||
verificationId = transactionId,
|
||||
selfVerificationMode = false
|
||||
))
|
||||
}
|
||||
setArguments(VerificationArgs(
|
||||
otherUserId = otherUserId,
|
||||
roomId = roomId,
|
||||
verificationId = transactionId,
|
||||
selfVerificationMode = false
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fun forSelfVerification(session: Session): VerificationBottomSheet {
|
||||
return VerificationBottomSheet().apply {
|
||||
arguments = Bundle().apply {
|
||||
putParcelable(Mavericks.KEY_ARG, VerificationArgs(
|
||||
otherUserId = session.myUserId,
|
||||
selfVerificationMode = true
|
||||
))
|
||||
}
|
||||
setArguments(VerificationArgs(
|
||||
otherUserId = session.myUserId,
|
||||
selfVerificationMode = true
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fun forSelfVerification(session: Session, outgoingRequest: String): VerificationBottomSheet {
|
||||
return VerificationBottomSheet().apply {
|
||||
arguments = Bundle().apply {
|
||||
putParcelable(Mavericks.KEY_ARG, VerificationArgs(
|
||||
otherUserId = session.myUserId,
|
||||
selfVerificationMode = true,
|
||||
verificationId = outgoingRequest
|
||||
))
|
||||
}
|
||||
setArguments(VerificationArgs(
|
||||
otherUserId = session.myUserId,
|
||||
selfVerificationMode = true,
|
||||
verificationId = outgoingRequest
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue