Ad
Convert Single To Boolean (Kotlin)
I have a mutable live data which I use to adjust visibility(with binding adapter) in my layout. I use the boolean value of live data to achieve this with the code below.
@BindingAdapter("viewVisibility")
fun setVisibility(view: View, visible: Boolean) {
view.visibility = if (visible) View.VISIBLE else View.GONE
}
To get this data I use the following method
Flowable.just(
Sdk().searchContact(CHATBOT_NAME)).map {!(it.isEmpty()) }
it.isEmpty() gives me a Flowable < Single< Boolean>> instead of Flowable and I want to convert this Single to a boolean(to give it as a parameter to my binding adapter) but I could not find a way to convert it. My temporary (probably bad) solution is below.
it.blockingLast().isEmpty() // Blocking last gives me a list so I can get non-single boolean with isEmpty. Since I need one element from search contact method blocking last or first works same in this case.
Is this an acceptable solution? How can I convert Single to normal Boolean?
Ad
Answer
it's me again,try following code:
fun doesExist(): Flowable<Boolean> {
return Flowable.just(Single.just(Sdk().searchContact(CHATBOT_NAME)).map{ it.isEmpty()}).map {it.blockingGet() }
}
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad