Utilize more KTX extensions (#7348)
This commit is contained in:
@@ -11,6 +11,7 @@ import androidx.annotation.ArrayRes
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.appcompat.view.menu.MenuBuilder
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.core.content.withStyledAttributes
|
||||
import androidx.core.view.forEach
|
||||
import androidx.core.view.get
|
||||
import com.fredporciuncula.flow.preferences.Preference
|
||||
@@ -51,16 +52,15 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
init {
|
||||
addView(binding.root)
|
||||
|
||||
val attr = context.obtainStyledAttributes(attrs, R.styleable.MaterialSpinnerView)
|
||||
context.withStyledAttributes(set = attrs, attrs = R.styleable.MaterialSpinnerView) {
|
||||
val title = getString(R.styleable.MaterialSpinnerView_title).orEmpty()
|
||||
binding.title.text = title
|
||||
|
||||
val title = attr.getString(R.styleable.MaterialSpinnerView_title).orEmpty()
|
||||
binding.title.text = title
|
||||
|
||||
val entries = (attr.getTextArray(R.styleable.MaterialSpinnerView_android_entries) ?: emptyArray()).map { it.toString() }
|
||||
this.entries = entries
|
||||
binding.details.text = entries.firstOrNull().orEmpty()
|
||||
|
||||
attr.recycle()
|
||||
val viewEntries = (getTextArray(R.styleable.MaterialSpinnerView_android_entries)
|
||||
?: emptyArray()).map { it.toString() }
|
||||
entries = viewEntries
|
||||
binding.details.text = viewEntries.firstOrNull().orEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
fun setSelection(selection: Int) {
|
||||
@@ -152,9 +152,7 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
popup.menu.forEach {
|
||||
it.icon = emptyIcon
|
||||
}
|
||||
popup.menu.getItem(selectedPosition)?.let {
|
||||
it.icon = checkmarkIcon
|
||||
}
|
||||
popup.menu[selectedPosition].icon = checkmarkIcon
|
||||
popup.setOnMenuItemClickListener { menuItem ->
|
||||
val pos = menuClicked(menuItem)
|
||||
onItemClick(pos)
|
||||
|
||||
Reference in New Issue
Block a user