diff options
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
3 files changed, 63 insertions, 6 deletions
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: |