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

Commit

Permalink
this commit fixes #49 for readme links and fixes #46 by showing confi…
Browse files Browse the repository at this point in the history
…rm dialog first before forking.
  • Loading branch information
Kosh committed Mar 1, 2017
1 parent 60cb930 commit c42d3cd
Show file tree
Hide file tree
Showing 16 changed files with 152 additions and 40 deletions.
1 change: 0 additions & 1 deletion app/src/main/java/com/fastaccess/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

public class App extends Application {
private static App instance;

private AndDown andDown;

@Override public void onCreate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
22 changes: 10 additions & 12 deletions app/src/main/java/com/fastaccess/provider/scheme/SchemeParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,8 +98,6 @@ public static void launchUri(@NonNull Context context, @NonNull Uri data) {
Optional<Intent> empty = Optional.empty();
if (intentOptional != null && intentOptional.isPresent() && intentOptional != empty) {
return intentOptional.get();
} else {
return getGeneralRepo(context, data);
}
}
return null;
Expand Down Expand Up @@ -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<String> segments = uri.getPathSegments();
if (segments == null || segments.size() < 4) return null;
Logger.e(segments, segments.size());
String owner;
String repo;
String number;
Expand Down Expand Up @@ -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<String> 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<String> 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;
}
Expand Down
78 changes: 78 additions & 0 deletions app/src/main/java/com/fastaccess/provider/uil/UILImageGetter.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,7 +108,9 @@ public class RepoPagerView extends BaseActivity<RepoPagerMvp.View, RepoPagerPres
@OnClick({R.id.forkRepo, R.id.starRepo, R.id.watchRepo}) public void onClick(View view) {
switch (view.getId()) {
case R.id.forkRepo:
getPresenter().onFork();
MessageDialogView.newInstance(getString(R.string.fork), getString(R.string.confirm_message),
Bundler.start().put(BundleConstant.EXTRA, true).end())
.show(getSupportFragmentManager(), MessageDialogView.TAG);
break;
case R.id.starRepo:
getPresenter().onStar();
Expand Down Expand Up @@ -293,6 +296,14 @@ public class RepoPagerView extends BaseActivity<RepoPagerMvp.View, RepoPagerPres
return super.onOptionsItemSelected(item);
}

@Override public void onMessageDialogActionClicked(boolean isOk, @Nullable Bundle bundle) {
super.onMessageDialogActionClicked(isOk, bundle);
if (isOk && bundle != null) {
boolean fork = bundle.getBoolean(BundleConstant.EXTRA);
if (fork) getPresenter().onFork();
}
}

@Override public void onBackPressed() {
if (navType == RepoPagerMvp.CODE) {
RepoCodePagerView codePagerView = (RepoCodePagerView) AppHelper.getFragmentByTag(getSupportFragmentManager(), RepoCodePagerView.TAG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ interface Presenter extends BaseMvp.FAPresenter {

void onWorkOffline(@NonNull String sha, @NonNull String repoId, @NonNull String login);

String getLogin();

String getRepoId();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,12 @@ class CommitPagerPresenter extends BasePresenter<CommitPagerMvp.View> implements
}));
}

@Override public String getLogin() {
return login;
}

@Override public String getRepoId() {
return repoId;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ interface Presenter extends BaseMvp.FAPresenter {
void onLoadLabels();

void onPutLabels(@NonNull ArrayList<LabelModel> labels);

String getLogin();

String getRepoId();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,12 @@ class IssuePagerPresenter extends BasePresenter<IssuePagerMvp.View> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<LabelModel> items);
}

Expand Down Expand Up @@ -59,6 +55,10 @@ interface Presenter extends BaseMvp.FAPresenter {
void onLoadLabels();

void onPutLabels(@NonNull ArrayList<LabelModel> labels);

String getLogin();

String getRepoId();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,12 @@ class PullRequestPagerPresenter extends BasePresenter<PullRequestPagerMvp.View>
);
}
}

@Override public String getLogin() {
return login;
}

@Override public String getRepoId() {
return repoId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down

0 comments on commit c42d3cd

Please sign in to comment.