Bimba.git

commit 027a562d35ed8083380a96a5501b7a08a9dd9c83

Author: Adam Evyčędo <git@apiote.xyz>

change stop icons and scale icons on map

%!v(PANIC=String method: strings: negative Repeat count)


diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/map/MapFragment.kt b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/map/MapFragment.kt
index 9220b90411416e40e7096d7000960485b19687f4..20f56bd9673a6a06a4c62de22349b81b694a365a 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/map/MapFragment.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/dashboard/ui/map/MapFragment.kt
@@ -41,6 +41,8 @@ import xyz.apiote.bimba.czwek.databinding.FragmentMapBinding
 import xyz.apiote.bimba.czwek.dpToPixelI
 import xyz.apiote.bimba.czwek.repo.ErrorLocatable
 import xyz.apiote.bimba.czwek.repo.Position
+import xyz.apiote.bimba.czwek.repo.Stop
+import xyz.apiote.bimba.czwek.repo.Vehicle
 
 class MapFragment : Fragment() {
 
@@ -146,8 +148,13 @@
 			it.forEach { locatable ->
 				val marker = Marker(binding.map)
 				marker.position = GeoPoint(locatable.location().latitude, locatable.location().longitude)
-				marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER)
-				marker.icon = context?.let { ctx -> locatable.icon(ctx, 2f) }
+				when (locatable) {
+					is Stop -> marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM)
+					is Vehicle -> marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER)
+				}
+
+				val scale = binding.map.zoomLevelDouble / -4 + 5.5
+				marker.icon = context?.let { ctx -> locatable.icon(ctx, scale.toFloat()) }
 
 				context?.let { ctx ->
 					marker.setOnMarkerClickListener { _, _ ->




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/repo/Stop.kt b/app/src/main/java/xyz/apiote/bimba/czwek/repo/Stop.kt
index 8b04a785d4d1890e3f86feb60bc3f150d163d47e..3c79dffea5278fa9f9090bd4cbd18c8f098a3a79 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/repo/Stop.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/repo/Stop.kt
@@ -5,10 +5,11 @@
 package xyz.apiote.bimba.czwek.repo
 
 import android.content.Context
+import android.content.res.Configuration
+import android.content.res.TypedArray
 import android.graphics.Bitmap
 import android.graphics.drawable.BitmapDrawable
 import android.graphics.drawable.Drawable
-import android.graphics.drawable.LayerDrawable
 import androidx.appcompat.content.res.AppCompatResources
 import androidx.core.graphics.ColorUtils
 import androidx.core.graphics.drawable.toBitmap
@@ -17,6 +18,7 @@ import xyz.apiote.bimba.czwek.api.StopV1
 import xyz.apiote.bimba.czwek.api.StopV2
 import xyz.apiote.bimba.czwek.dpToPixelI
 import java.util.zip.Adler32
+
 
 data class Stop(
 	val code: String,
@@ -29,25 +31,28 @@ 	val changeOptions: List
 ) : Queryable, Locatable {
 
 	override fun icon(context: Context, scale: Float): Drawable {
-		val saturationArray = arrayOf(0.5f, 0.65f, 0.8f)
-		val sal = saturationArray.size
-		val lightnessArray = arrayOf(.5f)
-		val lal = lightnessArray.size
 		val md = Adler32().let {
 			it.update(nodeName.toByteArray())
 			it.value
 		}
 		val h = md % 359f
-		val s = saturationArray[(md / 360 % sal).toInt()]
-		val l = lightnessArray[(md / 360 / sal % lal).toInt()]
-		val fg = AppCompatResources.getDrawable(context, R.drawable.stop)
-		val bg = AppCompatResources.getDrawable(context, R.drawable.stop_bg)!!.mutate().apply {
-			setTint(ColorUtils.HSLToColor(arrayOf(h, s, l).toFloatArray()))
+		val s = 1.0f
+		val a: TypedArray = context.theme.obtainStyledAttributes(
+			R.style.Theme_Bimba, intArrayOf(R.attr.randomColourLightness)
+		)
+		val l = a.getFloat(0, when (context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
+			Configuration.UI_MODE_NIGHT_YES -> 1f
+			Configuration.UI_MODE_NIGHT_NO -> 0f
+			Configuration.UI_MODE_NIGHT_UNDEFINED -> 0f
+			else -> 0f
+		})
+		a.recycle()
+		val bg = AppCompatResources.getDrawable(context, R.drawable.stop)!!.mutate().apply {
+			setTint(ColorUtils.HSLToColor(floatArrayOf(h, s, l)))
 		}
 		return BitmapDrawable(
 			context.resources,
-			LayerDrawable(arrayOf(bg, fg)).mutate()
-				.toBitmap(dpToPixelI(24f / scale), dpToPixelI(24f / scale), Bitmap.Config.ARGB_8888)
+			bg.toBitmap(dpToPixelI(24f / scale), dpToPixelI(24f / scale), Bitmap.Config.ARGB_8888)
 		)
 	}
 




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/repo/StopStub.kt b/app/src/main/java/xyz/apiote/bimba/czwek/repo/StopStub.kt
index e6d65fdd033d94cfe647831aecf9c8f45b427199..b3536dc60d5d3c69af3f9dab98b919110aa0856e 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/repo/StopStub.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/repo/StopStub.kt
@@ -5,10 +5,11 @@
 package xyz.apiote.bimba.czwek.repo
 
 import android.content.Context
+import android.content.res.Configuration
+import android.content.res.TypedArray
 import android.graphics.Bitmap
 import android.graphics.drawable.BitmapDrawable
 import android.graphics.drawable.Drawable
-import android.graphics.drawable.LayerDrawable
 import android.os.Parcelable
 import androidx.appcompat.content.res.AppCompatResources
 import androidx.core.graphics.ColorUtils
@@ -30,25 +31,29 @@ 		stopStub.zone,
 		stopStub.onDemand
 	)
 	fun icon(context: Context, scale: Float = 1f): Drawable {
-		val saturationArray = arrayOf(0.5f, 0.65f, 0.8f)
-		val sal = saturationArray.size
-		val lightnessArray = arrayOf(.5f)
-		val lal = lightnessArray.size
+		// TODO same is in Stop
 		val md = Adler32().let {
 			it.update(nodeName.toByteArray())
 			it.value
 		}
 		val h = md % 359f
-		val s = saturationArray[(md / 360 % sal).toInt()]
-		val l = lightnessArray[(md / 360 / sal % lal).toInt()]
-		val fg = AppCompatResources.getDrawable(context, R.drawable.stop)
-		val bg = AppCompatResources.getDrawable(context, R.drawable.stop_bg)!!.mutate().apply {
-			setTint(ColorUtils.HSLToColor(arrayOf(h, s, l).toFloatArray()))
+		val s = 1.0f
+		val a: TypedArray = context.theme.obtainStyledAttributes(
+			R.style.Theme_Bimba, intArrayOf(R.attr.randomColourLightness)
+		)
+		val l = a.getFloat(0, when (context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
+			Configuration.UI_MODE_NIGHT_YES -> 1f
+			Configuration.UI_MODE_NIGHT_NO -> 0f
+			Configuration.UI_MODE_NIGHT_UNDEFINED -> 0f
+			else -> 0f
+		})
+		a.recycle()
+		val bg = AppCompatResources.getDrawable(context, R.drawable.stop)!!.mutate().apply {
+			setTint(ColorUtils.HSLToColor(floatArrayOf(h, s, l)))
 		}
 		return BitmapDrawable(
 			context.resources,
-			LayerDrawable(arrayOf(bg, fg)).mutate()
-				.toBitmap(dpToPixelI(24f / scale), dpToPixelI(24f / scale), Bitmap.Config.ARGB_8888)
+			bg.toBitmap(dpToPixelI(24f / scale), dpToPixelI(24f / scale), Bitmap.Config.ARGB_8888)
 		)
 	}
 }
\ No newline at end of file




diff --git a/app/src/main/res/drawable/stop.xml b/app/src/main/res/drawable/stop.xml
index b3c29073c2ff638e0738fd96e22660036a3ad9c5..493cef04b4310be6238f14aab53810ebb50acca5 100644
--- a/app/src/main/res/drawable/stop.xml
+++ b/app/src/main/res/drawable/stop.xml
@@ -4,8 +4,13 @@
 SPDX-License-Identifier: Apache-2.0
 -->
 
-<vector android:height="24dp" android:tint="?attr/colorOnSurface"
-    android:viewportHeight="24" android:viewportWidth="24"
-    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
-    <path android:fillColor="@android:color/white" android:pathData="M2,12C2,6.48 6.48,2 12,2s10,4.48 10,10 -4.48,10 -10,10S2,17.52 2,12zM12,18c3.31,0 6,-2.69 6,-6s-2.69,-6 -6,-6 -6,2.69 -6,6 2.69,6 6,6z"/>
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+	android:width="24dp"
+	android:height="24dp"
+	android:tint="#000000"
+	android:viewportWidth="24"
+	android:viewportHeight="24">
+	<path
+		android:fillColor="@android:color/white"
+		android:pathData="M12,2C8.13,2 5,5.13 5,9C5,14.25 12,22 12,22C12,22 19,14.25 19,9C19,5.13 15.87,2 12,2zM9.666,6.334L12,6.334C12.553,6.334 13,6.781 13,7.334L13,7.666L12.334,7.666L12.334,7L9.334,6.994L9.334,9.334L11,9.334L11,11L10.334,10.99L9.666,11.666L9.334,11.666L9.334,11.334L9.666,11C9.113,11 8.666,10.553 8.666,10L8.666,7.334C8.666,6.781 9.113,6.334 9.666,6.334zM12.137,8L14.533,8C14.683,8 14.811,8.087 14.857,8.221L15.334,9.59L15.334,10.971L15.33,11.426C15.33,11.552 15.226,11.666 15.1,11.666L14.896,11.666C14.77,11.666 14.666,11.541 14.666,11.414L14.666,11L12,11L12,11.414C12,11.541 11.9,11.666 11.773,11.666L11.566,11.666C11.44,11.666 11.336,11.552 11.336,11.426L11.334,9.59L11.811,8.221C11.861,8.087 11.983,8 12.137,8zM12.137,8.334L11.793,9.334L14.877,9.334L14.533,8.334L12.137,8.334zM9.666,9.666C9.483,9.666 9.334,9.817 9.334,10C9.334,10.183 9.483,10.334 9.666,10.334C9.849,10.334 10,10.183 10,10C10,9.817 9.849,9.666 9.666,9.666zM12,9.666C11.817,9.666 11.666,9.817 11.666,10C11.666,10.183 11.817,10.334 12,10.334C12.183,10.334 12.334,10.183 12.334,10C12.334,9.817 12.183,9.666 12,9.666zM14.666,9.666C14.483,9.666 14.334,9.817 14.334,10C14.334,10.183 14.483,10.334 14.666,10.334C14.849,10.334 15,10.183 15,10C15,9.817 14.849,9.666 14.666,9.666z" />
 </vector>




diff --git a/app/src/main/res/drawable/stop_bg.xml b/app/src/main/res/drawable/stop_bg.xml
deleted file mode 100644
index a80209bc336341e345e8f8dc79bf12034456bb7e..0000000000000000000000000000000000000000
--- a/app/src/main/res/drawable/stop_bg.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-<!--
-SPDX-FileCopyrightText: Adam Evyčędo
-
-SPDX-License-Identifier: GPL-3.0-or-later
--->
-
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
-    android:width="24dp"
-    android:height="24dp"
-    android:viewportWidth="24"
-    android:viewportHeight="24">
-  <path
-      android:pathData="M2.807,12a9.193,9.193 0,1 0,18.386 0a9.193,9.193 0,1 0,-18.386 0z"
-      android:fillColor="@android:color/black"/>
-</vector>




diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index d2d028dc2a2b307a95da612b39c9f73808299b92..2ed4f97f64d1cafcc78e7558ca4486830dc8c3ea 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -39,9 +39,11 @@ 		@android:color/transparent
 		<item name="android:statusBarColor">@android:color/transparent</item>
 		<item name="android:enforceStatusBarContrast" tool:targetApi="q">false</item>
 		<item name="lightStatusBar">true</item>
+		<item name="randomColourLightness">.2</item>
 	</style>
 
 	<declare-styleable name="Theme.Bimba">
+		<attr name="randomColourLightness" format="float"/>
 		<attr name="lightStatusBar" format="boolean" />
 	</declare-styleable>
 




diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml
index 54aa31eafebed406ab21f7cf3459b2b212ab6244..e97857fb100d4f924cc140f36f4fb2c5e36955e1 100644
--- a/app/src/main/res/values-night/themes.xml
+++ b/app/src/main/res/values-night/themes.xml
@@ -39,11 +39,8 @@ 		@android:color/transparent
 		<item name="android:statusBarColor">@android:color/transparent</item>
 		<item name="android:enforceStatusBarContrast" tool:targetApi="q">false</item>
 		<item name="lightStatusBar">false</item>
+		<item name="randomColourLightness">.75</item>
 	</style>
-
-	<declare-styleable name="Theme.Bimba">
-		<attr name="lightStatusBar" format="boolean" />
-	</declare-styleable>
 
 	<style name="Theme.Bimba.SearchResult.Title" parent="Theme.Bimba">
 		<item name="android:textColor">@color/md_theme_dark_onSurfaceVariant</item>




diff --git a/app/src/main/res/values-night-v31/themes.xml b/app/src/main/res/values-night-v31/themes.xml
index 385d76110e175b88ebef16401247501cf5bed32e..46bfea2a804f1f31a66f557a49524933c3883bcc 100644
--- a/app/src/main/res/values-night-v31/themes.xml
+++ b/app/src/main/res/values-night-v31/themes.xml
@@ -44,11 +44,8 @@ 		@android:color/transparent
 		<item name="android:statusBarColor">@android:color/transparent</item>
 		<item name="android:enforceStatusBarContrast">false</item>
 		<item name="lightStatusBar">false</item>
+		<item name="randomColourLightness">.75</item>
 	</style>
-
-	<declare-styleable name="Theme.Bimba">
-		<attr name="lightStatusBar" format="boolean" />
-	</declare-styleable>
 
 	<style name="Theme.Bimba.SearchResult.Title" parent="Theme.Bimba">
 		<item name="android:textColor">@android:color/system_neutral2_100</item>




diff --git a/app/src/main/res/values-v31/themes.xml b/app/src/main/res/values-v31/themes.xml
index 2e8bb56b42f58897274348b623bccddb580b190d..aa59c699a273350a5c22eac337f924fff8759988 100644
--- a/app/src/main/res/values-v31/themes.xml
+++ b/app/src/main/res/values-v31/themes.xml
@@ -44,6 +44,7 @@ 		@android:color/transparent
 		<item name="android:statusBarColor">@android:color/transparent</item>
 		<item name="android:enforceStatusBarContrast">false</item>
 		<item name="lightStatusBar">true</item>
+		<item name="randomColourLightness">.2</item>
 	</style>
 
 	<style name="Theme.Bimba.SearchResult.Title" parent="Theme.Bimba">