From 0f42f379c6f6125f40d2b5c6cef7bf328a66410c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 19 Nov 2021 17:12:38 +0100 Subject: [PATCH] Cleanup: use setArguments() and avoid direct usage of Mavericks.KEY_ARG `fun T.withArgs` should not be used anymore --- .../app/core/extensions/BasicExtensions.kt | 7 ------- .../home/room/detail/RoomDetailFragment.kt | 10 +++++----- .../DisplayReadReceiptsBottomSheet.kt | 10 +++------- .../edithistory/ViewEditHistoryBottomSheet.kt | 16 +++++++--------- .../reactions/ViewReactionsBottomSheet.kt | 16 +++++++--------- .../features/matrixto/MatrixToBottomSheet.kt | 19 +++++++------------ .../devices/DeviceListBottomSheet.kt | 7 +++---- .../DeviceVerificationInfoBottomSheet.kt | 8 +++----- .../RoomWidgetPermissionBottomSheet.kt | 8 ++++---- 9 files changed, 39 insertions(+), 62 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/extensions/BasicExtensions.kt b/vector/src/main/java/im/vector/app/core/extensions/BasicExtensions.kt index dbe90dfdc1..f8b8b83178 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/BasicExtensions.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/BasicExtensions.kt @@ -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.ooi(block: (T) -> Unit): T = also(block) -/** - * Apply argument to a Fragment - */ -fun T.withArgs(block: Bundle.() -> Unit) = apply { arguments = Bundle().apply(block) } - /** * Check if a CharSequence is an email */ diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt index 3fcdefaf56..bb69bd5339 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt @@ -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") } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/readreceipts/DisplayReadReceiptsBottomSheet.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/readreceipts/DisplayReadReceiptsBottomSheet.kt index 6c315a4e76..db80b02a6b 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/readreceipts/DisplayReadReceiptsBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/readreceipts/DisplayReadReceiptsBottomSheet.kt @@ -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): 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)) + } } } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryBottomSheet.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryBottomSheet.kt index 63140edd8b..321745355e 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/edithistory/ViewEditHistoryBottomSheet.kt @@ -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 + )) + } } } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/reactions/ViewReactionsBottomSheet.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/reactions/ViewReactionsBottomSheet.kt index 8071ed8809..6ae3cd227f 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/reactions/ViewReactionsBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/reactions/ViewReactionsBottomSheet.kt @@ -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 + )) + } } } } diff --git a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheet.kt b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheet.kt index 029234a66d..63e0398fc1 100644 --- a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheet.kt @@ -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)) } } } diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheet.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheet.kt index f83ac8f19d..bb2317b59c 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheet.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 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)) + } } } } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/DeviceVerificationInfoBottomSheet.kt b/vector/src/main/java/im/vector/app/features/settings/devices/DeviceVerificationInfoBottomSheet.kt index 441a344660..e5a67675e6 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/DeviceVerificationInfoBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/DeviceVerificationInfoBottomSheet.kt @@ -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)) + } } } diff --git a/vector/src/main/java/im/vector/app/features/widgets/permissions/RoomWidgetPermissionBottomSheet.kt b/vector/src/main/java/im/vector/app/features/widgets/permissions/RoomWidgetPermissionBottomSheet.kt index ae3028925a..58cfebba94 100644 --- a/vector/src/main/java/im/vector/app/features/widgets/permissions/RoomWidgetPermissionBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/widgets/permissions/RoomWidgetPermissionBottomSheet.kt @@ -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) + } } } }