Skip to content

Instantly share code, notes, and snippets.

@Pooh3Mobi
Last active December 23, 2017 10:50
Show Gist options
  • Save Pooh3Mobi/40f369265136d3c0b4129d959113e33c to your computer and use it in GitHub Desktop.
Save Pooh3Mobi/40f369265136d3c0b4129d959113e33c to your computer and use it in GitHub Desktop.
List -> itr -> toList -> subscribe -> recyclerview.adapter = adapter
class TpcsFgmt : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val sLoadingVisible = RxView.visibility(loadingTextView, View.INVISIBLE)
val sRVVisible = RxView.visibility(list, View.INVISIBLE)
val sIsLoading = BehaviorSubject.createDefault(false)
sIsLoading.observeOn(AndroidSchedulers.mainThread()).subscribe { loading ->
sLoadingVisible.accept(loading)
sRVVisible.accept(!loading)
}
Zaif.client.currencyPairObs()
.doOnSubscribe { sIsLoading.onNext(true) }
.doAfterTerminate{ sIsLoading.onNext(false) }
.flatMapIterable { data -> data }
.map { item -> convertTpcItem(item) }
.toList()
.observeOn(AndroidSchedulers.mainThread())
.subscribe { items ->
list.layoutManager = LMng(view.context)
list.adapter = TpcsAdptr(
items,
createVH = { vg -> vg.createVH(R.layout.vh_tpc, sIntrvl, sRng) },
bindVH = { tpc, vh ->
vh.ttl.text = tpc.ttl
vh.dtil.text = tpc.dtil
vh.item = tpc
},
itemCnt = { cchdItems -> cchdItems.size }
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment