Bimba.git

commit f60415ef9a4689341637a03c0b3c5b7047aec699

Author: Adam <git@apiote.xyz>

fix results height

 app/src/main/java/ml/adamsprogs/bimba/search/Results.kt | 50 +++++-----
 app/src/main/res/layout/result.xml | 45 +++++++++
 app/src/main/res/layout/suggestion.xml | 2 


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 2feea303cf6eb8996b3741935e2b2945ee77c47c..576997efda9bb9db7bc74b89daa12ba069d3541d 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/search/Results.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/search/Results.kt
@@ -64,24 +64,23 @@ 				@Suppress("DEPRECATION")
 				holder.text.text = Html.fromHtml(suggestion.getBody(context))
 			}
 
-			holder.text.setTextColor(getColor(context, R.color.textDark))
+interface Adapter {
+	fun createViewHolder(
+		inflater: LayoutInflater,
+		layout: Int,
+		parent: ViewGroup
+	): BimbaViewHolder {
+		val rowView = inflater.inflate(layout, parent, false)
+		return BimbaViewHolder(rowView)
+	}
 
-			val icon = getDrawable(suggestion.getIcon(), context)
-			icon.mutate()
-			icon.colorFilter = null
-			if (suggestion is StopSuggestion)
-				when (suggestion.zone) {
-					"A" -> icon.setColorFilter(getColor(context, R.color.zoneA), PorterDuff.Mode.SRC_IN)
-					"B" -> icon.setColorFilter(getColor(context, R.color.zoneB), PorterDuff.Mode.SRC_IN)
-					"C" -> icon.setColorFilter(getColor(context, R.color.zoneC), PorterDuff.Mode.SRC_IN)
-					else -> icon.setColorFilter(getColor(context, R.color.textDark), PorterDuff.Mode.SRC_IN)
-				}
-			else if (suggestion is LineSuggestion) {
-				icon.setColorFilter(suggestion.getColour(), PorterDuff.Mode.SRC_IN)
-				holder.icon.setBackgroundColor(suggestion.getBgColour())
-			}
-			holder.icon.setImageDrawable(icon)*/
-		}
+	fun bindSuggestionHolder(
+		item: Item,
+		holder: BimbaViewHolder?,
+		context: Context?,
+		onClickListener: (Item) -> Unit
+	) {
+		BimbaViewHolder.bind(item, holder, context, onClickListener)
 	}
 }
 
@@ -91,14 +90,13 @@ 	private val context: Context?,
 	private var items: List<Item>,
 	private val onClickListener: ((Item) -> Unit)
 ) :
-	RecyclerView.Adapter<BimbaViewHolder>() {
+	RecyclerView.Adapter<BimbaViewHolder>(), Adapter {
 	override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BimbaViewHolder {
-		val rowView = inflater.inflate(R.layout.suggestion, parent, false)
-		return BimbaViewHolder(rowView)
+		return createViewHolder(inflater, R.layout.result, parent)
 	}
 
 	override fun onBindViewHolder(holder: BimbaViewHolder, position: Int) {
-		BimbaViewHolder.bind(items[position], holder, context, onClickListener)
+		bindSuggestionHolder(items[position], holder, context, onClickListener)
 	}
 
 	override fun getItemCount(): Int = items.size
@@ -114,16 +112,14 @@ 	inflater: LayoutInflater,
 	private val context: Context?,
 	private val onClickListener: ((Item) -> Unit)
 ) :
-	SuggestionsAdapter<Item, BimbaViewHolder>(inflater) {
-
+	SuggestionsAdapter<Item, BimbaViewHolder>(inflater), Adapter {
 	override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BimbaViewHolder {
-		val rowView = layoutInflater.inflate(R.layout.suggestion, parent, false)
-		return BimbaViewHolder(rowView)
+		return createViewHolder(layoutInflater, R.layout.suggestion, parent)
 	}
 
-	override fun getSingleViewHeight(): Int = 72  // todo calculate actual height
+	override fun getSingleViewHeight(): Int = 72
 
 	override fun onBindSuggestionHolder(item: Item, holder: BimbaViewHolder?, pos: Int) {
-		BimbaViewHolder.bind(item, holder, context, onClickListener)
+		bindSuggestionHolder(item, holder, context, onClickListener)
 	}
 }
\ No newline at end of file




diff --git a/app/src/main/res/layout/result.xml b/app/src/main/res/layout/result.xml
new file mode 100644
index 0000000000000000000000000000000000000000..b0d9d514924029ec71102dede57e8e96b7e7317c
--- /dev/null
+++ b/app/src/main/res/layout/result.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- git:sugg_result -->
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+	xmlns:app="http://schemas.android.com/apk/res-auto"
+	android:id="@+id/suggestion"
+	android:layout_width="match_parent"
+	android:layout_height="wrap_content">
+
+	<ImageView
+		android:id="@+id/suggestion_image"
+		android:layout_width="wrap_content"
+		android:layout_height="wrap_content"
+		android:layout_marginStart="8dp"
+		android:layout_marginTop="8dp"
+		android:layout_marginBottom="8dp"
+		app:layout_constraintBottom_toBottomOf="parent"
+		app:layout_constraintStart_toStartOf="parent"
+		app:layout_constraintTop_toTopOf="parent" />
+
+	<TextView
+		android:id="@+id/suggestion_title"
+		android:layout_width="0dp"
+		android:layout_height="wrap_content"
+		android:layout_marginStart="8dp"
+		android:layout_marginTop="8dp"
+		android:layout_marginEnd="8dp"
+		android:text=""
+		android:textAppearance="@style/Theme.Bimba.SearchResult.Title"
+		app:layout_constraintEnd_toEndOf="parent"
+		app:layout_constraintStart_toEndOf="@+id/suggestion_image"
+		app:layout_constraintTop_toTopOf="parent" />
+
+	<TextView
+		android:id="@+id/suggestion_description"
+		style="@style/Theme.Bimba.SearchResult.Description"
+		android:layout_width="0dp"
+		android:layout_height="wrap_content"
+		android:layout_marginEnd="8dp"
+		android:text=""
+		app:layout_constraintBottom_toBottomOf="parent"
+		app:layout_constraintEnd_toEndOf="parent"
+		app:layout_constraintStart_toStartOf="@+id/suggestion_title"
+		app:layout_constraintTop_toBottomOf="@+id/suggestion_title" />
+
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file




diff --git a/app/src/main/res/layout/suggestion.xml b/app/src/main/res/layout/suggestion.xml
index 5124ef7550b5cd3f1ca31d167ca91fe333b587a2..8aa8652229bde6d4f63e2b9c40da7c884b4f3bb5 100644
--- a/app/src/main/res/layout/suggestion.xml
+++ b/app/src/main/res/layout/suggestion.xml
@@ -3,7 +3,7 @@  	xmlns:app="http://schemas.android.com/apk/res-auto"
 	android:id="@+id/suggestion"
 	android:layout_width="match_parent"
-	android:layout_height="72dp"> <!-- todo wrap_content -->
+	android:layout_height="72dp">
 
 	<ImageView
 		android:id="@+id/suggestion_image"