Rename ShowLocationEvents -> ShowLocationEvent

This commit is contained in:
ganfra
2026-03-12 12:47:52 +01:00
parent 089b0cd847
commit 30919dcff4
7 changed files with 51 additions and 51 deletions

View File

@@ -10,11 +10,11 @@ package io.element.android.features.location.impl.show
import io.element.android.features.location.api.Location import io.element.android.features.location.api.Location
sealed interface ShowLocationEvents { sealed interface ShowLocationEvent {
data class Share(val location: Location) : ShowLocationEvents data class Share(val location: Location) : ShowLocationEvent
data class TrackMyLocation(val enabled: Boolean) : ShowLocationEvents data class TrackMyLocation(val enabled: Boolean) : ShowLocationEvent
data object DismissDialog : ShowLocationEvents data object DismissDialog : ShowLocationEvent
data object RequestPermissions : ShowLocationEvents data object RequestPermissions : ShowLocationEvent
data object OpenAppSettings : ShowLocationEvents data object OpenAppSettings : ShowLocationEvent
data object OpenLocationSettings : ShowLocationEvents data object OpenLocationSettings : ShowLocationEvent
} }

View File

@@ -68,12 +68,12 @@ class ShowLocationPresenter(
} }
} }
fun handleEvent(event: ShowLocationEvents) { fun handleEvent(event: ShowLocationEvent) {
when (event) { when (event) {
is ShowLocationEvents.Share -> { is ShowLocationEvent.Share -> {
locationActions.share(event.location, null) locationActions.share(event.location, null)
} }
is ShowLocationEvents.TrackMyLocation -> { is ShowLocationEvent.TrackMyLocation -> {
if (event.enabled) { if (event.enabled) {
val locationConstraints = checkLocationConstraints(permissionsState, locationActions) val locationConstraints = checkLocationConstraints(permissionsState, locationActions)
isTrackMyLocation = locationConstraints is LocationConstraintsCheck.Success isTrackMyLocation = locationConstraints is LocationConstraintsCheck.Success
@@ -82,16 +82,16 @@ class ShowLocationPresenter(
isTrackMyLocation = false isTrackMyLocation = false
} }
} }
ShowLocationEvents.DismissDialog -> dialogState = LocationConstraintsDialogState.None ShowLocationEvent.DismissDialog -> dialogState = LocationConstraintsDialogState.None
ShowLocationEvents.OpenAppSettings -> { ShowLocationEvent.OpenAppSettings -> {
locationActions.openAppSettings() locationActions.openAppSettings()
dialogState = LocationConstraintsDialogState.None dialogState = LocationConstraintsDialogState.None
} }
ShowLocationEvents.OpenLocationSettings -> { ShowLocationEvent.OpenLocationSettings -> {
locationActions.openLocationSettings() locationActions.openLocationSettings()
dialogState = LocationConstraintsDialogState.None dialogState = LocationConstraintsDialogState.None
} }
ShowLocationEvents.RequestPermissions -> permissionsState.eventSink(PermissionsEvents.RequestPermissions) ShowLocationEvent.RequestPermissions -> permissionsState.eventSink(PermissionsEvents.RequestPermissions)
} }
} }

View File

@@ -24,7 +24,7 @@ data class ShowLocationState(
val hasLocationPermission: Boolean, val hasLocationPermission: Boolean,
val isTrackMyLocation: Boolean, val isTrackMyLocation: Boolean,
val appName: String, val appName: String,
val eventSink: (ShowLocationEvents) -> Unit, val eventSink: (ShowLocationEvent) -> Unit,
) { ) {
val isSheetDraggable = locationShares.any { item -> item.isLive } val isSheetDraggable = locationShares.any { item -> item.isLive }
} }

View File

@@ -53,7 +53,7 @@ fun aShowLocationState(
hasLocationPermission: Boolean = false, hasLocationPermission: Boolean = false,
isTrackMyLocation: Boolean = false, isTrackMyLocation: Boolean = false,
appName: String = APP_NAME, appName: String = APP_NAME,
eventSink: (ShowLocationEvents) -> Unit = {}, eventSink: (ShowLocationEvent) -> Unit = {},
): ShowLocationState { ): ShowLocationState {
val effectiveMarkers = markers ?: when (mode) { val effectiveMarkers = markers ?: when (mode) {
is ShowLocationMode.Static -> listOf( is ShowLocationMode.Static -> listOf(

View File

@@ -57,10 +57,10 @@ fun ShowLocationView(
LocationConstraintsDialog( LocationConstraintsDialog(
state = state.dialogState, state = state.dialogState,
appName = state.appName, appName = state.appName,
onRequestPermissions = { state.eventSink(ShowLocationEvents.RequestPermissions) }, onRequestPermissions = { state.eventSink(ShowLocationEvent.RequestPermissions) },
onOpenAppSettings = { state.eventSink(ShowLocationEvents.OpenAppSettings) }, onOpenAppSettings = { state.eventSink(ShowLocationEvent.OpenAppSettings) },
onOpenLocationSettings = { state.eventSink(ShowLocationEvents.OpenLocationSettings) }, onOpenLocationSettings = { state.eventSink(ShowLocationEvent.OpenLocationSettings) },
onDismiss = { state.eventSink(ShowLocationEvents.DismissDialog) }, onDismiss = { state.eventSink(ShowLocationEvent.DismissDialog) },
) )
val initialPosition = when (val mode = state.mode) { val initialPosition = when (val mode = state.mode) {
@@ -74,7 +74,7 @@ fun ShowLocationView(
val userLocationState = rememberUserLocationState(state.hasLocationPermission) val userLocationState = rememberUserLocationState(state.hasLocationPermission)
LaunchedEffect(cameraState.isCameraMoving) { LaunchedEffect(cameraState.isCameraMoving) {
if (cameraState.moveReason == CameraMoveReason.GESTURE) { 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 -> state.locationShares.forEach { locationShare ->
LocationShareRow( LocationShareRow(
item = locationShare, item = locationShare,
onShareClick = { state.eventSink(ShowLocationEvents.Share(locationShare.location)) }, onShareClick = { state.eventSink(ShowLocationEvent.Share(locationShare.location)) },
modifier = Modifier.clickable { modifier = Modifier.clickable {
state.eventSink(ShowLocationEvents.TrackMyLocation(false)) state.eventSink(ShowLocationEvent.TrackMyLocation(false))
val position = CameraPosition( val position = CameraPosition(
padding = sheetPaddings, padding = sheetPaddings,
target = Position(locationShare.location.lon, locationShare.location.lat), target = Position(locationShare.location.lon, locationShare.location.lat),
@@ -146,7 +146,7 @@ fun ShowLocationView(
overlayContent = { overlayContent = {
LocationFloatingActionButton( LocationFloatingActionButton(
isMapCenteredOnUser = state.isTrackMyLocation, isMapCenteredOnUser = state.isTrackMyLocation,
onClick = { state.eventSink(ShowLocationEvents.TrackMyLocation(true)) }, onClick = { state.eventSink(ShowLocationEvent.TrackMyLocation(true)) },
modifier = Modifier modifier = Modifier
.align(Alignment.TopEnd) .align(Alignment.TopEnd)
.padding(all = 16.dp), .padding(all = 16.dp),

View File

@@ -121,7 +121,7 @@ class ShowLocationPresenterTest {
val presenter = createShowLocationPresenter() val presenter = createShowLocationPresenter()
presenter.test { presenter.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(ShowLocationEvents.Share(location)) initialState.eventSink(ShowLocationEvent.Share(location))
assertThat(fakeLocationActions.sharedLocation).isEqualTo(location) assertThat(fakeLocationActions.sharedLocation).isEqualTo(location)
} }
@@ -137,7 +137,7 @@ class ShowLocationPresenterTest {
assertThat(initialState.hasLocationPermission).isTrue() assertThat(initialState.hasLocationPermission).isTrue()
assertThat(initialState.isTrackMyLocation).isFalse() assertThat(initialState.isTrackMyLocation).isFalse()
initialState.eventSink(ShowLocationEvents.TrackMyLocation(true)) initialState.eventSink(ShowLocationEvent.TrackMyLocation(true))
val trackMyLocationState = awaitItem() val trackMyLocationState = awaitItem()
delay(1) delay(1)
@@ -146,7 +146,7 @@ class ShowLocationPresenterTest {
assertThat(trackMyLocationState.isTrackMyLocation).isTrue() assertThat(trackMyLocationState.isTrackMyLocation).isTrue()
// Swipe the map to switch mode // Swipe the map to switch mode
initialState.eventSink(ShowLocationEvents.TrackMyLocation(false)) initialState.eventSink(ShowLocationEvent.TrackMyLocation(false))
val trackLocationDisabledState = awaitItem() val trackLocationDisabledState = awaitItem()
assertThat(trackLocationDisabledState.dialogState).isEqualTo(LocationConstraintsDialogState.None) assertThat(trackLocationDisabledState.dialogState).isEqualTo(LocationConstraintsDialogState.None)
assertThat(trackLocationDisabledState.isTrackMyLocation).isFalse() assertThat(trackLocationDisabledState.isTrackMyLocation).isFalse()
@@ -169,14 +169,14 @@ class ShowLocationPresenterTest {
val initialState = awaitItem() val initialState = awaitItem()
// Click on the button to switch mode // Click on the button to switch mode
initialState.eventSink(ShowLocationEvents.TrackMyLocation(true)) initialState.eventSink(ShowLocationEvent.TrackMyLocation(true))
val trackLocationState = awaitItem() val trackLocationState = awaitItem()
assertThat(trackLocationState.dialogState).isEqualTo(LocationConstraintsDialogState.PermissionRationale) assertThat(trackLocationState.dialogState).isEqualTo(LocationConstraintsDialogState.PermissionRationale)
assertThat(trackLocationState.isTrackMyLocation).isFalse() assertThat(trackLocationState.isTrackMyLocation).isFalse()
assertThat(trackLocationState.hasLocationPermission).isFalse() assertThat(trackLocationState.hasLocationPermission).isFalse()
// Dismiss the dialog // Dismiss the dialog
initialState.eventSink(ShowLocationEvents.DismissDialog) initialState.eventSink(ShowLocationEvent.DismissDialog)
val dialogDismissedState = awaitItem() val dialogDismissedState = awaitItem()
assertThat(dialogDismissedState.dialogState).isEqualTo(LocationConstraintsDialogState.None) assertThat(dialogDismissedState.dialogState).isEqualTo(LocationConstraintsDialogState.None)
assertThat(dialogDismissedState.isTrackMyLocation).isFalse() assertThat(dialogDismissedState.isTrackMyLocation).isFalse()
@@ -198,14 +198,14 @@ class ShowLocationPresenterTest {
val initialState = awaitItem() val initialState = awaitItem()
// Click on the button to switch mode // Click on the button to switch mode
initialState.eventSink(ShowLocationEvents.TrackMyLocation(true)) initialState.eventSink(ShowLocationEvent.TrackMyLocation(true))
val trackLocationState = awaitItem() val trackLocationState = awaitItem()
assertThat(trackLocationState.dialogState).isEqualTo(LocationConstraintsDialogState.PermissionRationale) assertThat(trackLocationState.dialogState).isEqualTo(LocationConstraintsDialogState.PermissionRationale)
assertThat(trackLocationState.isTrackMyLocation).isFalse() assertThat(trackLocationState.isTrackMyLocation).isFalse()
assertThat(trackLocationState.hasLocationPermission).isFalse() assertThat(trackLocationState.hasLocationPermission).isFalse()
// Continue the dialog sends permission request to the permissions presenter // 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) assertThat(fakePermissionsPresenter.events.last()).isEqualTo(PermissionsEvents.RequestPermissions)
} }
} }
@@ -225,14 +225,14 @@ class ShowLocationPresenterTest {
val initialState = awaitItem() val initialState = awaitItem()
// Click on the button to switch mode // Click on the button to switch mode
initialState.eventSink(ShowLocationEvents.TrackMyLocation(true)) initialState.eventSink(ShowLocationEvent.TrackMyLocation(true))
val trackLocationState = awaitItem() val trackLocationState = awaitItem()
assertThat(trackLocationState.dialogState).isEqualTo(LocationConstraintsDialogState.PermissionDenied) assertThat(trackLocationState.dialogState).isEqualTo(LocationConstraintsDialogState.PermissionDenied)
assertThat(trackLocationState.isTrackMyLocation).isFalse() assertThat(trackLocationState.isTrackMyLocation).isFalse()
assertThat(trackLocationState.hasLocationPermission).isFalse() assertThat(trackLocationState.hasLocationPermission).isFalse()
// Dismiss the dialog // Dismiss the dialog
initialState.eventSink(ShowLocationEvents.DismissDialog) initialState.eventSink(ShowLocationEvent.DismissDialog)
val dialogDismissedState = awaitItem() val dialogDismissedState = awaitItem()
assertThat(dialogDismissedState.dialogState).isEqualTo(LocationConstraintsDialogState.None) assertThat(dialogDismissedState.dialogState).isEqualTo(LocationConstraintsDialogState.None)
assertThat(dialogDismissedState.isTrackMyLocation).isFalse() assertThat(dialogDismissedState.isTrackMyLocation).isFalse()
@@ -254,11 +254,11 @@ class ShowLocationPresenterTest {
// Skip initial state // Skip initial state
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(ShowLocationEvents.TrackMyLocation(true)) initialState.eventSink(ShowLocationEvent.TrackMyLocation(true))
val dialogShownState = awaitItem() val dialogShownState = awaitItem()
// Open settings // Open settings
dialogShownState.eventSink(ShowLocationEvents.OpenAppSettings) dialogShownState.eventSink(ShowLocationEvent.OpenAppSettings)
val settingsOpenedState = awaitItem() val settingsOpenedState = awaitItem()
assertThat(settingsOpenedState.dialogState).isEqualTo(LocationConstraintsDialogState.None) assertThat(settingsOpenedState.dialogState).isEqualTo(LocationConstraintsDialogState.None)
@@ -287,7 +287,7 @@ class ShowLocationPresenterTest {
assertThat(initialState.hasLocationPermission).isTrue() assertThat(initialState.hasLocationPermission).isTrue()
// Try to track location when location services are disabled // Try to track location when location services are disabled
initialState.eventSink(ShowLocationEvents.TrackMyLocation(true)) initialState.eventSink(ShowLocationEvent.TrackMyLocation(true))
val dialogShownState = awaitItem() val dialogShownState = awaitItem()
assertThat(dialogShownState.dialogState).isEqualTo(LocationConstraintsDialogState.LocationServiceDisabled) assertThat(dialogShownState.dialogState).isEqualTo(LocationConstraintsDialogState.LocationServiceDisabled)
@@ -304,12 +304,12 @@ class ShowLocationPresenterTest {
presenter.test { presenter.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(ShowLocationEvents.TrackMyLocation(true)) initialState.eventSink(ShowLocationEvent.TrackMyLocation(true))
val dialogShownState = awaitItem() val dialogShownState = awaitItem()
assertThat(dialogShownState.dialogState).isEqualTo(LocationConstraintsDialogState.LocationServiceDisabled) assertThat(dialogShownState.dialogState).isEqualTo(LocationConstraintsDialogState.LocationServiceDisabled)
// Open location settings // Open location settings
dialogShownState.eventSink(ShowLocationEvents.OpenLocationSettings) dialogShownState.eventSink(ShowLocationEvent.OpenLocationSettings)
val settingsOpenedState = awaitItem() val settingsOpenedState = awaitItem()
assertThat(settingsOpenedState.dialogState).isEqualTo(LocationConstraintsDialogState.None) assertThat(settingsOpenedState.dialogState).isEqualTo(LocationConstraintsDialogState.None)

View File

@@ -37,7 +37,7 @@ class ShowLocationViewTest {
@Test @Test
fun `test back action`() { fun `test back action`() {
val eventsRecorder = EventsRecorder<ShowLocationEvents>(expectEvents = false) val eventsRecorder = EventsRecorder<ShowLocationEvent>(expectEvents = false)
ensureCalledOnce { callback -> ensureCalledOnce { callback ->
rule.setShowLocationView( rule.setShowLocationView(
state = aShowLocationState( state = aShowLocationState(
@@ -51,7 +51,7 @@ class ShowLocationViewTest {
@Test @Test
fun `test share action`() { fun `test share action`() {
val eventsRecorder = EventsRecorder<ShowLocationEvents>() val eventsRecorder = EventsRecorder<ShowLocationEvent>()
rule.setShowLocationView( rule.setShowLocationView(
aShowLocationState( aShowLocationState(
eventSink = eventsRecorder eventSink = eventsRecorder
@@ -61,12 +61,12 @@ class ShowLocationViewTest {
val shareContentDescription = rule.activity.getString(CommonStrings.action_share) val shareContentDescription = rule.activity.getString(CommonStrings.action_share)
rule.onNodeWithContentDescription(shareContentDescription).performClick() rule.onNodeWithContentDescription(shareContentDescription).performClick()
// The default aStaticLocationMode uses Location(1.23, 2.34, 4f) // 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 @Test
fun `test fab click`() { fun `test fab click`() {
val eventsRecorder = EventsRecorder<ShowLocationEvents>() val eventsRecorder = EventsRecorder<ShowLocationEvent>()
rule.setShowLocationView( rule.setShowLocationView(
aShowLocationState( aShowLocationState(
eventSink = eventsRecorder eventSink = eventsRecorder
@@ -74,12 +74,12 @@ class ShowLocationViewTest {
onBackClick = EnsureNeverCalled(), onBackClick = EnsureNeverCalled(),
) )
rule.onNodeWithTag(TestTags.floatingActionButton.value).performClick() rule.onNodeWithTag(TestTags.floatingActionButton.value).performClick()
eventsRecorder.assertSingle(ShowLocationEvents.TrackMyLocation(true)) eventsRecorder.assertSingle(ShowLocationEvent.TrackMyLocation(true))
} }
@Test @Test
fun `when permission denied is displayed user can open the settings`() { fun `when permission denied is displayed user can open the settings`() {
val eventsRecorder = EventsRecorder<ShowLocationEvents>() val eventsRecorder = EventsRecorder<ShowLocationEvent>()
rule.setShowLocationView( rule.setShowLocationView(
aShowLocationState( aShowLocationState(
constraintsDialogState = LocationConstraintsDialogState.PermissionDenied, constraintsDialogState = LocationConstraintsDialogState.PermissionDenied,
@@ -88,12 +88,12 @@ class ShowLocationViewTest {
onBackClick = EnsureNeverCalled(), onBackClick = EnsureNeverCalled(),
) )
rule.clickOn(CommonStrings.action_continue) rule.clickOn(CommonStrings.action_continue)
eventsRecorder.assertSingle(ShowLocationEvents.OpenAppSettings) eventsRecorder.assertSingle(ShowLocationEvent.OpenAppSettings)
} }
@Test @Test
fun `when permission denied is displayed user can close the dialog`() { fun `when permission denied is displayed user can close the dialog`() {
val eventsRecorder = EventsRecorder<ShowLocationEvents>() val eventsRecorder = EventsRecorder<ShowLocationEvent>()
rule.setShowLocationView( rule.setShowLocationView(
aShowLocationState( aShowLocationState(
constraintsDialogState = LocationConstraintsDialogState.PermissionDenied, constraintsDialogState = LocationConstraintsDialogState.PermissionDenied,
@@ -102,12 +102,12 @@ class ShowLocationViewTest {
onBackClick = EnsureNeverCalled(), onBackClick = EnsureNeverCalled(),
) )
rule.clickOn(CommonStrings.action_cancel) rule.clickOn(CommonStrings.action_cancel)
eventsRecorder.assertSingle(ShowLocationEvents.DismissDialog) eventsRecorder.assertSingle(ShowLocationEvent.DismissDialog)
} }
@Test @Test
fun `when permission rationale is displayed user can request permissions`() { fun `when permission rationale is displayed user can request permissions`() {
val eventsRecorder = EventsRecorder<ShowLocationEvents>() val eventsRecorder = EventsRecorder<ShowLocationEvent>()
rule.setShowLocationView( rule.setShowLocationView(
aShowLocationState( aShowLocationState(
constraintsDialogState = LocationConstraintsDialogState.PermissionRationale, constraintsDialogState = LocationConstraintsDialogState.PermissionRationale,
@@ -116,12 +116,12 @@ class ShowLocationViewTest {
onBackClick = EnsureNeverCalled(), onBackClick = EnsureNeverCalled(),
) )
rule.clickOn(CommonStrings.action_continue) rule.clickOn(CommonStrings.action_continue)
eventsRecorder.assertSingle(ShowLocationEvents.RequestPermissions) eventsRecorder.assertSingle(ShowLocationEvent.RequestPermissions)
} }
@Test @Test
fun `when permission rationale is displayed user can close the dialog`() { fun `when permission rationale is displayed user can close the dialog`() {
val eventsRecorder = EventsRecorder<ShowLocationEvents>() val eventsRecorder = EventsRecorder<ShowLocationEvent>()
rule.setShowLocationView( rule.setShowLocationView(
aShowLocationState( aShowLocationState(
constraintsDialogState = LocationConstraintsDialogState.PermissionRationale, constraintsDialogState = LocationConstraintsDialogState.PermissionRationale,
@@ -130,7 +130,7 @@ class ShowLocationViewTest {
onBackClick = EnsureNeverCalled(), onBackClick = EnsureNeverCalled(),
) )
rule.clickOn(CommonStrings.action_cancel) rule.clickOn(CommonStrings.action_cancel)
eventsRecorder.assertSingle(ShowLocationEvents.DismissDialog) eventsRecorder.assertSingle(ShowLocationEvent.DismissDialog)
} }
} }