|
|
|
@ -22,6 +22,7 @@ import androidx.preference.PreferenceFragmentCompat |
|
|
|
|
import android.text.Editable |
|
|
|
|
import android.text.TextWatcher |
|
|
|
|
import android.widget.EditText |
|
|
|
|
import androidx.preference.Preference |
|
|
|
|
import com.keylesspalace.tusky.R |
|
|
|
|
import java.util.regex.Pattern |
|
|
|
|
|
|
|
|
@ -34,47 +35,45 @@ class TabFilterPreferencesFragment : PreferenceFragmentCompat() { |
|
|
|
|
|
|
|
|
|
sharedPreferences = preferenceManager.sharedPreferences |
|
|
|
|
|
|
|
|
|
val regexPref = findPreference("tabFilterRegex") |
|
|
|
|
if (regexPref != null) { |
|
|
|
|
|
|
|
|
|
regexPref.summary = sharedPreferences.getString("tabFilterRegex", "") |
|
|
|
|
regexPref.setOnPreferenceClickListener { |
|
|
|
|
|
|
|
|
|
val editText = EditText(requireContext()) |
|
|
|
|
editText.setText(sharedPreferences.getString("tabFilterRegex", "")) |
|
|
|
|
|
|
|
|
|
val dialog = AlertDialog.Builder(requireContext()) |
|
|
|
|
.setTitle(R.string.pref_title_filter_regex) |
|
|
|
|
.setView(editText) |
|
|
|
|
.setPositiveButton(android.R.string.ok) { _, _ -> |
|
|
|
|
sharedPreferences |
|
|
|
|
.edit() |
|
|
|
|
.putString("tabFilterRegex", editText.text.toString()) |
|
|
|
|
.apply() |
|
|
|
|
regexPref.summary = editText.text.toString() |
|
|
|
|
} |
|
|
|
|
.setNegativeButton(android.R.string.cancel, null) |
|
|
|
|
.create() |
|
|
|
|
|
|
|
|
|
editText.addTextChangedListener(object : TextWatcher { |
|
|
|
|
override fun afterTextChanged(newRegex: Editable) { |
|
|
|
|
try { |
|
|
|
|
Pattern.compile(newRegex.toString()) |
|
|
|
|
editText.error = null |
|
|
|
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = true |
|
|
|
|
} catch (e: IllegalArgumentException) { |
|
|
|
|
editText.error = getString(R.string.error_invalid_regex) |
|
|
|
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = false |
|
|
|
|
} |
|
|
|
|
val regexPref: Preference = findPreference("tabFilterRegex") |
|
|
|
|
|
|
|
|
|
regexPref.summary = sharedPreferences.getString("tabFilterRegex", "") |
|
|
|
|
regexPref.setOnPreferenceClickListener { |
|
|
|
|
|
|
|
|
|
val editText = EditText(requireContext()) |
|
|
|
|
editText.setText(sharedPreferences.getString("tabFilterRegex", "")) |
|
|
|
|
|
|
|
|
|
val dialog = AlertDialog.Builder(requireContext()) |
|
|
|
|
.setTitle(R.string.pref_title_filter_regex) |
|
|
|
|
.setView(editText) |
|
|
|
|
.setPositiveButton(android.R.string.ok) { _, _ -> |
|
|
|
|
sharedPreferences |
|
|
|
|
.edit() |
|
|
|
|
.putString("tabFilterRegex", editText.text.toString()) |
|
|
|
|
.apply() |
|
|
|
|
regexPref.summary = editText.text.toString() |
|
|
|
|
} |
|
|
|
|
.setNegativeButton(android.R.string.cancel, null) |
|
|
|
|
.create() |
|
|
|
|
|
|
|
|
|
editText.addTextChangedListener(object : TextWatcher { |
|
|
|
|
override fun afterTextChanged(newRegex: Editable) { |
|
|
|
|
try { |
|
|
|
|
Pattern.compile(newRegex.toString()) |
|
|
|
|
editText.error = null |
|
|
|
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = true |
|
|
|
|
} catch (e: IllegalArgumentException) { |
|
|
|
|
editText.error = getString(R.string.error_invalid_regex) |
|
|
|
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun beforeTextChanged(s1: CharSequence, start: Int, count: Int, after: Int) {} |
|
|
|
|
override fun beforeTextChanged(s1: CharSequence, start: Int, count: Int, after: Int) {} |
|
|
|
|
|
|
|
|
|
override fun onTextChanged(s1: CharSequence, start: Int, before: Int, count: Int) {} |
|
|
|
|
}) |
|
|
|
|
dialog.show() |
|
|
|
|
true |
|
|
|
|
} |
|
|
|
|
override fun onTextChanged(s1: CharSequence, start: Int, before: Int, count: Int) {} |
|
|
|
|
}) |
|
|
|
|
dialog.show() |
|
|
|
|
true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|