|
@@ -1,40 +1,15 @@
|
|
package eu.kanade.tachiyomi.widget.materialdialogs
|
|
package eu.kanade.tachiyomi.widget.materialdialogs
|
|
|
|
|
|
import android.view.LayoutInflater
|
|
import android.view.LayoutInflater
|
|
-import android.view.inputmethod.InputMethodManager
|
|
|
|
-import android.widget.TextView
|
|
|
|
import androidx.annotation.StringRes
|
|
import androidx.annotation.StringRes
|
|
import androidx.appcompat.app.AlertDialog
|
|
import androidx.appcompat.app.AlertDialog
|
|
-import androidx.core.content.getSystemService
|
|
|
|
import androidx.core.view.isVisible
|
|
import androidx.core.view.isVisible
|
|
-import androidx.core.widget.doAfterTextChanged
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
import eu.kanade.tachiyomi.databinding.DialogStubQuadstatemultichoiceBinding
|
|
import eu.kanade.tachiyomi.databinding.DialogStubQuadstatemultichoiceBinding
|
|
-import eu.kanade.tachiyomi.databinding.DialogStubTextinputBinding
|
|
|
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
|
import kotlin.coroutines.resume
|
|
import kotlin.coroutines.resume
|
|
|
|
|
|
-fun MaterialAlertDialogBuilder.setTextInput(
|
|
|
|
- hint: String? = null,
|
|
|
|
- prefill: String? = null,
|
|
|
|
- onTextChanged: (String) -> Unit,
|
|
|
|
-): MaterialAlertDialogBuilder {
|
|
|
|
- val binding = DialogStubTextinputBinding.inflate(LayoutInflater.from(context))
|
|
|
|
- binding.textField.hint = hint
|
|
|
|
- binding.textField.editText?.apply {
|
|
|
|
- setText(prefill, TextView.BufferType.EDITABLE)
|
|
|
|
- doAfterTextChanged {
|
|
|
|
- onTextChanged(it?.toString() ?: "")
|
|
|
|
- }
|
|
|
|
- post {
|
|
|
|
- requestFocusFromTouch()
|
|
|
|
- context.getSystemService<InputMethodManager>()?.showSoftInput(this, 0)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return setView(binding.root)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Sets a list of items with checkboxes that supports 4 states.
|
|
* Sets a list of items with checkboxes that supports 4 states.
|
|
*
|
|
*
|
|
@@ -79,7 +54,7 @@ suspend fun MaterialAlertDialogBuilder.await(
|
|
@StringRes positiveLabelId: Int,
|
|
@StringRes positiveLabelId: Int,
|
|
@StringRes negativeLabelId: Int,
|
|
@StringRes negativeLabelId: Int,
|
|
@StringRes neutralLabelId: Int? = null,
|
|
@StringRes neutralLabelId: Int? = null,
|
|
-) = suspendCancellableCoroutine<Int> { cont ->
|
|
|
|
|
|
+) = suspendCancellableCoroutine { cont ->
|
|
setPositiveButton(positiveLabelId) { _, _ -> cont.resume(AlertDialog.BUTTON_POSITIVE) }
|
|
setPositiveButton(positiveLabelId) { _, _ -> cont.resume(AlertDialog.BUTTON_POSITIVE) }
|
|
setNegativeButton(negativeLabelId) { _, _ -> cont.resume(AlertDialog.BUTTON_NEGATIVE) }
|
|
setNegativeButton(negativeLabelId) { _, _ -> cont.resume(AlertDialog.BUTTON_NEGATIVE) }
|
|
if (neutralLabelId != null) {
|
|
if (neutralLabelId != null) {
|