Select source domains using AutoCompleteTextView
parent
c220bd5517
commit
7bffb5f22d
@ -0,0 +1,58 @@
|
|||||||
|
package org.koitharu.kotatsu.settings.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.ArrayAdapter
|
||||||
|
import android.widget.AutoCompleteTextView
|
||||||
|
import android.widget.EditText
|
||||||
|
import androidx.annotation.ArrayRes
|
||||||
|
import androidx.annotation.AttrRes
|
||||||
|
import androidx.annotation.StyleRes
|
||||||
|
import androidx.preference.EditTextPreference
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
|
||||||
|
class AutoCompleteTextViewPreference @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
@AttrRes defStyleAttr: Int = R.attr.autoCompleteTextViewPreferenceStyle,
|
||||||
|
@StyleRes defStyleRes: Int = R.style.Preference_AutoCompleteTextView,
|
||||||
|
) : EditTextPreference(context, attrs, defStyleAttr, defStyleRes) {
|
||||||
|
|
||||||
|
private val autoCompleteBindListener = AutoCompleteBindListener()
|
||||||
|
var entries: Array<String> = emptyArray()
|
||||||
|
|
||||||
|
init {
|
||||||
|
super.setOnBindEditTextListener(autoCompleteBindListener)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setEntries(@ArrayRes arrayResId: Int) {
|
||||||
|
this.entries = context.resources.getStringArray(arrayResId)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setEntries(entries: Collection<String>) {
|
||||||
|
this.entries = entries.toTypedArray()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setOnBindEditTextListener(onBindEditTextListener: OnBindEditTextListener?) {
|
||||||
|
autoCompleteBindListener.delegate = onBindEditTextListener
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class AutoCompleteBindListener : OnBindEditTextListener {
|
||||||
|
|
||||||
|
var delegate: OnBindEditTextListener? = null
|
||||||
|
|
||||||
|
override fun onBindEditText(editText: EditText) {
|
||||||
|
delegate?.onBindEditText(editText)
|
||||||
|
if (editText !is AutoCompleteTextView || entries.isEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
editText.threshold = 0
|
||||||
|
editText.setAdapter(ArrayAdapter(editText.context, android.R.layout.simple_spinner_dropdown_item, entries))
|
||||||
|
(editText.parent as? ViewGroup)?.findViewById<View>(R.id.dropdown)?.setOnClickListener {
|
||||||
|
editText.showDropDown()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ScrollView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginTop="48dp"
|
||||||
|
android:layout_marginBottom="48dp"
|
||||||
|
android:overScrollMode="ifContentScrolls">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@android:id/message"
|
||||||
|
style="?android:attr/textAppearanceSmall"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="24dp"
|
||||||
|
android:layout_marginLeft="24dp"
|
||||||
|
android:layout_marginEnd="24dp"
|
||||||
|
android:layout_marginRight="24dp"
|
||||||
|
android:layout_marginBottom="48dp"
|
||||||
|
android:labelFor="@android:id/edit"
|
||||||
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
|
tools:ignore="LabelFor" />
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="20dp"
|
||||||
|
android:layout_marginLeft="20dp"
|
||||||
|
android:layout_marginEnd="20dp"
|
||||||
|
android:layout_marginRight="20dp">
|
||||||
|
|
||||||
|
<AutoCompleteTextView
|
||||||
|
android:id="@android:id/edit"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:importantForAutofill="no"
|
||||||
|
android:minHeight="48dp" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/dropdown"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_gravity="center_vertical|end"
|
||||||
|
android:background="?selectableItemBackgroundBorderless"
|
||||||
|
android:paddingBottom="2dp"
|
||||||
|
android:scaleType="center"
|
||||||
|
android:src="@drawable/ic_expand_more"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
||||||
Loading…
Reference in New Issue