Simplify ShowLocationState
This commit is contained in:
@@ -78,7 +78,11 @@ fun LocationShareRow(
|
||||
modifier = Modifier.size(16.dp),
|
||||
)
|
||||
} else {
|
||||
val icon = if (item.assetType == AssetType.PIN) CompoundIcons.LocationNavigator() else CompoundIcons.LocationNavigatorCentred()
|
||||
val icon = if (item.assetType == AssetType.PIN) {
|
||||
CompoundIcons.LocationNavigator()
|
||||
} else {
|
||||
CompoundIcons.LocationNavigatorCentred()
|
||||
}
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = null,
|
||||
@@ -120,8 +124,8 @@ internal fun LocationShareRowPreview() = ElementPreview {
|
||||
size = AvatarSize.UserListItem,
|
||||
),
|
||||
formattedTimestamp = "Shared 1 min ago",
|
||||
assetType = AssetType.SENDER,
|
||||
isLive = true,
|
||||
assetType = AssetType.SENDER,
|
||||
location = Location(0.0, 0.0)
|
||||
),
|
||||
onShareClick = {},
|
||||
@@ -136,9 +140,9 @@ internal fun LocationShareRowPreview() = ElementPreview {
|
||||
url = null,
|
||||
size = AvatarSize.UserListItem,
|
||||
),
|
||||
isLive = false,
|
||||
assetType = AssetType.PIN,
|
||||
formattedTimestamp = "Shared 5 hours ago",
|
||||
isLive = false,
|
||||
location = Location(0.0, 0.0)
|
||||
),
|
||||
onShareClick = {},
|
||||
|
||||
@@ -28,15 +28,12 @@ import io.element.android.features.location.impl.common.permissions.PermissionsP
|
||||
import io.element.android.features.location.impl.common.permissions.PermissionsState
|
||||
import io.element.android.features.location.impl.common.toDialogState
|
||||
import io.element.android.features.location.impl.common.ui.LocationConstraintsDialogState
|
||||
import io.element.android.features.location.impl.common.ui.LocationMarkerData
|
||||
import io.element.android.libraries.architecture.Presenter
|
||||
import io.element.android.libraries.core.meta.BuildMeta
|
||||
import io.element.android.libraries.dateformatter.api.DateFormatter
|
||||
import io.element.android.libraries.dateformatter.api.DateFormatterMode
|
||||
import io.element.android.libraries.designsystem.components.PinVariant
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
|
||||
import io.element.android.libraries.matrix.api.room.location.AssetType
|
||||
import io.element.android.libraries.ui.strings.CommonStrings
|
||||
import io.element.android.services.toolbox.api.strings.StringProvider
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
@@ -99,34 +96,6 @@ class ShowLocationPresenter(
|
||||
}
|
||||
}
|
||||
|
||||
val markers = remember {
|
||||
when (mode) {
|
||||
is ShowLocationMode.Static -> {
|
||||
val pinVariant = if (mode.assetType == AssetType.PIN) {
|
||||
PinVariant.PinnedLocation
|
||||
} else {
|
||||
PinVariant.UserLocation(
|
||||
avatarData = AvatarData(
|
||||
id = mode.senderId.value,
|
||||
name = mode.senderName,
|
||||
url = mode.senderAvatarUrl,
|
||||
size = AvatarSize.UserListItem,
|
||||
),
|
||||
isLive = false,
|
||||
)
|
||||
}
|
||||
persistentListOf(
|
||||
LocationMarkerData(
|
||||
id = mode.senderId.value,
|
||||
location = mode.location,
|
||||
variant = pinVariant,
|
||||
)
|
||||
)
|
||||
}
|
||||
ShowLocationMode.Live -> persistentListOf()
|
||||
}
|
||||
}
|
||||
|
||||
val locationShares = remember {
|
||||
when (mode) {
|
||||
is ShowLocationMode.Static -> {
|
||||
@@ -146,9 +115,9 @@ class ShowLocationPresenter(
|
||||
size = AvatarSize.UserListItem,
|
||||
),
|
||||
formattedTimestamp = formattedTimestamp,
|
||||
location = mode.location,
|
||||
isLive = false,
|
||||
assetType = mode.assetType,
|
||||
location = mode.location,
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -158,7 +127,6 @@ class ShowLocationPresenter(
|
||||
|
||||
return ShowLocationState(
|
||||
dialogState = dialogState,
|
||||
markers = markers,
|
||||
locationShares = locationShares,
|
||||
hasLocationPermission = permissionsState.isAnyGranted,
|
||||
isTrackMyLocation = isTrackMyLocation,
|
||||
|
||||
@@ -11,6 +11,7 @@ package io.element.android.features.location.impl.show
|
||||
import io.element.android.features.location.api.Location
|
||||
import io.element.android.features.location.impl.common.ui.LocationConstraintsDialogState
|
||||
import io.element.android.features.location.impl.common.ui.LocationMarkerData
|
||||
import io.element.android.libraries.designsystem.components.PinVariant
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||
import io.element.android.libraries.matrix.api.core.UserId
|
||||
import io.element.android.libraries.matrix.api.room.location.AssetType
|
||||
@@ -18,7 +19,6 @@ import kotlinx.collections.immutable.ImmutableList
|
||||
|
||||
data class ShowLocationState(
|
||||
val dialogState: LocationConstraintsDialogState,
|
||||
val markers: ImmutableList<LocationMarkerData>,
|
||||
val locationShares: ImmutableList<LocationShareItem>,
|
||||
val hasLocationPermission: Boolean,
|
||||
val isTrackMyLocation: Boolean,
|
||||
@@ -37,3 +37,19 @@ data class LocationShareItem(
|
||||
val isLive: Boolean,
|
||||
val assetType: AssetType?,
|
||||
)
|
||||
|
||||
fun LocationShareItem.toMarkerData(): LocationMarkerData {
|
||||
val pinVariant = if (assetType == AssetType.PIN) {
|
||||
PinVariant.PinnedLocation
|
||||
} else {
|
||||
PinVariant.UserLocation(
|
||||
avatarData = avatarData,
|
||||
isLive = isLive,
|
||||
)
|
||||
}
|
||||
return LocationMarkerData(
|
||||
id = userId.value,
|
||||
location = location,
|
||||
variant = pinVariant,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -11,16 +11,12 @@ package io.element.android.features.location.impl.show
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
import io.element.android.features.location.api.Location
|
||||
import io.element.android.features.location.impl.common.ui.LocationConstraintsDialogState
|
||||
import io.element.android.features.location.impl.common.ui.LocationMarkerData
|
||||
import io.element.android.libraries.designsystem.components.PinVariant
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
|
||||
import io.element.android.libraries.matrix.api.core.UserId
|
||||
import io.element.android.libraries.matrix.api.room.location.AssetType
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
private const val APP_NAME = "ApplicationName"
|
||||
|
||||
class ShowLocationStateProvider : PreviewParameterProvider<ShowLocationState> {
|
||||
override val values: Sequence<ShowLocationState>
|
||||
get() = sequenceOf(
|
||||
@@ -45,13 +41,10 @@ class ShowLocationStateProvider : PreviewParameterProvider<ShowLocationState> {
|
||||
)
|
||||
}
|
||||
|
||||
private val defaultLocation = Location(1.23, 2.34, 4f)
|
||||
private val defaultSenderId = UserId("@alice:matrix.org")
|
||||
private const val defaultSenderName = "Alice"
|
||||
private const val APP_NAME = "ApplicationName"
|
||||
|
||||
fun aShowLocationState(
|
||||
constraintsDialogState: LocationConstraintsDialogState = LocationConstraintsDialogState.None,
|
||||
markers: List<LocationMarkerData> = listOf(aLocationMarkerData()),
|
||||
locationShares: List<LocationShareItem> = listOf(aLocationShareItem()),
|
||||
hasLocationPermission: Boolean = false,
|
||||
isTrackMyLocation: Boolean = false,
|
||||
@@ -60,7 +53,6 @@ fun aShowLocationState(
|
||||
): ShowLocationState {
|
||||
return ShowLocationState(
|
||||
dialogState = constraintsDialogState,
|
||||
markers = markers.toImmutableList(),
|
||||
locationShares = locationShares.toImmutableList(),
|
||||
hasLocationPermission = hasLocationPermission,
|
||||
isTrackMyLocation = isTrackMyLocation,
|
||||
@@ -69,35 +61,17 @@ fun aShowLocationState(
|
||||
)
|
||||
}
|
||||
|
||||
fun aLocationMarkerData(
|
||||
id: String = defaultSenderId.value,
|
||||
location: Location = defaultLocation,
|
||||
variant: PinVariant = PinVariant.UserLocation(
|
||||
avatarData = AvatarData(
|
||||
id = defaultSenderId.value,
|
||||
name = defaultSenderName,
|
||||
url = null,
|
||||
size = AvatarSize.LocationPin,
|
||||
),
|
||||
isLive = false,
|
||||
),
|
||||
) = LocationMarkerData(
|
||||
id = id,
|
||||
location = location,
|
||||
variant = variant,
|
||||
)
|
||||
|
||||
fun aLocationShareItem(
|
||||
userId: UserId = defaultSenderId,
|
||||
displayName: String = defaultSenderName,
|
||||
userId: UserId = UserId("@alice:matrix.org"),
|
||||
displayName: String = "Alice",
|
||||
avatarData: AvatarData = AvatarData(
|
||||
id = defaultSenderId.value,
|
||||
name = defaultSenderName,
|
||||
id = userId.value,
|
||||
name = displayName,
|
||||
url = null,
|
||||
size = AvatarSize.UserListItem,
|
||||
),
|
||||
formattedTimestamp: String = "Shared 1 min ago",
|
||||
location: Location = defaultLocation,
|
||||
location: Location = Location(1.23, 2.34, 4f),
|
||||
isLive: Boolean = false,
|
||||
assetType: AssetType? = null,
|
||||
) = LocationShareItem(
|
||||
|
||||
@@ -66,10 +66,10 @@ fun ShowLocationView(
|
||||
)
|
||||
|
||||
val initialPosition = remember {
|
||||
if (state.markers.isEmpty()) {
|
||||
if (state.locationShares.isEmpty()) {
|
||||
MapDefaults.defaultCameraPosition
|
||||
} else {
|
||||
val firstLocation = state.markers.first().location
|
||||
val firstLocation = state.locationShares.first().location
|
||||
CameraPosition(
|
||||
target = Position(latitude = firstLocation.lat, longitude = firstLocation.lon),
|
||||
zoom = MapDefaults.DEFAULT_ZOOM
|
||||
@@ -147,7 +147,10 @@ fun ShowLocationView(
|
||||
locationState = userLocationState,
|
||||
trackUserLocation = state.isTrackMyLocation
|
||||
)
|
||||
LocationPinMarkers(state.markers)
|
||||
val markers = remember(state.locationShares) {
|
||||
state.locationShares.map { it.toMarkerData() }
|
||||
}
|
||||
LocationPinMarkers(markers)
|
||||
},
|
||||
overlayContent = {
|
||||
LocationFloatingActionButton(
|
||||
|
||||
Reference in New Issue
Block a user