mirror of
https://github.com/k0shk0sh/FastHub.git
synced 2025-12-08 19:05:54 +00:00
better way of handling links, now ensuring that link is coming from github before opening it anywhere in the app.
This commit is contained in:
parent
64f4a51998
commit
4f786e6c19
@ -1,7 +1,6 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'me.tatarka.retrolambda'
|
||||
apply plugin: "com.neenbedankt.android-apt"
|
||||
apply plugin: 'com.jakewharton.hugo'
|
||||
apply plugin: 'com.siimkinks.sqlitemagic'
|
||||
apply plugin: 'com.google.firebase.firebase-crash'
|
||||
|
||||
|
||||
@ -44,17 +44,17 @@
|
||||
<activity
|
||||
android:name=".ui.modules.user.UserPagerView"
|
||||
android:label="@string/user"
|
||||
android:noHistory="true"/>
|
||||
android:excludeFromRecents="true"/>
|
||||
|
||||
<activity
|
||||
android:name=".ui.modules.repos.RepoPagerView"
|
||||
android:label="@string/repo"
|
||||
android:noHistory="true"/>
|
||||
android:excludeFromRecents="true"/>
|
||||
|
||||
<activity
|
||||
android:name=".ui.modules.repos.issues.issue.details.IssuePagerView"
|
||||
android:label="@string/issue"
|
||||
android:noHistory="true"/>
|
||||
android:excludeFromRecents="true"/>
|
||||
<activity
|
||||
android:name=".ui.modules.repos.issues.create.CreateIssueView"
|
||||
android:configChanges="keyboard|orientation|screenSize"
|
||||
@ -64,18 +64,18 @@
|
||||
<activity
|
||||
android:name=".ui.modules.repos.pull_requests.pull_request.details.PullRequestPagerView"
|
||||
android:label="@string/pull_request"
|
||||
android:noHistory="true"/>
|
||||
android:excludeFromRecents="true"/>
|
||||
|
||||
<activity
|
||||
android:name=".ui.modules.repos.code.commit.details.CommitPagerView"
|
||||
android:label="@string/commit"
|
||||
android:noHistory="true"/>
|
||||
android:excludeFromRecents="true"/>
|
||||
|
||||
<activity
|
||||
android:name=".ui.modules.code.CodeViewerView"
|
||||
android:configChanges="keyboard|orientation|screenSize"
|
||||
android:label="@string/viewer"
|
||||
android:noHistory="true"/>
|
||||
android:excludeFromRecents="true"/>
|
||||
|
||||
<activity
|
||||
android:name=".ui.modules.editor.EditorView"
|
||||
@ -92,14 +92,14 @@
|
||||
<activity
|
||||
android:name=".ui.modules.gists.gist.GistView"
|
||||
android:label="@string/gist"
|
||||
android:noHistory="true"/>
|
||||
android:excludeFromRecents="true"/>
|
||||
|
||||
<activity android:name=".ui.modules.search.SearchView"/>
|
||||
|
||||
<activity
|
||||
android:name=".ui.modules.notification.NotificationActivityView"
|
||||
android:label="@string/notifictions"
|
||||
android:noHistory="true"/>
|
||||
android:excludeFromRecents="true"/>
|
||||
|
||||
<activity
|
||||
android:name=".ui.modules.parser.LinksParserActivity"
|
||||
|
||||
@ -5,6 +5,7 @@ import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.annimon.stream.Optional;
|
||||
import com.annimon.stream.Stream;
|
||||
@ -29,6 +30,8 @@ import static android.content.Intent.ACTION_VIEW;
|
||||
public class SchemeParser {
|
||||
private static final String HOST_DEFAULT = "github.com";
|
||||
private static final String HOST_GISTS = "gist.github.com";
|
||||
private static final String RAW_AUTHORITY = "raw.githubusercontent.com";
|
||||
private static final String API_AUTHORITY = "api.github.com";
|
||||
private static final String PROTOCOL_HTTPS = "https";
|
||||
|
||||
public static void launchUri(@NonNull Context context, @NonNull Intent data) {
|
||||
@ -86,18 +89,24 @@ public class SchemeParser {
|
||||
return GistView.createIntent(context, gist);
|
||||
}
|
||||
} else {
|
||||
Intent userIntent = getUser(context, data);
|
||||
Intent pullRequestIntent = getPullRequestIntent(context, data);
|
||||
Intent issueIntent = getIssueIntent(context, data);
|
||||
Intent repoIntent = getRepo(context, data);
|
||||
Intent commit = getCommit(context, data);
|
||||
Intent commits = getCommits(context, data);
|
||||
Intent blob = getBlob(context, data);
|
||||
Optional<Intent> intentOptional = returnNonNull(userIntent, pullRequestIntent, commit, commits,
|
||||
issueIntent, repoIntent, blob);
|
||||
Optional<Intent> empty = Optional.empty();
|
||||
if (intentOptional != null && intentOptional.isPresent() && intentOptional != empty) {
|
||||
return intentOptional.get();
|
||||
String authority = data.getAuthority();
|
||||
if (TextUtils.equals(authority, HOST_DEFAULT) || TextUtils.equals(authority, RAW_AUTHORITY) ||
|
||||
TextUtils.equals(authority, API_AUTHORITY)) {
|
||||
Intent userIntent = getUser(context, data);
|
||||
Intent pullRequestIntent = getPullRequestIntent(context, data);
|
||||
Intent issueIntent = getIssueIntent(context, data);
|
||||
Intent repoIntent = getRepo(context, data);
|
||||
Intent commit = getCommit(context, data);
|
||||
Intent commits = getCommits(context, data);
|
||||
Intent blob = getBlob(context, data);
|
||||
Optional<Intent> intentOptional = returnNonNull(userIntent, pullRequestIntent, commit, commits,
|
||||
issueIntent, repoIntent, blob);
|
||||
Optional<Intent> empty = Optional.empty();
|
||||
if (intentOptional != null && intentOptional.isPresent() && intentOptional != empty) {
|
||||
return intentOptional.get();
|
||||
} else {
|
||||
return getGeneralRepo(context, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -174,7 +183,7 @@ public class SchemeParser {
|
||||
*/
|
||||
@Nullable private static Intent getGeneralRepo(@NonNull Context context, @NonNull Uri uri) {
|
||||
//TODO parse deeper links to their associate views. meantime fallback to repoPage
|
||||
if (uri.getAuthority().equals(HOST_DEFAULT) || uri.getAuthority().equals("api.github.com")) {
|
||||
if (uri.getAuthority().equals(HOST_DEFAULT) || uri.getAuthority().equals(API_AUTHORITY)) {
|
||||
List<String> segments = uri.getPathSegments();
|
||||
if (segments == null || segments.isEmpty()) return null;
|
||||
if (segments.size() == 1) {
|
||||
@ -229,10 +238,15 @@ public class SchemeParser {
|
||||
if (segmentTwo.equals("blob") || segmentTwo.equals("tree")) {
|
||||
String fullUrl = uri.toString();
|
||||
if (uri.getAuthority().equalsIgnoreCase(HOST_DEFAULT)) {
|
||||
fullUrl = "https://raw.githubusercontent.com/" + segments.get(0) + "/" + segments.get(1) + "/" +
|
||||
fullUrl = "https://" + RAW_AUTHORITY + "/" + segments.get(0) + "/" + segments.get(1) + "/" +
|
||||
segments.get(segments.size() - 2) + "/" + uri.getLastPathSegment();
|
||||
}
|
||||
if (fullUrl != null) return CodeViewerView.createIntent(context, fullUrl);
|
||||
} else {
|
||||
String authority = uri.getAuthority();
|
||||
if (TextUtils.equals(authority, RAW_AUTHORITY)) {
|
||||
return CodeViewerView.createIntent(context, uri.toString());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -15,8 +15,6 @@ import com.fastaccess.ui.modules.feeds.FeedsView;
|
||||
import com.fastaccess.ui.modules.gists.GistsView;
|
||||
import com.fastaccess.ui.modules.profile.ProfilePagerView;
|
||||
|
||||
import hugo.weaving.DebugLog;
|
||||
|
||||
import static com.fastaccess.helper.ActivityHelper.getVisibleFragment;
|
||||
import static com.fastaccess.helper.AppHelper.getFragmentByTag;
|
||||
|
||||
@ -30,7 +28,7 @@ class MainPresenter extends BasePresenter<MainMvp.View> implements MainMvp.Prese
|
||||
return !drawerLayout.isDrawerOpen(GravityCompat.START);
|
||||
}
|
||||
|
||||
@DebugLog @SuppressWarnings("ConstantConditions")
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Override public void onModuleChanged(@NonNull FragmentManager fragmentManager, @MainMvp.NavigationType int type) {
|
||||
Fragment currentVisible = getVisibleFragment(fragmentManager);
|
||||
FeedsView homeView = (FeedsView) getFragmentByTag(fragmentManager, FeedsView.TAG);
|
||||
@ -61,7 +59,7 @@ class MainPresenter extends BasePresenter<MainMvp.View> implements MainMvp.Prese
|
||||
}
|
||||
}
|
||||
|
||||
@DebugLog @Override public void onShowHideFragment(@NonNull FragmentManager fragmentManager, @NonNull Fragment toShow, @NonNull Fragment toHide) {
|
||||
@Override public void onShowHideFragment(@NonNull FragmentManager fragmentManager, @NonNull Fragment toShow, @NonNull Fragment toHide) {
|
||||
toHide.onHiddenChanged(true);
|
||||
fragmentManager
|
||||
.beginTransaction()
|
||||
@ -71,7 +69,7 @@ class MainPresenter extends BasePresenter<MainMvp.View> implements MainMvp.Prese
|
||||
toShow.onHiddenChanged(false);
|
||||
}
|
||||
|
||||
@DebugLog @Override public void onAddAndHide(@NonNull FragmentManager fragmentManager, @NonNull Fragment toAdd, @NonNull Fragment toHide) {
|
||||
@Override public void onAddAndHide(@NonNull FragmentManager fragmentManager, @NonNull Fragment toAdd, @NonNull Fragment toHide) {
|
||||
toHide.onHiddenChanged(true);
|
||||
fragmentManager
|
||||
.beginTransaction()
|
||||
@ -90,7 +88,7 @@ class MainPresenter extends BasePresenter<MainMvp.View> implements MainMvp.Prese
|
||||
} else if (item.getItemId() == R.id.logout) {
|
||||
getView().onLogout();
|
||||
return true;
|
||||
}else if(item.getItemId() == R.id.fhRepo){
|
||||
} else if (item.getItemId() == R.id.fhRepo) {
|
||||
getView().openFasHubRepo();
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +38,6 @@ import butterknife.BindColor;
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.OnLongClick;
|
||||
import hugo.weaving.DebugLog;
|
||||
import icepick.State;
|
||||
import it.sephiroth.android.library.bottomnavigation.BottomNavigation;
|
||||
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
|
||||
@ -63,13 +62,13 @@ public class RepoPagerView extends BaseActivity<RepoPagerMvp.View, RepoPagerPres
|
||||
@State @RepoPagerMvp.RepoNavigationType int navType;
|
||||
private NumberFormat numberFormat = NumberFormat.getNumberInstance();
|
||||
|
||||
@DebugLog public static void startRepoPager(@NonNull Context context, @NonNull NameParser nameParser) {
|
||||
public static void startRepoPager(@NonNull Context context, @NonNull NameParser nameParser) {
|
||||
if (!InputHelper.isEmpty(nameParser.getName()) && !InputHelper.isEmpty(nameParser.getUsername())) {
|
||||
context.startActivity(createIntent(context, nameParser.getName(), nameParser.getUsername()));
|
||||
}
|
||||
}
|
||||
|
||||
@DebugLog public static Intent createIntent(@NonNull Context context, @NonNull String repoId, @NonNull String login) {
|
||||
public static Intent createIntent(@NonNull Context context, @NonNull String repoId, @NonNull String login) {
|
||||
Intent intent = new Intent(context, RepoPagerView.class);
|
||||
intent.putExtras(Bundler.start()
|
||||
.put(BundleConstant.ID, repoId)
|
||||
|
||||
@ -18,7 +18,6 @@ import com.fastaccess.ui.widgets.StateLayout;
|
||||
import com.fastaccess.ui.widgets.recyclerview.DynamicRecyclerView;
|
||||
|
||||
import butterknife.BindView;
|
||||
import hugo.weaving.DebugLog;
|
||||
import icepick.State;
|
||||
|
||||
/**
|
||||
@ -74,7 +73,7 @@ public class CommitFilesView extends BaseFragment<CommitFilesMvp.View, CommitFil
|
||||
adapter.notifyItemChanged(position);
|
||||
}
|
||||
|
||||
@DebugLog @Override public boolean isCollapsed(int position) {
|
||||
@Override public boolean isCollapsed(int position) {
|
||||
return getSparseBooleanArray().get(position);
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@ import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
import com.fastaccess.helper.InputHelper;
|
||||
import com.fastaccess.helper.Logger;
|
||||
import com.fastaccess.provider.markdown.MarkDownProvider;
|
||||
import com.fastaccess.provider.scheme.SchemeParser;
|
||||
import com.fastaccess.ui.modules.code.CodeViewerView;
|
||||
@ -138,16 +139,9 @@ public class PrettifyWebView extends NestedWebView {
|
||||
}
|
||||
}
|
||||
|
||||
private class WebClient extends WebViewClient {
|
||||
@Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
||||
startActivity(request.getUrl());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void startActivity(Uri url) {
|
||||
if (url == null) return;
|
||||
Logger.e(url);
|
||||
if (MarkDownProvider.isImage(url.toString())) {
|
||||
CodeViewerView.startActivity(getContext(), url.toString());
|
||||
} else {
|
||||
@ -155,6 +149,13 @@ public class PrettifyWebView extends NestedWebView {
|
||||
}
|
||||
}
|
||||
|
||||
private class WebClient extends WebViewClient {
|
||||
@Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
||||
startActivity(request.getUrl());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class WebClientCompat extends WebViewClient {
|
||||
@SuppressWarnings("deprecation") @Override public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
startActivity(Uri.parse(url));
|
||||
|
||||
@ -3,10 +3,8 @@ package com.prettifier.pretty.helper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.fastaccess.BuildConfig;
|
||||
import com.fastaccess.data.dao.NameParser;
|
||||
import com.fastaccess.helper.Logger;
|
||||
import com.fastaccess.provider.markdown.MarkDownProvider;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -51,17 +49,10 @@ public class GithubHelper {
|
||||
Matcher matcher = LINK_TAG_MATCHER.matcher(source);
|
||||
while (matcher.find()) {
|
||||
String href = matcher.group(1).trim();
|
||||
if (href.startsWith("#") || href.startsWith("http://") || href.startsWith("https://") || href.startsWith("mailto:")) {
|
||||
if (href.startsWith("http://") || href.startsWith("https://") || href.startsWith("mailto:")) {
|
||||
continue;
|
||||
}
|
||||
Logger.e(href);
|
||||
boolean isImage = MarkDownProvider.isImage(href);
|
||||
String link;
|
||||
if (isImage) {
|
||||
link = "https://raw.githubusercontent.com/" + owner + "/" + repoName + "/master/" + href;
|
||||
} else {
|
||||
link = BuildConfig.REST_URL + "repos/" + owner + "/" + repoName + "/contents/" + href;
|
||||
}
|
||||
String link = "https://raw.githubusercontent.com/" + owner + "/" + repoName + "/master/" + href;
|
||||
source = source.replace("href=\"" + href + "\"", "href=\"" + link + "\"");
|
||||
}
|
||||
return source;
|
||||
|
||||
@ -11,7 +11,6 @@ buildscript {
|
||||
classpath 'com.google.gms:google-services:3.0.0'
|
||||
classpath 'me.tatarka:gradle-retrolambda:3.2.4'
|
||||
classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2'
|
||||
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
|
||||
classpath 'com.siimkinks.sqlitemagic:sqlitemagic-plugin:0.11.0'
|
||||
classpath 'com.google.firebase:firebase-plugins:1.0.5'
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user