Introduce fun aShowLocationState to reduce boilerplate code.

This commit is contained in:
Benoit Marty 2024-02-19 09:16:43 +01:00 committed by Benoit Marty
parent 6240f24e10
commit 9c599a298a

View file

@ -24,78 +24,47 @@ private const val APP_NAME = "ApplicationName"
class ShowLocationStateProvider : PreviewParameterProvider<ShowLocationState> { class ShowLocationStateProvider : PreviewParameterProvider<ShowLocationState> {
override val values: Sequence<ShowLocationState> override val values: Sequence<ShowLocationState>
get() = sequenceOf( get() = sequenceOf(
ShowLocationState( aShowLocationState(),
ShowLocationState.Dialog.None, aShowLocationState(
Location(1.23, 2.34, 4f), permissionDialog = ShowLocationState.Dialog.PermissionDenied,
description = null,
hasLocationPermission = false,
isTrackMyLocation = false,
appName = APP_NAME,
eventSink = {},
), ),
ShowLocationState( aShowLocationState(
ShowLocationState.Dialog.PermissionDenied, permissionDialog = ShowLocationState.Dialog.PermissionRationale,
Location(1.23, 2.34, 4f),
description = null,
hasLocationPermission = false,
isTrackMyLocation = false,
appName = APP_NAME,
eventSink = {},
), ),
ShowLocationState( aShowLocationState(
ShowLocationState.Dialog.PermissionRationale,
Location(1.23, 2.34, 4f),
description = null,
hasLocationPermission = false,
isTrackMyLocation = false,
appName = APP_NAME,
eventSink = {},
),
ShowLocationState(
ShowLocationState.Dialog.None,
Location(1.23, 2.34, 4f),
description = null,
hasLocationPermission = true, hasLocationPermission = true,
isTrackMyLocation = false,
appName = APP_NAME,
eventSink = {},
), ),
ShowLocationState( aShowLocationState(
ShowLocationState.Dialog.None,
Location(1.23, 2.34, 4f),
description = null,
hasLocationPermission = true, hasLocationPermission = true,
isTrackMyLocation = true, isTrackMyLocation = true,
appName = APP_NAME,
eventSink = {},
), ),
ShowLocationState( aShowLocationState(
ShowLocationState.Dialog.None,
Location(1.23, 2.34, 4f),
description = "My favourite place!", description = "My favourite place!",
hasLocationPermission = false,
isTrackMyLocation = false,
appName = APP_NAME,
eventSink = {},
), ),
ShowLocationState( aShowLocationState(
ShowLocationState.Dialog.None,
Location(1.23, 2.34, 4f),
description = "For some reason I decided to to write a small essay that wraps at just two lines!", description = "For some reason I decided to to write a small essay that wraps at just two lines!",
hasLocationPermission = false,
isTrackMyLocation = false,
appName = APP_NAME,
eventSink = {},
), ),
ShowLocationState( aShowLocationState(
ShowLocationState.Dialog.None,
Location(1.23, 2.34, 4f),
description = "For some reason I decided to write a small essay in the location description. " + description = "For some reason I decided to write a small essay in the location description. " +
"It is so long that it will wrap onto more than two lines!", "It is so long that it will wrap onto more than two lines!",
hasLocationPermission = false,
isTrackMyLocation = false,
appName = APP_NAME,
eventSink = {},
), ),
) )
} }
fun aShowLocationState(
permissionDialog: ShowLocationState.Dialog = ShowLocationState.Dialog.None,
location: Location = Location(1.23, 2.34, 4f),
description: String? = null,
hasLocationPermission: Boolean = false,
isTrackMyLocation: Boolean = false,
appName: String = APP_NAME,
eventSink: (ShowLocationEvents) -> Unit = {},
) = ShowLocationState(
permissionDialog = permissionDialog,
location = location,
description = description,
hasLocationPermission = hasLocationPermission,
isTrackMyLocation = isTrackMyLocation,
appName = appName,
eventSink = eventSink,
)