diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-08-15 08:25:20 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-08-15 08:25:20 +0000 |
commit | 2c6ca51e5c772f30490a35bf73305b43eef91b56 (patch) | |
tree | a4f531938c172bb1776811f217799be0ec33a224 /app/src | |
parent | 478b85e67b1798ab6b0bdc4392785c40fe1c1307 (diff) | |
download | infinity-for-reddit-2c6ca51e5c772f30490a35bf73305b43eef91b56.tar infinity-for-reddit-2c6ca51e5c772f30490a35bf73305b43eef91b56.tar.gz infinity-for-reddit-2c6ca51e5c772f30490a35bf73305b43eef91b56.tar.bz2 infinity-for-reddit-2c6ca51e5c772f30490a35bf73305b43eef91b56.tar.lz infinity-for-reddit-2c6ca51e5c772f30490a35bf73305b43eef91b56.tar.xz infinity-for-reddit-2c6ca51e5c772f30490a35bf73305b43eef91b56.tar.zst infinity-for-reddit-2c6ca51e5c772f30490a35bf73305b43eef91b56.zip |
Handle invalid uri when opening in Custom Tabs.
Diffstat (limited to 'app/src')
5 files changed, 70 insertions, 7 deletions
diff --git a/app/src/main/java/CustomView/CustomMarkwonView.java b/app/src/main/java/CustomView/CustomMarkwonView.java index da6b2f55..d5828f13 100644 --- a/app/src/main/java/CustomView/CustomMarkwonView.java +++ b/app/src/main/java/CustomView/CustomMarkwonView.java @@ -44,7 +44,11 @@ public class CustomMarkwonView extends MarkwonView { if(uri.getHost() != null && uri.getHost().contains("reddit.com")) { customTabsIntent.intent.setPackage(context.getPackageName()); } - customTabsIntent.launchUrl(context, uri); + String uriString = uri.toString(); + if(!uriString.startsWith("http://") && (!uriString.startsWith("https://"))) { + uriString = "http://" + uriString; + } + customTabsIntent.launchUrl(context, Uri.parse(uriString)); } }).build(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java index 5ecc81df..9816946c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java @@ -374,7 +374,15 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie builder.addDefaultShareMenuItem(); builder.setToolbarColor(mActivity.getResources().getColor(R.color.colorPrimary)); CustomTabsIntent customTabsIntent = builder.build(); - customTabsIntent.launchUrl(mActivity, Uri.parse(mPost.getUrl())); + Uri uri = Uri.parse(mPost.getUrl()); + if(uri.getHost() != null && uri.getHost().contains("reddit.com")) { + customTabsIntent.intent.setPackage(mActivity.getPackageName()); + } + String uriString = mPost.getUrl(); + if(!uriString.startsWith("http://") && !uriString.startsWith("https://")) { + uriString = "http://" + uriString; + } + customTabsIntent.launchUrl(mActivity, Uri.parse(uriString)); }); break; case Post.GIF_VIDEO_TYPE: @@ -431,7 +439,15 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie builder.addDefaultShareMenuItem(); builder.setToolbarColor(mActivity.getResources().getColor(R.color.colorPrimary)); CustomTabsIntent customTabsIntent = builder.build(); - customTabsIntent.launchUrl(mActivity, Uri.parse(mPost.getUrl())); + Uri uri = Uri.parse(mPost.getUrl()); + if(uri.getHost() != null && uri.getHost().contains("reddit.com")) { + customTabsIntent.intent.setPackage(mActivity.getPackageName()); + } + String uriString = mPost.getUrl(); + if(!uriString.startsWith("http://") && !uriString.startsWith("https://")) { + uriString = "http://" + uriString; + } + customTabsIntent.launchUrl(mActivity, Uri.parse(uriString)); }); break; case Post.TEXT_TYPE: @@ -451,6 +467,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie comment = mVisibleComments.get(holder.getAdapterPosition() - 1); } + if(mIsSingleCommentThreadMode && comment.getId().equals(mSingleCommentId)) { + ((CommentViewHolder) holder).itemView.setBackgroundColor( + mActivity.getResources().getColor(R.color.singleCommentThreadBackgroundColor)); + } + String authorPrefixed = "u/" + comment.getAuthor(); ((CommentViewHolder) holder).authorTextView.setText(authorPrefixed); @@ -722,6 +743,8 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie ((CommentViewHolder) holder).expandButton.setVisibility(View.GONE); ((CommentViewHolder) holder).upVoteButton.clearColorFilter(); ((CommentViewHolder) holder).downVoteButton.clearColorFilter(); + ((CommentViewHolder) holder).itemView.setBackgroundColor( + mActivity.getResources().getColor(R.color.cardViewBackgroundColor)); } } @@ -1297,6 +1320,8 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie itemView.setOnClickListener(view -> { if(mActivity != null && mActivity instanceof ViewPostDetailActivity) { + mIsSingleCommentThreadMode = false; + mSingleCommentId = null; ((ViewPostDetailActivity) mActivity).changeToSingleThreadMode(); } }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/LinkResolverActivity.java index 8df02968..a091cef0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/LinkResolverActivity.java @@ -17,7 +17,8 @@ import static androidx.browser.customtabs.CustomTabsService.ACTION_CUSTOM_TABS_C public class LinkResolverActivity extends AppCompatActivity { - private static final String POST_PATTERN = "/r/\\w+/comments/\\w+/*[\\w+]*/*"; + private static final String POST_PATTERN = "/r/\\w+/comments/\\w+/{0,1}\\w+/{0,1}"; + private static final String COMMENT_PATTERN = "/r/\\w+/comments/\\w+/{0,1}\\w+/\\w+/{0,1}"; private static final String SUBREDDIT_PATTERN = "/r/\\w+/*"; private static final String USER_PATTERN = "/user/\\w+/*"; @@ -41,6 +42,17 @@ public class LinkResolverActivity extends AppCompatActivity { } else { deepLinkError(uri); } + } else if(path.matches(COMMENT_PATTERN)) { + List<String> segments = uri.getPathSegments(); + int commentsIndex = segments.lastIndexOf("comments"); + if(commentsIndex >=0 && commentsIndex < segments.size() - 1) { + Intent intent = new Intent(this, ViewPostDetailActivity.class); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1)); + intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, segments.get(segments.size() - 1)); + startActivity(intent); + } else { + deepLinkError(uri); + } } else if(path.matches(SUBREDDIT_PATTERN)) { String subredditName = path.substring(3); if(subredditName.equals("popular") || subredditName.equals("all")) { @@ -73,7 +85,11 @@ public class LinkResolverActivity extends AppCompatActivity { builder.setToolbarColor(getResources().getColor(R.color.colorPrimary)); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.intent.setPackage(resolveInfos.get(0).activityInfo.packageName); - customTabsIntent.launchUrl(this, uri); + String uriString = uri.toString(); + if(!uriString.startsWith("http://") || (!uriString.startsWith("https://"))) { + uriString = "http://" + uriString; + } + customTabsIntent.launchUrl(this, Uri.parse(uriString)); } else { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(uri); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index 07b620ca..239bf8c0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -390,7 +390,15 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo builder.addDefaultShareMenuItem(); builder.setToolbarColor(mContext.getResources().getColor(R.color.colorPrimary)); CustomTabsIntent customTabsIntent = builder.build(); - customTabsIntent.launchUrl(mContext, Uri.parse(post.getUrl())); + Uri uri = Uri.parse(post.getUrl()); + if(uri.getHost() != null && uri.getHost().contains("reddit.com")) { + customTabsIntent.intent.setPackage(mContext.getPackageName()); + } + String uriString = post.getUrl(); + if(!uriString.startsWith("http://") && !uriString.startsWith("https://")) { + uriString = "http://" + uriString; + } + customTabsIntent.launchUrl(mContext, Uri.parse(uriString)); }); break; case Post.GIF_VIDEO_TYPE: @@ -443,7 +451,15 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo builder.addDefaultShareMenuItem(); builder.setToolbarColor(mContext.getResources().getColor(R.color.colorPrimary)); CustomTabsIntent customTabsIntent = builder.build(); - customTabsIntent.launchUrl(mContext, Uri.parse(noPreviewLinkUrl)); + Uri uri = Uri.parse(post.getUrl()); + if(uri.getHost() != null && uri.getHost().contains("reddit.com")) { + customTabsIntent.intent.setPackage(mContext.getPackageName()); + } + String uriString = noPreviewLinkUrl; + if(!uriString.startsWith("http://") && !uriString.startsWith("https://")) { + uriString = "http://" + uriString; + } + customTabsIntent.launchUrl(mContext, Uri.parse(uriString)); }); break; case Post.TEXT_TYPE: diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index bf91858c..ee3bdeed 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -45,4 +45,6 @@ <color name="navBarColor">#FFFFFF</color> <color name="cardViewBackgroundColor">#FFFFFF</color> + + <color name="singleCommentThreadBackgroundColor">#B3E5F9</color> </resources> |