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

Commit

Permalink
fixed offline mode crash to solve #64 and #63, fixed #62 where i misp…
Browse files Browse the repository at this point in the history
…laced a menuItem and finally #48 now should fixed for good and released 1.0.6
  • Loading branch information
Kosh committed Mar 6, 2017
1 parent 4c716dd commit bd9c920
Show file tree
Hide file tree
Showing 28 changed files with 74 additions and 60 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ android {
applicationId "com.fastaccess.github"
minSdkVersion 21
targetSdkVersion 25
versionCode 105
versionName "1.0.5"
versionCode 106
versionName "1.0.6"
signingConfig signingConfigs.signing
buildConfigField "String", "GITHUB_CLIENT_ID", "\"${GITHUB_CLIENT_ID}\""
buildConfigField "String", "GITHUB_SECRET", "\"${GITHUB_SECRET}\""
Expand Down
33 changes: 14 additions & 19 deletions app/src/main/java/com/fastaccess/helper/ParseDateFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,35 @@ public class ParseDateFormat {

private static final ParseDateFormat INSTANCE = new ParseDateFormat();

private static ParseDateFormat getInstance() {
return INSTANCE;
}

private final Object lock = new Object();

private final DateFormat dateFormat;
private final TimeZone timeZone;

private ParseDateFormat() {
dateFormat = new SimpleDateFormat("HH:mm:ss", Locale.US);
dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
dateFormat.setTimeZone(TimeZone.getDefault());
timeZone = TimeZone.getDefault();
}

public String format(Date date) {
@NonNull public String format(Date date) {
synchronized (lock) {
return dateFormat.format(date);
}
}

public static CharSequence getTimeAgo(@Nullable Date parsedDate) {
@NonNull public static CharSequence getTimeAgo(@Nullable Date parsedDate) {
if (parsedDate != null) {
long toLocalTime = parsedDate.getTime() + getInstance().timeZone.getRawOffset() + getInstance().timeZone.getDSTSavings();
if (INSTANCE.timeZone.getID().equalsIgnoreCase("UTC")) {
toLocalTime = parsedDate.getTime();
}
return DateUtils.getRelativeTimeSpanString(toLocalTime, System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
long now = System.currentTimeMillis();
return DateUtils.getRelativeTimeSpanString(parsedDate.getTime(), now, DateUtils.SECOND_IN_MILLIS);
}
return "N/A";
}

public static String toGithubDate(@NonNull Date date) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
return simpleDateFormat.format(date);
@NonNull public static String toGithubDate(@NonNull Date date) {
return getInstance().format(date);
}

public static String prettifyDate(long timestamp) {
return new SimpleDateFormat("dd-MM-yyyy", Locale.US).format(new Date(timestamp));
@NonNull public static String prettifyDate(long timestamp) {
return new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH).format(new Date(timestamp));
}

@Nullable public static Date getDateFromString(@NonNull String date) {
Expand All @@ -63,4 +54,8 @@ public static String prettifyDate(long timestamp) {
}
return null;
}

@NonNull private static ParseDateFormat getInstance() {
return INSTANCE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class RestProvider {
private final static Gson gson = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.excludeFieldsWithModifiers(Modifier.FINAL, Modifier.TRANSIENT, Modifier.STATIC)
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.setDateFormat("yyyy-MM-dd HH:mm:ss")
.setPrettyPrinting()
.create();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.fastaccess.data.dao.SimpleUrlsModel;
import com.fastaccess.data.dao.types.EventsType;
import com.fastaccess.helper.InputHelper;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.provider.scheme.SchemeParser;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
Expand Down Expand Up @@ -90,7 +91,7 @@ class FeedsPresenter extends BasePresenter<FeedsMvp.View> implements FeedsMvp.Pr

@Override public void onWorkOffline() {
if (eventsModels.isEmpty()) {
manageSubscription(EventsModel.getEvents().subscribe(modelList -> {
manageSubscription(RxHelper.getObserver(EventsModel.getEvents()).subscribe(modelList -> {
if (modelList != null) {
eventsModels.addAll(modelList);
sendToView(FeedsMvp.View::onNotifyAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.view.View;

import com.fastaccess.data.dao.GistsModel;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
import com.fastaccess.ui.modules.gists.gist.GistView;
Expand Down Expand Up @@ -72,7 +73,7 @@ class GistsPresenter extends BasePresenter<GistsMvp.View> implements GistsMvp.Pr

@Override public void onWorkOffline() {
if (gistsModels.isEmpty()) {
manageSubscription(GistsModel.getGists().subscribe(gistsModels1 -> {
manageSubscription(RxHelper.getObserver(GistsModel.getGists()).subscribe(gistsModels1 -> {
gistsModels.addAll(gistsModels1);
sendToView(GistsMvp.View::onNotifyAdapter);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class GistPresenter extends BasePresenter<GistMvp.View> implements GistMvp.Prese

@Override public void onWorkOffline(@NonNull String gistId) {
if (gist == null) {
manageSubscription(GistsModel.getGist(gistId)
manageSubscription(RxHelper.getObserver(GistsModel.getGist(gistId))
.subscribe(gistsModel -> {
this.gist = gistsModel;
sendToView(GistMvp.View::onSetupDetails);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.fastaccess.ui.modules.gists.gist.comments;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand All @@ -12,11 +10,10 @@
import com.fastaccess.data.dao.LoginModel;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.helper.Logger;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.adapter.CommentsAdapter;
import com.fastaccess.ui.base.mvp.BaseMvp;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
import com.fastaccess.ui.widgets.recyclerview.DynamicRecyclerView;

import java.util.ArrayList;

Expand Down Expand Up @@ -94,7 +91,7 @@ class GistCommentsPresenter extends BasePresenter<GistCommentsMvp.View> implemen

@Override public void onWorkOffline(@NonNull String gistId) {
if (comments.isEmpty()) {
manageSubscription(CommentsModel.getGistComments(gistId).subscribe(
manageSubscription(RxHelper.getObserver(CommentsModel.getGistComments(gistId)).subscribe(
localComments -> {
if (localComments != null && !localComments.isEmpty()) {
Logger.e(localComments.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class NotificationsPresenter extends BasePresenter<NotificationsMvp.View>

@Override public void onWorkOffline() {
if (notifications.isEmpty()) {
manageSubscription(NotificationThreadModel.getNotifications()
manageSubscription(RxHelper.getObserver(NotificationThreadModel.getNotifications())
.subscribe(models -> {
if (models != null) {
notifications.addAll(models);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.view.View;

import com.fastaccess.data.dao.UserModel;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;

Expand Down Expand Up @@ -79,7 +80,7 @@ class ProfileFollowersPresenter extends BasePresenter<ProfileFollowersMvp.View>

@Override public void onWorkOffline(@NonNull String login) {
if (users.isEmpty()) {
manageSubscription(UserModel.getFollowers(login).subscribe(userModels -> {
manageSubscription(RxHelper.getObserver(UserModel.getFollowers(login)).subscribe(userModels -> {
users.addAll(userModels);
sendToView(ProfileFollowersMvp.View::onNotifyAdapter);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.view.View;

import com.fastaccess.data.dao.UserModel;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;

Expand Down Expand Up @@ -79,7 +80,7 @@ class ProfileFollowingPresenter extends BasePresenter<ProfileFollowingMvp.View>

@Override public void onWorkOffline(@NonNull String login) {
if (users.isEmpty()) {
manageSubscription(UserModel.getFollowing(login).subscribe(userModels -> {
manageSubscription(RxHelper.getObserver(UserModel.getFollowing(login)).subscribe(userModels -> {
users.addAll(userModels);
sendToView(ProfileFollowingMvp.View::onNotifyAdapter);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.view.View;

import com.fastaccess.data.dao.GistsModel;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;

Expand Down Expand Up @@ -78,7 +79,7 @@ class ProfileGistsPresenter extends BasePresenter<ProfileGistsMvp.View> implemen

@Override public void onWorkOffline(@NonNull String login) {
if (gistsModels.isEmpty()) {
manageSubscription(GistsModel.getMyGists(login).subscribe(gistsModels1 -> {
manageSubscription(RxHelper.getObserver(GistsModel.getMyGists(login)).subscribe(gistsModels1 -> {
gistsModels.addAll(gistsModels1);
sendToView(ProfileGistsMvp.View::onNotifyAdapter);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.fastaccess.data.dao.LoginModel;
import com.fastaccess.data.dao.NameParser;
import com.fastaccess.data.dao.RepoModel;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
import com.fastaccess.ui.modules.repos.RepoPagerView;
Expand Down Expand Up @@ -89,7 +90,7 @@ class ProfileReposPresenter extends BasePresenter<ProfileReposMvp.View> implemen

@Override public void onWorkOffline(@NonNull String login) {
if (repos.isEmpty()) {
manageSubscription(RepoModel.getMyRepos(login).subscribe(repoModels -> {
manageSubscription(RxHelper.getObserver(RepoModel.getMyRepos(login)).subscribe(repoModels -> {
repos.addAll(repoModels);
sendToView(ProfileReposMvp.View::onNotifyAdapter);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.fastaccess.data.dao.NameParser;
import com.fastaccess.data.dao.RepoModel;
import com.fastaccess.helper.Logger;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
import com.fastaccess.ui.modules.repos.RepoPagerView;
Expand Down Expand Up @@ -82,7 +83,7 @@ class ProfileStarredPresenter extends BasePresenter<ProfileStarredMvp.View> impl

@Override public void onWorkOffline(@NonNull String login) {
if (repos.isEmpty()) {
manageSubscription(RepoModel.getStarred(login).subscribe(repoModels -> {
manageSubscription(RxHelper.getObserver(RepoModel.getStarred(login)).subscribe(repoModels -> {
repos.addAll(repoModels);
Logger.e(repoModels);
sendToView(ProfileStarredMvp.View::onNotifyAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class RepoPagerPresenter extends BasePresenter<RepoPagerMvp.View> implements Rep

@Override public void onWorkOffline() {
if (!InputHelper.isEmpty(login()) && !InputHelper.isEmpty(repoId())) {
manageSubscription(RepoModel.getRepo(repoId)
manageSubscription(RxHelper.getObserver(RepoModel.getRepo(repoId))
.subscribe(repoModel -> {
repo = repoModel;
sendToView(view -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.fastaccess.data.dao.CommitModel;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.helper.InputHelper;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.BaseMvp;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
Expand Down Expand Up @@ -88,7 +89,7 @@ class RepoCommitsPresenter extends BasePresenter<RepoCommitsMvp.View> implements

@Override public void onWorkOffline() {
if (commits.isEmpty()) {
manageSubscription(CommitModel.getCommits(repoId, login)
manageSubscription(RxHelper.getObserver(CommitModel.getCommits(repoId, login))
.subscribe(models -> {
commits.addAll(models);
sendToView(RepoCommitsMvp.View::onNotifyAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.fastaccess.data.dao.CommitModel;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.helper.InputHelper;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;

Expand Down Expand Up @@ -55,7 +56,7 @@ class CommitPagerPresenter extends BasePresenter<CommitPagerMvp.View> implements
}

@Override public void onWorkOffline(@NonNull String sha, @NonNull String repoId, @NonNull String login) {
manageSubscription(CommitModel.getCommit(sha, repoId, login)
manageSubscription(RxHelper.getObserver(CommitModel.getCommit(sha, repoId, login))
.subscribe(commit -> {
commitModel = commit;
sendToView(CommitPagerMvp.View::onSetup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.fastaccess.data.dao.CommentsModel;
import com.fastaccess.data.dao.LoginModel;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;

Expand Down Expand Up @@ -88,7 +89,7 @@ class CommitCommentsPresenter extends BasePresenter<CommitCommentsMvp.View> impl

@Override public void onWorkOffline() {
if (comments.isEmpty()) {
manageSubscription(CommentsModel.getCommitComments(repoId(), login(), sha)
manageSubscription(RxHelper.getObserver(CommentsModel.getCommitComments(repoId(), login(), sha))
.subscribe(models -> {
if (models != null) {
comments.addAll(models);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.fastaccess.data.dao.UserModel;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.helper.InputHelper;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.BaseMvp;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
Expand Down Expand Up @@ -75,7 +76,7 @@ class RepoContributorsPresenter extends BasePresenter<RepoContributorsMvp.View>

@Override public void onWorkOffline() {
if (users.isEmpty()) {
manageSubscription(UserModel.getContributors(repoId)
manageSubscription(RxHelper.getObserver(UserModel.getContributors(repoId))
.subscribe(userModels -> {
users.addAll(userModels);
sendToView(RepoContributorsMvp.View::onNotifyAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.fastaccess.data.dao.RepoFilesModel;
import com.fastaccess.data.dao.RepoPathsManager;
import com.fastaccess.data.dao.types.FilesType;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;

Expand Down Expand Up @@ -52,7 +53,7 @@ class RepoFilesPresenter extends BasePresenter<RepoFilesMvp.View> implements Rep

@Override public void onWorkOffline() {
if ((repoId == null || login == null) || !files.isEmpty()) return;
manageSubscription(RepoFilesModel.getFiles(login, repoId).subscribe(
manageSubscription(RxHelper.getObserver(RepoFilesModel.getFiles(login, repoId)).subscribe(
models -> {
files.addAll(models);
sendToView(RepoFilesMvp.View::onNotifyAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.fastaccess.data.dao.MarkdownModel;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.helper.InputHelper;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.markdown.MarkDownProvider;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
Expand Down Expand Up @@ -69,7 +70,7 @@ class ViewerPresenter extends BasePresenter<ViewerMvp.View> implements ViewerMvp

@Override public void onWorkOffline() {
if (downloadedStream == null) {
manageSubscription(FileModel.get(url)
manageSubscription(RxHelper.getObserver(FileModel.get(url))
.subscribe(fileModel -> {
if (fileModel != null) {
isImage = MarkDownProvider.isImage(fileModel.getFullUrl());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.fastaccess.data.dao.ReleasesModel;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.helper.InputHelper;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;

Expand Down Expand Up @@ -84,7 +85,7 @@ class RepoReleasesPresenter extends BasePresenter<RepoReleasesMvp.View> implemen

@Override public void onWorkOffline() {
if (releases.isEmpty()) {
manageSubscription(ReleasesModel.get(repoId, login)
manageSubscription(RxHelper.getObserver(ReleasesModel.get(repoId, login))
.subscribe(releasesModels -> {
releases.addAll(releasesModels);
sendToView(RepoReleasesMvp.View::onNotifyAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.fastaccess.helper.Bundler;
import com.fastaccess.helper.InputHelper;
import com.fastaccess.helper.Logger;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.BaseMvp;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
Expand Down Expand Up @@ -91,7 +92,7 @@ class RepoIssuesPresenter extends BasePresenter<RepoIssuesMvp.View> implements R

@Override public void onWorkOffline() {
if (issues.isEmpty()) {
manageSubscription(IssueModel.getIssues(repoId, login, issueState)
manageSubscription(RxHelper.getObserver(IssueModel.getIssues(repoId, login, issueState))
.subscribe(issueModel -> {
issues.addAll(issueModel);
sendToView(RepoIssuesMvp.View::onNotifyAdapter);
Expand Down
Loading

0 comments on commit bd9c920

Please sign in to comment.