mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-15 05:27:28 +01:00
Address coroutine scope leaks in custom views
This commit is contained in:
@@ -7,10 +7,6 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import eu.kanade.tachiyomi.databinding.DownloadCustomAmountBinding
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.widget.textChanges
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
@@ -35,8 +31,6 @@ class DialogCustomDownloadView @JvmOverloads constructor(context: Context, attrs
|
||||
*/
|
||||
private var max = 0
|
||||
|
||||
private val scope = MainScope()
|
||||
|
||||
private val binding: DownloadCustomAmountBinding
|
||||
|
||||
init {
|
||||
@@ -71,16 +65,16 @@ class DialogCustomDownloadView @JvmOverloads constructor(context: Context, attrs
|
||||
}
|
||||
|
||||
// When user inputs custom number set amount equal to input.
|
||||
binding.myNumber.textChanges()
|
||||
.onEach {
|
||||
binding.myNumber.addTextChangedListener(object : SimpleTextWatcher() {
|
||||
override fun onTextChanged(text: CharSequence, start: Int, before: Int, count: Int) {
|
||||
try {
|
||||
amount = getAmount(Integer.parseInt(it.toString()))
|
||||
amount = getAmount(text.toString().toInt())
|
||||
} catch (error: NumberFormatException) {
|
||||
// Catch NumberFormatException to prevent parse exception when input is empty.
|
||||
Timber.e(error)
|
||||
}
|
||||
}
|
||||
.launchIn(scope)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package eu.kanade.tachiyomi.widget
|
||||
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
|
||||
open class SimpleTextWatcher : TextWatcher {
|
||||
override fun beforeTextChanged(text: CharSequence, start: Int, count: Int, after: Int) {
|
||||
}
|
||||
|
||||
override fun onTextChanged(text: CharSequence, start: Int, before: Int, count: Int) {
|
||||
}
|
||||
|
||||
override fun afterTextChanged(text: Editable) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user