Skip to content

Commit

Permalink
Add companion app warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bubelov committed May 2, 2024
1 parent 77cf3b7 commit 37bf5ec
Show file tree
Hide file tree
Showing 43 changed files with 147 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- Remove sync progress indicator from the map screen
- Add place directions
- Add share location button
- Add companion app warnings for the minority of places which require it

## [0.7.2] - 2023-04-26

Expand Down
10 changes: 9 additions & 1 deletion app/src/main/kotlin/element/Element.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@ data class Element(
)

fun Element.name(res: Resources): String {
return (osmJson.optJSONObject("tags") ?: JSONObject()).name(res)
return osmTags().name(res)
}

fun Element.osmTag(name: String): String {
return osmTags().optString(name, "")
}

fun Element.osmTags(): OsmTags {
return (osmJson.optJSONObject("tags") ?: JSONObject())
}
11 changes: 11 additions & 0 deletions app/src/main/kotlin/element/ElementFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ class ElementFragment : Fragment() {

binding.toolbar.title = tags.name(resources)

if (element.osmTag("payment:lightning:requires_companion_app") == "yes") {
binding.companionWarning.isVisible = true
binding.companionWarning.setTextColor(requireContext().getErrorColor())
val companionApp = element
.osmTag("payment:lightning:companion_app_url")
.ifBlank { getString(R.string.unknown) }
binding.companionWarning.text = getString(R.string.companion_warning, companionApp)
} else {
binding.companionWarning.isVisible = false
}

val surveyDate = tags.bitcoinSurveyDate()

val outdatedUri = "https://wiki.btcmap.org/general/outdated".toUri()
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/kotlin/element/ElementQueries.kt
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ class ElementQueries(private val db: SQLiteOpenHelper) {
lat,
lon,
json_extract(tags, '$.icon:android') AS icon_id,
json_extract(tags, '$.boost:expires') AS boost_expires
json_extract(tags, '$.boost:expires') AS boost_expires,
json_extract(osm_json, '$.tags.payment:lightning:requires_companion_app') AS requires_companion_app
FROM element
WHERE
deleted_at = '' AND json_extract(tags, '$.category') NOT IN (${
Expand Down Expand Up @@ -249,6 +250,7 @@ class ElementQueries(private val db: SQLiteOpenHelper) {
lon = cursor.getDouble(2),
iconId = cursor.getString(3),
boostExpires = cursor.getZonedDateTime(4),
requiresCompanionApp = (cursor.getStringOrNull(5) ?: "no") == "yes"
)
}
}
Expand All @@ -268,7 +270,8 @@ class ElementQueries(private val db: SQLiteOpenHelper) {
avg(e.lat) AS lat,
avg(e.lon) AS lon,
json_extract(e.tags, '$.icon:android') AS icon_id,
json_extract(e.tags, '$.boost:expires') AS boost_expires
json_extract(e.tags, '$.boost:expires') AS boost_expires,
json_extract(e.osm_json, '$.tags.payment:lightning:requires_companion_app') AS requires_companion_app
FROM element e
WHERE e.deleted_at = '' AND json_extract(e.tags, '$.category') NOT IN (${
excludedCategories.joinToString { "'$it'" }
Expand All @@ -288,6 +291,7 @@ class ElementQueries(private val db: SQLiteOpenHelper) {
lon = cursor.getDouble(3),
iconId = cursor.getString(4),
boostExpires = cursor.getZonedDateTime(5),
requiresCompanionApp = (cursor.getStringOrNull(6) ?: "no") == "yes"
)
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/kotlin/element/ElementsCluster.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ data class ElementsCluster(
val lon: Double,
val iconId: String,
val boostExpires: ZonedDateTime?,
val requiresCompanionApp: Boolean,
)
4 changes: 3 additions & 1 deletion app/src/main/kotlin/map/MapFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ class MapFragment : Fragment() {
marker.position = GeoPoint(it.cluster.lat, it.cluster.lon)

if (it.cluster.count == 1L) {
val icon = if (
val icon = if (it.cluster.requiresCompanionApp) {
markersRepo.getWarningMarker(it.cluster.iconId.ifBlank { "question_mark" })
} else if (
it.cluster.boostExpires != null
&& it.cluster.boostExpires.isAfter(ZonedDateTime.now(ZoneOffset.UTC))
) {
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/kotlin/map/MapMarkersRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class MapMarkersRepo(

private val boostedCache = mutableMapOf<String?, BitmapDrawable>()

private val warningCache = mutableMapOf<String?, BitmapDrawable>()

val meetupMarker by lazy {
createMarkerIcon("groups", BackgroundType.MEETUP).toDrawable(context.resources)
}
Expand Down Expand Up @@ -84,6 +86,18 @@ class MapMarkersRepo(
return markerDrawable
}

fun getWarningMarker(iconId: String): BitmapDrawable {
var markerDrawable = warningCache[iconId]

if (markerDrawable == null) {
markerDrawable =
createMarkerIcon(iconId, BackgroundType.WARNING).toDrawable(context.resources)
warningCache[iconId] = markerDrawable
}

return markerDrawable
}

private fun createMarkerIcon(iconId: String, backgroundType: BackgroundType): Bitmap {
val pinSizePx = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 48f, context.resources.displayMetrics
Expand All @@ -106,6 +120,11 @@ class MapMarkersRepo(
emptyPinDrawable,
Color.parseColor("#0e95af")
)

BackgroundType.WARNING -> DrawableCompat.setTint(
emptyPinDrawable,
context.getPrimaryContainerColor(),
)
}

val emptyPinBitmap = emptyPinDrawable.toBitmap(width = pinSizePx, height = pinSizePx)
Expand All @@ -125,6 +144,12 @@ class MapMarkersRepo(
// Paint()
// )

if (backgroundType == BackgroundType.WARNING) {
iconPaint.color = context.getErrorColor()
} else {
iconPaint.color = context.getOnPrimaryContainerColor()
}

drawText(
iconId,
markerIcon.width / 2f - textWidth / 2f,
Expand All @@ -144,6 +169,7 @@ class MapMarkersRepo(
enum class BackgroundType {
PRIMARY_CONTAINER,
BOOSTED,
WARNING,
MEETUP,
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/warning.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="@android:color/white"
android:pathData="M40,840L480,80L920,840L40,840ZM178,760L782,760L480,240L178,760ZM480,720Q497,720 508.5,708.5Q520,697 520,680Q520,663 508.5,651.5Q497,640 480,640Q463,640 451.5,651.5Q440,663 440,680Q440,697 451.5,708.5Q463,720 480,720ZM440,600L520,600L520,400L440,400L440,600ZM480,500L480,500L480,500L480,500Z" />
</vector>
12 changes: 12 additions & 0 deletions app/src/main/res/layout/fragment_element.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@

</LinearLayout>

<TextView
android:id="@+id/companionWarning"
style="?attr/textAppearanceSubtitle1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:drawablePadding="20dp"
android:paddingHorizontal="16dp"
android:paddingVertical="16dp"
app:drawableStartCompat="@drawable/warning"
app:drawableTint="?colorError" />

<TextView
android:id="@+id/address"
style="?attr/textAppearanceSubtitle1"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-af/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="one">%d change</item>
<item quantity="other">%d changes</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="zero">%d changes</item>
<item quantity="one">%d change</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-bg/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="one">%d промяна</item>
<item quantity="other">%d промени</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-bn/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="one">%d change</item>
<item quantity="other">%d changes</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="one">%d change</item>
<item quantity="many">%d changes</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="one">%d změn</item>
<item quantity="few">%d změn</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-da/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="one">%d change</item>
<item quantity="other">%d changes</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="one">%d Änderung</item>
<item quantity="other">%d Änderungen</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="one">%d αλλαγή</item>
<item quantity="other">%d αλλαγές</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="one">%d cambio</item>
<item quantity="many">%d cambios</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="one">%d change</item>
<item quantity="other">%d changes</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-fi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="one">%d change</item>
<item quantity="other">%d changes</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="one">%d modification</item>
<item quantity="many">%d modifications</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="one">%d change</item>
<item quantity="other">%d changes</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="one">%d change</item>
<item quantity="other">%d changes</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="one">%d change</item>
<item quantity="many">%d changes</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-iw/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="one">שינויים %d</item>
<item quantity="two">שינויים %d</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="other">%d changes</item>
</plurals>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<string name="show_all_new_elements">Show all new elements</string>
<string name="directions">Directions</string>
<string name="share">Share</string>
<string name="unknown">unknown</string>
<string name="companion_warning">You\'ll need a companion app (%1$s) in order to make a payment. This app doesn\'t require you to fill any personal data, to the best of our knowledge. Please let us know if it\'s not the case and we\'ll remove this place.</string>
<plurals name="d_changes">
<item quantity="other">%d changes</item>
</plurals>
Expand Down
Loading

0 comments on commit 37bf5ec

Please sign in to comment.