Add the 'whole word' setting to the filter preferences UI (#1278)
This commit is contained in:
parent
f19aa22bf1
commit
46efdf7830
3 changed files with 29 additions and 5 deletions
|
@ -83,8 +83,8 @@ class FiltersActivity: BaseActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun createFilter(phrase: String) {
|
||||
api.createFilter(phrase, listOf(context), false, true, "").enqueue(object: Callback<Filter> {
|
||||
private fun createFilter(phrase: String, wholeWord: Boolean) {
|
||||
api.createFilter(phrase, listOf(context), false, wholeWord, "").enqueue(object: Callback<Filter> {
|
||||
override fun onResponse(call: Call<Filter>, response: Response<Filter>) {
|
||||
filters.add(response.body()!!)
|
||||
refreshFilterDisplay()
|
||||
|
@ -102,11 +102,12 @@ class FiltersActivity: BaseActivity() {
|
|||
.setTitle(R.string.filter_addition_dialog_title)
|
||||
.setView(R.layout.dialog_filter)
|
||||
.setPositiveButton(android.R.string.ok){ _, _ ->
|
||||
createFilter(dialog.phraseEditText.text.toString())
|
||||
createFilter(dialog.phraseEditText.text.toString(), dialog.phraseWholeWord.isChecked)
|
||||
}
|
||||
.setNeutralButton(android.R.string.cancel, null)
|
||||
.create()
|
||||
dialog.show()
|
||||
dialog.phraseWholeWord.isChecked = true
|
||||
}
|
||||
|
||||
private fun setupEditDialogForItem(itemIndex: Int) {
|
||||
|
@ -116,7 +117,7 @@ class FiltersActivity: BaseActivity() {
|
|||
.setPositiveButton(R.string.filter_dialog_update_button) { _, _ ->
|
||||
val oldFilter = filters[itemIndex]
|
||||
val newFilter = Filter(oldFilter.id, dialog.phraseEditText.text.toString(), oldFilter.context,
|
||||
oldFilter.expiresAt, oldFilter.irreversible, oldFilter.wholeWord)
|
||||
oldFilter.expiresAt, oldFilter.irreversible, dialog.phraseWholeWord.isChecked)
|
||||
updateFilter(newFilter, itemIndex)
|
||||
}
|
||||
.setNegativeButton(R.string.filter_dialog_remove_button) { _, _ ->
|
||||
|
@ -127,7 +128,9 @@ class FiltersActivity: BaseActivity() {
|
|||
dialog.show()
|
||||
|
||||
// Need to show the dialog before referencing any elements from its view
|
||||
dialog.phraseEditText.setText(filters[itemIndex].phrase)
|
||||
val filter = filters[itemIndex]
|
||||
dialog.phraseEditText.setText(filter.phrase)
|
||||
dialog.phraseWholeWord.isChecked = filter.wholeWord
|
||||
}
|
||||
|
||||
private fun refreshFilterDisplay() {
|
||||
|
|
|
@ -15,4 +15,23 @@
|
|||
android:hint="@string/filter_add_description"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
/>
|
||||
<CheckBox
|
||||
android:id="@+id/phraseWholeWord"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingEnd="24dp"
|
||||
android:paddingStart="24dp"
|
||||
android:text="@string/filter_dialog_whole_word"
|
||||
app:layout_constraintTop_toBottomOf="@id/phraseEditText"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingStart="8dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/phraseWholeWord"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
android:text="@string/filter_dialog_whole_word_description"
|
||||
/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -323,6 +323,8 @@
|
|||
<string name="filter_edit_dialog_title">Edit filter</string>
|
||||
<string name="filter_dialog_remove_button">Remove</string>
|
||||
<string name="filter_dialog_update_button">Update</string>
|
||||
<string name="filter_dialog_whole_word">Whole word</string>
|
||||
<string name="filter_dialog_whole_word_description">When the keyword or phrase is alphanumeric only, it will only be applied if it matches the whole word</string>
|
||||
<string name="filter_add_description">Phrase to filter</string>
|
||||
|
||||
<string name="add_account_name">Add Account</string>
|
||||
|
|
Loading…
Reference in a new issue