diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-09-09 08:30:26 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-09-09 08:30:26 +0000 |
commit | 8ba7bd7b7e0ce4bf1cdbc4276f3ee9f4118a3d62 (patch) | |
tree | f63574ecee31b2676aa09ba0bd54b31315c9fb44 | |
parent | 3bb5e83d2e300e9b37c999f65c56195c5351df51 (diff) | |
download | infinity-for-reddit-8ba7bd7b7e0ce4bf1cdbc4276f3ee9f4118a3d62.tar infinity-for-reddit-8ba7bd7b7e0ce4bf1cdbc4276f3ee9f4118a3d62.tar.gz infinity-for-reddit-8ba7bd7b7e0ce4bf1cdbc4276f3ee9f4118a3d62.tar.bz2 infinity-for-reddit-8ba7bd7b7e0ce4bf1cdbc4276f3ee9f4118a3d62.tar.lz infinity-for-reddit-8ba7bd7b7e0ce4bf1cdbc4276f3ee9f4118a3d62.tar.xz infinity-for-reddit-8ba7bd7b7e0ce4bf1cdbc4276f3ee9f4118a3d62.tar.zst infinity-for-reddit-8ba7bd7b7e0ce4bf1cdbc4276f3ee9f4118a3d62.zip |
Handle no browser installed when opening links and no apps are eligible to share when sharing.
Diffstat (limited to '')
5 files changed, 183 insertions, 186 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java index fc6619a3..d0893b14 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit; import android.app.Activity; +import android.content.ActivityNotFoundException; import android.content.Intent; import android.graphics.ColorFilter; import android.graphics.PorterDuff; @@ -22,7 +23,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; -import androidx.browser.customtabs.CustomTabsIntent; import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; @@ -411,20 +411,14 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie ((PostDetailViewHolder) holder).linkTextView.setText(domain); ((PostDetailViewHolder) holder).mImageView.setOnClickListener(view -> { - CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); - // add share action to menu list - builder.addDefaultShareMenuItem(); - builder.setToolbarColor(mActivity.getResources().getColor(R.color.colorPrimary)); - CustomTabsIntent customTabsIntent = builder.build(); + Intent intent = new Intent(mActivity, LinkResolverActivity.class); 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; + if(uri.getScheme() == null && uri.getHost() == null) { + intent.setData(LinkResolverActivity.getRedditUriByPath(mPost.getUrl())); + } else { + intent.setData(uri); } - customTabsIntent.launchUrl(mActivity, Uri.parse(uriString)); + mActivity.startActivity(intent); }); break; case Post.GIF_VIDEO_TYPE: @@ -477,20 +471,14 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie ((PostDetailViewHolder) holder).mNoPreviewLinkImageView.setVisibility(View.VISIBLE); ((PostDetailViewHolder) holder).mNoPreviewLinkImageView.setOnClickListener(view -> { - CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); - // add share action to menu list - builder.addDefaultShareMenuItem(); - builder.setToolbarColor(mActivity.getResources().getColor(R.color.colorPrimary)); - CustomTabsIntent customTabsIntent = builder.build(); + Intent intent = new Intent(mActivity, LinkResolverActivity.class); 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; + if(uri.getScheme() == null && uri.getHost() == null) { + intent.setData(LinkResolverActivity.getRedditUriByPath(mPost.getUrl())); + } else { + intent.setData(uri); } - customTabsIntent.launchUrl(mActivity, Uri.parse(uriString)); + mActivity.startActivity(intent); }); break; case Post.TEXT_TYPE: @@ -1078,11 +1066,15 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie }); mShareButton.setOnClickListener(view -> { - Intent intent = new Intent(Intent.ACTION_SEND); - intent.setType("text/plain"); - String extraText = mPost.getTitle() + "\n" + mPost.getPermalink(); - intent.putExtra(Intent.EXTRA_TEXT, extraText); - mActivity.startActivity(Intent.createChooser(intent, "Share")); + try { + Intent intent = new Intent(Intent.ACTION_SEND); + intent.setType("text/plain"); + String extraText = mPost.getTitle() + "\n" + mPost.getPermalink(); + intent.putExtra(Intent.EXTRA_TEXT, extraText); + mActivity.startActivity(Intent.createChooser(intent, mActivity.getString(R.string.share))); + } catch (ActivityNotFoundException e) { + Toast.makeText(mActivity, R.string.no_activity_found_for_share, Toast.LENGTH_SHORT).show(); + } }); mUpvoteButton.setOnClickListener(view -> { @@ -1257,12 +1249,16 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie }); shareButton.setOnClickListener(view -> { - Intent intent = new Intent(Intent.ACTION_SEND); - intent.setType("text/plain"); - String extraText = mIsSingleCommentThreadMode ? mVisibleComments.get(getAdapterPosition() - 2).getPermalink() - : mVisibleComments.get(getAdapterPosition() - 1).getPermalink(); - intent.putExtra(Intent.EXTRA_TEXT, extraText); - mActivity.startActivity(Intent.createChooser(intent, "Share")); + try { + Intent intent = new Intent(Intent.ACTION_SEND); + intent.setType("text/plain"); + String extraText = mIsSingleCommentThreadMode ? mVisibleComments.get(getAdapterPosition() - 2).getPermalink() + : mVisibleComments.get(getAdapterPosition() - 1).getPermalink(); + intent.putExtra(Intent.EXTRA_TEXT, extraText); + mActivity.startActivity(Intent.createChooser(intent, mActivity.getString(R.string.share))); + } catch (ActivityNotFoundException e) { + Toast.makeText(mActivity, R.string.no_activity_found_for_share, Toast.LENGTH_SHORT).show(); + } }); expandButton.setOnClickListener(view -> { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java index 3b39ace5..668a66b0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit; +import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.net.Uri; @@ -161,6 +162,131 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, R modifyCommentBottomSheetFragment.show(((AppCompatActivity) mContext).getSupportFragmentManager(), modifyCommentBottomSheetFragment.getTag()); }); } + + ((DataViewHolder) holder).linearLayout.setOnClickListener(view -> { + Intent intent = new Intent(mContext, ViewPostDetailActivity.class); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, comment.getLinkId()); + intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, comment.getId()); + mContext.startActivity(intent); + }); + + ((DataViewHolder) holder).verticalBlock.setVisibility(View.GONE); + + ((DataViewHolder) holder).commentMarkdownView.setOnClickListener(view -> + ((DataViewHolder) holder).linearLayout.callOnClick()); + + ((DataViewHolder) holder).shareButton.setOnClickListener(view -> { + try { + Intent intent = new Intent(Intent.ACTION_SEND); + intent.setType("text/plain"); + String extraText = comment.getPermalink(); + intent.putExtra(Intent.EXTRA_TEXT, extraText); + mContext.startActivity(Intent.createChooser(intent, mContext.getString(R.string.share))); + } catch (ActivityNotFoundException e) { + Toast.makeText(mContext, R.string.no_activity_found_for_share, Toast.LENGTH_SHORT).show(); + } + }); + + ((DataViewHolder) holder).replyButton.setVisibility(View.GONE); + + ((DataViewHolder) holder).upvoteButton.setOnClickListener(view -> { + if(mAccessToken == null) { + Toast.makeText(mContext, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } + + int previousVoteType = comment.getVoteType(); + String newVoteType; + + ((DataViewHolder) holder).downvoteButton.clearColorFilter(); + + if(previousVoteType != CommentData.VOTE_TYPE_UPVOTE) { + //Not upvoted before + comment.setVoteType(CommentData.VOTE_TYPE_UPVOTE); + newVoteType = RedditUtils.DIR_UPVOTE; + ((DataViewHolder) holder).upvoteButton + .setColorFilter(ContextCompat.getColor(mContext, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); + ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.upvoted)); + } else { + //Upvoted before + comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); + newVoteType = RedditUtils.DIR_UNVOTE; + ((DataViewHolder) holder).upvoteButton.clearColorFilter(); + ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.defaultTextColor)); + } + + ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType())); + + VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { + @Override + public void onVoteThingSuccess(int position) { + if(newVoteType.equals(RedditUtils.DIR_UPVOTE)) { + comment.setVoteType(CommentData.VOTE_TYPE_UPVOTE); + ((DataViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); + ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.upvoted)); + } else { + comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); + ((DataViewHolder) holder).upvoteButton.clearColorFilter(); + ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.defaultTextColor)); + } + + ((DataViewHolder) holder).downvoteButton.clearColorFilter(); + ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType())); + } + + @Override + public void onVoteThingFail(int position) { } + }, comment.getFullName(), newVoteType, holder.getAdapterPosition()); + }); + + ((DataViewHolder) holder).downvoteButton.setOnClickListener(view -> { + if(mAccessToken == null) { + Toast.makeText(mContext, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } + + int previousVoteType = comment.getVoteType(); + String newVoteType; + + ((DataViewHolder) holder).upvoteButton.clearColorFilter(); + + if(previousVoteType != CommentData.VOTE_TYPE_DOWNVOTE) { + //Not downvoted before + comment.setVoteType(CommentData.VOTE_TYPE_DOWNVOTE); + newVoteType = RedditUtils.DIR_DOWNVOTE; + ((DataViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); + ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.downvoted)); + } else { + //Downvoted before + comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); + newVoteType = RedditUtils.DIR_UNVOTE; + ((DataViewHolder) holder).downvoteButton.clearColorFilter(); + ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.defaultTextColor)); + } + + ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType())); + + VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { + @Override + public void onVoteThingSuccess(int position1) { + if(newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) { + comment.setVoteType(CommentData.VOTE_TYPE_DOWNVOTE); + ((DataViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); + ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.downvoted)); + } else { + comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); + ((DataViewHolder) holder).downvoteButton.clearColorFilter(); + ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.defaultTextColor)); + } + + ((DataViewHolder) holder).upvoteButton.clearColorFilter(); + ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType())); + } + + @Override + public void onVoteThingFail(int position1) { } + }, comment.getFullName(), newVoteType, holder.getAdapterPosition()); + }); } } } @@ -232,125 +358,6 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, R DataViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); - - linearLayout.setOnClickListener(view -> { - Intent intent = new Intent(mContext, ViewPostDetailActivity.class); - intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, getItem(getAdapterPosition()).getLinkId()); - intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, getItem(getAdapterPosition()).getId()); - mContext.startActivity(intent); - }); - - verticalBlock.setVisibility(View.GONE); - - commentMarkdownView.setOnClickListener(view -> linearLayout.callOnClick()); - - shareButton.setOnClickListener(view -> { - Intent intent = new Intent(Intent.ACTION_SEND); - intent.setType("text/plain"); - String extraText = getItem(getAdapterPosition()).getPermalink(); - intent.putExtra(Intent.EXTRA_TEXT, extraText); - mContext.startActivity(Intent.createChooser(intent, "Share")); - }); - - replyButton.setVisibility(View.GONE); - - upvoteButton.setOnClickListener(view -> { - if(mAccessToken == null) { - Toast.makeText(mContext, R.string.login_first, Toast.LENGTH_SHORT).show(); - return; - } - - int previousVoteType = getItem(getAdapterPosition()).getVoteType(); - String newVoteType; - - downvoteButton.clearColorFilter(); - - if(previousVoteType != CommentData.VOTE_TYPE_UPVOTE) { - //Not upvoted before - getItem(getAdapterPosition()).setVoteType(CommentData.VOTE_TYPE_UPVOTE); - newVoteType = RedditUtils.DIR_UPVOTE; - upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); - scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.upvoted)); - } else { - //Upvoted before - getItem(getAdapterPosition()).setVoteType(CommentData.VOTE_TYPE_NO_VOTE); - newVoteType = RedditUtils.DIR_UNVOTE; - upvoteButton.clearColorFilter(); - scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.defaultTextColor)); - } - - scoreTextView.setText(Integer.toString(getItem(getAdapterPosition()).getScore() + getItem(getAdapterPosition()).getVoteType())); - - VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { - @Override - public void onVoteThingSuccess(int position) { - if(newVoteType.equals(RedditUtils.DIR_UPVOTE)) { - getItem(getAdapterPosition()).setVoteType(CommentData.VOTE_TYPE_UPVOTE); - upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); - scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.upvoted)); - } else { - getItem(getAdapterPosition()).setVoteType(CommentData.VOTE_TYPE_NO_VOTE); - upvoteButton.clearColorFilter(); - scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.defaultTextColor)); - } - - downvoteButton.clearColorFilter(); - scoreTextView.setText(Integer.toString(getItem(getAdapterPosition()).getScore() + getItem(getAdapterPosition()).getVoteType())); - } - - @Override - public void onVoteThingFail(int position) { } - }, getItem(getAdapterPosition()).getFullName(), newVoteType, getAdapterPosition()); - }); - - downvoteButton.setOnClickListener(view -> { - if(mAccessToken == null) { - Toast.makeText(mContext, R.string.login_first, Toast.LENGTH_SHORT).show(); - return; - } - - int previousVoteType = getItem(getAdapterPosition()).getVoteType(); - String newVoteType; - - upvoteButton.clearColorFilter(); - - if(previousVoteType != CommentData.VOTE_TYPE_DOWNVOTE) { - //Not downvoted before - getItem(getAdapterPosition()).setVoteType(CommentData.VOTE_TYPE_DOWNVOTE); - newVoteType = RedditUtils.DIR_DOWNVOTE; - downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); - scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.downvoted)); - } else { - //Downvoted before - getItem(getAdapterPosition()).setVoteType(CommentData.VOTE_TYPE_NO_VOTE); - newVoteType = RedditUtils.DIR_UNVOTE; - downvoteButton.clearColorFilter(); - scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.defaultTextColor)); - } - - scoreTextView.setText(Integer.toString(getItem(getAdapterPosition()).getScore() + getItem(getAdapterPosition()).getVoteType())); - - VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { - @Override - public void onVoteThingSuccess(int position1) { - if(newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) { - getItem(getAdapterPosition()).setVoteType(CommentData.VOTE_TYPE_DOWNVOTE); - downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); - scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.downvoted)); - } else { - getItem(getAdapterPosition()).setVoteType(CommentData.VOTE_TYPE_NO_VOTE); - downvoteButton.clearColorFilter(); - scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.defaultTextColor)); - } - - upvoteButton.clearColorFilter(); - scoreTextView.setText(Integer.toString(getItem(getAdapterPosition()).getScore() + getItem(getAdapterPosition()).getVoteType())); - } - - @Override - public void onVoteThingFail(int position1) { } - }, getItem(getAdapterPosition()).getFullName(), newVoteType, getAdapterPosition()); - }); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index 164b21a1..fa2c097f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit; +import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.graphics.ColorFilter; @@ -18,7 +19,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.browser.customtabs.CustomTabsIntent; import androidx.cardview.widget.CardView; import androidx.core.content.ContextCompat; import androidx.paging.PagedListAdapter; @@ -401,20 +401,14 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo ((DataViewHolder) holder).linkTextView.setText(domain); ((DataViewHolder) holder).imageView.setOnClickListener(view -> { - CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); - // add share action to menu list - builder.addDefaultShareMenuItem(); - builder.setToolbarColor(mContext.getResources().getColor(R.color.colorPrimary)); - CustomTabsIntent customTabsIntent = builder.build(); + Intent intent = new Intent(mContext, LinkResolverActivity.class); 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; + if(uri.getScheme() == null && uri.getHost() == null) { + intent.setData(LinkResolverActivity.getRedditUriByPath(post.getUrl())); + } else { + intent.setData(uri); } - customTabsIntent.launchUrl(mContext, Uri.parse(uriString)); + mContext.startActivity(intent); }); break; case Post.GIF_VIDEO_TYPE: @@ -462,20 +456,14 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo ((DataViewHolder) holder).linkTextView.setText(noPreviewLinkDomain); ((DataViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE); ((DataViewHolder) holder).noPreviewLinkImageView.setOnClickListener(view -> { - CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); - // add share action to menu list - builder.addDefaultShareMenuItem(); - builder.setToolbarColor(mContext.getResources().getColor(R.color.colorPrimary)); - CustomTabsIntent customTabsIntent = builder.build(); + Intent intent = new Intent(mContext, LinkResolverActivity.class); 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; + if(uri.getScheme() == null && uri.getHost() == null) { + intent.setData(LinkResolverActivity.getRedditUriByPath(post.getUrl())); + } else { + intent.setData(uri); } - customTabsIntent.launchUrl(mContext, Uri.parse(uriString)); + mContext.startActivity(intent); }); break; case Post.TEXT_TYPE: @@ -626,11 +614,15 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo }); ((DataViewHolder) holder).shareButton.setOnClickListener(view -> { - Intent intent = new Intent(Intent.ACTION_SEND); - intent.setType("text/plain"); - String extraText = title + "\n" + permalink; - intent.putExtra(Intent.EXTRA_TEXT, extraText); - mContext.startActivity(Intent.createChooser(intent, "Share")); + try { + Intent intent = new Intent(Intent.ACTION_SEND); + intent.setType("text/plain"); + String extraText = title + "\n" + permalink; + intent.putExtra(Intent.EXTRA_TEXT, extraText); + mContext.startActivity(Intent.createChooser(intent, mContext.getString(R.string.share))); + } catch (ActivityNotFoundException e) { + Toast.makeText(mContext, R.string.no_activity_found_for_share, Toast.LENGTH_SHORT).show(); + } }); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java index 98374317..5c6b9945 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java @@ -212,7 +212,6 @@ class SubmitPost { submitPostListener.submitFailed(null); } } else { - Log.i("call_failed", response.message()); submitPostListener.submitFailed(response.message()); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 900c8750..cc7d32e1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -188,6 +188,7 @@ <string name="open_link_with">Open link with</string> <string name="no_browser_found">No browser found</string> + <string name="no_activity_found_for_share">There is no app that can handle the share action</string> <string name="archived_post_vote_unavailable">Archived post. Vote unavailable.</string> <string name="archived_post_comment_unavailable">Archived post. Comment unavailable.</string> @@ -301,4 +302,6 @@ <string name="no_image_path_received">No image path received</string> <string name="no_video_path_received">No video path received</string> <string name="cannot_handle_intent">Could not handle the share request</string> + + <string name="share">Share</string> </resources> |