More rxbindings migration

This commit is contained in:
arkon 2020-04-17 09:28:26 -04:00
parent 29776c739a
commit f7b3450d65
3 changed files with 15 additions and 27 deletions

View File

@ -232,7 +232,6 @@ dependencies {
// RxBindings // RxBindings
final rxbindings_version = '1.0.1' final rxbindings_version = '1.0.1'
implementation "com.jakewharton.rxbinding:rxbinding-appcompat-v7-kotlin:$rxbindings_version"
implementation "com.jakewharton.rxbinding:rxbinding-support-v4-kotlin:$rxbindings_version" implementation "com.jakewharton.rxbinding:rxbinding-support-v4-kotlin:$rxbindings_version"
// FlowBinding // FlowBinding

View File

@ -102,7 +102,7 @@ class TrackSearchDialog : DialogController {
override fun onAttach(view: View) { override fun onAttach(view: View) {
super.onAttach(view) super.onAttach(view)
dialogView!!.track_search.textChanges(false) dialogView!!.track_search.textChanges()
.debounce(TimeUnit.SECONDS.toMillis(1)) .debounce(TimeUnit.SECONDS.toMillis(1))
.map { it.toString() } .map { it.toString() }
.filter { it.isNotBlank() } .filter { it.isNotBlank() }

View File

@ -16,7 +16,6 @@ import androidx.recyclerview.widget.RecyclerView
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.f2prateek.rx.preferences.Preference import com.f2prateek.rx.preferences.Preference
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import com.jakewharton.rxbinding.support.v7.widget.queryTextChangeEvents
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.IFlexible import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -41,10 +40,14 @@ import eu.kanade.tachiyomi.util.view.snack
import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.util.view.visible
import eu.kanade.tachiyomi.widget.AutofitRecyclerView import eu.kanade.tachiyomi.widget.AutofitRecyclerView
import eu.kanade.tachiyomi.widget.EmptyView import eu.kanade.tachiyomi.widget.EmptyView
import java.util.concurrent.TimeUnit import kotlinx.coroutines.CoroutineScope
import rx.Observable import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import reactivecircus.flowbinding.appcompat.QueryTextEvent
import reactivecircus.flowbinding.appcompat.queryTextEvents
import rx.Subscription import rx.Subscription
import rx.android.schedulers.AndroidSchedulers
import timber.log.Timber import timber.log.Timber
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
@ -84,11 +87,6 @@ open class BrowseSourceController(bundle: Bundle) :
*/ */
private var recycler: RecyclerView? = null private var recycler: RecyclerView? = null
/**
* Subscription for the search view.
*/
private var searchViewSubscription: Subscription? = null
/** /**
* Subscription for the number of manga per row. * Subscription for the number of manga per row.
*/ */
@ -99,6 +97,8 @@ open class BrowseSourceController(bundle: Bundle) :
*/ */
private var progressItem: ProgressItem? = null private var progressItem: ProgressItem? = null
private val uiScope = CoroutineScope(Dispatchers.Main)
private lateinit var binding: SourceControllerBinding private lateinit var binding: SourceControllerBinding
init { init {
@ -160,8 +160,6 @@ open class BrowseSourceController(bundle: Bundle) :
override fun onDestroyView(view: View) { override fun onDestroyView(view: View) {
numColumnsSubscription?.unsubscribe() numColumnsSubscription?.unsubscribe()
numColumnsSubscription = null numColumnsSubscription = null
searchViewSubscription?.unsubscribe()
searchViewSubscription = null
adapter = null adapter = null
snack = null snack = null
recycler = null recycler = null
@ -244,20 +242,11 @@ open class BrowseSourceController(bundle: Bundle) :
searchView.clearFocus() searchView.clearFocus()
} }
val searchEventsObservable = searchView.queryTextChangeEvents() searchView.queryTextEvents()
.skip(1) .filter { router.backstack.lastOrNull()?.controller() == this@BrowseSourceController }
.filter { router.backstack.lastOrNull()?.controller() == this@BrowseSourceController } .filter { it is QueryTextEvent.QuerySubmitted }
.share() .onEach { searchWithQuery(it.queryText.toString()) }
val writingObservable = searchEventsObservable .launchIn(uiScope)
.filter { !it.isSubmitted }
.debounce(1250, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
val submitObservable = searchEventsObservable
.filter { it.isSubmitted }
searchViewSubscription?.unsubscribe()
searchViewSubscription = Observable.merge(writingObservable, submitObservable)
.map { it.queryText().toString() }
.subscribeUntilDestroy { searchWithQuery(it) }
searchItem.fixExpand( searchItem.fixExpand(
onExpand = { invalidateMenuOnExpand() }, onExpand = { invalidateMenuOnExpand() },