mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-11-04 00:33:55 +01:00 
			
		
		
		
	Implemented retry with delay of 5000ms
This commit is contained in:
		
							parent
							
								
									a94e8b4b1a
								
							
						
					
					
						commit
						bc7ed146d9
					
				
					 1 changed files with 21 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -107,6 +107,7 @@ import io.reactivex.schedulers.Schedulers;
 | 
			
		|||
import java.io.File;
 | 
			
		||||
import java.io.FileOutputStream;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.io.InterruptedIOException;
 | 
			
		||||
import java.text.SimpleDateFormat;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
| 
						 | 
				
			
			@ -1263,6 +1264,16 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
 | 
			
		|||
        compositeDisposable.add(nearbyPlacesInfoObservable
 | 
			
		||||
            .subscribeOn(Schedulers.io())
 | 
			
		||||
            .observeOn(AndroidSchedulers.mainThread())
 | 
			
		||||
            .retryWhen(errors -> errors
 | 
			
		||||
                .zipWith(Observable.range(1, 4), (throwable, retryCount) -> {
 | 
			
		||||
                    if (throwable instanceof InterruptedIOException && retryCount < 4) {
 | 
			
		||||
                        Timber.d("Retry attempt %d due to %s", retryCount, throwable.getMessage());
 | 
			
		||||
                        return retryCount;
 | 
			
		||||
                    }
 | 
			
		||||
                    throw new Exception(throwable);
 | 
			
		||||
                })
 | 
			
		||||
                .flatMap(retryCount -> Observable.timer(5, TimeUnit.SECONDS))
 | 
			
		||||
            )
 | 
			
		||||
            .subscribe(nearbyPlacesInfo -> {
 | 
			
		||||
                    if (nearbyPlacesInfo.placeList == null || nearbyPlacesInfo.placeList.isEmpty()) {
 | 
			
		||||
                        showErrorMessage(getString(R.string.no_nearby_places_around));
 | 
			
		||||
| 
						 | 
				
			
			@ -1300,6 +1311,16 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
 | 
			
		|||
        compositeDisposable.add(nearbyPlacesInfoObservable
 | 
			
		||||
            .subscribeOn(Schedulers.io())
 | 
			
		||||
            .observeOn(AndroidSchedulers.mainThread())
 | 
			
		||||
            .retryWhen(errors -> errors
 | 
			
		||||
                .zipWith(Observable.range(1, 4), (throwable, retryCount) -> {
 | 
			
		||||
                    if (throwable instanceof InterruptedIOException && retryCount < 4) {
 | 
			
		||||
                        Timber.d("Retry attempt %d due to %s", retryCount, throwable.getMessage());
 | 
			
		||||
                        return retryCount;
 | 
			
		||||
                    }
 | 
			
		||||
                    throw new Exception(throwable);
 | 
			
		||||
                })
 | 
			
		||||
                .flatMap(retryCount -> Observable.timer(5, TimeUnit.SECONDS))
 | 
			
		||||
            )
 | 
			
		||||
            .subscribe(nearbyPlacesInfo -> {
 | 
			
		||||
                    if (nearbyPlacesInfo.placeList == null || nearbyPlacesInfo.placeList.isEmpty()) {
 | 
			
		||||
                        showErrorMessage(getString(R.string.no_nearby_places_around));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue