Add delete button to edit filter activity. (#3553)
Adds workaround for #3545
This commit is contained in:
parent
66a394245b
commit
4cddd2c5e6
2 changed files with 55 additions and 7 deletions
|
@ -11,6 +11,7 @@ import androidx.core.content.IntentCompat
|
||||||
import androidx.core.view.size
|
import androidx.core.view.size
|
||||||
import androidx.core.widget.doAfterTextChanged
|
import androidx.core.widget.doAfterTextChanged
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import at.connyduck.calladapter.networkresult.fold
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import com.google.android.material.switchmaterial.SwitchMaterial
|
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.entity.FilterKeyword
|
||||||
import com.keylesspalace.tusky.network.MastodonApi
|
import com.keylesspalace.tusky.network.MastodonApi
|
||||||
import com.keylesspalace.tusky.util.viewBinding
|
import com.keylesspalace.tusky.util.viewBinding
|
||||||
|
import com.keylesspalace.tusky.util.visible
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import retrofit2.HttpException
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -78,6 +81,9 @@ class EditFilterActivity : BaseActivity() {
|
||||||
|
|
||||||
binding.actionChip.setOnClickListener { showAddKeywordDialog() }
|
binding.actionChip.setOnClickListener { showAddKeywordDialog() }
|
||||||
binding.filterSaveButton.setOnClickListener { saveChanges() }
|
binding.filterSaveButton.setOnClickListener { saveChanges() }
|
||||||
|
binding.filterDeleteButton.setOnClickListener { deleteFilter() }
|
||||||
|
binding.filterDeleteButton.visible(originalFilter != null)
|
||||||
|
|
||||||
for (switch in contextSwitches.keys) {
|
for (switch in contextSwitches.keys) {
|
||||||
switch.setOnCheckedChangeListener { _, isChecked ->
|
switch.setOnCheckedChangeListener { _, isChecked ->
|
||||||
val context = contextSwitches[switch]!!
|
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 {
|
companion object {
|
||||||
const val FILTER_TO_EDIT = "FilterToEdit"
|
const val FILTER_TO_EDIT = "FilterToEdit"
|
||||||
|
|
||||||
|
|
|
@ -144,14 +144,30 @@
|
||||||
android:minHeight="48dp"
|
android:minHeight="48dp"
|
||||||
android:text="@string/pref_title_account_filter_keywords" />
|
android:text="@string/pref_title_account_filter_keywords" />
|
||||||
|
|
||||||
<Button
|
<LinearLayout
|
||||||
android:id="@+id/filter_save_button"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_gravity="end"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="6dp"
|
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||||
android:layout_marginBottom="16dp"
|
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||||
android:text="@string/action_save" />
|
android:gravity="end"
|
||||||
|
style="?android:attr/buttonBarStyle">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/filter_delete_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/action_delete"
|
||||||
|
style="?android:attr/buttonBarButtonStyle" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/filter_save_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:text="@string/action_save"
|
||||||
|
style="?android:attr/buttonBarButtonStyle" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
|
|
Loading…
Reference in a new issue