diff --git a/app/src/main/java/net/vonforst/evmap/ui/BindingAdapters.kt b/app/src/main/java/net/vonforst/evmap/ui/BindingAdapters.kt index 3aed3586..36e44d8d 100644 --- a/app/src/main/java/net/vonforst/evmap/ui/BindingAdapters.kt +++ b/app/src/main/java/net/vonforst/evmap/ui/BindingAdapters.kt @@ -2,6 +2,7 @@ package net.vonforst.evmap.ui import android.content.Context import android.content.res.ColorStateList +import android.text.SpannableString import android.view.View import android.view.ViewGroup.MarginLayoutParams import android.widget.ImageView @@ -150,6 +151,26 @@ fun setTopMargin(view: View, topMargin: Float) { view.layoutParams = layoutParams } +/** + * Linkify is already possible using the autoLink and linksClickable attributes, but this does not + * remove spans correctly. So we implement a new version that manually removes the spans. + */ +@BindingAdapter("linkify") +fun setLinkify(textView: TextView, oldValue: Int, newValue: Int) { + if (oldValue == newValue) return + + textView.autoLinkMask = newValue + textView.linksClickable = newValue != 0 + + // remove spans + if (newValue == 0) { + val text = textView.text as SpannableString + text.getSpans(0, text.length, Any::class.java).forEach { + text.removeSpan(it) + } + } +} + private fun availabilityColor( status: List?, context: Context diff --git a/app/src/main/res/layout/item_detail.xml b/app/src/main/res/layout/item_detail.xml index 24da4b9e..96b84f56 100644 --- a/app/src/main/res/layout/item_detail.xml +++ b/app/src/main/res/layout/item_detail.xml @@ -18,7 +18,7 @@ app:selectableItemBackground="@{item.clickable}"> diff --git a/app/src/main/res/layout/item_detail_openinghours.xml b/app/src/main/res/layout/item_detail_openinghours.xml index 5cc771a1..8eca0e9a 100644 --- a/app/src/main/res/layout/item_detail_openinghours.xml +++ b/app/src/main/res/layout/item_detail_openinghours.xml @@ -24,7 +24,7 @@ app:selectableItemBackground="@{item.clickable}"> @@ -83,8 +82,8 @@ app:goneUnless="@{expandToggle.checked}" app:hours="@{item.hoursDays}" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="@+id/textView9" - app:layout_constraintTop_toBottomOf="@+id/textView8" /> + app:layout_constraintStart_toStartOf="@+id/txtTitle" + app:layout_constraintTop_toBottomOf="@+id/txtContent" />