Bimba.git

commit acc39fc5bbe92ee240e1389a27037057e2eee6af

Author: Adam <git@apiote.xyz>

partially remove context from Struct method

 app/src/main/java/ml/adamsprogs/bimba/api/Structs.kt | 36 +++++++------


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 e03b3e160d1e6d22734b6ac95ae17f80ec9f235d..05903f2d7837f44e74016db3c97799d54bdbb637 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/api/Structs.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/api/Structs.kt
@@ -1,6 +1,7 @@
 package ml.adamsprogs.bimba.api
 
 import android.content.Context
+import android.content.res.Resources
 import android.graphics.*
 import android.util.DisplayMetrics
 import androidx.appcompat.content.res.AppCompatResources
@@ -232,46 +233,47 @@ 			((part + 0.055) / 1.055).pow(2.4)
 		}
 	}
 
-	private fun dpToPixel(dp: Float, context: Context): Float {
-		val metrics: DisplayMetrics = context.resources.displayMetrics
+	private fun dpToPixel(dp: Float): Float {
+		val metrics: DisplayMetrics = Resources.getSystem().displayMetrics
 		return dp * (metrics.densityDpi / 160f)
 	}
 
-	private fun dpToPixelI(dp: Float, context: Context): Int = dpToPixel(dp, context).roundToInt()
+	private fun dpToPixelI(dp: Float): Int = dpToPixel(dp).roundToInt()
 
 	fun icon(context: Context, type: LineType, colour: Colour): Bitmap {
 		val drawingBitmap = Bitmap.createBitmap(
-			dpToPixelI(24f, context),
-			dpToPixelI(24f, context),
+			dpToPixelI(24f),
+			dpToPixelI(24f),
 			Bitmap.Config.ARGB_8888
 		)
 		val canvas = Canvas(drawingBitmap)
 
 		canvas.drawPath(
 			getSquirclePath(
-				dpToPixel(.8f, context),
-				dpToPixel(.8f, context),
-				dpToPixelI(11.2f, context)
+				dpToPixel(.8f),
+				dpToPixel(.8f),
+				dpToPixelI(11.2f)
 			), Paint().apply { color = textColour(colour) })
 		canvas.drawPath(
 			getSquirclePath(
-				dpToPixel(1.6f, context),
-				dpToPixel(1.6f, context),
-				dpToPixelI(10.4f, context)
+				dpToPixel(1.6f),
+				dpToPixel(1.6f),
+				dpToPixelI(10.4f)
 			), Paint().apply { color = colour.toInt() })
 		val iconID = when (type) {
 			LineType.BUS -> R.drawable.ic_bus_black_24dp
 			LineType.TRAM -> R.drawable.ic_tram_black_24dp
 			LineType.UNKNOWN -> R.drawable.ic_commute_black_24dp
 		}
-		val icon = AppCompatResources.getDrawable(context, iconID)?.mutate()
-			?.apply {
-				setTint(textColour(colour))
-			}?.toBitmap(dpToPixelI(19.2f, context), dpToPixelI(19.2f, context), Bitmap.Config.ARGB_8888)
+		val icon =
+			AppCompatResources.getDrawable(context, iconID)?.mutate()  // todo(code) move context out
+				?.apply {
+					setTint(textColour(colour))
+				}?.toBitmap(dpToPixelI(19.2f), dpToPixelI(19.2f), Bitmap.Config.ARGB_8888)
 		canvas.drawBitmap(
 			icon!!,
-			dpToPixel(2.4f, context),
-			dpToPixel(2.4f, context),
+			dpToPixel(2.4f),
+			dpToPixel(2.4f),
 			Paint()
 		)
 		return drawingBitmap