Update dependencies

This commit is contained in:
Mygod
2019-01-03 23:22:28 +08:00
parent 32c5973cdc
commit b00791d644
11 changed files with 125 additions and 105 deletions

View File

@@ -3,17 +3,18 @@ package be.mygod.vpnhotspot.preference
import android.content.Context
import android.text.TextUtils
import android.util.AttributeSet
import androidx.preference.EditTextPreference
import be.mygod.vpnhotspot.R
import be.mygod.vpnhotspot.widget.AlwaysAutoCompleteEditText
import com.takisoft.preferencex.AutoSummaryEditTextPreference
open class AlwaysAutoCompleteEditTextPreference @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = R.attr.editTextPreferenceStyle,
defStyleRes: Int = 0) : AutoSummaryEditTextPreference(context, attrs, defStyleAttr, defStyleRes) {
defStyleRes: Int = 0) : EditTextPreference(context, attrs, defStyleAttr, defStyleRes) {
val editText = AlwaysAutoCompleteEditText(context, attrs)
init {
editText.id = android.R.id.edit
SummaryFallbackProvider(this)
}
override fun setText(text: String?) {

View File

@@ -5,11 +5,16 @@ import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.EditText
import androidx.appcompat.widget.AppCompatAutoCompleteTextView
import androidx.core.os.bundleOf
import androidx.preference.PreferenceDialogFragmentCompat
open class AlwaysAutoCompleteEditTextPreferenceDialogFragmentCompat : PreferenceDialogFragmentCompat() {
companion object {
const val KEY_SUGGESTIONS = "suggestions"
private const val ARG_SUGGESTIONS = "suggestions"
}
fun setArguments(key: String, suggestions: Array<String>) {
arguments = bundleOf(Pair(ARG_KEY, key), Pair(ARG_SUGGESTIONS, suggestions))
}
private lateinit var editText: AppCompatAutoCompleteTextView
@@ -19,12 +24,13 @@ open class AlwaysAutoCompleteEditTextPreferenceDialogFragmentCompat : Preference
super.onBindDialogView(view)
editText = editTextPreference.editText
editText.hint = (editTextPreference.summaryProvider as SummaryFallbackProvider).fallback
editText.setText(this.editTextPreference.text)
val text = editText.text
if (text != null) editText.setSelection(text.length, text.length)
val suggestions = arguments?.getStringArray(KEY_SUGGESTIONS)
val suggestions = arguments?.getStringArray(ARG_SUGGESTIONS)
if (suggestions != null)
editText.setAdapter(ArrayAdapter(view.context, android.R.layout.select_dialog_item, suggestions))

View File

@@ -0,0 +1,15 @@
package be.mygod.vpnhotspot.preference
import androidx.preference.EditTextPreference
import androidx.preference.Preference
class SummaryFallbackProvider(preference: Preference) : Preference.SummaryProvider<EditTextPreference> {
val fallback = preference.summary
init {
preference.summaryProvider = this
}
override fun provideSummary(preference: EditTextPreference) = preference.text.let {
if (it.isNullOrEmpty()) fallback else it
}
}