mirror of
https://github.com/k0shk0sh/FastHub.git
synced 2025-12-08 19:05:54 +00:00
proper urls handling.
This commit is contained in:
parent
5818184fda
commit
e62c044e9d
@ -1,6 +1,5 @@
|
||||
package com.fastaccess.provider.scheme;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
@ -11,6 +10,7 @@ import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import com.annimon.stream.Collectors;
|
||||
import com.annimon.stream.Optional;
|
||||
import com.annimon.stream.Stream;
|
||||
import com.fastaccess.helper.ActivityHelper;
|
||||
@ -25,6 +25,7 @@ import com.fastaccess.ui.modules.repos.issues.issue.details.IssuePagerView;
|
||||
import com.fastaccess.ui.modules.repos.pull_requests.pull_request.details.PullRequestPagerView;
|
||||
import com.fastaccess.ui.modules.user.UserPagerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -38,6 +39,10 @@ public class SchemeParser {
|
||||
private static final String API_AUTHORITY = "api.github.com";
|
||||
private static final String PROTOCOL_HTTPS = "https";
|
||||
|
||||
static final ArrayList<String> IGNORED_LIST = Stream.of("notifications", "/settings", "blog", "explore",
|
||||
"dashboard", "repositories", "site", "security", "contact", "about", "orgs", "")
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
public static void launchUri(@NonNull Context context, @NonNull Uri data) {
|
||||
launchUri(context, data, false);
|
||||
}
|
||||
@ -50,12 +55,7 @@ public class SchemeParser {
|
||||
}
|
||||
context.startActivity(intent);
|
||||
} else {
|
||||
Activity activity = ActivityHelper.getActivity(context);
|
||||
if (activity == null) {
|
||||
ActivityHelper.forceOpenInBrowser(context, data);
|
||||
} else {
|
||||
ActivityHelper.startCustomTab(activity, data);
|
||||
}
|
||||
ActivityHelper.forceOpenInBrowser(context, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,7 +78,12 @@ public class SchemeParser {
|
||||
data = Uri.parse(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.getPathSegments().isEmpty()) {
|
||||
Logger.e(SchemeParser.IGNORED_LIST.contains(data.getPath()), data.getPathSegments().get(0));
|
||||
if (SchemeParser.IGNORED_LIST.contains(data.getPathSegments().get(0))) return null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return getIntentForURI(context, data, showRepoBtn);
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.fastaccess.provider.scheme;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
@ -28,8 +27,6 @@ import com.fastaccess.ui.modules.user.UserPagerView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static android.content.Intent.ACTION_VIEW;
|
||||
|
||||
/**
|
||||
* Created by Kosh on 09 Dec 2016, 4:44 PM
|
||||
*/
|
||||
@ -52,22 +49,10 @@ public class StackBuilderSchemeParser {
|
||||
if (intent != null) {
|
||||
intent.startActivities();
|
||||
} else {
|
||||
Activity activity = ActivityHelper.getActivity(context);
|
||||
if (activity == null) {
|
||||
ActivityHelper.forceOpenInBrowser(context, data);
|
||||
} else {
|
||||
ActivityHelper.startCustomTab(activity, data);
|
||||
}
|
||||
ActivityHelper.forceOpenInBrowser(context, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable private static TaskStackBuilder convert(@NonNull Context context, final Intent intent) {
|
||||
if (intent == null) return null;
|
||||
if (!ACTION_VIEW.equals(intent.getAction())) return null;
|
||||
Uri data = intent.getData();
|
||||
return convert(context, data);
|
||||
}
|
||||
|
||||
@Nullable private static TaskStackBuilder convert(@NonNull Context context, Uri data) {
|
||||
if (data == null) return null;
|
||||
if (InputHelper.isEmpty(data.getHost()) || InputHelper.isEmpty(data.getScheme())) {
|
||||
@ -87,7 +72,12 @@ public class StackBuilderSchemeParser {
|
||||
data = Uri.parse(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.getPathSegments().isEmpty()) {
|
||||
Logger.e(SchemeParser.IGNORED_LIST.contains(data.getPath()), data.getPathSegments().get(0));
|
||||
if (SchemeParser.IGNORED_LIST.contains(data.getPathSegments().get(0))) return null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return getIntentForURI(context, data);
|
||||
}
|
||||
|
||||
@ -197,6 +187,7 @@ public class StackBuilderSchemeParser {
|
||||
.addNextIntentWithParentStack(new Intent(context, MainView.class))
|
||||
.addNextIntent(RepoPagerView.createIntent(context, repoName, owner));
|
||||
}
|
||||
|
||||
/**
|
||||
* [[k0shk0sh, FastHub, issues], k0shk0sh/fastHub/(issues,pulls,commits, etc)]
|
||||
*/
|
||||
@ -208,7 +199,6 @@ public class StackBuilderSchemeParser {
|
||||
if (segments.size() == 1) {
|
||||
return getUser(context, uri);
|
||||
} else if (segments.size() > 1) {
|
||||
if (segments.contains("wiki")) return null;
|
||||
String owner = segments.get(0);
|
||||
String repoName = segments.get(1);
|
||||
return TaskStackBuilder.create(context)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user