0

I am having a list of images which i wanted to download.So below is the code which i used:

Observable.fromIterable(imagelist).subscribeOn(Scheduler.io). subscribe {
//download logic
}.addtodisposible(compositedisposible)

Initially, all downloaded images are saved into folder A. Now I have written a condition inside this iteration. if that condition satisfies, it should break the loop and call the same function again with only remaining items that are left to be iterated/downloaded and store it in folder B. Note:-1-> I tried to use takeuntil and added a Boolean value which i turn true if that condition satisfies.but iteration doesn't stop. 2-> if i clear composite disposible, the iteration stops and iteration with new items also begins, but iterates only few items.

Please help. Thank you.

Allan Antony
  • 21
  • 1
  • 5
  • I don't understand the requirement: call with remaining items <- that's just continuing the loop. – akarnokd Sep 28 '22 at 05:44
  • Sorry , my mistake. I forgot to mention. I download the images into a folder A. After condition satifies , it should break the loop and the remaining images should be downloaded into folder B. – Allan Antony Sep 28 '22 at 06:21

1 Answers1

0

Sounds like you need a phase change in your subscribe's onNext call since you have to process the full imagelist either way. Just have an external variable that remembers which phase are you in and do an if in the onNext call:

var phase = AtomicBoolean();

Observable.fromIterable(imagelist)
.subscribeOn(Scheduler.io)
.subscribe {
    if (!phase.get()) {
        // download to folder A
        // process the image here
        // then make a decision if it is time to switch
        if (someCondition) {
            phase.set(true)
        }
    } else {
        // download to folder B
    }
}.addtodisposible(compositedisposible)
akarnokd
  • 69,132
  • 14
  • 157
  • 192
  • I will try implementing the same. Thanks for the reply. Really appreciate it. I have been stuck on this issue for past how many days i don't remember. – Allan Antony Sep 30 '22 at 04:55