Skip to content

Instantly share code, notes, and snippets.

@AndSky90
Created November 4, 2019 11:59
Show Gist options
  • Save AndSky90/b998efdaf9cbe23decf58022bc135e34 to your computer and use it in GitHub Desktop.
Save AndSky90/b998efdaf9cbe23decf58022bc135e34 to your computer and use it in GitHub Desktop.
CompositeDisposable
private val compositeDisposable = CompositeDisposable()
private val photoChangeState: Subject<Boolean> = PublishSubject.create()
private var isPhotoChanged: Boolean = false
set(value) {
field = value
photoChangeState.onNext(value)
}
//---------
compositeDisposable.add(Observable.combineLatest(
/**устанавливаем листенеры полей*/
surnameForm.getValidatingObservable(),
nameForm.getValidatingObservable(),
patronymicForm.getValidatingObservable(),
photoChangeState,
Function4<Boolean, Boolean, Boolean, Boolean, Boolean> { nameIsPass, surnameIsPass, patronymicIsPass, photoChanged ->
/**активируем кнопку, если поля ФИО нормальные и поменялось ФИО или фото*/
nameIsPass && surnameIsPass && patronymicIsPass &&
(surnameForm.text != data.user!!.surname.orEmpty()
|| nameForm.text != data.user!!.name.orEmpty()
|| patronymicForm.text != data.user!!.patronymic.orEmpty()
|| photoChanged)
}).subscribe { setSaveButtonState(it) })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment