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
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"
// FlowBinding

View file

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

View file

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