Bimba.git

commit f10261064921d083e6bfa2cf83901350176b9f0d

Author: Adam <git@apiote.xyz>

change size of icons on map

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


diff --git a/app/src/main/java/ml/adamsprogs/bimba/api/Structs.kt b/app/src/main/java/ml/adamsprogs/bimba/api/Structs.kt
index 7bf00e8e16c98a6999c0950d44aefc999d561e58..679095292cc90d1148e69e45088868d8f5a93ad4 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/api/Structs.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/api/Structs.kt
@@ -177,8 +177,8 @@ 	}
 
 	override fun id(): String = ID
 
-	override fun icon(context: Context): Drawable {
-		return BitmapDrawable(context.resources, Line.icon(context, 1f))
+	override fun icon(context: Context, scale: Float): Drawable {
+		return BitmapDrawable(context.resources, Line.icon(context, scale))
 	}
 
 	override fun location(): Position = Position
@@ -254,7 +254,7 @@ }
 
 interface Item
 interface Locatable {
-	fun icon(context: Context): Drawable
+	fun icon(context: Context, scale: Float = 1f): Drawable
 	fun location(): Position
 	fun id(): String
 }
@@ -266,7 +266,7 @@ 	val position: Position,
 	val changeOptions: List<ChangeOption>,
 	val name: String
 ) : Item, Locatable {
-	override fun icon(context: Context): Drawable {
+	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)
@@ -284,7 +284,11 @@ 			AppCompatResources.getDrawable(context, R.drawable.stop_bg)!!.mutate()
 				.apply {
 					setTint(HSLToColor(arrayOf(h, s, l).toFloatArray()))
 				}
-		return LayerDrawable(arrayOf(bg, fg))
+		return BitmapDrawable(
+			context.resources,
+			LayerDrawable(arrayOf(bg, fg)).mutate()
+				.toBitmap(dpToPixelI(24f / scale), dpToPixelI(24f / scale), Bitmap.Config.ARGB_8888)
+		)
 	}
 
 	override fun id(): String = code
@@ -356,23 +360,23 @@ 	}
 
 	fun icon(context: Context, type: LineType, colour: Colour, scale: Float): Bitmap {
 		val drawingBitmap = Bitmap.createBitmap(
-			dpToPixelI(24f/scale),
-			dpToPixelI(24f/scale),
+			dpToPixelI(24f / scale),
+			dpToPixelI(24f / scale),
 			Bitmap.Config.ARGB_8888
 		)
 		val canvas = Canvas(drawingBitmap)
 
 		canvas.drawPath(
 			getSquirclePath(
-				dpToPixel(.8f/scale),
-				dpToPixel(.8f/scale),
-				dpToPixelI(11.2f/scale)
+				dpToPixel(.8f / scale),
+				dpToPixel(.8f / scale),
+				dpToPixelI(11.2f / scale)
 			), Paint().apply { color = textColour(colour) })
 		canvas.drawPath(
 			getSquirclePath(
-				dpToPixel(1.6f/scale),
-				dpToPixel(1.6f/scale),
-				dpToPixelI(10.4f/scale)
+				dpToPixel(1.6f / scale),
+				dpToPixel(1.6f / scale),
+				dpToPixelI(10.4f / scale)
 			), Paint().apply { color = colour.toInt() })
 
 		val iconID = when (type) {
@@ -384,11 +388,11 @@ 		val icon =
 			AppCompatResources.getDrawable(context, iconID)?.mutate()  // todo(code) move context out
 				?.apply {
 					setTint(textColour(colour))
-				}?.toBitmap(dpToPixelI(19.2f/scale), dpToPixelI(19.2f/scale), Bitmap.Config.ARGB_8888)
+				}?.toBitmap(dpToPixelI(19.2f / scale), dpToPixelI(19.2f / scale), Bitmap.Config.ARGB_8888)
 		canvas.drawBitmap(
 			icon!!,
-			dpToPixel(2.4f/scale),
-			dpToPixel(2.4f/scale),
+			dpToPixel(2.4f / scale),
+			dpToPixel(2.4f / scale),
 			Paint()
 		)
 		return drawingBitmap




diff --git a/app/src/main/java/ml/adamsprogs/bimba/dashboard/ui/map/MapFragment.kt b/app/src/main/java/ml/adamsprogs/bimba/dashboard/ui/map/MapFragment.kt
index 7b5fac52304e9b3dba3df0f0232d35bcba485d27..ac039dcfa0c61f36da8ad0c583c4871f14fe07a4 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/dashboard/ui/map/MapFragment.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/dashboard/ui/map/MapFragment.kt
@@ -88,10 +88,12 @@ 			locationOverlay.setDirectionIcon(
 				AppCompatResources.getDrawable(it, R.drawable.navigation_arrow)?.mutate()
 					?.toBitmap(dpToPixelI(36f), dpToPixelI(36f), Bitmap.Config.ARGB_8888)
 			)
+			locationOverlay.setDirectionAnchor(.5f, .5f)
 			locationOverlay.setPersonIcon(
 				AppCompatResources.getDrawable(it, R.drawable.navigation_circle)?.mutate()
-					?.toBitmap(dpToPixelI(36f), dpToPixelI(36f), Bitmap.Config.ARGB_8888)
+					?.toBitmap(dpToPixelI(24f), dpToPixelI(24f), Bitmap.Config.ARGB_8888)
 			)
+			locationOverlay.setPersonAnchor(.5f, .5f)
 		}
 
 		binding.floatingActionButton.setOnClickListener {
@@ -152,7 +154,7 @@ 			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) }
+				marker.icon = context?.let { ctx -> locatable.icon(ctx, 2f) }
 
 				context?.let { ctx ->
 					marker.setOnMarkerClickListener { _, _ ->




diff --git a/app/src/main/java/ml/adamsprogs/bimba/search/Results.kt b/app/src/main/java/ml/adamsprogs/bimba/search/Results.kt
index 9ce76e9d21d575e48739745db6497a38996de56c..8758a66de867fce2a67bf3abb40ff6d45a7907eb 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/search/Results.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/search/Results.kt
@@ -29,7 +29,7 @@ 			context: Context?,
 			onClickListener: (Item) -> Unit
 		) {
 			when (item) {
-				is Stop -> bindStop(item, holder)
+				is Stop -> bindStop(item, holder, context)
 				is Line -> bindLine(item, holder, context)
 				else -> throw NotImplementedError("Shouldn't happen")
 			}
@@ -39,8 +39,8 @@ 			}
 		}
 
 		@SuppressLint("SetTextI18n")
-		fun bindStop(stop: Stop, holder: BimbaViewHolder?) {
-			holder?.icon?.setImageResource(R.drawable.stop)
+		fun bindStop(stop: Stop, holder: BimbaViewHolder?, context: Context?) {
+			holder?.icon?.setImageDrawable(stop.icon(context!!))
 			holder?.title?.text = "${stop.name} [${stop.code}]"
 			holder?.description?.text = stop.changeOptions()
 		}