feat(map): device panel contract, view model, arrow and close icons
Made-with: Cursor
This commit is contained in:
@@ -32,7 +32,12 @@ object MapScreenContract {
|
||||
val status: String,
|
||||
val selectedRange: TimeRange = TimeRange.DAY,
|
||||
val displayedDateRange: String = "",
|
||||
val selectedSensor: DeviceSensorType = DeviceSensorType.TEMPERATURE
|
||||
val selectedSensor: DeviceSensorType = DeviceSensorType.TEMPERATURE,
|
||||
val supportedSensors: List<DeviceSensorType> = listOf(
|
||||
DeviceSensorType.TEMPERATURE,
|
||||
DeviceSensorType.DUST,
|
||||
DeviceSensorType.RADIOACTIVITY
|
||||
)
|
||||
)
|
||||
|
||||
data class SearchPanelState(
|
||||
@@ -45,7 +50,8 @@ object MapScreenContract {
|
||||
val items: List<MapMarker> = emptyList(),
|
||||
val selectedTopSensor: SensorType = SensorType.DUST,
|
||||
val searchPanelState: SearchPanelState? = null,
|
||||
val devicePanelState: DevicePanelState? = null
|
||||
val devicePanelState: DevicePanelState? = null,
|
||||
val selectedMarkerId: String? = null
|
||||
)
|
||||
|
||||
sealed interface Action {
|
||||
|
||||
@@ -82,7 +82,8 @@ class MapViewModel @Inject constructor(
|
||||
val selectedItem = _uiState.value.items.firstOrNull { it.id == event.resultId } ?: return
|
||||
_uiState.value = _uiState.value.copy(
|
||||
searchPanelState = null,
|
||||
devicePanelState = selectedItem.toDevicePanelState()
|
||||
devicePanelState = selectedItem.toDevicePanelState(),
|
||||
selectedMarkerId = event.resultId
|
||||
)
|
||||
}
|
||||
|
||||
@@ -99,13 +100,16 @@ class MapViewModel @Inject constructor(
|
||||
val selectedItem = _uiState.value.items.firstOrNull { it.id == event.itemId } ?: return
|
||||
_uiState.value = _uiState.value.copy(
|
||||
searchPanelState = null,
|
||||
devicePanelState = selectedItem.toDevicePanelState()
|
||||
devicePanelState = selectedItem.toDevicePanelState(),
|
||||
selectedMarkerId = event.itemId
|
||||
)
|
||||
}
|
||||
|
||||
is Event.DevicePanelClosed -> {
|
||||
val previousMarkerId = _uiState.value.devicePanelState?.id
|
||||
_uiState.value = _uiState.value.copy(
|
||||
devicePanelState = null
|
||||
devicePanelState = null,
|
||||
selectedMarkerId = previousMarkerId
|
||||
)
|
||||
}
|
||||
|
||||
@@ -168,7 +172,9 @@ class MapViewModel @Inject constructor(
|
||||
domainItems = items
|
||||
val searchPanelState = _uiState.value.searchPanelState
|
||||
val selectedSensorType = _uiState.value.selectedTopSensor
|
||||
val markers = items.toMarkers(selectedSensorType)
|
||||
val markers = items.toMarkers(selectedSensorType).ifEmpty {
|
||||
dummyMarkers(selectedSensorType)
|
||||
}
|
||||
_uiState.value.copy(
|
||||
isLoading = false,
|
||||
items = markers,
|
||||
@@ -185,9 +191,10 @@ class MapViewModel @Inject constructor(
|
||||
)
|
||||
)
|
||||
val searchPanelState = _uiState.value.searchPanelState
|
||||
val selectedSensorType = _uiState.value.selectedTopSensor
|
||||
_uiState.value.copy(
|
||||
isLoading = false,
|
||||
items = emptyList(),
|
||||
items = dummyMarkers(selectedSensorType),
|
||||
searchPanelState = searchPanelState?.copy(results = emptyList())
|
||||
)
|
||||
}
|
||||
@@ -220,11 +227,59 @@ class MapViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
private fun remapMarkers() {
|
||||
val markers = domainItems.toMarkers(_uiState.value.selectedTopSensor)
|
||||
_uiState.value = _uiState.value.copy(
|
||||
items = domainItems.toMarkers(_uiState.value.selectedTopSensor)
|
||||
items = markers.ifEmpty { dummyMarkers(_uiState.value.selectedTopSensor) }
|
||||
)
|
||||
}
|
||||
|
||||
private fun dummyMarkers(sensorType: SensorType): List<MapMarker> = listOf(
|
||||
MapMarker(
|
||||
id = "dummy-1",
|
||||
title = "AirMQ Demo #1",
|
||||
city = "Minsk",
|
||||
latitude = 53.9,
|
||||
longitude = 27.56,
|
||||
isOnline = true,
|
||||
sensorType = sensorType,
|
||||
value = 12.0,
|
||||
isOwned = false
|
||||
),
|
||||
MapMarker(
|
||||
id = "dummy-2",
|
||||
title = "AirMQ Demo #2",
|
||||
city = "Minsk",
|
||||
latitude = 53.85,
|
||||
longitude = 27.65,
|
||||
isOnline = true,
|
||||
sensorType = sensorType,
|
||||
value = 45.0,
|
||||
isOwned = true
|
||||
),
|
||||
MapMarker(
|
||||
id = "dummy-3",
|
||||
title = "AirMQ Demo #3",
|
||||
city = "Minsk",
|
||||
latitude = 53.75,
|
||||
longitude = 27.45,
|
||||
isOnline = false,
|
||||
sensorType = sensorType,
|
||||
value = 8.5,
|
||||
isOwned = false
|
||||
),
|
||||
MapMarker(
|
||||
id = "dummy-4",
|
||||
title = "AirMQ Demo #4",
|
||||
city = null,
|
||||
latitude = 53.82,
|
||||
longitude = 27.92,
|
||||
isOnline = true,
|
||||
sensorType = sensorType,
|
||||
value = null,
|
||||
isOwned = false
|
||||
)
|
||||
)
|
||||
|
||||
private fun List<MapItem>.toMarkers(sensorType: SensorType): List<MapMarker> {
|
||||
return mapNotNull { item ->
|
||||
val value = when (sensorType) {
|
||||
|
||||
10
app/src/main/res/drawable/ic_arrow_right_24.xml
Normal file
10
app/src/main/res/drawable/ic_arrow_right_24.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M11.71,15.29l2.59,-2.59c0.39,-0.39 0.39,-1.02 0,-1.41L11.71,8.7c-0.63,-0.62 -1.71,-0.18 -1.71,0.71v5.17c0,0.9 1.08,1.34 1.71,0.71z"/>
|
||||
</vector>
|
||||
10
app/src/main/res/drawable/ic_close_24.xml
Normal file
10
app/src/main/res/drawable/ic_close_24.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M18.3,5.71c-0.39,-0.39 -1.02,-0.39 -1.41,0L12,10.59 7.11,5.7c-0.39,-0.39 -1.02,-0.39 -1.41,0 -0.39,0.39 -0.39,1.02 0,1.41L10.59,12 5.7,16.89c-0.39,0.39 -0.39,1.02 0,1.41 0.39,0.39 1.02,0.39 1.41,0L12,13.41l4.89,4.89c0.39,0.39 1.02,0.39 1.41,0 0.39,-0.39 0.39,-1.02 0,-1.41L13.41,12l4.89,-4.89c0.38,-0.38 0.38,-1.02 0,-1.4z"/>
|
||||
</vector>
|
||||
Reference in New Issue
Block a user