mirror of
https://github.com/k0shk0sh/FastHub.git
synced 2025-12-08 19:05:54 +00:00
this commit migrates from rxJava1 to rxJava2
This commit is contained in:
parent
ec8a0b223b
commit
060d36babf
@ -77,7 +77,7 @@ available until further notice~~
|
||||
|
||||
- Minimum **SDK 21**, _but AppCompat is used all the way ;-)_
|
||||
- **MVP**-architecture: [**ThirtyInch**](https://github.com/grandcentrix/ThirtyInch) because its ThirtyInch.
|
||||
- [**RxJava**](https://github.com/ReactiveX/RxJava) & [**RxAndroid**](https://github.com/ReactiveX/RxAndroid) for Retrofit & background threads
|
||||
- [**RxJava2**](https://github.com/ReactiveX/RxJava) & [**RxAndroid**](https://github.com/ReactiveX/RxAndroid) for Retrofit & background threads
|
||||
- [**Retrofit**](https://github.com/square/retrofit) for constructing the REST API
|
||||
- [**Requery**](https://github.com/requery/requery/) for offline-mode
|
||||
- [**Stream API**](https://github.com/aNNiMON/Lightweight-Stream-API) for dealing with `Collections`
|
||||
|
||||
@ -110,17 +110,17 @@ dependencies {
|
||||
compile "com.android.support:palette-v7:${supportVersion}"
|
||||
// compile "com.android.support:support-emoji-appcompat:${supportVersion}"
|
||||
compile "net.grandcentrix.thirtyinch:thirtyinch:${thirtyinchVersion}"
|
||||
compile "net.grandcentrix.thirtyinch:thirtyinch-rx:${thirtyinchVersion}"
|
||||
compile "net.grandcentrix.thirtyinch:thirtyinch-rx2:${thirtyinchVersion}"
|
||||
compile "com.squareup.retrofit2:retrofit:${retrofit}"
|
||||
compile "com.squareup.retrofit2:converter-gson:${retrofit}"
|
||||
compile "com.squareup.retrofit2:adapter-rxjava:${retrofit}"
|
||||
compile "com.squareup.retrofit2:adapter-rxjava2:${retrofit}"
|
||||
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
|
||||
compile 'cn.gavinliu.android.lib:ShapedImageView:0.8.3'
|
||||
compile "frankiesardo:icepick:${icepickVersion}"
|
||||
compile "com.jakewharton:butterknife:${butterKnifeVersion}"
|
||||
compile 'it.sephiroth.android.library.bottomnavigation:bottom-navigation:2.0.1-rc1'
|
||||
compile 'io.reactivex:rxandroid:1.2.1'
|
||||
compile 'io.reactivex:rxjava:1.3.0'
|
||||
compile 'io.reactivex.rxjava2:rxjava:2.0.6'
|
||||
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
|
||||
compile 'com.squareup.okhttp3:logging-interceptor:3.8.0'
|
||||
compile 'com.annimon:stream:1.1.7'
|
||||
compile 'com.github.GrenderG:Toasty:1.1.3'
|
||||
@ -139,14 +139,18 @@ dependencies {
|
||||
compile "com.google.firebase:firebase-messaging:${gms}"
|
||||
releaseCompile "com.google.firebase:firebase-crash:${gms}"
|
||||
compile "com.google.android.gms:play-services-auth:${gms}"
|
||||
compile "com.github.florent37:retrojsoup:${retroJsoup}"
|
||||
compile "com.github.florent37:rxjsoup:${retroJsoup}"
|
||||
compile "org.jsoup:jsoup:1.10.2"
|
||||
// compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:${kotlin_version}"
|
||||
provided "org.projectlombok:lombok:${lombokVersion}"
|
||||
annotationProcessor "com.github.florent37:retrojsoup-compiler:${retroJsoup}"
|
||||
annotationProcessor "io.requery:requery-processor:${requery}"
|
||||
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
|
||||
annotationProcessor "frankiesardo:icepick-processor:${icepickVersion}"
|
||||
annotationProcessor "com.jakewharton:butterknife-compiler:${butterKnifeVersion}"
|
||||
annotationProcessor 'com.github.matthiasrobbers:shortbread-compiler:1.0.1'
|
||||
testCompile "net.grandcentrix.thirtyinch:thirtyinch-test:$thirtyinchVersion"
|
||||
// testCompile "net.grandcentrix.thirtyinch:thirtyinch-test:$thirtyinchVersion"
|
||||
testCompile "junit:junit:${junitVersion}"
|
||||
testCompile "org.mockito:mockito-core:${mockitoVersion}"
|
||||
testCompile "org.assertj:assertj-core:${assertjVersion}"
|
||||
|
||||
@ -16,21 +16,22 @@ import com.google.android.gms.common.api.GoogleApiClient;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.android.sqlite.DatabaseSource;
|
||||
import io.requery.meta.EntityModel;
|
||||
import io.requery.rx.RxSupport;
|
||||
import io.requery.rx.SingleEntityStore;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
import io.requery.reactivex.ReactiveSupport;
|
||||
import io.requery.sql.Configuration;
|
||||
import io.requery.sql.EntityDataStore;
|
||||
import io.requery.sql.TableCreationMode;
|
||||
import shortbread.Shortbread;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Created by Kosh on 03 Feb 2017, 12:07 AM
|
||||
*/
|
||||
|
||||
public class App extends Application {
|
||||
private static App instance;
|
||||
private SingleEntityStore<Persistable> dataStore;
|
||||
private ReactiveEntityStore<Persistable> dataStore;
|
||||
private static GoogleApiClient googleApiClient;
|
||||
|
||||
@Override public void onCreate() {
|
||||
@ -88,7 +89,7 @@ public class App extends Application {
|
||||
PreferenceManager.setDefaultValues(this, R.xml.notification_settings, false);
|
||||
}
|
||||
|
||||
public SingleEntityStore<Persistable> getDataStore() {
|
||||
public ReactiveEntityStore<Persistable> getDataStore() {
|
||||
if (dataStore == null) {
|
||||
EntityModel model = Models.DEFAULT;
|
||||
DatabaseSource source = new DatabaseSource(this, model, "FastHub-DB", 9);
|
||||
@ -96,7 +97,7 @@ public class App extends Application {
|
||||
if (BuildConfig.DEBUG) {
|
||||
source.setTableCreationMode(TableCreationMode.CREATE_NOT_EXISTS);
|
||||
}
|
||||
dataStore = RxSupport.toReactiveStore(new EntityDataStore<Persistable>(configuration));
|
||||
dataStore = ReactiveSupport.toReactiveStore(new EntityDataStore<Persistable>(configuration));
|
||||
}
|
||||
return dataStore;
|
||||
}
|
||||
|
||||
@ -13,19 +13,18 @@ import com.fastaccess.helper.RxHelper;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import io.requery.Column;
|
||||
import io.requery.Convert;
|
||||
import io.requery.Entity;
|
||||
import io.requery.Key;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.rx.SingleEntityStore;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
import lombok.NoArgsConstructor;
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
|
||||
import static com.fastaccess.data.dao.model.Comment.COMMIT_ID;
|
||||
import static com.fastaccess.data.dao.model.Comment.GIST_ID;
|
||||
import static com.fastaccess.data.dao.model.Comment.ID;
|
||||
import static com.fastaccess.data.dao.model.Comment.ISSUE_ID;
|
||||
import static com.fastaccess.data.dao.model.Comment.LOGIN;
|
||||
import static com.fastaccess.data.dao.model.Comment.PULL_REQUEST_ID;
|
||||
@ -55,61 +54,55 @@ import static com.fastaccess.data.dao.model.Comment.UPDATED_AT;
|
||||
String pullRequestId;
|
||||
@Convert(ReactionsConverter.class) ReactionsModel reactions;
|
||||
|
||||
public Single save(Comment modelEntity) {
|
||||
return RxHelper.getSingle(
|
||||
App.getInstance().getDataStore()
|
||||
.delete(Comment.class)
|
||||
.where(ID.eq(modelEntity.getId()))
|
||||
.get()
|
||||
.toSingle()
|
||||
.flatMap(integer -> App.getInstance().getDataStore().insert(modelEntity)));
|
||||
public Single<Comment> save(Comment entity) {
|
||||
return RxHelper.getSingle(App.getInstance().getDataStore().upsert(entity));
|
||||
}
|
||||
|
||||
public static Observable saveForGist(@NonNull List<Comment> models, @NonNull String gistId) {
|
||||
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
public static Observable<Comment> saveForGist(@NonNull List<Comment> models, @NonNull String gistId) {
|
||||
ReactiveEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
return RxHelper.safeObservable(singleEntityStore.delete(Comment.class)
|
||||
.where(GIST_ID.equal(gistId))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toObservable()
|
||||
.flatMap(integer -> Observable.from(models))
|
||||
.flatMap(integer -> Observable.fromIterable(models))
|
||||
.flatMap(comment -> {
|
||||
comment.setGistId(gistId);
|
||||
return singleEntityStore.insert(comment).toObservable();
|
||||
return comment.save(comment).toObservable();
|
||||
}));
|
||||
}
|
||||
|
||||
public static Observable saveForCommits(@NonNull List<Comment> models, @NonNull String repoId,
|
||||
@NonNull String login, @NonNull String commitId) {
|
||||
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
ReactiveEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
return RxHelper.safeObservable(singleEntityStore.delete(Comment.class)
|
||||
.where(COMMIT_ID.equal(commitId)
|
||||
.and(REPO_ID.equal(repoId))
|
||||
.and(LOGIN.equal(login)))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toObservable()
|
||||
.flatMap(integer -> Observable.from(models))
|
||||
.flatMap(integer -> Observable.fromIterable(models))
|
||||
.flatMap(model -> {
|
||||
model.setLogin(login);
|
||||
model.setRepoId(repoId);
|
||||
model.setCommitId(commitId);
|
||||
return singleEntityStore.insert(model).toObservable();
|
||||
return model.save(model).toObservable();
|
||||
}));
|
||||
}
|
||||
|
||||
public static Observable<List<Comment>> getGistComments(@NonNull String gistId) {
|
||||
public static Single<List<Comment>> getGistComments(@NonNull String gistId) {
|
||||
return App.getInstance().getDataStore()
|
||||
.select(Comment.class)
|
||||
.where(GIST_ID.equal(gistId))
|
||||
.orderBy(UPDATED_AT.desc())
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static Observable<List<Comment>> getCommitComments(@NonNull String repoId, @NonNull String login,
|
||||
@NonNull String commitId) {
|
||||
public static Single<List<Comment>> getCommitComments(@NonNull String repoId, @NonNull String login,
|
||||
@NonNull String commitId) {
|
||||
return App.getInstance().getDataStore()
|
||||
.select(Comment.class)
|
||||
.where(REPO_ID.equal(repoId)
|
||||
@ -117,12 +110,11 @@ import static com.fastaccess.data.dao.model.Comment.UPDATED_AT;
|
||||
.and(COMMIT_ID.equal(commitId)))
|
||||
.orderBy(UPDATED_AT.desc())
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static Observable<List<Comment>> getIssueComments(@NonNull String repoId, @NonNull String login,
|
||||
@NonNull String issueId) {
|
||||
public static Single<List<Comment>> getIssueComments(@NonNull String repoId, @NonNull String login, @NonNull String issueId) {
|
||||
return App.getInstance().getDataStore()
|
||||
.select(Comment.class)
|
||||
.where(REPO_ID.equal(repoId)
|
||||
@ -130,12 +122,12 @@ import static com.fastaccess.data.dao.model.Comment.UPDATED_AT;
|
||||
.and(ISSUE_ID.equal(issueId)))
|
||||
.orderBy(UPDATED_AT.desc())
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static Observable<List<Comment>> getPullRequestComments(@NonNull String repoId, @NonNull String login,
|
||||
@NonNull String pullRequestId) {
|
||||
public static Single<List<Comment>> getPullRequestComments(@NonNull String repoId, @NonNull String login,
|
||||
@NonNull String pullRequestId) {
|
||||
return App.getInstance().getDataStore()
|
||||
.select(Comment.class)
|
||||
.where(REPO_ID.equal(repoId)
|
||||
@ -143,7 +135,7 @@ import static com.fastaccess.data.dao.model.Comment.UPDATED_AT;
|
||||
.and(PULL_REQUEST_ID.equal(pullRequestId)))
|
||||
.orderBy(UPDATED_AT.desc())
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
||||
@ -20,6 +20,8 @@ import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import io.requery.Column;
|
||||
import io.requery.Convert;
|
||||
import io.requery.Entity;
|
||||
@ -28,10 +30,8 @@ import io.requery.Key;
|
||||
import io.requery.Nullable;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.Table;
|
||||
import io.requery.rx.SingleEntityStore;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
import lombok.NoArgsConstructor;
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
|
||||
import static com.fastaccess.data.dao.model.Commit.LOGIN;
|
||||
import static com.fastaccess.data.dao.model.Commit.PULL_REQUEST_NUMBER;
|
||||
@ -59,22 +59,19 @@ public abstract class AbstractCommit implements Parcelable {
|
||||
@Column(name = "user_column") @Convert(UserConverter.class) User user;
|
||||
@Nullable int commentCount;
|
||||
|
||||
public Single save(Commit modelEntity) {
|
||||
return RxHelper.getSingle(
|
||||
App.getInstance()
|
||||
.getDataStore()
|
||||
.insert(modelEntity));
|
||||
public Single<Commit> save(Commit entity) {
|
||||
return RxHelper.getSingle(App.getInstance().getDataStore().upsert(entity));
|
||||
}
|
||||
|
||||
public static Observable save(@NonNull List<Commit> models, @NonNull String repoId, @NonNull String login) {
|
||||
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
public static Observable<Commit> save(@NonNull List<Commit> models, @NonNull String repoId, @NonNull String login) {
|
||||
ReactiveEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
return RxHelper.safeObservable(singleEntityStore.delete(Commit.class)
|
||||
.where(REPO_ID.eq(repoId)
|
||||
.and(LOGIN.eq(login)))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toObservable()
|
||||
.flatMap(integer -> Observable.from(models))
|
||||
.flatMap(integer -> Observable.fromIterable(models))
|
||||
.flatMap(commitModel -> {
|
||||
commitModel.setRepoId(repoId);
|
||||
commitModel.setLogin(login);
|
||||
@ -82,16 +79,16 @@ public abstract class AbstractCommit implements Parcelable {
|
||||
}));
|
||||
}
|
||||
|
||||
public static Observable save(@NonNull List<Commit> models, @NonNull String repoId, @NonNull String login, long number) {
|
||||
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
public static Observable<Commit> save(@NonNull List<Commit> models, @NonNull String repoId, @NonNull String login, long number) {
|
||||
ReactiveEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
return RxHelper.safeObservable(singleEntityStore.delete(Commit.class)
|
||||
.where(REPO_ID.eq(repoId)
|
||||
.and(LOGIN.eq(login))
|
||||
.and(PULL_REQUEST_NUMBER.eq(number)))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toObservable()
|
||||
.flatMap(integer -> Observable.from(models))
|
||||
.flatMap(integer -> Observable.fromIterable(models))
|
||||
.flatMap(commitModel -> {
|
||||
commitModel.setRepoId(repoId);
|
||||
commitModel.setLogin(login);
|
||||
@ -100,25 +97,25 @@ public abstract class AbstractCommit implements Parcelable {
|
||||
}));
|
||||
}
|
||||
|
||||
public static Observable<List<Commit>> getCommits(@NonNull String repoId, @NonNull String login) {
|
||||
public static Single<List<Commit>> getCommits(@NonNull String repoId, @NonNull String login) {
|
||||
return App.getInstance().getDataStore()
|
||||
.select(Commit.class)
|
||||
.where(REPO_ID.eq(repoId)
|
||||
.and(LOGIN.eq(login))
|
||||
.and(PULL_REQUEST_NUMBER.eq(0L)))
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static Observable<List<Commit>> getCommits(@NonNull String repoId, @NonNull String login, long pullRequestNumber) {
|
||||
public static Single<List<Commit>> getCommits(@NonNull String repoId, @NonNull String login, long pullRequestNumber) {
|
||||
return App.getInstance().getDataStore()
|
||||
.select(Commit.class)
|
||||
.where(REPO_ID.eq(repoId)
|
||||
.and(LOGIN.eq(login))
|
||||
.and(PULL_REQUEST_NUMBER.eq(pullRequestNumber)))
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
@ -130,7 +127,7 @@ public abstract class AbstractCommit implements Parcelable {
|
||||
.and(SHA.eq(sha)))
|
||||
.limit(1)
|
||||
.get()
|
||||
.toObservable();
|
||||
.observable();
|
||||
}
|
||||
|
||||
@Override public int describeContents() { return 0; }
|
||||
|
||||
@ -16,14 +16,13 @@ import com.google.gson.annotations.SerializedName;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Single;
|
||||
import io.requery.Convert;
|
||||
import io.requery.Entity;
|
||||
import io.requery.Key;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.rx.SingleEntityStore;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
import lombok.NoArgsConstructor;
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 16 Mar 2017, 7:29 PM
|
||||
@ -38,23 +37,23 @@ import rx.Single;
|
||||
@Convert(PayloadConverter.class) PayloadModel payload;
|
||||
@SerializedName("public") boolean publicEvent;
|
||||
|
||||
@NonNull public static Single save(@NonNull List<Event> events) {
|
||||
SingleEntityStore<Persistable> dataSource = App.getInstance().getDataStore();
|
||||
@NonNull public static Single<Iterable<Event>> save(@NonNull List<Event> events) {
|
||||
ReactiveEntityStore<Persistable> dataSource = App.getInstance().getDataStore();
|
||||
return RxHelper.getSingle(
|
||||
dataSource.delete(Event.class)
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.flatMap(i -> dataSource.insert(events))
|
||||
);
|
||||
}
|
||||
|
||||
@NonNull public static Observable<List<Event>> getEvents() {
|
||||
return RxHelper.getObserver(
|
||||
@NonNull public static Single<List<Event>> getEvents() {
|
||||
return RxHelper.getSingle(
|
||||
App.getInstance().getDataStore()
|
||||
.select(Event.class)
|
||||
.orderBy(Event.CREATED_AT.desc())
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList());
|
||||
}
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ import com.fastaccess.data.dao.GithubFileModel;
|
||||
import com.fastaccess.data.dao.converters.GitHubFilesConverter;
|
||||
import com.fastaccess.data.dao.converters.UserConverter;
|
||||
import com.fastaccess.helper.InputHelper;
|
||||
import com.fastaccess.helper.ObjectsCompat;
|
||||
import com.fastaccess.helper.RxHelper;
|
||||
import com.fastaccess.ui.widgets.SpannableBuilder;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
@ -20,15 +21,15 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import io.requery.Column;
|
||||
import io.requery.Convert;
|
||||
import io.requery.Entity;
|
||||
import io.requery.Key;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.rx.SingleEntityStore;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
import lombok.NoArgsConstructor;
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 16 Mar 2017, 7:32 PM
|
||||
@ -55,58 +56,53 @@ import rx.Single;
|
||||
@Column(name = "user_column") @Convert(UserConverter.class) User user;
|
||||
@Convert(UserConverter.class) User owner;
|
||||
|
||||
public Single save(Gist modelEntity) {
|
||||
return RxHelper.getSingle(
|
||||
App.getInstance().getDataStore()
|
||||
.delete(Gist.class)
|
||||
.where(Gist.ID.eq(modelEntity.getId()))
|
||||
.get()
|
||||
.toSingle()
|
||||
.flatMap(integer -> App.getInstance().getDataStore().insert(modelEntity)));
|
||||
public Single<Gist> save(Gist entity) {
|
||||
return RxHelper.getSingle(App.getInstance().getDataStore().upsert(entity));
|
||||
}
|
||||
|
||||
public static Observable<Gist> save(@NonNull List<Gist> gists) {
|
||||
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
ReactiveEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
return RxHelper.safeObservable(singleEntityStore.delete(Gist.class)
|
||||
.where(Gist.OWNER_NAME.isNull())
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toObservable()
|
||||
.flatMap(integer -> Observable.from(gists))
|
||||
.flatMap(gist -> singleEntityStore.insert(gist).toObservable()));
|
||||
.flatMap(integer -> Observable.fromIterable(gists))
|
||||
.flatMap(gist -> gist.save(gist).toObservable()));
|
||||
}
|
||||
|
||||
public static Observable<Gist> save(@NonNull List<Gist> gists, @NonNull String ownerName) {
|
||||
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
ReactiveEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
return RxHelper.safeObservable(singleEntityStore.delete(Gist.class)
|
||||
.where(Gist.OWNER_NAME.equal(ownerName))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toObservable()
|
||||
.flatMap(integer -> Observable.from(gists))
|
||||
.flatMap(integer -> Observable.fromIterable(gists))
|
||||
.filter(ObjectsCompat::nonNull)
|
||||
.flatMap(gist -> {
|
||||
gist.setOwnerName(ownerName);
|
||||
return gist.save(gist).toObservable();
|
||||
}));
|
||||
}
|
||||
|
||||
@NonNull public static Observable<List<Gist>> getMyGists(@NonNull String ownerName) {
|
||||
@NonNull public static Single<List<Gist>> getMyGists(@NonNull String ownerName) {
|
||||
return App.getInstance()
|
||||
.getDataStore()
|
||||
.select(Gist.class)
|
||||
.where(Gist.OWNER_NAME.equal(ownerName))
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
@NonNull public static Observable<List<Gist>> getGists() {
|
||||
@NonNull public static Single<List<Gist>> getGists() {
|
||||
return App.getInstance()
|
||||
.getDataStore()
|
||||
.select(Gist.class)
|
||||
.where(Gist.OWNER_NAME.isNull())
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
@ -116,7 +112,7 @@ import rx.Single;
|
||||
.select(Gist.class)
|
||||
.where(Gist.GIST_ID.eq(gistId))
|
||||
.get()
|
||||
.toObservable();
|
||||
.observable();
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
|
||||
@ -22,15 +22,15 @@ import com.fastaccess.helper.RxHelper;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import io.requery.Column;
|
||||
import io.requery.Convert;
|
||||
import io.requery.Entity;
|
||||
import io.requery.Key;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.rx.SingleEntityStore;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
import lombok.NoArgsConstructor;
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
|
||||
import static com.fastaccess.data.dao.model.Issue.ID;
|
||||
import static com.fastaccess.data.dao.model.Issue.LOGIN;
|
||||
@ -69,25 +69,19 @@ import static com.fastaccess.data.dao.model.Issue.UPDATED_AT;
|
||||
@Convert(UserConverter.class) User closedBy;
|
||||
@Convert(ReactionsConverter.class) ReactionsModel reactions;
|
||||
|
||||
public Single save(Issue entity) {
|
||||
return RxHelper.getSingle(
|
||||
App.getInstance().getDataStore()
|
||||
.delete(Issue.class)
|
||||
.where(ID.eq(entity.getId()))
|
||||
.get()
|
||||
.toSingle()
|
||||
.flatMap(i -> App.getInstance().getDataStore().insert(entity)));
|
||||
public Single<Issue> save(Issue entity) {
|
||||
return RxHelper.getSingle(App.getInstance().getDataStore().upsert(entity));
|
||||
}
|
||||
|
||||
public static Observable<Issue> save(@NonNull List<Issue> models, @NonNull String repoId, @NonNull String login) {
|
||||
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
ReactiveEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
return RxHelper.safeObservable(
|
||||
singleEntityStore.delete(Issue.class)
|
||||
.where(REPO_ID.equal(repoId).and(LOGIN.equal(login)))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toObservable()
|
||||
.flatMap(integer -> Observable.from(models))
|
||||
.flatMap(integer -> Observable.fromIterable(models))
|
||||
.flatMap(issueModel -> {
|
||||
issueModel.setRepoId(repoId);
|
||||
issueModel.setLogin(login);
|
||||
@ -95,14 +89,14 @@ import static com.fastaccess.data.dao.model.Issue.UPDATED_AT;
|
||||
}));
|
||||
}
|
||||
|
||||
public static Observable<List<Issue>> getIssues(@NonNull String repoId, @NonNull String login, @NonNull IssueState issueState) {
|
||||
public static Single<List<Issue>> getIssues(@NonNull String repoId, @NonNull String login, @NonNull IssueState issueState) {
|
||||
return App.getInstance().getDataStore().select(Issue.class)
|
||||
.where(REPO_ID.equal(repoId)
|
||||
.and(LOGIN.equal(login))
|
||||
.and(STATE.equal(issueState)))
|
||||
.orderBy(UPDATED_AT.desc())
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
@ -111,7 +105,7 @@ import static com.fastaccess.data.dao.model.Issue.UPDATED_AT;
|
||||
.select(Issue.class)
|
||||
.where(ID.equal(id))
|
||||
.get()
|
||||
.toObservable();
|
||||
.observable();
|
||||
}
|
||||
|
||||
public static Observable<Issue> getIssueByNumber(int number, String repoId, String login) {
|
||||
@ -121,7 +115,7 @@ import static com.fastaccess.data.dao.model.Issue.UPDATED_AT;
|
||||
.and(REPO_ID.eq(repoId))
|
||||
.and(LOGIN.eq(login)))
|
||||
.get()
|
||||
.toObservable();
|
||||
.observable();
|
||||
}
|
||||
|
||||
@Override public int describeContents() { return 0; }
|
||||
|
||||
@ -20,18 +20,17 @@ import com.fastaccess.helper.RxHelper;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import io.requery.Convert;
|
||||
import io.requery.Entity;
|
||||
import io.requery.Key;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.Transient;
|
||||
import io.requery.rx.SingleEntityStore;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
import lombok.NoArgsConstructor;
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
|
||||
import static com.fastaccess.data.dao.model.IssueEvent.CREATED_AT;
|
||||
import static com.fastaccess.data.dao.model.IssueEvent.ID;
|
||||
import static com.fastaccess.data.dao.model.IssueEvent.ISSUE_ID;
|
||||
import static com.fastaccess.data.dao.model.IssueEvent.LOGIN;
|
||||
import static com.fastaccess.data.dao.model.IssueEvent.REPO_ID;
|
||||
@ -62,26 +61,20 @@ import static com.fastaccess.data.dao.model.IssueEvent.REPO_ID;
|
||||
@Transient CharSequence labels;
|
||||
|
||||
public Single save(IssueEvent entity) {
|
||||
return RxHelper.getSingle(
|
||||
App.getInstance().getDataStore()
|
||||
.delete(IssueEvent.class)
|
||||
.where(ID.eq(entity.getId()))
|
||||
.get()
|
||||
.toSingle()
|
||||
.flatMap(i -> App.getInstance().getDataStore().update(entity)));
|
||||
return RxHelper.getSingle(App.getInstance().getDataStore().upsert(entity));
|
||||
}
|
||||
|
||||
public static Observable save(@NonNull List<IssueEvent> models, @NonNull String repoId,
|
||||
@NonNull String login, @NonNull String issueId) {
|
||||
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
ReactiveEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
return RxHelper.safeObservable(singleEntityStore.delete(IssueEvent.class)
|
||||
.where(LOGIN.equal(login)
|
||||
.and(REPO_ID.equal(repoId))
|
||||
.and(ISSUE_ID.equal(issueId)))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toObservable()
|
||||
.flatMap(integer -> Observable.from(models))
|
||||
.flatMap(integer -> Observable.fromIterable(models))
|
||||
.flatMap(issueEventModel -> {
|
||||
issueEventModel.setIssueId(issueId);
|
||||
issueEventModel.setLogin(login);
|
||||
@ -90,8 +83,8 @@ import static com.fastaccess.data.dao.model.IssueEvent.REPO_ID;
|
||||
}));
|
||||
}
|
||||
|
||||
public static Observable<List<IssueEvent>> get(@NonNull String repoId, @NonNull String login,
|
||||
@NonNull String issueId) {
|
||||
public static Single<List<IssueEvent>> get(@NonNull String repoId, @NonNull String login,
|
||||
@NonNull String issueId) {
|
||||
return App.getInstance().getDataStore()
|
||||
.select(IssueEvent.class)
|
||||
.where(LOGIN.equal(login)
|
||||
@ -99,7 +92,7 @@ import static com.fastaccess.data.dao.model.IssueEvent.REPO_ID;
|
||||
.and(ISSUE_ID.equal(issueId)))
|
||||
.orderBy(CREATED_AT.desc())
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
||||
@ -9,12 +9,12 @@ import com.fastaccess.helper.RxHelper;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.requery.Column;
|
||||
import io.requery.Entity;
|
||||
import io.requery.Key;
|
||||
import io.requery.Nullable;
|
||||
import lombok.NoArgsConstructor;
|
||||
import rx.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 16 Mar 2017, 7:36 PM
|
||||
@ -74,8 +74,7 @@ import rx.Observable;
|
||||
// entity.setIsLoggedIn(true); TODO for multiple logins
|
||||
App.getInstance().getDataStore()
|
||||
.insert(entity)
|
||||
.toBlocking()
|
||||
.value();
|
||||
.blockingGet();
|
||||
}
|
||||
|
||||
public static Login getUser() {
|
||||
|
||||
@ -13,16 +13,16 @@ import com.fastaccess.helper.RxHelper;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import io.requery.Convert;
|
||||
import io.requery.Entity;
|
||||
import io.requery.Key;
|
||||
import io.requery.Nullable;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.rx.SingleEntityStore;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
import lombok.NoArgsConstructor;
|
||||
import rx.Completable;
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 16 Mar 2017, 7:37 PM
|
||||
@ -39,14 +39,8 @@ import rx.Single;
|
||||
Date lastReadAt;
|
||||
@Nullable boolean isSubscribed;
|
||||
|
||||
public Single<Notification> save(Notification notification) {
|
||||
return RxHelper.getSingle(
|
||||
App.getInstance().getDataStore()
|
||||
.delete(Notification.class)
|
||||
.where(Notification.ID.eq(notification.getId()))
|
||||
.get()
|
||||
.toSingle()
|
||||
.flatMap(integer -> App.getInstance().getDataStore().insert(notification)));
|
||||
public Single<Notification> save(Notification entity) {
|
||||
return RxHelper.getSingle(App.getInstance().getDataStore().upsert(entity));
|
||||
}
|
||||
|
||||
public static Completable markAsRead(long id) {
|
||||
@ -60,7 +54,7 @@ import rx.Single;
|
||||
notification.setUnread(false);
|
||||
return notification.save(notification);
|
||||
}
|
||||
return Observable.empty().toSingle();
|
||||
return "";
|
||||
});
|
||||
}
|
||||
|
||||
@ -68,33 +62,33 @@ import rx.Single;
|
||||
if (models == null) {
|
||||
return Observable.empty();
|
||||
}
|
||||
SingleEntityStore<Persistable> dataSource = App.getInstance().getDataStore();
|
||||
ReactiveEntityStore<Persistable> dataSource = App.getInstance().getDataStore();
|
||||
return RxHelper.safeObservable(dataSource.delete(Notification.class)
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toObservable()
|
||||
.flatMap(integer -> Observable.from(models)))
|
||||
.flatMap(integer -> Observable.fromIterable(models)))
|
||||
.flatMap(notification -> notification.save(notification).toObservable());
|
||||
}
|
||||
|
||||
public static Observable<List<Notification>> getUnreadNotifications() {
|
||||
public static Single<List<Notification>> getUnreadNotifications() {
|
||||
return App.getInstance()
|
||||
.getDataStore()
|
||||
.select(Notification.class)
|
||||
.where(Notification.UNREAD.eq(true))
|
||||
.orderBy(Notification.UPDATED_AT.desc())
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static Observable<List<Notification>> getAlltNotifications() {
|
||||
public static Single<List<Notification>> getAlltNotifications() {
|
||||
return App.getInstance()
|
||||
.getDataStore()
|
||||
.select(Notification.class)
|
||||
.orderBy(Notification.UPDATED_AT.desc(), Notification.UNREAD.eq(false).getLeftOperand())
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
@ -104,8 +98,6 @@ import rx.Single;
|
||||
.count(Notification.class)
|
||||
.where(Notification.UNREAD.equal(true))
|
||||
.get()
|
||||
.toSingle()
|
||||
.toBlocking()
|
||||
.value() > 0;
|
||||
}
|
||||
|
||||
|
||||
@ -10,14 +10,13 @@ import com.fastaccess.helper.RxHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Single;
|
||||
import io.requery.Column;
|
||||
import io.requery.Convert;
|
||||
import io.requery.Entity;
|
||||
import io.requery.Generated;
|
||||
import io.requery.Key;
|
||||
import lombok.NoArgsConstructor;
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
|
||||
import static com.fastaccess.data.dao.model.PinnedRepos.ID;
|
||||
import static com.fastaccess.data.dao.model.PinnedRepos.REPO_FULL_NAME;
|
||||
@ -41,7 +40,7 @@ import static com.fastaccess.data.dao.model.PinnedRepos.REPO_FULL_NAME;
|
||||
PinnedRepos pinned = new PinnedRepos();
|
||||
pinned.setRepoFullName(repo.getFullName());
|
||||
pinned.setPinnedRepo(repo);
|
||||
save(pinned).toObservable().toBlocking().firstOrDefault(null);
|
||||
save(pinned).toObservable().blockingFirst(null);
|
||||
return true;
|
||||
} else {
|
||||
delete(pinnedRepos.getId());
|
||||
@ -67,11 +66,11 @@ import static com.fastaccess.data.dao.model.PinnedRepos.REPO_FULL_NAME;
|
||||
return get(repoFullName) != null;
|
||||
}
|
||||
|
||||
@NonNull public static Observable<List<PinnedRepos>> getMyPinnedRepos() {
|
||||
@NonNull public static Single<List<PinnedRepos>> getMyPinnedRepos() {
|
||||
return App.getInstance().getDataStore().select(PinnedRepos.class)
|
||||
.orderBy(ID.desc())
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
|
||||
}
|
||||
|
||||
@ -28,15 +28,15 @@ import com.fastaccess.ui.widgets.SpannableBuilder;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import io.requery.Column;
|
||||
import io.requery.Convert;
|
||||
import io.requery.Entity;
|
||||
import io.requery.Key;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.rx.SingleEntityStore;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
import lombok.NoArgsConstructor;
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
|
||||
import static com.fastaccess.data.dao.model.PullRequest.ID;
|
||||
import static com.fastaccess.data.dao.model.PullRequest.LOGIN;
|
||||
@ -90,25 +90,19 @@ import static com.fastaccess.data.dao.model.PullRequest.UPDATED_AT;
|
||||
@Convert(PullRequestConverter.class) PullRequest pullRequest;
|
||||
@Convert(ReactionsConverter.class) ReactionsModel reactions;
|
||||
|
||||
public Single save(PullRequest entity) {
|
||||
return RxHelper.getSingle(
|
||||
App.getInstance().getDataStore()
|
||||
.delete(PullRequest.class)
|
||||
.where(ID.eq(entity.getId()))
|
||||
.get()
|
||||
.toSingle()
|
||||
.flatMap(integer -> App.getInstance().getDataStore().insert(entity)));
|
||||
public Single<PullRequest> save(PullRequest entity) {
|
||||
return RxHelper.getSingle(App.getInstance().getDataStore().upsert(entity));
|
||||
}
|
||||
|
||||
public static Observable<PullRequest> save(@NonNull List<PullRequest> models, @NonNull String repoId, @NonNull String login) {
|
||||
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
ReactiveEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
return RxHelper.safeObservable(singleEntityStore.delete(PullRequest.class)
|
||||
.where(REPO_ID.equal(repoId)
|
||||
.and(LOGIN.equal(login)))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toObservable()
|
||||
.flatMap(integer -> Observable.from(models))
|
||||
.flatMap(integer -> Observable.fromIterable(models))
|
||||
.flatMap(pulRequest -> {
|
||||
pulRequest.setRepoId(repoId);
|
||||
pulRequest.setLogin(login);
|
||||
@ -116,8 +110,8 @@ import static com.fastaccess.data.dao.model.PullRequest.UPDATED_AT;
|
||||
}));
|
||||
}
|
||||
|
||||
public static Observable<List<PullRequest>> getPullRequests(@NonNull String repoId, @NonNull String login,
|
||||
@NonNull IssueState issueState) {
|
||||
public static Single<List<PullRequest>> getPullRequests(@NonNull String repoId, @NonNull String login,
|
||||
@NonNull IssueState issueState) {
|
||||
return App.getInstance().getDataStore()
|
||||
.select(PullRequest.class)
|
||||
.where(REPO_ID.equal(repoId)
|
||||
@ -125,7 +119,7 @@ import static com.fastaccess.data.dao.model.PullRequest.UPDATED_AT;
|
||||
.and(STATE.equal(issueState)))
|
||||
.orderBy(UPDATED_AT.desc())
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
@ -134,7 +128,7 @@ import static com.fastaccess.data.dao.model.PullRequest.UPDATED_AT;
|
||||
.select(PullRequest.class)
|
||||
.where(ID.eq(id))
|
||||
.get()
|
||||
.toObservable();
|
||||
.observable();
|
||||
}
|
||||
|
||||
public static Observable<PullRequest> getPullRequestByNumber(int number, @NonNull String repoId, @NonNull String login) {
|
||||
@ -144,7 +138,7 @@ import static com.fastaccess.data.dao.model.PullRequest.UPDATED_AT;
|
||||
.and(LOGIN.equal(login))
|
||||
.and(NUMBER.equal(number)))
|
||||
.get()
|
||||
.toObservable();
|
||||
.observable();
|
||||
}
|
||||
|
||||
@NonNull public static SpannableBuilder getMergeBy(@NonNull PullRequest pullRequest, @NonNull Context context, boolean showRepoName) {
|
||||
|
||||
@ -14,16 +14,14 @@ import com.google.gson.annotations.SerializedName;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import io.requery.Convert;
|
||||
import io.requery.Entity;
|
||||
import io.requery.Key;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.Table;
|
||||
import io.requery.rx.SingleEntityStore;
|
||||
import lombok.NoArgsConstructor;
|
||||
import rx.Completable;
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
|
||||
import static com.fastaccess.data.dao.model.Release.CREATED_AT;
|
||||
import static com.fastaccess.data.dao.model.Release.ID;
|
||||
@ -57,23 +55,16 @@ public abstract class AbstractRelease implements Parcelable {
|
||||
@Convert(ReleasesAssetsConverter.class) ReleasesAssetsListModel assets;
|
||||
|
||||
public Single<Release> save(Release entity) {
|
||||
return RxHelper.getSingle(
|
||||
App.getInstance().getDataStore()
|
||||
.delete(Release.class)
|
||||
.where(ID.eq(entity.getId()))
|
||||
.get()
|
||||
.toSingle()
|
||||
.flatMap(i -> App.getInstance().getDataStore().insert(entity)));
|
||||
return RxHelper.getSingle(App.getInstance().getDataStore().upsert(entity));
|
||||
}
|
||||
|
||||
public static Observable<Release> save(@NonNull List<Release> models, @NonNull String repoId, @NonNull String login) {
|
||||
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
return RxHelper.safeObservable(singleEntityStore.delete(Release.class)
|
||||
return RxHelper.safeObservable(App.getInstance().getDataStore().delete(Release.class)
|
||||
.where(REPO_ID.eq(login))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toObservable()
|
||||
.flatMap(integer -> Observable.from(models))
|
||||
.flatMap(integer -> Observable.fromIterable(models))
|
||||
.flatMap(releasesModel -> {
|
||||
releasesModel.setRepoId(repoId);
|
||||
releasesModel.setLogin(login);
|
||||
@ -88,7 +79,7 @@ public abstract class AbstractRelease implements Parcelable {
|
||||
.where(REPO_ID.eq(repoId)
|
||||
.and(LOGIN.eq(login)))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toCompletable();
|
||||
}
|
||||
|
||||
@ -97,17 +88,17 @@ public abstract class AbstractRelease implements Parcelable {
|
||||
.select(Release.class)
|
||||
.where(ID.eq(id))
|
||||
.get()
|
||||
.toObservable();
|
||||
.observable();
|
||||
}
|
||||
|
||||
public static Observable<List<Release>> get(@NonNull String repoId, @NonNull String login) {
|
||||
public static Single<List<Release>> get(@NonNull String repoId, @NonNull String login) {
|
||||
return App.getInstance().getDataStore()
|
||||
.select(Release.class)
|
||||
.where(REPO_ID.eq(repoId)
|
||||
.and(LOGIN.eq(login)))
|
||||
.orderBy(CREATED_AT.desc())
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
||||
@ -19,16 +19,17 @@ import com.google.gson.annotations.SerializedName;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Maybe;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import io.requery.Column;
|
||||
import io.requery.Convert;
|
||||
import io.requery.Entity;
|
||||
import io.requery.Key;
|
||||
import io.requery.Nullable;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.rx.SingleEntityStore;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
import lombok.NoArgsConstructor;
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
|
||||
import static com.fastaccess.data.dao.model.Repo.FULL_NAME;
|
||||
import static com.fastaccess.data.dao.model.Repo.ID;
|
||||
@ -120,20 +121,15 @@ import static com.fastaccess.data.dao.model.Repo.UPDATED_AT;
|
||||
String reposOwner;
|
||||
|
||||
public Single<Repo> save(@NonNull Repo entity) {
|
||||
return RxHelper.getSingle(
|
||||
App.getInstance().getDataStore().delete(Repo.class)
|
||||
.where(ID.eq(entity.getId()))
|
||||
.get()
|
||||
.toSingle()
|
||||
.flatMap(i -> App.getInstance().getDataStore().insert(entity)));
|
||||
return RxHelper.getSingle(App.getInstance().getDataStore().upsert(entity));
|
||||
}
|
||||
|
||||
public static Observable<Repo> getRepo(@NonNull String name, @NonNull String login) {
|
||||
public static Maybe<Repo> getRepo(@NonNull String name, @NonNull String login) {
|
||||
return App.getInstance().getDataStore()
|
||||
.select(Repo.class)
|
||||
.where(FULL_NAME.eq(login + "/" + name))
|
||||
.get()
|
||||
.toObservable();
|
||||
.maybe();
|
||||
}
|
||||
|
||||
public static Repo getRepo(long id) {
|
||||
@ -145,13 +141,13 @@ import static com.fastaccess.data.dao.model.Repo.UPDATED_AT;
|
||||
}
|
||||
|
||||
public static Observable<Repo> saveStarred(@NonNull List<Repo> models, @NonNull String starredUser) {
|
||||
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
ReactiveEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
return RxHelper.safeObservable(singleEntityStore.delete(Repo.class)
|
||||
.where(STARRED_USER.eq(starredUser))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toObservable()
|
||||
.flatMap(integer -> Observable.from(models))
|
||||
.flatMap(integer -> Observable.fromIterable(models))
|
||||
.flatMap(repo -> {
|
||||
repo.setStarredUser(starredUser);
|
||||
return repo.save(repo).toObservable();
|
||||
@ -159,36 +155,36 @@ import static com.fastaccess.data.dao.model.Repo.UPDATED_AT;
|
||||
}
|
||||
|
||||
public static Observable<Repo> saveMyRepos(@NonNull List<Repo> models, @NonNull String reposOwner) {
|
||||
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
ReactiveEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
return RxHelper.safeObservable(singleEntityStore.delete(Repo.class)
|
||||
.where(REPOS_OWNER.eq(reposOwner))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toObservable()
|
||||
.flatMap(integer -> Observable.from(models))
|
||||
.flatMap(integer -> Observable.fromIterable(models))
|
||||
.flatMap(repo -> {
|
||||
repo.setReposOwner(reposOwner);
|
||||
return repo.save(repo).toObservable();
|
||||
}));
|
||||
}
|
||||
|
||||
public static Observable<List<Repo>> getStarred(@NonNull String starredUser) {
|
||||
public static Single<List<Repo>> getStarred(@NonNull String starredUser) {
|
||||
return App.getInstance().getDataStore()
|
||||
.select(Repo.class)
|
||||
.where(STARRED_USER.eq(starredUser))
|
||||
.orderBy(UPDATED_AT.desc())
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static Observable<List<Repo>> getMyRepos(@NonNull String reposOwner) {
|
||||
public static Single<List<Repo>> getMyRepos(@NonNull String reposOwner) {
|
||||
return App.getInstance().getDataStore()
|
||||
.select(Repo.class)
|
||||
.where(REPOS_OWNER.eq(reposOwner))
|
||||
.orderBy(UPDATED_AT.desc())
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
||||
@ -10,14 +10,14 @@ import com.fastaccess.helper.RxHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import io.requery.Entity;
|
||||
import io.requery.Generated;
|
||||
import io.requery.Key;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.rx.SingleEntityStore;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
import lombok.NoArgsConstructor;
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
|
||||
import static com.fastaccess.data.dao.model.RepoFile.LOGIN;
|
||||
import static com.fastaccess.data.dao.model.RepoFile.REPO_ID;
|
||||
@ -48,14 +48,14 @@ import static com.fastaccess.data.dao.model.RepoFile.TYPE;
|
||||
}
|
||||
|
||||
public static Observable<RepoFile> save(@NonNull List<RepoFile> models, @NonNull String login, @NonNull String repoId) {
|
||||
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
ReactiveEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
return RxHelper.safeObservable(singleEntityStore.delete(RepoFile.class)
|
||||
.where(REPO_ID.eq(repoId)
|
||||
.and(LOGIN.eq(login)))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toObservable()
|
||||
.flatMap(integer -> Observable.from(models))
|
||||
.flatMap(integer -> Observable.fromIterable(models))
|
||||
.flatMap(filesModel -> {
|
||||
filesModel.setRepoId(repoId);
|
||||
filesModel.setLogin(login);
|
||||
@ -63,14 +63,14 @@ import static com.fastaccess.data.dao.model.RepoFile.TYPE;
|
||||
}));
|
||||
}
|
||||
|
||||
public static Observable<List<RepoFile>> getFiles(@NonNull String login, @NonNull String repoId) {
|
||||
public static Single<List<RepoFile>> getFiles(@NonNull String login, @NonNull String repoId) {
|
||||
return App.getInstance().getDataStore()
|
||||
.select(RepoFile.class)
|
||||
.where(REPO_ID.eq(repoId)
|
||||
.and(LOGIN.eq(login)))
|
||||
.orderBy(TYPE.asc())
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ import static com.fastaccess.data.dao.model.RepoFile.TYPE;
|
||||
.and(SHA.eq(sha)))
|
||||
.orderBy(TYPE.asc())
|
||||
.get()
|
||||
.toObservable();
|
||||
.observable();
|
||||
}
|
||||
|
||||
@Override public int describeContents() { return 0; }
|
||||
|
||||
@ -8,10 +8,9 @@ import com.fastaccess.helper.RxHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Single;
|
||||
import io.requery.Column;
|
||||
import io.requery.Entity;
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 01 Jan 2017, 11:20 PM
|
||||
@ -28,16 +27,16 @@ public abstract class AbstractSearchHistory implements Parcelable {
|
||||
.delete(SearchHistory.class)
|
||||
.where(SearchHistory.TEXT.eq(entity.getText()))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.flatMap(integer -> App.getInstance().getDataStore().insert(entity)));
|
||||
}
|
||||
|
||||
public static Observable<List<SearchHistory>> getHistory() {
|
||||
public static Single<List<SearchHistory>> getHistory() {
|
||||
return App.getInstance().getDataStore()
|
||||
.select(SearchHistory.class)
|
||||
.groupBy(SearchHistory.TEXT.asc())
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
||||
@ -11,15 +11,15 @@ import com.fastaccess.helper.RxHelper;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import io.requery.Column;
|
||||
import io.requery.Entity;
|
||||
import io.requery.Key;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.Table;
|
||||
import io.requery.rx.SingleEntityStore;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
import lombok.NoArgsConstructor;
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
|
||||
import static com.fastaccess.data.dao.model.User.FOLLOWER_NAME;
|
||||
import static com.fastaccess.data.dao.model.User.FOLLOWING_NAME;
|
||||
@ -72,20 +72,14 @@ public abstract class AbstractUser implements Parcelable {
|
||||
|
||||
public void save(User entity) {
|
||||
if (getUser(entity.getId()) != null) {
|
||||
App.getInstance().getDataStore().update(entity).toBlocking().value();
|
||||
App.getInstance().getDataStore().update(entity).blockingGet();
|
||||
} else {
|
||||
App.getInstance().getDataStore().insert(entity).toBlocking().value();
|
||||
App.getInstance().getDataStore().insert(entity).blockingGet();
|
||||
}
|
||||
}
|
||||
|
||||
protected Single<User> saveAsSingle(User user) {
|
||||
return RxHelper.getSingle(
|
||||
App.getInstance().getDataStore()
|
||||
.delete(User.class)
|
||||
.where(LOGIN.eq(user.getLogin()))
|
||||
.get()
|
||||
.toSingle()
|
||||
.flatMap(aVoid -> App.getInstance().getDataStore().insert(user)));
|
||||
protected Single<User> saveAsSingle(User entity) {
|
||||
return RxHelper.getSingle(App.getInstance().getDataStore().upsert(entity));
|
||||
}
|
||||
|
||||
@Nullable public static User getUser(String login) {
|
||||
@ -104,72 +98,72 @@ public abstract class AbstractUser implements Parcelable {
|
||||
.firstOrNull();
|
||||
}
|
||||
|
||||
public static Observable saveUserFollowerList(@NonNull List<User> models, @NonNull String followingName) {
|
||||
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
public static Observable<User> saveUserFollowerList(@NonNull List<User> models, @NonNull String followingName) {
|
||||
ReactiveEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
return RxHelper.safeObservable(singleEntityStore.delete(User.class)
|
||||
.where(FOLLOWING_NAME.eq(followingName))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toObservable()
|
||||
.flatMap(integer -> Observable.from(models))
|
||||
.flatMap(integer -> Observable.fromIterable(models))
|
||||
.flatMap(userModel -> {
|
||||
userModel.setFollowingName(followingName);
|
||||
return userModel.saveAsSingle(userModel).toObservable();
|
||||
}));
|
||||
}
|
||||
|
||||
public static Observable saveUserFollowingList(@NonNull List<User> models, @NonNull String followerName) {
|
||||
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
public static Observable<User> saveUserFollowingList(@NonNull List<User> models, @NonNull String followerName) {
|
||||
ReactiveEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
return RxHelper.safeObservable(singleEntityStore.delete(User.class)
|
||||
.where(FOLLOWER_NAME.eq(followerName))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toObservable()
|
||||
.flatMap(integer -> Observable.from(models))
|
||||
.flatMap(integer -> Observable.fromIterable(models))
|
||||
.flatMap(userModel -> {
|
||||
userModel.setFollowerName(followerName);
|
||||
return userModel.saveAsSingle(userModel).toObservable();
|
||||
}));
|
||||
}
|
||||
|
||||
public static Observable saveUserContributorList(@NonNull List<User> models, @NonNull String repoId) {
|
||||
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
public static Observable<User> saveUserContributorList(@NonNull List<User> models, @NonNull String repoId) {
|
||||
ReactiveEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
|
||||
return RxHelper.safeObservable(singleEntityStore.delete(User.class)
|
||||
.where(REPO_ID.eq(repoId))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.toObservable()
|
||||
.flatMap(integer -> Observable.from(models))
|
||||
.flatMap(integer -> Observable.fromIterable(models))
|
||||
.flatMap(userModel -> {
|
||||
userModel.setRepoId(repoId);
|
||||
return userModel.saveAsSingle(userModel).toObservable();
|
||||
}));
|
||||
}
|
||||
|
||||
@NonNull public static Observable<List<User>> getUserFollowerList(@NonNull String following) {
|
||||
@NonNull public static Single<List<User>> getUserFollowerList(@NonNull String following) {
|
||||
return App.getInstance().getDataStore()
|
||||
.select(User.class)
|
||||
.where(FOLLOWING_NAME.eq(following))
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
@NonNull public static Observable<List<User>> getUserFollowingList(@NonNull String follower) {
|
||||
@NonNull public static Single<List<User>> getUserFollowingList(@NonNull String follower) {
|
||||
return App.getInstance().getDataStore()
|
||||
.select(User.class)
|
||||
.where(FOLLOWER_NAME.eq(follower))
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
@NonNull public static Observable<List<User>> getUserContributorList(@NonNull String repoId) {
|
||||
@NonNull public static Single<List<User>> getUserContributorList(@NonNull String repoId) {
|
||||
return App.getInstance().getDataStore()
|
||||
.select(User.class)
|
||||
.where(REPO_ID.eq(repoId))
|
||||
.get()
|
||||
.toObservable()
|
||||
.observable()
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
||||
@ -12,8 +12,7 @@ import io.requery.Entity;
|
||||
import io.requery.Generated;
|
||||
import io.requery.Key;
|
||||
import lombok.NoArgsConstructor;
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
import io.reactivex.Observable;import io.reactivex.Single;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 06 Dec 2016, 10:42 PM
|
||||
@ -31,7 +30,7 @@ import rx.Single;
|
||||
.delete(ViewerFile.class)
|
||||
.where(ViewerFile.FULL_URL.eq(modelEntity.getFullUrl()))
|
||||
.get()
|
||||
.toSingle()
|
||||
.single()
|
||||
.flatMap(i -> App.getInstance().getDataStore().insert(modelEntity)));
|
||||
}
|
||||
|
||||
@ -41,7 +40,7 @@ import rx.Single;
|
||||
.select(ViewerFile.class)
|
||||
.where(ViewerFile.FULL_URL.equal(url))
|
||||
.get()
|
||||
.toObservable();
|
||||
.observable();
|
||||
}
|
||||
|
||||
@Override public int describeContents() { return 0; }
|
||||
|
||||
@ -19,7 +19,7 @@ import retrofit2.http.PUT;
|
||||
import retrofit2.http.Path;
|
||||
import retrofit2.http.Query;
|
||||
import retrofit2.http.Url;
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 20 Nov 2016, 10:28 AM
|
||||
|
||||
@ -8,7 +8,7 @@ import okhttp3.RequestBody;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Query;
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 15 Apr 2017, 8:06 PM
|
||||
|
||||
@ -25,7 +25,7 @@ import retrofit2.http.POST;
|
||||
import retrofit2.http.PUT;
|
||||
import retrofit2.http.Path;
|
||||
import retrofit2.http.Query;
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
public interface IssueService {
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Headers;
|
||||
import retrofit2.http.POST;
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
public interface LoginRestService {
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ import retrofit2.http.POST;
|
||||
import retrofit2.http.Path;
|
||||
import retrofit2.http.Query;
|
||||
import retrofit2.http.Url;
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 19 Feb 2017, 6:34 PM
|
||||
|
||||
@ -12,7 +12,7 @@ import retrofit2.Response;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Path;
|
||||
import retrofit2.http.Query;
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 22 Mar 2017, 6:44 PM
|
||||
|
||||
@ -21,7 +21,7 @@ import retrofit2.http.POST;
|
||||
import retrofit2.http.PUT;
|
||||
import retrofit2.http.Path;
|
||||
import retrofit2.http.Query;
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 15 Dec 2016, 10:21 PM
|
||||
|
||||
@ -14,7 +14,7 @@ import retrofit2.http.Headers;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Path;
|
||||
import retrofit2.http.Query;
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 29 Mar 2017, 9:48 PM
|
||||
|
||||
@ -29,7 +29,7 @@ import retrofit2.http.PUT;
|
||||
import retrofit2.http.Path;
|
||||
import retrofit2.http.Query;
|
||||
import retrofit2.http.Url;
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 10 Dec 2016, 3:16 PM
|
||||
|
||||
@ -15,7 +15,7 @@ import retrofit2.http.Headers;
|
||||
import retrofit2.http.PATCH;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Path;
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 07 May 2017, 1:01 PM
|
||||
|
||||
@ -8,7 +8,7 @@ import com.fastaccess.data.dao.model.User;
|
||||
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 08 Dec 2016, 9:07 PM
|
||||
|
||||
@ -6,7 +6,7 @@ import com.fastaccess.data.dao.SlackResponseModel;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.Headers;
|
||||
import retrofit2.http.POST;
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 01 May 2017, 1:04 AM
|
||||
|
||||
@ -8,6 +8,7 @@ import com.fastaccess.data.dao.model.Login;
|
||||
import com.fastaccess.data.dao.model.Repo;
|
||||
import com.fastaccess.data.dao.model.User;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.http.DELETE;
|
||||
import retrofit2.http.GET;
|
||||
@ -15,7 +16,7 @@ import retrofit2.http.PUT;
|
||||
import retrofit2.http.Path;
|
||||
import retrofit2.http.Query;
|
||||
import retrofit2.http.Url;
|
||||
import rx.Observable;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Kosh on 08 Feb 2017, 8:54 PM
|
||||
|
||||
@ -2,10 +2,11 @@ package com.fastaccess.helper;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Kosh on 11 Nov 2016, 11:53 AM
|
||||
@ -20,13 +21,13 @@ public class RxHelper {
|
||||
|
||||
public static <T> Observable<T> safeObservable(@NonNull Observable<T> observable) {
|
||||
return getObserver(observable)
|
||||
.onErrorReturn(throwable -> null);
|
||||
.onErrorReturn(throwable -> null)
|
||||
.doOnError(Throwable::printStackTrace);
|
||||
}
|
||||
|
||||
public static <T> Single<T> getSingle(@NonNull Single<T> observable) {
|
||||
return observable
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.onErrorReturn(throwable -> null);
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 26 Mar 2017, 10:07 PM
|
||||
|
||||
@ -21,8 +21,8 @@ import java.lang.reflect.Type;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.schedulers.Schedulers;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 27 May 2017, 9:50 PM
|
||||
|
||||
@ -12,8 +12,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.schedulers.Schedulers;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Holds the loaded emojis and provides search functions.
|
||||
|
||||
@ -5,111 +5,107 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class EmojiTrie {
|
||||
private Node root = new Node();
|
||||
private Node root = new Node();
|
||||
|
||||
public EmojiTrie(Collection<Emoji> emojis) {
|
||||
for (Emoji emoji : emojis) {
|
||||
Node tree = root;
|
||||
for (char c: emoji.getUnicode().toCharArray()) {
|
||||
if (!tree.hasChild(c)) {
|
||||
tree.addChild(c);
|
||||
public EmojiTrie(Collection<Emoji> emojis) {
|
||||
for (Emoji emoji : emojis) {
|
||||
Node tree = root;
|
||||
for (char c : emoji.getUnicode().toCharArray()) {
|
||||
if (!tree.hasChild(c)) {
|
||||
tree.addChild(c);
|
||||
}
|
||||
tree = tree.getChild(c);
|
||||
}
|
||||
tree.setEmoji(emoji);
|
||||
}
|
||||
tree = tree.getChild(c);
|
||||
}
|
||||
tree.setEmoji(emoji);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if sequence of chars contain an emoji.
|
||||
*
|
||||
* @param sequence Sequence of char that may contain emoji in full or
|
||||
* partially.
|
||||
*
|
||||
* @return
|
||||
* <li>
|
||||
* Matches.EXACTLY if char sequence in its entirety is an emoji
|
||||
* </li>
|
||||
* <li>
|
||||
* Matches.POSSIBLY if char sequence matches prefix of an emoji
|
||||
* </li>
|
||||
* <li>
|
||||
* Matches.IMPOSSIBLE if char sequence matches no emoji or prefix of an
|
||||
* emoji
|
||||
* </li>
|
||||
*/
|
||||
public Matches isEmoji(char[] sequence) {
|
||||
if (sequence == null) {
|
||||
return Matches.POSSIBLY;
|
||||
}
|
||||
|
||||
Node tree = root;
|
||||
for (char c : sequence) {
|
||||
if (!tree.hasChild(c)) {
|
||||
return Matches.IMPOSSIBLE;
|
||||
}
|
||||
tree = tree.getChild(c);
|
||||
|
||||
/**
|
||||
* Checks if sequence of chars contain an emoji.
|
||||
*
|
||||
* @param sequence
|
||||
* Sequence of char that may contain emoji in full or partially.
|
||||
* @return <li> Matches.EXACTLY if char sequence in its entirety is an emoji </li> <li> Matches.POSSIBLY if char sequence
|
||||
* matches prefix of an emoji </li> <li> Matches.IMPOSSIBLE if char sequence matches no emoji or prefix of an emoji </li>
|
||||
*/
|
||||
public Matches isEmoji(char[] sequence) {
|
||||
if (sequence == null) {
|
||||
return Matches.POSSIBLY;
|
||||
}
|
||||
|
||||
Node tree = root;
|
||||
for (char c : sequence) {
|
||||
if (!tree.hasChild(c)) {
|
||||
return Matches.IMPOSSIBLE;
|
||||
}
|
||||
tree = tree.getChild(c);
|
||||
}
|
||||
|
||||
return tree.isEndOfEmoji() ? Matches.EXACTLY : Matches.POSSIBLY;
|
||||
}
|
||||
|
||||
return tree.isEndOfEmoji() ? Matches.EXACTLY : Matches.POSSIBLY;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds Emoji instance from emoji unicode
|
||||
* @param unicode unicode of emoji to get
|
||||
* @return Emoji instance if unicode matches and emoji, null otherwise.
|
||||
*/
|
||||
public Emoji getEmoji(String unicode) {
|
||||
Node tree = root;
|
||||
for (char c : unicode.toCharArray()) {
|
||||
if (!tree.hasChild(c)) {
|
||||
return null;
|
||||
}
|
||||
tree = tree.getChild(c);
|
||||
}
|
||||
return tree.getEmoji();
|
||||
}
|
||||
|
||||
public enum Matches {
|
||||
EXACTLY, POSSIBLY, IMPOSSIBLE;
|
||||
|
||||
public boolean exactMatch() {
|
||||
return this == EXACTLY;
|
||||
/**
|
||||
* Finds Emoji instance from emoji unicode
|
||||
*
|
||||
* @param unicode
|
||||
* unicode of emoji to get
|
||||
* @return Emoji instance if unicode matches and emoji, null otherwise.
|
||||
*/
|
||||
public Emoji getEmoji(String unicode) {
|
||||
Node tree = root;
|
||||
for (char c : unicode.toCharArray()) {
|
||||
if (!tree.hasChild(c)) {
|
||||
return null;
|
||||
}
|
||||
tree = tree.getChild(c);
|
||||
}
|
||||
return tree.getEmoji();
|
||||
}
|
||||
|
||||
public boolean impossibleMatch() {
|
||||
return this == IMPOSSIBLE;
|
||||
}
|
||||
}
|
||||
public enum Matches {
|
||||
EXACTLY, POSSIBLY, IMPOSSIBLE;
|
||||
|
||||
private class Node {
|
||||
private Map<Character, Node> children = new HashMap<Character, Node>();
|
||||
private Emoji emoji;
|
||||
public boolean exactMatch() {
|
||||
return this == EXACTLY;
|
||||
}
|
||||
|
||||
private void setEmoji(Emoji emoji) {
|
||||
this.emoji = emoji;
|
||||
public boolean impossibleMatch() {
|
||||
return this == IMPOSSIBLE;
|
||||
}
|
||||
|
||||
public boolean possibleMatch() {
|
||||
return this == POSSIBLY;
|
||||
}
|
||||
}
|
||||
|
||||
private Emoji getEmoji() {
|
||||
return emoji;
|
||||
}
|
||||
private class Node {
|
||||
private Map<Character, Node> children = new HashMap<Character, Node>();
|
||||
private Emoji emoji;
|
||||
|
||||
private boolean hasChild(char child) {
|
||||
return children.containsKey(child);
|
||||
}
|
||||
private void setEmoji(Emoji emoji) {
|
||||
this.emoji = emoji;
|
||||
}
|
||||
|
||||
private void addChild(char child) {
|
||||
children.put(child, new Node());
|
||||
}
|
||||
private Emoji getEmoji() {
|
||||
return emoji;
|
||||
}
|
||||
|
||||
private Node getChild(char child) {
|
||||
return children.get(child);
|
||||
}
|
||||
private boolean hasChild(char child) {
|
||||
return children.containsKey(child);
|
||||
}
|
||||
|
||||
private boolean isEndOfEmoji() {
|
||||
return emoji != null;
|
||||
private void addChild(char child) {
|
||||
children.put(child, new Node());
|
||||
}
|
||||
|
||||
private Node getChild(char child) {
|
||||
return children.get(child);
|
||||
}
|
||||
|
||||
private boolean isEndOfEmoji() {
|
||||
return emoji != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 15 Apr 2017, 7:59 PM
|
||||
@ -51,7 +51,7 @@ public class ImgurProvider {
|
||||
.baseUrl(BuildConfig.IMGUR_URL)
|
||||
.client(provideOkHttpClient())
|
||||
.addConverterFactory(new GithubResponseConverter(gson))
|
||||
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ import java.lang.reflect.Modifier;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 08 Feb 2017, 8:37 PM
|
||||
@ -46,7 +46,7 @@ public class LoginProvider {
|
||||
.baseUrl(BuildConfig.REST_URL)
|
||||
.client(provideOkHttpClient(authToken, otp))
|
||||
.addConverterFactory(new GithubResponseConverter(gson))
|
||||
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ public class LoginProvider {
|
||||
.baseUrl("https://github.com/login/oauth/")
|
||||
.client(provideOkHttpClient(null, null))
|
||||
.addConverterFactory(new GithubResponseConverter(gson))
|
||||
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.build()
|
||||
.create(LoginRestService.class);
|
||||
}
|
||||
|
||||
@ -40,9 +40,9 @@ import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.HttpException;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 08 Feb 2017, 8:37 PM
|
||||
@ -91,7 +91,7 @@ public class RestProvider {
|
||||
.baseUrl(BuildConfig.REST_URL)
|
||||
.client(provideOkHttpClient(isRawString))
|
||||
.addConverterFactory(new GithubResponseConverter(gson))
|
||||
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -141,7 +141,7 @@ public class RestProvider {
|
||||
return new Retrofit.Builder()
|
||||
.baseUrl(BuildConfig.REST_URL)
|
||||
.addConverterFactory(new GithubResponseConverter(gson))
|
||||
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.build()
|
||||
.create(UserRestService.class);
|
||||
}
|
||||
@ -207,7 +207,7 @@ public class RestProvider {
|
||||
return new Retrofit.Builder()
|
||||
.baseUrl("https://ok13pknpj4.execute-api.eu-central-1.amazonaws.com/prod/")
|
||||
.addConverterFactory(new GithubResponseConverter(gson))
|
||||
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.build()
|
||||
.create(SlackService.class);
|
||||
}
|
||||
|
||||
@ -18,7 +18,8 @@ import com.fastaccess.provider.rest.RestProvider;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import rx.schedulers.Schedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Kosh on 12 Mar 2017, 2:25 PM
|
||||
@ -113,7 +114,7 @@ public class GithubActionService extends IntentService {
|
||||
String msg = getString(R.string.forking, getString(R.string.gist));
|
||||
RestProvider.getGistService()
|
||||
.forkGist(id)
|
||||
.doOnSubscribe(() -> showNotification(msg))
|
||||
.doOnSubscribe(disposable -> showNotification(msg))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(response -> {
|
||||
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
|
||||
@ -125,7 +126,7 @@ public class GithubActionService extends IntentService {
|
||||
String msg = getString(R.string.forking, id);
|
||||
RestProvider.getRepoService()
|
||||
.forkRepo(login, id)
|
||||
.doOnSubscribe(() -> showNotification(msg))
|
||||
.doOnSubscribe(disposable -> showNotification(msg))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(response -> {
|
||||
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
|
||||
@ -137,7 +138,7 @@ public class GithubActionService extends IntentService {
|
||||
String msg = getString(R.string.starring, getString(R.string.gist));
|
||||
RestProvider.getGistService()
|
||||
.starGist(id)
|
||||
.doOnSubscribe(() -> showNotification(msg))
|
||||
.doOnSubscribe(disposable -> showNotification(msg))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(response -> {
|
||||
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
|
||||
@ -149,7 +150,7 @@ public class GithubActionService extends IntentService {
|
||||
String msg = getString(R.string.starring, id);
|
||||
RestProvider.getRepoService()
|
||||
.starRepo(login, id)
|
||||
.doOnSubscribe(() -> showNotification(msg))
|
||||
.doOnSubscribe(disposable -> showNotification(msg))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(response -> {
|
||||
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
|
||||
@ -161,7 +162,7 @@ public class GithubActionService extends IntentService {
|
||||
String msg = getString(R.string.un_starring, getString(R.string.gist));
|
||||
RestProvider.getGistService()
|
||||
.unStarGist(id)
|
||||
.doOnSubscribe(() -> showNotification(msg))
|
||||
.doOnSubscribe(disposable -> showNotification(msg))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(response -> {
|
||||
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
|
||||
@ -173,7 +174,7 @@ public class GithubActionService extends IntentService {
|
||||
String msg = getString(R.string.un_starring, id);
|
||||
RestProvider.getRepoService()
|
||||
.unstarRepo(login, id)
|
||||
.doOnSubscribe(() -> showNotification(msg))
|
||||
.doOnSubscribe(disposable -> showNotification(msg))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(response -> {
|
||||
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
|
||||
@ -185,7 +186,7 @@ public class GithubActionService extends IntentService {
|
||||
String msg = getString(R.string.un_watching, id);
|
||||
RestProvider.getRepoService()
|
||||
.unwatchRepo(login, id)
|
||||
.doOnSubscribe(() -> showNotification(msg))
|
||||
.doOnSubscribe(disposable -> showNotification(msg))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(response -> {
|
||||
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
|
||||
@ -197,7 +198,7 @@ public class GithubActionService extends IntentService {
|
||||
String msg = getString(R.string.watching, id);
|
||||
RestProvider.getRepoService()
|
||||
.watchRepo(login, id)
|
||||
.doOnSubscribe(() -> showNotification(msg))
|
||||
.doOnSubscribe(disposable -> showNotification(msg))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(response -> {
|
||||
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
|
||||
|
||||
@ -68,14 +68,14 @@ public class ReactionService extends IntentService {
|
||||
private void post(@NonNull ReactionTypes reactionType, @NonNull String login, @NonNull String repo, long commentId) {
|
||||
RxHelper.safeObservable(RestProvider.getReactionsService()
|
||||
.postIssueCommentReaction(new PostReactionModel(reactionType.getContent()), login, repo, commentId))
|
||||
.doOnSubscribe(() -> showNotificatin(getNotification(reactionType), (int) commentId))
|
||||
.doOnSubscribe(disposable -> showNotificatin(getNotification(reactionType), (int) commentId))
|
||||
.subscribe(response -> hideNotificat((int) commentId), throwable -> hideNotificat((int) commentId));
|
||||
}
|
||||
|
||||
private void postCommit(@NonNull ReactionTypes reactionType, @NonNull String login, @NonNull String repo, long commentId) {
|
||||
RxHelper.safeObservable(RestProvider.getReactionsService()
|
||||
.postCommitReaction(new PostReactionModel(reactionType.getContent()), login, repo, commentId))
|
||||
.doOnSubscribe(() -> showNotificatin(getNotification(reactionType), (int) commentId))
|
||||
.doOnSubscribe(disposable -> showNotificatin(getNotification(reactionType), (int) commentId))
|
||||
.subscribe(response -> hideNotificat((int) commentId), throwable -> hideNotificat((int) commentId));
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,6 @@ import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
@ -38,8 +37,8 @@ import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.schedulers.Schedulers;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 19 Feb 2017, 6:32 PM
|
||||
@ -110,7 +109,7 @@ public class NotificationSchedulerJobTask extends JobService {
|
||||
|
||||
private void onSave(@Nullable List<Notification> notificationThreadModels, JobParameters job) {
|
||||
if (notificationThreadModels != null) {
|
||||
RxHelper.safeObservable(Notification.save(notificationThreadModels)).subscribe();
|
||||
RxHelper.safeObservable(Notification.save(notificationThreadModels)).subscribe(notification -> {/**/}, Throwable::printStackTrace);
|
||||
onNotifyUser(notificationThreadModels, job);
|
||||
}
|
||||
}
|
||||
@ -126,14 +125,12 @@ public class NotificationSchedulerJobTask extends JobService {
|
||||
}
|
||||
Context context = getApplicationContext();
|
||||
int accentColor = ContextCompat.getColor(this, R.color.material_blue_700);
|
||||
Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(),
|
||||
R.mipmap.ic_launcher);
|
||||
String[] url = new String[1];
|
||||
Notification first = notificationThreadModels.get(0);
|
||||
Observable.from(notificationThreadModels)
|
||||
Observable.fromIterable(notificationThreadModels)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.filter(notification -> notification.isUnread() && first.getId() != notification.getId())
|
||||
.limit(10)
|
||||
.take(10)
|
||||
.flatMap(notification -> RestProvider.getNotificationService()
|
||||
.getComment(notification.getSubject().getLatestCommentUrl())
|
||||
.subscribeOn(Schedulers.io()), (thread, comment) -> {
|
||||
|
||||
@ -21,8 +21,8 @@ import com.fastaccess.helper.PrefGetter;
|
||||
import com.fastaccess.provider.rest.RestProvider;
|
||||
import com.fastaccess.provider.scheme.SchemeParser;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.schedulers.Schedulers;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 11 Mar 2017, 12:13 AM
|
||||
@ -108,7 +108,7 @@ public class ReadNotificationService extends IntentService {
|
||||
private void unSubscribeFromThread(long id) {
|
||||
RestProvider.getNotificationService()
|
||||
.unSubscribe(id)
|
||||
.doOnSubscribe(() -> notify(id, getNotification().build()))
|
||||
.doOnSubscribe(disposable -> notify(id, getNotification().build()))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.flatMap(notification1 -> Observable.create(subscriber -> markSingleAsRead(id)))
|
||||
.subscribe(booleanResponse -> cancel(id), throwable -> cancel(id));
|
||||
@ -136,7 +136,7 @@ public class ReadNotificationService extends IntentService {
|
||||
.subscribe();
|
||||
RestProvider.getNotificationService()
|
||||
.markAsRead(String.valueOf(id))
|
||||
.doOnSubscribe(() -> notify(id, getNotification().build()))
|
||||
.doOnSubscribe(disposable -> notify(id, getNotification().build()))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(booleanResponse -> cancel(id), throwable -> cancel(id));
|
||||
}
|
||||
|
||||
@ -31,7 +31,6 @@ public class SlackInvitationService extends IntentService {
|
||||
body.setLast_name(login.getLogin());
|
||||
RxHelper.getObserver(RestProvider.getSlackService()
|
||||
.invite(body))
|
||||
.onErrorReturn(throwable -> null)
|
||||
.subscribe(response -> {
|
||||
if (response != null) {
|
||||
if (response.isOk()) {
|
||||
@ -40,7 +39,7 @@ public class SlackInvitationService extends IntentService {
|
||||
Toasty.info(getApplicationContext(), response.getError().replaceAll("_", " ")).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}, Throwable::printStackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 09 Apr 2017, 10:40 AM
|
||||
|
||||
@ -2,6 +2,9 @@ package com.fastaccess.provider.timeline.handler;
|
||||
|
||||
import android.text.SpannableStringBuilder;
|
||||
|
||||
import com.fastaccess.helper.InputHelper;
|
||||
import com.fastaccess.helper.Logger;
|
||||
import com.fastaccess.provider.emoji.Emoji;
|
||||
import com.fastaccess.provider.emoji.EmojiManager;
|
||||
|
||||
import net.nightwhistler.htmlspanner.TagNodeHandler;
|
||||
@ -14,12 +17,19 @@ import org.htmlcleaner.TagNode;
|
||||
|
||||
public class EmojiHandler extends TagNodeHandler {
|
||||
|
||||
@Override public void handleTagNode(TagNode tagNode, SpannableStringBuilder spannableStringBuilder, int i, int i1) {
|
||||
|
||||
@Override public void handleTagNode(TagNode node, SpannableStringBuilder builder, int start, int end) {
|
||||
Logger.e(builder);
|
||||
String emoji = node.getAttributeByName("alias");
|
||||
Logger.e(emoji);
|
||||
if (!InputHelper.isEmpty(emoji)) {
|
||||
Emoji unicode = EmojiManager.getForAlias(emoji);
|
||||
if (unicode != null && unicode.getUnicode() != null) {
|
||||
builder.replace(start, end, unicode.getUnicode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void beforeChildren(TagNode node, SpannableStringBuilder builder) {
|
||||
super.beforeChildren(node, builder);
|
||||
builder.append(EmojiManager.getForAlias(node.getAttributeByName("alias")).getUnicode());
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +46,6 @@ import com.fastaccess.ui.modules.main.donation.DonationActivity;
|
||||
import com.fastaccess.ui.modules.main.orgs.OrgListDialogFragment;
|
||||
import com.fastaccess.ui.modules.notification.NotificationActivity;
|
||||
import com.fastaccess.ui.modules.pinned.PinnedReposActivity;
|
||||
import com.fastaccess.ui.modules.profile.banner.BannerInfoActivity;
|
||||
import com.fastaccess.ui.modules.settings.SettingsActivity;
|
||||
import com.fastaccess.ui.modules.user.UserPagerActivity;
|
||||
import com.fastaccess.ui.widgets.AvatarLayout;
|
||||
@ -77,6 +76,8 @@ public abstract class BaseActivity<V extends BaseMvp.FAView, P extends BasePrese
|
||||
@Nullable @BindView(R.id.drawer) public DrawerLayout drawer;
|
||||
@Nullable @BindView(R.id.extrasNav) public NavigationView extraNav;
|
||||
|
||||
@State Bundle presenterStateBundle = new Bundle();
|
||||
|
||||
private static int REFRESH_CODE = 64;
|
||||
|
||||
private long backPressTimer;
|
||||
@ -93,7 +94,7 @@ public abstract class BaseActivity<V extends BaseMvp.FAView, P extends BasePrese
|
||||
@Override protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
getPresenter().onSaveInstanceState(outState);
|
||||
Icepick.saveInstanceState(this, outState);
|
||||
Icepick.saveInstanceState(this, presenterStateBundle);
|
||||
}
|
||||
|
||||
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -113,7 +114,7 @@ public abstract class BaseActivity<V extends BaseMvp.FAView, P extends BasePrese
|
||||
Icepick.setDebug(BuildConfig.DEBUG);
|
||||
if (savedInstanceState != null && !savedInstanceState.isEmpty()) {
|
||||
Icepick.restoreInstanceState(this, savedInstanceState);
|
||||
getPresenter().onRestoreInstanceState(savedInstanceState);
|
||||
getPresenter().onRestoreInstanceState(presenterStateBundle);
|
||||
}
|
||||
setupToolbarAndStatusBar(toolbar);
|
||||
//showHideAds();
|
||||
@ -387,7 +388,8 @@ public abstract class BaseActivity<V extends BaseMvp.FAView, P extends BasePrese
|
||||
}
|
||||
|
||||
private void setupTheme() {
|
||||
if (this instanceof LoginActivity || this instanceof LoginChooserActivity) return; // we really should consider putting this outside as it starts growing :D
|
||||
if (this instanceof LoginActivity || this instanceof LoginChooserActivity)
|
||||
return; // we really should consider putting this outside as it starts growing :D
|
||||
int themeMode = PrefGetter.getThemeType(getApplicationContext());
|
||||
int themeColor = PrefGetter.getThemeColor(getApplicationContext());
|
||||
if (themeMode == PrefGetter.LIGHT) {
|
||||
|
||||
@ -10,9 +10,9 @@ import com.fastaccess.ui.widgets.dialog.MessageDialogView;
|
||||
import net.grandcentrix.thirtyinch.TiView;
|
||||
import net.grandcentrix.thirtyinch.callonmainthread.CallOnMainThread;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.Subscription;
|
||||
import rx.functions.Action1;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Consumer;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 25 May 2016, 9:09 PM
|
||||
@ -49,7 +49,9 @@ public interface BaseMvp {
|
||||
|
||||
void onRestoreInstanceState(Bundle outState);
|
||||
|
||||
void manageSubscription(@Nullable Subscription... subscription);
|
||||
void manageSubscription(@Nullable Disposable... disposables);
|
||||
|
||||
<T> void manageObservable(@Nullable Observable<T> observable);
|
||||
|
||||
boolean isApiCalled();
|
||||
|
||||
@ -57,7 +59,7 @@ public interface BaseMvp {
|
||||
|
||||
void onError(@NonNull Throwable throwable);
|
||||
|
||||
<T> void makeRestCall(@NonNull Observable<T> observable, @NonNull Action1<T> onNext);
|
||||
<T> void makeRestCall(@NonNull Observable<T> observable, @NonNull Consumer<T> onNext);
|
||||
}
|
||||
|
||||
interface PaginationListener<P> {
|
||||
|
||||
@ -12,16 +12,17 @@ import com.fastaccess.provider.rest.RestProvider;
|
||||
import com.fastaccess.ui.base.mvp.BaseMvp;
|
||||
|
||||
import net.grandcentrix.thirtyinch.TiPresenter;
|
||||
import net.grandcentrix.thirtyinch.rx.RxTiPresenterSubscriptionHandler;
|
||||
import net.grandcentrix.thirtyinch.rx2.RxTiPresenterDisposableHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import icepick.Icepick;
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
import rx.Observable;
|
||||
import rx.Subscription;
|
||||
import rx.functions.Action1;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import retrofit2.HttpException;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Kosh on 25 May 2016, 9:12 PM
|
||||
@ -29,19 +30,25 @@ import rx.functions.Action1;
|
||||
|
||||
public class BasePresenter<V extends BaseMvp.FAView> extends TiPresenter<V> implements BaseMvp.FAPresenter {
|
||||
private boolean apiCalled;
|
||||
private final RxTiPresenterSubscriptionHandler subscriptionHandler = new RxTiPresenterSubscriptionHandler(this);
|
||||
private final RxTiPresenterDisposableHandler subscriptionHandler = new RxTiPresenterDisposableHandler(this);
|
||||
|
||||
@Override public void onSaveInstanceState(Bundle outState) {
|
||||
// Icepick.saveInstanceState(this, outState);
|
||||
Icepick.saveInstanceState(this, outState);
|
||||
}
|
||||
|
||||
@Override public void onRestoreInstanceState(Bundle outState) {
|
||||
// Icepick.restoreInstanceState(this, outState);
|
||||
Icepick.restoreInstanceState(this, outState);
|
||||
}
|
||||
|
||||
@Override public void manageSubscription(@Nullable Subscription... subscription) {
|
||||
@Override public void manageSubscription(@Nullable Disposable... subscription) {
|
||||
if (subscription != null) {
|
||||
subscriptionHandler.manageSubscriptions(subscription);
|
||||
subscriptionHandler.manageDisposables(subscription);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public <T> void manageObservable(@Nullable Observable<T> observable) {
|
||||
if (observable != null) {
|
||||
manageSubscription(observable.subscribe(t -> {/**/}, Throwable::printStackTrace));
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,10 +75,10 @@ public class BasePresenter<V extends BaseMvp.FAView> extends TiPresenter<V> impl
|
||||
}
|
||||
}
|
||||
|
||||
@Override public <T> void makeRestCall(@NonNull Observable<T> observable, @NonNull Action1<T> onNext) {
|
||||
@Override public <T> void makeRestCall(@NonNull Observable<T> observable, @NonNull Consumer<T> onNext) {
|
||||
manageSubscription(
|
||||
RxHelper.getObserver(observable)
|
||||
.doOnSubscribe(this::onSubscribed)
|
||||
.doOnSubscribe(disposable -> onSubscribed())
|
||||
.subscribe(onNext, this::onError, () -> apiCalled = true)
|
||||
);
|
||||
}
|
||||
|
||||
@ -8,23 +8,20 @@ import android.widget.ProgressBar;
|
||||
|
||||
import com.fastaccess.R;
|
||||
import com.fastaccess.helper.PrefGetter;
|
||||
import com.fastaccess.helper.RxHelper;
|
||||
import com.fastaccess.provider.changelog.ChangelogProvider;
|
||||
import com.fastaccess.ui.base.BaseBottomSheetDialog;
|
||||
import com.fastaccess.ui.base.BaseMvpBottomSheetDialogFragment;
|
||||
import com.fastaccess.ui.widgets.FontButton;
|
||||
import com.fastaccess.ui.widgets.FontTextView;
|
||||
import com.prettifier.pretty.PrettifyWebView;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import icepick.State;
|
||||
import rx.Subscription;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 26 Mar 2017, 10:15 PM
|
||||
*/
|
||||
|
||||
public class ChangelogBottomSheetDialog extends BaseBottomSheetDialog {
|
||||
public class ChangelogBottomSheetDialog extends BaseMvpBottomSheetDialogFragment<ChangelogMvp.View, ChangelogPresenter> implements
|
||||
ChangelogMvp.View {
|
||||
|
||||
@BindView(R.id.title) FontTextView title;
|
||||
@BindView(R.id.message) FontTextView message;
|
||||
@ -32,18 +29,11 @@ public class ChangelogBottomSheetDialog extends BaseBottomSheetDialog {
|
||||
@BindView(R.id.messageLayout) View messageLayout;
|
||||
@BindView(R.id.prettifyWebView) PrettifyWebView prettifyWebView;
|
||||
@BindView(R.id.webProgress) ProgressBar webProgress;
|
||||
@State String html;
|
||||
|
||||
private Subscription subscription;
|
||||
|
||||
@OnClick(R.id.ok) void onOk() {
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override protected int layoutRes() {
|
||||
return R.layout.message_dialog;
|
||||
}
|
||||
|
||||
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
if (savedInstanceState == null) {
|
||||
@ -52,18 +42,26 @@ public class ChangelogBottomSheetDialog extends BaseBottomSheetDialog {
|
||||
webProgress.setVisibility(View.VISIBLE);
|
||||
cancel.setVisibility(View.GONE);
|
||||
title.setText(R.string.changelog);
|
||||
if (html == null) {
|
||||
subscription = RxHelper.getObserver(ChangelogProvider.getChangelog(getContext()))
|
||||
.subscribe(s -> {
|
||||
this.html = s;
|
||||
showChangelog();
|
||||
});
|
||||
if (getPresenter().getHtml() == null) {
|
||||
getPresenter().onLoadChangelog();
|
||||
} else {
|
||||
showChangelog();
|
||||
showChangelog(getPresenter().getHtml());
|
||||
}
|
||||
}
|
||||
|
||||
private void showChangelog() {
|
||||
@Override protected int fragmentLayout() {
|
||||
return R.layout.message_dialog;
|
||||
}
|
||||
|
||||
@Override public void onChangelogLoaded(@Nullable String html) {
|
||||
showChangelog(html);
|
||||
}
|
||||
|
||||
@NonNull @Override public ChangelogPresenter providePresenter() {
|
||||
return new ChangelogPresenter();
|
||||
}
|
||||
|
||||
private void showChangelog(String html) {
|
||||
webProgress.setVisibility(View.GONE);
|
||||
if (html != null) {
|
||||
message.setVisibility(View.GONE);
|
||||
@ -72,11 +70,4 @@ public class ChangelogBottomSheetDialog extends BaseBottomSheetDialog {
|
||||
prettifyWebView.setNestedScrollingEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onDestroyView() {
|
||||
if (subscription != null && !subscription.isUnsubscribed()) {
|
||||
subscription.unsubscribe();
|
||||
}
|
||||
super.onDestroyView();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
package com.fastaccess.ui.modules.changelog;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.fastaccess.ui.base.mvp.BaseMvp;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 28 May 2017, 10:53 AM
|
||||
*/
|
||||
|
||||
public interface ChangelogMvp {
|
||||
|
||||
interface View extends BaseMvp.FAView {
|
||||
void onChangelogLoaded(@Nullable String html);
|
||||
}
|
||||
|
||||
interface Presenter {
|
||||
void onLoadChangelog();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package com.fastaccess.ui.modules.changelog;
|
||||
|
||||
import com.fastaccess.App;
|
||||
import com.fastaccess.helper.RxHelper;
|
||||
import com.fastaccess.provider.changelog.ChangelogProvider;
|
||||
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 28 May 2017, 10:53 AM
|
||||
*/
|
||||
|
||||
@Getter public class ChangelogPresenter extends BasePresenter<ChangelogMvp.View> implements ChangelogMvp.Presenter {
|
||||
private String html;
|
||||
|
||||
@Override public void onLoadChangelog() {
|
||||
manageSubscription(RxHelper.getObserver(ChangelogProvider.getChangelog(App.getInstance()))
|
||||
.subscribe(s -> {
|
||||
this.html = s;
|
||||
sendToView(view -> view.onChangelogLoaded(html));
|
||||
}, throwable -> sendToView(view -> view.onChangelogLoaded(null))));
|
||||
}
|
||||
}
|
||||
@ -48,7 +48,7 @@ class FeedsPresenter extends BasePresenter<FeedsMvp.View> implements FeedsMvp.Pr
|
||||
makeRestCall(RestProvider.getUserService().getReceivedEvents(Login.getUser().getLogin(), page), response -> {
|
||||
lastPage = response.getLast();
|
||||
if (getCurrentPage() == 1) {
|
||||
manageSubscription(Event.save(response.getItems()).subscribe());
|
||||
manageObservable(Event.save(response.getItems()).toObservable());
|
||||
}
|
||||
sendToView(view -> view.onNotifyAdapter(response.getItems(), page));
|
||||
});
|
||||
@ -89,7 +89,8 @@ class FeedsPresenter extends BasePresenter<FeedsMvp.View> implements FeedsMvp.Pr
|
||||
|
||||
@Override public void onWorkOffline() {
|
||||
if (eventsModels.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(Event.getEvents()).subscribe(modelList -> {
|
||||
manageSubscription(RxHelper.getObserver(Event.getEvents().toObservable())
|
||||
.subscribe(modelList -> {
|
||||
if (modelList != null) {
|
||||
sendToView(view -> view.onNotifyAdapter(modelList, 1));
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import lombok.Getter;
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 09 Apr 2017, 6:22 PM
|
||||
|
||||
@ -57,7 +57,7 @@ class GistsPresenter extends BasePresenter<GistsMvp.View> implements GistsMvp.Pr
|
||||
listResponse -> {
|
||||
lastPage = listResponse.getLast();
|
||||
if (getCurrentPage() == 1) {
|
||||
manageSubscription(Gist.save(listResponse.getItems()).subscribe());
|
||||
manageObservable(Gist.save(listResponse.getItems()));
|
||||
}
|
||||
sendToView(view -> view.onNotifyAdapter(listResponse.getItems(), page));
|
||||
});
|
||||
@ -69,7 +69,7 @@ class GistsPresenter extends BasePresenter<GistsMvp.View> implements GistsMvp.Pr
|
||||
|
||||
@Override public void onWorkOffline() {
|
||||
if (gistsModels.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(Gist.getGists()).subscribe(gists -> sendToView(view -> view.onNotifyAdapter(gists, 1))));
|
||||
manageSubscription(RxHelper.getObserver(Gist.getGists().toObservable()).subscribe(gists -> sendToView(view -> view.onNotifyAdapter(gists, 1))));
|
||||
} else {
|
||||
sendToView(GistsMvp.View::hideProgress);
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ class GistPresenter extends BasePresenter<GistMvp.View> implements GistMvp.Prese
|
||||
@Override public void onDeleteGist() {
|
||||
if (getGist() == null) return;
|
||||
manageSubscription(RxHelper.getObserver(RestProvider.getGistService().deleteGist(getGist().getGistId()))
|
||||
.doOnSubscribe(this::onSubscribed)
|
||||
.doOnSubscribe(disposable -> onSubscribed())
|
||||
.doOnNext(booleanResponse -> {
|
||||
if (booleanResponse.code() == 204) {
|
||||
sendToView(GistMvp.View::onSuccessDeleted);
|
||||
@ -62,11 +62,9 @@ class GistPresenter extends BasePresenter<GistMvp.View> implements GistMvp.Prese
|
||||
sendToView(GistMvp.View::onErrorDeleting);
|
||||
}
|
||||
})
|
||||
.onErrorReturn(throwable -> {
|
||||
.subscribe(booleanResponse -> {/**/}, throwable -> {
|
||||
sendToView(view -> view.showErrorMessage(throwable.getMessage()));
|
||||
return null;
|
||||
})
|
||||
.subscribe());
|
||||
}));
|
||||
}
|
||||
|
||||
@Override public boolean isOwner() {
|
||||
|
||||
@ -64,7 +64,7 @@ class GistCommentsPresenter extends BasePresenter<GistCommentsMvp.View> implemen
|
||||
listResponse -> {
|
||||
lastPage = listResponse.getLast();
|
||||
if (getCurrentPage() == 1) {
|
||||
manageSubscription(Comment.saveForGist(listResponse.getItems(), parameter).subscribe());
|
||||
manageObservable(Comment.saveForGist(listResponse.getItems(), parameter));
|
||||
}
|
||||
sendToView(view -> view.onNotifyAdapter(listResponse.getItems(), page));
|
||||
});
|
||||
@ -95,7 +95,7 @@ class GistCommentsPresenter extends BasePresenter<GistCommentsMvp.View> implemen
|
||||
|
||||
@Override public void onWorkOffline(@NonNull String gistId) {
|
||||
if (comments.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(Comment.getGistComments(gistId))
|
||||
manageSubscription(RxHelper.getObserver(Comment.getGistComments(gistId).toObservable())
|
||||
.subscribe(localComments -> sendToView(view -> view.onNotifyAdapter(localComments, 1))));
|
||||
} else {
|
||||
sendToView(BaseMvp.FAView::hideProgress);
|
||||
|
||||
@ -21,7 +21,7 @@ import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
|
||||
import java.util.Arrays;
|
||||
|
||||
import okhttp3.Credentials;
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
import retrofit2.HttpException;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 09 Nov 2016, 9:43 PM
|
||||
|
||||
@ -7,7 +7,6 @@ import android.view.View;
|
||||
|
||||
import com.fastaccess.R;
|
||||
import com.fastaccess.helper.AnimHelper;
|
||||
import com.fastaccess.helper.Logger;
|
||||
import com.fastaccess.ui.base.BaseActivity;
|
||||
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
|
||||
|
||||
@ -15,10 +14,7 @@ import net.grandcentrix.thirtyinch.TiPresenter;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import io.octo.bear.pago.Pago;
|
||||
import rx.Subscription;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 24 Mar 2017, 9:16 PM
|
||||
@ -28,19 +24,19 @@ public class DonationActivity extends BaseActivity {
|
||||
@BindView(R.id.cardsHolder) View cardsHolder;
|
||||
@BindView(R.id.appbar) AppBarLayout appBarLayout;
|
||||
|
||||
private Pago pago;
|
||||
private Subscription subscription;
|
||||
// private Pago pago;
|
||||
private Disposable subscription;
|
||||
|
||||
@NonNull public Pago getPago() {
|
||||
if (pago == null) {
|
||||
pago = new Pago(getApplicationContext());
|
||||
}
|
||||
return pago;
|
||||
}
|
||||
// @NonNull public Pago getPago() {
|
||||
// if (pago == null) {
|
||||
// pago = new Pago(getApplicationContext());
|
||||
// }
|
||||
// return pago;
|
||||
// }
|
||||
|
||||
@Override protected void onDestroy() {
|
||||
if (subscription != null && subscription.isUnsubscribed()) {
|
||||
subscription.unsubscribe();
|
||||
if (subscription != null && !subscription.isDisposed()) {
|
||||
subscription.dispose();
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
@ -91,16 +87,16 @@ public class DonationActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void onProceed(@NonNull String productKey) {
|
||||
subscription = getPago().purchaseProduct(productKey, "inapp:com.fastaccess.github:" + productKey)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.onErrorReturn(throwable -> {
|
||||
showErrorMessage(throwable.getMessage());
|
||||
return null;
|
||||
})
|
||||
.subscribe(order -> {
|
||||
Logger.e(order);
|
||||
if (order != null) showMessage(R.string.success, R.string.success_purchase_message);
|
||||
}, Throwable::printStackTrace);
|
||||
// subscription = getPago().purchaseProduct(productKey, "inapp:com.fastaccess.github:" + productKey)
|
||||
// .subscribeOn(Schedulers.io())
|
||||
// .observeOn(AndroidSchedulers.mainThread())
|
||||
// .onErrorReturn(throwable -> {
|
||||
// showErrorMessage(throwable.getMessage());
|
||||
// return null;
|
||||
// })
|
||||
// .subscribe(order -> {
|
||||
// Logger.e(order);
|
||||
// if (order != null) showMessage(R.string.success, R.string.success_purchase_message);
|
||||
// }, Throwable::printStackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 15 Apr 2017, 1:54 PM
|
||||
@ -20,12 +20,18 @@ public class OrgListDialogPresenter extends BasePresenter<OrgListDialogMvp.View>
|
||||
|
||||
@Override public void onLoadOrgs() {
|
||||
makeRestCall(RestProvider.getOrgService().getMyOrganizations()
|
||||
.flatMap(userPageable -> userPageable.getItems() != null ? Observable.from(userPageable.getItems()) : Observable.empty())
|
||||
.flatMap(userPageable -> {
|
||||
if (userPageable != null && userPageable.getItems() != null) {
|
||||
return Observable.fromIterable(userPageable.getItems());
|
||||
}
|
||||
return Observable.empty();
|
||||
})
|
||||
.map(user -> {
|
||||
if (user != null) user.setType("Organization");
|
||||
return user;
|
||||
})
|
||||
.toList(), list -> {
|
||||
.toList()
|
||||
.toObservable(), list -> {
|
||||
List<User> myOrgs = new ArrayList<>();
|
||||
if (list != null && !list.isEmpty()) {
|
||||
myOrgs.addAll(list);
|
||||
|
||||
@ -20,7 +20,7 @@ import com.fastaccess.ui.modules.repos.RepoPagerActivity;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 20 Feb 2017, 8:46 PM
|
||||
@ -39,7 +39,7 @@ public class AllNotificationsPresenter extends BasePresenter<AllNotificationsMvp
|
||||
}
|
||||
} else if (v.getId() == R.id.unsubsribe) {
|
||||
item.setUnread(false);
|
||||
manageSubscription(item.save(item).subscribe());
|
||||
manageObservable(item.save(item).toObservable());
|
||||
sendToView(view -> view.onUpdateReadState(new GroupedNotificationModel(item), position));
|
||||
ReadNotificationService.unSubscribe(v.getContext(), item.getId());
|
||||
} else {
|
||||
@ -63,7 +63,7 @@ public class AllNotificationsPresenter extends BasePresenter<AllNotificationsMvp
|
||||
|
||||
private void markAsRead(int position, View v, Notification item) {
|
||||
item.setUnread(false);
|
||||
manageSubscription(item.save(item).subscribe());
|
||||
manageObservable(item.save(item).toObservable());
|
||||
sendToView(view -> view.onUpdateReadState(new GroupedNotificationModel(item), position));
|
||||
ReadNotificationService.start(v.getContext(), item.getId());
|
||||
}
|
||||
@ -77,8 +77,8 @@ public class AllNotificationsPresenter extends BasePresenter<AllNotificationsMvp
|
||||
|
||||
@Override public void onWorkOffline() {
|
||||
if (notifications.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(Notification.getAlltNotifications())
|
||||
.flatMap(notifications -> Observable.from(GroupedNotificationModel.construct(notifications)).toList())
|
||||
manageSubscription(RxHelper.getObserver(Notification.getAlltNotifications().toObservable())
|
||||
.flatMap(notifications -> Observable.just(GroupedNotificationModel.construct(notifications)))
|
||||
.subscribe(models -> sendToView(view -> view.onNotifyAdapter(models))));
|
||||
} else {
|
||||
sendToView(BaseMvp.FAView::hideProgress);
|
||||
@ -91,7 +91,7 @@ public class AllNotificationsPresenter extends BasePresenter<AllNotificationsMvp
|
||||
|
||||
@Override public void onCallApi() {
|
||||
// Observable<List<Notification>> notifications = RestProvider.getNotificationService().getAllNotifications()
|
||||
// .flatMap(response -> response.getItems() != null ? Observable.from(response.getItems()) : Observable.empty())
|
||||
// .flatMap(response -> response.getItems() != null ? Observable.fromIterable(response.getItems()) : Observable.empty())
|
||||
// .filter(ObjectsCompat::nonNull)
|
||||
// .flatMap(notification -> RestProvider.getNotificationService().isSubscribed(notification.getId())
|
||||
// .onErrorReturn(throwable -> null),
|
||||
@ -117,20 +117,20 @@ public class AllNotificationsPresenter extends BasePresenter<AllNotificationsMvp
|
||||
}
|
||||
|
||||
@Override public void onMarkAllAsRead(@NonNull List<GroupedNotificationModel> data) {
|
||||
manageSubscription(RxHelper.getObserver(Observable.from(data))
|
||||
manageSubscription(RxHelper.getObserver(Observable.fromIterable(data))
|
||||
.filter(group -> group.getType() == GroupedNotificationModel.ROW)
|
||||
.filter(group -> group.getNotification() != null && group.getNotification().isUnread())
|
||||
.map(GroupedNotificationModel::getNotification)
|
||||
.subscribe(notification -> {
|
||||
Logger.e(notification.getUrl());
|
||||
notification.setUnread(false);
|
||||
manageSubscription(notification.save(notification).subscribe());
|
||||
manageObservable(notification.save(notification).toObservable());
|
||||
sendToView(view -> view.onReadNotification(notification));
|
||||
}));
|
||||
}, this::onError));
|
||||
}
|
||||
|
||||
@Override public void onMarkReadByRepo(@NonNull List<GroupedNotificationModel> data, @NonNull Repo repo) {
|
||||
manageSubscription(RxHelper.getObserver(Observable.from(data))
|
||||
manageSubscription(RxHelper.getObserver(Observable.fromIterable(data))
|
||||
.filter(group -> group.getType() == GroupedNotificationModel.ROW)
|
||||
.filter(group -> group.getNotification() != null && group.getNotification().isUnread())
|
||||
.filter(group -> group.getNotification().getRepository().getFullName().equalsIgnoreCase(repo.getFullName()))
|
||||
@ -138,8 +138,8 @@ public class AllNotificationsPresenter extends BasePresenter<AllNotificationsMvp
|
||||
.subscribe(notification -> {
|
||||
Logger.e(notification.getUrl());
|
||||
notification.setUnread(false);
|
||||
manageSubscription(notification.save(notification).subscribe());
|
||||
manageObservable(notification.save(notification).toObservable());
|
||||
sendToView(view -> view.onReadNotification(notification));
|
||||
}));
|
||||
}, this::onError));
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 25 Apr 2017, 3:55 PM
|
||||
@ -35,7 +35,7 @@ public class UnreadNotificationsPresenter extends BasePresenter<UnreadNotificati
|
||||
}
|
||||
} else if (v.getId() == R.id.unsubsribe) {
|
||||
item.setUnread(false);
|
||||
manageSubscription(item.save(item).subscribe());
|
||||
manageObservable(item.save(item).toObservable());
|
||||
sendToView(view -> view.onRemove(position));
|
||||
ReadNotificationService.unSubscribe(v.getContext(), item.getId());
|
||||
} else {
|
||||
@ -52,8 +52,8 @@ public class UnreadNotificationsPresenter extends BasePresenter<UnreadNotificati
|
||||
|
||||
@Override public void onWorkOffline() {
|
||||
if (notifications.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(Notification.getUnreadNotifications())
|
||||
.flatMap(notifications -> Observable.from(GroupedNotificationModel.onlyNotifications(notifications)).toList())
|
||||
manageSubscription(RxHelper.getObserver(Notification.getUnreadNotifications().toObservable())
|
||||
.flatMap(notifications -> Observable.just(GroupedNotificationModel.onlyNotifications(notifications)))
|
||||
.subscribe(models -> sendToView(view -> view.onNotifyAdapter(models))));
|
||||
} else {
|
||||
sendToView(BaseMvp.FAView::hideProgress);
|
||||
@ -65,21 +65,21 @@ public class UnreadNotificationsPresenter extends BasePresenter<UnreadNotificati
|
||||
}
|
||||
|
||||
@Override public void onMarkAllAsRead(@NonNull List<GroupedNotificationModel> data) {
|
||||
manageSubscription(RxHelper.getObserver(Observable.from(data))
|
||||
manageSubscription(RxHelper.getObserver(Observable.fromIterable(data))
|
||||
.filter(group -> group.getType() == GroupedNotificationModel.ROW)
|
||||
.filter(group -> group.getNotification() != null && group.getNotification().isUnread())
|
||||
.map(GroupedNotificationModel::getNotification)
|
||||
.subscribe(notification -> {
|
||||
notification.setUnread(false);
|
||||
manageSubscription(notification.save(notification).subscribe());
|
||||
manageObservable(notification.save(notification).toObservable());
|
||||
sendToView(view -> view.onReadNotification(notification));
|
||||
}));
|
||||
}, this::onError));
|
||||
}
|
||||
|
||||
@Override public void onCallApi() {
|
||||
Observable<List<GroupedNotificationModel>> observable = RestProvider.getNotificationService()
|
||||
.getNotifications(ParseDateFormat.getLastWeekDate()).flatMap(response -> {
|
||||
if (response.getItems() != null) manageSubscription(Notification.save(response.getItems()).subscribe());
|
||||
if (response.getItems() != null) manageObservable(Notification.save(response.getItems()));
|
||||
return Observable.just(GroupedNotificationModel.onlyNotifications(response.getItems()));
|
||||
});
|
||||
makeRestCall(observable, response -> sendToView(view -> view.onNotifyAdapter(response)));
|
||||
@ -87,7 +87,7 @@ public class UnreadNotificationsPresenter extends BasePresenter<UnreadNotificati
|
||||
|
||||
private void markAsRead(int position, View v, Notification item) {
|
||||
item.setUnread(false);
|
||||
manageSubscription(item.save(item).subscribe());
|
||||
manageObservable(item.save(item).toObservable());
|
||||
sendToView(view -> view.onRemove(position));
|
||||
ReadNotificationService.start(v.getContext(), item.getId());
|
||||
}
|
||||
|
||||
@ -24,9 +24,9 @@ public class PinnedReposPresenter extends BasePresenter<PinnedReposMvp.View> imp
|
||||
if (pinnedRepos.isEmpty()) {
|
||||
onReload();
|
||||
if (!AbstractPinnedRepos.isPinned("k0shk0sh/FastHub"))
|
||||
manageSubscription(Repo.getRepo("FastHub", "k0shk0sh")
|
||||
manageObservable(Repo.getRepo("FastHub", "k0shk0sh")
|
||||
.map(repo -> repo != null && AbstractPinnedRepos.pinUpin(repo))
|
||||
.subscribe());
|
||||
.toObservable());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ import java.util.HashMap;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by JediB on 5/25/2017.
|
||||
|
||||
@ -64,7 +64,7 @@ class ProfileFollowersPresenter extends BasePresenter<ProfileFollowersMvp.View>
|
||||
response -> {
|
||||
lastPage = response.getLast();
|
||||
if (getCurrentPage() == 1) {
|
||||
manageSubscription(User.saveUserFollowerList(response.getItems(), parameter).subscribe());
|
||||
manageObservable(User.saveUserFollowerList(response.getItems(), parameter));
|
||||
}
|
||||
sendToView(view -> view.onNotifyAdapter(response.getItems(), page));
|
||||
});
|
||||
@ -76,7 +76,7 @@ class ProfileFollowersPresenter extends BasePresenter<ProfileFollowersMvp.View>
|
||||
|
||||
@Override public void onWorkOffline(@NonNull String login) {
|
||||
if (users.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(User.getUserFollowerList(login)).subscribe(userModels ->
|
||||
manageSubscription(RxHelper.getSingle(User.getUserFollowerList(login)).subscribe(userModels ->
|
||||
sendToView(view -> view.onNotifyAdapter(userModels, 1))));
|
||||
} else {
|
||||
sendToView(ProfileFollowersMvp.View::hideProgress);
|
||||
|
||||
@ -64,7 +64,7 @@ class ProfileFollowingPresenter extends BasePresenter<ProfileFollowingMvp.View>
|
||||
response -> {
|
||||
lastPage = response.getLast();
|
||||
if (getCurrentPage() == 1) {
|
||||
manageSubscription(User.saveUserFollowingList(response.getItems(), parameter).subscribe());
|
||||
manageObservable(User.saveUserFollowingList(response.getItems(), parameter));
|
||||
}
|
||||
sendToView(view -> view.onNotifyAdapter(response.getItems(), page));
|
||||
});
|
||||
@ -76,7 +76,7 @@ class ProfileFollowingPresenter extends BasePresenter<ProfileFollowingMvp.View>
|
||||
|
||||
@Override public void onWorkOffline(@NonNull String login) {
|
||||
if (users.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(User.getUserFollowingList(login)).subscribe(userModels ->
|
||||
manageSubscription(RxHelper.getSingle(User.getUserFollowingList(login)).subscribe(userModels ->
|
||||
sendToView(view -> view.onNotifyAdapter(userModels, 1))));
|
||||
} else {
|
||||
sendToView(ProfileFollowingMvp.View::hideProgress);
|
||||
|
||||
@ -63,7 +63,7 @@ class ProfileGistsPresenter extends BasePresenter<ProfileGistsMvp.View> implemen
|
||||
listResponse -> {
|
||||
lastPage = listResponse.getLast();
|
||||
if (getCurrentPage() == 1) {
|
||||
manageSubscription(Gist.save(listResponse.getItems(), parameter).subscribe());
|
||||
manageObservable(Gist.save(listResponse.getItems(), parameter));
|
||||
}
|
||||
sendToView(view -> view.onNotifyAdapter(listResponse.getItems(), page));
|
||||
});
|
||||
@ -75,7 +75,7 @@ class ProfileGistsPresenter extends BasePresenter<ProfileGistsMvp.View> implemen
|
||||
|
||||
@Override public void onWorkOffline(@NonNull String login) {
|
||||
if (gistsModels.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(Gist.getMyGists(login)).subscribe(gistsModels1 ->
|
||||
manageSubscription(RxHelper.getObserver(Gist.getMyGists(login).toObservable()).subscribe(gistsModels1 ->
|
||||
sendToView(view -> view.onNotifyAdapter(gistsModels1, 1))));
|
||||
} else {
|
||||
sendToView(ProfileGistsMvp.View::hideProgress);
|
||||
|
||||
@ -66,7 +66,7 @@ class OrgReposPresenter extends BasePresenter<OrgReposMvp.View> implements OrgRe
|
||||
repoModelPageable -> {
|
||||
lastPage = repoModelPageable.getLast();
|
||||
if (getCurrentPage() == 1) {
|
||||
manageSubscription(Repo.saveMyRepos(repoModelPageable.getItems(), parameter).subscribe());
|
||||
manageObservable(Repo.saveMyRepos(repoModelPageable.getItems(), parameter));
|
||||
}
|
||||
sendToView(view -> view.onNotifyAdapter(repoModelPageable.getItems(), page));
|
||||
});
|
||||
@ -78,7 +78,7 @@ class OrgReposPresenter extends BasePresenter<OrgReposMvp.View> implements OrgRe
|
||||
|
||||
@Override public void onWorkOffline(@NonNull String login) {
|
||||
if (repos.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(Repo.getMyRepos(login)).subscribe(repoModels ->
|
||||
manageSubscription(RxHelper.getObserver(Repo.getMyRepos(login).toObservable()).subscribe(repoModels ->
|
||||
sendToView(view -> view.onNotifyAdapter(repoModels, 1))));
|
||||
} else {
|
||||
sendToView(OrgReposMvp.View::hideProgress);
|
||||
|
||||
@ -25,7 +25,7 @@ import java.util.HashMap;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 03 Dec 2016, 9:16 AM
|
||||
@ -199,7 +199,7 @@ class ProfileOverviewPresenter extends BasePresenter<ProfileOverviewMvp.View> im
|
||||
if (Login.getUser().getLogin().equalsIgnoreCase(login)) {
|
||||
if (PrefGetter.getProfileBackgroundUrl() == null) {
|
||||
manageSubscription(getHeaderGist()
|
||||
.flatMap(s -> RxHelper.getObserver(Observable.from(s.split("\n"))))
|
||||
.flatMap(s -> RxHelper.getObserver(Observable.fromArray(s.split("\n"))))
|
||||
.flatMap(s -> RxHelper.getObserver(Observable.just(s.split("->"))))
|
||||
.filter(strings -> strings != null && strings[0].equalsIgnoreCase(login))
|
||||
.map(strings -> strings[1])
|
||||
@ -209,7 +209,7 @@ class ProfileOverviewPresenter extends BasePresenter<ProfileOverviewMvp.View> im
|
||||
}
|
||||
} else {
|
||||
manageSubscription(getHeaderGist()
|
||||
.flatMap(s -> RxHelper.getObserver(Observable.from(s.split("\n"))))
|
||||
.flatMap(s -> RxHelper.getObserver(Observable.fromArray(s.split("\n"))))
|
||||
.flatMap(s -> RxHelper.getObserver(Observable.just(s.split("->"))))
|
||||
.filter(strings -> strings != null && strings[0].equalsIgnoreCase(login))
|
||||
.map(strings -> strings[1])
|
||||
|
||||
@ -74,7 +74,7 @@ class ProfileReposPresenter extends BasePresenter<ProfileReposMvp.View> implemen
|
||||
repoModelPageable -> {
|
||||
lastPage = repoModelPageable.getLast();
|
||||
if (getCurrentPage() == 1) {
|
||||
manageSubscription(Repo.saveMyRepos(repoModelPageable.getItems(), parameter).subscribe());
|
||||
manageObservable(Repo.saveMyRepos(repoModelPageable.getItems(), parameter));
|
||||
}
|
||||
sendToView(view -> view.onNotifyAdapter(repoModelPageable.getItems(), page));
|
||||
});
|
||||
@ -86,7 +86,7 @@ class ProfileReposPresenter extends BasePresenter<ProfileReposMvp.View> implemen
|
||||
|
||||
@Override public void onWorkOffline(@NonNull String login) {
|
||||
if (repos.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(Repo.getMyRepos(login)).subscribe(repoModels ->
|
||||
manageSubscription(RxHelper.getObserver(Repo.getMyRepos(login).toObservable()).subscribe(repoModels ->
|
||||
sendToView(view -> view.onNotifyAdapter(repoModels, 1))));
|
||||
} else {
|
||||
sendToView(ProfileReposMvp.View::hideProgress);
|
||||
|
||||
@ -66,7 +66,7 @@ class ProfileStarredPresenter extends BasePresenter<ProfileStarredMvp.View> impl
|
||||
repoModelPageable -> {
|
||||
lastPage = repoModelPageable.getLast();
|
||||
if (getCurrentPage() == 1) {
|
||||
manageSubscription(Repo.saveStarred(repoModelPageable.getItems(), parameter).subscribe());
|
||||
manageObservable(Repo.saveStarred(repoModelPageable.getItems(), parameter));
|
||||
}
|
||||
sendToView(view -> view.onNotifyAdapter(repoModelPageable.getItems(), page));
|
||||
});
|
||||
@ -78,7 +78,7 @@ class ProfileStarredPresenter extends BasePresenter<ProfileStarredMvp.View> impl
|
||||
|
||||
@Override public void onWorkOffline(@NonNull String login) {
|
||||
if (repos.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(Repo.getStarred(login)).subscribe(repoModels ->
|
||||
manageSubscription(RxHelper.getObserver(Repo.getStarred(login).toObservable()).subscribe(repoModels ->
|
||||
sendToView(view -> view.onNotifyAdapter(repoModels, 1))));
|
||||
} else {
|
||||
sendToView(ProfileStarredMvp.View::hideProgress);
|
||||
|
||||
@ -41,7 +41,7 @@ class RepoPagerPresenter extends BasePresenter<RepoPagerMvp.View> implements Rep
|
||||
makeRestCall(RestProvider.getRepoService().getRepo(login(), repoId()),
|
||||
repoModel -> {
|
||||
this.repo = repoModel;
|
||||
manageSubscription(this.repo.save(repo).subscribe());
|
||||
manageObservable(this.repo.save(repo).toObservable());
|
||||
sendToView(view -> {
|
||||
view.onInitRepo();
|
||||
view.onNavigationChanged(navTyp);
|
||||
@ -133,14 +133,12 @@ class RepoPagerPresenter extends BasePresenter<RepoPagerMvp.View> implements Rep
|
||||
String login = login();
|
||||
String name = repoId();
|
||||
manageSubscription(RxHelper.getObserver(RestProvider.getRepoService().isWatchingRepo(login, name))
|
||||
.doOnSubscribe(() -> sendToView(view -> view.onEnableDisableWatch(false)))
|
||||
.doOnSubscribe(disposable -> sendToView(view -> view.onEnableDisableWatch(false)))
|
||||
.doOnNext(subscriptionModel -> sendToView(view -> view.onRepoWatched(isWatched = subscriptionModel.isSubscribed())))
|
||||
.onErrorReturn(throwable -> {
|
||||
.subscribe(o -> {/**/}, throwable -> {
|
||||
isWatched = false;
|
||||
sendToView(view -> view.onRepoWatched(isWatched));
|
||||
return null;
|
||||
})
|
||||
.subscribe());
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,20 +147,18 @@ class RepoPagerPresenter extends BasePresenter<RepoPagerMvp.View> implements Rep
|
||||
String login = login();
|
||||
String name = repoId();
|
||||
manageSubscription(RxHelper.getObserver(RestProvider.getRepoService().checkStarring(login, name))
|
||||
.doOnSubscribe(() -> sendToView(view -> view.onEnableDisableStar(false)))
|
||||
.doOnSubscribe(disposable -> sendToView(view -> view.onEnableDisableStar(false)))
|
||||
.doOnNext(response -> sendToView(view -> view.onRepoStarred(isStarred = response.code() == 204)))
|
||||
.onErrorReturn(throwable -> {
|
||||
.subscribe(booleanResponse -> {/**/}, throwable -> {
|
||||
isStarred = false;
|
||||
sendToView(view -> view.onRepoStarred(isStarred));
|
||||
return null;
|
||||
})
|
||||
.subscribe());
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onWorkOffline() {
|
||||
if (!InputHelper.isEmpty(login()) && !InputHelper.isEmpty(repoId())) {
|
||||
manageSubscription(RxHelper.getObserver(Repo.getRepo(repoId, login))
|
||||
manageSubscription(RxHelper.getObserver(Repo.getRepo(repoId, login).toObservable())
|
||||
.subscribe(repoModel -> {
|
||||
repo = repoModel;
|
||||
if (repo != null) {
|
||||
|
||||
@ -21,7 +21,7 @@ import com.fastaccess.ui.modules.repos.code.commit.details.CommitPagerActivity;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 03 Dec 2016, 3:48 PM
|
||||
@ -75,7 +75,7 @@ class RepoCommitsPresenter extends BasePresenter<RepoCommitsMvp.View> implements
|
||||
if (response != null && response.getItems() != null) {
|
||||
lastPage = response.getLast();
|
||||
if (getCurrentPage() == 1) {
|
||||
manageSubscription(Commit.save(response.getItems(), repoId, login).subscribe());
|
||||
manageObservable(Commit.save(response.getItems(), repoId, login));
|
||||
}
|
||||
}
|
||||
sendToView(view -> view.onNotifyAdapter(response != null ? response.getItems() : null, page));
|
||||
@ -111,17 +111,13 @@ class RepoCommitsPresenter extends BasePresenter<RepoCommitsMvp.View> implements
|
||||
return branchesModels;
|
||||
}));
|
||||
manageSubscription(observable
|
||||
.doOnSubscribe(() -> sendToView(RepoCommitsMvp.View::showBranchesProgress))
|
||||
.doOnSubscribe(disposable -> sendToView(RepoCommitsMvp.View::showBranchesProgress))
|
||||
.doOnNext(branchesModels -> {
|
||||
branches.clear();
|
||||
branches.addAll(branchesModels);
|
||||
sendToView(view -> view.setBranchesData(branches, true));
|
||||
})
|
||||
.onErrorReturn(throwable -> {
|
||||
sendToView(view -> view.setBranchesData(branches, true));
|
||||
return null;
|
||||
})
|
||||
.subscribe());
|
||||
.subscribe(branchesModels -> {/**/}, throwable -> sendToView(view -> view.setBranchesData(branches, true))));
|
||||
}
|
||||
if (!InputHelper.isEmpty(login) && !InputHelper.isEmpty(repoId)) {
|
||||
onCallApi(1, null);
|
||||
@ -138,7 +134,7 @@ class RepoCommitsPresenter extends BasePresenter<RepoCommitsMvp.View> implements
|
||||
|
||||
@Override public void onWorkOffline() {
|
||||
if (commits.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(Commit.getCommits(repoId, login))
|
||||
manageSubscription(RxHelper.getObserver(Commit.getCommits(repoId, login).toObservable())
|
||||
.subscribe(models -> sendToView(view -> view.onNotifyAdapter(models, 1))));
|
||||
} else {
|
||||
sendToView(BaseMvp.FAView::hideProgress);
|
||||
|
||||
@ -12,7 +12,7 @@ import com.fastaccess.helper.RxHelper;
|
||||
import com.fastaccess.provider.rest.RestProvider;
|
||||
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
|
||||
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 10 Dec 2016, 9:23 AM
|
||||
@ -70,7 +70,7 @@ class CommitPagerPresenter extends BasePresenter<CommitPagerMvp.View> implements
|
||||
commitModel.setRepoId(repoId);
|
||||
commitModel.setLogin(login);
|
||||
sendToView(CommitPagerMvp.View::onSetup);
|
||||
manageSubscription(commitModel.save(commitModel).subscribe());
|
||||
manageObservable(commitModel.save(commitModel).toObservable());
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 11 Nov 2016, 12:36 PM
|
||||
@ -102,7 +102,7 @@ class CommitCommentsPresenter extends BasePresenter<CommitCommentsMvp.View> impl
|
||||
|
||||
@Override public void onWorkOffline() {
|
||||
if (comments.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(Comment.getCommitComments(repoId(), login(), sha))
|
||||
manageSubscription(RxHelper.getObserver(Comment.getCommitComments(repoId(), login(), sha).toObservable())
|
||||
.flatMap(comments -> Observable.just(TimelineModel.construct(comments)))
|
||||
.subscribe(models -> sendToView(view -> view.onNotifyAdapter(models, 1))));
|
||||
} else {
|
||||
@ -178,6 +178,6 @@ class CommitCommentsPresenter extends BasePresenter<CommitCommentsMvp.View> impl
|
||||
|
||||
private void onHandleReaction(int viewId, long id) {
|
||||
Observable observable = getReactionsProvider().onHandleReaction(viewId, id, login, repoId, ReactionsProvider.COMMIT);
|
||||
if (observable != null) manageSubscription(observable.subscribe());
|
||||
if (observable != null) manageObservable(observable);
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ class RepoContributorsPresenter extends BasePresenter<RepoContributorsMvp.View>
|
||||
if (response != null) {
|
||||
lastPage = response.getLast();
|
||||
if (getCurrentPage() == 1) {
|
||||
manageSubscription(User.saveUserContributorList(response.getItems(), repoId).subscribe());
|
||||
manageObservable(User.saveUserContributorList(response.getItems(), repoId));
|
||||
}
|
||||
}
|
||||
sendToView(view -> view.onNotifyAdapter(response != null ? response.getItems() : null, page));
|
||||
@ -81,7 +81,7 @@ class RepoContributorsPresenter extends BasePresenter<RepoContributorsMvp.View>
|
||||
|
||||
@Override public void onWorkOffline() {
|
||||
if (users.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(User.getUserContributorList(repoId))
|
||||
manageSubscription(RxHelper.getObserver(User.getUserContributorList(repoId).toObservable())
|
||||
.subscribe(userModels -> sendToView(view -> view.onNotifyAdapter(userModels, 1))));
|
||||
} else {
|
||||
sendToView(BaseMvp.FAView::hideProgress);
|
||||
|
||||
@ -14,7 +14,7 @@ import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 15 Feb 2017, 10:10 PM
|
||||
@ -50,10 +50,10 @@ class RepoFilesPresenter extends BasePresenter<RepoFilesMvp.View> implements Rep
|
||||
|
||||
@Override public void onWorkOffline() {
|
||||
if ((repoId == null || login == null) || !files.isEmpty()) return;
|
||||
manageSubscription(RxHelper.getObserver(RepoFile.getFiles(login, repoId))
|
||||
manageSubscription(RxHelper.getObserver(RepoFile.getFiles(login, repoId).toObservable())
|
||||
.flatMap(response -> {
|
||||
if (response != null) {
|
||||
return Observable.from(response).sorted((repoFile, repoFile2) -> repoFile2.getType().compareTo(repoFile.getType()));
|
||||
return Observable.fromIterable(response).sorted((repoFile, repoFile2) -> repoFile2.getType().compareTo(repoFile.getType()));
|
||||
}
|
||||
return Observable.empty();
|
||||
})
|
||||
@ -70,15 +70,15 @@ class RepoFilesPresenter extends BasePresenter<RepoFilesMvp.View> implements Rep
|
||||
makeRestCall(RestProvider.getRepoService().getRepoFiles(login, repoId, path, ref)
|
||||
.flatMap(response -> {
|
||||
if (response != null && response.getItems() != null) {
|
||||
return Observable.from(response.getItems())
|
||||
return Observable.fromIterable(response.getItems())
|
||||
.sorted((repoFile, repoFile2) -> repoFile2.getType().compareTo(repoFile.getType()));
|
||||
}
|
||||
return Observable.empty();
|
||||
})
|
||||
.toList(), response -> {
|
||||
.toList().toObservable(), response -> {
|
||||
files.clear();
|
||||
if (response != null) {
|
||||
manageSubscription(RepoFile.save(response, login, repoId).subscribe());
|
||||
manageObservable(RepoFile.save(response, login, repoId));
|
||||
pathsModel.setFiles(ref, path, response);
|
||||
files.addAll(response);
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 15 Feb 2017, 10:10 PM
|
||||
@ -100,17 +100,15 @@ class RepoFilePathPresenter extends BasePresenter<RepoFilePathMvp.View> implemen
|
||||
return branchesModels;
|
||||
}));
|
||||
manageSubscription(observable
|
||||
.doOnSubscribe(() -> sendToView(view -> view.showProgress(0)))
|
||||
.doOnSubscribe(disposable -> sendToView(view -> view.showProgress(0)))
|
||||
.doOnNext(branchesModels -> {
|
||||
branches.clear();
|
||||
branches.addAll(branchesModels);
|
||||
sendToView(view -> view.setBranchesData(branches, true));
|
||||
})
|
||||
.onErrorReturn(throwable -> {
|
||||
.subscribe(branchesModels -> {/**/}, throwable -> {
|
||||
sendToView(view -> view.setBranchesData(branches, true));
|
||||
return null;
|
||||
})
|
||||
.subscribe());
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
throw new NullPointerException("Bundle is null");
|
||||
|
||||
@ -16,7 +16,7 @@ import com.fastaccess.provider.markdown.MarkDownProvider;
|
||||
import com.fastaccess.provider.rest.RestProvider;
|
||||
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
|
||||
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 27 Nov 2016, 3:43 PM
|
||||
@ -132,7 +132,7 @@ class ViewerPresenter extends BasePresenter<ViewerMvp.View> implements ViewerMvp
|
||||
downloadedStream = string;
|
||||
fileModel.setMarkdown(true);
|
||||
fileModel.setContent(downloadedStream);
|
||||
manageSubscription(fileModel.save(fileModel).subscribe());
|
||||
manageObservable(fileModel.save(fileModel).toObservable());
|
||||
sendToView(view -> view.onSetMdText(downloadedStream, url));
|
||||
});
|
||||
return;
|
||||
@ -140,7 +140,7 @@ class ViewerPresenter extends BasePresenter<ViewerMvp.View> implements ViewerMvp
|
||||
fileModel.setMarkdown(false);
|
||||
sendToView(view -> view.onSetCode(downloadedStream));
|
||||
}
|
||||
manageSubscription(fileModel.save(fileModel).subscribe());
|
||||
manageObservable(fileModel.save(fileModel).toObservable());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -74,7 +74,7 @@ class RepoReleasesPresenter extends BasePresenter<RepoReleasesMvp.View> implemen
|
||||
private void onResponse(Pageable<Release> response) {
|
||||
lastPage = response.getLast();
|
||||
if (getCurrentPage() == 1) {
|
||||
manageSubscription(Release.save(response.getItems(), repoId, login).subscribe());
|
||||
manageObservable(Release.save(response.getItems(), repoId, login));
|
||||
}
|
||||
sendToView(view -> view.onNotifyAdapter(response.getItems(), getCurrentPage()));
|
||||
}
|
||||
@ -89,7 +89,7 @@ class RepoReleasesPresenter extends BasePresenter<RepoReleasesMvp.View> implemen
|
||||
|
||||
@Override public void onWorkOffline() {
|
||||
if (releases.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(Release.get(repoId, login))
|
||||
manageSubscription(RxHelper.getSingle(Release.get(repoId, login))
|
||||
.subscribe(releasesModels -> sendToView(view -> view.onNotifyAdapter(releasesModels, 1))));
|
||||
} else {
|
||||
sendToView(RepoReleasesMvp.View::hideProgress);
|
||||
|
||||
@ -16,7 +16,7 @@ import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 04 May 2017, 8:33 PM
|
||||
@ -87,9 +87,10 @@ public class RepoMiscPresenter extends BasePresenter<RepoMiscMVp.View> implement
|
||||
makeRestCall(RestProvider.getRepoService().getForks(owner, repo, page)
|
||||
.flatMap(repoPageable -> {
|
||||
lastPage = repoPageable.getLast();
|
||||
return Observable.from(repoPageable.getItems())
|
||||
return Observable.fromIterable(repoPageable.getItems())
|
||||
.map(Repo::getOwner)
|
||||
.toList();
|
||||
.toList()
|
||||
.toObservable();
|
||||
}), owners -> sendToView(view -> view.onNotifyAdapter(owners, page)));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ class RepoIssuesPresenter extends BasePresenter<RepoIssuesMvp.View> implements R
|
||||
.filter(issue -> issue.getPullRequest() == null)
|
||||
.toList();
|
||||
if (getCurrentPage() == 1) {
|
||||
manageSubscription(Issue.save(filtered, repoId, login).subscribe());
|
||||
manageObservable(Issue.save(filtered, repoId, login));
|
||||
}
|
||||
sendToView(view -> view.onNotifyAdapter(filtered, page));
|
||||
});
|
||||
@ -109,7 +109,7 @@ class RepoIssuesPresenter extends BasePresenter<RepoIssuesMvp.View> implements R
|
||||
|
||||
@Override public void onWorkOffline() {
|
||||
if (issues.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(Issue.getIssues(repoId, login, issueState))
|
||||
manageSubscription(RxHelper.getSingle(Issue.getIssues(repoId, login, issueState))
|
||||
.subscribe(issueModel -> sendToView(view -> {
|
||||
view.onNotifyAdapter(issueModel, 1);
|
||||
view.onUpdateCount(issueModel.size());
|
||||
|
||||
@ -33,8 +33,8 @@ import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.Response;
|
||||
import rx.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 10 Dec 2016, 9:23 AM
|
||||
@ -156,7 +156,7 @@ class IssuePagerPresenter extends BasePresenter<IssuePagerMvp.View> implements I
|
||||
IssueRequestModel requestModel = IssueRequestModel.clone(currentIssue, true);
|
||||
manageSubscription(RxHelper.getObserver(RestProvider.getIssueService().editIssue(login, repoId,
|
||||
issueNumber, requestModel))
|
||||
.doOnSubscribe(() -> sendToView(view -> view.showProgress(0)))
|
||||
.doOnSubscribe(disposable -> sendToView(view -> view.showProgress(0)))
|
||||
.doOnNext(issue -> {
|
||||
if (issue != null) {
|
||||
sendToView(view -> view.showSuccessIssueActionMsg(currentIssue.getState() == IssueState.open));
|
||||
@ -166,11 +166,8 @@ class IssuePagerPresenter extends BasePresenter<IssuePagerMvp.View> implements I
|
||||
sendToView(IssuePagerMvp.View::onSetupIssue);
|
||||
}
|
||||
})
|
||||
.onErrorReturn(throwable -> {
|
||||
sendToView(view -> view.showErrorIssueActionMsg(currentIssue.getState() == IssueState.open));
|
||||
return null;
|
||||
})
|
||||
.subscribe());
|
||||
.subscribe(issue -> {/**/},
|
||||
throwable -> sendToView(view -> view.showErrorIssueActionMsg(currentIssue.getState() == IssueState.open))));
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,7 +194,7 @@ class IssuePagerPresenter extends BasePresenter<IssuePagerMvp.View> implements I
|
||||
@Override public void onLoadLabels() {
|
||||
manageSubscription(
|
||||
RxHelper.getObserver(RestProvider.getRepoService().getLabels(login, repoId))
|
||||
.doOnSubscribe(this::onSubscribed)
|
||||
.doOnSubscribe(disposable -> onSubscribed())
|
||||
.doOnNext(response -> {
|
||||
if (response.getItems() != null && !response.getItems().isEmpty()) {
|
||||
sendToView(view -> view.onLabelsRetrieved(response.getItems()));
|
||||
@ -205,11 +202,9 @@ class IssuePagerPresenter extends BasePresenter<IssuePagerMvp.View> implements I
|
||||
sendToView(view -> view.showMessage(R.string.error, R.string.no_labels));
|
||||
}
|
||||
})
|
||||
.onErrorReturn(throwable -> {
|
||||
.subscribe(labelModelPageable -> {/**/}, throwable -> {
|
||||
sendToView(view -> view.showMessage(R.string.error, R.string.no_labels));
|
||||
return null;
|
||||
})
|
||||
.subscribe()
|
||||
);
|
||||
}
|
||||
|
||||
@ -221,7 +216,7 @@ class IssuePagerPresenter extends BasePresenter<IssuePagerMvp.View> implements I
|
||||
this.issueModel = issue;
|
||||
issueModel.setLogin(login);
|
||||
issueModel.setRepoId(repoId);
|
||||
manageSubscription(issue.save(issueModel).subscribe());
|
||||
manageObservable(issue.save(issueModel).toObservable());
|
||||
sendToView(IssuePagerMvp.View::onUpdateTimeline);
|
||||
});
|
||||
|
||||
@ -236,7 +231,7 @@ class IssuePagerPresenter extends BasePresenter<IssuePagerMvp.View> implements I
|
||||
LabelListModel listModel = new LabelListModel();
|
||||
listModel.addAll(labels);
|
||||
issueModel.setLabels(listModel);
|
||||
manageSubscription(issueModel.save(issueModel).subscribe());
|
||||
manageObservable(issueModel.save(issueModel).toObservable());
|
||||
});
|
||||
}
|
||||
|
||||
@ -253,7 +248,7 @@ class IssuePagerPresenter extends BasePresenter<IssuePagerMvp.View> implements I
|
||||
UsersListModel assignee = new UsersListModel();
|
||||
assignee.addAll(users);
|
||||
issueModel.setAssignees(assignee);
|
||||
manageSubscription(issueModel.save(issueModel).subscribe());
|
||||
manageObservable(issueModel.save(issueModel).toObservable());
|
||||
sendToView(IssuePagerMvp.View::onUpdateTimeline);
|
||||
}
|
||||
);
|
||||
@ -271,7 +266,7 @@ class IssuePagerPresenter extends BasePresenter<IssuePagerMvp.View> implements I
|
||||
this.issueModel = issue;
|
||||
this.issueModel.setLogin(login);
|
||||
this.issueModel.setRepoId(repoId);
|
||||
manageSubscription(issueModel.save(issueModel).subscribe());
|
||||
manageObservable(issueModel.save(issueModel).toObservable());
|
||||
sendToView(IssuePagerMvp.View::onSetupIssue);
|
||||
}
|
||||
|
||||
@ -283,7 +278,7 @@ class IssuePagerPresenter extends BasePresenter<IssuePagerMvp.View> implements I
|
||||
String token = PrefGetter.getToken();
|
||||
String id = mute ? NotificationService.MUTE : NotificationService.SUBSCRIBE;
|
||||
makeRestCall(AbstractRepo.getRepo(repoId, login)
|
||||
.flatMap(repo -> RestProvider.getNotificationService()
|
||||
.flatMapObservable(repo -> RestProvider.getNotificationService()
|
||||
.subscribe(url, repo.getId(), getIssue().getId(), issue, id, token, utf)),
|
||||
booleanResponse -> {
|
||||
if (booleanResponse.code() == 204 || booleanResponse.code() == 200) {
|
||||
|
||||
@ -29,7 +29,7 @@ import com.fastaccess.ui.modules.repos.issues.create.CreateIssueActivity;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 31 Mar 2017, 7:17 PM
|
||||
|
||||
@ -72,7 +72,7 @@ class RepoPullRequestPresenter extends BasePresenter<RepoPullRequestMvp.View> im
|
||||
makeRestCall(RestProvider.getPullRequestService().getPullRequests(login, repoId, parameter.name(), page), response -> {
|
||||
lastPage = response.getLast();
|
||||
if (getCurrentPage() == 1) {
|
||||
manageSubscription(PullRequest.save(response.getItems(), login, repoId).subscribe());
|
||||
manageObservable(PullRequest.save(response.getItems(), login, repoId));
|
||||
}
|
||||
sendToView(view -> view.onNotifyAdapter(response.getItems(), page));
|
||||
});
|
||||
@ -97,7 +97,7 @@ class RepoPullRequestPresenter extends BasePresenter<RepoPullRequestMvp.View> im
|
||||
|
||||
@Override public void onWorkOffline() {
|
||||
if (pullRequests.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(PullRequest.getPullRequests(repoId, login, issueState))
|
||||
manageSubscription(RxHelper.getSingle(PullRequest.getPullRequests(repoId, login, issueState))
|
||||
.subscribe(pulls -> sendToView(view -> {
|
||||
view.onNotifyAdapter(pulls, 1);
|
||||
view.onUpdateCount(pulls.size());
|
||||
|
||||
@ -32,8 +32,8 @@ import com.fastaccess.ui.widgets.SpannableBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.Response;
|
||||
import rx.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 10 Dec 2016, 9:23 AM
|
||||
@ -88,7 +88,7 @@ class PullRequestPagerPresenter extends BasePresenter<PullRequestPagerMvp.View>
|
||||
pullRequest.setRepoId(repoId);
|
||||
pullRequest.setLogin(login);
|
||||
sendToView(PullRequestPagerMvp.View::onSetupIssue);
|
||||
manageSubscription(pullRequest.save(pullRequest).subscribe());
|
||||
manageObservable(pullRequest.save(pullRequest).toObservable());
|
||||
});
|
||||
return;
|
||||
}
|
||||
@ -168,7 +168,7 @@ class PullRequestPagerPresenter extends BasePresenter<PullRequestPagerMvp.View>
|
||||
IssueRequestModel requestModel = IssueRequestModel.clone(getPullRequest(), true);
|
||||
manageSubscription(RxHelper.getObserver(RestProvider.getPullRequestService().editPullRequest(login, repoId,
|
||||
issueNumber, requestModel))
|
||||
.doOnSubscribe(() -> sendToView(view -> view.showProgress(0)))
|
||||
.doOnSubscribe(disposable -> sendToView(view -> view.showProgress(0)))
|
||||
.doOnNext(issue -> {
|
||||
if (issue != null) {
|
||||
sendToView(view -> view.showSuccessIssueActionMsg(getPullRequest().getState() == IssueState.open));
|
||||
@ -178,11 +178,8 @@ class PullRequestPagerPresenter extends BasePresenter<PullRequestPagerMvp.View>
|
||||
sendToView(PullRequestPagerMvp.View::onSetupIssue);
|
||||
}
|
||||
})
|
||||
.onErrorReturn(throwable -> {
|
||||
sendToView(view -> view.showErrorIssueActionMsg(getPullRequest().getState() == IssueState.open));
|
||||
return null;
|
||||
})
|
||||
.subscribe());
|
||||
.subscribe(pullRequest1 -> {/**/},
|
||||
throwable -> sendToView(view -> view.showErrorIssueActionMsg(getPullRequest().getState() == IssueState.open))));
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,7 +190,7 @@ class PullRequestPagerPresenter extends BasePresenter<PullRequestPagerMvp.View>
|
||||
@Override public void onLoadLabels() {
|
||||
manageSubscription(
|
||||
RxHelper.getObserver(RestProvider.getRepoService().getLabels(login, repoId))
|
||||
.doOnSubscribe(this::onSubscribed)
|
||||
.doOnSubscribe(disposable -> onSubscribed())
|
||||
.doOnNext(response -> {
|
||||
if (response.getItems() != null && !response.getItems().isEmpty()) {
|
||||
sendToView(view -> view.onLabelsRetrieved(response.getItems()));
|
||||
@ -201,11 +198,9 @@ class PullRequestPagerPresenter extends BasePresenter<PullRequestPagerMvp.View>
|
||||
sendToView(view -> view.showMessage(R.string.error, R.string.no_labels));
|
||||
}
|
||||
})
|
||||
.onErrorReturn(throwable -> {
|
||||
.subscribe(labelModelPageable -> {/**/}, throwable -> {
|
||||
sendToView(view -> view.showMessage(R.string.error, R.string.no_labels));
|
||||
return null;
|
||||
})
|
||||
.subscribe()
|
||||
);
|
||||
}
|
||||
|
||||
@ -218,7 +213,7 @@ class PullRequestPagerPresenter extends BasePresenter<PullRequestPagerMvp.View>
|
||||
LabelListModel listModel = new LabelListModel();
|
||||
listModel.addAll(labels);
|
||||
pullRequest.setLabels(listModel);
|
||||
manageSubscription(pullRequest.save(pullRequest).subscribe());
|
||||
manageObservable(pullRequest.save(pullRequest).toObservable());
|
||||
});
|
||||
}
|
||||
|
||||
@ -230,7 +225,7 @@ class PullRequestPagerPresenter extends BasePresenter<PullRequestPagerMvp.View>
|
||||
this.pullRequest = pr;
|
||||
pullRequest.setLogin(login);
|
||||
pullRequest.setRepoId(repoId);
|
||||
manageSubscription(pr.save(pullRequest).subscribe());
|
||||
manageObservable(pr.save(pullRequest).toObservable());
|
||||
sendToView(PullRequestPagerMvp.View::onUpdateTimeline);
|
||||
});
|
||||
|
||||
@ -251,7 +246,7 @@ class PullRequestPagerPresenter extends BasePresenter<PullRequestPagerMvp.View>
|
||||
UsersListModel assignee = new UsersListModel();
|
||||
assignee.addAll(users);
|
||||
pullRequest.setAssignees(assignee);
|
||||
manageSubscription(pullRequest.save(pullRequest).subscribe());
|
||||
manageObservable(pullRequest.save(pullRequest).toObservable());
|
||||
sendToView(PullRequestPagerMvp.View::onUpdateTimeline);
|
||||
}
|
||||
);
|
||||
@ -271,7 +266,7 @@ class PullRequestPagerPresenter extends BasePresenter<PullRequestPagerMvp.View>
|
||||
mergeRequestModel.setCommitMessage(msg);
|
||||
manageSubscription(
|
||||
RxHelper.getObserver(RestProvider.getPullRequestService().mergePullRequest(login, repoId, issueNumber, mergeRequestModel))
|
||||
.doOnSubscribe(() -> sendToView(view -> view.showProgress(0)))
|
||||
.doOnSubscribe(disposable -> sendToView(view -> view.showProgress(0)))
|
||||
.doOnNext(mergeResponseModel -> {
|
||||
if (mergeResponseModel.isMerged()) {
|
||||
sendToView(view -> {
|
||||
@ -282,11 +277,7 @@ class PullRequestPagerPresenter extends BasePresenter<PullRequestPagerMvp.View>
|
||||
sendToView(view -> view.showErrorMessage(mergeResponseModel.getMessage()));
|
||||
}
|
||||
})
|
||||
.onErrorReturn(throwable -> {
|
||||
sendToView(view -> view.showErrorMessage(throwable.getMessage()));
|
||||
return null;
|
||||
})
|
||||
.subscribe()
|
||||
.subscribe(mergeResponseModel -> {/**/}, throwable -> sendToView(view -> view.showErrorMessage(throwable.getMessage())))
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -307,7 +298,7 @@ class PullRequestPagerPresenter extends BasePresenter<PullRequestPagerMvp.View>
|
||||
this.pullRequest = pullRequestModel;
|
||||
this.pullRequest.setLogin(login);
|
||||
this.pullRequest.setRepoId(repoId);
|
||||
manageSubscription(pullRequest.save(pullRequest).subscribe());
|
||||
manageObservable(pullRequest.save(pullRequest).toObservable());
|
||||
sendToView(PullRequestPagerMvp.View::onSetupIssue);
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ class PullRequestCommitsPresenter extends BasePresenter<PullRequestCommitsMvp.Vi
|
||||
response -> {
|
||||
lastPage = response.getLast();
|
||||
if (getCurrentPage() == 1) {
|
||||
manageSubscription(Commit.save(response.getItems(), repoId, login, number).subscribe());
|
||||
manageObservable(Commit.save(response.getItems(), repoId, login, number));
|
||||
}
|
||||
sendToView(view -> view.onNotifyAdapter(response.getItems(), page));
|
||||
});
|
||||
@ -86,7 +86,7 @@ class PullRequestCommitsPresenter extends BasePresenter<PullRequestCommitsMvp.Vi
|
||||
|
||||
@Override public void onWorkOffline() {
|
||||
if (commits.isEmpty()) {
|
||||
manageSubscription(RxHelper.getObserver(Commit.getCommits(repoId, login, number))
|
||||
manageSubscription(RxHelper.getSingle(Commit.getCommits(repoId, login, number))
|
||||
.subscribe(models -> sendToView(view -> view.onNotifyAdapter(models, 1))));
|
||||
} else {
|
||||
sendToView(BaseMvp.FAView::hideProgress);
|
||||
|
||||
@ -33,7 +33,7 @@ import com.fastaccess.ui.modules.repos.issues.create.CreateIssueActivity;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 31 Mar 2017, 7:17 PM
|
||||
|
||||
@ -17,7 +17,7 @@ import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import rx.Observable;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 11 Apr 2017, 11:20 AM
|
||||
|
||||
@ -58,7 +58,7 @@ class SearchPresenter extends BasePresenter<SearchMvp.View> implements SearchMvp
|
||||
boolean noneMatch = Stream.of(hints).noneMatch(value -> value.getText().equalsIgnoreCase(query));
|
||||
if (noneMatch) {
|
||||
SearchHistory searchHistory = new SearchHistory(query);
|
||||
manageSubscription(searchHistory.save(searchHistory).subscribe());
|
||||
manageObservable(searchHistory.save(searchHistory).toObservable());
|
||||
sendToView(view -> view.onNotifyAdapter(new SearchHistory(query)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Vasily Styagov.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.octo.bear.pago;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentSender;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Created by shc on 18.07.16.
|
||||
*/
|
||||
|
||||
public class BillingActivity extends Activity {
|
||||
|
||||
private static final String TAG = BillingActivity.class.getSimpleName();
|
||||
|
||||
static final String ACTION_PURCHASE = "io.octo.bear.pago.broadcast:purchase_success";
|
||||
static final String EXTRA_SUCCESS = "io.octo.bear.pago:extra.success";
|
||||
|
||||
static final int REQUEST_CODE = 1001;
|
||||
|
||||
static final String EXTRA_BUY_INTENT = "extra.buy_intent";
|
||||
|
||||
static void start(@NonNull
|
||||
final Context context, @NonNull
|
||||
final PendingIntent buyIntent) {
|
||||
final Intent intent = new Intent(context, BillingActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra(EXTRA_BUY_INTENT, buyIntent);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
final Bundle data = getIntent().getExtras();
|
||||
final PendingIntent buyIntent = data.getParcelable(EXTRA_BUY_INTENT);
|
||||
|
||||
startPurchaseFlow(buyIntent);
|
||||
}
|
||||
|
||||
private void startPurchaseFlow(PendingIntent buyIntent) {
|
||||
try {
|
||||
startIntentSenderForResult(buyIntent.getIntentSender(), REQUEST_CODE, new Intent(), 0, 0, 0);
|
||||
} catch (IntentSender.SendIntentException e) {
|
||||
Log.e(TAG, "onCreate: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == REQUEST_CODE && data != null) {
|
||||
data.setAction(ACTION_PURCHASE);
|
||||
data.putExtra(EXTRA_SUCCESS, resultCode == RESULT_OK);
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(data);
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Vasily Styagov.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.octo.bear.pago;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import io.octo.bear.pago.model.entity.PurchaseType;
|
||||
import io.octo.bear.pago.model.entity.ResponseCode;
|
||||
import io.octo.bear.pago.model.exception.BillingException;
|
||||
import rx.Single;
|
||||
|
||||
/**
|
||||
* Created by shc on 19.07.16.
|
||||
*/
|
||||
|
||||
class BillingAvailabilitySingle extends Single<Boolean> {
|
||||
BillingAvailabilitySingle(final Context context, final PurchaseType type) {
|
||||
super((OnSubscribe<Boolean>) subscriber -> new BillingServiceConnection(context, service -> {
|
||||
try {
|
||||
final int codeNumber = service.isBillingSupported(Pago.BILLING_API_VERSION, context.getPackageName(), type.value);
|
||||
final ResponseCode code = ResponseCode.getByCode(codeNumber);
|
||||
if (code == ResponseCode.OK) {
|
||||
subscriber.onSuccess(true);
|
||||
} else {
|
||||
throw new BillingException(ResponseCode.BILLING_UNAVAILABLE);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
subscriber.onError(e);
|
||||
}
|
||||
}).bindService()
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Vasily Styagov.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.octo.bear.pago;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.vending.billing.IInAppBillingService;
|
||||
|
||||
import static android.content.Context.BIND_AUTO_CREATE;
|
||||
|
||||
/**
|
||||
* Created by shc on 15.07.16.
|
||||
*/
|
||||
|
||||
class BillingServiceConnection implements ServiceConnection {
|
||||
|
||||
private static final String TAG = BillingServiceConnection.class.getSimpleName();
|
||||
private static final String IAB_SERVICE_ACTION = "com.android.vending.billing.InAppBillingService.BIND";
|
||||
private static final String IAB_SERVICE_PACKAGE = "com.android.vending";
|
||||
|
||||
private IInAppBillingService inAppBillingService;
|
||||
private ServiceConnectionListener listener;
|
||||
private Context context;
|
||||
|
||||
BillingServiceConnection(Context context, ServiceConnectionListener listener) {
|
||||
this.context = context;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
void bindService() {
|
||||
final Intent serviceIntent = new Intent(IAB_SERVICE_ACTION);
|
||||
serviceIntent.setPackage(IAB_SERVICE_PACKAGE);
|
||||
context.bindService(serviceIntent, this, BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
private void unbindService(Context context) {
|
||||
if (inAppBillingService != null) {
|
||||
context.unbindService(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
||||
Log.d(TAG, "onServiceConnected: billing service connected");
|
||||
inAppBillingService = IInAppBillingService.Stub.asInterface(iBinder);
|
||||
try {
|
||||
listener.onServiceConnected(inAppBillingService);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "onServiceConnected: ", e);
|
||||
} finally {
|
||||
unbindService(context);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onServiceDisconnected(ComponentName componentName) {
|
||||
Log.d(TAG, "onServiceDisconnected: billing service disconnected");
|
||||
inAppBillingService = null;
|
||||
}
|
||||
|
||||
interface ServiceConnectionListener {
|
||||
void onServiceConnected(IInAppBillingService service) throws RemoteException;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Vasily Styagov.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.octo.bear.pago;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import io.octo.bear.pago.model.entity.ResponseCode;
|
||||
import io.octo.bear.pago.model.exception.BillingException;
|
||||
|
||||
import static io.octo.bear.pago.model.entity.ResponseCode.ERROR;
|
||||
|
||||
/**
|
||||
* Created by shc on 15.07.16.
|
||||
*/
|
||||
final class BillingServiceUtils {
|
||||
static final String RESPONSE_CODE = "RESPONSE_CODE";
|
||||
static final Gson GSON = new Gson();
|
||||
|
||||
static ResponseCode retrieveResponseCode(final Bundle result) {
|
||||
return result == null ? ERROR : ResponseCode.getByCode(result.getInt(RESPONSE_CODE));
|
||||
}
|
||||
|
||||
static void checkResponseAndThrowIfError(ResponseCode code) throws BillingException {
|
||||
if (code != ResponseCode.OK) throw new BillingException(code);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Vasily Styagov.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.octo.bear.pago;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import io.octo.bear.pago.model.entity.ResponseCode;
|
||||
import io.octo.bear.pago.model.exception.BillingException;
|
||||
import rx.Completable;
|
||||
|
||||
import static io.octo.bear.pago.BillingServiceUtils.checkResponseAndThrowIfError;
|
||||
|
||||
/**
|
||||
* Created by shc on 18.07.16.
|
||||
*/
|
||||
|
||||
class ConsumePurchaseCompletable extends Completable {
|
||||
ConsumePurchaseCompletable(final Context context, final String purchaseToken) {
|
||||
super(subscriber -> new BillingServiceConnection(context, service -> {
|
||||
try {
|
||||
final int codeNumber = service.consumePurchase(Pago.BILLING_API_VERSION, context.getPackageName(), purchaseToken);
|
||||
final ResponseCode code = ResponseCode.getByCode(codeNumber);
|
||||
checkResponseAndThrowIfError(code);
|
||||
subscriber.onCompleted();
|
||||
} catch (BillingException e) {
|
||||
subscriber.onError(e);
|
||||
}
|
||||
}).bindService());
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,150 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Vasily Styagov.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.octo.bear.pago;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.octo.bear.pago.model.entity.Inventory;
|
||||
import io.octo.bear.pago.model.entity.Order;
|
||||
import io.octo.bear.pago.model.entity.PurchaseType;
|
||||
import rx.Completable;
|
||||
import rx.Single;
|
||||
|
||||
/**
|
||||
* Created by shc on 14.07.16.
|
||||
* <p>
|
||||
* This class is entry point to the wonderful world of Play Store in-app purchases. <br/>
|
||||
* There's couple of wrapped in Rx methods for each purchase-related action (for products and subscriptions). <br/>
|
||||
* <b>Note</b>: presented observables don't have default scheduler, so it would work on thread where they were called.
|
||||
* Applying any schedulers stays up to you.
|
||||
* </p>
|
||||
*/
|
||||
public class Pago {
|
||||
|
||||
static final int BILLING_API_VERSION = 3;
|
||||
|
||||
private final Context context;
|
||||
|
||||
/**
|
||||
* @param context
|
||||
* the context is needed to start IAB-related services
|
||||
*/
|
||||
public Pago(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if target version of billing API supports <i>in-app purchases</i>.
|
||||
*
|
||||
* @return single that emits {@code true} value if supported and Exception otherwise
|
||||
*/
|
||||
public Single<Boolean> checkPurchasesAvailability() {
|
||||
return new BillingAvailabilitySingle(context, PurchaseType.INAPP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if target version of billing API supports <i>subscriptions</i>.
|
||||
*
|
||||
* @return single that emits {@code true} value if supported and Exception otherwise
|
||||
*/
|
||||
public Single<Boolean> checkSubscriptionAvailability() {
|
||||
return new BillingAvailabilitySingle(context, PurchaseType.SUBSCRIPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to query details about desired <i>products</i> (title, price, descriptions etc).
|
||||
*
|
||||
* @param skus
|
||||
* list of desired items' product IDs
|
||||
* @return {@link Inventory}, that represents collection of described products
|
||||
*/
|
||||
public Single<Inventory> obtainProductsDetails(final List<String> skus) {
|
||||
return new ProductDetailsSingle(context, PurchaseType.INAPP, skus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to query details about desired <i>subscriptions</i> (title, price, descriptions etc).
|
||||
*
|
||||
* @param skus
|
||||
* list of desired items' product IDs
|
||||
* @return {@link Inventory}, that represents collection of described products
|
||||
*/
|
||||
public Single<Inventory> obtainSubscriptionsDetails(final List<String> skus) {
|
||||
return new ProductDetailsSingle(context, PurchaseType.SUBSCRIPTION, skus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Here you can start to spend your money. This method starts <i>product</i> purchase flow and performs purchase.
|
||||
*
|
||||
* @param sku
|
||||
* product id of desired product
|
||||
* @param payload
|
||||
* some arbitrary data, that purchased item info will contain
|
||||
* @return {@link Single} emits {@link Order} containing purchased item info and signature
|
||||
*/
|
||||
public Single<Order> purchaseProduct(final String sku, final String payload) {
|
||||
return new PerformPurchaseSingle(context, PurchaseType.INAPP, sku, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Here you can start to spend your money. This method starts <i>subscription</i> purchase flow and performs purchase.
|
||||
*
|
||||
* @param sku
|
||||
* product id of desired product
|
||||
* @param payload
|
||||
* some arbitrary data, that purchased item info will contain
|
||||
* @return {@link Single} that emits {@link Order} containing purchased item info and signature
|
||||
*/
|
||||
public Single<Order> purchaseSubscription(final String sku, final String payload) {
|
||||
return new PerformPurchaseSingle(context, PurchaseType.SUBSCRIPTION, sku, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to check <i>products</i>, that user has already bought.
|
||||
*
|
||||
* @return {@link Single} that emits {@link Order} containing purchased products data
|
||||
*/
|
||||
public Single<List<Order>> obtainPurchasedProducts() {
|
||||
return new PurchasedItemsSingle(context, PurchaseType.INAPP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to check <i>subscription</i>, that user has already bought.
|
||||
*
|
||||
* @return {@link Single} that emits {@link Order} containing purchased subscriptions data
|
||||
*/
|
||||
public Single<List<Order>> obtainPurchasedSubscriptions() {
|
||||
return new PurchasedItemsSingle(context, PurchaseType.SUBSCRIPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* If user already owns some product, Google Play would prevent user from purchasing another product with the same
|
||||
* product id. You have to consume this purchase and make the product available again.
|
||||
* And yes, you can do it with this method. <br/>
|
||||
* <b>Note:</b> subscriptions cannot be consumed.
|
||||
*
|
||||
* @param purchaseToken
|
||||
* token of purchased product, can be taken from {@link Order}
|
||||
* @return {@link Completable} that notifies you about either successful consumption, or error
|
||||
*/
|
||||
public Completable consumeProduct(final String purchaseToken) {
|
||||
return new ConsumePurchaseCompletable(context, purchaseToken);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Vasily Styagov.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.octo.bear.pago;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import io.octo.bear.pago.model.entity.Order;
|
||||
import io.octo.bear.pago.model.entity.Purchase;
|
||||
import io.octo.bear.pago.model.entity.PurchaseType;
|
||||
import io.octo.bear.pago.model.entity.ResponseCode;
|
||||
import io.octo.bear.pago.model.exception.BillingException;
|
||||
import rx.Single;
|
||||
import rx.SingleSubscriber;
|
||||
|
||||
import static io.octo.bear.pago.BillingServiceUtils.GSON;
|
||||
import static io.octo.bear.pago.BillingServiceUtils.checkResponseAndThrowIfError;
|
||||
import static io.octo.bear.pago.BillingServiceUtils.retrieveResponseCode;
|
||||
|
||||
/**
|
||||
* Created by shc on 14.07.16.
|
||||
*/
|
||||
|
||||
class PerformPurchaseSingle extends Single<Order> {
|
||||
|
||||
static final String RESPONSE_BUY_INTENT = "BUY_INTENT";
|
||||
static final String RESPONSE_INAPP_PURCHASE_DATA = "INAPP_PURCHASE_DATA";
|
||||
static final String RESPONSE_INAPP_DATA_SIGNATURE = "INAPP_DATA_SIGNATURE";
|
||||
|
||||
PerformPurchaseSingle(final Context context, final PurchaseType type, final String sku, String payload) {
|
||||
super((OnSubscribe<Order>) subscriber -> new BillingServiceConnection(context, service -> {
|
||||
try {
|
||||
final Bundle buyIntentBundle = service.getBuyIntent(Pago.BILLING_API_VERSION,
|
||||
context.getPackageName(), sku, type.value, payload);
|
||||
final ResponseCode responseCode = retrieveResponseCode(buyIntentBundle);
|
||||
checkResponseAndThrowIfError(responseCode);
|
||||
final PendingIntent buyIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
|
||||
if (buyIntent == null) {
|
||||
throw new RuntimeException("unable to retrieve buy intent");
|
||||
}
|
||||
LocalBroadcastManager
|
||||
.getInstance(context)
|
||||
.registerReceiver(
|
||||
createPurchaseBroadcastReceiver(payload, subscriber),
|
||||
new IntentFilter(BillingActivity.ACTION_PURCHASE));
|
||||
|
||||
BillingActivity.start(context, buyIntent);
|
||||
} catch (BillingException e) {
|
||||
subscriber.onError(e);
|
||||
}
|
||||
|
||||
}).bindService()
|
||||
);
|
||||
}
|
||||
|
||||
private static BroadcastReceiver createPurchaseBroadcastReceiver(final String payload, final SingleSubscriber<? super Order> subscriber) {
|
||||
|
||||
return new BroadcastReceiver() {
|
||||
@Override public void onReceive(Context context, Intent data) {
|
||||
try {
|
||||
LocalBroadcastManager.getInstance(context).unregisterReceiver(this);
|
||||
|
||||
final Bundle result = data.getExtras();
|
||||
|
||||
final boolean success = result.getBoolean(BillingActivity.EXTRA_SUCCESS, false);
|
||||
if (!success) {
|
||||
throw new BillingException(ResponseCode.ITEM_UNAVAILABLE);
|
||||
}
|
||||
final ResponseCode code = retrieveResponseCode(result);
|
||||
checkResponseAndThrowIfError(code);
|
||||
String originalJson = result.getString(RESPONSE_INAPP_PURCHASE_DATA);
|
||||
Log.e("JsonDate", originalJson + "");
|
||||
final Purchase purchase = GSON.fromJson(originalJson, Purchase.class);
|
||||
final Order order = new Order(purchase, result.getString(RESPONSE_INAPP_DATA_SIGNATURE), originalJson);
|
||||
final boolean purchaseDataIsCorrect = TextUtils.equals(payload, purchase.developerPayload);
|
||||
Log.e("payload", purchase.developerPayload + " " + purchaseDataIsCorrect);
|
||||
if (purchaseDataIsCorrect) {
|
||||
subscriber.onSuccess(order);
|
||||
} else {
|
||||
throw new BillingException(ResponseCode.ERROR);
|
||||
}
|
||||
} catch (BillingException e) {
|
||||
subscriber.onError(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Vasily Styagov.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.octo.bear.pago;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.octo.bear.pago.model.entity.Inventory;
|
||||
import io.octo.bear.pago.model.entity.PurchaseType;
|
||||
import io.octo.bear.pago.model.entity.ResponseCode;
|
||||
import io.octo.bear.pago.model.entity.Sku;
|
||||
import io.octo.bear.pago.model.exception.BillingException;
|
||||
import rx.Single;
|
||||
|
||||
import static io.octo.bear.pago.BillingServiceUtils.GSON;
|
||||
import static io.octo.bear.pago.BillingServiceUtils.checkResponseAndThrowIfError;
|
||||
import static io.octo.bear.pago.BillingServiceUtils.retrieveResponseCode;
|
||||
|
||||
/**
|
||||
* Created by shc on 14.07.16.
|
||||
*/
|
||||
|
||||
class ProductDetailsSingle extends Single<Inventory> {
|
||||
|
||||
static final String RESPONSE_DETAILS_LIST = "DETAILS_LIST";
|
||||
static final String EXTRA_ITEM_ID_LIST = "ITEM_ID_LIST";
|
||||
|
||||
ProductDetailsSingle(final Context context, final PurchaseType type, final List<String> purchaseIds) {
|
||||
super((OnSubscribe<Inventory>) subscriber -> new BillingServiceConnection(context, service -> {
|
||||
try {
|
||||
final Bundle querySku = new Bundle();
|
||||
querySku.putStringArrayList(EXTRA_ITEM_ID_LIST, new ArrayList<>(purchaseIds));
|
||||
|
||||
final Bundle details = service.getSkuDetails(Pago.BILLING_API_VERSION, context.getPackageName(), type.value, querySku);
|
||||
final ResponseCode responseCode = retrieveResponseCode(details);
|
||||
|
||||
checkResponseAndThrowIfError(responseCode);
|
||||
|
||||
final ArrayList<String> skus = details.getStringArrayList(RESPONSE_DETAILS_LIST);
|
||||
if (skus == null) throw new RuntimeException("skus list is not supplied");
|
||||
|
||||
final Inventory inventory = new Inventory();
|
||||
for (String serializedSku : skus) {
|
||||
inventory.addItem(GSON.fromJson(serializedSku, Sku.class));
|
||||
}
|
||||
|
||||
subscriber.onSuccess(inventory);
|
||||
} catch (RemoteException | BillingException e) {
|
||||
subscriber.onError(e);
|
||||
}
|
||||
}).bindService()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Vasily Styagov.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.octo.bear.pago;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.octo.bear.pago.model.entity.Order;
|
||||
import io.octo.bear.pago.model.entity.Purchase;
|
||||
import io.octo.bear.pago.model.entity.PurchaseType;
|
||||
import io.octo.bear.pago.model.entity.ResponseCode;
|
||||
import io.octo.bear.pago.model.exception.BillingException;
|
||||
import rx.Single;
|
||||
|
||||
import static io.octo.bear.pago.BillingServiceUtils.GSON;
|
||||
import static io.octo.bear.pago.BillingServiceUtils.checkResponseAndThrowIfError;
|
||||
import static io.octo.bear.pago.BillingServiceUtils.retrieveResponseCode;
|
||||
|
||||
/**
|
||||
* Created by shc on 18.07.16.
|
||||
*/
|
||||
|
||||
class PurchasedItemsSingle extends Single<List<Order>> {
|
||||
|
||||
static final String RESPONSE_INAPP_PURCHASE_ITEM_LIST = "INAPP_PURCHASE_ITEM_LIST";
|
||||
static final String RESPONSE_INAPP_PURCHASE_DATA_LIST = "INAPP_PURCHASE_DATA_LIST";
|
||||
static final String RESPONSE_INAPP_PURCHASE_SIGNATURE_LIST = "INAPP_DATA_SIGNATURE_LIST";
|
||||
static final String RESPONSE_INAPP_CONTINUATION_TOKEN = "INAPP_CONTINUATION_TOKEN";
|
||||
|
||||
PurchasedItemsSingle(final Context context, final PurchaseType type) {
|
||||
super((OnSubscribe<List<Order>>) subscriber ->
|
||||
new BillingServiceConnection(context, service -> {
|
||||
try {
|
||||
final Bundle purchases =
|
||||
service.getPurchases(Pago.BILLING_API_VERSION, context.getPackageName(), type.value, null);
|
||||
|
||||
final ResponseCode code = retrieveResponseCode(purchases);
|
||||
|
||||
checkResponseAndThrowIfError(code);
|
||||
|
||||
final List<String> data = purchases.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST);
|
||||
final List<String> signatures = purchases.getStringArrayList(RESPONSE_INAPP_PURCHASE_SIGNATURE_LIST);
|
||||
|
||||
if (data != null && signatures != null) {
|
||||
|
||||
final List<Order> result = new ArrayList<>();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
String originalJson = data.get(i);
|
||||
result.add(new Order(GSON.fromJson(originalJson, Purchase.class), signatures.get(i), originalJson));
|
||||
}
|
||||
subscriber.onSuccess(result);
|
||||
|
||||
} else {
|
||||
subscriber.onError(new NullPointerException((data == null) ? "data is null" : "signatures is null"));
|
||||
}
|
||||
|
||||
} catch (BillingException e) {
|
||||
subscriber.onError(e);
|
||||
}
|
||||
}).bindService()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user