Cleanup: use setArguments() and avoid direct usage of Mavericks.KEY_ARG

`fun <T : Fragment> T.withArgs` should not be used anymore
This commit is contained in:
Benoit Marty 2021-11-19 17:12:38 +01:00
parent 292c09b176
commit 0f42f379c6
9 changed files with 39 additions and 62 deletions

View file

@ -16,9 +16,7 @@
package im.vector.app.core.extensions
import android.os.Bundle
import android.util.Patterns
import androidx.fragment.app.Fragment
import com.google.i18n.phonenumbers.NumberParseException
import com.google.i18n.phonenumbers.PhoneNumberUtil
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)
/**
* 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
*/

View file

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

View file

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

View file

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

View file

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

View file

@ -24,7 +24,6 @@ import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import com.airbnb.mvrx.Incomplete
import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import com.google.android.material.dialog.MaterialAlertDialogBuilder
@ -66,15 +65,15 @@ class MatrixToBottomSheet :
override fun invalidate() = withState(viewModel) { state ->
super.invalidate()
when (state.linkType) {
is PermalinkData.RoomLink -> {
is PermalinkData.RoomLink -> {
views.matrixToCardContentLoading.isVisible = state.roomPeekResult is Incomplete
showFragment(MatrixToRoomSpaceFragment::class, Bundle())
}
is PermalinkData.UserLink -> {
is PermalinkData.UserLink -> {
views.matrixToCardContentLoading.isVisible = state.matrixItem is Incomplete
showFragment(MatrixToUserFragment::class, Bundle())
}
is PermalinkData.GroupLink -> {
is PermalinkData.GroupLink -> {
}
is PermalinkData.FallbackLink -> {
}
@ -98,16 +97,16 @@ class MatrixToBottomSheet :
viewModel.observeViewEvents {
when (it) {
is MatrixToViewEvents.NavigateToRoom -> {
is MatrixToViewEvents.NavigateToRoom -> {
interactionListener?.mxToBottomSheetNavigateToRoom(it.roomId)
dismiss()
}
MatrixToViewEvents.Dismiss -> dismiss()
MatrixToViewEvents.Dismiss -> dismiss()
is MatrixToViewEvents.NavigateToSpace -> {
interactionListener?.mxToBottomSheetSwitchToSpace(it.spaceId)
dismiss()
}
is MatrixToViewEvents.ShowModalError -> {
is MatrixToViewEvents.ShowModalError -> {
MaterialAlertDialogBuilder(requireContext())
.setMessage(it.error)
.setPositiveButton(getString(R.string.ok), null)
@ -120,11 +119,7 @@ class MatrixToBottomSheet :
companion object {
fun withLink(matrixToLink: String): MatrixToBottomSheet {
return MatrixToBottomSheet().apply {
arguments = Bundle().apply {
putParcelable(Mavericks.KEY_ARG, MatrixToArgs(
matrixToLink = matrixToLink
))
}
setArguments(MatrixToArgs(matrixToLink = matrixToLink))
}
}
}

View file

@ -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 dagger.hilt.android.AndroidEntryPoint
@ -115,9 +114,9 @@ class DeviceListBottomSheet :
companion object {
fun newInstance(userId: String, allowDeviceAction: Boolean = true): DeviceListBottomSheet {
val args = Bundle()
args.putParcelable(Mavericks.KEY_ARG, Args(userId, allowDeviceAction))
return DeviceListBottomSheet().apply { arguments = args }
return DeviceListBottomSheet().apply {
setArguments(Args(userId, allowDeviceAction))
}
}
}
}

View file

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

View file

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