Long click the url to see more options. Make getRedditUriByPath in LinkResolverActivity private.

This commit is contained in:
Alex Ning 2020-12-31 14:46:19 +08:00
parent 1d857eed47
commit 321f4da623
16 changed files with 77 additions and 87 deletions

View File

@ -132,6 +132,7 @@ dependencies {
implementation "io.noties.markwon:recycler-table:$markwonVersion"
implementation "io.noties.markwon:simple-ext:$markwonVersion"
implementation 'com.atlassian.commonmark:commonmark-ext-gfm-tables:0.14.0'
implementation 'me.saket:better-link-movement-method:2.2.0'
// Animations
implementation 'com.airbnb.android:lottie:3.4.4'

View File

@ -139,7 +139,7 @@ public class PullNotificationWorker extends Worker {
if (kind.equals(Message.TYPE_COMMENT)) {
Intent intent = new Intent(context, LinkResolverActivity.class);
Uri uri = LinkResolverActivity.getRedditUriByPath(message.getContext());
Uri uri = Uri.parse(message.getContext());
intent.setData(uri);
intent.putExtra(LinkResolverActivity.EXTRA_NEW_ACCOUNT_NAME, accountName);
intent.putExtra(LinkResolverActivity.EXTRA_MESSAGE_FULLNAME, message.getFullname());
@ -152,7 +152,7 @@ public class PullNotificationWorker extends Worker {
builder.setContentIntent(summaryPendingIntent);
} else if (kind.equals(Message.TYPE_LINK)) {
Intent intent = new Intent(context, LinkResolverActivity.class);
Uri uri = LinkResolverActivity.getRedditUriByPath(message.getContext());
Uri uri = Uri.parse(message.getContext());
intent.setData(uri);
intent.putExtra(LinkResolverActivity.EXTRA_NEW_ACCOUNT_NAME, accountName);
intent.putExtra(LinkResolverActivity.EXTRA_MESSAGE_FULLNAME, message.getFullname());

View File

@ -154,11 +154,7 @@ public class CommentActivity extends BaseActivity {
builder.linkResolver((view, link) -> {
Intent intent = new Intent(CommentActivity.this, LinkResolverActivity.class);
Uri uri = Uri.parse(link);
if (uri.getScheme() == null && uri.getHost() == null) {
intent.setData(LinkResolverActivity.getRedditUriByPath(link));
} else {
intent.setData(uri);
}
intent.setData(uri);
startActivity(intent);
});
}
@ -218,11 +214,7 @@ public class CommentActivity extends BaseActivity {
builder.linkResolver((view, link) -> {
Intent intent = new Intent(CommentActivity.this, LinkResolverActivity.class);
Uri uri = Uri.parse(link);
if (uri.getScheme() == null && uri.getHost() == null) {
intent.setData(LinkResolverActivity.getRedditUriByPath(link));
} else {
intent.setData(uri);
}
intent.setData(uri);
startActivity(intent);
});
}

View File

@ -191,11 +191,7 @@ public class FullMarkdownActivity extends BaseActivity {
builder.linkResolver((view, link) -> {
Intent intent = new Intent(FullMarkdownActivity.this, LinkResolverActivity.class);
Uri uri = Uri.parse(link);
if (uri.getScheme() == null && uri.getHost() == null) {
intent.setData(LinkResolverActivity.getRedditUriByPath(link));
} else {
intent.setData(uri);
}
intent.setData(uri);
intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, isNsfw);
startActivity(intent);
});

View File

@ -51,7 +51,7 @@ public class LinkResolverActivity extends AppCompatActivity {
@Inject
CustomThemeWrapper mCustomThemeWrapper;
public static Uri getRedditUriByPath(String path) {
private Uri getRedditUriByPath(String path) {
return Uri.parse("https://www.reddit.com" + path);
}
@ -62,7 +62,12 @@ public class LinkResolverActivity extends AppCompatActivity {
((Infinity) getApplication()).getAppComponent().inject(this);
Uri uri = getIntent().getData();
handleUri(uri);
if (uri.getScheme() == null && uri.getHost() == null) {
handleUri(getRedditUriByPath(uri.toString()));
} else {
handleUri(uri);
}
}
private void handleUri(Uri uri) {

View File

@ -332,11 +332,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
builder.linkResolver((view, link) -> {
Intent intent = new Intent(mActivity, LinkResolverActivity.class);
Uri uri = Uri.parse(link);
if (uri.getScheme() == null && uri.getHost() == null) {
intent.setData(LinkResolverActivity.getRedditUriByPath(link));
} else {
intent.setData(uri);
}
intent.setData(uri);
intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, mPost.isNSFW());
mActivity.startActivity(intent);
});
@ -420,11 +416,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
builder.linkResolver((view, link) -> {
Intent intent = new Intent(mActivity, LinkResolverActivity.class);
Uri uri = Uri.parse(link);
if (uri.getScheme() == null && uri.getHost() == null) {
intent.setData(LinkResolverActivity.getRedditUriByPath(link));
} else {
intent.setData(uri);
}
intent.setData(uri);
intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, mPost.isNSFW());
mActivity.startActivity(intent);
});
@ -2992,11 +2984,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mImageView.setOnClickListener(view -> {
Intent intent = new Intent(mActivity, LinkResolverActivity.class);
Uri uri = Uri.parse(mPost.getUrl());
if (uri.getScheme() == null && uri.getHost() == null) {
intent.setData(LinkResolverActivity.getRedditUriByPath(mPost.getUrl()));
} else {
intent.setData(uri);
}
intent.setData(uri);
intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, mPost.isNSFW());
mActivity.startActivity(intent);
});
@ -3120,11 +3108,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
} else if (mPost.getPostType() == Post.LINK_TYPE || mPost.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
Intent intent = new Intent(mActivity, LinkResolverActivity.class);
Uri uri = Uri.parse(mPost.getUrl());
if (uri.getScheme() == null && uri.getHost() == null) {
intent.setData(LinkResolverActivity.getRedditUriByPath(mPost.getUrl()));
} else {
intent.setData(uri);
}
intent.setData(uri);
intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, mPost.isNSFW());
mActivity.startActivity(intent);
} else if (mPost.getPostType() == Post.GALLERY_TYPE) {

View File

@ -184,11 +184,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
builder.linkResolver((view, link) -> {
Intent intent = new Intent(mContext, LinkResolverActivity.class);
Uri uri = Uri.parse(link);
if (uri.getScheme() == null && uri.getHost() == null) {
intent.setData(LinkResolverActivity.getRedditUriByPath(link));
} else {
intent.setData(uri);
}
intent.setData(uri);
mContext.startActivity(intent);
});

View File

@ -164,11 +164,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
builder.linkResolver((view, link) -> {
Intent intent = new Intent(mContext, LinkResolverActivity.class);
Uri uri = Uri.parse(link);
if (uri.getScheme() == null && uri.getHost() == null) {
intent.setData(LinkResolverActivity.getRedditUriByPath(link));
} else {
intent.setData(uri);
}
intent.setData(uri);
mContext.startActivity(intent);
});
}
@ -238,7 +234,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
((DataViewHolder) holder).itemView.setOnClickListener(view -> {
if (mMessageType == FetchMessage.MESSAGE_TYPE_INBOX
&& message.getContext() != null && !message.getContext().equals("")) {
Uri uri = LinkResolverActivity.getRedditUriByPath(message.getContext());
Uri uri = Uri.parse(message.getContext());
Intent intent = new Intent(mContext, LinkResolverActivity.class);
intent.setData(uri);
mContext.startActivity(intent);

View File

@ -2359,11 +2359,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} else if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
Intent intent = new Intent(mActivity, LinkResolverActivity.class);
Uri uri = Uri.parse(post.getUrl());
if (uri.getScheme() == null && uri.getHost() == null) {
intent.setData(LinkResolverActivity.getRedditUriByPath(post.getUrl()));
} else {
intent.setData(uri);
}
intent.setData(uri);
intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, post.isNSFW());
mActivity.startActivity(intent);
} else if (post.getPostType() == Post.GALLERY_TYPE) {
@ -2731,11 +2727,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} else if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
Intent intent = new Intent(mActivity, LinkResolverActivity.class);
Uri uri = Uri.parse(post.getUrl());
if (uri.getScheme() == null && uri.getHost() == null) {
intent.setData(LinkResolverActivity.getRedditUriByPath(post.getUrl()));
} else {
intent.setData(uri);
}
intent.setData(uri);
intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, post.isNSFW());
mActivity.startActivity(intent);
} else if (post.getPostType() == Post.GALLERY_TYPE) {

View File

@ -73,11 +73,7 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
builder.linkResolver((view, link) -> {
Intent intent = new Intent(viewPrivateMessagesActivity, LinkResolverActivity.class);
Uri uri = Uri.parse(link);
if (uri.getScheme() == null && uri.getHost() == null) {
intent.setData(LinkResolverActivity.getRedditUriByPath(link));
} else {
intent.setData(uri);
}
intent.setData(uri);
viewPrivateMessagesActivity.startActivity(intent);
});
}

View File

@ -43,11 +43,7 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler
builder.linkResolver((view, link) -> {
Intent intent = new Intent(context, LinkResolverActivity.class);
Uri uri = Uri.parse(link);
if (uri.getScheme() == null && uri.getHost() == null) {
intent.setData(LinkResolverActivity.getRedditUriByPath(link));
} else {
intent.setData(uri);
}
intent.setData(uri);
context.startActivity(intent);
});
}

View File

@ -1,6 +1,7 @@
package ml.docilealligator.infinityforreddit.bottomsheetfragments;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
@ -25,6 +26,8 @@ import ml.docilealligator.infinityforreddit.R;
public class UrlMenuBottomSheetFragment extends RoundedBottomSheetDialogFragment {
public static final String EXTRA_URL = "EU";
@BindView(R.id.link_text_view_url_menu_bottom_sheet_fragment)
TextView linkTextView;
@BindView(R.id.open_link_text_view_url_menu_bottom_sheet_fragment)
TextView openLinkTextView;
@BindView(R.id.copy_link_text_view_url_menu_bottom_sheet_fragment)
@ -32,6 +35,7 @@ public class UrlMenuBottomSheetFragment extends RoundedBottomSheetDialogFragment
@BindView(R.id.share_link_text_view_url_menu_bottom_sheet_fragment)
TextView shareLinkTextView;
private Activity activity;
private String url;
public UrlMenuBottomSheetFragment() {
// Required empty public constructor
@ -43,7 +47,14 @@ public class UrlMenuBottomSheetFragment extends RoundedBottomSheetDialogFragment
View rootView = inflater.inflate(R.layout.fragment_url_menu_bottom_sheet, container, false);
ButterKnife.bind(this, rootView);
String url = getArguments().getString(EXTRA_URL);
url = getArguments().getString(EXTRA_URL);
Uri uri = Uri.parse(url);
if (uri.getScheme() == null && uri.getHost() == null) {
url = "https://www.reddit.com" + url;
}
linkTextView.setText(url);
openLinkTextView.setOnClickListener(view -> {
Intent intent = new Intent(activity, LinkResolverActivity.class);
@ -68,9 +79,11 @@ public class UrlMenuBottomSheetFragment extends RoundedBottomSheetDialogFragment
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, url);
if (intent.resolveActivity(activity.getPackageManager()) != null) {
startActivity(intent);
} else {
try {
Intent shareIntent = Intent.createChooser(intent, null);
startActivity(shareIntent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
Toast.makeText(activity, R.string.no_app, Toast.LENGTH_SHORT).show();
}
dismiss();

View File

@ -34,17 +34,20 @@ import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
import io.noties.markwon.linkify.LinkifyPlugin;
import io.noties.markwon.movement.MovementMethodPlugin;
import io.noties.markwon.recycler.MarkwonAdapter;
import io.noties.markwon.recycler.table.TableEntry;
import io.noties.markwon.recycler.table.TableEntryPlugin;
import io.noties.markwon.simple.ext.SimpleExtPlugin;
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditDataAsyncTask;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditDataAsyncTask;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData;
import ml.docilealligator.infinityforreddit.subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.subreddit.SubredditViewModel;
@ -111,16 +114,20 @@ public class SidebarFragment extends Fragment {
builder.linkResolver((view, link) -> {
Intent intent = new Intent(activity, LinkResolverActivity.class);
Uri uri = Uri.parse(link);
if (uri.getScheme() == null && uri.getHost() == null) {
intent.setData(LinkResolverActivity.getRedditUriByPath(link));
} else {
intent.setData(uri);
}
intent.setData(uri);
startActivity(intent);
});
}
})
.usePlugin(StrikethroughPlugin.create())
.usePlugin(MovementMethodPlugin.create(BetterLinkMovementMethod.linkify(Linkify.WEB_URLS, recyclerView).setOnLinkLongClickListener((textView, url) -> {
UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, url);
urlMenuBottomSheetFragment.setArguments(bundle);
urlMenuBottomSheetFragment.show(getChildFragmentManager(), urlMenuBottomSheetFragment.getTag());
return true;
})))
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
.usePlugin(SimpleExtPlugin.create(plugin ->
plugin.addExtension(1, '^', (configuration, props) -> {

View File

@ -16,7 +16,10 @@
android:id="@+id/markdown_recycler_view_sidebar_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:paddingTop="8dp"
android:paddingBottom="144dp"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:clipToPadding="false" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

View File

@ -12,11 +12,23 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/link_text_view_url_menu_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?attr/primaryTextColor"
android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="32dp"
android:paddingEnd="32dp" />
<TextView
android:id="@+id/open_link_text_view_url_menu_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/copy_raw_text"
android:text="@string/open_link"
android:textColor="?attr/primaryTextColor"
android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family"
@ -34,7 +46,7 @@
android:id="@+id/copy_link_text_view_url_menu_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/copy_markdown"
android:text="@string/copy_link"
android:textColor="?attr/primaryTextColor"
android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family"
@ -52,7 +64,7 @@
android:id="@+id/share_link_text_view_url_menu_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/copy_all_raw_text"
android:text="@string/share_link"
android:textColor="?attr/primaryTextColor"
android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family"

View File

@ -583,6 +583,7 @@
<string name="copy_gif_link">Copy Gif Link</string>
<string name="copy_video_link">Copy Video Link</string>
<string name="copy_link">Copy Link</string>
<string name="open_link">Open Link</string>
<string name="copy_success">Copied</string>
<string name="copy_link_failed">Cannot copy the link</string>