diff --git a/app/src/main/java/com/keylesspalace/tusky/components/filters/EditFilterActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/filters/EditFilterActivity.kt
index 66407394..2ef7902c 100644
--- a/app/src/main/java/com/keylesspalace/tusky/components/filters/EditFilterActivity.kt
+++ b/app/src/main/java/com/keylesspalace/tusky/components/filters/EditFilterActivity.kt
@@ -11,6 +11,7 @@ import androidx.core.content.IntentCompat
import androidx.core.view.size
import androidx.core.widget.doAfterTextChanged
import androidx.lifecycle.lifecycleScope
+import at.connyduck.calladapter.networkresult.fold
import com.google.android.material.chip.Chip
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.switchmaterial.SwitchMaterial
@@ -24,7 +25,9 @@ import com.keylesspalace.tusky.entity.Filter
import com.keylesspalace.tusky.entity.FilterKeyword
import com.keylesspalace.tusky.network.MastodonApi
import com.keylesspalace.tusky.util.viewBinding
+import com.keylesspalace.tusky.util.visible
import kotlinx.coroutines.launch
+import retrofit2.HttpException
import java.util.Date
import javax.inject.Inject
@@ -78,6 +81,9 @@ class EditFilterActivity : BaseActivity() {
binding.actionChip.setOnClickListener { showAddKeywordDialog() }
binding.filterSaveButton.setOnClickListener { saveChanges() }
+ binding.filterDeleteButton.setOnClickListener { deleteFilter() }
+ binding.filterDeleteButton.visible(originalFilter != null)
+
for (switch in contextSwitches.keys) {
switch.setOnCheckedChangeListener { _, isChecked ->
val context = contextSwitches[switch]!!
@@ -259,6 +265,32 @@ class EditFilterActivity : BaseActivity() {
}
}
+ private fun deleteFilter() {
+ originalFilter?.let { filter ->
+ lifecycleScope.launch {
+ api.deleteFilter(filter.id).fold(
+ {
+ finish()
+ },
+ { throwable ->
+ if (throwable is HttpException && throwable.code() == 404) {
+ api.deleteFilterV1(filter.id).fold(
+ {
+ finish()
+ },
+ {
+ Snackbar.make(binding.root, "Error deleting filter '${filter.title}'", Snackbar.LENGTH_SHORT).show()
+ }
+ )
+ } else {
+ Snackbar.make(binding.root, "Error deleting filter '${filter.title}'", Snackbar.LENGTH_SHORT).show()
+ }
+ }
+ )
+ }
+ }
+ }
+
companion object {
const val FILTER_TO_EDIT = "FilterToEdit"
diff --git a/app/src/main/res/layout/activity_edit_filter.xml b/app/src/main/res/layout/activity_edit_filter.xml
index 3aa8e7e4..755aab5a 100644
--- a/app/src/main/res/layout/activity_edit_filter.xml
+++ b/app/src/main/res/layout/activity_edit_filter.xml
@@ -144,14 +144,30 @@
android:minHeight="48dp"
android:text="@string/pref_title_account_filter_keywords" />
-
+ android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+ android:gravity="end"
+ style="?android:attr/buttonBarStyle">
+
+
+
+
+
+