Merge pull request #4526 from vector-im/feature/bma/setarguments

Some cleanup on Fragment argument
This commit is contained in:
Benoit Marty 2021-11-19 21:05:31 +01:00 committed by GitHub
commit 72360104fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 165 additions and 174 deletions

View File

@ -16,9 +16,7 @@
package im.vector.app.core.extensions package im.vector.app.core.extensions
import android.os.Bundle
import android.util.Patterns import android.util.Patterns
import androidx.fragment.app.Fragment
import com.google.i18n.phonenumbers.NumberParseException import com.google.i18n.phonenumbers.NumberParseException
import com.google.i18n.phonenumbers.PhoneNumberUtil import com.google.i18n.phonenumbers.PhoneNumberUtil
import org.matrix.android.sdk.api.extensions.ensurePrefix import org.matrix.android.sdk.api.extensions.ensurePrefix
@ -27,11 +25,6 @@ fun Boolean.toOnOff() = if (this) "ON" else "OFF"
inline fun <T> T.ooi(block: (T) -> Unit): T = also(block) inline fun <T> T.ooi(block: (T) -> Unit): T = also(block)
/**
* Apply argument to a Fragment
*/
fun <T : Fragment> T.withArgs(block: Bundle.() -> Unit) = apply { arguments = Bundle().apply(block) }
/** /**
* Check if a CharSequence is an email * Check if a CharSequence is an email
*/ */

View File

@ -22,6 +22,7 @@ import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Parcelable
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
@ -60,6 +61,7 @@ import im.vector.app.core.extensions.registerStartForActivityResult
import im.vector.app.core.extensions.restart import im.vector.app.core.extensions.restart
import im.vector.app.core.extensions.setTextOrHide import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.core.extensions.singletonEntryPoint import im.vector.app.core.extensions.singletonEntryPoint
import im.vector.app.core.extensions.toMvRxBundle
import im.vector.app.core.flow.throttleFirst import im.vector.app.core.flow.throttleFirst
import im.vector.app.core.utils.toast import im.vector.app.core.utils.toast
import im.vector.app.features.MainActivity import im.vector.app.features.MainActivity
@ -385,9 +387,9 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
bugReporter.inMultiWindowMode = isInMultiWindowMode bugReporter.inMultiWindowMode = isInMultiWindowMode
} }
protected fun createFragment(fragmentClass: Class<out Fragment>, args: Bundle?): Fragment { protected fun createFragment(fragmentClass: Class<out Fragment>, argsParcelable: Parcelable? = null): Fragment {
return fragmentFactory.instantiate(classLoader, fragmentClass.name).apply { return fragmentFactory.instantiate(classLoader, fragmentClass.name).apply {
arguments = args arguments = argsParcelable?.toMvRxBundle()
} }
} }

View File

@ -28,13 +28,13 @@ import androidx.annotation.CallSuper
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.viewbinding.ViewBinding import androidx.viewbinding.ViewBinding
import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.MavericksView import com.airbnb.mvrx.MavericksView
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import dagger.hilt.android.EntryPointAccessors import dagger.hilt.android.EntryPointAccessors
import im.vector.app.core.di.ActivityEntryPoint import im.vector.app.core.di.ActivityEntryPoint
import im.vector.app.core.extensions.toMvRxBundle
import im.vector.app.core.flow.throttleFirst import im.vector.app.core.flow.throttleFirst
import im.vector.app.core.utils.DimensionConverter import im.vector.app.core.utils.DimensionConverter
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
@ -159,7 +159,7 @@ abstract class VectorBaseBottomSheetDialogFragment<VB : ViewBinding> : BottomShe
} }
protected fun setArguments(args: Parcelable? = null) { protected fun setArguments(args: Parcelable? = null) {
arguments = args?.let { Bundle().apply { putParcelable(Mavericks.KEY_ARG, it) } } arguments = args.toMvRxBundle()
} }
/* ========================================================================================== /* ==========================================================================================

View File

@ -38,6 +38,7 @@ import im.vector.app.R
import im.vector.app.core.extensions.commitTransaction import im.vector.app.core.extensions.commitTransaction
import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.extensions.registerStartForActivityResult import im.vector.app.core.extensions.registerStartForActivityResult
import im.vector.app.core.extensions.toMvRxBundle
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.databinding.BottomSheetBootstrapBinding import im.vector.app.databinding.BottomSheetBootstrapBinding
import im.vector.app.features.auth.ReAuthActivity import im.vector.app.features.auth.ReAuthActivity
@ -154,48 +155,48 @@ class BootstrapBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetBoot
is BootstrapStep.CheckingMigration -> { is BootstrapStep.CheckingMigration -> {
views.bootstrapIcon.isVisible = false views.bootstrapIcon.isVisible = false
views.bootstrapTitleText.text = getString(R.string.bottom_sheet_setup_secure_backup_title) views.bootstrapTitleText.text = getString(R.string.bottom_sheet_setup_secure_backup_title)
showFragment(BootstrapWaitingFragment::class, Bundle()) showFragment(BootstrapWaitingFragment::class)
} }
is BootstrapStep.FirstForm -> { is BootstrapStep.FirstForm -> {
views.bootstrapIcon.isVisible = false views.bootstrapIcon.isVisible = false
views.bootstrapTitleText.text = getString(R.string.bottom_sheet_setup_secure_backup_title) views.bootstrapTitleText.text = getString(R.string.bottom_sheet_setup_secure_backup_title)
showFragment(BootstrapSetupRecoveryKeyFragment::class, Bundle()) showFragment(BootstrapSetupRecoveryKeyFragment::class)
} }
is BootstrapStep.SetupPassphrase -> { is BootstrapStep.SetupPassphrase -> {
views.bootstrapIcon.isVisible = true views.bootstrapIcon.isVisible = true
views.bootstrapIcon.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_security_phrase_24dp)) views.bootstrapIcon.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_security_phrase_24dp))
views.bootstrapTitleText.text = getString(R.string.set_a_security_phrase_title) views.bootstrapTitleText.text = getString(R.string.set_a_security_phrase_title)
showFragment(BootstrapEnterPassphraseFragment::class, Bundle()) showFragment(BootstrapEnterPassphraseFragment::class)
} }
is BootstrapStep.ConfirmPassphrase -> { is BootstrapStep.ConfirmPassphrase -> {
views.bootstrapIcon.isVisible = true views.bootstrapIcon.isVisible = true
views.bootstrapIcon.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_security_phrase_24dp)) views.bootstrapIcon.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_security_phrase_24dp))
views.bootstrapTitleText.text = getString(R.string.set_a_security_phrase_title) views.bootstrapTitleText.text = getString(R.string.set_a_security_phrase_title)
showFragment(BootstrapConfirmPassphraseFragment::class, Bundle()) showFragment(BootstrapConfirmPassphraseFragment::class)
} }
is BootstrapStep.AccountReAuth -> { is BootstrapStep.AccountReAuth -> {
views.bootstrapIcon.isVisible = true views.bootstrapIcon.isVisible = true
views.bootstrapIcon.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_user)) views.bootstrapIcon.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_user))
views.bootstrapTitleText.text = getString(R.string.re_authentication_activity_title) views.bootstrapTitleText.text = getString(R.string.re_authentication_activity_title)
showFragment(BootstrapReAuthFragment::class, Bundle()) showFragment(BootstrapReAuthFragment::class)
} }
is BootstrapStep.Initializing -> { is BootstrapStep.Initializing -> {
views.bootstrapIcon.isVisible = true views.bootstrapIcon.isVisible = true
views.bootstrapIcon.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_security_key_24dp)) views.bootstrapIcon.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_security_key_24dp))
views.bootstrapTitleText.text = getString(R.string.bootstrap_loading_title) views.bootstrapTitleText.text = getString(R.string.bootstrap_loading_title)
showFragment(BootstrapWaitingFragment::class, Bundle()) showFragment(BootstrapWaitingFragment::class)
} }
is BootstrapStep.SaveRecoveryKey -> { is BootstrapStep.SaveRecoveryKey -> {
views.bootstrapIcon.isVisible = true views.bootstrapIcon.isVisible = true
views.bootstrapIcon.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_security_key_24dp)) views.bootstrapIcon.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_security_key_24dp))
views.bootstrapTitleText.text = getString(R.string.bottom_sheet_save_your_recovery_key_title) views.bootstrapTitleText.text = getString(R.string.bottom_sheet_save_your_recovery_key_title)
showFragment(BootstrapSaveRecoveryKeyFragment::class, Bundle()) showFragment(BootstrapSaveRecoveryKeyFragment::class)
} }
is BootstrapStep.DoneSuccess -> { is BootstrapStep.DoneSuccess -> {
views.bootstrapIcon.isVisible = true views.bootstrapIcon.isVisible = true
views.bootstrapIcon.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_security_key_24dp)) views.bootstrapIcon.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_security_key_24dp))
views.bootstrapTitleText.text = getString(R.string.bootstrap_finish_title) views.bootstrapTitleText.text = getString(R.string.bootstrap_finish_title)
showFragment(BootstrapConclusionFragment::class, Bundle()) showFragment(BootstrapConclusionFragment::class)
} }
is BootstrapStep.GetBackupSecretForMigration -> { is BootstrapStep.GetBackupSecretForMigration -> {
val isKey = state.step.useKey() val isKey = state.step.useKey()
@ -206,7 +207,7 @@ class BootstrapBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetBoot
drawableRes) drawableRes)
) )
views.bootstrapTitleText.text = getString(R.string.upgrade_security) views.bootstrapTitleText.text = getString(R.string.upgrade_security)
showFragment(BootstrapMigrateBackupFragment::class, Bundle()) showFragment(BootstrapMigrateBackupFragment::class)
} }
}.exhaustive }.exhaustive
super.invalidate() super.invalidate()
@ -214,26 +215,22 @@ class BootstrapBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetBoot
companion object { companion object {
const val EXTRA_ARGS = "EXTRA_ARGS"
fun show(fragmentManager: FragmentManager, mode: SetupMode): BootstrapBottomSheet { fun show(fragmentManager: FragmentManager, mode: SetupMode): BootstrapBottomSheet {
return BootstrapBottomSheet().apply { return BootstrapBottomSheet().apply {
isCancelable = false isCancelable = false
arguments = Bundle().apply { setArguments(Args(setUpMode = mode))
this.putParcelable(EXTRA_ARGS, Args(setUpMode = mode))
}
}.also { }.also {
it.show(fragmentManager, "BootstrapBottomSheet") it.show(fragmentManager, "BootstrapBottomSheet")
} }
} }
} }
private fun showFragment(fragmentClass: KClass<out Fragment>, bundle: Bundle) { private fun showFragment(fragmentClass: KClass<out Fragment>, argsParcelable: Parcelable? = null) {
if (childFragmentManager.findFragmentByTag(fragmentClass.simpleName) == null) { if (childFragmentManager.findFragmentByTag(fragmentClass.simpleName) == null) {
childFragmentManager.commitTransaction { childFragmentManager.commitTransaction {
replace(R.id.bottomSheetFragmentContainer, replace(R.id.bottomSheetFragmentContainer,
fragmentClass.java, fragmentClass.java,
bundle, argsParcelable?.toMvRxBundle(),
fragmentClass.simpleName fragmentClass.simpleName
) )
} }

View File

@ -24,7 +24,6 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
import com.google.android.material.dialog.MaterialAlertDialogBuilder 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.commitTransaction
import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.extensions.registerStartForActivityResult 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.VectorBaseActivity
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.databinding.BottomSheetVerificationBinding import im.vector.app.databinding.BottomSheetVerificationBinding
@ -178,36 +178,37 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetV
} }
if (state.quadSHasBeenReset) { if (state.quadSHasBeenReset) {
showFragment(VerificationConclusionFragment::class, Bundle().apply { showFragment(
putParcelable(Mavericks.KEY_ARG, VerificationConclusionFragment.Args( VerificationConclusionFragment::class,
VerificationConclusionFragment.Args(
isSuccessFull = true, isSuccessFull = true,
isMe = true, isMe = true,
cancelReason = null cancelReason = null
)) ))
})
return@withState return@withState
} }
if (state.userThinkItsNotHim) { if (state.userThinkItsNotHim) {
views.otherUserNameText.text = getString(R.string.dialog_title_warning) views.otherUserNameText.text = getString(R.string.dialog_title_warning)
showFragment(VerificationNotMeFragment::class, Bundle()) showFragment(VerificationNotMeFragment::class)
return@withState return@withState
} }
if (state.userWantsToCancel) { if (state.userWantsToCancel) {
views.otherUserNameText.text = getString(R.string.are_you_sure) views.otherUserNameText.text = getString(R.string.are_you_sure)
showFragment(VerificationCancelFragment::class, Bundle()) showFragment(VerificationCancelFragment::class)
return@withState return@withState
} }
if (state.selfVerificationMode && state.verifyingFrom4S) { if (state.selfVerificationMode && state.verifyingFrom4S) {
showFragment(QuadSLoadingFragment::class, Bundle()) showFragment(QuadSLoadingFragment::class)
return@withState return@withState
} }
if (state.selfVerificationMode && state.verifiedFromPrivateKeys) { if (state.selfVerificationMode && state.verifiedFromPrivateKeys) {
showFragment(VerificationConclusionFragment::class, Bundle().apply { showFragment(
putParcelable(Mavericks.KEY_ARG, VerificationConclusionFragment.Args(true, null, state.isMe)) VerificationConclusionFragment::class,
}) VerificationConclusionFragment.Args(true, null, state.isMe)
)
return@withState return@withState
} }
@ -229,23 +230,27 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetV
is VerificationTxState.SendingMac, is VerificationTxState.SendingMac,
is VerificationTxState.MacSent, is VerificationTxState.MacSent,
is VerificationTxState.Verifying -> { is VerificationTxState.Verifying -> {
showFragment(VerificationEmojiCodeFragment::class, Bundle().apply { showFragment(
putParcelable(Mavericks.KEY_ARG, VerificationArgs( VerificationEmojiCodeFragment::class,
VerificationArgs(
state.otherUserMxItem?.id ?: "", state.otherUserMxItem?.id ?: "",
// If it was outgoing it.transaction id would be null, but the pending request // If it was outgoing it.transaction id would be null, but the pending request
// would be updated (from localId to txId) // would be updated (from localId to txId)
state.pendingRequest.invoke()?.transactionId ?: state.transactionId)) state.pendingRequest.invoke()?.transactionId ?: state.transactionId
}) )
)
} }
is VerificationTxState.Verified -> { is VerificationTxState.Verified -> {
showFragment(VerificationConclusionFragment::class, Bundle().apply { showFragment(
putParcelable(Mavericks.KEY_ARG, VerificationConclusionFragment.Args(true, null, state.isMe)) VerificationConclusionFragment::class,
}) VerificationConclusionFragment.Args(true, null, state.isMe)
)
} }
is VerificationTxState.Cancelled -> { is VerificationTxState.Cancelled -> {
showFragment(VerificationConclusionFragment::class, Bundle().apply { showFragment(
putParcelable(Mavericks.KEY_ARG, VerificationConclusionFragment.Args(false, state.sasTransactionState.cancelCode.value, state.isMe)) VerificationConclusionFragment::class,
}) VerificationConclusionFragment.Args(false, state.sasTransactionState.cancelCode.value, state.isMe)
)
} }
} }
@ -254,29 +259,32 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetV
when (state.qrTransactionState) { when (state.qrTransactionState) {
is VerificationTxState.QrScannedByOther -> { is VerificationTxState.QrScannedByOther -> {
showFragment(VerificationQrScannedByOtherFragment::class, Bundle()) showFragment(VerificationQrScannedByOtherFragment::class)
return@withState return@withState
} }
is VerificationTxState.Started, is VerificationTxState.Started,
is VerificationTxState.WaitingOtherReciprocateConfirm -> { is VerificationTxState.WaitingOtherReciprocateConfirm -> {
showFragment(VerificationQRWaitingFragment::class, Bundle().apply { showFragment(
putParcelable(Mavericks.KEY_ARG, VerificationQRWaitingFragment.Args( VerificationQRWaitingFragment::class,
VerificationQRWaitingFragment.Args(
isMe = state.isMe, isMe = state.isMe,
otherUserName = state.otherUserMxItem?.getBestName() ?: "" otherUserName = state.otherUserMxItem?.getBestName() ?: ""
)) )
}) )
return@withState return@withState
} }
is VerificationTxState.Verified -> { is VerificationTxState.Verified -> {
showFragment(VerificationConclusionFragment::class, Bundle().apply { showFragment(
putParcelable(Mavericks.KEY_ARG, VerificationConclusionFragment.Args(true, null, state.isMe)) VerificationConclusionFragment::class,
}) VerificationConclusionFragment.Args(true, null, state.isMe)
)
return@withState return@withState
} }
is VerificationTxState.Cancelled -> { is VerificationTxState.Cancelled -> {
showFragment(VerificationConclusionFragment::class, Bundle().apply { showFragment(
putParcelable(Mavericks.KEY_ARG, VerificationConclusionFragment.Args(false, state.qrTransactionState.cancelCode.value, state.isMe)) VerificationConclusionFragment::class,
}) VerificationConclusionFragment.Args(false, state.qrTransactionState.cancelCode.value, state.isMe)
)
return@withState return@withState
} }
else -> Unit else -> Unit
@ -288,12 +296,14 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetV
if (state.pendingRequest.invoke()?.cancelConclusion != null) { if (state.pendingRequest.invoke()?.cancelConclusion != null) {
// The request has been declined, we should dismiss // The request has been declined, we should dismiss
views.otherUserNameText.text = getString(R.string.verification_cancelled) views.otherUserNameText.text = getString(R.string.verification_cancelled)
showFragment(VerificationConclusionFragment::class, Bundle().apply { showFragment(
putParcelable(Mavericks.KEY_ARG, VerificationConclusionFragment.Args( VerificationConclusionFragment::class,
false, VerificationConclusionFragment.Args(
state.pendingRequest.invoke()?.cancelConclusion?.value ?: CancelCode.User.value, isSuccessFull = false,
state.isMe)) cancelReason = state.pendingRequest.invoke()?.cancelConclusion?.value ?: CancelCode.User.value,
}) isMe = state.isMe
)
)
return@withState return@withState
} }
@ -303,36 +313,44 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetV
if (state.pendingRequest.invoke()?.isReady == true) { if (state.pendingRequest.invoke()?.isReady == true) {
Timber.v("## SAS show bottom sheet for outgoing and ready request") Timber.v("## SAS show bottom sheet for outgoing and ready request")
// Show choose method fragment with waiting // Show choose method fragment with waiting
showFragment(VerificationChooseMethodFragment::class, Bundle().apply { showFragment(
putParcelable(Mavericks.KEY_ARG, VerificationArgs(state.otherUserMxItem?.id VerificationChooseMethodFragment::class,
?: "", state.pendingRequest.invoke()?.transactionId)) VerificationArgs(
}) otherUserId = state.otherUserMxItem?.id ?: "",
verificationId = state.pendingRequest.invoke()?.transactionId
)
)
} else { } else {
// Stay on the start fragment // Stay on the start fragment
showFragment(VerificationRequestFragment::class, Bundle().apply { showFragment(
putParcelable(Mavericks.KEY_ARG, VerificationArgs( VerificationRequestFragment::class,
state.otherUserMxItem?.id ?: "", VerificationArgs(
state.pendingRequest.invoke()?.transactionId, otherUserId = state.otherUserMxItem?.id ?: "",
state.roomId)) verificationId = state.pendingRequest.invoke()?.transactionId,
}) verificationLocalId = state.roomId
)
)
} }
} else if (state.pendingRequest.invoke()?.isIncoming == true) { } else if (state.pendingRequest.invoke()?.isIncoming == true) {
Timber.v("## SAS show bottom sheet for Incoming request") 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 // For incoming we can switch to choose method because ready is being sent or already sent
showFragment(VerificationChooseMethodFragment::class, Bundle().apply { showFragment(
putParcelable(Mavericks.KEY_ARG, VerificationArgs(state.otherUserMxItem?.id VerificationChooseMethodFragment::class,
?: "", state.pendingRequest.invoke()?.transactionId)) VerificationArgs(
}) otherUserId = state.otherUserMxItem?.id ?: "",
verificationId = state.pendingRequest.invoke()?.transactionId
)
)
} }
super.invalidate() super.invalidate()
} }
private fun showFragment(fragmentClass: KClass<out Fragment>, bundle: Bundle) { private fun showFragment(fragmentClass: KClass<out Fragment>, argsParcelable: Parcelable? = null) {
if (childFragmentManager.findFragmentByTag(fragmentClass.simpleName) == null) { if (childFragmentManager.findFragmentByTag(fragmentClass.simpleName) == null) {
childFragmentManager.commitTransaction { childFragmentManager.commitTransaction {
replace(R.id.bottomSheetFragmentContainer, replace(R.id.bottomSheetFragmentContainer,
fragmentClass.java, fragmentClass.java,
bundle, argsParcelable?.toMvRxBundle(),
fragmentClass.simpleName fragmentClass.simpleName
) )
} }
@ -342,8 +360,7 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetV
companion object { companion object {
fun withArgs(roomId: String?, otherUserId: String, transactionId: String? = null): VerificationBottomSheet { fun withArgs(roomId: String?, otherUserId: String, transactionId: String? = null): VerificationBottomSheet {
return VerificationBottomSheet().apply { return VerificationBottomSheet().apply {
arguments = Bundle().apply { setArguments(VerificationArgs(
putParcelable(Mavericks.KEY_ARG, VerificationArgs(
otherUserId = otherUserId, otherUserId = otherUserId,
roomId = roomId, roomId = roomId,
verificationId = transactionId, verificationId = transactionId,
@ -351,30 +368,25 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetV
)) ))
} }
} }
}
fun forSelfVerification(session: Session): VerificationBottomSheet { fun forSelfVerification(session: Session): VerificationBottomSheet {
return VerificationBottomSheet().apply { return VerificationBottomSheet().apply {
arguments = Bundle().apply { setArguments(VerificationArgs(
putParcelable(Mavericks.KEY_ARG, VerificationArgs(
otherUserId = session.myUserId, otherUserId = session.myUserId,
selfVerificationMode = true selfVerificationMode = true
)) ))
} }
} }
}
fun forSelfVerification(session: Session, outgoingRequest: String): VerificationBottomSheet { fun forSelfVerification(session: Session, outgoingRequest: String): VerificationBottomSheet {
return VerificationBottomSheet().apply { return VerificationBottomSheet().apply {
arguments = Bundle().apply { setArguments(VerificationArgs(
putParcelable(Mavericks.KEY_ARG, VerificationArgs(
otherUserId = session.myUserId, otherUserId = session.myUserId,
selfVerificationMode = true, selfVerificationMode = true,
verificationId = outgoingRequest verificationId = outgoingRequest
)) ))
} }
} }
}
const val WAITING_SELF_VERIF_TAG: String = "WAITING_SELF_VERIF_TAG" const val WAITING_SELF_VERIF_TAG: String = "WAITING_SELF_VERIF_TAG"
} }

View File

@ -18,7 +18,6 @@ package im.vector.app.features.devtools
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle
import android.os.Parcelable import android.os.Parcelable
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
@ -37,7 +36,6 @@ import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.extensions.replaceFragment import im.vector.app.core.extensions.replaceFragment
import im.vector.app.core.extensions.toMvRxBundle
import im.vector.app.core.platform.SimpleFragmentActivity import im.vector.app.core.platform.SimpleFragmentActivity
import im.vector.app.core.resources.ColorProvider import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.utils.createJSonViewerStyleProvider import im.vector.app.core.utils.createJSonViewerStyleProvider
@ -109,15 +107,15 @@ class RoomDevToolActivity : SimpleFragmentActivity(), FragmentManager.OnBackStac
} }
RoomDevToolViewState.Mode.StateEventList, RoomDevToolViewState.Mode.StateEventList,
RoomDevToolViewState.Mode.StateEventListByType -> { RoomDevToolViewState.Mode.StateEventListByType -> {
val frag = createFragment(RoomDevToolStateEventListFragment::class.java, Bundle().toMvRxBundle()) val frag = createFragment(RoomDevToolStateEventListFragment::class.java)
navigateTo(frag) navigateTo(frag)
} }
RoomDevToolViewState.Mode.EditEventContent -> { RoomDevToolViewState.Mode.EditEventContent -> {
val frag = createFragment(RoomDevToolEditFragment::class.java, Bundle().toMvRxBundle()) val frag = createFragment(RoomDevToolEditFragment::class.java)
navigateTo(frag) navigateTo(frag)
} }
is RoomDevToolViewState.Mode.SendEventForm -> { is RoomDevToolViewState.Mode.SendEventForm -> {
val frag = createFragment(RoomDevToolSendFormFragment::class.java, Bundle().toMvRxBundle()) val frag = createFragment(RoomDevToolSendFormFragment::class.java)
navigateTo(frag) navigateTo(frag)
} }
} }

View File

@ -62,7 +62,6 @@ import com.airbnb.epoxy.EpoxyModel
import com.airbnb.epoxy.OnModelBuildFinishedListener import com.airbnb.epoxy.OnModelBuildFinishedListener
import com.airbnb.epoxy.addGlidePreloader import com.airbnb.epoxy.addGlidePreloader
import com.airbnb.epoxy.glidePreloader import com.airbnb.epoxy.glidePreloader
import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.args import com.airbnb.mvrx.args
import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
@ -1635,10 +1634,11 @@ class RoomDetailFragment @Inject constructor(
is RoomDetailAction.ResumeVerification -> { is RoomDetailAction.ResumeVerification -> {
val otherUserId = data.otherUserId ?: return val otherUserId = data.otherUserId ?: return
VerificationBottomSheet().apply { VerificationBottomSheet().apply {
arguments = Bundle().apply { setArguments(VerificationBottomSheet.VerificationArgs(
putParcelable(Mavericks.KEY_ARG, VerificationBottomSheet.VerificationArgs( otherUserId = otherUserId,
otherUserId, data.transactionId, roomId = roomDetailArgs.roomId)) verificationId = data.transactionId,
} roomId = roomDetailArgs.roomId
))
}.show(parentFragmentManager, "REQ") }.show(parentFragmentManager, "REQ")
} }
} }

View File

@ -21,7 +21,6 @@ import android.os.Parcelable
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.args import com.airbnb.mvrx.args
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R import im.vector.app.R
@ -81,12 +80,9 @@ class DisplayReadReceiptsBottomSheet :
companion object { companion object {
fun newInstance(readReceipts: List<ReadReceiptData>): DisplayReadReceiptsBottomSheet { fun newInstance(readReceipts: List<ReadReceiptData>): DisplayReadReceiptsBottomSheet {
val args = Bundle() return DisplayReadReceiptsBottomSheet().apply {
val parcelableArgs = DisplayReadReceiptArgs( setArguments(DisplayReadReceiptArgs(readReceipts = readReceipts))
readReceipts }
)
args.putParcelable(Mavericks.KEY_ARG, parcelableArgs)
return DisplayReadReceiptsBottomSheet().apply { arguments = args }
} }
} }
} }

View File

@ -19,7 +19,6 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
@ -68,14 +67,13 @@ class ViewEditHistoryBottomSheet :
companion object { companion object {
fun newInstance(roomId: String, informationData: MessageInformationData): ViewEditHistoryBottomSheet { fun newInstance(roomId: String, informationData: MessageInformationData): ViewEditHistoryBottomSheet {
val args = Bundle() return ViewEditHistoryBottomSheet().apply {
val parcelableArgs = TimelineEventFragmentArgs( setArguments(TimelineEventFragmentArgs(
informationData.eventId, eventId = informationData.eventId,
roomId, roomId = roomId,
informationData informationData = informationData
) ))
args.putParcelable(Mavericks.KEY_ARG, parcelableArgs) }
return ViewEditHistoryBottomSheet().apply { arguments = args }
} }
} }
} }

View File

@ -20,7 +20,6 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
@ -82,14 +81,13 @@ class ViewReactionsBottomSheet :
companion object { companion object {
fun newInstance(roomId: String, informationData: MessageInformationData): ViewReactionsBottomSheet { fun newInstance(roomId: String, informationData: MessageInformationData): ViewReactionsBottomSheet {
val args = Bundle() return ViewReactionsBottomSheet().apply {
val parcelableArgs = TimelineEventFragmentArgs( setArguments(TimelineEventFragmentArgs(
informationData.eventId, eventId = informationData.eventId,
roomId, roomId = roomId,
informationData informationData = informationData
) ))
args.putParcelable(Mavericks.KEY_ARG, parcelableArgs) }
return ViewReactionsBottomSheet().apply { arguments = args }
} }
} }
} }

View File

@ -24,7 +24,6 @@ import android.view.ViewGroup
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.airbnb.mvrx.Incomplete import com.airbnb.mvrx.Incomplete
import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
@ -120,11 +119,7 @@ class MatrixToBottomSheet :
companion object { companion object {
fun withLink(matrixToLink: String): MatrixToBottomSheet { fun withLink(matrixToLink: String): MatrixToBottomSheet {
return MatrixToBottomSheet().apply { return MatrixToBottomSheet().apply {
arguments = Bundle().apply { setArguments(MatrixToArgs(matrixToLink = matrixToLink))
putParcelable(Mavericks.KEY_ARG, MatrixToArgs(
matrixToLink = matrixToLink
))
}
} }
} }
} }

View File

@ -24,7 +24,6 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
@ -115,9 +114,9 @@ class DeviceListBottomSheet :
companion object { companion object {
fun newInstance(userId: String, allowDeviceAction: Boolean = true): DeviceListBottomSheet { fun newInstance(userId: String, allowDeviceAction: Boolean = true): DeviceListBottomSheet {
val args = Bundle() return DeviceListBottomSheet().apply {
args.putParcelable(Mavericks.KEY_ARG, Args(userId, allowDeviceAction)) setArguments(Args(userId, allowDeviceAction))
return DeviceListBottomSheet().apply { arguments = args } }
} }
} }
} }

View File

@ -21,7 +21,6 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.parentFragmentViewModel import com.airbnb.mvrx.parentFragmentViewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
@ -76,10 +75,9 @@ class DeviceVerificationInfoBottomSheet :
companion object { companion object {
fun newInstance(userId: String, deviceId: String): DeviceVerificationInfoBottomSheet { fun newInstance(userId: String, deviceId: String): DeviceVerificationInfoBottomSheet {
val args = Bundle() return DeviceVerificationInfoBottomSheet().apply {
val parcelableArgs = DeviceVerificationInfoArgs(userId, deviceId) setArguments(DeviceVerificationInfoArgs(userId, deviceId))
args.putParcelable(Mavericks.KEY_ARG, parcelableArgs) }
return DeviceVerificationInfoBottomSheet().apply { arguments = args }
} }
} }

View File

@ -26,7 +26,6 @@ import com.airbnb.mvrx.withState
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.extensions.toMvRxBundle
import im.vector.app.core.platform.SimpleFragmentActivity import im.vector.app.core.platform.SimpleFragmentActivity
import im.vector.app.features.spaces.create.ChoosePrivateSpaceTypeFragment import im.vector.app.features.spaces.create.ChoosePrivateSpaceTypeFragment
import im.vector.app.features.spaces.create.ChooseSpaceTypeFragment import im.vector.app.features.spaces.create.ChooseSpaceTypeFragment
@ -121,7 +120,7 @@ class SpaceCreationActivity : SimpleFragmentActivity() {
} }
private fun navigateToFragment(fragmentClass: Class<out Fragment>) { private fun navigateToFragment(fragmentClass: Class<out Fragment>) {
val frag = supportFragmentManager.findFragmentByTag(fragmentClass.name) ?: createFragment(fragmentClass, Bundle().toMvRxBundle()) val frag = supportFragmentManager.findFragmentByTag(fragmentClass.name) ?: createFragment(fragmentClass)
supportFragmentManager.beginTransaction() supportFragmentManager.beginTransaction()
.setCustomAnimations(R.anim.fade_in, R.anim.fade_out, R.anim.fade_in, R.anim.fade_out) .setCustomAnimations(R.anim.fade_in, R.anim.fade_out, R.anim.fade_in, R.anim.fade_out)
.replace(R.id.container, .replace(R.id.container,

View File

@ -23,12 +23,10 @@ import android.text.style.BulletSpan
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.extensions.withArgs
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.databinding.BottomSheetRoomWidgetPermissionBinding import im.vector.app.databinding.BottomSheetRoomWidgetPermissionBinding
import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.AvatarRenderer
@ -111,8 +109,10 @@ class RoomWidgetPermissionBottomSheet :
companion object { companion object {
fun newInstance(widgetArgs: WidgetArgs) = RoomWidgetPermissionBottomSheet().withArgs { fun newInstance(widgetArgs: WidgetArgs): RoomWidgetPermissionBottomSheet {
putParcelable(Mavericks.KEY_ARG, widgetArgs) return RoomWidgetPermissionBottomSheet().apply {
setArguments(widgetArgs)
}
} }
} }
} }

View File

@ -35,6 +35,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:imeOptions="actionDone" android:imeOptions="actionDone"
android:inputType="textPassword"
android:maxLines="3" android:maxLines="3"
android:singleLine="false" android:singleLine="false"
tools:hint="@string/passphrase_enter_passphrase" /> tools:hint="@string/passphrase_enter_passphrase" />

View File

@ -33,6 +33,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:imeOptions="actionDone" android:imeOptions="actionDone"
android:inputType="textPassword"
android:maxLines="3" android:maxLines="3"
android:singleLine="false" android:singleLine="false"
tools:hint="@string/passphrase_enter_passphrase" /> tools:hint="@string/passphrase_enter_passphrase" />

View File

@ -35,6 +35,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:imeOptions="actionDone" android:imeOptions="actionDone"
android:inputType="textPassword"
android:maxLines="3" android:maxLines="3"
android:singleLine="false" android:singleLine="false"
tools:hint="@string/keys_backup_restore_key_enter_hint" /> tools:hint="@string/keys_backup_restore_key_enter_hint" />

View File

@ -56,6 +56,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/passphrase_enter_passphrase" android:hint="@string/passphrase_enter_passphrase"
android:inputType="textPassword"
android:maxLines="3" android:maxLines="3"
android:singleLine="false" /> android:singleLine="false" />

View File

@ -58,6 +58,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/passphrase_create_passphrase" android:hint="@string/passphrase_create_passphrase"
android:inputType="textPassword"
android:maxLines="3" /> android:maxLines="3" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
@ -86,6 +87,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/passphrase_confirm_passphrase" android:hint="@string/passphrase_confirm_passphrase"
android:inputType="textPassword"
android:maxLines="3" /> android:maxLines="3" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>

View File

@ -70,9 +70,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/passphrase_enter_passphrase" android:hint="@string/passphrase_enter_passphrase"
android:imeOptions="actionDone" android:imeOptions="actionDone"
android:inputType="textPassword"
android:maxLines="3" android:maxLines="3"
android:singleLine="false" android:singleLine="false" />
tools:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>