diff --git a/app/src/main/graphql/MapLocations.graphql b/app/src/main/graphql/MapLocations.graphql new file mode 100644 index 0000000..58d51da --- /dev/null +++ b/app/src/main/graphql/MapLocations.graphql @@ -0,0 +1,10 @@ +query MapLocations { + locations { + _id + name + city + latitude + longitude + isOnline + } +} diff --git a/app/src/main/graphql/schema.graphqls b/app/src/main/graphql/schema.graphqls new file mode 100644 index 0000000..a7ac540 --- /dev/null +++ b/app/src/main/graphql/schema.graphqls @@ -0,0 +1,709 @@ +""" +A custom scalar that returns date and time as JavaScript Date object +""" +scalar Date + +""" +A custom scalar that returns data as a generic JavaScript Object. Data will be returned +as a String, when data is published as a simple string. +""" +scalar Object + +enum Role { + visitor + + apiUser + + admin +} + +""" +Location +""" +type Location { + """ + Location ID + """ + _id: String! + + """ + City name in English + """ + city: String + + """ + Location name + """ + name: String! + + """ + Location online state + """ + isOnline: Boolean + + """ + Location latitude + """ + latitude: Float! + + """ + Location longitude + """ + longitude: Float! + + """ + Location telemetry info + """ + status: Status + + """ + Location metric list + """ + metricList: [String]! + + """ + Last sensor value set + """ + currentValue(filter: TimeSpan): SensorData + + """ + Sensor values for certain time span + """ + timeSeries(filter: TimeSpan): [SensorData] + + """ + Sensor values to export for certain time span + """ + timeSeries_export(filter: TimeSpan): [SensorData] +} + +""" +The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text. +""" +scalar String + +""" +The `Boolean` scalar type represents `true` or `false`. +""" +scalar Boolean + +""" +The `Float` scalar type represents signed double-precision fractional values as specified by [IEEE 754](https://en.wikipedia.org/wiki/IEEE_floating_point). +""" +scalar Float + +type Status { + _id: String! + + RSSI: Int + + channel: Int + + build: String + + created: String + + ext_ip: String + + local_ip: String + + isOnline: Boolean + + start: String + + uptime: Int +} + +""" +The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1. +""" +scalar Int + +""" + Sensor values +""" +type SensorData { + """ + Time in ISO 8601 format, UTC time + """ + time: DateTime! + + """ + Primary temperature, °C + """ + Temp: Float + + """ + Secondary temperature, °C + """ + Temp1: Float + + """ + Water temperature, °C + """ + wTemp: Float + + """ + Relative humidity, % + """ + Hum: Float + + """ + Air pressure, Pa + """ + Press: Float + + """ + PM1 particulate matter, μg/m³ + """ + PMS1: Float + + """ + PM2.5 particulate matter, μg/m³ + """ + PMS25: Float + + """ + PM10 particulate matter, μg/m³ + """ + PMS10: Float + + """ + Ambient radioactivity, μSv/h + """ + Count: Float + + """ + NOx index + """ + NOx: Float + + """ + VOC index + """ + VOC: Float + + """ + AQI index + """ + AQI: Int + + """ + IKAV index + """ + IKAV: Float + + """ + Water level + """ + WaterLevel: Float + + """ + Solar irradiance + """ + SolRad: Float + + """ + Illumination level + """ + Light: Float +} + +type Telemetry { + deviceId: String + + time: String! + + IP: String + + VCC: String + + RSSI: String + + Uptime: String +} + +type AuthResponse { + token: String + + name: String + + email: String + + id: String +} + +type City { + _id: String + + countryCode: String + + cityName: CityName + + locationCount: Int + + latitude: Float + + longitude: Float +} + +type CityName { + be: String + + ru: String + + en: String + + ge: String + + pl: String +} + +type Marker { + _id: String + + name: String + + latitude: Float + + longitude: Float + + """ + status: Status + """ + text: String + + isPublic: Boolean + + owned: Boolean + + metricList: [String] + + value: Float + + values: [SensorData] +} + +input LocationFilter { + _id: String + + name: String +} + +input LocationsFilter { + _ids: [String] + + city: String + + cityName: String + + cityId: String + + isOnline: Boolean +} + +input TimeSpan { + t_from: String + + t_to: String + + interval_d: Int = 0 + + interval_h: Int = 0 + + interval_m: Int = 0 +} + +input LastFilter { + city: String + + interval_d: Int = 0 + + interval_h: Int = 0 + + interval_m: Int = 15 +} + +input MeanFilter { + city: String + + t_from: String! + + t_to: String! + + interval_d: Int = 0 + + interval_h: Int = 0 + + interval_m: Int = 15 +} + +input AuthInput { + uid: String + + accessToken: String! +} + +input LocInput { + _id: String +} + +enum Sensor { + DUST + + TEMPERATURE + + HUMIDITY + + PRESSURE + + RADIOACTIVITY + + WATERLEVEL +} + +enum TimeFilter { + HOUR + + DAY + + WEEK + + MONTH +} + +input MarkerFilter { + city: String + + isOnline: Boolean + + mapLayer: String +} + +type Query { + location(filter: LocationFilter): Location + + locations(filter: LocationsFilter): [Location] + + myLocation: Location + + myLocations: [Location] + + cityList(countryCode: String): [City] + + cityAverage(filter: LastFilter): SensorData + + cityAverages(filter: MeanFilter): [SensorData] + + getMarkers(filter: MarkerFilter): [Marker] +} + +""" +A date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the `date-time` format outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar. +""" +scalar DateTime + +""" +A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations. +""" +type __Schema { + description: String + + """ + A list of all types supported by this server. + """ + types: [__Type!]! + + """ + The type that query operations will be rooted at. + """ + queryType: __Type! + + """ + If this server supports mutation, the type that mutation operations will be rooted at. + """ + mutationType: __Type + + """ + If this server support subscription, the type that subscription operations will be rooted at. + """ + subscriptionType: __Type + + """ + A list of all directives supported by this server. + """ + directives: [__Directive!]! +} + +""" +The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the `__TypeKind` enum. + +Depending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name, description and optional `specifiedByUrl`, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types. +""" +type __Type { + kind: __TypeKind! + + name: String + + description: String + + specifiedByUrl: String + + fields(includeDeprecated: Boolean = false): [__Field!] + + interfaces: [__Type!] + + possibleTypes: [__Type!] + + enumValues(includeDeprecated: Boolean = false): [__EnumValue!] + + inputFields(includeDeprecated: Boolean = false): [__InputValue!] + + ofType: __Type +} + +""" +An enum describing what kind of type a given `__Type` is. +""" +enum __TypeKind { + """ + Indicates this type is a scalar. + """ + SCALAR + + """ + Indicates this type is an object. `fields` and `interfaces` are valid fields. + """ + OBJECT + + """ + Indicates this type is an interface. `fields`, `interfaces`, and `possibleTypes` are valid fields. + """ + INTERFACE + + """ + Indicates this type is a union. `possibleTypes` is a valid field. + """ + UNION + + """ + Indicates this type is an enum. `enumValues` is a valid field. + """ + ENUM + + """ + Indicates this type is an input object. `inputFields` is a valid field. + """ + INPUT_OBJECT + + """ + Indicates this type is a list. `ofType` is a valid field. + """ + LIST + + """ + Indicates this type is a non-null. `ofType` is a valid field. + """ + NON_NULL +} + +""" +Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type. +""" +type __Field { + name: String! + + description: String + + args(includeDeprecated: Boolean = false): [__InputValue!]! + + type: __Type! + + isDeprecated: Boolean! + + deprecationReason: String +} + +""" +Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value. +""" +type __InputValue { + name: String! + + description: String + + type: __Type! + + """ + A GraphQL-formatted string representing the default value for this input value. + """ + defaultValue: String + + isDeprecated: Boolean! + + deprecationReason: String +} + +""" +One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string. +""" +type __EnumValue { + name: String! + + description: String + + isDeprecated: Boolean! + + deprecationReason: String +} + +""" +A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document. + +In some cases, you need to provide options to alter GraphQL's execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor. +""" +type __Directive { + name: String! + + description: String + + isRepeatable: Boolean! + + locations: [__DirectiveLocation!]! + + args: [__InputValue!]! +} + +""" +A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies. +""" +enum __DirectiveLocation { + """ + Location adjacent to a query operation. + """ + QUERY + + """ + Location adjacent to a mutation operation. + """ + MUTATION + + """ + Location adjacent to a subscription operation. + """ + SUBSCRIPTION + + """ + Location adjacent to a field. + """ + FIELD + + """ + Location adjacent to a fragment definition. + """ + FRAGMENT_DEFINITION + + """ + Location adjacent to a fragment spread. + """ + FRAGMENT_SPREAD + + """ + Location adjacent to an inline fragment. + """ + INLINE_FRAGMENT + + """ + Location adjacent to a variable definition. + """ + VARIABLE_DEFINITION + + """ + Location adjacent to a schema definition. + """ + SCHEMA + + """ + Location adjacent to a scalar definition. + """ + SCALAR + + """ + Location adjacent to an object type definition. + """ + OBJECT + + """ + Location adjacent to a field definition. + """ + FIELD_DEFINITION + + """ + Location adjacent to an argument definition. + """ + ARGUMENT_DEFINITION + + """ + Location adjacent to an interface definition. + """ + INTERFACE + + """ + Location adjacent to a union definition. + """ + UNION + + """ + Location adjacent to an enum definition. + """ + ENUM + + """ + Location adjacent to an enum value definition. + """ + ENUM_VALUE + + """ + Location adjacent to an input object type definition. + """ + INPUT_OBJECT + + """ + Location adjacent to an input object field definition. + """ + INPUT_FIELD_DEFINITION +} + +directive @hasScope(scopes: [String]) on OBJECT | FIELD_DEFINITION + +directive @hasRole(roles: [Role]) on OBJECT | FIELD_DEFINITION + +directive @isAuthenticated on OBJECT | FIELD_DEFINITION + +directive @isHidden on OBJECT | FIELD_DEFINITION | ENUM + +directive @undocumented on OBJECT | FIELD_DEFINITION | ENUM + +""" +Directs the executor to include this field or fragment only when the `if` argument is true. +""" +directive @include("Included when true." if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT + +""" +Directs the executor to skip this field or fragment when the `if` argument is true. +""" +directive @skip("Skipped when true." if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT + +""" +Marks an element of a GraphQL schema as no longer supported. +""" +directive @deprecated("Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/)." reason: String = "No longer supported") on FIELD_DEFINITION | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | ENUM_VALUE + +""" +Exposes a URL that specifies the behaviour of this scalar. +""" +directive @specifiedBy("The URL that specifies the behaviour of this scalar." url: String!) on SCALAR + +schema { + query: Query +} diff --git a/app/src/main/kotlin/org/db3/airmq/features/common/AirMqButtons.kt b/app/src/main/kotlin/org/db3/airmq/features/common/AirMqButtons.kt new file mode 100644 index 0000000..04bed27 --- /dev/null +++ b/app/src/main/kotlin/org/db3/airmq/features/common/AirMqButtons.kt @@ -0,0 +1,202 @@ +package org.db3.airmq.features.common + +import androidx.compose.foundation.background +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsPressedAsState +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.BorderStroke +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.OutlinedButton +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Brush +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import org.db3.airmq.ui.theme.LegacyButtonContained +import org.db3.airmq.ui.theme.LegacyButtonGradientEnd +import org.db3.airmq.ui.theme.LegacyButtonGradientStart +import org.db3.airmq.ui.theme.LegacyButtonOnContained +import org.db3.airmq.ui.theme.LegacyButtonOnOutlined +import org.db3.airmq.ui.theme.LegacyButtonOnText +import org.db3.airmq.ui.theme.LegacyOutlineLight + +enum class AirMqButtonStyle { + Contained, + Outlined, + Text, + Gradient +} + +private val LegacyButtonShape = RoundedCornerShape(18.dp) +private val LegacyButtonHeight = 36.dp +private val LegacyDisabledContainer = Color(0xFFE0E0E0) +private val LegacyDisabledContent = Color(0x61000000) + +@Composable +fun AirMqButton( + text: String, + onClick: () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + style: AirMqButtonStyle = AirMqButtonStyle.Contained +) { + when (style) { + AirMqButtonStyle.Contained -> AirMqContainedButton( + text = text, + onClick = onClick, + modifier = modifier, + enabled = enabled + ) + AirMqButtonStyle.Outlined -> AirMqOutlinedButton( + text = text, + onClick = onClick, + modifier = modifier, + enabled = enabled + ) + AirMqButtonStyle.Text -> AirMqTextButton( + text = text, + onClick = onClick, + modifier = modifier, + enabled = enabled + ) + AirMqButtonStyle.Gradient -> AirMqGradientButton( + text = text, + onClick = onClick, + modifier = modifier, + enabled = enabled + ) + } +} + +@Composable +fun AirMqContainedButton( + text: String, + onClick: () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true +) { + Button( + onClick = onClick, + enabled = enabled, + shape = LegacyButtonShape, + modifier = modifier.heightIn(min = LegacyButtonHeight), + colors = ButtonDefaults.buttonColors( + containerColor = LegacyButtonContained, + contentColor = LegacyButtonOnContained, + disabledContainerColor = LegacyDisabledContainer, + disabledContentColor = LegacyDisabledContent + ) + ) { + Text(text = text, fontWeight = FontWeight.Medium) + } +} + +@Composable +fun AirMqOutlinedButton( + text: String, + onClick: () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true +) { + OutlinedButton( + onClick = onClick, + enabled = enabled, + shape = LegacyButtonShape, + border = BorderStroke( + width = 1.dp, + color = if (enabled) LegacyOutlineLight else LegacyDisabledContent + ), + modifier = modifier.heightIn(min = LegacyButtonHeight), + colors = ButtonDefaults.outlinedButtonColors( + contentColor = LegacyButtonOnOutlined, + disabledContentColor = LegacyDisabledContent + ) + ) { + Text(text = text, fontWeight = FontWeight.Medium) + } +} + +@Composable +fun AirMqTextButton( + text: String, + onClick: () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true +) { + TextButton( + onClick = onClick, + enabled = enabled, + shape = LegacyButtonShape, + modifier = modifier.heightIn(min = LegacyButtonHeight), + colors = ButtonDefaults.textButtonColors( + contentColor = LegacyButtonOnText, + disabledContentColor = LegacyDisabledContent + ) + ) { + Text(text = text, fontWeight = FontWeight.Medium) + } +} + +@Composable +fun AirMqGradientButton( + text: String, + onClick: () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true +) { + val interactionSource = remember { MutableInteractionSource() } + val isPressed by interactionSource.collectIsPressedAsState() + val overlay = when { + !enabled -> Color.Black.copy(alpha = 0.12f) + isPressed -> Color.Black.copy(alpha = 0.2f) + else -> Color.Transparent + } + + Button( + onClick = onClick, + enabled = enabled, + shape = LegacyButtonShape, + interactionSource = interactionSource, + modifier = modifier + .heightIn(min = LegacyButtonHeight) + .clip(LegacyButtonShape), + contentPadding = PaddingValues(0.dp), + colors = ButtonDefaults.buttonColors( + containerColor = Color.Transparent, + contentColor = LegacyButtonOnContained, + disabledContainerColor = Color.Transparent, + disabledContentColor = LegacyDisabledContent + ) + ) { + Box( + modifier = Modifier + .fillMaxWidth() + .clip(LegacyButtonShape) + .background( + brush = Brush.horizontalGradient( + colors = listOf(LegacyButtonGradientStart, LegacyButtonGradientEnd) + ) + ) + .background(overlay), + contentAlignment = Alignment.Center + ) { + Text( + text = text, + fontWeight = FontWeight.Medium, + color = if (enabled) LegacyButtonOnContained else LegacyDisabledContent + ) + } + } +} diff --git a/app/src/main/kotlin/org/db3/airmq/features/common/MockScreenScaffold.kt b/app/src/main/kotlin/org/db3/airmq/features/common/MockScreenScaffold.kt index 2c356ac..7e0917e 100644 --- a/app/src/main/kotlin/org/db3/airmq/features/common/MockScreenScaffold.kt +++ b/app/src/main/kotlin/org/db3/airmq/features/common/MockScreenScaffold.kt @@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll -import androidx.compose.material3.Button import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Text @@ -18,7 +17,8 @@ import androidx.compose.ui.unit.dp data class ScreenAction( val label: String, - val onClick: () -> Unit + val onClick: () -> Unit, + val style: AirMqButtonStyle = AirMqButtonStyle.Contained ) @Composable @@ -61,9 +61,12 @@ private fun ScreenContent( } content?.invoke() actions.forEach { action -> - Button(onClick = action.onClick, modifier = Modifier.fillMaxWidth()) { - Text(text = action.label) - } + AirMqButton( + text = action.label, + onClick = action.onClick, + style = action.style, + modifier = Modifier.fillMaxWidth() + ) } } } diff --git a/app/src/main/kotlin/org/db3/airmq/features/map/AirMQMapApi.kt b/app/src/main/kotlin/org/db3/airmq/features/map/AirMQMapApi.kt new file mode 100644 index 0000000..d506f56 --- /dev/null +++ b/app/src/main/kotlin/org/db3/airmq/features/map/AirMQMapApi.kt @@ -0,0 +1,110 @@ +package org.db3.airmq.features.map + +import org.json.JSONArray +import org.json.JSONObject +import java.io.BufferedReader +import java.io.OutputStreamWriter +import java.net.HttpURLConnection +import java.net.URL + +class AirMqMapApi { + fun fetchMapItems(): List { + val payload = JSONObject() + .put("query", LOCATIONS_QUERY) + .put("variables", JSONObject()) + + val connection = (URL(API_URL).openConnection() as HttpURLConnection).apply { + requestMethod = "POST" + connectTimeout = 15_000 + readTimeout = 15_000 + setRequestProperty("Content-Type", "application/json") + doInput = true + doOutput = true + } + + return try { + OutputStreamWriter(connection.outputStream).use { writer -> + writer.write(payload.toString()) + writer.flush() + } + + val responseCode = connection.responseCode + val body = readResponseBody(connection, responseCode) + if (responseCode !in 200..299) { + throw IllegalStateException("Map API request failed: HTTP $responseCode") + } + + parseMapItems(body) + } finally { + connection.disconnect() + } + } + + private fun parseMapItems(rawJson: String): List { + val root = JSONObject(rawJson) + val errors = root.optJSONArray("errors") + if (errors != null && errors.length() > 0) { + throw IllegalStateException(firstGraphQlError(errors)) + } + + val data = root.optJSONObject("data") + ?: throw IllegalStateException("Map API response is missing data") + val locations = data.optJSONArray("locations") ?: JSONArray() + + return buildList { + for (index in 0 until locations.length()) { + val location = locations.optJSONObject(index) ?: continue + val id = location.optString("_id") + val latitude = location.optDouble("latitude", Double.NaN) + val longitude = location.optDouble("longitude", Double.NaN) + if (id.isBlank() || latitude.isNaN() || longitude.isNaN()) { + continue + } + + add( + MapItem( + id = id, + title = location.optString("name").ifBlank { id }, + city = location.optString("city").ifBlank { null }, + latitude = latitude, + longitude = longitude, + isOnline = location.optBoolean("isOnline", false) + ) + ) + } + } + } + + private fun readResponseBody(connection: HttpURLConnection, responseCode: Int): String { + val source = if (responseCode in 200..299) { + connection.inputStream + } else { + connection.errorStream ?: connection.inputStream + } + + return source.bufferedReader().use(BufferedReader::readText) + } + + private fun firstGraphQlError(errors: JSONArray): String { + val firstError = errors.optJSONObject(0) + return firstError?.optString("message").orEmpty().ifBlank { + "Map API returned an unknown GraphQL error" + } + } + + companion object { + private const val API_URL = "https://api.airmq.cc" + private const val LOCATIONS_QUERY = """ + query MapLocations { + locations { + _id + name + city + latitude + longitude + isOnline + } + } + """ + } +} diff --git a/app/src/main/kotlin/org/db3/airmq/features/map/MapItem.kt b/app/src/main/kotlin/org/db3/airmq/features/map/MapItem.kt new file mode 100644 index 0000000..5dbad6b --- /dev/null +++ b/app/src/main/kotlin/org/db3/airmq/features/map/MapItem.kt @@ -0,0 +1,10 @@ +package org.db3.airmq.features.map + +data class MapItem( + val id: String, + val title: String, + val city: String?, + val latitude: Double, + val longitude: Double, + val isOnline: Boolean +) diff --git a/app/src/main/kotlin/org/db3/airmq/features/map/MapScreen.kt b/app/src/main/kotlin/org/db3/airmq/features/map/MapScreen.kt index 0c1b037..1d431e2 100644 --- a/app/src/main/kotlin/org/db3/airmq/features/map/MapScreen.kt +++ b/app/src/main/kotlin/org/db3/airmq/features/map/MapScreen.kt @@ -1,20 +1,129 @@ package org.db3.airmq.features.map +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.material3.CircularProgressIndicator import androidx.compose.runtime.Composable -import org.db3.airmq.features.common.MockScreenScaffold -import org.db3.airmq.features.common.ScreenAction +import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.unit.dp +import androidx.compose.ui.viewinterop.AndroidView +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleEventObserver +import androidx.lifecycle.compose.LocalLifecycleOwner +import androidx.lifecycle.viewmodel.compose.viewModel +import org.db3.airmq.features.common.AirMqContainedButton +import org.osmdroid.config.Configuration +import org.osmdroid.tileprovider.tilesource.TileSourceFactory +import org.osmdroid.util.GeoPoint +import org.osmdroid.views.MapView +import org.osmdroid.views.overlay.Marker @Composable fun MapScreen( - onOpenDevice: () -> Unit, - onBackToDashboard: () -> Unit + viewModel: MapViewModel = viewModel() ) { - MockScreenScaffold( - title = "Map", - subtitle = "Bottom-tab equivalent: map", - actions = listOf( - ScreenAction("Open Device", onOpenDevice), - ScreenAction("Back to Dashboard", onBackToDashboard) + val uiState by viewModel.uiState.collectAsState() + val context = LocalContext.current + val lifecycleOwner = LocalLifecycleOwner.current + + val mapView = remember { + Configuration.getInstance().userAgentValue = context.packageName + MapView(context).apply { + setTileSource(TileSourceFactory.MAPNIK) + setMultiTouchControls(true) + controller.setZoom(7.0) + controller.setCenter(GeoPoint(53.7098, 27.9534)) + } + } + + DisposableEffect(lifecycleOwner, mapView) { + val observer = LifecycleEventObserver { _, event -> + when (event) { + Lifecycle.Event.ON_RESUME -> mapView.onResume() + Lifecycle.Event.ON_PAUSE -> mapView.onPause() + else -> Unit + } + } + lifecycleOwner.lifecycle.addObserver(observer) + onDispose { + lifecycleOwner.lifecycle.removeObserver(observer) + mapView.onDetach() + } + } + + Box(modifier = Modifier.fillMaxSize()) { + AndroidView( + modifier = Modifier.fillMaxSize(), + factory = { mapView }, + update = { map -> + map.overlays.removeAll { it is Marker } + uiState.items.forEach { item -> + val marker = Marker(map).apply { + position = GeoPoint(item.latitude, item.longitude) + title = listOfNotNull(item.title, item.city).joinToString(" - ") + subDescription = if (item.isOnline) "Online" else "Offline" + setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM) + } + map.overlays.add(marker) + } + + uiState.items.firstOrNull()?.let { first -> + map.controller.animateTo(GeoPoint(first.latitude, first.longitude)) + } + map.invalidate() + } ) - ) + + if (uiState.isLoading) { + Box( + modifier = Modifier + .fillMaxSize() + .background(Color.Black.copy(alpha = 0.2f)), + contentAlignment = Alignment.Center + ) { + CircularProgressIndicator(modifier = Modifier.size(40.dp)) + } + } + + if (uiState.errorMessage != null) { + ErrorOverlay( + message = uiState.errorMessage ?: "Unknown error", + onRetry = viewModel::refresh + ) + } + } +} + +@Composable +private fun ErrorOverlay( + message: String, + onRetry: () -> Unit +) { + Column( + modifier = Modifier + .fillMaxSize() + .padding(PaddingValues(16.dp)), + verticalArrangement = Arrangement.Bottom, + horizontalAlignment = Alignment.CenterHorizontally + ) { + AirMqContainedButton( + text = "Retry: $message", + onClick = onRetry, + modifier = Modifier.fillMaxWidth() + ) + } } diff --git a/app/src/main/kotlin/org/db3/airmq/features/map/MapUiState.kt b/app/src/main/kotlin/org/db3/airmq/features/map/MapUiState.kt new file mode 100644 index 0000000..6550b8f --- /dev/null +++ b/app/src/main/kotlin/org/db3/airmq/features/map/MapUiState.kt @@ -0,0 +1,7 @@ +package org.db3.airmq.features.map + +data class MapUiState( + val isLoading: Boolean = false, + val items: List = emptyList(), + val errorMessage: String? = null +) diff --git a/app/src/main/kotlin/org/db3/airmq/features/map/MapViewModel.kt b/app/src/main/kotlin/org/db3/airmq/features/map/MapViewModel.kt new file mode 100644 index 0000000..74475e8 --- /dev/null +++ b/app/src/main/kotlin/org/db3/airmq/features/map/MapViewModel.kt @@ -0,0 +1,44 @@ +package org.db3.airmq.features.map + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.launch + +class MapViewModel( + private val mapApi: AirMqMapApi = AirMqMapApi() +) : ViewModel() { + + private val _uiState = MutableStateFlow(MapUiState(isLoading = true)) + val uiState: StateFlow = _uiState.asStateFlow() + + init { + refresh() + } + + fun refresh() { + _uiState.value = _uiState.value.copy(isLoading = true, errorMessage = null) + viewModelScope.launch(Dispatchers.IO) { + val result = runCatching { mapApi.fetchMapItems() } + _uiState.value = result.fold( + onSuccess = { items -> + MapUiState( + isLoading = false, + items = items, + errorMessage = null + ) + }, + onFailure = { throwable -> + MapUiState( + isLoading = false, + items = emptyList(), + errorMessage = throwable.message ?: "Failed to load map items" + ) + } + ) + } + } +} diff --git a/app/src/main/kotlin/org/db3/airmq/features/navigation/AirMQNavGraph.kt b/app/src/main/kotlin/org/db3/airmq/features/navigation/AirMQNavGraph.kt new file mode 100644 index 0000000..76bb029 --- /dev/null +++ b/app/src/main/kotlin/org/db3/airmq/features/navigation/AirMQNavGraph.kt @@ -0,0 +1,251 @@ +package org.db3.airmq.features.navigation + +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Icon +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.material3.NavigationBar +import androidx.compose.material3.NavigationBarItem +import androidx.compose.material3.NavigationBarItemDefaults +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.navigation.NavType +import androidx.navigation.NavGraph.Companion.findStartDestination +import androidx.navigation.compose.NavHost +import androidx.navigation.compose.composable +import androidx.navigation.compose.currentBackStackEntryAsState +import androidx.navigation.compose.rememberNavController +import androidx.navigation.navArgument +import org.db3.airmq.R +import org.db3.airmq.features.city.CityScreen +import org.db3.airmq.features.constructor.ChartConstructorScreen +import org.db3.airmq.features.constructor.MapConstructorScreen +import org.db3.airmq.features.constructor.NewsConstructorScreen +import org.db3.airmq.features.constructor.SelectMapWidgetLocationScreen +import org.db3.airmq.features.constructor.WidgetConstructorScreen +import org.db3.airmq.features.dashboard.DashboardScreen +import org.db3.airmq.features.debug.DebugScreen +import org.db3.airmq.features.device.DeviceScreen +import org.db3.airmq.features.entry.SplashScreen +import org.db3.airmq.features.entry.WizardScreen +import org.db3.airmq.features.location.LocationScreen +import org.db3.airmq.features.login.LoginScreen +import org.db3.airmq.features.manage.ManageScreen +import org.db3.airmq.features.map.MapScreen +import org.db3.airmq.features.news.NewsDetailScreen +import org.db3.airmq.features.news.NewsScreen +import org.db3.airmq.features.settings.SettingsScreen +import org.db3.airmq.features.setup.SetupScreen +import org.db3.airmq.ui.theme.LegacyNavContainer +import org.db3.airmq.ui.theme.LegacyNavSelected +import org.db3.airmq.ui.theme.LegacyNavUnselected + +@Composable +fun AirMQNavGraph(modifier: Modifier = Modifier) { + val navController = rememberNavController() + val tabItems = listOf( + BottomTabItem(route = AirMqRoutes.MAP, label = "Map", iconRes = R.drawable.ic_map), + BottomTabItem(route = AirMqRoutes.DASHBOARD, label = "Dashboard", iconRes = R.drawable.ic_dashboard), + BottomTabItem(route = AirMqRoutes.MANAGE, label = "Manage", iconRes = R.drawable.ic_manage_active) + ) + val tabRoutes = tabItems.map { it.route }.toSet() + val navBackStackEntry by navController.currentBackStackEntryAsState() + val currentRoute = navBackStackEntry?.destination?.route + val showBottomBar = currentRoute in tabRoutes + + Scaffold( + modifier = modifier, + bottomBar = { + if (showBottomBar) { + NavigationBar( + containerColor = LegacyNavContainer + ) { + tabItems.forEach { tabItem -> + NavigationBarItem( + selected = currentRoute == tabItem.route, + onClick = { + navController.navigate(tabItem.route) { + popUpTo(navController.graph.findStartDestination().id) { + saveState = true + } + launchSingleTop = true + restoreState = true + } + }, + colors = NavigationBarItemDefaults.colors( + selectedIconColor = LegacyNavSelected, + unselectedIconColor = LegacyNavUnselected, + selectedTextColor = LegacyNavSelected, + unselectedTextColor = LegacyNavUnselected, + indicatorColor = LegacyNavContainer + ), + icon = { + Icon( + painter = painterResource(id = tabItem.iconRes), + contentDescription = tabItem.label + ) + }, + label = { Text(tabItem.label) } + ) + } + } + } + } + ) { innerPadding -> + NavHost( + navController = navController, + startDestination = AirMqRoutes.DASHBOARD, + modifier = Modifier.padding(innerPadding) + ) { + composable(AirMqRoutes.SPLASH) { + SplashScreen( + onContinue = { navController.navigate(AirMqRoutes.WIZARD) } + ) + } + composable(AirMqRoutes.WIZARD) { + WizardScreen( + onFinish = { + navController.navigate(AirMqRoutes.DASHBOARD) { + popUpTo(AirMqRoutes.SPLASH) { inclusive = true } + } + } + ) + } + composable(AirMqRoutes.DASHBOARD) { + DashboardScreen( + onOpenMap = { navController.navigate(AirMqRoutes.MAP) }, + onOpenManage = { navController.navigate(AirMqRoutes.MANAGE) }, + onOpenCity = { navController.navigate(AirMqRoutes.CITY) }, + onOpenDevice = { navController.navigate(AirMqRoutes.device()) }, + onOpenNews = { navController.navigate(AirMqRoutes.NEWS) }, + onOpenWidgetConstructor = { navController.navigate(AirMqRoutes.WIDGET_CONSTRUCTOR) } + ) + } + composable(AirMqRoutes.MAP) { + MapScreen() + } + composable(AirMqRoutes.MANAGE) { + ManageScreen( + onOpenDevice = { navController.navigate(AirMqRoutes.device()) }, + onOpenSetup = { navController.navigate(AirMqRoutes.SETUP) }, + onOpenSettings = { navController.navigate(AirMqRoutes.SETTINGS) }, + onOpenLogin = { navController.navigate(AirMqRoutes.LOGIN) }, + onOpenLocation = { navController.navigate(AirMqRoutes.LOCATION) }, + onOpenWidgetConstructor = { navController.navigate(AirMqRoutes.WIDGET_CONSTRUCTOR) }, + onBackToDashboard = { navController.navigate(AirMqRoutes.DASHBOARD) } + ) + } + composable( + route = AirMqRoutes.DEVICE, + arguments = listOf( + navArgument("deviceId") { + type = NavType.StringType + defaultValue = "mock-device-id" + } + ) + ) { backStackEntry -> + DeviceScreen( + deviceId = backStackEntry.arguments?.getString("deviceId") ?: "mock-device-id", + onOpenLocation = { navController.navigate(AirMqRoutes.LOCATION) }, + onShowOnMap = { navController.navigate(AirMqRoutes.MAP) } + ) + } + composable(AirMqRoutes.CITY) { + CityScreen( + onBackToDashboard = { navController.navigate(AirMqRoutes.DASHBOARD) } + ) + } + composable(AirMqRoutes.SETTINGS) { + SettingsScreen( + onOpenDebug = { navController.navigate(AirMqRoutes.DEBUG) }, + onOpenCity = { navController.navigate(AirMqRoutes.CITY) }, + onLogOutToManage = { + navController.navigate(AirMqRoutes.MANAGE) { + popUpTo(AirMqRoutes.MANAGE) { inclusive = true } + } + } + ) + } + composable(AirMqRoutes.DEBUG) { + DebugScreen( + onBackToSettings = { navController.popBackStack() } + ) + } + composable(AirMqRoutes.LOCATION) { + LocationScreen( + onBackToManage = { navController.navigate(AirMqRoutes.MANAGE) } + ) + } + composable(AirMqRoutes.SETUP) { + SetupScreen( + onFinishSetup = { navController.navigate(AirMqRoutes.MANAGE) }, + onCancelSetup = { navController.navigate(AirMqRoutes.MANAGE) } + ) + } + composable(AirMqRoutes.LOGIN) { + LoginScreen( + onLogInToManage = { navController.navigate(AirMqRoutes.MANAGE) } + ) + } + composable(AirMqRoutes.NEWS) { + NewsScreen( + onOpenNewsDetail = { navController.navigate(AirMqRoutes.newsDetail()) }, + onBackToDashboard = { navController.navigate(AirMqRoutes.DASHBOARD) } + ) + } + composable( + route = AirMqRoutes.NEWS_DETAIL, + arguments = listOf( + navArgument("newsId") { + type = NavType.StringType + defaultValue = "mock-news-id" + } + ) + ) { backStackEntry -> + NewsDetailScreen( + newsId = backStackEntry.arguments?.getString("newsId") ?: "mock-news-id", + onBackToNews = { navController.popBackStack() } + ) + } + composable(AirMqRoutes.WIDGET_CONSTRUCTOR) { + WidgetConstructorScreen( + onOpenSelectMapWidgetLocation = { + navController.navigate(AirMqRoutes.SELECT_MAP_WIDGET_LOCATION) + }, + onOpenMapConstructor = { navController.navigate(AirMqRoutes.MAP_CONSTRUCTOR) }, + onOpenChartConstructor = { navController.navigate(AirMqRoutes.CHART_CONSTRUCTOR) }, + onOpenNewsConstructor = { navController.navigate(AirMqRoutes.NEWS_CONSTRUCTOR) }, + onBackToManage = { navController.navigate(AirMqRoutes.MANAGE) } + ) + } + composable(AirMqRoutes.SELECT_MAP_WIDGET_LOCATION) { + SelectMapWidgetLocationScreen( + onDone = { navController.popBackStack() } + ) + } + composable(AirMqRoutes.MAP_CONSTRUCTOR) { + MapConstructorScreen( + onBackToWidgetConstructor = { navController.popBackStack() } + ) + } + composable(AirMqRoutes.CHART_CONSTRUCTOR) { + ChartConstructorScreen( + onBackToWidgetConstructor = { navController.popBackStack() } + ) + } + composable(AirMqRoutes.NEWS_CONSTRUCTOR) { + NewsConstructorScreen( + onBackToWidgetConstructor = { navController.popBackStack() } + ) + } + } + } +} + +private data class BottomTabItem( + val route: String, + val label: String, + val iconRes: Int +) diff --git a/app/src/main/kotlin/org/db3/airmq/features/navigation/AirMqNavGraph.kt b/app/src/main/kotlin/org/db3/airmq/features/navigation/AirMqNavGraph.kt deleted file mode 100644 index 80e9d1b..0000000 --- a/app/src/main/kotlin/org/db3/airmq/features/navigation/AirMqNavGraph.kt +++ /dev/null @@ -1,184 +0,0 @@ -package org.db3.airmq.features.navigation - -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.navigation.NavType -import androidx.navigation.compose.NavHost -import androidx.navigation.compose.composable -import androidx.navigation.compose.rememberNavController -import androidx.navigation.navArgument -import org.db3.airmq.features.city.CityScreen -import org.db3.airmq.features.constructor.ChartConstructorScreen -import org.db3.airmq.features.constructor.MapConstructorScreen -import org.db3.airmq.features.constructor.NewsConstructorScreen -import org.db3.airmq.features.constructor.SelectMapWidgetLocationScreen -import org.db3.airmq.features.constructor.WidgetConstructorScreen -import org.db3.airmq.features.dashboard.DashboardScreen -import org.db3.airmq.features.debug.DebugScreen -import org.db3.airmq.features.device.DeviceScreen -import org.db3.airmq.features.entry.SplashScreen -import org.db3.airmq.features.entry.WizardScreen -import org.db3.airmq.features.location.LocationScreen -import org.db3.airmq.features.login.LoginScreen -import org.db3.airmq.features.manage.ManageScreen -import org.db3.airmq.features.map.MapScreen -import org.db3.airmq.features.news.NewsDetailScreen -import org.db3.airmq.features.news.NewsScreen -import org.db3.airmq.features.settings.SettingsScreen -import org.db3.airmq.features.setup.SetupScreen - -@Composable -fun AirMqNavGraph(modifier: Modifier = Modifier) { - val navController = rememberNavController() - - NavHost( - navController = navController, - startDestination = AirMqRoutes.SPLASH, - modifier = modifier - ) { - composable(AirMqRoutes.SPLASH) { - SplashScreen( - onContinue = { navController.navigate(AirMqRoutes.WIZARD) } - ) - } - composable(AirMqRoutes.WIZARD) { - WizardScreen( - onFinish = { - navController.navigate(AirMqRoutes.DASHBOARD) { - popUpTo(AirMqRoutes.SPLASH) { inclusive = true } - } - } - ) - } - composable(AirMqRoutes.DASHBOARD) { - DashboardScreen( - onOpenMap = { navController.navigate(AirMqRoutes.MAP) }, - onOpenManage = { navController.navigate(AirMqRoutes.MANAGE) }, - onOpenCity = { navController.navigate(AirMqRoutes.CITY) }, - onOpenDevice = { navController.navigate(AirMqRoutes.device()) }, - onOpenNews = { navController.navigate(AirMqRoutes.NEWS) }, - onOpenWidgetConstructor = { navController.navigate(AirMqRoutes.WIDGET_CONSTRUCTOR) } - ) - } - composable(AirMqRoutes.MAP) { - MapScreen( - onOpenDevice = { navController.navigate(AirMqRoutes.device()) }, - onBackToDashboard = { navController.navigate(AirMqRoutes.DASHBOARD) } - ) - } - composable(AirMqRoutes.MANAGE) { - ManageScreen( - onOpenDevice = { navController.navigate(AirMqRoutes.device()) }, - onOpenSetup = { navController.navigate(AirMqRoutes.SETUP) }, - onOpenSettings = { navController.navigate(AirMqRoutes.SETTINGS) }, - onOpenLogin = { navController.navigate(AirMqRoutes.LOGIN) }, - onOpenLocation = { navController.navigate(AirMqRoutes.LOCATION) }, - onOpenWidgetConstructor = { navController.navigate(AirMqRoutes.WIDGET_CONSTRUCTOR) }, - onBackToDashboard = { navController.navigate(AirMqRoutes.DASHBOARD) } - ) - } - composable( - route = AirMqRoutes.DEVICE, - arguments = listOf( - navArgument("deviceId") { - type = NavType.StringType - defaultValue = "mock-device-id" - } - ) - ) { backStackEntry -> - DeviceScreen( - deviceId = backStackEntry.arguments?.getString("deviceId") ?: "mock-device-id", - onOpenLocation = { navController.navigate(AirMqRoutes.LOCATION) }, - onShowOnMap = { navController.navigate(AirMqRoutes.MAP) } - ) - } - composable(AirMqRoutes.CITY) { - CityScreen( - onBackToDashboard = { navController.navigate(AirMqRoutes.DASHBOARD) } - ) - } - composable(AirMqRoutes.SETTINGS) { - SettingsScreen( - onOpenDebug = { navController.navigate(AirMqRoutes.DEBUG) }, - onOpenCity = { navController.navigate(AirMqRoutes.CITY) }, - onLogOutToManage = { - navController.navigate(AirMqRoutes.MANAGE) { - popUpTo(AirMqRoutes.MANAGE) { inclusive = true } - } - } - ) - } - composable(AirMqRoutes.DEBUG) { - DebugScreen( - onBackToSettings = { navController.popBackStack() } - ) - } - composable(AirMqRoutes.LOCATION) { - LocationScreen( - onBackToManage = { navController.navigate(AirMqRoutes.MANAGE) } - ) - } - composable(AirMqRoutes.SETUP) { - SetupScreen( - onFinishSetup = { navController.navigate(AirMqRoutes.MANAGE) }, - onCancelSetup = { navController.navigate(AirMqRoutes.MANAGE) } - ) - } - composable(AirMqRoutes.LOGIN) { - LoginScreen( - onLogInToManage = { navController.navigate(AirMqRoutes.MANAGE) } - ) - } - composable(AirMqRoutes.NEWS) { - NewsScreen( - onOpenNewsDetail = { navController.navigate(AirMqRoutes.newsDetail()) }, - onBackToDashboard = { navController.navigate(AirMqRoutes.DASHBOARD) } - ) - } - composable( - route = AirMqRoutes.NEWS_DETAIL, - arguments = listOf( - navArgument("newsId") { - type = NavType.StringType - defaultValue = "mock-news-id" - } - ) - ) { backStackEntry -> - NewsDetailScreen( - newsId = backStackEntry.arguments?.getString("newsId") ?: "mock-news-id", - onBackToNews = { navController.popBackStack() } - ) - } - composable(AirMqRoutes.WIDGET_CONSTRUCTOR) { - WidgetConstructorScreen( - onOpenSelectMapWidgetLocation = { - navController.navigate(AirMqRoutes.SELECT_MAP_WIDGET_LOCATION) - }, - onOpenMapConstructor = { navController.navigate(AirMqRoutes.MAP_CONSTRUCTOR) }, - onOpenChartConstructor = { navController.navigate(AirMqRoutes.CHART_CONSTRUCTOR) }, - onOpenNewsConstructor = { navController.navigate(AirMqRoutes.NEWS_CONSTRUCTOR) }, - onBackToManage = { navController.navigate(AirMqRoutes.MANAGE) } - ) - } - composable(AirMqRoutes.SELECT_MAP_WIDGET_LOCATION) { - SelectMapWidgetLocationScreen( - onDone = { navController.popBackStack() } - ) - } - composable(AirMqRoutes.MAP_CONSTRUCTOR) { - MapConstructorScreen( - onBackToWidgetConstructor = { navController.popBackStack() } - ) - } - composable(AirMqRoutes.CHART_CONSTRUCTOR) { - ChartConstructorScreen( - onBackToWidgetConstructor = { navController.popBackStack() } - ) - } - composable(AirMqRoutes.NEWS_CONSTRUCTOR) { - NewsConstructorScreen( - onBackToWidgetConstructor = { navController.popBackStack() } - ) - } - } -} diff --git a/app/src/main/kotlin/org/db3/airmq/ui/theme/Color.kt b/app/src/main/kotlin/org/db3/airmq/ui/theme/Color.kt index 89408e0..0d7a1f5 100644 --- a/app/src/main/kotlin/org/db3/airmq/ui/theme/Color.kt +++ b/app/src/main/kotlin/org/db3/airmq/ui/theme/Color.kt @@ -2,10 +2,27 @@ package org.db3.airmq.ui.theme import androidx.compose.ui.graphics.Color -val Purple80 = Color(0xFFD0BCFF) -val PurpleGrey80 = Color(0xFFCCC2DC) -val Pink80 = Color(0xFFEFB8C8) +val LegacyPrimary = Color(0xFF295989) +val LegacyPrimaryDark = Color(0xFF0069C0) +val LegacyAccent = Color(0xFF295989) +val LegacyBackground = Color(0xFFFAFAFA) +val LegacySurface = Color(0xFFFFFFFF) +val LegacyOnPrimary = Color(0xFFFFFFFF) +val LegacyOnSecondary = Color(0xFFFFFFFF) +val LegacyOnBackground = Color(0xFF000000) +val LegacyOnSurface = Color(0xFF000000) +val LegacyOutline = Color(0x61000000) +val LegacyOutlineLight = Color(0x3B000000) +val LegacyNavSelected = Color(0xFFFFFFFF) +val LegacyNavUnselected = Color(0x8AFFFFFF) +val LegacyNavContainer = Color(0xFF295989) -val Purple40 = Color(0xFF6650a4) -val PurpleGrey40 = Color(0xFF625b71) -val Pink40 = Color(0xFF7D5260) \ No newline at end of file +val LegacyButtonContained = Color(0xFF135CA5) +val LegacyButtonContainedDisabledOverlay = Color(0x1F000000) +val LegacyButtonPressedOverlayDark = Color(0x33000000) +val LegacyButtonPressedOverlayLight = Color(0x33FFFFFF) +val LegacyButtonOnContained = Color(0xFFFFFFFF) +val LegacyButtonOnOutlined = Color(0xFF135CA5) +val LegacyButtonOnText = Color(0xFF295989) +val LegacyButtonGradientStart = Color(0xFF03B6EC) +val LegacyButtonGradientEnd = Color(0xFF01DEA7) \ No newline at end of file diff --git a/app/src/main/kotlin/org/db3/airmq/ui/theme/Theme.kt b/app/src/main/kotlin/org/db3/airmq/ui/theme/Theme.kt index eeb3969..fbc4874 100644 --- a/app/src/main/kotlin/org/db3/airmq/ui/theme/Theme.kt +++ b/app/src/main/kotlin/org/db3/airmq/ui/theme/Theme.kt @@ -1,51 +1,46 @@ package org.db3.airmq.ui.theme -import android.app.Activity -import android.os.Build -import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme -import androidx.compose.material3.dynamicDarkColorScheme -import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable -import androidx.compose.ui.platform.LocalContext private val DarkColorScheme = darkColorScheme( - primary = Purple80, - secondary = PurpleGrey80, - tertiary = Pink80 + primary = LegacyPrimary, + onPrimary = LegacyOnPrimary, + secondary = LegacyAccent, + onSecondary = LegacyOnSecondary, + tertiary = LegacyPrimaryDark, + background = LegacyBackground, + onBackground = LegacyOnBackground, + surface = LegacySurface, + onSurface = LegacyOnSurface, + outline = LegacyOutline, + onSurfaceVariant = LegacyNavUnselected ) private val LightColorScheme = lightColorScheme( - primary = Purple40, - secondary = PurpleGrey40, - tertiary = Pink40 - - /* Other default colors to override - background = Color(0xFFFFFBFE), - surface = Color(0xFFFFFBFE), - onPrimary = Color.White, - onSecondary = Color.White, - onTertiary = Color.White, - onBackground = Color(0xFF1C1B1F), - onSurface = Color(0xFF1C1B1F), - */ + primary = LegacyPrimary, + onPrimary = LegacyOnPrimary, + secondary = LegacyAccent, + onSecondary = LegacyOnSecondary, + tertiary = LegacyPrimaryDark, + background = LegacyBackground, + onBackground = LegacyOnBackground, + surface = LegacySurface, + onSurface = LegacyOnSurface, + outline = LegacyOutline, + onSurfaceVariant = LegacyNavUnselected ) @Composable fun AirMQTheme( - darkTheme: Boolean = isSystemInDarkTheme(), - // Dynamic color is available on Android 12+ - dynamicColor: Boolean = true, + darkTheme: Boolean = false, + dynamicColor: Boolean = false, content: @Composable () -> Unit ) { val colorScheme = when { - dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { - val context = LocalContext.current - if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) - } - + dynamicColor -> LightColorScheme darkTheme -> DarkColorScheme else -> LightColorScheme } diff --git a/app/src/main/res/drawable/ic_dashboard.xml b/app/src/main/res/drawable/ic_dashboard.xml new file mode 100644 index 0000000..8958b9c --- /dev/null +++ b/app/src/main/res/drawable/ic_dashboard.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_manage_active.xml b/app/src/main/res/drawable/ic_manage_active.xml new file mode 100644 index 0000000..73ae469 --- /dev/null +++ b/app/src/main/res/drawable/ic_manage_active.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_map.xml b/app/src/main/res/drawable/ic_map.xml new file mode 100644 index 0000000..30313b5 --- /dev/null +++ b/app/src/main/res/drawable/ic_map.xml @@ -0,0 +1,9 @@ + + +