Rename ShowLocationEvents -> ShowLocationEvent
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -37,7 +37,7 @@ class ShowLocationViewTest {
|
||||
|
||||
@Test
|
||||
fun `test back action`() {
|
||||
val eventsRecorder = EventsRecorder<ShowLocationEvents>(expectEvents = false)
|
||||
val eventsRecorder = EventsRecorder<ShowLocationEvent>(expectEvents = false)
|
||||
ensureCalledOnce { callback ->
|
||||
rule.setShowLocationView(
|
||||
state = aShowLocationState(
|
||||
@@ -51,7 +51,7 @@ class ShowLocationViewTest {
|
||||
|
||||
@Test
|
||||
fun `test share action`() {
|
||||
val eventsRecorder = EventsRecorder<ShowLocationEvents>()
|
||||
val eventsRecorder = EventsRecorder<ShowLocationEvent>()
|
||||
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<ShowLocationEvents>()
|
||||
val eventsRecorder = EventsRecorder<ShowLocationEvent>()
|
||||
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<ShowLocationEvents>()
|
||||
val eventsRecorder = EventsRecorder<ShowLocationEvent>()
|
||||
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<ShowLocationEvents>()
|
||||
val eventsRecorder = EventsRecorder<ShowLocationEvent>()
|
||||
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<ShowLocationEvents>()
|
||||
val eventsRecorder = EventsRecorder<ShowLocationEvent>()
|
||||
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<ShowLocationEvents>()
|
||||
val eventsRecorder = EventsRecorder<ShowLocationEvent>()
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user