Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Commit

Permalink
improving offline module and reading for 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Kosh committed Mar 19, 2017
1 parent 247a803 commit 11ddea1
Show file tree
Hide file tree
Showing 14 changed files with 176 additions and 204 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ android {
applicationId "com.fastaccess.github"
minSdkVersion 21
targetSdkVersion 25
versionCode 111
versionName "1.1.1"
versionCode 120
versionName "1.2.0"
signingConfig signingConfigs.signing
buildConfigString "GITHUB_CLIENT_ID", (buildProperties.secrets['github_client_id'] | buildProperties.notThere['github_client_id']).string
buildConfigString "GITHUB_SECRET", (buildProperties.secrets['github_secret'] | buildProperties.notThere['github_secret']).string
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/java/com/fastaccess/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import io.requery.rx.RxSupport;
import io.requery.rx.SingleEntityStore;
import io.requery.sql.Configuration;
import io.requery.sql.ConfigurationBuilder;
import io.requery.sql.EntityDataStore;
import io.requery.sql.TableCreationMode;

Expand Down Expand Up @@ -46,9 +45,7 @@ public SingleEntityStore<Persistable> getDataStore() {
if (dataStore == null) {
EntityModel model = Models.DEFAULT;
DatabaseSource source = new DatabaseSource(this, model, "FastHub-DB", 1);
Configuration configuration = new ConfigurationBuilder(source, model)
.useDefaultLogging()
.build();
Configuration configuration = source.getConfiguration();
if (BuildConfig.DEBUG) {
source.setTableCreationMode(TableCreationMode.DROP_CREATE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Parcelable;
import android.support.annotation.NonNull;

import com.annimon.stream.Stream;
import com.fastaccess.App;
import com.fastaccess.data.dao.converters.UserConverter;

Expand Down Expand Up @@ -61,79 +62,72 @@ public Completable save(Comment modelEntity) {
.andThen(App.getInstance().getDataStore().insert(modelEntity).toCompletable());
}

public static Completable saveForGist(@NonNull List<Comment> models, @NonNull String gistId) {
public static Observable saveForGist(@NonNull List<Comment> models, @NonNull String gistId) {
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
return singleEntityStore.delete(Comment.class)
singleEntityStore.delete(Comment.class)
.where(GIST_ID.equal(gistId))
.get()
.toSingle()
.toCompletable()
.andThen(Observable.from(models)
.map(model -> {
model.setGistId(gistId);
return model.save(model);
}))
.toCompletable();
.value();
return Observable.create(subscriber -> Stream.of(models)
.forEach(model -> {
model.setGistId(gistId);
model.save(model).toObservable().toBlocking().singleOrDefault(null);
}));
}

public static Completable saveForCommits(@NonNull List<Comment> models, @NonNull String repoId,
@NonNull String login, @NonNull String commitId) {
public static Observable saveForCommits(@NonNull List<Comment> models, @NonNull String repoId,
@NonNull String login, @NonNull String commitId) {
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
return singleEntityStore.delete(Comment.class)
singleEntityStore.delete(Comment.class)
.where(COMMIT_ID.equal(commitId)
.and(REPO_ID.equal(repoId))
.and(LOGIN.equal(login)))
.get()
.toSingle()
.toCompletable()
.andThen(Observable.from(models)
.map(model -> {
model.setLogin(login);
model.setRepoId(repoId);
model.setCommitId(commitId);
return model.save(model);
}))
.toCompletable();
.value();
return Observable.create(subscriber -> Stream.of(models)
.forEach(model -> {
model.setLogin(login);
model.setRepoId(repoId);
model.setCommitId(commitId);
model.save(model).toObservable().toBlocking().singleOrDefault(null);
}));
}

public static Completable saveForIssues(@NonNull List<Comment> models, @NonNull String repoId,
@NonNull String login, @NonNull String issueId) {
public static Observable saveForIssues(@NonNull List<Comment> models, @NonNull String repoId,
@NonNull String login, @NonNull String issueId) {
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
return singleEntityStore.delete(Comment.class)
singleEntityStore.delete(Comment.class)
.where(ISSUE_ID.equal(issueId)
.and(REPO_ID.equal(repoId))
.and(LOGIN.equal(login)))
.get()
.toSingle()
.toCompletable()
.andThen(Observable.from(models)
.map(model -> {
model.setLogin(login);
model.setRepoId(repoId);
model.setIssueId(issueId);
return model.save(model);
}))
.toCompletable();
.value();

return Observable.create(subscriber -> Stream.of(models)
.forEach(model -> {
model.setLogin(login);
model.setRepoId(repoId);
model.setIssueId(issueId);
model.save(model).toObservable().toBlocking().singleOrDefault(null);
}));
}

public static Completable saveForPullRequest(@NonNull List<Comment> models, @NonNull String repoId,
@NonNull String login, @NonNull String pullRequestId) {
public static Observable saveForPullRequest(@NonNull List<Comment> models, @NonNull String repoId,
@NonNull String login, @NonNull String pullRequestId) {
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
return singleEntityStore.delete(Comment.class)
singleEntityStore.delete(Comment.class)
.where(PULL_REQUEST_ID.equal(pullRequestId)
.and(REPO_ID.equal(repoId))
.and(LOGIN.equal(login)))
.get()
.toSingle()
.toCompletable()
.andThen(Observable.from(models)
.map(model -> {
model.setLogin(login);
model.setRepoId(repoId);
model.setPullRequestId(pullRequestId);
return model.save(model);
}))
.toCompletable();
.value();
return Observable.create(subscriber -> Stream.of(models)
.forEach(model -> {
model.setLogin(login);
model.setRepoId(repoId);
model.setPullRequestId(pullRequestId);
model.save(model).toObservable().toBlocking().singleOrDefault(null);
}));
}

public static Observable<List<Comment>> getGistComments(@NonNull String gistId) {
Expand Down
43 changes: 20 additions & 23 deletions app/src/main/java/com/fastaccess/data/dao/model/AbstractCommit.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Parcelable;
import android.support.annotation.NonNull;

import com.annimon.stream.Stream;
import com.fastaccess.App;
import com.fastaccess.data.dao.CommitFileListModel;
import com.fastaccess.data.dao.CommitListModel;
Expand Down Expand Up @@ -63,40 +64,36 @@ public Completable save(Commit modelEntity) {
.toCompletable();
}

public static Completable save(@NonNull List<Commit> models, @NonNull String repoId, @NonNull String login) {
public static Observable save(@NonNull List<Commit> models, @NonNull String repoId, @NonNull String login) {
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
return singleEntityStore.delete(Commit.class)
singleEntityStore.delete(Commit.class)
.where(REPO_ID.eq(repoId)
.and(LOGIN.eq(login)))
.get()
.toSingle()
.toCompletable()
.andThen(Observable.from(models)
.map(commitModel -> {
commitModel.setRepoId(repoId);
commitModel.setLogin(login);
return commitModel.save(commitModel);
}))
.toCompletable();
.value();
return Observable.create(subscriber -> Stream.of(models)
.forEach(commitModel -> {
commitModel.setRepoId(repoId);
commitModel.setLogin(login);
commitModel.save(commitModel).toObservable().toBlocking().singleOrDefault(null);
}));
}

public static Completable save(@NonNull List<Commit> models, @NonNull String repoId, @NonNull String login, long number) {
public static Observable save(@NonNull List<Commit> models, @NonNull String repoId, @NonNull String login, long number) {
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
return singleEntityStore.delete(Commit.class)
singleEntityStore.delete(Commit.class)
.where(REPO_ID.eq(repoId)
.and(LOGIN.eq(login))
.and(PULL_REQUEST_NUMBER.eq(number)))
.get()
.toSingle()
.toCompletable()
.andThen(Observable.from(models)
.map(commitModel -> {
commitModel.setRepoId(repoId);
commitModel.setLogin(login);
commitModel.setPullRequestNumber(number);
return commitModel.save(commitModel);
}))
.toCompletable();
.value();
return Observable.create(subscriber -> Stream.of(models)
.forEach(commitModel -> {
commitModel.setRepoId(repoId);
commitModel.setLogin(login);
commitModel.setPullRequestNumber(number);
commitModel.save(commitModel).toObservable().toBlocking().singleOrDefault(null);
}));
}

public static Observable<List<Commit>> getCommits(@NonNull String repoId, @NonNull String login) {
Expand Down
19 changes: 9 additions & 10 deletions app/src/main/java/com/fastaccess/data/dao/model/AbstractGist.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public Completable save(Gist modelEntity) {
public static Completable save(@NonNull List<Gist> gists) {
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
return singleEntityStore.delete(Gist.class)
.where(Gist.OWNER_NAME.isNull())
.get()
.toSingle()
.toCompletable()
Expand All @@ -78,19 +79,17 @@ public static Completable save(@NonNull List<Gist> gists) {
.toCompletable();
}

public static Completable save(@NonNull List<Gist> gists, @NonNull String ownerName) {
public static Observable save(@NonNull List<Gist> gists, @NonNull String ownerName) {
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
return singleEntityStore.delete(Gist.class)
singleEntityStore.delete(Gist.class)
.where(Gist.OWNER_NAME.equal(ownerName))
.get()
.toSingle()
.toCompletable()
.andThen(Observable.from(gists)
.map(gistsModel -> {
gistsModel.setOwnerName(ownerName);
return gistsModel.save(gistsModel);
}))
.toCompletable();
.value();
return Observable.create(subscriber -> Stream.of(gists)
.forEach(gistsModel -> {
gistsModel.setOwnerName(ownerName);
gistsModel.save(gistsModel).toObservable().toBlocking().singleOrDefault(null);
}));
}

@NonNull public static Observable<List<Gist>> getMyGists(@NonNull String ownerName) {
Expand Down
22 changes: 10 additions & 12 deletions app/src/main/java/com/fastaccess/data/dao/model/AbstractIssue.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Parcelable;
import android.support.annotation.NonNull;

import com.annimon.stream.Stream;
import com.fastaccess.App;
import com.fastaccess.data.dao.LabelListModel;
import com.fastaccess.data.dao.MilestoneModel;
Expand Down Expand Up @@ -77,22 +78,19 @@ public Completable save(Issue entity) {
.toCompletable());
}

public static Completable save(@NonNull List<Issue> models, @NonNull String repoId, @NonNull String login) {
public static Observable save(@NonNull List<Issue> models, @NonNull String repoId, @NonNull String login) {
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
return singleEntityStore.delete(Issue.class)
singleEntityStore.delete(Issue.class)
.where(REPO_ID.equal(repoId)
.and(LOGIN.equal(login)))
.get()
.toSingle()
.toCompletable()
.andThen(Observable.from(models)
.map(issueModel -> {
issueModel.setRepoId(repoId);
issueModel.setLogin(login);
return issueModel.save(issueModel);
}))
.toCompletable();

.value();
return Observable.create(subscriber -> Stream.of(models)
.forEach(issueModel -> {
issueModel.setRepoId(repoId);
issueModel.setLogin(login);
issueModel.save(issueModel).toObservable().toBlocking().singleOrDefault(null);
}));
}

public static Observable<List<Issue>> getIssues(@NonNull String repoId, @NonNull String login, @NonNull IssueState issueState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Parcelable;
import android.support.annotation.NonNull;

import com.annimon.stream.Stream;
import com.fastaccess.App;
import com.fastaccess.data.dao.LabelModel;
import com.fastaccess.data.dao.MilestoneModel;
Expand Down Expand Up @@ -68,24 +69,22 @@ public Completable save(IssueEvent entity) {
.toCompletable());
}

public static Completable save(@NonNull List<IssueEvent> models, @NonNull String repoId,
@NonNull String login, @NonNull String issueId) {
public static Observable save(@NonNull List<IssueEvent> models, @NonNull String repoId,
@NonNull String login, @NonNull String issueId) {
SingleEntityStore<Persistable> singleEntityStore = App.getInstance().getDataStore();
return singleEntityStore.delete(IssueEvent.class)
singleEntityStore.delete(IssueEvent.class)
.where(LOGIN.equal(login)
.and(REPO_ID.equal(repoId))
.and(ISSUE_ID.equal(issueId)))
.get()
.toSingle()
.toCompletable()
.andThen(Observable.from(models)
.map(issueEventModel -> {
issueEventModel.setIssueId(issueId);
issueEventModel.setLogin(login);
issueEventModel.setRepoId(repoId);
return issueEventModel.save(issueEventModel);
}))
.toCompletable();
.value();
return Observable.create(subscriber -> Stream.of(models)
.forEach(issueEventModel -> {
issueEventModel.setIssueId(issueId);
issueEventModel.setLogin(login);
issueEventModel.setRepoId(repoId);
issueEventModel.save(issueEventModel).toObservable().toBlocking().singleOrDefault(null);
}));
}

public static Observable<List<IssueEvent>> get(@NonNull String repoId, @NonNull String login,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.os.Parcel;
import android.os.Parcelable;

import com.annimon.stream.Stream;
import com.fastaccess.App;
import com.fastaccess.data.dao.NotificationSubjectModel;
import com.fastaccess.data.dao.converters.NotificationSubjectConverter;
Expand Down Expand Up @@ -48,15 +49,13 @@ public Completable save(Notification notification) {
.toCompletable());
}

public static Completable save(@NonNull List<Notification> models) {
public static Observable<Object> save(@NonNull List<Notification> models) {
SingleEntityStore<Persistable> dataSource = App.getInstance().getDataStore();
return dataSource.delete(Notification.class)
dataSource.delete(Notification.class)
.get()
.toSingle()
.toCompletable()
.andThen(Observable.from(models)
.map(notification -> notification.save(notification)))
.toCompletable();
.value();
return Observable.create(subscriber -> Stream.of(models)
.forEach(notification -> notification.save(notification).toObservable().toBlocking().singleOrDefault(null)));
}

public static Observable<List<Notification>> getNotifications() {
Expand Down
Loading

0 comments on commit 11ddea1

Please sign in to comment.