I'm trying to get started with RxJava2, RxScala and Android. I found a little example online which I tried to translate into Scala. But the Scala compiler can't figure out the type here:
MainIntent.scala:7:missing parameter type
[error] actions("Button").subscribe(s => mainModel.resetText())
I'm also not sure what type is expected here. A Flowable[_ <: Any]]
? How can I make it work?
This is the code:
import io.reactivex.functions.Consumer
import io.reactivex.Flowable
trait MainView {
def getActions: Map[String, Flowable[_ <: Any]]
def getConsumers: Map[String, Consumer[String]]
}
class MainIntent(mainView: MainView) {
lazy val actions: Map[String, Flowable[_ <: Any]] = mainView.getActions
lazy val mainModel = MainModel(mainView.getConsumers)
def start(): Unit = {
actions("Button").subscribe(s => mainModel.resetText())
actions("EditText").subscribe(changedText => mainModel.changeText(changedText.toString))
}
}
class MainActivity extends AppCompatActivity with MainView with TypedFindView {
...
override def onCreate(savedInstanceState: Bundle): Unit = {
...
new MainIntent(this).start()
}
def getActions(): Map[String, Flowable[_ <: Any]] = {
Map("Button" -> RxView.clicks(button).toFlowable(BackpressureStrategy.DROP),
"EditText" -> RxTextView.textChanges(editText).toFlowable(BackpressureStrategy.DROP))
}
...
}