Skip to content

Commit

Permalink
Switch to server-generated icons
Browse files Browse the repository at this point in the history
  • Loading branch information
bubelov committed Nov 1, 2022
1 parent 28cedbc commit e446af1
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 497 deletions.
2 changes: 1 addition & 1 deletion app/src/main/kotlin/area/AreaFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class AreaFragment : Fragment() {

AreaAdapter.Item.Element(
id = it.id,
iconId = it.icon_id,
iconId = it.icon_id ?: "question_mark",
name = tags["name"]?.jsonPrimitive?.content
?: getString(R.string.unnamed_place),
status = status,
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/kotlin/db/Db.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fun database(context: Context): Database {
val driver = AndroidSqliteDriver(
schema = Database.Schema,
context = context,
name = "btcmap-v24.db",
name = "btcmap-v25.db",
factory = RequerySQLiteOpenHelperFactory(),
)

Expand Down Expand Up @@ -48,6 +48,12 @@ private fun elementAdapter(): Element.Adapter {

override fun encode(value: JsonObject) = value.toString()
},
tagsAdapter = object : ColumnAdapter<JsonObject, String> {
override fun decode(databaseValue: String): JsonObject =
Json.decodeFromString(databaseValue)

override fun encode(value: JsonObject) = value.toString()
},
)
}

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/kotlin/element/ElementFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ class ElementFragment : Fragment() {
val markersRepo = MapMarkersRepo(requireContext(), confRepo)
val marker = Marker(binding.map)
marker.position = GeoPoint(element.lat, element.lon)
marker.icon = markersRepo.getMarker(element.icon_id)
marker.icon = markersRepo.getMarker(
element.tags["icon:android"]?.jsonPrimitive?.content ?: "question_mark"
)
binding.map.overlays.add(marker)
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/kotlin/elements/ElementsRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Context
import app.cash.sqldelight.coroutines.*
import db.*
import http.await
import icons.iconId
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.first
Expand Down Expand Up @@ -190,8 +189,8 @@ class ElementsRepo(
id = it.id,
lat = latLon.first,
lon = latLon.second,
icon_id = it.osm_json["tags"]?.jsonObject?.iconId() ?: "",
osm_json = it.osm_json,
tags = it.tags,
created_at = it.created_at,
updated_at = it.updated_at,
deleted_at = it.deleted_at,
Expand Down Expand Up @@ -242,8 +241,8 @@ class ElementsRepo(
id = it.id,
lat = latLon.first,
lon = latLon.second,
icon_id = it.osm_json["tags"]?.jsonObject?.iconId() ?: "",
osm_json = it.osm_json,
tags = it.tags,
created_at = it.created_at,
updated_at = it.updated_at,
deleted_at = it.deleted_at,
Expand Down Expand Up @@ -286,6 +285,7 @@ class ElementsRepo(
private data class ElementJson(
val id: String,
val osm_json: JsonObject,
val tags: JsonObject,
val created_at: String,
val updated_at: String,
val deleted_at: String,
Expand Down
Loading

0 comments on commit e446af1

Please sign in to comment.