Compare commits
65 Commits
master
...
master-kot
| Author | SHA1 | Date |
|---|---|---|
|
|
fbc64cfb1f | |
|
|
ae81477a1d | |
|
|
44af99f9cf | |
|
|
8eaa50d891 | |
|
|
5805c63288 | |
|
|
a3dca51488 | |
|
|
426a213a44 | |
|
|
352ff5a8b4 | |
|
|
03689b5382 | |
|
|
e3c3c95767 | |
|
|
6a6ea0ec08 | |
|
|
43ad3d62d9 | |
|
|
3a3f416b8c | |
|
|
bab8ceb74f | |
|
|
d3191cd472 | |
|
|
6d0f74a972 | |
|
|
37f5664187 | |
|
|
46d00ffc5f | |
|
|
dc94030420 | |
|
|
527de35579 | |
|
|
dd2732c129 | |
|
|
6faabed582 | |
|
|
c9448639d5 | |
|
|
fda49db855 | |
|
|
99e1046907 | |
|
|
de52c32e98 | |
|
|
0a82b7a57c | |
|
|
ea35a1dc5d | |
|
|
3f8955f31b | |
|
|
64ae48ae39 | |
|
|
8405c76bf0 | |
|
|
97c9a7571b | |
|
|
ef7cf6d50d | |
|
|
70e6b99e79 | |
|
|
00d3433b87 | |
|
|
ffe587a8f5 | |
|
|
a517b16334 | |
|
|
c32eb4b835 | |
|
|
155ad932f6 | |
|
|
dfc7615187 | |
|
|
bb7473e839 | |
|
|
2398b4fc10 | |
|
|
6faf786ba4 | |
|
|
d3bcd89743 | |
|
|
540e573888 | |
|
|
06f9b1d2cc | |
|
|
9da0e059b5 | |
|
|
8953170dca | |
|
|
e9f7815ca3 | |
|
|
e23d9d55b0 | |
|
|
16624b3657 | |
|
|
660065490d | |
|
|
88113ef0ee | |
|
|
c57f30aca1 | |
|
|
e847fcedc5 | |
|
|
a2b69d64a1 | |
|
|
38f8a8018e | |
|
|
5d0847370d | |
|
|
d8ca0e610b | |
|
|
e2d584b5f7 | |
|
|
5f13aefa84 | |
|
|
949025a106 | |
|
|
a4a0e0d4b8 | |
|
|
68f7c73ff9 | |
|
|
fd68f1ffd4 |
15
build.gradle
15
build.gradle
|
|
@ -1,9 +1,7 @@
|
||||||
apply plugin: 'com.android.library'
|
apply plugin: 'com.android.library'
|
||||||
apply plugin: 'me.tatarka.retrolambda'
|
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 25
|
compileSdkVersion compileSdk
|
||||||
buildToolsVersion '25.0.3'
|
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
|
@ -16,11 +14,12 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(':libraries:core')
|
api project(':libraries:core')
|
||||||
|
|
||||||
provided 'com.android.support:appcompat-v7:25.4.0'
|
compileOnly "com.android.support:appcompat-v7:$supportLibraryVersion"
|
||||||
provided 'com.android.support:recyclerview-v7:25.4.0'
|
compileOnly "com.android.support:design:$supportLibraryVersion"
|
||||||
|
compileOnly "com.android.support:recyclerview-v7:$supportLibraryVersion"
|
||||||
|
|
||||||
provided 'io.reactivex:rxandroid:1.2.1'
|
compileOnly "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion"
|
||||||
provided 'io.reactivex:rxjava:1.3.0'
|
compileOnly "io.reactivex.rxjava2:rxjava:$rxJavaVersion"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,14 +22,15 @@ package ru.touchin.roboswag.components.adapters;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import io.reactivex.Completable;
|
||||||
|
import io.reactivex.Maybe;
|
||||||
|
import io.reactivex.Observable;
|
||||||
|
import io.reactivex.Single;
|
||||||
|
import io.reactivex.disposables.Disposable;
|
||||||
|
import io.reactivex.functions.Action;
|
||||||
|
import io.reactivex.functions.Consumer;
|
||||||
import ru.touchin.roboswag.components.utils.LifecycleBindable;
|
import ru.touchin.roboswag.components.utils.LifecycleBindable;
|
||||||
import ru.touchin.roboswag.components.utils.UiUtils;
|
import ru.touchin.roboswag.components.utils.UiUtils;
|
||||||
import rx.Completable;
|
|
||||||
import rx.Observable;
|
|
||||||
import rx.Single;
|
|
||||||
import rx.Subscription;
|
|
||||||
import rx.functions.Action0;
|
|
||||||
import rx.functions.Action1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Objects of such class controls creation and binding of specific type of RecyclerView's ViewHolders.
|
* Objects of such class controls creation and binding of specific type of RecyclerView's ViewHolders.
|
||||||
|
|
@ -82,140 +83,180 @@ public abstract class AdapterDelegate<TViewHolder extends BindableViewHolder> im
|
||||||
//CPD: it is same as in other implementation based on BaseLifecycleBindable
|
//CPD: it is same as in other implementation based on BaseLifecycleBindable
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable) {
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable) {
|
||||||
return parentLifecycleBindable.untilStop(observable);
|
return parentLifecycleBindable.untilStop(observable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable, @NonNull final Action1<T> onNextAction) {
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable, @NonNull final Consumer<T> onNextAction) {
|
||||||
return parentLifecycleBindable.untilStop(observable, onNextAction);
|
return parentLifecycleBindable.untilStop(observable, onNextAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable,
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return parentLifecycleBindable.untilStop(observable, onNextAction, onErrorAction);
|
return parentLifecycleBindable.untilStop(observable, onNextAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable,
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction,
|
@NonNull final Consumer<Throwable> onErrorAction,
|
||||||
@NonNull final Action0 onCompletedAction) {
|
@NonNull final Action onCompletedAction) {
|
||||||
return parentLifecycleBindable.untilStop(observable, onNextAction, onErrorAction, onCompletedAction);
|
return parentLifecycleBindable.untilStop(observable, onNextAction, onErrorAction, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single) {
|
public <T> Disposable untilStop(@NonNull final Single<T> single) {
|
||||||
return parentLifecycleBindable.untilStop(single);
|
return parentLifecycleBindable.untilStop(single);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
|
public <T> Disposable untilStop(@NonNull final Single<T> single, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
return parentLifecycleBindable.untilStop(single, onSuccessAction);
|
return parentLifecycleBindable.untilStop(single, onSuccessAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single,
|
public <T> Disposable untilStop(@NonNull final Single<T> single,
|
||||||
@NonNull final Action1<T> onSuccessAction,
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return parentLifecycleBindable.untilStop(single, onSuccessAction, onErrorAction);
|
return parentLifecycleBindable.untilStop(single, onSuccessAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilStop(@NonNull final Completable completable) {
|
public Disposable untilStop(@NonNull final Completable completable) {
|
||||||
return parentLifecycleBindable.untilStop(completable);
|
return parentLifecycleBindable.untilStop(completable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilStop(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
|
public Disposable untilStop(@NonNull final Completable completable, @NonNull final Action onCompletedAction) {
|
||||||
return parentLifecycleBindable.untilStop(completable, onCompletedAction);
|
return parentLifecycleBindable.untilStop(completable, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilStop(@NonNull final Completable completable,
|
public Disposable untilStop(@NonNull final Completable completable,
|
||||||
@NonNull final Action0 onCompletedAction,
|
@NonNull final Action onCompletedAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return parentLifecycleBindable.untilStop(completable, onCompletedAction, onErrorAction);
|
return parentLifecycleBindable.untilStop(completable, onCompletedAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable) {
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe) {
|
||||||
|
return parentLifecycleBindable.untilStop(maybe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
|
return parentLifecycleBindable.untilStop(maybe, onSuccessAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe,
|
||||||
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
|
return parentLifecycleBindable.untilStop(maybe, onSuccessAction, onErrorAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable) {
|
||||||
return parentLifecycleBindable.untilDestroy(observable);
|
return parentLifecycleBindable.untilDestroy(observable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable, @NonNull final Action1<T> onNextAction) {
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable, @NonNull final Consumer<T> onNextAction) {
|
||||||
return parentLifecycleBindable.untilDestroy(observable, onNextAction);
|
return parentLifecycleBindable.untilDestroy(observable, onNextAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable,
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return parentLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction);
|
return parentLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable,
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction,
|
@NonNull final Consumer<Throwable> onErrorAction,
|
||||||
@NonNull final Action0 onCompletedAction) {
|
@NonNull final Action onCompletedAction) {
|
||||||
return parentLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction, onCompletedAction);
|
return parentLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single) {
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single) {
|
||||||
return parentLifecycleBindable.untilDestroy(single);
|
return parentLifecycleBindable.untilDestroy(single);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
return parentLifecycleBindable.untilDestroy(single, onSuccessAction);
|
return parentLifecycleBindable.untilDestroy(single, onSuccessAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single,
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single,
|
||||||
@NonNull final Action1<T> onSuccessAction,
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return parentLifecycleBindable.untilDestroy(single, onSuccessAction, onErrorAction);
|
return parentLifecycleBindable.untilDestroy(single, onSuccessAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable) {
|
public Disposable untilDestroy(@NonNull final Completable completable) {
|
||||||
return parentLifecycleBindable.untilDestroy(completable);
|
return parentLifecycleBindable.untilDestroy(completable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
|
public Disposable untilDestroy(@NonNull final Completable completable, @NonNull final Action onCompletedAction) {
|
||||||
return parentLifecycleBindable.untilDestroy(completable, onCompletedAction);
|
return parentLifecycleBindable.untilDestroy(completable, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable,
|
public Disposable untilDestroy(@NonNull final Completable completable,
|
||||||
@NonNull final Action0 onCompletedAction,
|
@NonNull final Action onCompletedAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return parentLifecycleBindable.untilDestroy(completable, onCompletedAction, onErrorAction);
|
return parentLifecycleBindable.untilDestroy(completable, onCompletedAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe) {
|
||||||
|
return parentLifecycleBindable.untilDestroy(maybe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
|
return parentLifecycleBindable.untilDestroy(maybe, onSuccessAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe,
|
||||||
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
|
return parentLifecycleBindable.untilDestroy(maybe, onSuccessAction, onErrorAction);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,14 +31,15 @@ import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import io.reactivex.Completable;
|
||||||
|
import io.reactivex.Maybe;
|
||||||
|
import io.reactivex.Observable;
|
||||||
|
import io.reactivex.Single;
|
||||||
|
import io.reactivex.disposables.Disposable;
|
||||||
|
import io.reactivex.functions.Action;
|
||||||
|
import io.reactivex.functions.Consumer;
|
||||||
import ru.touchin.roboswag.components.utils.LifecycleBindable;
|
import ru.touchin.roboswag.components.utils.LifecycleBindable;
|
||||||
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
|
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
|
||||||
import rx.Completable;
|
|
||||||
import rx.Observable;
|
|
||||||
import rx.Single;
|
|
||||||
import rx.Subscription;
|
|
||||||
import rx.functions.Action0;
|
|
||||||
import rx.functions.Action1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gavriil Sitnikov on 12/8/2016.
|
* Created by Gavriil Sitnikov on 12/8/2016.
|
||||||
|
|
@ -122,142 +123,185 @@ public class BindableViewHolder extends RecyclerView.ViewHolder implements Lifec
|
||||||
return ContextCompat.getDrawable(itemView.getContext(), resId);
|
return ContextCompat.getDrawable(itemView.getContext(), resId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("CPD-START")
|
||||||
|
//CPD: it's ok as it's LifecycleBindable
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable) {
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable) {
|
||||||
return baseLifecycleBindable.untilStop(observable);
|
return baseLifecycleBindable.untilStop(observable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable, @NonNull final Action1<T> onNextAction) {
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable, @NonNull final Consumer<T> onNextAction) {
|
||||||
return baseLifecycleBindable.untilStop(observable, onNextAction);
|
return baseLifecycleBindable.untilStop(observable, onNextAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable,
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction);
|
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable,
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction,
|
@NonNull final Consumer<Throwable> onErrorAction,
|
||||||
@NonNull final Action0 onCompletedAction) {
|
@NonNull final Action onCompletedAction) {
|
||||||
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction, onCompletedAction);
|
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single) {
|
public <T> Disposable untilStop(@NonNull final Single<T> single) {
|
||||||
return baseLifecycleBindable.untilStop(single);
|
return baseLifecycleBindable.untilStop(single);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
|
public <T> Disposable untilStop(@NonNull final Single<T> single, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
return baseLifecycleBindable.untilStop(single, onSuccessAction);
|
return baseLifecycleBindable.untilStop(single, onSuccessAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single,
|
public <T> Disposable untilStop(@NonNull final Single<T> single,
|
||||||
@NonNull final Action1<T> onSuccessAction,
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilStop(single, onSuccessAction, onErrorAction);
|
return baseLifecycleBindable.untilStop(single, onSuccessAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilStop(@NonNull final Completable completable) {
|
public Disposable untilStop(@NonNull final Completable completable) {
|
||||||
return baseLifecycleBindable.untilStop(completable);
|
return baseLifecycleBindable.untilStop(completable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilStop(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
|
public Disposable untilStop(@NonNull final Completable completable, @NonNull final Action onCompletedAction) {
|
||||||
return baseLifecycleBindable.untilStop(completable, onCompletedAction);
|
return baseLifecycleBindable.untilStop(completable, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilStop(@NonNull final Completable completable,
|
public Disposable untilStop(@NonNull final Completable completable,
|
||||||
@NonNull final Action0 onCompletedAction,
|
@NonNull final Action onCompletedAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilStop(completable, onCompletedAction, onErrorAction);
|
return baseLifecycleBindable.untilStop(completable, onCompletedAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable) {
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe) {
|
||||||
|
return baseLifecycleBindable.untilStop(maybe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
|
return baseLifecycleBindable.untilStop(maybe, onSuccessAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe,
|
||||||
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
|
return baseLifecycleBindable.untilStop(maybe, onSuccessAction, onErrorAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable) {
|
||||||
return baseLifecycleBindable.untilDestroy(observable);
|
return baseLifecycleBindable.untilDestroy(observable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable, @NonNull final Action1<T> onNextAction) {
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable, @NonNull final Consumer<T> onNextAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(observable, onNextAction);
|
return baseLifecycleBindable.untilDestroy(observable, onNextAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable,
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction);
|
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable,
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction,
|
@NonNull final Consumer<Throwable> onErrorAction,
|
||||||
@NonNull final Action0 onCompletedAction) {
|
@NonNull final Action onCompletedAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction, onCompletedAction);
|
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single) {
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single) {
|
||||||
return baseLifecycleBindable.untilDestroy(single);
|
return baseLifecycleBindable.untilDestroy(single);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(single, onSuccessAction);
|
return baseLifecycleBindable.untilDestroy(single, onSuccessAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single,
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single,
|
||||||
@NonNull final Action1<T> onSuccessAction,
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(single, onSuccessAction, onErrorAction);
|
return baseLifecycleBindable.untilDestroy(single, onSuccessAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable) {
|
public Disposable untilDestroy(@NonNull final Completable completable) {
|
||||||
return baseLifecycleBindable.untilDestroy(completable);
|
return baseLifecycleBindable.untilDestroy(completable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
|
public Disposable untilDestroy(@NonNull final Completable completable, @NonNull final Action onCompletedAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction);
|
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable,
|
public Disposable untilDestroy(@NonNull final Completable completable,
|
||||||
@NonNull final Action0 onCompletedAction,
|
@NonNull final Action onCompletedAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction, onErrorAction);
|
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe) {
|
||||||
|
return baseLifecycleBindable.untilDestroy(maybe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
|
return baseLifecycleBindable.untilDestroy(maybe, onSuccessAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("CPD-END")
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe,
|
||||||
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
|
return baseLifecycleBindable.untilDestroy(maybe, onSuccessAction, onErrorAction);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ public abstract class ItemAdapterDelegate<TViewHolder extends BindableViewHolder
|
||||||
* This item will be casted to {@link TItem} and passes to {@link #onBindViewHolder(TViewHolder, TItem, int, int)}.
|
* This item will be casted to {@link TItem} and passes to {@link #onBindViewHolder(TViewHolder, TItem, int, int)}.
|
||||||
*
|
*
|
||||||
* @param item Item to check;
|
* @param item Item to check;
|
||||||
* @param positionInAdapter Position of item in adapter;
|
* @param positionInAdapter Position of item in adapter;
|
||||||
* @param itemCollectionPosition Position of item in collection that contains item;
|
* @param itemCollectionPosition Position of item in collection that contains item;
|
||||||
* @return True if item is processable by this delegate.
|
* @return True if item is processable by this delegate.
|
||||||
*/
|
*/
|
||||||
|
|
@ -35,8 +35,8 @@ public abstract class ItemAdapterDelegate<TViewHolder extends BindableViewHolder
|
||||||
/**
|
/**
|
||||||
* Returns unique ID of item to support stable ID's logic of RecyclerView's adapter.
|
* Returns unique ID of item to support stable ID's logic of RecyclerView's adapter.
|
||||||
*
|
*
|
||||||
* @param item Item to check;
|
* @param item Item to check;
|
||||||
* @param positionInAdapter Position of item in adapter;
|
* @param positionInAdapter Position of item in adapter;
|
||||||
* @param positionInCollection Position of item in collection that contains item;
|
* @param positionInCollection Position of item in collection that contains item;
|
||||||
* @return Unique item ID.
|
* @return Unique item ID.
|
||||||
*/
|
*/
|
||||||
|
|
@ -56,9 +56,9 @@ public abstract class ItemAdapterDelegate<TViewHolder extends BindableViewHolder
|
||||||
/**
|
/**
|
||||||
* Binds item to created by this object ViewHolder.
|
* Binds item to created by this object ViewHolder.
|
||||||
*
|
*
|
||||||
* @param holder ViewHolder to bind item to;
|
* @param holder ViewHolder to bind item to;
|
||||||
* @param item Item to check;
|
* @param item Item to check;
|
||||||
* @param positionInAdapter Position of item in adapter;
|
* @param positionInAdapter Position of item in adapter;
|
||||||
* @param positionInCollection Position of item in collection that contains item;
|
* @param positionInCollection Position of item in collection that contains item;
|
||||||
*/
|
*/
|
||||||
public abstract void onBindViewHolder(@NonNull final TViewHolder holder, @NonNull final TItem item,
|
public abstract void onBindViewHolder(@NonNull final TViewHolder holder, @NonNull final TItem item,
|
||||||
|
|
@ -67,10 +67,10 @@ public abstract class ItemAdapterDelegate<TViewHolder extends BindableViewHolder
|
||||||
/**
|
/**
|
||||||
* Binds item with payloads to created by this object ViewHolder.
|
* Binds item with payloads to created by this object ViewHolder.
|
||||||
*
|
*
|
||||||
* @param holder ViewHolder to bind item to;
|
* @param holder ViewHolder to bind item to;
|
||||||
* @param item Item to check;
|
* @param item Item to check;
|
||||||
* @param payloads Payloads;
|
* @param payloads Payloads;
|
||||||
* @param positionInAdapter Position of item in adapter;
|
* @param positionInAdapter Position of item in adapter;
|
||||||
* @param positionInCollection Position of item in collection that contains item;
|
* @param positionInCollection Position of item in collection that contains item;
|
||||||
*/
|
*/
|
||||||
public void onBindViewHolder(@NonNull final TViewHolder holder, @NonNull final TItem item, @NonNull final List<Object> payloads,
|
public void onBindViewHolder(@NonNull final TViewHolder holder, @NonNull final TItem item, @NonNull final List<Object> payloads,
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,10 @@ import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import io.reactivex.Observable;
|
||||||
|
import io.reactivex.functions.BiConsumer;
|
||||||
|
import io.reactivex.functions.Consumer;
|
||||||
|
import io.reactivex.subjects.BehaviorSubject;
|
||||||
import ru.touchin.roboswag.components.utils.LifecycleBindable;
|
import ru.touchin.roboswag.components.utils.LifecycleBindable;
|
||||||
import ru.touchin.roboswag.components.utils.UiUtils;
|
import ru.touchin.roboswag.components.utils.UiUtils;
|
||||||
import ru.touchin.roboswag.core.log.Lc;
|
import ru.touchin.roboswag.core.log.Lc;
|
||||||
|
|
@ -43,11 +47,6 @@ import ru.touchin.roboswag.core.observables.collections.changes.SameItemsPredica
|
||||||
import ru.touchin.roboswag.core.observables.collections.loadable.LoadingMoreList;
|
import ru.touchin.roboswag.core.observables.collections.loadable.LoadingMoreList;
|
||||||
import ru.touchin.roboswag.core.utils.Optional;
|
import ru.touchin.roboswag.core.utils.Optional;
|
||||||
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
|
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
|
||||||
import rx.Observable;
|
|
||||||
import rx.functions.Action1;
|
|
||||||
import rx.functions.Action2;
|
|
||||||
import rx.functions.Action3;
|
|
||||||
import rx.subjects.BehaviorSubject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gavriil Sitnikov on 20/11/2015.
|
* Created by Gavriil Sitnikov on 20/11/2015.
|
||||||
|
|
@ -79,7 +78,7 @@ public abstract class ObservableCollectionAdapter<TItem, TItemViewHolder extends
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final BehaviorSubject<Optional<ObservableCollection<TItem>>> observableCollectionSubject
|
private final BehaviorSubject<Optional<ObservableCollection<TItem>>> observableCollectionSubject
|
||||||
= BehaviorSubject.create(new Optional<>(null));
|
= BehaviorSubject.createDefault(new Optional<>(null));
|
||||||
@NonNull
|
@NonNull
|
||||||
private final BehaviorSubject<Boolean> moreAutoLoadingRequested = BehaviorSubject.create();
|
private final BehaviorSubject<Boolean> moreAutoLoadingRequested = BehaviorSubject.create();
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
@ -104,6 +103,11 @@ public abstract class ObservableCollectionAdapter<TItem, TItemViewHolder extends
|
||||||
lifecycleBindable.untilDestroy(observableCollectionSubject
|
lifecycleBindable.untilDestroy(observableCollectionSubject
|
||||||
.switchMap(optional -> {
|
.switchMap(optional -> {
|
||||||
final ObservableCollection<TItem> collection = optional.get();
|
final ObservableCollection<TItem> collection = optional.get();
|
||||||
|
if (collection instanceof ObservableList) {
|
||||||
|
innerCollection.setDiffUtilsSource((ObservableList<TItem>) collection);
|
||||||
|
} else {
|
||||||
|
innerCollection.setDiffUtilsSource(null);
|
||||||
|
}
|
||||||
return collection != null ? collection.observeItems() : Observable.just(Collections.emptyList());
|
return collection != null ? collection.observeItems() : Observable.just(Collections.emptyList());
|
||||||
}), innerCollection::set);
|
}), innerCollection::set);
|
||||||
lifecycleBindable.untilDestroy(createMoreAutoLoadingObservable());
|
lifecycleBindable.untilDestroy(createMoreAutoLoadingObservable());
|
||||||
|
|
@ -126,8 +130,9 @@ public abstract class ObservableCollectionAdapter<TItem, TItemViewHolder extends
|
||||||
final int size = collection.size();
|
final int size = collection.size();
|
||||||
return ((LoadingMoreList<?, ?, ?>) collection)
|
return ((LoadingMoreList<?, ?, ?>) collection)
|
||||||
.loadRange(size, size + PRE_LOADING_COUNT)
|
.loadRange(size, size + PRE_LOADING_COUNT)
|
||||||
.onErrorResumeNext(Observable.empty())
|
.onErrorReturnItem(new ArrayList<>())
|
||||||
.doOnCompleted(() -> moreAutoLoadingRequested.onNext(false));
|
.toObservable()
|
||||||
|
.doOnComplete(() -> moreAutoLoadingRequested.onNext(false));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -386,36 +391,49 @@ public abstract class ObservableCollectionAdapter<TItem, TItemViewHolder extends
|
||||||
public long getItemId(final int positionInAdapter) {
|
public long getItemId(final int positionInAdapter) {
|
||||||
final LongContainer result = new LongContainer();
|
final LongContainer result = new LongContainer();
|
||||||
tryDelegateAction(positionInAdapter,
|
tryDelegateAction(positionInAdapter,
|
||||||
(itemAdapterDelegate, item, positionInCollection) ->
|
(itemAdapterDelegate, positionInCollection) ->
|
||||||
result.value = itemAdapterDelegate.getItemId(item, positionInAdapter, positionInCollection),
|
result.value = itemAdapterDelegate.getItemId(innerCollection.get(positionInCollection),
|
||||||
|
positionInAdapter, positionInCollection),
|
||||||
positionAdapterDelegate -> result.value = positionAdapterDelegate.getItemId(positionInAdapter),
|
positionAdapterDelegate -> result.value = positionAdapterDelegate.getItemId(positionInAdapter),
|
||||||
(item, positionInCollection) -> result.value = super.getItemId(positionInAdapter));
|
(positionInCollection) -> result.value = super.getItemId(positionInAdapter));
|
||||||
return result.value;
|
return result.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("PMD.CyclomaticComplexity")
|
||||||
private void tryDelegateAction(final int positionInAdapter,
|
private void tryDelegateAction(final int positionInAdapter,
|
||||||
@NonNull final Action3<ItemAdapterDelegate, TItem, Integer> itemAdapterDelegateAction,
|
@NonNull final BiConsumer<ItemAdapterDelegate, Integer> itemAdapterDelegateAction,
|
||||||
@NonNull final Action1<PositionAdapterDelegate> positionAdapterDelegateAction,
|
@NonNull final Consumer<PositionAdapterDelegate> positionAdapterDelegateAction,
|
||||||
@NonNull final Action2<TItem, Integer> defaultAction) {
|
@NonNull final Consumer<Integer> defaultAction) {
|
||||||
final int viewType = getItemViewType(positionInAdapter);
|
final int viewType = getItemViewType(positionInAdapter);
|
||||||
final int positionInCollection = getItemPositionInCollection(positionInAdapter);
|
final int positionInCollection = getItemPositionInCollection(positionInAdapter);
|
||||||
final TItem item = positionInCollection >= 0 ? innerCollection.get(positionInCollection) : null;
|
|
||||||
for (final AdapterDelegate<?> delegate : delegates) {
|
for (final AdapterDelegate<?> delegate : delegates) {
|
||||||
if (delegate instanceof ItemAdapterDelegate) {
|
if (delegate instanceof ItemAdapterDelegate) {
|
||||||
if (item != null && viewType == delegate.getItemViewType()) {
|
if (positionInCollection >= 0 && viewType == delegate.getItemViewType()) {
|
||||||
itemAdapterDelegateAction.call((ItemAdapterDelegate) delegate, item, positionInCollection);
|
try {
|
||||||
|
itemAdapterDelegateAction.accept((ItemAdapterDelegate) delegate, positionInCollection);
|
||||||
|
} catch (final Exception exception) {
|
||||||
|
Lc.assertion(exception);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (delegate instanceof PositionAdapterDelegate) {
|
} else if (delegate instanceof PositionAdapterDelegate) {
|
||||||
if (viewType == delegate.getItemViewType()) {
|
if (viewType == delegate.getItemViewType()) {
|
||||||
positionAdapterDelegateAction.call((PositionAdapterDelegate) delegate);
|
try {
|
||||||
|
positionAdapterDelegateAction.accept((PositionAdapterDelegate) delegate);
|
||||||
|
} catch (final Exception exception) {
|
||||||
|
Lc.assertion(exception);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Lc.assertion("Delegate of type " + delegate.getClass());
|
Lc.assertion("Delegate of type " + delegate.getClass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defaultAction.call(item, positionInCollection);
|
try {
|
||||||
|
defaultAction.accept(positionInCollection);
|
||||||
|
} catch (final Exception exception) {
|
||||||
|
Lc.assertion(exception);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -439,14 +457,15 @@ public abstract class ObservableCollectionAdapter<TItem, TItemViewHolder extends
|
||||||
lastUpdatedChangeNumber = innerCollection.getChangesCount();
|
lastUpdatedChangeNumber = innerCollection.getChangesCount();
|
||||||
|
|
||||||
tryDelegateAction(positionInAdapter,
|
tryDelegateAction(positionInAdapter,
|
||||||
(itemAdapterDelegate, item, positionInCollection) -> {
|
(itemAdapterDelegate, positionInCollection) -> {
|
||||||
bindItemViewHolder(itemAdapterDelegate, holder, item, null, positionInAdapter, positionInCollection);
|
bindItemViewHolder(itemAdapterDelegate, holder, innerCollection.get(positionInCollection),
|
||||||
|
null, positionInAdapter, positionInCollection);
|
||||||
updateMoreAutoLoadingRequest(positionInCollection);
|
updateMoreAutoLoadingRequest(positionInCollection);
|
||||||
},
|
},
|
||||||
positionAdapterDelegate -> positionAdapterDelegate.onBindViewHolder(holder, positionInAdapter),
|
positionAdapterDelegate -> positionAdapterDelegate.onBindViewHolder(holder, positionInAdapter),
|
||||||
(item, positionInCollection) -> {
|
(positionInCollection) -> {
|
||||||
if (item != null) {
|
if (positionInCollection >= 0) {
|
||||||
bindItemViewHolder(null, holder, item, null, positionInAdapter, positionInCollection);
|
bindItemViewHolder(null, holder, innerCollection.get(positionInCollection), null, positionInAdapter, positionInCollection);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -455,14 +474,16 @@ public abstract class ObservableCollectionAdapter<TItem, TItemViewHolder extends
|
||||||
public void onBindViewHolder(@NonNull final BindableViewHolder holder, final int positionInAdapter, @NonNull final List<Object> payloads) {
|
public void onBindViewHolder(@NonNull final BindableViewHolder holder, final int positionInAdapter, @NonNull final List<Object> payloads) {
|
||||||
super.onBindViewHolder(holder, positionInAdapter, payloads);
|
super.onBindViewHolder(holder, positionInAdapter, payloads);
|
||||||
tryDelegateAction(positionInAdapter,
|
tryDelegateAction(positionInAdapter,
|
||||||
(itemAdapterDelegate, item, positionInCollection) -> {
|
(itemAdapterDelegate, positionInCollection) -> {
|
||||||
bindItemViewHolder(itemAdapterDelegate, holder, item, payloads, positionInAdapter, positionInCollection);
|
bindItemViewHolder(itemAdapterDelegate, holder, innerCollection.get(positionInCollection),
|
||||||
|
payloads, positionInAdapter, positionInCollection);
|
||||||
updateMoreAutoLoadingRequest(positionInCollection);
|
updateMoreAutoLoadingRequest(positionInCollection);
|
||||||
},
|
},
|
||||||
positionAdapterDelegate -> positionAdapterDelegate.onBindViewHolder(holder, positionInAdapter),
|
positionAdapterDelegate -> positionAdapterDelegate.onBindViewHolder(holder, positionInAdapter),
|
||||||
(item, positionInCollection) -> {
|
(positionInCollection) -> {
|
||||||
if (item != null) {
|
if (positionInCollection >= 0) {
|
||||||
bindItemViewHolder(null, holder, item, payloads, positionInAdapter, positionInCollection);
|
bindItemViewHolder(null, holder, innerCollection.get(positionInCollection),
|
||||||
|
payloads, positionInAdapter, positionInCollection);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -607,8 +628,8 @@ public abstract class ObservableCollectionAdapter<TItem, TItemViewHolder extends
|
||||||
/**
|
/**
|
||||||
* Enable diff utils algorithm in collection changes.
|
* Enable diff utils algorithm in collection changes.
|
||||||
*
|
*
|
||||||
* @param detectMoves The flag that determines whether the {@link Change.Moved} changes will be generated or not;
|
* @param detectMoves The flag that determines whether the {@link Change.Moved} changes will be generated or not;
|
||||||
* @param sameItemsPredicate Predicate for the determination of the same elements;
|
* @param sameItemsPredicate Predicate for the determination of the same elements;
|
||||||
* @param changePayloadProducer Function that calculate change payload when items the same but contents are different.
|
* @param changePayloadProducer Function that calculate change payload when items the same but contents are different.
|
||||||
*/
|
*/
|
||||||
public void enableDiffUtils(final boolean detectMoves,
|
public void enableDiffUtils(final boolean detectMoves,
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ public abstract class PositionAdapterDelegate<TViewHolder extends BindableViewHo
|
||||||
/**
|
/**
|
||||||
* Binds position to ViewHolder.
|
* Binds position to ViewHolder.
|
||||||
*
|
*
|
||||||
* @param holder ViewHolder to bind position to;
|
* @param holder ViewHolder to bind position to;
|
||||||
* @param positionInAdapter Position of item in adapter.
|
* @param positionInAdapter Position of item in adapter.
|
||||||
*/
|
*/
|
||||||
public abstract void onBindViewHolder(@NonNull final TViewHolder holder, final int positionInAdapter);
|
public abstract void onBindViewHolder(@NonNull final TViewHolder holder, final int positionInAdapter);
|
||||||
|
|
@ -58,8 +58,8 @@ public abstract class PositionAdapterDelegate<TViewHolder extends BindableViewHo
|
||||||
/**
|
/**
|
||||||
* Binds position with payloads to ViewHolder.
|
* Binds position with payloads to ViewHolder.
|
||||||
*
|
*
|
||||||
* @param holder ViewHolder to bind position to;
|
* @param holder ViewHolder to bind position to;
|
||||||
* @param payloads Payloads;
|
* @param payloads Payloads;
|
||||||
* @param positionInAdapter Position of item in adapter.
|
* @param positionInAdapter Position of item in adapter.
|
||||||
*/
|
*/
|
||||||
public void onBindViewHolder(@NonNull final TViewHolder holder, @NonNull final List<Object> payloads, final int positionInAdapter) {
|
public void onBindViewHolder(@NonNull final TViewHolder holder, @NonNull final List<Object> payloads, final int positionInAdapter) {
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,9 @@ import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
|
import io.reactivex.functions.BiFunction;
|
||||||
|
import io.reactivex.functions.Function;
|
||||||
import ru.touchin.roboswag.core.log.Lc;
|
import ru.touchin.roboswag.core.log.Lc;
|
||||||
import rx.functions.Func1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gavriil Sitnikov on 07/03/2016.
|
* Created by Gavriil Sitnikov on 07/03/2016.
|
||||||
|
|
@ -44,7 +45,7 @@ import rx.functions.Func1;
|
||||||
* If {@link #back()} method will be called then stack will go to previous fragment.
|
* If {@link #back()} method will be called then stack will go to previous fragment.
|
||||||
* Usually such logic using to set as top fragments from sidebar and show hamburger when some of them appeared;
|
* Usually such logic using to set as top fragments from sidebar and show hamburger when some of them appeared;
|
||||||
* 4) {@link #pushForResult} means to push fragment with target fragment. It is also adding {@link #WITH_TARGET_FRAGMENT_TAG_MARK} tag.
|
* 4) {@link #pushForResult} means to push fragment with target fragment. It is also adding {@link #WITH_TARGET_FRAGMENT_TAG_MARK} tag.
|
||||||
* Also if such up/back navigation logic is not OK then {@link #backTo(Func1)} method could be used with any condition to back to.
|
* Also if such up/back navigation logic is not OK then {@link #backTo(Function)} method could be used with any condition to back to.
|
||||||
* In that case in any stack-change method it is allowed to setup fragment transactions.
|
* In that case in any stack-change method it is allowed to setup fragment transactions.
|
||||||
*/
|
*/
|
||||||
public class FragmentNavigation {
|
public class FragmentNavigation {
|
||||||
|
|
@ -118,6 +119,7 @@ public class FragmentNavigation {
|
||||||
*
|
*
|
||||||
* @param fragmentClass Class of {@link Fragment} to instantiate;
|
* @param fragmentClass Class of {@link Fragment} to instantiate;
|
||||||
* @param targetFragment Target fragment to be set as {@link Fragment#getTargetFragment()} of instantiated {@link Fragment};
|
* @param targetFragment Target fragment to be set as {@link Fragment#getTargetFragment()} of instantiated {@link Fragment};
|
||||||
|
* @param addToStack Flag to add this transaction to the back stack;
|
||||||
* @param args Bundle to be set as {@link Fragment#getArguments()} of instantiated {@link Fragment};
|
* @param args Bundle to be set as {@link Fragment#getArguments()} of instantiated {@link Fragment};
|
||||||
* @param backStackTag Tag of {@link Fragment} in back stack;
|
* @param backStackTag Tag of {@link Fragment} in back stack;
|
||||||
* @param transactionSetup Function to setup transaction before commit. It is useful to specify transition animations or additional info.
|
* @param transactionSetup Function to setup transaction before commit. It is useful to specify transition animations or additional info.
|
||||||
|
|
@ -126,9 +128,10 @@ public class FragmentNavigation {
|
||||||
//CommitTransaction: it is ok as we could setup transaction before commit
|
//CommitTransaction: it is ok as we could setup transaction before commit
|
||||||
protected void addToStack(@NonNull final Class<? extends Fragment> fragmentClass,
|
protected void addToStack(@NonNull final Class<? extends Fragment> fragmentClass,
|
||||||
@Nullable final Fragment targetFragment,
|
@Nullable final Fragment targetFragment,
|
||||||
|
final boolean addToStack,
|
||||||
@Nullable final Bundle args,
|
@Nullable final Bundle args,
|
||||||
@Nullable final String backStackTag,
|
@Nullable final String backStackTag,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
if (fragmentManager.isDestroyed()) {
|
if (fragmentManager.isDestroyed()) {
|
||||||
Lc.assertion("FragmentManager is destroyed");
|
Lc.assertion("FragmentManager is destroyed");
|
||||||
return;
|
return;
|
||||||
|
|
@ -143,17 +146,23 @@ public class FragmentNavigation {
|
||||||
fragment.setTargetFragment(targetFragment, 0);
|
fragment.setTargetFragment(targetFragment, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction()
|
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||||
.replace(containerViewId, fragment, null)
|
|
||||||
.addToBackStack(backStackTag);
|
|
||||||
if (fragmentManager.getBackStackEntryCount() != 0) {
|
if (fragmentManager.getBackStackEntryCount() != 0) {
|
||||||
fragmentTransaction.setTransition(getDefaultTransition());
|
fragmentTransaction.setTransition(getDefaultTransition());
|
||||||
}
|
}
|
||||||
if (transactionSetup != null) {
|
if (transactionSetup != null) {
|
||||||
transactionSetup.call(fragmentTransaction).commit();
|
try {
|
||||||
} else {
|
fragmentTransaction = transactionSetup.apply(fragmentTransaction, fragment);
|
||||||
fragmentTransaction.commit();
|
} catch (final Exception exception) {
|
||||||
|
Lc.assertion(exception);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fragmentTransaction.replace(containerViewId, fragment, null);
|
||||||
|
if (addToStack) {
|
||||||
|
fragmentTransaction.addToBackStack(backStackTag);
|
||||||
|
}
|
||||||
|
fragmentTransaction.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -184,15 +193,20 @@ public class FragmentNavigation {
|
||||||
* @param condition Condition of back stack entry to be satisfied;
|
* @param condition Condition of back stack entry to be satisfied;
|
||||||
* @return True if it have back to some entry in stack.
|
* @return True if it have back to some entry in stack.
|
||||||
*/
|
*/
|
||||||
public boolean backTo(@NonNull final Func1<FragmentManager.BackStackEntry, Boolean> condition) {
|
public boolean backTo(@NonNull final Function<FragmentManager.BackStackEntry, Boolean> condition) {
|
||||||
final int stackSize = fragmentManager.getBackStackEntryCount();
|
final int stackSize = fragmentManager.getBackStackEntryCount();
|
||||||
Integer id = null;
|
Integer id = null;
|
||||||
for (int i = stackSize - 2; i >= 0; i--) {
|
try {
|
||||||
final FragmentManager.BackStackEntry backStackEntry = fragmentManager.getBackStackEntryAt(i);
|
for (int i = stackSize - 2; i >= 0; i--) {
|
||||||
id = backStackEntry.getId();
|
final FragmentManager.BackStackEntry backStackEntry = fragmentManager.getBackStackEntryAt(i);
|
||||||
if (condition.call(backStackEntry)) {
|
id = backStackEntry.getId();
|
||||||
break;
|
if (condition.apply(backStackEntry)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (final Exception exception) {
|
||||||
|
Lc.assertion(exception);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
fragmentManager.popBackStack(id, 0);
|
fragmentManager.popBackStack(id, 0);
|
||||||
|
|
@ -221,7 +235,7 @@ public class FragmentNavigation {
|
||||||
* @param fragmentClass Class of {@link Fragment} to instantiate.
|
* @param fragmentClass Class of {@link Fragment} to instantiate.
|
||||||
*/
|
*/
|
||||||
public void push(@NonNull final Class<? extends Fragment> fragmentClass) {
|
public void push(@NonNull final Class<? extends Fragment> fragmentClass) {
|
||||||
addToStack(fragmentClass, null, null, null, null);
|
addToStack(fragmentClass, null, true, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -232,7 +246,7 @@ public class FragmentNavigation {
|
||||||
*/
|
*/
|
||||||
public void push(@NonNull final Class<? extends Fragment> fragmentClass,
|
public void push(@NonNull final Class<? extends Fragment> fragmentClass,
|
||||||
@NonNull final Bundle args) {
|
@NonNull final Bundle args) {
|
||||||
addToStack(fragmentClass, null, args, null, null);
|
addToStack(fragmentClass, null, true, args, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -242,8 +256,8 @@ public class FragmentNavigation {
|
||||||
* @param transactionSetup Function to setup transaction before commit. It is useful to specify transition animations or additional info.
|
* @param transactionSetup Function to setup transaction before commit. It is useful to specify transition animations or additional info.
|
||||||
*/
|
*/
|
||||||
public void push(@NonNull final Class<? extends Fragment> fragmentClass,
|
public void push(@NonNull final Class<? extends Fragment> fragmentClass,
|
||||||
@NonNull final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@NonNull final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
addToStack(fragmentClass, null, null, null, transactionSetup);
|
addToStack(fragmentClass, null, true, null, null, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -255,8 +269,8 @@ public class FragmentNavigation {
|
||||||
*/
|
*/
|
||||||
public void push(@NonNull final Class<? extends Fragment> fragmentClass,
|
public void push(@NonNull final Class<? extends Fragment> fragmentClass,
|
||||||
@Nullable final Bundle args,
|
@Nullable final Bundle args,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
addToStack(fragmentClass, null, args, null, transactionSetup);
|
addToStack(fragmentClass, null, true, args, null, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -267,7 +281,7 @@ public class FragmentNavigation {
|
||||||
*/
|
*/
|
||||||
public void pushForResult(@NonNull final Class<? extends Fragment> fragmentClass,
|
public void pushForResult(@NonNull final Class<? extends Fragment> fragmentClass,
|
||||||
@NonNull final Fragment targetFragment) {
|
@NonNull final Fragment targetFragment) {
|
||||||
addToStack(fragmentClass, targetFragment, null, fragmentClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, null);
|
addToStack(fragmentClass, targetFragment, true, null, fragmentClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -280,7 +294,7 @@ public class FragmentNavigation {
|
||||||
public void pushForResult(@NonNull final Class<? extends Fragment> fragmentClass,
|
public void pushForResult(@NonNull final Class<? extends Fragment> fragmentClass,
|
||||||
@NonNull final Fragment targetFragment,
|
@NonNull final Fragment targetFragment,
|
||||||
@NonNull final Bundle args) {
|
@NonNull final Bundle args) {
|
||||||
addToStack(fragmentClass, targetFragment, args, fragmentClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, null);
|
addToStack(fragmentClass, targetFragment, true, args, fragmentClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -292,8 +306,8 @@ public class FragmentNavigation {
|
||||||
*/
|
*/
|
||||||
public void pushForResult(@NonNull final Class<? extends Fragment> fragmentClass,
|
public void pushForResult(@NonNull final Class<? extends Fragment> fragmentClass,
|
||||||
@NonNull final Fragment targetFragment,
|
@NonNull final Fragment targetFragment,
|
||||||
@NonNull final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@NonNull final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
addToStack(fragmentClass, targetFragment, null, fragmentClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, transactionSetup);
|
addToStack(fragmentClass, targetFragment, true, null, fragmentClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -307,8 +321,8 @@ public class FragmentNavigation {
|
||||||
public void pushForResult(@NonNull final Class<? extends Fragment> fragmentClass,
|
public void pushForResult(@NonNull final Class<? extends Fragment> fragmentClass,
|
||||||
@NonNull final Fragment targetFragment,
|
@NonNull final Fragment targetFragment,
|
||||||
@Nullable final Bundle args,
|
@Nullable final Bundle args,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
addToStack(fragmentClass, targetFragment, args, fragmentClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, transactionSetup);
|
addToStack(fragmentClass, targetFragment, true, args, fragmentClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -317,7 +331,7 @@ public class FragmentNavigation {
|
||||||
* @param fragmentClass Class of {@link Fragment} to instantiate.
|
* @param fragmentClass Class of {@link Fragment} to instantiate.
|
||||||
*/
|
*/
|
||||||
public void setAsTop(@NonNull final Class<? extends Fragment> fragmentClass) {
|
public void setAsTop(@NonNull final Class<? extends Fragment> fragmentClass) {
|
||||||
addToStack(fragmentClass, null, null, fragmentClass.getName() + ';' + TOP_FRAGMENT_TAG_MARK, null);
|
addToStack(fragmentClass, null, true, null, fragmentClass.getName() + ';' + TOP_FRAGMENT_TAG_MARK, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -328,7 +342,7 @@ public class FragmentNavigation {
|
||||||
*/
|
*/
|
||||||
public void setAsTop(@NonNull final Class<? extends Fragment> fragmentClass,
|
public void setAsTop(@NonNull final Class<? extends Fragment> fragmentClass,
|
||||||
@NonNull final Bundle args) {
|
@NonNull final Bundle args) {
|
||||||
addToStack(fragmentClass, null, args, fragmentClass.getName() + ';' + TOP_FRAGMENT_TAG_MARK, null);
|
addToStack(fragmentClass, null, true, args, fragmentClass.getName() + ';' + TOP_FRAGMENT_TAG_MARK, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -339,8 +353,8 @@ public class FragmentNavigation {
|
||||||
* @param transactionSetup Function to setup transaction before commit. It is useful to specify transition animations or additional info.
|
* @param transactionSetup Function to setup transaction before commit. It is useful to specify transition animations or additional info.
|
||||||
*/
|
*/
|
||||||
public void setAsTop(@NonNull final Class<? extends Fragment> fragmentClass,
|
public void setAsTop(@NonNull final Class<? extends Fragment> fragmentClass,
|
||||||
@NonNull final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@NonNull final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
addToStack(fragmentClass, null, null, fragmentClass.getName() + ';' + TOP_FRAGMENT_TAG_MARK, transactionSetup);
|
addToStack(fragmentClass, null, true, null, fragmentClass.getName() + ';' + TOP_FRAGMENT_TAG_MARK, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -353,8 +367,8 @@ public class FragmentNavigation {
|
||||||
*/
|
*/
|
||||||
public void setAsTop(@NonNull final Class<? extends Fragment> fragmentClass,
|
public void setAsTop(@NonNull final Class<? extends Fragment> fragmentClass,
|
||||||
@Nullable final Bundle args,
|
@Nullable final Bundle args,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
addToStack(fragmentClass, null, args, fragmentClass.getName() + ';' + TOP_FRAGMENT_TAG_MARK, transactionSetup);
|
addToStack(fragmentClass, null, true, args, fragmentClass.getName() + ';' + TOP_FRAGMENT_TAG_MARK, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -384,7 +398,7 @@ public class FragmentNavigation {
|
||||||
* @param transactionSetup Function to setup transaction before commit. It is useful to specify transition animations or additional info.
|
* @param transactionSetup Function to setup transaction before commit. It is useful to specify transition animations or additional info.
|
||||||
*/
|
*/
|
||||||
public void setInitial(@NonNull final Class<? extends Fragment> fragmentClass,
|
public void setInitial(@NonNull final Class<? extends Fragment> fragmentClass,
|
||||||
@NonNull final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@NonNull final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
setInitial(fragmentClass, null, transactionSetup);
|
setInitial(fragmentClass, null, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -397,7 +411,7 @@ public class FragmentNavigation {
|
||||||
*/
|
*/
|
||||||
public void setInitial(@NonNull final Class<? extends Fragment> fragmentClass,
|
public void setInitial(@NonNull final Class<? extends Fragment> fragmentClass,
|
||||||
@Nullable final Bundle args,
|
@Nullable final Bundle args,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
beforeSetInitialActions();
|
beforeSetInitialActions();
|
||||||
setAsTop(fragmentClass, args, transactionSetup);
|
setAsTop(fragmentClass, args, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package ru.touchin.roboswag.components.navigation;
|
package ru.touchin.roboswag.components.navigation;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.CallSuper;
|
import android.support.annotation.CallSuper;
|
||||||
|
|
@ -37,6 +38,13 @@ import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import io.reactivex.Completable;
|
||||||
|
import io.reactivex.Maybe;
|
||||||
|
import io.reactivex.Observable;
|
||||||
|
import io.reactivex.Single;
|
||||||
|
import io.reactivex.disposables.Disposable;
|
||||||
|
import io.reactivex.functions.Action;
|
||||||
|
import io.reactivex.functions.Consumer;
|
||||||
import ru.touchin.roboswag.components.navigation.activities.ViewControllerActivity;
|
import ru.touchin.roboswag.components.navigation.activities.ViewControllerActivity;
|
||||||
import ru.touchin.roboswag.components.navigation.fragments.ViewControllerFragment;
|
import ru.touchin.roboswag.components.navigation.fragments.ViewControllerFragment;
|
||||||
import ru.touchin.roboswag.components.utils.BaseLifecycleBindable;
|
import ru.touchin.roboswag.components.utils.BaseLifecycleBindable;
|
||||||
|
|
@ -44,12 +52,6 @@ import ru.touchin.roboswag.components.utils.LifecycleBindable;
|
||||||
import ru.touchin.roboswag.components.utils.UiUtils;
|
import ru.touchin.roboswag.components.utils.UiUtils;
|
||||||
import ru.touchin.roboswag.core.log.Lc;
|
import ru.touchin.roboswag.core.log.Lc;
|
||||||
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
|
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
|
||||||
import rx.Completable;
|
|
||||||
import rx.Observable;
|
|
||||||
import rx.Single;
|
|
||||||
import rx.Subscription;
|
|
||||||
import rx.functions.Action0;
|
|
||||||
import rx.functions.Action1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gavriil Sitnikov on 21/10/2015.
|
* Created by Gavriil Sitnikov on 21/10/2015.
|
||||||
|
|
@ -149,7 +151,7 @@ public class ViewController<TActivity extends ViewControllerActivity<?>,
|
||||||
*
|
*
|
||||||
* @param layoutResId Resource ID to be inflated.
|
* @param layoutResId Resource ID to be inflated.
|
||||||
*/
|
*/
|
||||||
public void setContentView(@LayoutRes final int layoutResId) {
|
public final void setContentView(@LayoutRes final int layoutResId) {
|
||||||
if (getContainer().getChildCount() > 0) {
|
if (getContainer().getChildCount() > 0) {
|
||||||
getContainer().removeAllViews();
|
getContainer().removeAllViews();
|
||||||
}
|
}
|
||||||
|
|
@ -162,7 +164,7 @@ public class ViewController<TActivity extends ViewControllerActivity<?>,
|
||||||
*
|
*
|
||||||
* @param view The desired content to display.
|
* @param view The desired content to display.
|
||||||
*/
|
*/
|
||||||
public void setContentView(@NonNull final View view) {
|
public final void setContentView(@NonNull final View view) {
|
||||||
setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -173,7 +175,7 @@ public class ViewController<TActivity extends ViewControllerActivity<?>,
|
||||||
* @param view The desired content to display;
|
* @param view The desired content to display;
|
||||||
* @param layoutParams Layout parameters for the view.
|
* @param layoutParams Layout parameters for the view.
|
||||||
*/
|
*/
|
||||||
public void setContentView(@NonNull final View view, @NonNull final ViewGroup.LayoutParams layoutParams) {
|
public final void setContentView(@NonNull final View view, @NonNull final ViewGroup.LayoutParams layoutParams) {
|
||||||
if (getContainer().getChildCount() > 0) {
|
if (getContainer().getChildCount() > 0) {
|
||||||
getContainer().removeAllViews();
|
getContainer().removeAllViews();
|
||||||
}
|
}
|
||||||
|
|
@ -329,6 +331,13 @@ public class ViewController<TActivity extends ViewControllerActivity<?>,
|
||||||
destroyed = true;
|
destroyed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback from parent fragment.
|
||||||
|
*/
|
||||||
|
public void onActivityResult(final int requestCode, final int resultCode, @Nullable final Intent data) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Similar to {@link ViewControllerFragment#onOptionsItemSelected(MenuItem)}.
|
* Similar to {@link ViewControllerFragment#onOptionsItemSelected(MenuItem)}.
|
||||||
*
|
*
|
||||||
|
|
@ -339,149 +348,186 @@ public class ViewController<TActivity extends ViewControllerActivity<?>,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("CPD-START")
|
|
||||||
//CPD: it is same as in other implementation based on BaseLifecycleBindable
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable) {
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable) {
|
||||||
return baseLifecycleBindable.untilStop(observable);
|
return baseLifecycleBindable.untilStop(observable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable, @NonNull final Action1<T> onNextAction) {
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable, @NonNull final Consumer<T> onNextAction) {
|
||||||
return baseLifecycleBindable.untilStop(observable, onNextAction);
|
return baseLifecycleBindable.untilStop(observable, onNextAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable,
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction);
|
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable,
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction,
|
@NonNull final Consumer<Throwable> onErrorAction,
|
||||||
@NonNull final Action0 onCompletedAction) {
|
@NonNull final Action onCompletedAction) {
|
||||||
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction, onCompletedAction);
|
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single) {
|
public <T> Disposable untilStop(@NonNull final Single<T> single) {
|
||||||
return baseLifecycleBindable.untilStop(single);
|
return baseLifecycleBindable.untilStop(single);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
|
public <T> Disposable untilStop(@NonNull final Single<T> single, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
return baseLifecycleBindable.untilStop(single, onSuccessAction);
|
return baseLifecycleBindable.untilStop(single, onSuccessAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single,
|
public <T> Disposable untilStop(@NonNull final Single<T> single,
|
||||||
@NonNull final Action1<T> onSuccessAction,
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilStop(single, onSuccessAction, onErrorAction);
|
return baseLifecycleBindable.untilStop(single, onSuccessAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilStop(@NonNull final Completable completable) {
|
public Disposable untilStop(@NonNull final Completable completable) {
|
||||||
return baseLifecycleBindable.untilStop(completable);
|
return baseLifecycleBindable.untilStop(completable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilStop(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
|
public Disposable untilStop(@NonNull final Completable completable, @NonNull final Action onCompletedAction) {
|
||||||
return baseLifecycleBindable.untilStop(completable, onCompletedAction);
|
return baseLifecycleBindable.untilStop(completable, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilStop(@NonNull final Completable completable,
|
public Disposable untilStop(@NonNull final Completable completable,
|
||||||
@NonNull final Action0 onCompletedAction,
|
@NonNull final Action onCompletedAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilStop(completable, onCompletedAction, onErrorAction);
|
return baseLifecycleBindable.untilStop(completable, onCompletedAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable) {
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe) {
|
||||||
|
return baseLifecycleBindable.untilStop(maybe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
|
return baseLifecycleBindable.untilStop(maybe, onSuccessAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe,
|
||||||
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
|
return baseLifecycleBindable.untilStop(maybe, onSuccessAction, onErrorAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable) {
|
||||||
return baseLifecycleBindable.untilDestroy(observable);
|
return baseLifecycleBindable.untilDestroy(observable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable, @NonNull final Action1<T> onNextAction) {
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable, @NonNull final Consumer<T> onNextAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(observable, onNextAction);
|
return baseLifecycleBindable.untilDestroy(observable, onNextAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable,
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction);
|
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable,
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction,
|
@NonNull final Consumer<Throwable> onErrorAction,
|
||||||
@NonNull final Action0 onCompletedAction) {
|
@NonNull final Action onCompletedAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction, onCompletedAction);
|
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single) {
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single) {
|
||||||
return baseLifecycleBindable.untilDestroy(single);
|
return baseLifecycleBindable.untilDestroy(single);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(single, onSuccessAction);
|
return baseLifecycleBindable.untilDestroy(single, onSuccessAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single,
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single,
|
||||||
@NonNull final Action1<T> onSuccessAction,
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(single, onSuccessAction, onErrorAction);
|
return baseLifecycleBindable.untilDestroy(single, onSuccessAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable) {
|
public Disposable untilDestroy(@NonNull final Completable completable) {
|
||||||
return baseLifecycleBindable.untilDestroy(completable);
|
return baseLifecycleBindable.untilDestroy(completable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
|
public Disposable untilDestroy(@NonNull final Completable completable, @NonNull final Action onCompletedAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction);
|
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable,
|
public Disposable untilDestroy(@NonNull final Completable completable,
|
||||||
@NonNull final Action0 onCompletedAction,
|
@NonNull final Action onCompletedAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction, onErrorAction);
|
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe) {
|
||||||
|
return baseLifecycleBindable.untilDestroy(maybe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe, @NonNull final Consumer<T> onCompletedAction) {
|
||||||
|
return baseLifecycleBindable.untilDestroy(maybe, onCompletedAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe,
|
||||||
|
@NonNull final Consumer<T> onCompletedAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
|
return baseLifecycleBindable.untilDestroy(maybe, onCompletedAction, onErrorAction);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("CPD-END")
|
@SuppressWarnings("CPD-END")
|
||||||
//CPD: it is same as in other implementation based on BaseLifecycleBindable
|
/*
|
||||||
/**
|
|
||||||
* Helper class to simplify constructor override.
|
* Helper class to simplify constructor override.
|
||||||
*/
|
*/
|
||||||
public static class CreationContext {
|
public static class CreationContext {
|
||||||
|
|
|
||||||
|
|
@ -27,13 +27,13 @@ import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
|
|
||||||
|
import io.reactivex.functions.BiFunction;
|
||||||
import ru.touchin.roboswag.components.navigation.activities.ViewControllerActivity;
|
import ru.touchin.roboswag.components.navigation.activities.ViewControllerActivity;
|
||||||
import ru.touchin.roboswag.components.navigation.fragments.SimpleViewControllerFragment;
|
import ru.touchin.roboswag.components.navigation.fragments.SimpleViewControllerFragment;
|
||||||
import ru.touchin.roboswag.components.navigation.fragments.StatelessTargetedViewControllerFragment;
|
import ru.touchin.roboswag.components.navigation.fragments.StatelessTargetedViewControllerFragment;
|
||||||
import ru.touchin.roboswag.components.navigation.fragments.StatelessViewControllerFragment;
|
import ru.touchin.roboswag.components.navigation.fragments.StatelessViewControllerFragment;
|
||||||
import ru.touchin.roboswag.components.navigation.fragments.TargetedViewControllerFragment;
|
import ru.touchin.roboswag.components.navigation.fragments.TargetedViewControllerFragment;
|
||||||
import ru.touchin.roboswag.components.navigation.fragments.ViewControllerFragment;
|
import ru.touchin.roboswag.components.navigation.fragments.ViewControllerFragment;
|
||||||
import rx.functions.Func1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gavriil Sitnikov on 07/03/2016.
|
* Created by Gavriil Sitnikov on 07/03/2016.
|
||||||
|
|
@ -59,7 +59,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
*/
|
*/
|
||||||
public <TState extends AbstractState> void push(@NonNull final Class<? extends ViewControllerFragment<TState, TActivity>> fragmentClass,
|
public <TState extends AbstractState> void push(@NonNull final Class<? extends ViewControllerFragment<TState, TActivity>> fragmentClass,
|
||||||
@NonNull final TState state) {
|
@NonNull final TState state) {
|
||||||
addToStack(fragmentClass, null, ViewControllerFragment.createState(state), null, null);
|
addToStack(fragmentClass, null, true, ViewControllerFragment.createState(state), null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -72,8 +72,8 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
*/
|
*/
|
||||||
public <TState extends AbstractState> void push(@NonNull final Class<? extends ViewControllerFragment<TState, TActivity>> fragmentClass,
|
public <TState extends AbstractState> void push(@NonNull final Class<? extends ViewControllerFragment<TState, TActivity>> fragmentClass,
|
||||||
@Nullable final TState state,
|
@Nullable final TState state,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
addToStack(fragmentClass, null, ViewControllerFragment.createState(state), null, transactionSetup);
|
addToStack(fragmentClass, null, true, ViewControllerFragment.createState(state), null, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -87,7 +87,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
public <TState extends AbstractState> void pushForResult(@NonNull final Class<? extends ViewControllerFragment<TState, TActivity>> fragmentClass,
|
public <TState extends AbstractState> void pushForResult(@NonNull final Class<? extends ViewControllerFragment<TState, TActivity>> fragmentClass,
|
||||||
@NonNull final Fragment targetFragment,
|
@NonNull final Fragment targetFragment,
|
||||||
@NonNull final TState state) {
|
@NonNull final TState state) {
|
||||||
addToStack(fragmentClass, targetFragment, ViewControllerFragment.createState(state),
|
addToStack(fragmentClass, targetFragment, true, ViewControllerFragment.createState(state),
|
||||||
fragmentClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, null);
|
fragmentClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,8 +103,9 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
public <TState extends AbstractState> void pushForResult(@NonNull final Class<? extends ViewControllerFragment<TState, TActivity>> fragmentClass,
|
public <TState extends AbstractState> void pushForResult(@NonNull final Class<? extends ViewControllerFragment<TState, TActivity>> fragmentClass,
|
||||||
@NonNull final Fragment targetFragment,
|
@NonNull final Fragment targetFragment,
|
||||||
@Nullable final TState state,
|
@Nullable final TState state,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment,
|
||||||
addToStack(fragmentClass, targetFragment, ViewControllerFragment.createState(state),
|
FragmentTransaction> transactionSetup) {
|
||||||
|
addToStack(fragmentClass, targetFragment, true, ViewControllerFragment.createState(state),
|
||||||
fragmentClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, transactionSetup);
|
fragmentClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,7 +132,8 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
*/
|
*/
|
||||||
public <TState extends AbstractState> void setAsTop(@NonNull final Class<? extends ViewControllerFragment<TState, TActivity>> fragmentClass,
|
public <TState extends AbstractState> void setAsTop(@NonNull final Class<? extends ViewControllerFragment<TState, TActivity>> fragmentClass,
|
||||||
@Nullable final TState state,
|
@Nullable final TState state,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment,
|
||||||
|
FragmentTransaction> transactionSetup) {
|
||||||
setAsTop(fragmentClass, ViewControllerFragment.createState(state), transactionSetup);
|
setAsTop(fragmentClass, ViewControllerFragment.createState(state), transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,7 +159,8 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
*/
|
*/
|
||||||
public <TState extends AbstractState> void setInitial(@NonNull final Class<? extends ViewControllerFragment<TState, TActivity>> fragmentClass,
|
public <TState extends AbstractState> void setInitial(@NonNull final Class<? extends ViewControllerFragment<TState, TActivity>> fragmentClass,
|
||||||
@Nullable final TState state,
|
@Nullable final TState state,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment,
|
||||||
|
FragmentTransaction> transactionSetup) {
|
||||||
setInitial(fragmentClass, ViewControllerFragment.createState(state), transactionSetup);
|
setInitial(fragmentClass, ViewControllerFragment.createState(state), transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,7 +184,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
public <TState extends AbstractState> void pushViewController(@NonNull final Class<? extends ViewController<TActivity,
|
public <TState extends AbstractState> void pushViewController(@NonNull final Class<? extends ViewController<TActivity,
|
||||||
SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
|
SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
|
||||||
@NonNull final TState state) {
|
@NonNull final TState state) {
|
||||||
addViewControllerToStack(viewControllerClass, null, state, null, null);
|
addViewControllerToStack(viewControllerClass, state, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -192,7 +195,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
*/
|
*/
|
||||||
public void pushViewController(
|
public void pushViewController(
|
||||||
@NonNull final Class<? extends ViewController<TActivity, StatelessViewControllerFragment<TActivity>>> viewControllerClass,
|
@NonNull final Class<? extends ViewController<TActivity, StatelessViewControllerFragment<TActivity>>> viewControllerClass,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
addStatelessViewControllerToStack(viewControllerClass, null, null, transactionSetup);
|
addStatelessViewControllerToStack(viewControllerClass, null, null, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -207,8 +210,30 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
public <TState extends AbstractState> void pushViewController(
|
public <TState extends AbstractState> void pushViewController(
|
||||||
@NonNull final Class<? extends ViewController<TActivity, SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
|
@NonNull final Class<? extends ViewController<TActivity, SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
|
||||||
@NonNull final TState state,
|
@NonNull final TState state,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
addViewControllerToStack(viewControllerClass, null, state, null, transactionSetup);
|
addViewControllerToStack(viewControllerClass, state, null, transactionSetup);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pushes {@link ViewController} without adding to stack.
|
||||||
|
*
|
||||||
|
* @param viewControllerClass Class of {@link ViewController} to be pushed.
|
||||||
|
*/
|
||||||
|
public void pushSingleViewController(@NonNull final Class<? extends ViewController<TActivity,
|
||||||
|
StatelessViewControllerFragment<TActivity>>> viewControllerClass) {
|
||||||
|
addToStack(StatelessViewControllerFragment.class, null, false, StatelessViewControllerFragment.createState(viewControllerClass), null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pushes {@link ViewController} without adding to stack and with specific {@link ViewControllerFragment#getState()}.
|
||||||
|
*
|
||||||
|
* @param viewControllerClass Class of {@link ViewController} to be pushed;
|
||||||
|
* @param state {@link AbstractState} of {@link ViewController}'s fragment;
|
||||||
|
* @param <TState> Type of state of fragment.
|
||||||
|
*/
|
||||||
|
public <TState extends AbstractState> void pushSingleViewController(@NonNull final Class<? extends ViewController<TActivity,
|
||||||
|
SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass, @NonNull final TState state) {
|
||||||
|
addToStack(SimpleViewControllerFragment.class, null, false, SimpleViewControllerFragment.createState(viewControllerClass, state), null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -242,7 +267,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
@NonNull final Class<? extends ViewController<TActivity,
|
@NonNull final Class<? extends ViewController<TActivity,
|
||||||
StatelessTargetedViewControllerFragment<TTargetState, TActivity>>> viewControllerClass,
|
StatelessTargetedViewControllerFragment<TTargetState, TActivity>>> viewControllerClass,
|
||||||
@NonNull final TTargetFragment targetFragment,
|
@NonNull final TTargetFragment targetFragment,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
addTargetedStatelessViewControllerToStack(viewControllerClass, targetFragment,
|
addTargetedStatelessViewControllerToStack(viewControllerClass, targetFragment,
|
||||||
viewControllerClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, transactionSetup);
|
viewControllerClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
@ -288,7 +313,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
TargetedViewControllerFragment<TState, TTargetState, TActivity>>> viewControllerClass,
|
TargetedViewControllerFragment<TState, TTargetState, TActivity>>> viewControllerClass,
|
||||||
@NonNull final TTargetFragment targetFragment,
|
@NonNull final TTargetFragment targetFragment,
|
||||||
@NonNull final TState state,
|
@NonNull final TState state,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
addTargetedViewControllerToStack(viewControllerClass, targetFragment, state,
|
addTargetedViewControllerToStack(viewControllerClass, targetFragment, state,
|
||||||
viewControllerClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, transactionSetup);
|
viewControllerClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
@ -314,7 +339,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
public <TState extends AbstractState> void setViewControllerAsTop(
|
public <TState extends AbstractState> void setViewControllerAsTop(
|
||||||
@NonNull final Class<? extends ViewController<TActivity, SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
|
@NonNull final Class<? extends ViewController<TActivity, SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
|
||||||
@NonNull final TState state) {
|
@NonNull final TState state) {
|
||||||
addViewControllerToStack(viewControllerClass, null, state, viewControllerClass.getName() + ' ' + TOP_FRAGMENT_TAG_MARK, null);
|
addViewControllerToStack(viewControllerClass, state, viewControllerClass.getName() + ' ' + TOP_FRAGMENT_TAG_MARK, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -326,7 +351,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
*/
|
*/
|
||||||
public void setViewControllerAsTop(
|
public void setViewControllerAsTop(
|
||||||
@NonNull final Class<? extends ViewController<TActivity, StatelessViewControllerFragment<TActivity>>> viewControllerClass,
|
@NonNull final Class<? extends ViewController<TActivity, StatelessViewControllerFragment<TActivity>>> viewControllerClass,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
addStatelessViewControllerToStack(viewControllerClass, null, viewControllerClass.getName() + ' ' + TOP_FRAGMENT_TAG_MARK, transactionSetup);
|
addStatelessViewControllerToStack(viewControllerClass, null, viewControllerClass.getName() + ' ' + TOP_FRAGMENT_TAG_MARK, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -342,8 +367,8 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
public <TState extends AbstractState> void setViewControllerAsTop(
|
public <TState extends AbstractState> void setViewControllerAsTop(
|
||||||
@NonNull final Class<? extends ViewController<TActivity, SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
|
@NonNull final Class<? extends ViewController<TActivity, SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
|
||||||
@NonNull final TState state,
|
@NonNull final TState state,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
addViewControllerToStack(viewControllerClass, null, state, viewControllerClass.getName() + ' ' + TOP_FRAGMENT_TAG_MARK, transactionSetup);
|
addViewControllerToStack(viewControllerClass, state, viewControllerClass.getName() + ' ' + TOP_FRAGMENT_TAG_MARK, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -379,7 +404,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
*/
|
*/
|
||||||
public void setInitialViewController(
|
public void setInitialViewController(
|
||||||
@NonNull final Class<? extends ViewController<TActivity, StatelessViewControllerFragment<TActivity>>> viewControllerClass,
|
@NonNull final Class<? extends ViewController<TActivity, StatelessViewControllerFragment<TActivity>>> viewControllerClass,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
beforeSetInitialActions();
|
beforeSetInitialActions();
|
||||||
setViewControllerAsTop(viewControllerClass, transactionSetup);
|
setViewControllerAsTop(viewControllerClass, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
@ -396,7 +421,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
public <TState extends AbstractState> void setInitialViewController(
|
public <TState extends AbstractState> void setInitialViewController(
|
||||||
@NonNull final Class<? extends ViewController<TActivity, SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
|
@NonNull final Class<? extends ViewController<TActivity, SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
|
||||||
@NonNull final TState state,
|
@NonNull final TState state,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
beforeSetInitialActions();
|
beforeSetInitialActions();
|
||||||
setViewControllerAsTop(viewControllerClass, state, transactionSetup);
|
setViewControllerAsTop(viewControllerClass, state, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
@ -413,8 +438,8 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
@NonNull final Class<? extends ViewController<TActivity, ? extends StatelessViewControllerFragment<TActivity>>> viewControllerClass,
|
@NonNull final Class<? extends ViewController<TActivity, ? extends StatelessViewControllerFragment<TActivity>>> viewControllerClass,
|
||||||
@Nullable final Fragment targetFragment,
|
@Nullable final Fragment targetFragment,
|
||||||
@Nullable final String backStackTag,
|
@Nullable final String backStackTag,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
addToStack(StatelessViewControllerFragment.class, targetFragment,
|
addToStack(StatelessViewControllerFragment.class, targetFragment, true,
|
||||||
StatelessViewControllerFragment.createState(viewControllerClass), backStackTag, transactionSetup);
|
StatelessViewControllerFragment.createState(viewControllerClass), backStackTag, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -435,8 +460,8 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
@NonNull final Fragment targetFragment,
|
@NonNull final Fragment targetFragment,
|
||||||
@NonNull final TState state,
|
@NonNull final TState state,
|
||||||
@Nullable final String backStackTag,
|
@Nullable final String backStackTag,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
addToStack(TargetedViewControllerFragment.class, targetFragment,
|
addToStack(TargetedViewControllerFragment.class, targetFragment, true,
|
||||||
TargetedViewControllerFragment.createState(viewControllerClass, state), backStackTag, transactionSetup);
|
TargetedViewControllerFragment.createState(viewControllerClass, state), backStackTag, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -454,8 +479,8 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
? extends StatelessTargetedViewControllerFragment<TState, TActivity>>> viewControllerClass,
|
? extends StatelessTargetedViewControllerFragment<TState, TActivity>>> viewControllerClass,
|
||||||
@NonNull final Fragment targetFragment,
|
@NonNull final Fragment targetFragment,
|
||||||
@Nullable final String backStackTag,
|
@Nullable final String backStackTag,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
addToStack(StatelessTargetedViewControllerFragment.class, targetFragment,
|
addToStack(StatelessTargetedViewControllerFragment.class, targetFragment, true,
|
||||||
StatelessTargetedViewControllerFragment.createState(viewControllerClass), backStackTag, transactionSetup);
|
StatelessTargetedViewControllerFragment.createState(viewControllerClass), backStackTag, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -463,7 +488,6 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
* Base method to push stateful {@link ViewControllerFragment} to stack.
|
* Base method to push stateful {@link ViewControllerFragment} to stack.
|
||||||
*
|
*
|
||||||
* @param viewControllerClass Class of {@link ViewController} to be pushed;
|
* @param viewControllerClass Class of {@link ViewController} to be pushed;
|
||||||
* @param targetFragment {@link ViewControllerFragment} to be set as target;
|
|
||||||
* @param state {@link AbstractState} of {@link ViewController}'s fragment;
|
* @param state {@link AbstractState} of {@link ViewController}'s fragment;
|
||||||
* @param backStackTag Tag of {@link ViewControllerFragment} in back stack;
|
* @param backStackTag Tag of {@link ViewControllerFragment} in back stack;
|
||||||
* @param transactionSetup Function to setup transaction before commit. It is useful to specify transition animations or additional info;
|
* @param transactionSetup Function to setup transaction before commit. It is useful to specify transition animations or additional info;
|
||||||
|
|
@ -471,11 +495,10 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
|
||||||
*/
|
*/
|
||||||
protected <TState extends AbstractState> void addViewControllerToStack(
|
protected <TState extends AbstractState> void addViewControllerToStack(
|
||||||
@NonNull final Class<? extends ViewController<TActivity, ? extends SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
|
@NonNull final Class<? extends ViewController<TActivity, ? extends SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
|
||||||
@Nullable final Fragment targetFragment,
|
|
||||||
@NonNull final TState state,
|
@NonNull final TState state,
|
||||||
@Nullable final String backStackTag,
|
@Nullable final String backStackTag,
|
||||||
@Nullable final Func1<FragmentTransaction, FragmentTransaction> transactionSetup) {
|
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
|
||||||
addToStack(SimpleViewControllerFragment.class, targetFragment,
|
addToStack(SimpleViewControllerFragment.class, null, true,
|
||||||
SimpleViewControllerFragment.createState(viewControllerClass, state), backStackTag, transactionSetup);
|
SimpleViewControllerFragment.createState(viewControllerClass, state), backStackTag, transactionSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,19 +35,20 @@ import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import io.reactivex.Completable;
|
||||||
|
import io.reactivex.Maybe;
|
||||||
|
import io.reactivex.Observable;
|
||||||
|
import io.reactivex.Single;
|
||||||
|
import io.reactivex.disposables.Disposable;
|
||||||
|
import io.reactivex.functions.Action;
|
||||||
|
import io.reactivex.functions.Consumer;
|
||||||
|
import io.reactivex.subjects.BehaviorSubject;
|
||||||
import ru.touchin.roboswag.components.utils.BaseLifecycleBindable;
|
import ru.touchin.roboswag.components.utils.BaseLifecycleBindable;
|
||||||
import ru.touchin.roboswag.components.utils.LifecycleBindable;
|
import ru.touchin.roboswag.components.utils.LifecycleBindable;
|
||||||
import ru.touchin.roboswag.components.utils.UiUtils;
|
import ru.touchin.roboswag.components.utils.UiUtils;
|
||||||
import ru.touchin.roboswag.core.log.Lc;
|
import ru.touchin.roboswag.core.log.Lc;
|
||||||
import ru.touchin.roboswag.core.utils.Optional;
|
import ru.touchin.roboswag.core.utils.Optional;
|
||||||
import ru.touchin.roboswag.core.utils.pairs.HalfNullablePair;
|
import ru.touchin.roboswag.core.utils.pairs.HalfNullablePair;
|
||||||
import rx.Completable;
|
|
||||||
import rx.Observable;
|
|
||||||
import rx.Single;
|
|
||||||
import rx.Subscription;
|
|
||||||
import rx.functions.Action0;
|
|
||||||
import rx.functions.Action1;
|
|
||||||
import rx.subjects.BehaviorSubject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gavriil Sitnikov on 08/03/2016.
|
* Created by Gavriil Sitnikov on 08/03/2016.
|
||||||
|
|
@ -68,7 +69,7 @@ public abstract class BaseActivity extends AppCompatActivity
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final BehaviorSubject<Optional<HalfNullablePair<Integer, Intent>>> lastActivityResult
|
private final BehaviorSubject<Optional<HalfNullablePair<Integer, Intent>>> lastActivityResult
|
||||||
= BehaviorSubject.create(new Optional<HalfNullablePair<Integer, Intent>>(null));
|
= BehaviorSubject.createDefault(new Optional<HalfNullablePair<Integer, Intent>>(null));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if activity resumed.
|
* Returns if activity resumed.
|
||||||
|
|
@ -114,7 +115,7 @@ public abstract class BaseActivity extends AppCompatActivity
|
||||||
@NonNull
|
@NonNull
|
||||||
public Observable<Intent> observeActivityResult(final int requestCode) {
|
public Observable<Intent> observeActivityResult(final int requestCode) {
|
||||||
return lastActivityResult
|
return lastActivityResult
|
||||||
.switchMap(optional -> {
|
.concatMap(optional -> {
|
||||||
final HalfNullablePair<Integer, Intent> activityResult = optional.get();
|
final HalfNullablePair<Integer, Intent> activityResult = optional.get();
|
||||||
if (activityResult == null || activityResult.getFirst() != requestCode) {
|
if (activityResult == null || activityResult.getFirst() != requestCode) {
|
||||||
return Observable.empty();
|
return Observable.empty();
|
||||||
|
|
@ -257,145 +258,185 @@ public abstract class BaseActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("CPD-START")
|
@SuppressWarnings("CPD-START")
|
||||||
//CPD: it is same as in other implementation based on BaseLifecycleBindable
|
//CPD: it's ok as it's LifecycleBindable
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable,
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable) {
|
||||||
@NonNull final Action1<T> onNextAction,
|
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
|
||||||
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable,
|
|
||||||
@NonNull final Action1<T> onNextAction,
|
|
||||||
@NonNull final Action1<Throwable> onErrorAction,
|
|
||||||
@NonNull final Action0 onCompletedAction) {
|
|
||||||
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction, onCompletedAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single) {
|
|
||||||
return baseLifecycleBindable.untilStop(single);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
|
|
||||||
return baseLifecycleBindable.untilStop(single, onSuccessAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single,
|
|
||||||
@NonNull final Action1<T> onSuccessAction,
|
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
|
||||||
return baseLifecycleBindable.untilStop(single, onSuccessAction, onErrorAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Subscription untilStop(@NonNull final Completable completable) {
|
|
||||||
return baseLifecycleBindable.untilStop(completable);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Subscription untilStop(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
|
|
||||||
return baseLifecycleBindable.untilStop(completable, onCompletedAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Subscription untilStop(@NonNull final Completable completable,
|
|
||||||
@NonNull final Action0 onCompletedAction,
|
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
|
||||||
return baseLifecycleBindable.untilStop(completable, onCompletedAction, onErrorAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable) {
|
|
||||||
return baseLifecycleBindable.untilStop(observable);
|
return baseLifecycleBindable.untilStop(observable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable, @NonNull final Action1<T> onNextAction) {
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable, @NonNull final Consumer<T> onNextAction) {
|
||||||
return baseLifecycleBindable.untilStop(observable, onNextAction);
|
return baseLifecycleBindable.untilStop(observable, onNextAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable) {
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable,
|
||||||
|
@NonNull final Consumer<T> onNextAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
|
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable,
|
||||||
|
@NonNull final Consumer<T> onNextAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction,
|
||||||
|
@NonNull final Action onCompletedAction) {
|
||||||
|
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction, onCompletedAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilStop(@NonNull final Single<T> single) {
|
||||||
|
return baseLifecycleBindable.untilStop(single);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilStop(@NonNull final Single<T> single, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
|
return baseLifecycleBindable.untilStop(single, onSuccessAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilStop(@NonNull final Single<T> single,
|
||||||
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
|
return baseLifecycleBindable.untilStop(single, onSuccessAction, onErrorAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Disposable untilStop(@NonNull final Completable completable) {
|
||||||
|
return baseLifecycleBindable.untilStop(completable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Disposable untilStop(@NonNull final Completable completable, @NonNull final Action onCompletedAction) {
|
||||||
|
return baseLifecycleBindable.untilStop(completable, onCompletedAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Disposable untilStop(@NonNull final Completable completable,
|
||||||
|
@NonNull final Action onCompletedAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
|
return baseLifecycleBindable.untilStop(completable, onCompletedAction, onErrorAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe) {
|
||||||
|
return baseLifecycleBindable.untilStop(maybe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
|
return baseLifecycleBindable.untilStop(maybe, onSuccessAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe,
|
||||||
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
|
return baseLifecycleBindable.untilStop(maybe, onSuccessAction, onErrorAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable) {
|
||||||
return baseLifecycleBindable.untilDestroy(observable);
|
return baseLifecycleBindable.untilDestroy(observable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable, @NonNull final Action1<T> onNextAction) {
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable, @NonNull final Consumer<T> onNextAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(observable, onNextAction);
|
return baseLifecycleBindable.untilDestroy(observable, onNextAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable,
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction);
|
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable,
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction,
|
@NonNull final Consumer<Throwable> onErrorAction,
|
||||||
@NonNull final Action0 onCompletedAction) {
|
@NonNull final Action onCompletedAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction, onCompletedAction);
|
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single) {
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single) {
|
||||||
return baseLifecycleBindable.untilDestroy(single);
|
return baseLifecycleBindable.untilDestroy(single);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(single, onSuccessAction);
|
return baseLifecycleBindable.untilDestroy(single, onSuccessAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single,
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single,
|
||||||
@NonNull final Action1<T> onSuccessAction,
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(single, onSuccessAction, onErrorAction);
|
return baseLifecycleBindable.untilDestroy(single, onSuccessAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable) {
|
public Disposable untilDestroy(@NonNull final Completable completable) {
|
||||||
return baseLifecycleBindable.untilDestroy(completable);
|
return baseLifecycleBindable.untilDestroy(completable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
|
public Disposable untilDestroy(@NonNull final Completable completable, @NonNull final Action onCompletedAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction);
|
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable,
|
public Disposable untilDestroy(@NonNull final Completable completable,
|
||||||
@NonNull final Action0 onCompletedAction,
|
@NonNull final Action onCompletedAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction, onErrorAction);
|
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe) {
|
||||||
|
return baseLifecycleBindable.untilDestroy(maybe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe, @NonNull final Consumer<T> onCompletedAction) {
|
||||||
|
return baseLifecycleBindable.untilDestroy(maybe, onCompletedAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe,
|
||||||
|
@NonNull final Consumer<T> onCompletedAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
|
return baseLifecycleBindable.untilDestroy(maybe, onCompletedAction, onErrorAction);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("CPD-END")
|
@SuppressWarnings("CPD-END")
|
||||||
/*
|
/*
|
||||||
* Interface to be implemented for someone who want to intercept device back button pressing event.
|
* Interface to be implemented for someone who want to intercept device back button pressing event.
|
||||||
|
|
|
||||||
|
|
@ -103,8 +103,8 @@ public abstract class ViewControllerActivity<TLogic extends Logic> extends BaseA
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public View findViewById(@IdRes final int id) {
|
public <T extends View> T findViewById(@IdRes final int id) {
|
||||||
final View viewById = super.findViewById(id);
|
final T viewById = super.findViewById(id);
|
||||||
if (viewById == null) {
|
if (viewById == null) {
|
||||||
throw new ShouldNotHappenException("No view for id=" + getResources().getResourceName(id));
|
throw new ShouldNotHappenException("No view for id=" + getResources().getResourceName(id));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
package ru.touchin.roboswag.components.navigation.fragments;
|
package ru.touchin.roboswag.components.navigation.fragments;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
|
|
@ -39,6 +40,9 @@ import java.io.Serializable;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
|
import io.reactivex.Observable;
|
||||||
|
import io.reactivex.disposables.Disposable;
|
||||||
|
import io.reactivex.subjects.BehaviorSubject;
|
||||||
import ru.touchin.roboswag.components.navigation.AbstractState;
|
import ru.touchin.roboswag.components.navigation.AbstractState;
|
||||||
import ru.touchin.roboswag.components.navigation.ViewController;
|
import ru.touchin.roboswag.components.navigation.ViewController;
|
||||||
import ru.touchin.roboswag.components.navigation.activities.ViewControllerActivity;
|
import ru.touchin.roboswag.components.navigation.activities.ViewControllerActivity;
|
||||||
|
|
@ -47,10 +51,6 @@ import ru.touchin.roboswag.core.log.Lc;
|
||||||
import ru.touchin.roboswag.core.utils.Optional;
|
import ru.touchin.roboswag.core.utils.Optional;
|
||||||
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
|
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
|
||||||
import ru.touchin.roboswag.core.utils.pairs.NullablePair;
|
import ru.touchin.roboswag.core.utils.pairs.NullablePair;
|
||||||
import rx.Observable;
|
|
||||||
import rx.Subscription;
|
|
||||||
import rx.exceptions.OnErrorThrowable;
|
|
||||||
import rx.subjects.BehaviorSubject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gavriil Sitnikov on 21/10/2015.
|
* Created by Gavriil Sitnikov on 21/10/2015.
|
||||||
|
|
@ -118,7 +118,7 @@ public abstract class ViewControllerFragment<TState extends AbstractState, TActi
|
||||||
private final BehaviorSubject<NullablePair<PlaceholderView, Bundle>> viewSubject = BehaviorSubject.create();
|
private final BehaviorSubject<NullablePair<PlaceholderView, Bundle>> viewSubject = BehaviorSubject.create();
|
||||||
@Nullable
|
@Nullable
|
||||||
private ViewController viewController;
|
private ViewController viewController;
|
||||||
private Subscription viewControllerSubscription;
|
private Disposable viewControllerSubscription;
|
||||||
private TState state;
|
private TState state;
|
||||||
private boolean started;
|
private boolean started;
|
||||||
private boolean stateCreated;
|
private boolean stateCreated;
|
||||||
|
|
@ -180,15 +180,14 @@ public abstract class ViewControllerFragment<TState extends AbstractState, TActi
|
||||||
final TActivity activity = activityOptional.get();
|
final TActivity activity = activityOptional.get();
|
||||||
final PlaceholderView container = viewInfo.getFirst();
|
final PlaceholderView container = viewInfo.getFirst();
|
||||||
if (activity == null || container == null) {
|
if (activity == null || container == null) {
|
||||||
return null;
|
return new Optional<ViewController>(null);
|
||||||
}
|
}
|
||||||
final ViewController newViewController = createViewController(activity, container, viewInfo.getSecond());
|
final ViewController newViewController = createViewController(activity, container, viewInfo.getSecond());
|
||||||
newViewController.onCreate();
|
newViewController.onCreate();
|
||||||
return newViewController;
|
return new Optional<>(newViewController);
|
||||||
})
|
})
|
||||||
.subscribe(this::onViewControllerChanged,
|
.subscribe(this::onViewControllerChanged,
|
||||||
throwable -> Lc.cutAssertion(throwable,
|
throwable -> Lc.cutAssertion(throwable, InvocationTargetException.class, InflateException.class));
|
||||||
OnErrorThrowable.class, InvocationTargetException.class, InflateException.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
@ -196,7 +195,7 @@ public abstract class ViewControllerFragment<TState extends AbstractState, TActi
|
||||||
@Nullable final Bundle savedInstanceState) {
|
@Nullable final Bundle savedInstanceState) {
|
||||||
|
|
||||||
if (getViewControllerClass().getConstructors().length != 1) {
|
if (getViewControllerClass().getConstructors().length != 1) {
|
||||||
throw OnErrorThrowable.from(new ShouldNotHappenException("There should be single constructor for " + getViewControllerClass()));
|
throw new ShouldNotHappenException("There should be single constructor for " + getViewControllerClass());
|
||||||
}
|
}
|
||||||
final Constructor<?> constructor = getViewControllerClass().getConstructors()[0];
|
final Constructor<?> constructor = getViewControllerClass().getConstructors()[0];
|
||||||
final ViewController.CreationContext creationContext = new ViewController.CreationContext(activity, this, view);
|
final ViewController.CreationContext creationContext = new ViewController.CreationContext(activity, this, view);
|
||||||
|
|
@ -208,11 +207,10 @@ public abstract class ViewControllerFragment<TState extends AbstractState, TActi
|
||||||
case 3:
|
case 3:
|
||||||
return (ViewController) constructor.newInstance(this, creationContext, savedInstanceState);
|
return (ViewController) constructor.newInstance(this, creationContext, savedInstanceState);
|
||||||
default:
|
default:
|
||||||
throw OnErrorThrowable
|
throw new ShouldNotHappenException("Wrong constructor parameters count: " + constructor.getParameterTypes().length);
|
||||||
.from(new ShouldNotHappenException("Wrong constructor parameters count: " + constructor.getParameterTypes().length));
|
|
||||||
}
|
}
|
||||||
} catch (final Exception exception) {
|
} catch (final Exception exception) {
|
||||||
throw OnErrorThrowable.from(exception);
|
throw new ShouldNotHappenException(exception);
|
||||||
} finally {
|
} finally {
|
||||||
checkCreationTime(creationTime);
|
checkCreationTime(creationTime);
|
||||||
}
|
}
|
||||||
|
|
@ -315,11 +313,11 @@ public abstract class ViewControllerFragment<TState extends AbstractState, TActi
|
||||||
return (viewController != null && viewController.onOptionsItemSelected(item)) || super.onOptionsItemSelected(item);
|
return (viewController != null && viewController.onOptionsItemSelected(item)) || super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onViewControllerChanged(@Nullable final ViewController viewController) {
|
private void onViewControllerChanged(@NonNull final Optional<ViewController> viewControllerOptional) {
|
||||||
if (this.viewController != null) {
|
if (this.viewController != null) {
|
||||||
this.viewController.onDestroy();
|
this.viewController.onDestroy();
|
||||||
}
|
}
|
||||||
this.viewController = viewController;
|
this.viewController = viewControllerOptional.get();
|
||||||
if (this.viewController != null) {
|
if (this.viewController != null) {
|
||||||
if (started) {
|
if (started) {
|
||||||
this.viewController.onStart();
|
this.viewController.onStart();
|
||||||
|
|
@ -376,7 +374,7 @@ public abstract class ViewControllerFragment<TState extends AbstractState, TActi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
viewControllerSubscription.unsubscribe();
|
viewControllerSubscription.dispose();
|
||||||
if (viewController != null && !viewController.isDestroyed()) {
|
if (viewController != null && !viewController.isDestroyed()) {
|
||||||
viewController.onDestroy();
|
viewController.onDestroy();
|
||||||
viewController = null;
|
viewController = null;
|
||||||
|
|
@ -384,6 +382,14 @@ public abstract class ViewControllerFragment<TState extends AbstractState, TActi
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(final int requestCode, final int resultCode, @Nullable final Intent data) {
|
||||||
|
if (viewController != null) {
|
||||||
|
viewController.onActivityResult(requestCode, resultCode, data);
|
||||||
|
}
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
}
|
||||||
|
|
||||||
private static class PlaceholderView extends FrameLayout {
|
private static class PlaceholderView extends FrameLayout {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,9 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import io.reactivex.functions.BiConsumer;
|
||||||
import ru.touchin.roboswag.components.navigation.OnFragmentStartedListener;
|
import ru.touchin.roboswag.components.navigation.OnFragmentStartedListener;
|
||||||
import ru.touchin.roboswag.core.log.Lc;
|
import ru.touchin.roboswag.core.log.Lc;
|
||||||
import rx.functions.Action2;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gavriil Sitnikov on 21/10/2015.
|
* Created by Gavriil Sitnikov on 21/10/2015.
|
||||||
|
|
@ -111,12 +111,16 @@ public abstract class ViewFragment<TActivity extends AppCompatActivity> extends
|
||||||
//do nothing
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callMethodAfterInstantiation(@NonNull final Action2<View, TActivity> action) {
|
private void callMethodAfterInstantiation(@NonNull final BiConsumer<View, TActivity> action) {
|
||||||
if (getView() == null || getBaseActivity() == null) {
|
if (getView() == null || getBaseActivity() == null) {
|
||||||
Lc.assertion("View and activity shouldn't be null");
|
Lc.assertion("View and activity shouldn't be null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
action.call(getView(), getBaseActivity());
|
try {
|
||||||
|
action.accept(getView(), getBaseActivity());
|
||||||
|
} catch (final Exception exception) {
|
||||||
|
Lc.assertion(exception);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
|
|
||||||
|
|
@ -21,18 +21,18 @@ package ru.touchin.roboswag.components.utils;
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
|
import io.reactivex.Completable;
|
||||||
|
import io.reactivex.Maybe;
|
||||||
|
import io.reactivex.Observable;
|
||||||
|
import io.reactivex.Single;
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.disposables.Disposable;
|
||||||
|
import io.reactivex.functions.Action;
|
||||||
|
import io.reactivex.functions.Consumer;
|
||||||
|
import io.reactivex.internal.functions.Functions;
|
||||||
|
import io.reactivex.subjects.BehaviorSubject;
|
||||||
import ru.touchin.roboswag.core.log.Lc;
|
import ru.touchin.roboswag.core.log.Lc;
|
||||||
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
|
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
|
||||||
import rx.Completable;
|
|
||||||
import rx.Observable;
|
|
||||||
import rx.Single;
|
|
||||||
import rx.Subscription;
|
|
||||||
import rx.android.schedulers.AndroidSchedulers;
|
|
||||||
import rx.exceptions.OnErrorThrowable;
|
|
||||||
import rx.functions.Action0;
|
|
||||||
import rx.functions.Action1;
|
|
||||||
import rx.functions.Actions;
|
|
||||||
import rx.subjects.BehaviorSubject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gavriil Sitnikov on 18/04/16.
|
* Created by Gavriil Sitnikov on 18/04/16.
|
||||||
|
|
@ -49,7 +49,7 @@ public class BaseLifecycleBindable implements LifecycleBindable {
|
||||||
@NonNull
|
@NonNull
|
||||||
private final BehaviorSubject<Boolean> isStartedSubject = BehaviorSubject.create();
|
private final BehaviorSubject<Boolean> isStartedSubject = BehaviorSubject.create();
|
||||||
@NonNull
|
@NonNull
|
||||||
private final BehaviorSubject<Boolean> isInAfterSaving = BehaviorSubject.create(false);
|
private final BehaviorSubject<Boolean> isInAfterSaving = BehaviorSubject.createDefault(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call it on parent's onCreate method.
|
* Call it on parent's onCreate method.
|
||||||
|
|
@ -62,9 +62,7 @@ public class BaseLifecycleBindable implements LifecycleBindable {
|
||||||
* Call it on parent's onStart method.
|
* Call it on parent's onStart method.
|
||||||
*/
|
*/
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
if (!isStartedSubject.hasValue() || !isStartedSubject.getValue()) {
|
isStartedSubject.onNext(true);
|
||||||
isStartedSubject.onNext(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -87,9 +85,7 @@ public class BaseLifecycleBindable implements LifecycleBindable {
|
||||||
* Call it on parent's onStop method.
|
* Call it on parent's onStop method.
|
||||||
*/
|
*/
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
if (!isStartedSubject.hasValue() || isStartedSubject.getValue()) {
|
isStartedSubject.onNext(false);
|
||||||
isStartedSubject.onNext(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -101,32 +97,32 @@ public class BaseLifecycleBindable implements LifecycleBindable {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable) {
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable) {
|
||||||
final String codePoint = Lc.getCodePoint(this, 2);
|
final String codePoint = Lc.getCodePoint(this, 2);
|
||||||
return untilStop(observable, Actions.empty(), getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD), Actions.empty());
|
return untilStop(observable, Functions.emptyConsumer(), getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD), Functions.EMPTY_ACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable, @NonNull final Action1<T> onNextAction) {
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable, @NonNull final Consumer<T> onNextAction) {
|
||||||
final String codePoint = Lc.getCodePoint(this, 2);
|
final String codePoint = Lc.getCodePoint(this, 2);
|
||||||
return untilStop(observable, onNextAction, getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD), Actions.empty());
|
return untilStop(observable, onNextAction, getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD), Functions.EMPTY_ACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable,
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return untilStop(observable, onNextAction, onErrorAction, Actions.empty());
|
return untilStop(observable, onNextAction, onErrorAction, Functions.EMPTY_ACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable,
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction,
|
@NonNull final Consumer<Throwable> onErrorAction,
|
||||||
@NonNull final Action0 onCompletedAction) {
|
@NonNull final Action onCompletedAction) {
|
||||||
return until(observable, isStartedSubject.map(started -> !started)
|
return until(observable, isStartedSubject.map(started -> !started)
|
||||||
.delay(item -> isInAfterSaving.filter(inAfterSaving -> !inAfterSaving)),
|
.delay(item -> isInAfterSaving.filter(inAfterSaving -> !inAfterSaving)),
|
||||||
onNextAction, onErrorAction, onCompletedAction);
|
onNextAction, onErrorAction, onCompletedAction);
|
||||||
|
|
@ -134,152 +130,197 @@ public class BaseLifecycleBindable implements LifecycleBindable {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single) {
|
public <T> Disposable untilStop(@NonNull final Single<T> single) {
|
||||||
final String codePoint = Lc.getCodePoint(this, 2);
|
final String codePoint = Lc.getCodePoint(this, 2);
|
||||||
return untilStop(single, Actions.empty(), getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD));
|
return untilStop(single, Functions.emptyConsumer(), getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
|
public <T> Disposable untilStop(@NonNull final Single<T> single, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
final String codePoint = Lc.getCodePoint(this, 2);
|
final String codePoint = Lc.getCodePoint(this, 2);
|
||||||
return untilStop(single, onSuccessAction, getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD));
|
return untilStop(single, onSuccessAction, getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single,
|
public <T> Disposable untilStop(@NonNull final Single<T> single,
|
||||||
@NonNull final Action1<T> onSuccessAction,
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return until(single.toObservable(), isStartedSubject.map(started -> !started)
|
return until(single.toObservable(), isStartedSubject.map(started -> !started)
|
||||||
.delay(item -> isInAfterSaving.filter(inAfterSaving -> !inAfterSaving)),
|
.delay(item -> isInAfterSaving.filter(inAfterSaving -> !inAfterSaving)),
|
||||||
onSuccessAction, onErrorAction, Actions.empty());
|
onSuccessAction, onErrorAction, Functions.EMPTY_ACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilStop(@NonNull final Completable completable) {
|
public Disposable untilStop(@NonNull final Completable completable) {
|
||||||
final String codePoint = Lc.getCodePoint(this, 2);
|
final String codePoint = Lc.getCodePoint(this, 2);
|
||||||
return untilStop(completable, Actions.empty(), getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD));
|
return untilStop(completable, Functions.EMPTY_ACTION, getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilStop(@NonNull final Completable completable,
|
public Disposable untilStop(@NonNull final Completable completable,
|
||||||
@NonNull final Action0 onCompletedAction) {
|
@NonNull final Action onCompletedAction) {
|
||||||
final String codePoint = Lc.getCodePoint(this, 2);
|
final String codePoint = Lc.getCodePoint(this, 2);
|
||||||
return untilStop(completable, onCompletedAction, getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD));
|
return untilStop(completable, onCompletedAction, getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilStop(@NonNull final Completable completable,
|
public Disposable untilStop(@NonNull final Completable completable,
|
||||||
@NonNull final Action0 onCompletedAction,
|
@NonNull final Action onCompletedAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return until(completable.toObservable(), isStartedSubject.map(started -> !started)
|
return until(completable.toObservable(), isStartedSubject.map(started -> !started)
|
||||||
.delay(item -> isInAfterSaving.filter(inAfterSaving -> !inAfterSaving)),
|
.delay(item -> isInAfterSaving.filter(inAfterSaving -> !inAfterSaving)),
|
||||||
Actions.empty(), onErrorAction, onCompletedAction);
|
Functions.emptyConsumer(), onErrorAction, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable) {
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe) {
|
||||||
final String codePoint = Lc.getCodePoint(this, 2);
|
final String codePoint = Lc.getCodePoint(this, 2);
|
||||||
return untilDestroy(observable, Actions.empty(), getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD), Actions.empty());
|
return untilStop(maybe, Functions.emptyConsumer(), getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable,
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
@NonNull final Action1<T> onNextAction) {
|
|
||||||
final String codePoint = Lc.getCodePoint(this, 2);
|
final String codePoint = Lc.getCodePoint(this, 2);
|
||||||
return untilDestroy(observable, onNextAction, getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD), Actions.empty());
|
return untilStop(maybe, onSuccessAction, getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable,
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return untilDestroy(observable, onNextAction, onErrorAction, Actions.empty());
|
return until(maybe.toObservable(), isStartedSubject.map(started -> !started), onSuccessAction, onErrorAction, Functions.EMPTY_ACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable,
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable) {
|
||||||
@NonNull final Action1<T> onNextAction,
|
final String codePoint = Lc.getCodePoint(this, 2);
|
||||||
@NonNull final Action1<Throwable> onErrorAction,
|
return untilDestroy(observable, Functions.emptyConsumer(),
|
||||||
@NonNull final Action0 onCompletedAction) {
|
getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD), Functions.EMPTY_ACTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable,
|
||||||
|
@NonNull final Consumer<T> onNextAction) {
|
||||||
|
final String codePoint = Lc.getCodePoint(this, 2);
|
||||||
|
return untilDestroy(observable, onNextAction, getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD), Functions.EMPTY_ACTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable,
|
||||||
|
@NonNull final Consumer<T> onNextAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
|
return untilDestroy(observable, onNextAction, onErrorAction, Functions.EMPTY_ACTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable,
|
||||||
|
@NonNull final Consumer<T> onNextAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction,
|
||||||
|
@NonNull final Action onCompletedAction) {
|
||||||
return until(observable, isCreatedSubject.map(created -> !created), onNextAction, onErrorAction, onCompletedAction);
|
return until(observable, isCreatedSubject.map(created -> !created), onNextAction, onErrorAction, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single) {
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single) {
|
||||||
final String codePoint = Lc.getCodePoint(this, 2);
|
final String codePoint = Lc.getCodePoint(this, 2);
|
||||||
return untilDestroy(single, Actions.empty(), getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD));
|
return untilDestroy(single, Functions.emptyConsumer(), getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
final String codePoint = Lc.getCodePoint(this, 2);
|
final String codePoint = Lc.getCodePoint(this, 2);
|
||||||
return untilDestroy(single, onSuccessAction, getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD));
|
return untilDestroy(single, onSuccessAction, getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single,
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single,
|
||||||
@NonNull final Action1<T> onSuccessAction,
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return until(single.toObservable(), isCreatedSubject.map(created -> !created), onSuccessAction, onErrorAction, Actions.empty());
|
return until(single.toObservable(), isCreatedSubject.map(created -> !created), onSuccessAction, onErrorAction, Functions.EMPTY_ACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable) {
|
public Disposable untilDestroy(@NonNull final Completable completable) {
|
||||||
final String codePoint = Lc.getCodePoint(this, 2);
|
final String codePoint = Lc.getCodePoint(this, 2);
|
||||||
return untilDestroy(completable, Actions.empty(), getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD));
|
return untilDestroy(completable, Functions.EMPTY_ACTION, getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
|
public Disposable untilDestroy(@NonNull final Completable completable, @NonNull final Action onCompletedAction) {
|
||||||
final String codePoint = Lc.getCodePoint(this, 2);
|
final String codePoint = Lc.getCodePoint(this, 2);
|
||||||
return untilDestroy(completable, onCompletedAction, getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD));
|
return untilDestroy(completable, onCompletedAction, getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable,
|
public Disposable untilDestroy(@NonNull final Completable completable,
|
||||||
@NonNull final Action0 onCompletedAction,
|
@NonNull final Action onCompletedAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return until(completable.toObservable(), isCreatedSubject.map(created -> !created), Actions.empty(), onErrorAction, onCompletedAction);
|
return until(completable.toObservable(), isCreatedSubject.map(created -> !created),
|
||||||
|
Functions.emptyConsumer(), onErrorAction, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private <T> Subscription until(@NonNull final Observable<T> observable,
|
@Override
|
||||||
@NonNull final Observable<Boolean> conditionSubject,
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe) {
|
||||||
@NonNull final Action1<T> onNextAction,
|
final String codePoint = Lc.getCodePoint(this, 2);
|
||||||
@NonNull final Action1<Throwable> onErrorAction,
|
return untilDestroy(maybe, Functions.emptyConsumer(), getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD));
|
||||||
@NonNull final Action0 onCompletedAction) {
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
|
final String codePoint = Lc.getCodePoint(this, 2);
|
||||||
|
return untilDestroy(maybe, onSuccessAction, getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD));
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe,
|
||||||
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
|
return until(maybe.toObservable(), isCreatedSubject.map(created -> !created), onSuccessAction, onErrorAction, Functions.EMPTY_ACTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private <T> Disposable until(@NonNull final Observable<T> observable,
|
||||||
|
@NonNull final Observable<Boolean> conditionSubject,
|
||||||
|
@NonNull final Consumer<T> onNextAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction,
|
||||||
|
@NonNull final Action onCompletedAction) {
|
||||||
final Observable<T> actualObservable;
|
final Observable<T> actualObservable;
|
||||||
if (onNextAction == Actions.empty() && onErrorAction == (Action1) Actions.empty() && onCompletedAction == Actions.empty()) {
|
if (onNextAction == Functions.emptyConsumer() && onErrorAction == (Consumer) Functions.emptyConsumer()
|
||||||
|
&& onCompletedAction == Functions.EMPTY_ACTION) {
|
||||||
actualObservable = observable;
|
actualObservable = observable;
|
||||||
} else {
|
} else {
|
||||||
actualObservable = observable.observeOn(AndroidSchedulers.mainThread())
|
actualObservable = observable.observeOn(AndroidSchedulers.mainThread())
|
||||||
.doOnCompleted(onCompletedAction)
|
.doOnComplete(onCompletedAction)
|
||||||
.doOnNext(onNextAction)
|
.doOnNext(onNextAction)
|
||||||
.doOnError(onErrorAction);
|
.doOnError(onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
return isCreatedSubject.first()
|
return isCreatedSubject.firstOrError()
|
||||||
.switchMap(created -> created ? actualObservable : Observable.empty())
|
.flatMapObservable(created -> created ? actualObservable : Observable.empty())
|
||||||
.takeUntil(conditionSubject.filter(condition -> condition))
|
.takeUntil(conditionSubject.filter(condition -> condition))
|
||||||
.onErrorResumeNext(throwable -> {
|
.onErrorResumeNext(throwable -> {
|
||||||
final boolean isRxError = throwable instanceof OnErrorThrowable;
|
if (throwable instanceof RuntimeException) {
|
||||||
if ((!isRxError && throwable instanceof RuntimeException)
|
|
||||||
|| (isRxError && throwable.getCause() instanceof RuntimeException)) {
|
|
||||||
Lc.assertion(throwable);
|
Lc.assertion(throwable);
|
||||||
}
|
}
|
||||||
return Observable.empty();
|
return Observable.empty();
|
||||||
|
|
@ -288,7 +329,7 @@ public class BaseLifecycleBindable implements LifecycleBindable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private Action1<Throwable> getActionThrowableForAssertion(@NonNull final String codePoint, @NonNull final String method) {
|
private Consumer<Throwable> getActionThrowableForAssertion(@NonNull final String codePoint, @NonNull final String method) {
|
||||||
return throwable -> Lc.assertion(new ShouldNotHappenException("Unexpected error on " + method + " at " + codePoint, throwable));
|
return throwable -> Lc.assertion(new ShouldNotHappenException("Unexpected error on " + method + " at " + codePoint, throwable));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,17 @@ package ru.touchin.roboswag.components.utils;
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import rx.Completable;
|
import io.reactivex.Completable;
|
||||||
import rx.CompletableSubscriber;
|
import io.reactivex.CompletableEmitter;
|
||||||
import rx.Observable;
|
import io.reactivex.Emitter;
|
||||||
import rx.Single;
|
import io.reactivex.Maybe;
|
||||||
import rx.SingleSubscriber;
|
import io.reactivex.MaybeEmitter;
|
||||||
import rx.Subscriber;
|
import io.reactivex.Observable;
|
||||||
import rx.Subscription;
|
import io.reactivex.Single;
|
||||||
import rx.functions.Action0;
|
import io.reactivex.SingleEmitter;
|
||||||
import rx.functions.Action1;
|
import io.reactivex.disposables.Disposable;
|
||||||
|
import io.reactivex.functions.Action;
|
||||||
|
import io.reactivex.functions.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gavriil Sitnikov on 15/04/16.
|
* Created by Gavriil Sitnikov on 15/04/16.
|
||||||
|
|
@ -49,10 +51,10 @@ public interface LifecycleBindable {
|
||||||
*
|
*
|
||||||
* @param observable {@link Observable} to subscribe until onStop;
|
* @param observable {@link Observable} to subscribe until onStop;
|
||||||
* @param <T> Type of emitted by observable items;
|
* @param <T> Type of emitted by observable items;
|
||||||
* @return {@link Subscription} which will unsubscribes from observable onStop.
|
* @return {@link Disposable} which will unsubscribes from observable onStop.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
<T> Subscription untilStop(@NonNull Observable<T> observable);
|
<T> Disposable untilStop(@NonNull Observable<T> observable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that observable won't be subscribed after onStop.
|
* Method should be used to guarantee that observable won't be subscribed after onStop.
|
||||||
|
|
@ -61,12 +63,12 @@ public interface LifecycleBindable {
|
||||||
* Don't forget to process errors if observable can emit them.
|
* Don't forget to process errors if observable can emit them.
|
||||||
*
|
*
|
||||||
* @param observable {@link Observable} to subscribe until onStop;
|
* @param observable {@link Observable} to subscribe until onStop;
|
||||||
* @param onNextAction Action which will raise on every {@link Subscriber#onNext(Object)} item;
|
* @param onNextAction Action which will raise on every {@link Emitter#onNext(Object)} item;
|
||||||
* @param <T> Type of emitted by observable items;
|
* @param <T> Type of emitted by observable items;
|
||||||
* @return {@link Subscription} which will unsubscribes from observable onStop.
|
* @return {@link Disposable} which will unsubscribes from observable onStop.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
<T> Subscription untilStop(@NonNull Observable<T> observable, @NonNull Action1<T> onNextAction);
|
<T> Disposable untilStop(@NonNull Observable<T> observable, @NonNull Consumer<T> onNextAction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that observable won't be subscribed after onStop.
|
* Method should be used to guarantee that observable won't be subscribed after onStop.
|
||||||
|
|
@ -75,13 +77,13 @@ public interface LifecycleBindable {
|
||||||
* Don't forget to process errors if observable can emit them.
|
* Don't forget to process errors if observable can emit them.
|
||||||
*
|
*
|
||||||
* @param observable {@link Observable} to subscribe until onStop;
|
* @param observable {@link Observable} to subscribe until onStop;
|
||||||
* @param onNextAction Action which will raise on every {@link Subscriber#onNext(Object)} item;
|
* @param onNextAction Action which will raise on every {@link Emitter#onNext(Object)} item;
|
||||||
* @param onErrorAction Action which will raise on every {@link Subscriber#onError(Throwable)} throwable;
|
* @param onErrorAction Action which will raise on every {@link Emitter#onError(Throwable)} throwable;
|
||||||
* @param <T> Type of emitted by observable items;
|
* @param <T> Type of emitted by observable items;
|
||||||
* @return {@link Subscription} which will unsubscribes from observable onStop.
|
* @return {@link Disposable} which will unsubscribes from observable onStop.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
<T> Subscription untilStop(@NonNull Observable<T> observable, @NonNull Action1<T> onNextAction, @NonNull Action1<Throwable> onErrorAction);
|
<T> Disposable untilStop(@NonNull Observable<T> observable, @NonNull Consumer<T> onNextAction, @NonNull Consumer<Throwable> onErrorAction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that observable won't be subscribed after onStop.
|
* Method should be used to guarantee that observable won't be subscribed after onStop.
|
||||||
|
|
@ -90,15 +92,15 @@ public interface LifecycleBindable {
|
||||||
* Don't forget to process errors if observable can emit them.
|
* Don't forget to process errors if observable can emit them.
|
||||||
*
|
*
|
||||||
* @param observable {@link Observable} to subscribe until onStop;
|
* @param observable {@link Observable} to subscribe until onStop;
|
||||||
* @param onNextAction Action which will raise on every {@link Subscriber#onNext(Object)} item;
|
* @param onNextAction Action which will raise on every {@link Emitter#onNext(Object)} item;
|
||||||
* @param onErrorAction Action which will raise on every {@link Subscriber#onError(Throwable)} throwable;
|
* @param onErrorAction Action which will raise on every {@link Emitter#onError(Throwable)} throwable;
|
||||||
* @param onCompletedAction Action which will raise at {@link Subscriber#onCompleted()} on completion of observable;
|
* @param onCompletedAction Action which will raise at {@link Emitter#onComplete()} on completion of observable;
|
||||||
* @param <T> Type of emitted by observable items;
|
* @param <T> Type of emitted by observable items;
|
||||||
* @return {@link Subscription} which is wrapping source observable to unsubscribe from it onStop.
|
* @return {@link Disposable} which is wrapping source observable to unsubscribe from it onStop.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
<T> Subscription untilStop(@NonNull Observable<T> observable,
|
<T> Disposable untilStop(@NonNull Observable<T> observable,
|
||||||
@NonNull Action1<T> onNextAction, @NonNull Action1<Throwable> onErrorAction, @NonNull Action0 onCompletedAction);
|
@NonNull Consumer<T> onNextAction, @NonNull Consumer<Throwable> onErrorAction, @NonNull Action onCompletedAction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that single won't be subscribed after onStop.
|
* Method should be used to guarantee that single won't be subscribed after onStop.
|
||||||
|
|
@ -108,10 +110,10 @@ public interface LifecycleBindable {
|
||||||
*
|
*
|
||||||
* @param single {@link Single} to subscribe until onStop;
|
* @param single {@link Single} to subscribe until onStop;
|
||||||
* @param <T> Type of emitted by single item;
|
* @param <T> Type of emitted by single item;
|
||||||
* @return {@link Subscription} which will unsubscribes from single onStop.
|
* @return {@link Disposable} which will unsubscribes from single onStop.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
<T> Subscription untilStop(@NonNull Single<T> single);
|
<T> Disposable untilStop(@NonNull Single<T> single);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that single won't be subscribed after onStop.
|
* Method should be used to guarantee that single won't be subscribed after onStop.
|
||||||
|
|
@ -120,12 +122,12 @@ public interface LifecycleBindable {
|
||||||
* Don't forget to process errors if single can emit them.
|
* Don't forget to process errors if single can emit them.
|
||||||
*
|
*
|
||||||
* @param single {@link Single} to subscribe until onStop;
|
* @param single {@link Single} to subscribe until onStop;
|
||||||
* @param onSuccessAction Action which will raise on every {@link SingleSubscriber#onSuccess(Object)} item;
|
* @param onSuccessAction Action which will raise on every {@link SingleEmitter#onSuccess(Object)} item;
|
||||||
* @param <T> Type of emitted by single item;
|
* @param <T> Type of emitted by single item;
|
||||||
* @return {@link Subscription} which will unsubscribes from single onStop.
|
* @return {@link Disposable} which will unsubscribes from single onStop.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
<T> Subscription untilStop(@NonNull Single<T> single, @NonNull Action1<T> onSuccessAction);
|
<T> Disposable untilStop(@NonNull Single<T> single, @NonNull Consumer<T> onSuccessAction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that single won't be subscribed after onStop.
|
* Method should be used to guarantee that single won't be subscribed after onStop.
|
||||||
|
|
@ -134,13 +136,13 @@ public interface LifecycleBindable {
|
||||||
* Don't forget to process errors if single can emit them.
|
* Don't forget to process errors if single can emit them.
|
||||||
*
|
*
|
||||||
* @param single {@link Single} to subscribe until onStop;
|
* @param single {@link Single} to subscribe until onStop;
|
||||||
* @param onSuccessAction Action which will raise on every {@link SingleSubscriber#onSuccess(Object)} item;
|
* @param onSuccessAction Action which will raise on every {@link SingleEmitter#onSuccess(Object)} item;
|
||||||
* @param onErrorAction Action which will raise on every {@link SingleSubscriber#onError(Throwable)} throwable;
|
* @param onErrorAction Action which will raise on every {@link SingleEmitter#onError(Throwable)} throwable;
|
||||||
* @param <T> Type of emitted by observable items;
|
* @param <T> Type of emitted by observable items;
|
||||||
* @return {@link Subscription} which is wrapping source single to unsubscribe from it onStop.
|
* @return {@link Disposable} which is wrapping source single to unsubscribe from it onStop.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
<T> Subscription untilStop(@NonNull Single<T> single, @NonNull Action1<T> onSuccessAction, @NonNull Action1<Throwable> onErrorAction);
|
<T> Disposable untilStop(@NonNull Single<T> single, @NonNull Consumer<T> onSuccessAction, @NonNull Consumer<Throwable> onErrorAction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that completable won't be subscribed after onStop.
|
* Method should be used to guarantee that completable won't be subscribed after onStop.
|
||||||
|
|
@ -149,10 +151,10 @@ public interface LifecycleBindable {
|
||||||
* Don't forget to process errors if completable can emit them.
|
* Don't forget to process errors if completable can emit them.
|
||||||
*
|
*
|
||||||
* @param completable {@link Completable} to subscribe until onStop;
|
* @param completable {@link Completable} to subscribe until onStop;
|
||||||
* @return {@link Subscription} which will unsubscribes from completable onStop.
|
* @return {@link Disposable} which will unsubscribes from completable onStop.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
Subscription untilStop(@NonNull Completable completable);
|
Disposable untilStop(@NonNull Completable completable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that completable won't be subscribed after onStop.
|
* Method should be used to guarantee that completable won't be subscribed after onStop.
|
||||||
|
|
@ -161,11 +163,11 @@ public interface LifecycleBindable {
|
||||||
* Don't forget to process errors if completable can emit them.
|
* Don't forget to process errors if completable can emit them.
|
||||||
*
|
*
|
||||||
* @param completable {@link Completable} to subscribe until onStop;
|
* @param completable {@link Completable} to subscribe until onStop;
|
||||||
* @param onCompletedAction Action which will raise at {@link CompletableSubscriber#onCompleted()} on completion of observable;
|
* @param onCompletedAction Action which will raise at {@link CompletableEmitter#onComplete()} on completion of observable;
|
||||||
* @return {@link Subscription} which is wrapping source completable to unsubscribe from it onStop.
|
* @return {@link Disposable} which is wrapping source completable to unsubscribe from it onStop.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
Subscription untilStop(@NonNull Completable completable, @NonNull Action0 onCompletedAction);
|
Disposable untilStop(@NonNull Completable completable, @NonNull Action onCompletedAction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that completable won't be subscribed after onStop.
|
* Method should be used to guarantee that completable won't be subscribed after onStop.
|
||||||
|
|
@ -174,12 +176,51 @@ public interface LifecycleBindable {
|
||||||
* Don't forget to process errors if completable can emit them.
|
* Don't forget to process errors if completable can emit them.
|
||||||
*
|
*
|
||||||
* @param completable {@link Completable} to subscribe until onStop;
|
* @param completable {@link Completable} to subscribe until onStop;
|
||||||
* @param onCompletedAction Action which will raise at {@link CompletableSubscriber#onCompleted()} on completion of observable;
|
* @param onCompletedAction Action which will raise at {@link CompletableEmitter#onComplete()} on completion of observable;
|
||||||
* @param onErrorAction Action which will raise on every {@link CompletableSubscriber#onError(Throwable)} throwable;
|
* @param onErrorAction Action which will raise on every {@link CompletableEmitter#onError(Throwable)} throwable;
|
||||||
* @return {@link Subscription} which is wrapping source completable to unsubscribe from it onStop.
|
* @return {@link Disposable} which is wrapping source completable to unsubscribe from it onStop.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
Subscription untilStop(@NonNull Completable completable, @NonNull Action0 onCompletedAction, @NonNull Action1<Throwable> onErrorAction);
|
Disposable untilStop(@NonNull Completable completable, @NonNull Action onCompletedAction, @NonNull Consumer<Throwable> onErrorAction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method should be used to guarantee that maybe won't be subscribed after onStop.
|
||||||
|
* It is automatically subscribing to the maybe.
|
||||||
|
* Usually it is using to stop requests/execution while element is off or to not do illegal actions after onStop like fragment's stack changing.
|
||||||
|
* Don't forget to process errors if completable can emit them.
|
||||||
|
*
|
||||||
|
* @param maybe {@link Maybe} to subscribe until onStop;
|
||||||
|
* @return {@link Disposable} which will unsubscribes from completable onStop.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
<T> Disposable untilStop(@NonNull Maybe<T> maybe);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method should be used to guarantee that maybe won't be subscribed after onStop.
|
||||||
|
* It is automatically subscribing to the maybe and calls onCompletedAction on maybe item.
|
||||||
|
* Usually it is using to stop requests/execution while element is off or to not do illegal actions after onStop like fragment's stack changing.
|
||||||
|
* Don't forget to process errors if completable can emit them.
|
||||||
|
*
|
||||||
|
* @param maybe {@link Maybe} to subscribe until onStop;
|
||||||
|
* @param onSuccessAction Action which will raise at {@link MaybeEmitter#onSuccess(Object)} ()} on completion of observable;
|
||||||
|
* @return {@link Disposable} which is wrapping source maybe to unsubscribe from it onStop.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
<T> Disposable untilStop(@NonNull Maybe<T> maybe, @NonNull Consumer<T> onSuccessAction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method should be used to guarantee that maybe won't be subscribed after onStop.
|
||||||
|
* It is automatically subscribing to the maybe and calls onCompletedAction and onErrorAction on maybe item.
|
||||||
|
* Usually it is using to stop requests/execution while element is off or to not do illegal actions after onStop like fragment's stack changing.
|
||||||
|
* Don't forget to process errors if completable can emit them.
|
||||||
|
*
|
||||||
|
* @param maybe {@link Maybe} to subscribe until onStop;
|
||||||
|
* @param onSuccessAction Action which will raise at {@link MaybeEmitter#onSuccess(Object)} ()} on completion of observable;
|
||||||
|
* @param onErrorAction Action which will raise on every {@link MaybeEmitter#onError(Throwable)} throwable;
|
||||||
|
* @return {@link Disposable} which is wrapping source maybe to unsubscribe from it onStop.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
<T> Disposable untilStop(@NonNull Maybe<T> maybe, @NonNull Consumer<T> onSuccessAction, @NonNull Consumer<Throwable> onErrorAction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that observable won't be subscribed after onDestroy.
|
* Method should be used to guarantee that observable won't be subscribed after onDestroy.
|
||||||
|
|
@ -188,10 +229,10 @@ public interface LifecycleBindable {
|
||||||
*
|
*
|
||||||
* @param observable {@link Observable} to subscribe until onDestroy;
|
* @param observable {@link Observable} to subscribe until onDestroy;
|
||||||
* @param <T> Type of emitted by observable items;
|
* @param <T> Type of emitted by observable items;
|
||||||
* @return {@link Subscription} which is wrapping source observable to unsubscribe from it onDestroy.
|
* @return {@link Disposable} which is wrapping source maybe to unsubscribe from it onDestroy.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
<T> Subscription untilDestroy(@NonNull Observable<T> observable);
|
<T> Disposable untilDestroy(@NonNull Observable<T> observable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that observable won't be subscribed after onDestroy.
|
* Method should be used to guarantee that observable won't be subscribed after onDestroy.
|
||||||
|
|
@ -199,12 +240,12 @@ public interface LifecycleBindable {
|
||||||
* Don't forget to process errors if observable can emit them.
|
* Don't forget to process errors if observable can emit them.
|
||||||
*
|
*
|
||||||
* @param observable {@link Observable} to subscribe until onDestroy;
|
* @param observable {@link Observable} to subscribe until onDestroy;
|
||||||
* @param onNextAction Action which will raise on every {@link Subscriber#onNext(Object)} item;
|
* @param onNextAction Action which will raise on every {@link Emitter#onNext(Object)} item;
|
||||||
* @param <T> Type of emitted by observable items;
|
* @param <T> Type of emitted by observable items;
|
||||||
* @return {@link Subscription} which is wrapping source observable to unsubscribe from it onDestroy.
|
* @return {@link Disposable} which is wrapping source observable to unsubscribe from it onDestroy.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
<T> Subscription untilDestroy(@NonNull Observable<T> observable, @NonNull Action1<T> onNextAction);
|
<T> Disposable untilDestroy(@NonNull Observable<T> observable, @NonNull Consumer<T> onNextAction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that observable won't be subscribed after onDestroy.
|
* Method should be used to guarantee that observable won't be subscribed after onDestroy.
|
||||||
|
|
@ -212,13 +253,13 @@ public interface LifecycleBindable {
|
||||||
* Don't forget to process errors if observable can emit them.
|
* Don't forget to process errors if observable can emit them.
|
||||||
*
|
*
|
||||||
* @param observable {@link Observable} to subscribe until onDestroy;
|
* @param observable {@link Observable} to subscribe until onDestroy;
|
||||||
* @param onNextAction Action which will raise on every {@link Subscriber#onNext(Object)} item;
|
* @param onNextAction Action which will raise on every {@link Emitter#onNext(Object)} item;
|
||||||
* @param onErrorAction Action which will raise on every {@link Subscriber#onError(Throwable)} throwable;
|
* @param onErrorAction Action which will raise on every {@link Emitter#onError(Throwable)} throwable;
|
||||||
* @param <T> Type of emitted by observable items;
|
* @param <T> Type of emitted by observable items;
|
||||||
* @return {@link Subscription} which is wrapping source observable to unsubscribe from it onDestroy.
|
* @return {@link Disposable} which is wrapping source observable to unsubscribe from it onDestroy.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
<T> Subscription untilDestroy(@NonNull Observable<T> observable, @NonNull Action1<T> onNextAction, @NonNull Action1<Throwable> onErrorAction);
|
<T> Disposable untilDestroy(@NonNull Observable<T> observable, @NonNull Consumer<T> onNextAction, @NonNull Consumer<Throwable> onErrorAction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that observable won't be subscribed after onDestroy.
|
* Method should be used to guarantee that observable won't be subscribed after onDestroy.
|
||||||
|
|
@ -226,15 +267,15 @@ public interface LifecycleBindable {
|
||||||
* Don't forget to process errors if observable can emit them.
|
* Don't forget to process errors if observable can emit them.
|
||||||
*
|
*
|
||||||
* @param observable {@link Observable} to subscribe until onDestroy;
|
* @param observable {@link Observable} to subscribe until onDestroy;
|
||||||
* @param onNextAction Action which will raise on every {@link Subscriber#onNext(Object)} item;
|
* @param onNextAction Action which will raise on every {@link Emitter#onNext(Object)} item;
|
||||||
* @param onErrorAction Action which will raise on every {@link Subscriber#onError(Throwable)} throwable;
|
* @param onErrorAction Action which will raise on every {@link Emitter#onError(Throwable)} throwable;
|
||||||
* @param onCompletedAction Action which will raise at {@link Subscriber#onCompleted()} on completion of observable;
|
* @param onCompletedAction Action which will raise at {@link Emitter#onComplete()} on completion of observable;
|
||||||
* @param <T> Type of emitted by observable items;
|
* @param <T> Type of emitted by observable items;
|
||||||
* @return {@link Subscription} which is wrapping source observable to unsubscribe from it onDestroy.
|
* @return {@link Disposable} which is wrapping source observable to unsubscribe from it onDestroy.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
<T> Subscription untilDestroy(@NonNull Observable<T> observable,
|
<T> Disposable untilDestroy(@NonNull Observable<T> observable,
|
||||||
@NonNull Action1<T> onNextAction, @NonNull Action1<Throwable> onErrorAction, @NonNull Action0 onCompletedAction);
|
@NonNull Consumer<T> onNextAction, @NonNull Consumer<Throwable> onErrorAction, @NonNull Action onCompletedAction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that single won't be subscribed after onDestroy.
|
* Method should be used to guarantee that single won't be subscribed after onDestroy.
|
||||||
|
|
@ -243,10 +284,10 @@ public interface LifecycleBindable {
|
||||||
*
|
*
|
||||||
* @param single {@link Single} to subscribe until onDestroy;
|
* @param single {@link Single} to subscribe until onDestroy;
|
||||||
* @param <T> Type of emitted by single items;
|
* @param <T> Type of emitted by single items;
|
||||||
* @return {@link Subscription} which is wrapping source single to unsubscribe from it onDestroy.
|
* @return {@link Disposable} which is wrapping source single to unsubscribe from it onDestroy.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
<T> Subscription untilDestroy(@NonNull Single<T> single);
|
<T> Disposable untilDestroy(@NonNull Single<T> single);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that single won't be subscribed after onDestroy.
|
* Method should be used to guarantee that single won't be subscribed after onDestroy.
|
||||||
|
|
@ -254,12 +295,12 @@ public interface LifecycleBindable {
|
||||||
* Don't forget to process errors if single can emit them.
|
* Don't forget to process errors if single can emit them.
|
||||||
*
|
*
|
||||||
* @param single {@link Single} to subscribe until onDestroy;
|
* @param single {@link Single} to subscribe until onDestroy;
|
||||||
* @param onSuccessAction Action which will raise on every {@link SingleSubscriber#onSuccess(Object)} item;
|
* @param onSuccessAction Action which will raise on every {@link SingleEmitter#onSuccess(Object)} item;
|
||||||
* @param <T> Type of emitted by single items;
|
* @param <T> Type of emitted by single items;
|
||||||
* @return {@link Subscription} which is wrapping source single to unsubscribe from it onDestroy.
|
* @return {@link Disposable} which is wrapping source single to unsubscribe from it onDestroy.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
<T> Subscription untilDestroy(@NonNull Single<T> single, @NonNull Action1<T> onSuccessAction);
|
<T> Disposable untilDestroy(@NonNull Single<T> single, @NonNull Consumer<T> onSuccessAction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that single won't be subscribed after onDestroy.
|
* Method should be used to guarantee that single won't be subscribed after onDestroy.
|
||||||
|
|
@ -267,13 +308,13 @@ public interface LifecycleBindable {
|
||||||
* Don't forget to process errors if single can emit them.
|
* Don't forget to process errors if single can emit them.
|
||||||
*
|
*
|
||||||
* @param single {@link Single} to subscribe until onDestroy;
|
* @param single {@link Single} to subscribe until onDestroy;
|
||||||
* @param onSuccessAction Action which will raise on every {@link SingleSubscriber#onSuccess(Object)} item;
|
* @param onSuccessAction Action which will raise on every {@link SingleEmitter#onSuccess(Object)} item;
|
||||||
* @param onErrorAction Action which will raise on every {@link SingleSubscriber#onError(Throwable)} throwable;
|
* @param onErrorAction Action which will raise on every {@link SingleEmitter#onError(Throwable)} throwable;
|
||||||
* @param <T> Type of emitted by single items;
|
* @param <T> Type of emitted by single items;
|
||||||
* @return {@link Subscription} which is wrapping source single to unsubscribe from it onDestroy.
|
* @return {@link Disposable} which is wrapping source single to unsubscribe from it onDestroy.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
<T> Subscription untilDestroy(@NonNull Single<T> single, @NonNull Action1<T> onSuccessAction, @NonNull Action1<Throwable> onErrorAction);
|
<T> Disposable untilDestroy(@NonNull Single<T> single, @NonNull Consumer<T> onSuccessAction, @NonNull Consumer<Throwable> onErrorAction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that completable won't be subscribed after onDestroy.
|
* Method should be used to guarantee that completable won't be subscribed after onDestroy.
|
||||||
|
|
@ -281,22 +322,22 @@ public interface LifecycleBindable {
|
||||||
* Don't forget to process errors if completable can emit them.
|
* Don't forget to process errors if completable can emit them.
|
||||||
*
|
*
|
||||||
* @param completable {@link Completable} to subscribe until onDestroy;
|
* @param completable {@link Completable} to subscribe until onDestroy;
|
||||||
* @return {@link Subscription} which is wrapping source completable to unsubscribe from it onDestroy.
|
* @return {@link Disposable} which is wrapping source completable to unsubscribe from it onDestroy.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
Subscription untilDestroy(@NonNull Completable completable);
|
Disposable untilDestroy(@NonNull Completable completable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that completable won't be subscribed after onDestroy.
|
* Method should be used to guarantee that completable won't be subscribed after onDestroy.
|
||||||
* It is automatically subscribing to the completable and calls onCompletedAction on completable item.
|
* It is automatically subscribing to the completable and calls onCompletedAction on completable item.
|
||||||
* Don't forget to process errors if single can emit them.
|
* Don't forget to process errors if completable can emit them.
|
||||||
*
|
*
|
||||||
* @param completable {@link Completable} to subscribe until onDestroy;
|
* @param completable {@link Completable} to subscribe until onDestroy;
|
||||||
* @param onCompletedAction Action which will raise on every {@link CompletableSubscriber#onCompleted()} item;
|
* @param onCompletedAction Action which will raise on every {@link CompletableEmitter#onComplete()} item;
|
||||||
* @return {@link Subscription} which is wrapping source single to unsubscribe from it onDestroy.
|
* @return {@link Disposable} which is wrapping source single to unsubscribe from it onDestroy.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
Subscription untilDestroy(@NonNull Completable completable, @NonNull Action0 onCompletedAction);
|
Disposable untilDestroy(@NonNull Completable completable, @NonNull Action onCompletedAction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method should be used to guarantee that completable won't be subscribed after onDestroy.
|
* Method should be used to guarantee that completable won't be subscribed after onDestroy.
|
||||||
|
|
@ -304,11 +345,47 @@ public interface LifecycleBindable {
|
||||||
* Don't forget to process errors if completable can emit them.
|
* Don't forget to process errors if completable can emit them.
|
||||||
*
|
*
|
||||||
* @param completable {@link Completable} to subscribe until onDestroy;
|
* @param completable {@link Completable} to subscribe until onDestroy;
|
||||||
* @param onCompletedAction Action which will raise on every {@link CompletableSubscriber#onCompleted()} item;
|
* @param onCompletedAction Action which will raise on every {@link CompletableEmitter#onComplete()} item;
|
||||||
* @param onErrorAction Action which will raise on every {@link CompletableSubscriber#onError(Throwable)} throwable;
|
* @param onErrorAction Action which will raise on every {@link CompletableEmitter#onError(Throwable)} throwable;
|
||||||
* @return {@link Subscription} which is wrapping source completable to unsubscribe from it onDestroy.
|
* @return {@link Disposable} which is wrapping source completable to unsubscribe from it onDestroy.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
Subscription untilDestroy(@NonNull Completable completable, @NonNull Action0 onCompletedAction, @NonNull Action1<Throwable> onErrorAction);
|
Disposable untilDestroy(@NonNull Completable completable, @NonNull Action onCompletedAction, @NonNull Consumer<Throwable> onErrorAction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method should be used to guarantee that maybe won't be subscribed after onDestroy.
|
||||||
|
* It is automatically subscribing to the maybe.
|
||||||
|
* Don't forget to process errors if maybe can emit them.
|
||||||
|
*
|
||||||
|
* @param maybe {@link Maybe} to subscribe until onDestroy;
|
||||||
|
* @return {@link Disposable} which is wrapping source maybe to unsubscribe from it onDestroy.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
<T> Disposable untilDestroy(@NonNull Maybe<T> maybe);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method should be used to guarantee that maybe won't be subscribed after onDestroy.
|
||||||
|
* It is automatically subscribing to the maybe and calls onCompletedAction on maybe item.
|
||||||
|
* Don't forget to process errors if maybe can emit them.
|
||||||
|
*
|
||||||
|
* @param maybe {@link Maybe} to subscribe until onDestroy;
|
||||||
|
* @param onSuccessAction Action which will raise on every {@link MaybeEmitter#onSuccess(Object)} ()} item;
|
||||||
|
* @return {@link Disposable} which is wrapping source maybe to unsubscribe from it onDestroy.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
<T> Disposable untilDestroy(@NonNull Maybe<T> maybe, @NonNull Consumer<T> onSuccessAction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method should be used to guarantee that maybe won't be subscribed after onDestroy.
|
||||||
|
* It is automatically subscribing to the maybe and calls onSuccessAction and onErrorAction on maybe events.
|
||||||
|
* Don't forget to process errors if completable can emit them.
|
||||||
|
*
|
||||||
|
* @param maybe {@link Maybe} to subscribe until onDestroy;
|
||||||
|
* @param onSuccessAction Action which will raise on every {@link MaybeEmitter#onSuccess(Object)} ()} item;
|
||||||
|
* @param onErrorAction Action which will raise on every {@link MaybeEmitter#onError(Throwable)} throwable;
|
||||||
|
* @return {@link Disposable} which is wrapping source maybe to unsubscribe from it onDestroy.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
<T> Disposable untilDestroy(@NonNull Maybe<T> maybe, @NonNull Consumer<T> onSuccessAction, @NonNull Consumer<Throwable> onErrorAction);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -27,8 +27,8 @@ import java.lang.reflect.Constructor;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import io.reactivex.Observable;
|
||||||
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
|
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
|
||||||
import rx.Observable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gavriil Sitnikov on 24/03/16.
|
* Created by Gavriil Sitnikov on 24/03/16.
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,11 @@ import android.view.ViewGroup;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import io.reactivex.functions.Action;
|
||||||
|
import io.reactivex.functions.Consumer;
|
||||||
import ru.touchin.roboswag.components.navigation.activities.BaseActivity;
|
import ru.touchin.roboswag.components.navigation.activities.BaseActivity;
|
||||||
|
import ru.touchin.roboswag.core.log.Lc;
|
||||||
import ru.touchin.roboswag.core.log.LcGroup;
|
import ru.touchin.roboswag.core.log.LcGroup;
|
||||||
import rx.functions.Action0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gavriil Sitnikov on 13/11/2015.
|
* Created by Gavriil Sitnikov on 13/11/2015.
|
||||||
|
|
@ -100,8 +102,8 @@ public final class UiUtils {
|
||||||
* @param onClickListener Click listener;
|
* @param onClickListener Click listener;
|
||||||
* @param delay Delay after which click listener will be called.
|
* @param delay Delay after which click listener will be called.
|
||||||
*/
|
*/
|
||||||
public static void setOnRippleClickListener(@NonNull final View targetView, @Nullable final Action0 onClickListener, final long delay) {
|
public static void setOnRippleClickListener(@NonNull final View targetView, @Nullable final Action onClickListener, final long delay) {
|
||||||
setOnRippleClickListener(targetView, onClickListener != null ? v -> onClickListener.call() : null, delay);
|
setOnRippleClickListener(targetView, onClickListener != null ? view -> onClickListener.run() : null, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -110,18 +112,8 @@ public final class UiUtils {
|
||||||
* @param targetView View to set click listener to;
|
* @param targetView View to set click listener to;
|
||||||
* @param onClickListener Click listener.
|
* @param onClickListener Click listener.
|
||||||
*/
|
*/
|
||||||
public static void setOnRippleClickListener(@NonNull final View targetView, @Nullable final Action0 onClickListener) {
|
public static void setOnRippleClickListener(@NonNull final View targetView, @Nullable final Action onClickListener) {
|
||||||
setOnRippleClickListener(targetView, onClickListener != null ? v -> onClickListener.call() : null, RIPPLE_EFFECT_DELAY);
|
setOnRippleClickListener(targetView, onClickListener != null ? view -> onClickListener.run() : null, RIPPLE_EFFECT_DELAY);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets click listener to view. On click it will call something with {@link #RIPPLE_EFFECT_DELAY}.
|
|
||||||
*
|
|
||||||
* @param targetView View to set click listener to;
|
|
||||||
* @param onClickListener Click listener.
|
|
||||||
*/
|
|
||||||
public static void setOnRippleClickListener(@NonNull final View targetView, @Nullable final View.OnClickListener onClickListener) {
|
|
||||||
setOnRippleClickListener(targetView, onClickListener, RIPPLE_EFFECT_DELAY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -131,9 +123,7 @@ public final class UiUtils {
|
||||||
* @param onClickListener Click listener;
|
* @param onClickListener Click listener;
|
||||||
* @param delay Delay after which click listener will be called.
|
* @param delay Delay after which click listener will be called.
|
||||||
*/
|
*/
|
||||||
public static void setOnRippleClickListener(@NonNull final View targetView,
|
public static void setOnRippleClickListener(@NonNull final View targetView, @Nullable final Consumer<View> onClickListener, final long delay) {
|
||||||
@Nullable final View.OnClickListener onClickListener,
|
|
||||||
final long delay) {
|
|
||||||
if (onClickListener == null) {
|
if (onClickListener == null) {
|
||||||
targetView.setOnClickListener(null);
|
targetView.setOnClickListener(null);
|
||||||
return;
|
return;
|
||||||
|
|
@ -145,7 +135,11 @@ public final class UiUtils {
|
||||||
|| (targetView.getContext() instanceof BaseActivity && !((BaseActivity) targetView.getContext()).isActuallyResumed())) {
|
|| (targetView.getContext() instanceof BaseActivity && !((BaseActivity) targetView.getContext()).isActuallyResumed())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
onClickListener.onClick(targetView);
|
try {
|
||||||
|
onClickListener.accept(targetView);
|
||||||
|
} catch (final Exception exception) {
|
||||||
|
Lc.assertion(exception);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
targetView.setOnClickListener(v -> {
|
targetView.setOnClickListener(v -> {
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ import android.content.IntentFilter;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import rx.Observable;
|
import io.reactivex.Observable;
|
||||||
import rx.subjects.BehaviorSubject;
|
import io.reactivex.subjects.BehaviorSubject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gavriil Sitnikov on 02/11/2015.
|
* Created by Gavriil Sitnikov on 02/11/2015.
|
||||||
|
|
@ -50,12 +50,12 @@ public final class HeadsetStateObserver {
|
||||||
isConnectedReceiver.isWirelessConnectedChangedEvent,
|
isConnectedReceiver.isWirelessConnectedChangedEvent,
|
||||||
(isWiredConnected, isWirelessConnected) -> isWiredConnected || isWirelessConnected)
|
(isWiredConnected, isWirelessConnected) -> isWiredConnected || isWirelessConnected)
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.doOnSubscribe(() -> {
|
.doOnSubscribe(disposable -> {
|
||||||
final IntentFilter headsetStateIntentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
|
final IntentFilter headsetStateIntentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
|
||||||
headsetStateIntentFilter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
|
headsetStateIntentFilter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
|
||||||
context.registerReceiver(isConnectedReceiver, headsetStateIntentFilter);
|
context.registerReceiver(isConnectedReceiver, headsetStateIntentFilter);
|
||||||
})
|
})
|
||||||
.doOnUnsubscribe(() -> context.unregisterReceiver(isConnectedReceiver)))
|
.doOnDispose(() -> context.unregisterReceiver(isConnectedReceiver)))
|
||||||
.replay(1)
|
.replay(1)
|
||||||
.refCount();
|
.refCount();
|
||||||
}
|
}
|
||||||
|
|
@ -90,8 +90,8 @@ public final class HeadsetStateObserver {
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public IsConnectedReceiver(@NonNull final AudioManager audioManager) {
|
public IsConnectedReceiver(@NonNull final AudioManager audioManager) {
|
||||||
super();
|
super();
|
||||||
isWiredConnectedChangedEvent = BehaviorSubject.create(audioManager.isWiredHeadsetOn());
|
isWiredConnectedChangedEvent = BehaviorSubject.createDefault(audioManager.isWiredHeadsetOn());
|
||||||
isWirelessConnectedChangedEvent = BehaviorSubject.create(audioManager.isBluetoothA2dpOn());
|
isWirelessConnectedChangedEvent = BehaviorSubject.createDefault(audioManager.isBluetoothA2dpOn());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,10 @@ import android.os.Looper;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
|
import io.reactivex.Observable;
|
||||||
|
import io.reactivex.subjects.PublishSubject;
|
||||||
import ru.touchin.roboswag.core.log.Lc;
|
import ru.touchin.roboswag.core.log.Lc;
|
||||||
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
|
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
|
||||||
import rx.Observable;
|
|
||||||
import rx.subjects.PublishSubject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gavriil Sitnikov on 02/11/2015.
|
* Created by Gavriil Sitnikov on 02/11/2015.
|
||||||
|
|
@ -58,9 +58,9 @@ public final class VolumeController {
|
||||||
.switchMap(volumeObserver -> selfVolumeChangedEvent
|
.switchMap(volumeObserver -> selfVolumeChangedEvent
|
||||||
.mergeWith(volumeObserver.systemVolumeChangedEvent
|
.mergeWith(volumeObserver.systemVolumeChangedEvent
|
||||||
.map(event -> getVolume())
|
.map(event -> getVolume())
|
||||||
.doOnSubscribe(() -> context.getContentResolver()
|
.doOnSubscribe(disposable -> context.getContentResolver()
|
||||||
.registerContentObserver(Settings.System.CONTENT_URI, true, volumeObserver))
|
.registerContentObserver(Settings.System.CONTENT_URI, true, volumeObserver))
|
||||||
.doOnUnsubscribe(() -> context.getContentResolver()
|
.doOnDispose(() -> context.getContentResolver()
|
||||||
.unregisterContentObserver(volumeObserver)))
|
.unregisterContentObserver(volumeObserver)))
|
||||||
.startWith(getVolume()))
|
.startWith(getVolume()))
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ import java.lang.reflect.Type;
|
||||||
import ru.touchin.roboswag.core.log.Lc;
|
import ru.touchin.roboswag.core.log.Lc;
|
||||||
import ru.touchin.roboswag.core.observables.storable.Store;
|
import ru.touchin.roboswag.core.observables.storable.Store;
|
||||||
import ru.touchin.roboswag.core.utils.Optional;
|
import ru.touchin.roboswag.core.utils.Optional;
|
||||||
import rx.Completable;
|
import io.reactivex.Completable;
|
||||||
import rx.Single;
|
import io.reactivex.Single;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import java.lang.reflect.Type;
|
||||||
import ru.touchin.roboswag.core.observables.storable.Converter;
|
import ru.touchin.roboswag.core.observables.storable.Converter;
|
||||||
import ru.touchin.roboswag.core.observables.storable.SameTypesConverter;
|
import ru.touchin.roboswag.core.observables.storable.SameTypesConverter;
|
||||||
import ru.touchin.roboswag.core.observables.storable.Storable;
|
import ru.touchin.roboswag.core.observables.storable.Storable;
|
||||||
import ru.touchin.roboswag.core.observables.storable.concrete.NonNullStorable;
|
import ru.touchin.roboswag.core.observables.storable.NonNullStorable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gavriil Sitnikov on 01/09/2016.
|
* Created by Gavriil Sitnikov on 01/09/2016.
|
||||||
|
|
|
||||||
|
|
@ -28,14 +28,15 @@ import android.support.annotation.Nullable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
|
import io.reactivex.Maybe;
|
||||||
import ru.touchin.roboswag.components.utils.BaseLifecycleBindable;
|
import ru.touchin.roboswag.components.utils.BaseLifecycleBindable;
|
||||||
import ru.touchin.roboswag.components.utils.LifecycleBindable;
|
import ru.touchin.roboswag.components.utils.LifecycleBindable;
|
||||||
import rx.Completable;
|
import io.reactivex.Completable;
|
||||||
import rx.Observable;
|
import io.reactivex.Observable;
|
||||||
import rx.Single;
|
import io.reactivex.Single;
|
||||||
import rx.Subscription;
|
import io.reactivex.disposables.Disposable;
|
||||||
import rx.functions.Action0;
|
import io.reactivex.functions.Action;
|
||||||
import rx.functions.Action1;
|
import io.reactivex.functions.Consumer;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -145,140 +146,180 @@ public class LifecycleView extends FrameLayout implements LifecycleBindable {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable) {
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable) {
|
||||||
return baseLifecycleBindable.untilStop(observable);
|
return baseLifecycleBindable.untilStop(observable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable, @NonNull final Action1<T> onNextAction) {
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable, @NonNull final Consumer<T> onNextAction) {
|
||||||
return baseLifecycleBindable.untilStop(observable, onNextAction);
|
return baseLifecycleBindable.untilStop(observable, onNextAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable,
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction);
|
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Observable<T> observable,
|
public <T> Disposable untilStop(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction,
|
@NonNull final Consumer<Throwable> onErrorAction,
|
||||||
@NonNull final Action0 onCompletedAction) {
|
@NonNull final Action onCompletedAction) {
|
||||||
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction, onCompletedAction);
|
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single) {
|
public <T> Disposable untilStop(@NonNull final Single<T> single) {
|
||||||
return baseLifecycleBindable.untilStop(single);
|
return baseLifecycleBindable.untilStop(single);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
|
public <T> Disposable untilStop(@NonNull final Single<T> single, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
return baseLifecycleBindable.untilStop(single, onSuccessAction);
|
return baseLifecycleBindable.untilStop(single, onSuccessAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilStop(@NonNull final Single<T> single,
|
public <T> Disposable untilStop(@NonNull final Single<T> single,
|
||||||
@NonNull final Action1<T> onSuccessAction,
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilStop(single, onSuccessAction, onErrorAction);
|
return baseLifecycleBindable.untilStop(single, onSuccessAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilStop(@NonNull final Completable completable) {
|
public Disposable untilStop(@NonNull final Completable completable) {
|
||||||
return baseLifecycleBindable.untilStop(completable);
|
return baseLifecycleBindable.untilStop(completable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilStop(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
|
public Disposable untilStop(@NonNull final Completable completable, @NonNull final Action onCompletedAction) {
|
||||||
return baseLifecycleBindable.untilStop(completable, onCompletedAction);
|
return baseLifecycleBindable.untilStop(completable, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilStop(@NonNull final Completable completable,
|
public Disposable untilStop(@NonNull final Completable completable,
|
||||||
@NonNull final Action0 onCompletedAction,
|
@NonNull final Action onCompletedAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilStop(completable, onCompletedAction, onErrorAction);
|
return baseLifecycleBindable.untilStop(completable, onCompletedAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable) {
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe) {
|
||||||
|
return baseLifecycleBindable.untilStop(maybe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
|
return baseLifecycleBindable.untilStop(maybe, onSuccessAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilStop(@NonNull final Maybe<T> maybe,
|
||||||
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
|
return baseLifecycleBindable.untilStop(maybe, onSuccessAction, onErrorAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable) {
|
||||||
return baseLifecycleBindable.untilDestroy(observable);
|
return baseLifecycleBindable.untilDestroy(observable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable, @NonNull final Action1<T> onNextAction) {
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable, @NonNull final Consumer<T> onNextAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(observable, onNextAction);
|
return baseLifecycleBindable.untilDestroy(observable, onNextAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable,
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction);
|
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable,
|
public <T> Disposable untilDestroy(@NonNull final Observable<T> observable,
|
||||||
@NonNull final Action1<T> onNextAction,
|
@NonNull final Consumer<T> onNextAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction,
|
@NonNull final Consumer<Throwable> onErrorAction,
|
||||||
@NonNull final Action0 onCompletedAction) {
|
@NonNull final Action onCompletedAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction, onCompletedAction);
|
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single) {
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single) {
|
||||||
return baseLifecycleBindable.untilDestroy(single);
|
return baseLifecycleBindable.untilDestroy(single);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(single, onSuccessAction);
|
return baseLifecycleBindable.untilDestroy(single, onSuccessAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T> Subscription untilDestroy(@NonNull final Single<T> single,
|
public <T> Disposable untilDestroy(@NonNull final Single<T> single,
|
||||||
@NonNull final Action1<T> onSuccessAction,
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(single, onSuccessAction, onErrorAction);
|
return baseLifecycleBindable.untilDestroy(single, onSuccessAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable) {
|
public Disposable untilDestroy(@NonNull final Completable completable) {
|
||||||
return baseLifecycleBindable.untilDestroy(completable);
|
return baseLifecycleBindable.untilDestroy(completable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
|
public Disposable untilDestroy(@NonNull final Completable completable, @NonNull final Action onCompletedAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction);
|
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Subscription untilDestroy(@NonNull final Completable completable,
|
public Disposable untilDestroy(@NonNull final Completable completable,
|
||||||
@NonNull final Action0 onCompletedAction,
|
@NonNull final Action onCompletedAction,
|
||||||
@NonNull final Action1<Throwable> onErrorAction) {
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction, onErrorAction);
|
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction, onErrorAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe) {
|
||||||
|
return baseLifecycleBindable.untilDestroy(maybe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe, @NonNull final Consumer<T> onSuccessAction) {
|
||||||
|
return baseLifecycleBindable.untilDestroy(maybe, onSuccessAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T> Disposable untilDestroy(@NonNull final Maybe<T> maybe,
|
||||||
|
@NonNull final Consumer<T> onSuccessAction,
|
||||||
|
@NonNull final Consumer<Throwable> onErrorAction) {
|
||||||
|
return baseLifecycleBindable.untilDestroy(maybe, onSuccessAction, onErrorAction);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ package ru.touchin.roboswag.components.views;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.support.annotation.ColorInt;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.AppCompatImageView;
|
import android.support.v7.widget.AppCompatImageView;
|
||||||
|
|
@ -89,7 +90,7 @@ public class MaterialLoadingBar extends AppCompatImageView {
|
||||||
typedArray.recycle();
|
typedArray.recycle();
|
||||||
|
|
||||||
progressDrawable = new MaterialProgressDrawable(context, size);
|
progressDrawable = new MaterialProgressDrawable(context, size);
|
||||||
progressDrawable.setColor(color);
|
setColor(color);
|
||||||
progressDrawable.setStrokeWidth(strokeWidth);
|
progressDrawable.setStrokeWidth(strokeWidth);
|
||||||
setScaleType(ScaleType.CENTER);
|
setScaleType(ScaleType.CENTER);
|
||||||
setImageDrawable(progressDrawable);
|
setImageDrawable(progressDrawable);
|
||||||
|
|
@ -107,4 +108,13 @@ public class MaterialLoadingBar extends AppCompatImageView {
|
||||||
super.onDetachedFromWindow();
|
super.onDetachedFromWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set color of loader.
|
||||||
|
*
|
||||||
|
* @param colorInt Color of loader to be set.
|
||||||
|
*/
|
||||||
|
public void setColor(@ColorInt final int colorInt) {
|
||||||
|
progressDrawable.setColor(colorInt);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -23,6 +23,7 @@ import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.design.widget.TextInputLayout;
|
||||||
import android.support.v7.widget.AppCompatEditText;
|
import android.support.v7.widget.AppCompatEditText;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
|
|
@ -31,12 +32,15 @@ import android.text.TextWatcher;
|
||||||
import android.text.method.SingleLineTransformationMethod;
|
import android.text.method.SingleLineTransformationMethod;
|
||||||
import android.text.method.TransformationMethod;
|
import android.text.method.TransformationMethod;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewParent;
|
||||||
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
import android.view.inputmethod.InputConnection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import ru.touchin.roboswag.components.R;
|
import ru.touchin.roboswag.components.R;
|
||||||
import ru.touchin.roboswag.components.utils.Typefaces;
|
|
||||||
import ru.touchin.roboswag.components.views.internal.AttributesUtils;
|
import ru.touchin.roboswag.components.views.internal.AttributesUtils;
|
||||||
import ru.touchin.roboswag.core.log.Lc;
|
import ru.touchin.roboswag.core.log.Lc;
|
||||||
|
|
||||||
|
|
@ -96,10 +100,6 @@ public class TypefacedEditText extends AppCompatEditText {
|
||||||
} else {
|
} else {
|
||||||
setSingleLine();
|
setSingleLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isInEditMode()) {
|
|
||||||
setTypeface(Typefaces.getFromAttributes(context, attrs, R.styleable.TypefacedEditText, R.styleable.TypefacedEditText_customTypeface));
|
|
||||||
}
|
|
||||||
typedArray.recycle();
|
typedArray.recycle();
|
||||||
if (inDebugMode) {
|
if (inDebugMode) {
|
||||||
checkAttributes(context, attrs);
|
checkAttributes(context, attrs);
|
||||||
|
|
@ -107,12 +107,25 @@ public class TypefacedEditText extends AppCompatEditText {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public InputConnection onCreateInputConnection(@NonNull final EditorInfo attrs) {
|
||||||
|
final InputConnection inputConnection = super.onCreateInputConnection(attrs);
|
||||||
|
if (inputConnection != null && attrs.hintText == null) {
|
||||||
|
for (ViewParent parent = getParent(); parent instanceof View; parent = parent.getParent()) {
|
||||||
|
if (parent instanceof TextInputLayout) {
|
||||||
|
attrs.hintText = ((TextInputLayout) parent).getHint();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return inputConnection;
|
||||||
|
}
|
||||||
|
|
||||||
private void checkAttributes(@NonNull final Context context, @NonNull final AttributeSet attrs) {
|
private void checkAttributes(@NonNull final Context context, @NonNull final AttributeSet attrs) {
|
||||||
final List<String> errors = new ArrayList<>();
|
final List<String> errors = new ArrayList<>();
|
||||||
Boolean multiline = null;
|
Boolean multiline = null;
|
||||||
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TypefacedEditText);
|
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TypefacedEditText);
|
||||||
AttributesUtils.checkAttribute(typedArray, errors, R.styleable.TypefacedEditText_customTypeface, true,
|
|
||||||
"customTypeface required parameter");
|
|
||||||
AttributesUtils.checkAttribute(typedArray, errors, R.styleable.TypefacedEditText_isMultiline, true,
|
AttributesUtils.checkAttribute(typedArray, errors, R.styleable.TypefacedEditText_isMultiline, true,
|
||||||
"isMultiline required parameter");
|
"isMultiline required parameter");
|
||||||
if (typedArray.hasValue(R.styleable.TypefacedEditText_isMultiline)) {
|
if (typedArray.hasValue(R.styleable.TypefacedEditText_isMultiline)) {
|
||||||
|
|
@ -139,12 +152,6 @@ public class TypefacedEditText extends AppCompatEditText {
|
||||||
private void checkEditTextSpecificAttributes(@NonNull final TypedArray typedArray, @NonNull final Class androidRes,
|
private void checkEditTextSpecificAttributes(@NonNull final TypedArray typedArray, @NonNull final Class androidRes,
|
||||||
@NonNull final List<String> errors)
|
@NonNull final List<String> errors)
|
||||||
throws NoSuchFieldException, IllegalAccessException {
|
throws NoSuchFieldException, IllegalAccessException {
|
||||||
AttributesUtils.checkAttribute(typedArray, errors, AttributesUtils.getField(androidRes, "TextView_typeface"), false,
|
|
||||||
"remove typeface and use customTypeface");
|
|
||||||
AttributesUtils.checkAttribute(typedArray, errors, AttributesUtils.getField(androidRes, "TextView_textStyle"), false,
|
|
||||||
"remove textStyle and use customTypeface");
|
|
||||||
AttributesUtils.checkAttribute(typedArray, errors, AttributesUtils.getField(androidRes, "TextView_fontFamily"), false,
|
|
||||||
"remove fontFamily and use customTypeface");
|
|
||||||
AttributesUtils.checkAttribute(typedArray, errors, AttributesUtils.getField(androidRes, "TextView_singleLine"), false,
|
AttributesUtils.checkAttribute(typedArray, errors, AttributesUtils.getField(androidRes, "TextView_singleLine"), false,
|
||||||
"remove singleLine and use isMultiline");
|
"remove singleLine and use isMultiline");
|
||||||
AttributesUtils.checkAttribute(typedArray, errors, AttributesUtils.getField(androidRes, "TextView_includeFontPadding"), false,
|
AttributesUtils.checkAttribute(typedArray, errors, AttributesUtils.getField(androidRes, "TextView_includeFontPadding"), false,
|
||||||
|
|
@ -317,15 +324,6 @@ public class TypefacedEditText extends AppCompatEditText {
|
||||||
super.setInputType(type);
|
super.setInputType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets typeface from 'assets/fonts' folder by name.
|
|
||||||
*
|
|
||||||
* @param name Full name of typeface (without extension, e.g. 'Roboto-Regular').
|
|
||||||
*/
|
|
||||||
public void setTypeface(@NonNull final String name) {
|
|
||||||
setTypeface(Typefaces.getByName(getContext(), name));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOnTextChangedListener(@Nullable final OnTextChangedListener onTextChangedListener) {
|
public void setOnTextChangedListener(@Nullable final OnTextChangedListener onTextChangedListener) {
|
||||||
this.onTextChangedListener = onTextChangedListener;
|
this.onTextChangedListener = onTextChangedListener;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import ru.touchin.roboswag.components.R;
|
import ru.touchin.roboswag.components.R;
|
||||||
import ru.touchin.roboswag.components.utils.Typefaces;
|
|
||||||
import ru.touchin.roboswag.components.utils.UiUtils;
|
import ru.touchin.roboswag.components.utils.UiUtils;
|
||||||
import ru.touchin.roboswag.components.views.internal.AttributesUtils;
|
import ru.touchin.roboswag.components.views.internal.AttributesUtils;
|
||||||
import ru.touchin.roboswag.core.log.Lc;
|
import ru.touchin.roboswag.core.log.Lc;
|
||||||
|
|
@ -93,9 +92,6 @@ public class TypefacedTextView extends AppCompatTextView {
|
||||||
} else {
|
} else {
|
||||||
setLineStrategy(lineStrategy);
|
setLineStrategy(lineStrategy);
|
||||||
}
|
}
|
||||||
if (!isInEditMode()) {
|
|
||||||
setTypeface(Typefaces.getFromAttributes(context, attrs, R.styleable.TypefacedTextView, R.styleable.TypefacedTextView_customTypeface));
|
|
||||||
}
|
|
||||||
typedArray.recycle();
|
typedArray.recycle();
|
||||||
if (inDebugMode) {
|
if (inDebugMode) {
|
||||||
checkAttributes(context, attrs);
|
checkAttributes(context, attrs);
|
||||||
|
|
@ -107,8 +103,6 @@ public class TypefacedTextView extends AppCompatTextView {
|
||||||
final List<String> errors = new ArrayList<>();
|
final List<String> errors = new ArrayList<>();
|
||||||
LineStrategy lineStrategy = null;
|
LineStrategy lineStrategy = null;
|
||||||
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TypefacedTextView);
|
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TypefacedTextView);
|
||||||
AttributesUtils.checkAttribute(typedArray, errors, R.styleable.TypefacedTextView_customTypeface, true,
|
|
||||||
"customTypeface required parameter");
|
|
||||||
AttributesUtils.checkAttribute(typedArray, errors, R.styleable.TypefacedTextView_lineStrategy, true,
|
AttributesUtils.checkAttribute(typedArray, errors, R.styleable.TypefacedTextView_lineStrategy, true,
|
||||||
"lineStrategy required parameter");
|
"lineStrategy required parameter");
|
||||||
if (typedArray.hasValue(R.styleable.TypefacedTextView_lineStrategy)) {
|
if (typedArray.hasValue(R.styleable.TypefacedTextView_lineStrategy)) {
|
||||||
|
|
@ -311,15 +305,6 @@ public class TypefacedTextView extends AppCompatTextView {
|
||||||
Lc.assertion(new IllegalStateException(AttributesUtils.viewError(this, "Do not specify ellipsize use setLineStrategy instead")));
|
Lc.assertion(new IllegalStateException(AttributesUtils.viewError(this, "Do not specify ellipsize use setLineStrategy instead")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets typeface from 'assets/fonts' folder by name.
|
|
||||||
*
|
|
||||||
* @param name Full name of typeface (without extension, e.g. 'Roboto-Regular').
|
|
||||||
*/
|
|
||||||
public void setTypeface(@NonNull final String name) {
|
|
||||||
setTypeface(Typefaces.getByName(getContext(), name));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setText(@Nullable final CharSequence text, @Nullable final BufferType type) {
|
public void setText(@Nullable final CharSequence text, @Nullable final BufferType type) {
|
||||||
super.setText(text, type);
|
super.setText(text, type);
|
||||||
|
|
|
||||||
|
|
@ -94,9 +94,7 @@ public final class AttributesUtils {
|
||||||
public static void checkRegularTextViewAttributes(@NonNull final TypedArray typedArray, @NonNull final Class androidRes,
|
public static void checkRegularTextViewAttributes(@NonNull final TypedArray typedArray, @NonNull final Class androidRes,
|
||||||
@NonNull final Collection<String> errors, @NonNull final String lineStrategyParameterName)
|
@NonNull final Collection<String> errors, @NonNull final String lineStrategyParameterName)
|
||||||
throws NoSuchFieldException, IllegalAccessException {
|
throws NoSuchFieldException, IllegalAccessException {
|
||||||
checkAttribute(typedArray, errors, getField(androidRes, "TextView_typeface"), false, "remove typeface and use customTypeface");
|
checkAttribute(typedArray, errors, getField(androidRes, "TextView_fontFamily"), true, "fontFamily required parameter");
|
||||||
checkAttribute(typedArray, errors, getField(androidRes, "TextView_textStyle"), false, "remove textStyle and use customTypeface");
|
|
||||||
checkAttribute(typedArray, errors, getField(androidRes, "TextView_fontFamily"), false, "remove fontFamily and use customTypeface");
|
|
||||||
checkAttribute(typedArray, errors, getField(androidRes, "TextView_includeFontPadding"), false, "includeFontPadding forbid parameter");
|
checkAttribute(typedArray, errors, getField(androidRes, "TextView_includeFontPadding"), false, "includeFontPadding forbid parameter");
|
||||||
checkAttribute(typedArray, errors, getField(androidRes, "TextView_singleLine"), false,
|
checkAttribute(typedArray, errors, getField(androidRes, "TextView_singleLine"), false,
|
||||||
"remove singleLine and use " + lineStrategyParameterName);
|
"remove singleLine and use " + lineStrategyParameterName);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
<attr name="customTypeface" format="string"/>
|
<attr name="customTypeface" format="string"/>
|
||||||
|
|
||||||
<declare-styleable name="TypefacedTextView">
|
<declare-styleable name="TypefacedTextView">
|
||||||
<attr name="customTypeface"/>
|
|
||||||
<attr name="lineStrategy" format="enum">
|
<attr name="lineStrategy" format="enum">
|
||||||
<enum name="singleLineEllipsize" value="0"/>
|
<enum name="singleLineEllipsize" value="0"/>
|
||||||
<enum name="singleLineMarquee" value="1"/>
|
<enum name="singleLineMarquee" value="1"/>
|
||||||
|
|
@ -17,7 +16,6 @@
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="TypefacedEditText">
|
<declare-styleable name="TypefacedEditText">
|
||||||
<attr name="customTypeface"/>
|
|
||||||
<attr name="isMultiline" format="boolean"/>
|
<attr name="isMultiline" format="boolean"/>
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue