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