Merge pull request #1286 from Xefir/1006

Backport #1006 New filter dialog gets closed if advanced dialog is edited before filter text
This commit is contained in:
Tlaster 2020-04-28 13:36:34 +08:00 committed by GitHub
commit f332fe71e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 17 deletions

View File

@ -3,6 +3,7 @@ package org.mariotaku.twidere.extension
import android.app.Dialog
import android.content.DialogInterface.*
import android.content.res.ColorStateList
import android.widget.Button
import androidx.annotation.StringRes
import androidx.appcompat.app.AlertDialog
import org.mariotaku.chameleon.Chameleon
@ -54,4 +55,7 @@ fun <T : Dialog> T.onShow(action: (dialog: T) -> Unit) {
@Suppress("UNCHECKED_CAST")
action(dialog as T)
}
}
}
inline val AlertDialog.positiveButton: Button get() = getButton(BUTTON_POSITIVE)
inline val AlertDialog.negativeButton: Button get() = getButton(BUTTON_NEGATIVE)

View File

@ -22,7 +22,6 @@ package org.mariotaku.twidere.fragment.filter
import android.accounts.AccountManager
import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.net.Uri
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
@ -50,7 +49,7 @@ import org.mariotaku.twidere.model.util.AccountUtils
import org.mariotaku.twidere.provider.TwidereDataStore.Filters
import org.mariotaku.twidere.util.premium.ExtraFeaturesService
class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListener {
class AddEditItemFragment : BaseDialogFragment() {
private val contentUri: Uri
get() = arguments?.getParcelable(EXTRA_URI)!!
@ -99,20 +98,19 @@ class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListene
advancedCollapseIndicator.rotation = if (value) 90f else 0f
}
override fun onClick(dialog: DialogInterface, which: Int) {
dialog as AlertDialog
when (which) {
DialogInterface.BUTTON_POSITIVE -> {
val scope = dialog.scopes ?: return
if (!canEditValue) {
saveScopeOnly(scope)
} else {
val value = dialog.value ?: return
saveItem(value, scope)
}
private fun handlePositiveClick(button: View) {
val scope = dialog?.scopes ?: return
if (!canEditValue) {
saveScopeOnly(scope)
} else {
val value = dialog!!.value?.takeIf(String::isNotEmpty)
if (value == null) {
dialog!!.editText.error = getString(R.string.hint_error_field_required)
return
}
saveItem(value, scope)
}
dismiss()
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
@ -124,8 +122,8 @@ class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListene
} else {
builder.setTitle(R.string.action_add_filter_rule)
}
builder.setPositiveButton(android.R.string.ok, this)
builder.setNegativeButton(android.R.string.cancel, this)
builder.setPositiveButton(android.R.string.ok, null)
builder.setNegativeButton(android.R.string.cancel, null)
val dialog = builder.create()
dialog.applyOnShow {
applyTheme()
@ -143,6 +141,7 @@ class AddEditItemFragment : BaseDialogFragment(), DialogInterface.OnClickListene
advancedToggle.setOnClickListener {
advancedExpanded = !advancedExpanded
}
positiveButton.setOnClickListener(this@AddEditItemFragment::handlePositiveClick)
advancedContainer.children.filter { it is CheckBox }.forEach {
val checkBox = it as CheckBox
checkBox.setOnClickListener onClick@ {