From c42d3cdd74545a21de809f81845f9c6d7975de42 Mon Sep 17 00:00:00 2001 From: Kosh Date: Wed, 1 Mar 2017 22:08:37 +0800 Subject: [PATCH] this commit fixes #49 for readme links and fixes #46 by showing confirm dialog first before forking. --- app/src/main/java/com/fastaccess/App.java | 1 - .../fastaccess/helper/ParseDateFormat.java | 1 - .../provider/markdown/MarkDownProvider.java | 3 +- .../provider/rest/RestProvider.java | 4 +- .../provider/scheme/SchemeParser.java | 22 +++--- .../provider/uil/UILImageGetter.java | 78 +++++++++++++++++++ .../ui/modules/repos/RepoPagerView.java | 13 +++- .../code/commit/details/CommitPagerMvp.java | 4 + .../commit/details/CommitPagerPresenter.java | 8 ++ .../code/commit/details/CommitPagerView.java | 4 + .../issues/issue/details/IssuePagerMvp.java | 4 + .../issue/details/IssuePagerPresenter.java | 8 ++ .../issues/issue/details/IssuePagerView.java | 4 + .../details/PullRequestPagerMvp.java | 8 +- .../details/PullRequestPagerPresenter.java | 8 ++ .../details/PullRequestPagerView.java | 22 +----- 16 files changed, 152 insertions(+), 40 deletions(-) create mode 100644 app/src/main/java/com/fastaccess/provider/uil/UILImageGetter.java diff --git a/app/src/main/java/com/fastaccess/App.java b/app/src/main/java/com/fastaccess/App.java index da4e121e2..b596aa827 100644 --- a/app/src/main/java/com/fastaccess/App.java +++ b/app/src/main/java/com/fastaccess/App.java @@ -17,7 +17,6 @@ public class App extends Application { private static App instance; - private AndDown andDown; @Override public void onCreate() { diff --git a/app/src/main/java/com/fastaccess/helper/ParseDateFormat.java b/app/src/main/java/com/fastaccess/helper/ParseDateFormat.java index 6aec4b4c1..f27529b9b 100644 --- a/app/src/main/java/com/fastaccess/helper/ParseDateFormat.java +++ b/app/src/main/java/com/fastaccess/helper/ParseDateFormat.java @@ -36,7 +36,6 @@ public String format(Date date) { public static CharSequence getTimeAgo(@Nullable Date parsedDate) { if (parsedDate != null) { long toLocalTime = parsedDate.getTime() + getInstance().timeZone.getRawOffset() + getInstance().timeZone.getDSTSavings(); - Logger.e(INSTANCE.timeZone.getID()); if (INSTANCE.timeZone.getID().equalsIgnoreCase("UTC")) { toLocalTime = parsedDate.getTime(); } diff --git a/app/src/main/java/com/fastaccess/provider/markdown/MarkDownProvider.java b/app/src/main/java/com/fastaccess/provider/markdown/MarkDownProvider.java index 68aa9c158..33f3a5566 100644 --- a/app/src/main/java/com/fastaccess/provider/markdown/MarkDownProvider.java +++ b/app/src/main/java/com/fastaccess/provider/markdown/MarkDownProvider.java @@ -11,6 +11,7 @@ import com.commonsware.cwac.anddown.AndDown; import com.fastaccess.App; import com.fastaccess.helper.InputHelper; +import com.fastaccess.provider.uil.UILImageGetter; /** * Created by Kosh on 24 Nov 2016, 7:43 PM @@ -42,7 +43,7 @@ public static void setMdText(@NonNull TextView textView, @NonNull String value) AndDown.HOEDOWN_EXT_SUPERSCRIPT | AndDown.HOEDOWN_EXT_DISABLE_INDENTED_CODE, 0); //noinspection deprecation - textView.setText(Html.fromHtml(text)); + textView.setText(Html.fromHtml(text, new UILImageGetter(textView), null)); } // public static RichText convertTextToMarkDown(@NonNull TextView textView, @NonNull String text) { diff --git a/app/src/main/java/com/fastaccess/provider/rest/RestProvider.java b/app/src/main/java/com/fastaccess/provider/rest/RestProvider.java index 43b53ac97..7bc07c39e 100644 --- a/app/src/main/java/com/fastaccess/provider/rest/RestProvider.java +++ b/app/src/main/java/com/fastaccess/provider/rest/RestProvider.java @@ -56,7 +56,7 @@ public class RestProvider { private static Cache provideCache() { if (cache == null) { - int cacheSize = 20 * 1024 * 1024; + int cacheSize = 20 * 1024 * 1024; //20MB cache = new Cache(App.getInstance().getCacheDir(), cacheSize); } return cache; @@ -86,7 +86,7 @@ private static OkHttpClient provideOkHttpClient(boolean forLogin) { Request request = requestBuilder.build(); return chain.proceed(request); }); -// client.cache(provideCache());//disable cache, since we are going offline. + client.cache(provideCache());//disable cache, since we are going offline. return client.build(); } diff --git a/app/src/main/java/com/fastaccess/provider/scheme/SchemeParser.java b/app/src/main/java/com/fastaccess/provider/scheme/SchemeParser.java index 1aec935ce..1ef1d7d83 100644 --- a/app/src/main/java/com/fastaccess/provider/scheme/SchemeParser.java +++ b/app/src/main/java/com/fastaccess/provider/scheme/SchemeParser.java @@ -10,7 +10,6 @@ import com.annimon.stream.Stream; import com.fastaccess.helper.ActivityHelper; import com.fastaccess.helper.InputHelper; -import com.fastaccess.helper.Logger; import com.fastaccess.ui.modules.code.CodeViewerView; import com.fastaccess.ui.modules.gists.gist.GistView; import com.fastaccess.ui.modules.repos.RepoPagerView; @@ -99,8 +98,6 @@ public static void launchUri(@NonNull Context context, @NonNull Uri data) { Optional empty = Optional.empty(); if (intentOptional != null && intentOptional.isPresent() && intentOptional != empty) { return intentOptional.get(); - } else { - return getGeneralRepo(context, data); } } return null; @@ -138,7 +135,6 @@ public static void launchUri(@NonNull Context context, @NonNull Uri data) { @Nullable private static Intent getIssueIntent(@NonNull Context context, @NonNull Uri uri) { List segments = uri.getPathSegments(); if (segments == null || segments.size() < 4) return null; - Logger.e(segments, segments.size()); String owner; String repo; String number; @@ -178,14 +174,16 @@ public static void launchUri(@NonNull Context context, @NonNull Uri data) { */ @Nullable private static Intent getGeneralRepo(@NonNull Context context, @NonNull Uri uri) { //TODO parse deeper links to their associate views. meantime fallback to repoPage - List segments = uri.getPathSegments(); - if (segments == null || segments.isEmpty()) return null; - if (segments.size() == 1) { - return getUser(context, uri); - } else if (segments.size() > 1) { - String owner = segments.get(0); - String repoName = segments.get(1); - return RepoPagerView.createIntent(context, repoName, owner); + if (uri.getAuthority().equals(HOST_DEFAULT) || uri.getAuthority().equals("api.github.com")) { + List segments = uri.getPathSegments(); + if (segments == null || segments.isEmpty()) return null; + if (segments.size() == 1) { + return getUser(context, uri); + } else if (segments.size() > 1) { + String owner = segments.get(0); + String repoName = segments.get(1); + return RepoPagerView.createIntent(context, repoName, owner); + } } return null; } diff --git a/app/src/main/java/com/fastaccess/provider/uil/UILImageGetter.java b/app/src/main/java/com/fastaccess/provider/uil/UILImageGetter.java new file mode 100644 index 000000000..8afb470a5 --- /dev/null +++ b/app/src/main/java/com/fastaccess/provider/uil/UILImageGetter.java @@ -0,0 +1,78 @@ +package com.fastaccess.provider.uil; + +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.support.v4.content.ContextCompat; +import android.text.Html; +import android.view.View; +import android.widget.TextView; + +import com.fastaccess.R; +import com.nostra13.universalimageloader.core.ImageLoader; +import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener; + +import java.io.InputStream; + +public class UILImageGetter implements Html.ImageGetter { + private TextView container; + + public UILImageGetter(TextView view) { + this.container = view; + } + + @Override public Drawable getDrawable(String source) { + UrlImageDownloader urlDrawable = new UrlImageDownloader(container.getResources(), source); + urlDrawable.drawable = ContextCompat.getDrawable(container.getContext(), R.drawable.ic_image); + ImageLoader.getInstance().loadImage(source, new SimpleListener(urlDrawable)); + return urlDrawable; + } + + private class SimpleListener extends SimpleImageLoadingListener { + UrlImageDownloader urlImageDownloader; + + public SimpleListener(UrlImageDownloader downloader) { + super(); + urlImageDownloader = downloader; + } + + @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { + int width = loadedImage.getWidth(); + int newWidth = width; + if (width > container.getWidth()) { + newWidth = container.getWidth(); + } + BitmapDrawable result = new BitmapDrawable(container.getResources(), loadedImage); + result.setBounds(0, 0, newWidth, loadedImage.getHeight()); + urlImageDownloader.setBounds(0, 0, newWidth, result.getIntrinsicHeight()); + urlImageDownloader.drawable = result; + container.requestLayout(); + container.invalidate(); + } + } + + private class UrlImageDownloader extends BitmapDrawable { + public Drawable drawable; + + public UrlImageDownloader(Resources res, InputStream is) { + super(res, is); + } + + public UrlImageDownloader(Resources res, String filepath) { + super(res, filepath); + drawable = new BitmapDrawable(res, filepath); + } + + public UrlImageDownloader(Resources res, Bitmap bitmap) { + super(res, bitmap); + } + + @Override public void draw(Canvas canvas) { + if (drawable != null) { + drawable.draw(canvas); + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/fastaccess/ui/modules/repos/RepoPagerView.java b/app/src/main/java/com/fastaccess/ui/modules/repos/RepoPagerView.java index 767fee87f..82b95db17 100644 --- a/app/src/main/java/com/fastaccess/ui/modules/repos/RepoPagerView.java +++ b/app/src/main/java/com/fastaccess/ui/modules/repos/RepoPagerView.java @@ -7,6 +7,7 @@ import android.graphics.Typeface; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; import android.view.Menu; import android.view.MenuItem; @@ -107,7 +108,9 @@ public class RepoPagerView extends BaseActivity implements })); } + @Override public String getLogin() { + return login; + } + + @Override public String getRepoId() { + return repoId; + } + } diff --git a/app/src/main/java/com/fastaccess/ui/modules/repos/code/commit/details/CommitPagerView.java b/app/src/main/java/com/fastaccess/ui/modules/repos/code/commit/details/CommitPagerView.java index ef6c626cb..6489235f7 100644 --- a/app/src/main/java/com/fastaccess/ui/modules/repos/code/commit/details/CommitPagerView.java +++ b/app/src/main/java/com/fastaccess/ui/modules/repos/code/commit/details/CommitPagerView.java @@ -152,6 +152,10 @@ public static void createIntentForOffline(@NonNull Context context, @NonNull Com hideShowFab(); } + @Override public void onBackPressed() { + super.onBackPressed(); + } + private void hideShowFab() { if (pager.getCurrentItem() == 1) { fab.show(); diff --git a/app/src/main/java/com/fastaccess/ui/modules/repos/issues/issue/details/IssuePagerMvp.java b/app/src/main/java/com/fastaccess/ui/modules/repos/issues/issue/details/IssuePagerMvp.java index b1bf6feba..fd1135feb 100644 --- a/app/src/main/java/com/fastaccess/ui/modules/repos/issues/issue/details/IssuePagerMvp.java +++ b/app/src/main/java/com/fastaccess/ui/modules/repos/issues/issue/details/IssuePagerMvp.java @@ -54,6 +54,10 @@ interface Presenter extends BaseMvp.FAPresenter { void onLoadLabels(); void onPutLabels(@NonNull ArrayList labels); + + String getLogin(); + + String getRepoId(); } } diff --git a/app/src/main/java/com/fastaccess/ui/modules/repos/issues/issue/details/IssuePagerPresenter.java b/app/src/main/java/com/fastaccess/ui/modules/repos/issues/issue/details/IssuePagerPresenter.java index 7eb18f621..b0d40749c 100644 --- a/app/src/main/java/com/fastaccess/ui/modules/repos/issues/issue/details/IssuePagerPresenter.java +++ b/app/src/main/java/com/fastaccess/ui/modules/repos/issues/issue/details/IssuePagerPresenter.java @@ -185,4 +185,12 @@ class IssuePagerPresenter extends BasePresenter implements I .map(LabelModel::getName).collect(Collectors.toList())), labelModels -> sendToView(view -> view.onLabelsAdded())); } + + @Override public String getLogin() { + return login; + } + + @Override public String getRepoId() { + return repoId; + } } diff --git a/app/src/main/java/com/fastaccess/ui/modules/repos/issues/issue/details/IssuePagerView.java b/app/src/main/java/com/fastaccess/ui/modules/repos/issues/issue/details/IssuePagerView.java index f07a60d6f..f170c5180 100644 --- a/app/src/main/java/com/fastaccess/ui/modules/repos/issues/issue/details/IssuePagerView.java +++ b/app/src/main/java/com/fastaccess/ui/modules/repos/issues/issue/details/IssuePagerView.java @@ -240,6 +240,10 @@ public static Intent createIntent(@NonNull Context context, @NonNull String repo getPresenter().onPutLabels(labels); } + @Override public void onBackPressed() { + super.onBackPressed(); + } + private void hideShowFab() { if (getPresenter().isLocked() && !getPresenter().isOwner()) { fab.hide(); diff --git a/app/src/main/java/com/fastaccess/ui/modules/repos/pull_requests/pull_request/details/PullRequestPagerMvp.java b/app/src/main/java/com/fastaccess/ui/modules/repos/pull_requests/pull_request/details/PullRequestPagerMvp.java index 005bd065c..a9d76a011 100644 --- a/app/src/main/java/com/fastaccess/ui/modules/repos/pull_requests/pull_request/details/PullRequestPagerMvp.java +++ b/app/src/main/java/com/fastaccess/ui/modules/repos/pull_requests/pull_request/details/PullRequestPagerMvp.java @@ -25,10 +25,6 @@ interface View extends BaseMvp.FAView, LabelsMvp.SelectedLabelsListener { void onSetupIssue(); - void showSuccessIssueActionMsg(boolean isClose); - - void showErrorIssueActionMsg(boolean isClose); - void onLabelsRetrieved(@NonNull List items); } @@ -59,6 +55,10 @@ interface Presenter extends BaseMvp.FAPresenter { void onLoadLabels(); void onPutLabels(@NonNull ArrayList labels); + + String getLogin(); + + String getRepoId(); } } diff --git a/app/src/main/java/com/fastaccess/ui/modules/repos/pull_requests/pull_request/details/PullRequestPagerPresenter.java b/app/src/main/java/com/fastaccess/ui/modules/repos/pull_requests/pull_request/details/PullRequestPagerPresenter.java index 403f485b9..5e6391d3c 100644 --- a/app/src/main/java/com/fastaccess/ui/modules/repos/pull_requests/pull_request/details/PullRequestPagerPresenter.java +++ b/app/src/main/java/com/fastaccess/ui/modules/repos/pull_requests/pull_request/details/PullRequestPagerPresenter.java @@ -188,4 +188,12 @@ class PullRequestPagerPresenter extends BasePresenter ); } } + + @Override public String getLogin() { + return login; + } + + @Override public String getRepoId() { + return repoId; + } } diff --git a/app/src/main/java/com/fastaccess/ui/modules/repos/pull_requests/pull_request/details/PullRequestPagerView.java b/app/src/main/java/com/fastaccess/ui/modules/repos/pull_requests/pull_request/details/PullRequestPagerView.java index 0dc932ddc..3d0aaed60 100644 --- a/app/src/main/java/com/fastaccess/ui/modules/repos/pull_requests/pull_request/details/PullRequestPagerView.java +++ b/app/src/main/java/com/fastaccess/ui/modules/repos/pull_requests/pull_request/details/PullRequestPagerView.java @@ -185,24 +185,6 @@ public static Intent createIntent(@NonNull Context context, @NonNull String repo hideShowFab(); } - @Override public void showSuccessIssueActionMsg(boolean isClose) { - hideProgress(); - if (isClose) { - showMessage(getString(R.string.success), getString(R.string.success_closed)); - } else { - showMessage(getString(R.string.success), getString(R.string.success_re_opened)); - } - } - - @Override public void showErrorIssueActionMsg(boolean isClose) { - hideProgress(); - if (isClose) { - showMessage(getString(R.string.error), getString(R.string.error_closing_issue)); - } else { - showMessage(getString(R.string.error), getString(R.string.error_re_opening_issue)); - } - } - @Override public void onMessageDialogActionClicked(boolean isOk, @Nullable Bundle bundle) { super.onMessageDialogActionClicked(isOk, bundle); if (isOk) { @@ -221,6 +203,10 @@ public static Intent createIntent(@NonNull Context context, @NonNull String repo getPresenter().onPutLabels(labels); } + @Override public void onBackPressed() { + super.onBackPressed(); + } + private void hideShowFab() { if (getPresenter().isLocked() && !getPresenter().isOwner()) { fab.hide();