Bimba.git

commit 681a75ec849392c5d42becedbcaf32c56c750f0f

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

show rounded coloured chips in change options

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


diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 13f5de92b8b809310bd9215cb67fa241b4200fdc..6ff0eb7f653b62e4287a86c19dd3f3612f2c5881 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -7,7 +7,6 @@ 	id("com.android.application")
 	kotlin("android")
 	kotlin("plugin.parcelize")
 	kotlin("plugin.serialization")
-	// id("com.mermake.locale-resource-generator") version "0.1.1"
 }
 
 android {




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/RoundedBackgroundSpan.kt b/app/src/main/java/xyz/apiote/bimba/czwek/RoundedBackgroundSpan.kt
new file mode 100644
index 0000000000000000000000000000000000000000..13a93d42c47db30aa1a50a5bc2fbdfdd2ac8e3ff
--- /dev/null
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/RoundedBackgroundSpan.kt
@@ -0,0 +1,38 @@
+package xyz.apiote.bimba.czwek
+
+import android.graphics.Canvas
+import android.graphics.Paint
+import android.graphics.RectF
+import android.text.style.ReplacementSpan
+
+class RoundedBackgroundSpan(private val bgColour: Int, private val fgColour: Int) : ReplacementSpan() {
+	override fun getSize(
+		paint: Paint,
+		text: CharSequence,
+		start: Int,
+		end: Int,
+		fm: Paint.FontMetricsInt?
+	): Int {
+		return (paint.measureText(text, start, end)+20).toInt()
+	}
+
+	override fun draw(
+		canvas: Canvas,
+		text: CharSequence,
+		start: Int,
+		end: Int,
+		x: Float,
+		top: Int,
+		y: Int,
+		bottom: Int,
+		paint: Paint
+	) {
+		val length = paint.measureText(text, start, end) + 20
+		val rect = RectF(x, top.toFloat() - 5f, x + length, y.toFloat() + 5f)
+		paint.color = bgColour
+		canvas.drawRoundRect(rect, 10f, 10f, paint)
+		paint.color = fgColour
+		paint.textAlign = Paint.Align.CENTER
+		canvas.drawText(text, start, end, x+(length/2), y.toFloat(), paint)
+	}
+}
\ No newline at end of file




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/api/responses/Departures.kt b/app/src/main/java/xyz/apiote/bimba/czwek/api/responses/Departures.kt
index 0d053162b88f3d4f2a65975d1d2cff92e2b979a4..4e22e00b1b8365b32fc365f86c904dd74366651c 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/api/responses/Departures.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/api/responses/Departures.kt
@@ -19,7 +19,7 @@ 	companion object {
 		fun unmarshal(stream: InputStream): DeparturesResponse {
 			val reader = Reader(stream)
 			return when (val v = reader.readUInt().toULong()) {
-				// 0UL -> DeparturesResponseDev.unmarshal(stream)
+				0UL -> DeparturesResponseDev.unmarshal(stream)
 				1UL -> DeparturesResponseV1.unmarshal(stream)
 				2UL -> DeparturesResponseV2.unmarshal(stream)
 				3UL -> DeparturesResponseV3.unmarshal(stream)




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/api/responses/Locatables.kt b/app/src/main/java/xyz/apiote/bimba/czwek/api/responses/Locatables.kt
index 3a42262c3955a75ef6245f6b17e8ceb88f03d429..2188e29c3297dc5614ce30f40b4bb359a67781f0 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/api/responses/Locatables.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/api/responses/Locatables.kt
@@ -21,7 +21,7 @@ 	companion object {
 		fun unmarshal(stream: InputStream): LocatablesResponse {
 			val reader = Reader(stream)
 			return when (val v = reader.readUInt().toULong()) {
-				// 0UL -> LocatablesResponseDev.unmarshal(stream)
+				0UL -> LocatablesResponseDev.unmarshal(stream)
 				1UL -> LocatablesResponseV1.unmarshal(stream)
 				2UL -> LocatablesResponseV2.unmarshal(stream)
 				3UL -> LocatablesResponseV3.unmarshal(stream)




diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/api/responses/Queryables.kt b/app/src/main/java/xyz/apiote/bimba/czwek/api/responses/Queryables.kt
index 8e7cc8f8c7a63204b4c2d69604ae33f2fe4ac768..216ab34e80475121dde939626338c14e59e382cb 100644
--- a/app/src/main/java/xyz/apiote/bimba/czwek/api/responses/Queryables.kt
+++ b/app/src/main/java/xyz/apiote/bimba/czwek/api/responses/Queryables.kt
@@ -22,7 +22,7 @@ 	companion object {
 		fun unmarshal(stream: InputStream): QueryablesResponse {
 			val reader = Reader(stream)
 			return when (val v = reader.readUInt().toULong()) {
-				// 0UL -> QueryablesResponseDev.unmarshal(stream)
+				0UL -> QueryablesResponseDev.unmarshal(stream)
 				1UL -> QueryablesResponseV1.unmarshal(stream)
 				2UL -> QueryablesResponseV2.unmarshal(stream)
 				3UL -> QueryablesResponseV3.unmarshal(stream)




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 662b6d26c696a2096f634ecfab49e7af6d7aacdb..af81fbf17847b928c5c2ee0c674cb4a451bf858a 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
@@ -12,13 +12,14 @@ import android.text.Spannable
 import android.text.SpannableStringBuilder
 import android.text.Spanned
 import android.text.SpannedString
-import android.text.style.BackgroundColorSpan
 import android.text.style.StyleSpan
 import androidx.preference.PreferenceManager
 import xyz.apiote.bimba.czwek.R
+import xyz.apiote.bimba.czwek.RoundedBackgroundSpan
 import xyz.apiote.bimba.czwek.api.StopV1
 import xyz.apiote.bimba.czwek.api.StopV2
 import xyz.apiote.bimba.czwek.api.StopV3
+
 
 data class Stop(
 	val code: String,
@@ -121,8 +122,8 @@ 				"decoration" -> {
 					if (args.isNotEmpty()) {
 						return@forEach
 					}
-					val background = BackgroundColorSpan(line.colour.toInt())
-					val foreground = line.textColour(line.colour)
+					// TODO rounded corners/padding
+					val background = RoundedBackgroundSpan(line.colour.toInt(), line.textColour(line.colour))
 					val ital = StyleSpan(Typeface.ITALIC)
 					when (decoration) {
 						LineDecoration.ITALICS -> str.setSpan(
@@ -134,7 +135,7 @@ 						)
 
 						LineDecoration.COLOUR -> {
 							str.setSpan(background, str.getSpanStart(it), str.getSpanEnd(it), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
-							str.setSpan(foreground, str.getSpanStart(it), str.getSpanEnd(it), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
+							// str.setSpan(foreground, str.getSpanStart(it), str.getSpanEnd(it), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
 						}
 
 						LineDecoration.NONE -> {}
@@ -170,4 +171,5 @@ 					else -> Stop.LineDecoration.ITALICS
 				}
 		}
 	}
-}
\ No newline at end of file
+}
+




diff --git a/app/src/main/res/layout/result.xml b/app/src/main/res/layout/result.xml
index e7dd45553043a5ffad0cfceb1ed5fc71ace8b0b6..76614ac6dfa60c71c84bfc0c97448af7c18426af 100644
--- a/app/src/main/res/layout/result.xml
+++ b/app/src/main/res/layout/result.xml
@@ -78,13 +78,19 @@ 		android:id="@+id/suggestion_description"
 		style="@style/Theme.Bimba.SearchResult.Description"
 		android:layout_width="0dp"
 		android:layout_height="wrap_content"
-		android:maxWidth="360dp"
 		android:layout_marginTop="4dp"
 		android:layout_marginEnd="4dp"
+		android:includeFontPadding="false"
+		android:lineSpacingMultiplier="1.6"
+		android:maxWidth="360dp"
+		android:paddingTop="4dp"
+		android:paddingBottom="4dp"
 		app:layout_constraintBottom_toBottomOf="parent"
 		app:layout_constraintEnd_toStartOf="@+id/distance"
+		app:layout_constraintHorizontal_bias="0.0"
 		app:layout_constraintStart_toStartOf="@+id/suggestion_title"
 		app:layout_constraintTop_toBottomOf="@+id/feed_name"
+		app:layout_constraintVertical_bias="1.0"
 		tool:text="Metropolitan » Baker Street, Tower Hill The Monument, Westminster, Piccadilly Circus, Oxford Street" />
 
 </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file




diff --git a/settings.gradle.kts b/settings.gradle.kts
index 5549aa5de8f76511812ade32b3e90a17fd758c27..1ce7ce840b4bacaa13bd373882ed08820ac536d9 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -31,4 +31,4 @@     }
 }
 rootProject.name = "Bimba"
 include(":app")
-include(":fruchtfleisch")
\ No newline at end of file
+include(":fruchtfleisch")