RxJava .zip发出相同的值

时间:2018-03-23 18:53:09

标签: android rx-java rx-java2

我有一个代码:

 val touchDownSource = BehaviorSubject.create<MotionEvent>()
    val touchUpSource = BehaviorSubject.create<MotionEvent>()
    RxView.touches(binding.containerOverlay)
      .subscribe({ me ->
        when (me.action) {
          MotionEvent.ACTION_DOWN -> touchDownSource.onNext(me)
          MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> touchUpSource.onNext(me)
        }
      })

    val zipper = BiFunction<MotionEvent, MotionEvent, Pair<MotionEvent, MotionEvent>>({ v1, v2 -> v1 to v2 })
      Observable.zip(touchDownSource, touchUpSource , zipper)
      .filter { Math.abs(it.first.toPoint().length() - it.second.toPoint().length()) < 50 }
      .map { it.second.toPoint() }
      .subscribe({ Utils.toast(this, "${it.x}--${it.y}") }, ErrLogger::e)

我有2个BehaviourSubject并向他们发送MotionEvent&#39; s - ACTION_UPACTION_DOWN。然后我将主题压缩为ACTION_UPACTION_DOWN。但我的zipper双功能总是将2个相同的事件作为参数 - ACTION_UP具有相同的哈希码和坐标。

我做错了什么?

0 个答案:

没有答案
相关问题