From 30919dcff45f91c6e272e535c2f992a3fca8af09 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 12 Mar 2026 12:47:52 +0100 Subject: [PATCH] Rename ShowLocationEvents -> ShowLocationEvent --- ...LocationEvents.kt => ShowLocationEvent.kt} | 14 +++++----- .../impl/show/ShowLocationPresenter.kt | 14 +++++----- .../location/impl/show/ShowLocationState.kt | 2 +- .../impl/show/ShowLocationStateProvider.kt | 2 +- .../location/impl/show/ShowLocationView.kt | 16 +++++------ .../impl/show/ShowLocationPresenterTest.kt | 28 +++++++++---------- .../impl/show/ShowLocationViewTest.kt | 26 ++++++++--------- 7 files changed, 51 insertions(+), 51 deletions(-) rename features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/{ShowLocationEvents.kt => ShowLocationEvent.kt} (64%) diff --git a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationEvents.kt b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationEvent.kt similarity index 64% rename from features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationEvents.kt rename to features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationEvent.kt index 52ff87b393..6a3e3521e0 100644 --- a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationEvents.kt +++ b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationEvent.kt @@ -10,11 +10,11 @@ package io.element.android.features.location.impl.show import io.element.android.features.location.api.Location -sealed interface ShowLocationEvents { - data class Share(val location: Location) : ShowLocationEvents - data class TrackMyLocation(val enabled: Boolean) : ShowLocationEvents - data object DismissDialog : ShowLocationEvents - data object RequestPermissions : ShowLocationEvents - data object OpenAppSettings : ShowLocationEvents - data object OpenLocationSettings : ShowLocationEvents +sealed interface ShowLocationEvent { + data class Share(val location: Location) : ShowLocationEvent + data class TrackMyLocation(val enabled: Boolean) : ShowLocationEvent + data object DismissDialog : ShowLocationEvent + data object RequestPermissions : ShowLocationEvent + data object OpenAppSettings : ShowLocationEvent + data object OpenLocationSettings : ShowLocationEvent } diff --git a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationPresenter.kt b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationPresenter.kt index 01021b9972..d74d2f36e1 100644 --- a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationPresenter.kt +++ b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationPresenter.kt @@ -68,12 +68,12 @@ class ShowLocationPresenter( } } - fun handleEvent(event: ShowLocationEvents) { + fun handleEvent(event: ShowLocationEvent) { when (event) { - is ShowLocationEvents.Share -> { + is ShowLocationEvent.Share -> { locationActions.share(event.location, null) } - is ShowLocationEvents.TrackMyLocation -> { + is ShowLocationEvent.TrackMyLocation -> { if (event.enabled) { val locationConstraints = checkLocationConstraints(permissionsState, locationActions) isTrackMyLocation = locationConstraints is LocationConstraintsCheck.Success @@ -82,16 +82,16 @@ class ShowLocationPresenter( isTrackMyLocation = false } } - ShowLocationEvents.DismissDialog -> dialogState = LocationConstraintsDialogState.None - ShowLocationEvents.OpenAppSettings -> { + ShowLocationEvent.DismissDialog -> dialogState = LocationConstraintsDialogState.None + ShowLocationEvent.OpenAppSettings -> { locationActions.openAppSettings() dialogState = LocationConstraintsDialogState.None } - ShowLocationEvents.OpenLocationSettings -> { + ShowLocationEvent.OpenLocationSettings -> { locationActions.openLocationSettings() dialogState = LocationConstraintsDialogState.None } - ShowLocationEvents.RequestPermissions -> permissionsState.eventSink(PermissionsEvents.RequestPermissions) + ShowLocationEvent.RequestPermissions -> permissionsState.eventSink(PermissionsEvents.RequestPermissions) } } diff --git a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationState.kt b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationState.kt index 3a8fcf51de..85d79f1192 100644 --- a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationState.kt +++ b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationState.kt @@ -24,7 +24,7 @@ data class ShowLocationState( val hasLocationPermission: Boolean, val isTrackMyLocation: Boolean, val appName: String, - val eventSink: (ShowLocationEvents) -> Unit, + val eventSink: (ShowLocationEvent) -> Unit, ) { val isSheetDraggable = locationShares.any { item -> item.isLive } } diff --git a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationStateProvider.kt b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationStateProvider.kt index 6880ed1bf5..7289ec000c 100644 --- a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationStateProvider.kt +++ b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationStateProvider.kt @@ -53,7 +53,7 @@ fun aShowLocationState( hasLocationPermission: Boolean = false, isTrackMyLocation: Boolean = false, appName: String = APP_NAME, - eventSink: (ShowLocationEvents) -> Unit = {}, + eventSink: (ShowLocationEvent) -> Unit = {}, ): ShowLocationState { val effectiveMarkers = markers ?: when (mode) { is ShowLocationMode.Static -> listOf( diff --git a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationView.kt b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationView.kt index 55fecf3e39..fdeb027b1e 100644 --- a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationView.kt +++ b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationView.kt @@ -57,10 +57,10 @@ fun ShowLocationView( LocationConstraintsDialog( state = state.dialogState, appName = state.appName, - onRequestPermissions = { state.eventSink(ShowLocationEvents.RequestPermissions) }, - onOpenAppSettings = { state.eventSink(ShowLocationEvents.OpenAppSettings) }, - onOpenLocationSettings = { state.eventSink(ShowLocationEvents.OpenLocationSettings) }, - onDismiss = { state.eventSink(ShowLocationEvents.DismissDialog) }, + onRequestPermissions = { state.eventSink(ShowLocationEvent.RequestPermissions) }, + onOpenAppSettings = { state.eventSink(ShowLocationEvent.OpenAppSettings) }, + onOpenLocationSettings = { state.eventSink(ShowLocationEvent.OpenLocationSettings) }, + onDismiss = { state.eventSink(ShowLocationEvent.DismissDialog) }, ) val initialPosition = when (val mode = state.mode) { @@ -74,7 +74,7 @@ fun ShowLocationView( val userLocationState = rememberUserLocationState(state.hasLocationPermission) LaunchedEffect(cameraState.isCameraMoving) { if (cameraState.moveReason == CameraMoveReason.GESTURE) { - state.eventSink(ShowLocationEvents.TrackMyLocation(false)) + state.eventSink(ShowLocationEvent.TrackMyLocation(false)) } } @@ -120,9 +120,9 @@ fun ShowLocationView( state.locationShares.forEach { locationShare -> LocationShareRow( item = locationShare, - onShareClick = { state.eventSink(ShowLocationEvents.Share(locationShare.location)) }, + onShareClick = { state.eventSink(ShowLocationEvent.Share(locationShare.location)) }, modifier = Modifier.clickable { - state.eventSink(ShowLocationEvents.TrackMyLocation(false)) + state.eventSink(ShowLocationEvent.TrackMyLocation(false)) val position = CameraPosition( padding = sheetPaddings, target = Position(locationShare.location.lon, locationShare.location.lat), @@ -146,7 +146,7 @@ fun ShowLocationView( overlayContent = { LocationFloatingActionButton( isMapCenteredOnUser = state.isTrackMyLocation, - onClick = { state.eventSink(ShowLocationEvents.TrackMyLocation(true)) }, + onClick = { state.eventSink(ShowLocationEvent.TrackMyLocation(true)) }, modifier = Modifier .align(Alignment.TopEnd) .padding(all = 16.dp), diff --git a/features/location/impl/src/test/kotlin/io/element/android/features/location/impl/show/ShowLocationPresenterTest.kt b/features/location/impl/src/test/kotlin/io/element/android/features/location/impl/show/ShowLocationPresenterTest.kt index a875800672..8a29f0463d 100644 --- a/features/location/impl/src/test/kotlin/io/element/android/features/location/impl/show/ShowLocationPresenterTest.kt +++ b/features/location/impl/src/test/kotlin/io/element/android/features/location/impl/show/ShowLocationPresenterTest.kt @@ -121,7 +121,7 @@ class ShowLocationPresenterTest { val presenter = createShowLocationPresenter() presenter.test { val initialState = awaitItem() - initialState.eventSink(ShowLocationEvents.Share(location)) + initialState.eventSink(ShowLocationEvent.Share(location)) assertThat(fakeLocationActions.sharedLocation).isEqualTo(location) } @@ -137,7 +137,7 @@ class ShowLocationPresenterTest { assertThat(initialState.hasLocationPermission).isTrue() assertThat(initialState.isTrackMyLocation).isFalse() - initialState.eventSink(ShowLocationEvents.TrackMyLocation(true)) + initialState.eventSink(ShowLocationEvent.TrackMyLocation(true)) val trackMyLocationState = awaitItem() delay(1) @@ -146,7 +146,7 @@ class ShowLocationPresenterTest { assertThat(trackMyLocationState.isTrackMyLocation).isTrue() // Swipe the map to switch mode - initialState.eventSink(ShowLocationEvents.TrackMyLocation(false)) + initialState.eventSink(ShowLocationEvent.TrackMyLocation(false)) val trackLocationDisabledState = awaitItem() assertThat(trackLocationDisabledState.dialogState).isEqualTo(LocationConstraintsDialogState.None) assertThat(trackLocationDisabledState.isTrackMyLocation).isFalse() @@ -169,14 +169,14 @@ class ShowLocationPresenterTest { val initialState = awaitItem() // Click on the button to switch mode - initialState.eventSink(ShowLocationEvents.TrackMyLocation(true)) + initialState.eventSink(ShowLocationEvent.TrackMyLocation(true)) val trackLocationState = awaitItem() assertThat(trackLocationState.dialogState).isEqualTo(LocationConstraintsDialogState.PermissionRationale) assertThat(trackLocationState.isTrackMyLocation).isFalse() assertThat(trackLocationState.hasLocationPermission).isFalse() // Dismiss the dialog - initialState.eventSink(ShowLocationEvents.DismissDialog) + initialState.eventSink(ShowLocationEvent.DismissDialog) val dialogDismissedState = awaitItem() assertThat(dialogDismissedState.dialogState).isEqualTo(LocationConstraintsDialogState.None) assertThat(dialogDismissedState.isTrackMyLocation).isFalse() @@ -198,14 +198,14 @@ class ShowLocationPresenterTest { val initialState = awaitItem() // Click on the button to switch mode - initialState.eventSink(ShowLocationEvents.TrackMyLocation(true)) + initialState.eventSink(ShowLocationEvent.TrackMyLocation(true)) val trackLocationState = awaitItem() assertThat(trackLocationState.dialogState).isEqualTo(LocationConstraintsDialogState.PermissionRationale) assertThat(trackLocationState.isTrackMyLocation).isFalse() assertThat(trackLocationState.hasLocationPermission).isFalse() // Continue the dialog sends permission request to the permissions presenter - trackLocationState.eventSink(ShowLocationEvents.RequestPermissions) + trackLocationState.eventSink(ShowLocationEvent.RequestPermissions) assertThat(fakePermissionsPresenter.events.last()).isEqualTo(PermissionsEvents.RequestPermissions) } } @@ -225,14 +225,14 @@ class ShowLocationPresenterTest { val initialState = awaitItem() // Click on the button to switch mode - initialState.eventSink(ShowLocationEvents.TrackMyLocation(true)) + initialState.eventSink(ShowLocationEvent.TrackMyLocation(true)) val trackLocationState = awaitItem() assertThat(trackLocationState.dialogState).isEqualTo(LocationConstraintsDialogState.PermissionDenied) assertThat(trackLocationState.isTrackMyLocation).isFalse() assertThat(trackLocationState.hasLocationPermission).isFalse() // Dismiss the dialog - initialState.eventSink(ShowLocationEvents.DismissDialog) + initialState.eventSink(ShowLocationEvent.DismissDialog) val dialogDismissedState = awaitItem() assertThat(dialogDismissedState.dialogState).isEqualTo(LocationConstraintsDialogState.None) assertThat(dialogDismissedState.isTrackMyLocation).isFalse() @@ -254,11 +254,11 @@ class ShowLocationPresenterTest { // Skip initial state val initialState = awaitItem() - initialState.eventSink(ShowLocationEvents.TrackMyLocation(true)) + initialState.eventSink(ShowLocationEvent.TrackMyLocation(true)) val dialogShownState = awaitItem() // Open settings - dialogShownState.eventSink(ShowLocationEvents.OpenAppSettings) + dialogShownState.eventSink(ShowLocationEvent.OpenAppSettings) val settingsOpenedState = awaitItem() assertThat(settingsOpenedState.dialogState).isEqualTo(LocationConstraintsDialogState.None) @@ -287,7 +287,7 @@ class ShowLocationPresenterTest { assertThat(initialState.hasLocationPermission).isTrue() // Try to track location when location services are disabled - initialState.eventSink(ShowLocationEvents.TrackMyLocation(true)) + initialState.eventSink(ShowLocationEvent.TrackMyLocation(true)) val dialogShownState = awaitItem() assertThat(dialogShownState.dialogState).isEqualTo(LocationConstraintsDialogState.LocationServiceDisabled) @@ -304,12 +304,12 @@ class ShowLocationPresenterTest { presenter.test { val initialState = awaitItem() - initialState.eventSink(ShowLocationEvents.TrackMyLocation(true)) + initialState.eventSink(ShowLocationEvent.TrackMyLocation(true)) val dialogShownState = awaitItem() assertThat(dialogShownState.dialogState).isEqualTo(LocationConstraintsDialogState.LocationServiceDisabled) // Open location settings - dialogShownState.eventSink(ShowLocationEvents.OpenLocationSettings) + dialogShownState.eventSink(ShowLocationEvent.OpenLocationSettings) val settingsOpenedState = awaitItem() assertThat(settingsOpenedState.dialogState).isEqualTo(LocationConstraintsDialogState.None) diff --git a/features/location/impl/src/test/kotlin/io/element/android/features/location/impl/show/ShowLocationViewTest.kt b/features/location/impl/src/test/kotlin/io/element/android/features/location/impl/show/ShowLocationViewTest.kt index a70d3441c4..fecbbdbf89 100644 --- a/features/location/impl/src/test/kotlin/io/element/android/features/location/impl/show/ShowLocationViewTest.kt +++ b/features/location/impl/src/test/kotlin/io/element/android/features/location/impl/show/ShowLocationViewTest.kt @@ -37,7 +37,7 @@ class ShowLocationViewTest { @Test fun `test back action`() { - val eventsRecorder = EventsRecorder(expectEvents = false) + val eventsRecorder = EventsRecorder(expectEvents = false) ensureCalledOnce { callback -> rule.setShowLocationView( state = aShowLocationState( @@ -51,7 +51,7 @@ class ShowLocationViewTest { @Test fun `test share action`() { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() rule.setShowLocationView( aShowLocationState( eventSink = eventsRecorder @@ -61,12 +61,12 @@ class ShowLocationViewTest { val shareContentDescription = rule.activity.getString(CommonStrings.action_share) rule.onNodeWithContentDescription(shareContentDescription).performClick() // The default aStaticLocationMode uses Location(1.23, 2.34, 4f) - eventsRecorder.assertSingle(ShowLocationEvents.Share(Location(1.23, 2.34, 4f))) + eventsRecorder.assertSingle(ShowLocationEvent.Share(Location(1.23, 2.34, 4f))) } @Test fun `test fab click`() { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() rule.setShowLocationView( aShowLocationState( eventSink = eventsRecorder @@ -74,12 +74,12 @@ class ShowLocationViewTest { onBackClick = EnsureNeverCalled(), ) rule.onNodeWithTag(TestTags.floatingActionButton.value).performClick() - eventsRecorder.assertSingle(ShowLocationEvents.TrackMyLocation(true)) + eventsRecorder.assertSingle(ShowLocationEvent.TrackMyLocation(true)) } @Test fun `when permission denied is displayed user can open the settings`() { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() rule.setShowLocationView( aShowLocationState( constraintsDialogState = LocationConstraintsDialogState.PermissionDenied, @@ -88,12 +88,12 @@ class ShowLocationViewTest { onBackClick = EnsureNeverCalled(), ) rule.clickOn(CommonStrings.action_continue) - eventsRecorder.assertSingle(ShowLocationEvents.OpenAppSettings) + eventsRecorder.assertSingle(ShowLocationEvent.OpenAppSettings) } @Test fun `when permission denied is displayed user can close the dialog`() { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() rule.setShowLocationView( aShowLocationState( constraintsDialogState = LocationConstraintsDialogState.PermissionDenied, @@ -102,12 +102,12 @@ class ShowLocationViewTest { onBackClick = EnsureNeverCalled(), ) rule.clickOn(CommonStrings.action_cancel) - eventsRecorder.assertSingle(ShowLocationEvents.DismissDialog) + eventsRecorder.assertSingle(ShowLocationEvent.DismissDialog) } @Test fun `when permission rationale is displayed user can request permissions`() { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() rule.setShowLocationView( aShowLocationState( constraintsDialogState = LocationConstraintsDialogState.PermissionRationale, @@ -116,12 +116,12 @@ class ShowLocationViewTest { onBackClick = EnsureNeverCalled(), ) rule.clickOn(CommonStrings.action_continue) - eventsRecorder.assertSingle(ShowLocationEvents.RequestPermissions) + eventsRecorder.assertSingle(ShowLocationEvent.RequestPermissions) } @Test fun `when permission rationale is displayed user can close the dialog`() { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() rule.setShowLocationView( aShowLocationState( constraintsDialogState = LocationConstraintsDialogState.PermissionRationale, @@ -130,7 +130,7 @@ class ShowLocationViewTest { onBackClick = EnsureNeverCalled(), ) rule.clickOn(CommonStrings.action_cancel) - eventsRecorder.assertSingle(ShowLocationEvents.DismissDialog) + eventsRecorder.assertSingle(ShowLocationEvent.DismissDialog) } }