Material spinner view now defaults to max lines

This commit is contained in:
Jays2Kings 2021-04-16 23:15:11 -04:00
parent 746468ee8d
commit 611ecbb552
2 changed files with 22 additions and 7 deletions

View File

@ -59,7 +59,11 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att
} }
} }
private val binding = MaterialSpinnerViewBinding.inflate(LayoutInflater.from(context), this, false) private val binding = MaterialSpinnerViewBinding.inflate(
LayoutInflater.from(context),
this,
false
)
init { init {
addView(binding.root) addView(binding.root)
@ -71,7 +75,7 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att
val entries = (a.getTextArray(R.styleable.MaterialSpinnerView_android_entries) ?: emptyArray()).map { it.toString() } val entries = (a.getTextArray(R.styleable.MaterialSpinnerView_android_entries) ?: emptyArray()).map { it.toString() }
this.entries = entries this.entries = entries
val maxLines = a.getInt(R.styleable.MaterialSpinnerView_android_maxLines, 1) val maxLines = a.getInt(R.styleable.MaterialSpinnerView_android_maxLines, Int.MAX_VALUE)
binding.titleView.maxLines = maxLines binding.titleView.maxLines = maxLines
this.entries = entries this.entries = entries
@ -142,7 +146,11 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att
} }
} }
fun bindToIntPreference(pref: Preference<Int>, @ArrayRes intValuesResource: Int, block: ((Int) -> Unit)? = null) { fun bindToIntPreference(
pref: Preference<Int>,
@ArrayRes intValuesResource: Int,
block: ((Int) -> Unit)? = null
) {
this.pref = pref this.pref = pref
prefOffset = 0 prefOffset = 0
val intValues = resources.getStringArray(intValuesResource).map { it.toIntOrNull() } val intValues = resources.getStringArray(intValuesResource).map { it.toIntOrNull() }
@ -173,7 +181,11 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att
return popup return popup
} }
private fun makeSettingsPopup(preference: Preference<Int>, intValues: List<Int?>, block: ((Int) -> Unit)? = null): PopupMenu { private fun makeSettingsPopup(
preference: Preference<Int>,
intValues: List<Int?>,
block: ((Int) -> Unit)? = null
): PopupMenu {
val popup = popup() val popup = popup()
// Set a listener so we are notified if a menu item is clicked // Set a listener so we are notified if a menu item is clicked
popup.setOnMenuItemClickListener { menuItem -> popup.setOnMenuItemClickListener { menuItem ->
@ -185,7 +197,11 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att
return popup return popup
} }
private fun makeSettingsPopup(preference: Preference<Int>, offset: Int = 0, block: ((Int) -> Unit)? = null): PopupMenu { private fun makeSettingsPopup(
preference: Preference<Int>,
offset: Int = 0,
block: ((Int) -> Unit)? = null
): PopupMenu {
val popup = popup() val popup = popup()
// Set a listener so we are notified if a menu item is clicked // Set a listener so we are notified if a menu item is clicked
popup.setOnMenuItemClickListener { menuItem -> popup.setOnMenuItemClickListener { menuItem ->

View File

@ -15,7 +15,6 @@
android:layout_marginEnd="24dp" android:layout_marginEnd="24dp"
android:layout_marginBottom="12dp" android:layout_marginBottom="12dp"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="2"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/halfway_point" app:layout_constraintEnd_toStartOf="@id/halfway_point"
@ -37,7 +36,7 @@
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
android:ellipsize="end" android:ellipsize="end"
app:layout_constraintHorizontal_chainStyle="spread_inside" app:layout_constraintHorizontal_chainStyle="spread_inside"
tools:text="Details dsfdsfsdfs df sfs dfsf er sd" /> tools:text="Details that are so long we need to" />
<ImageView <ImageView
android:id="@+id/dropdown_caret" android:id="@+id/dropdown_caret"