@ NonNull private static Single < Boolean > checkPermissionUntilGranted ( final LocationServicesStatus locationServicesStatus , Scheduler timerScheduler ) { return Observable . interval ( 0 , 1L , TimeUnit . SECONDS , timerScheduler ) . takeWhile ( new Predicate < Long > ( ) { @ Override public boolean test ( Long timer ) { return ! locationServicesStatus . isLocationPermissionOk ( ) ; } } ) . count ( ) . map ( new Function < Long , Boolean > ( ) { @ Override public Boolean apply ( Long count ) { // if no elements were emitted then the permission was granted from the beginning return count == 0 ; } } ) ; }
Observable that emits true if the permission was granted on the time of subscription