This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
repositories { | |
jcenter() | |
} | |
configurations { | |
ktlint | |
} | |
dependencies { | |
ktlint "com.pinterest:ktlint:0.33.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val cacheObservable:Observable<Data> = cacheSourceObservable | |
val remoteObservable:Observable<Data> = remoteSourceObservable.doOnNext { data -> | |
saveDataToCache(data) | |
} | |
val sourceObservable = Observable.concat( | |
cacheObservable.onErrorResumeNext(Function<Throwable, Observable<DriverStatsEntity>> { Observable.empty() /*ignore any errors from serving data from cache*/ }), | |
remoteObservable.onErrorResumeNext(Function<Throwable, Observable<DriverStatsEntity>> { throwable -> | |
if (!cache.hasCachedData()) Observable.error<Throwable>(throwable) /*show error from server since there is no data to be served*/ | |
Observable.empty() /*ignore any errors from remote server and continue serving data from cache*/ | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val cacheObservable:Observable<Data> = cacheSourceObservable | |
val remoteObservable:Observable<Data> = remoteSourceObservable.doOnNext { data -> | |
saveDataToCache(data) | |
} | |
val sourceObservable = Observable.concat(cacheObservable, remoteObservable) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val pattern = "###-##-#-####" | |
val count = pattern.length - pattern.replace("-", "").length | |
val patternsLength = mutableListOf<Int>() | |
var index = pattern.indexOf('-') | |
var length = pattern.substring(0,index).length | |
for(i in 0..count){ | |
patternsLength.add(length) | |
length = index+1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyReceiver extends BroadcastReceiver { | |
final String ACTION_MY_CALLBACK_ACTION = "..."; | |
final String EXTRA_PARAM_1 = "..."; | |
final String EXTRA_PARAM_2 = "..."; | |
public PendingIntent getPendingIntent(Context context, int value1, int value2) { | |
Intent intent = new Intent(context, MyReceiver.class); | |
intent.setaction(ACTION_MY_CALLBACK_ACTION); | |
intent.putExtra(EXTRA_PARAM_1, value1); | |
intent.putExtra(EXTRA_PARAM_2, value2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class CompletableUseCase<in Params> constructor( | |
private val postExecutionThread: PostExecutionThread) { | |
private val disposables = CompositeDisposable() | |
protected abstract fun buildUseCaseCompletable(params: Params? = null): Completable | |
open fun execute(observer: DisposableCompletableObserver, params: Params? = null) { | |
val completable = this.buildUseCaseCompletable(params) | |
.subscribeOn(Schedulers.io()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class CompletableUseCase<in Params> constructor( | |
private val postExecutionThread: PostExecutionThread) { | |
private val disposables = CompositeDisposable() | |
protected abstract fun buildUseCaseCompletable(params: Params? = null): Completable | |
open fun execute(observer: DisposableCompletableObserver, params: Params? = null) { | |
val completable = this.buildUseCaseCompletable(params) | |
.subscribeOn(Schedulers.io()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class CompletableUseCase<in Params> constructor( | |
private val postExecutionThread: PostExecutionThread) { | |
private val disposables = CompositeDisposable() | |
protected abstract fun buildUseCaseCompletable(params: Params? = null): Completable | |
open fun execute(observer: DisposableCompletableObserver, params: Params? = null) { | |
val completable = this.buildUseCaseCompletable(params) | |
.subscribeOn(Schedulers.io()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class CompletableUseCase<in Params> constructor( | |
private val postExecutionThread: PostExecutionThread) { | |
private val disposables = CompositeDisposable() | |
protected abstract fun buildUseCaseCompletable(params: Params? = null): Completable | |
open fun execute(observer: DisposableCompletableObserver, params: Params? = null) { | |
val completable = this.buildUseCaseCompletable(params) | |
.subscribeOn(Schedulers.io()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class CompletableUseCase<in Params> constructor( | |
private val postExecutionThread: PostExecutionThread) { | |
private val disposables = CompositeDisposable() | |
protected abstract fun buildUseCaseCompletable(params: Params? = null): Completable | |
open fun execute(observer: DisposableCompletableObserver, params: Params? = null) { | |
val completable = this.buildUseCaseCompletable(params) | |
.subscribeOn(Schedulers.io()) |