Skip to content

Instantly share code, notes, and snippets.

View photizzo's full-sized avatar

Ememobong Akpanekpo photizzo

View GitHub Profile
repositories {
jcenter()
}
configurations {
ktlint
}
dependencies {
ktlint "com.pinterest:ktlint:0.33.0"
@photizzo
photizzo / gistB
Last active April 23, 2019 15:39
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*/
})
val cacheObservable:Observable<Data> = cacheSourceObservable
val remoteObservable:Observable<Data> = remoteSourceObservable.doOnNext { data ->
saveDataToCache(data)
}
val sourceObservable = Observable.concat(cacheObservable, remoteObservable)
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
@photizzo
photizzo / Remote Callbacks
Last active December 12, 2018 18:50
Remote callbacks provide a wrapper that makes it easier for developers to provide a PendingIntent. Generally those writing widgets, notifications, and more recently slices, have the fun of writing code that looks like this relatively frequently. The goal of Remote Callbacks is to remove as much of that fun as possible and let you get right down …
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);
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())
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())
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())
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())
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())