When you open the application, the repository returns Observable :

  fun role(): Observable<Triple<Role, Boolean, List<Int>>> { return repository .data() .map { val bgList = it.directions .flatMap { it.departments } .flatMap { it.businessGroups } when { bgList.size > 1 -> Role.MANAGER it.directions.isNotEmpty() -> Role.RBG it.directions.isEmpty() -> Role.NOT_RBG else -> Role.NOT_RBG } } .map { val requireBg = (it == Role.MANAGER && preferences.bgSelect.get() == null) Triple(it, requireBg, tabs()) } } 

But if the role changes in the settings, the data coming from the server changes and you have to force this sequence to be called again.

I created a class:

 class BgChange @Inject constructor() { val change: Subject<Any> = PublishSubject.create() fun isBgChange(): Observable<Any> = change } 

When I click on the button in the settings, onNext is onNext : bgChange.change.onNext(Any()) Now, as I understand it, I need to add this signal to my sequence using the flatMap operator so that when I call onNext Observable re-emit data. All attempts failed. Explain how this can be done?

  • oh well, and chain ... you need to make a flatMap {role ()} in the change subscription, at the moment change.onNext () the subscription is cut and your role () is called, you can remove the implementation with role () just for example fun role () = repository.data () so as not to scare anyone who wants to paint you an answer with rxSubject - Shwarz Andrei

1 answer 1

solved the problem with the switchMap operator:

 .switchMap { triple -> bgChange.isBgChange() .map { triple } .startWith(triple) }