Add back auto complete interface names from 0.1.0
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package be.mygod.vpnhotspot.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.text.TextUtils
|
||||
import android.util.AttributeSet
|
||||
import be.mygod.vpnhotspot.R
|
||||
import be.mygod.vpnhotspot.widget.AlwaysAutoCompleteEditText
|
||||
import com.takisoft.fix.support.v7.preference.AutoSummaryEditTextPreference
|
||||
|
||||
open class AlwaysAutoCompleteEditTextPreference @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = R.attr.editTextPreferenceStyle,
|
||||
defStyleRes: Int = 0) : AutoSummaryEditTextPreference(context, attrs, defStyleAttr, defStyleRes) {
|
||||
val editText = AlwaysAutoCompleteEditText(context, attrs)
|
||||
|
||||
init {
|
||||
editText.id = android.R.id.edit
|
||||
}
|
||||
|
||||
override fun setText(text: String) {
|
||||
val oldText = getText()
|
||||
super.setText(text)
|
||||
if (!TextUtils.equals(text, oldText)) notifyChanged()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package be.mygod.vpnhotspot.preference
|
||||
|
||||
import android.support.v7.preference.PreferenceDialogFragmentCompat
|
||||
import android.support.v7.widget.AppCompatAutoCompleteTextView
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.EditText
|
||||
|
||||
open class AlwaysAutoCompleteEditTextPreferenceDialogFragmentCompat : PreferenceDialogFragmentCompat() {
|
||||
companion object {
|
||||
const val KEY_SUGGESTIONS = "suggestions"
|
||||
}
|
||||
|
||||
private lateinit var editText: AppCompatAutoCompleteTextView
|
||||
private val editTextPreference get() = this.preference as AlwaysAutoCompleteEditTextPreference
|
||||
|
||||
override fun onBindDialogView(view: View) {
|
||||
super.onBindDialogView(view)
|
||||
|
||||
editText = editTextPreference.editText
|
||||
editText.setText(this.editTextPreference.text)
|
||||
|
||||
val text = editText.text
|
||||
if (text != null) editText.setSelection(text.length, text.length)
|
||||
|
||||
val suggestions = arguments?.getStringArray(KEY_SUGGESTIONS)
|
||||
if (suggestions != null)
|
||||
editText.setAdapter(ArrayAdapter(view.context, android.R.layout.select_dialog_item, suggestions))
|
||||
|
||||
val oldParent = editText.parent as? ViewGroup?
|
||||
if (oldParent !== view) {
|
||||
oldParent?.removeView(editText)
|
||||
onAddEditTextToDialogView(view, editText)
|
||||
}
|
||||
}
|
||||
|
||||
override fun needInputMethod(): Boolean = true
|
||||
|
||||
protected fun onAddEditTextToDialogView(dialogView: View, editText: EditText) {
|
||||
val oldEditText = dialogView.findViewById<View>(android.R.id.edit)
|
||||
if (oldEditText != null) {
|
||||
val container = oldEditText.parent as? ViewGroup?
|
||||
if (container != null) {
|
||||
container.removeView(oldEditText)
|
||||
container.addView(editText, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDialogClosed(positiveResult: Boolean) {
|
||||
if (positiveResult) {
|
||||
val value = this.editText.text.toString()
|
||||
if (this.editTextPreference.callChangeListener(value)) {
|
||||
this.editTextPreference.text = value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package be.mygod.vpnhotspot.preference
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.support.v7.preference.PreferenceDataStore
|
||||
|
||||
class SharedPreferenceDataStore(private val pref: SharedPreferences) : PreferenceDataStore() {
|
||||
override fun getBoolean(key: String?, defValue: Boolean) = pref.getBoolean(key, defValue)
|
||||
override fun getFloat(key: String?, defValue: Float) = pref.getFloat(key, defValue)
|
||||
override fun getInt(key: String?, defValue: Int) = pref.getInt(key, defValue)
|
||||
override fun getLong(key: String?, defValue: Long) = pref.getLong(key, defValue)
|
||||
override fun getString(key: String?, defValue: String?): String? = pref.getString(key, defValue)
|
||||
override fun getStringSet(key: String?, defValue: MutableSet<String>?): MutableSet<String>? =
|
||||
pref.getStringSet(key, defValue)
|
||||
override fun putBoolean(key: String?, value: Boolean) = pref.edit().putBoolean(key, value).apply()
|
||||
override fun putFloat(key: String?, value: Float) = pref.edit().putFloat(key, value).apply()
|
||||
override fun putInt(key: String?, value: Int) = pref.edit().putInt(key, value).apply()
|
||||
override fun putLong(key: String?, value: Long) = pref.edit().putLong(key, value).apply()
|
||||
override fun putString(key: String?, value: String?) = pref.edit().putString(key, value).apply()
|
||||
override fun putStringSet(key: String?, value: MutableSet<String>?) = pref.edit().putStringSet(key, value).apply()
|
||||
}
|
||||
Reference in New Issue
Block a user