Here is the code
private fun setUpDistrictSpinner() {
commonRepo.getAllDistricts()
.observeOn(AndroidSchedulers.mainThread())
.flatMap { list -> Flowable.fromIterable(list) }
.map { district ->
districtNameList.add(district.district_name)
district
}.subscribe(object:Subscriber<District>{
override fun onComplete() {
labSelectionInterface.loadDistricts(districtNameList)
Timber.d("district List loaded total " + districtList.size)
}
override fun onError(t: Throwable?) {
t!!.printStackTrace()
}
override fun onNext(t: District) {
districtList.add(t)
}
override fun onSubscribe(s: Subscription) {
s.request(Long.MAX_VALUE)
}
})
}
onNext is firing but onComplete will not fire. There is also no error message. I am loading list of district into a spinner. Using Room database and Kotlin This is where I get the Flowable
fun getAllDistricts(): Flowable<List<District>> {
Timber.d("District list accessed")
return appDatabase.districtDao().getAllDistricts()
.subscribeOn(Schedulers.io())
}