Copy markdown in sidebar.

This commit is contained in:
Alex Ning 2021-08-03 12:21:38 +08:00
parent 9564515d21
commit c5b32494b7
3 changed files with 32 additions and 17 deletions

View File

@ -53,23 +53,26 @@ public class CopyTextBottomSheetFragment extends RoundedBottomSheetDialogFragmen
View rootView = inflater.inflate(R.layout.fragment_copy_text_bottom_sheet, container, false);
ButterKnife.bind(this, rootView);
String rawText = getArguments().getString(EXTRA_RAW_TEXT);
markdownText = getArguments().getString(EXTRA_MARKDOWN);
if (markdownText != null) {
markdownText = markdownText.replaceAll("<sup>", "^").replaceAll("</sup>", "");
String rawText = getArguments().getString(EXTRA_RAW_TEXT, null);
markdownText = getArguments().getString(EXTRA_MARKDOWN, null);
if (rawText != null) {
copyRawTextTextView.setOnClickListener(view -> {
showCopyDialog(rawText);
dismiss();
});
copyAllRawTextTextView.setOnClickListener(view -> {
copyText(rawText);
dismiss();
});
} else {
copyRawTextTextView.setVisibility(View.GONE);
copyAllRawTextTextView.setVisibility(View.GONE);
}
copyRawTextTextView.setOnClickListener(view -> {
showCopyDialog(rawText);
dismiss();
});
copyAllRawTextTextView.setOnClickListener(view -> {
copyText(rawText);
dismiss();
});
if (markdownText != null) {
markdownText = markdownText.replaceAll("<sup>", "^").replaceAll("</sup>", "");
copyMarkdownTextView.setOnClickListener(view -> {
showCopyDialog(markdownText);
dismiss();

View File

@ -48,6 +48,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditData;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.CopyTextBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData;
@ -76,6 +77,7 @@ public class SidebarFragment extends Fragment {
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor mExecutor;
private String sidebarDescription;
public SidebarFragment() {
// Required empty public constructor
@ -107,6 +109,16 @@ public class SidebarFragment extends Fragment {
@Override
public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) {
textView.setTextColor(markdownColor);
textView.setOnLongClickListener(view -> {
if (sidebarDescription != null && !sidebarDescription.equals("") && textView.getSelectionStart() == -1 && textView.getSelectionEnd() == -1) {
Bundle bundle = new Bundle();
bundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, sidebarDescription);
CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
copyTextBottomSheetFragment.setArguments(bundle);
copyTextBottomSheetFragment.show(getChildFragmentManager(), copyTextBottomSheetFragment.getTag());
}
return true;
});
}
@Override
@ -162,8 +174,9 @@ public class SidebarFragment extends Fragment {
.get(SubredditViewModel.class);
mSubredditViewModel.getSubredditLiveData().observe(getViewLifecycleOwner(), subredditData -> {
if (subredditData != null) {
if (subredditData.getSidebarDescription() != null && !subredditData.getSidebarDescription().equals("")) {
markwonAdapter.setMarkdown(markwon, subredditData.getSidebarDescription());
sidebarDescription = subredditData.getSidebarDescription();
if (sidebarDescription != null && !sidebarDescription.equals("")) {
markwonAdapter.setMarkdown(markwon, sidebarDescription);
markwonAdapter.notifyDataSetChanged();
}
} else {

View File

@ -395,7 +395,6 @@ public class ViewRPANBroadcastFragment extends Fragment {
@Override
public void onMessage(@NonNull WebSocket webSocket, @NonNull String text) {
Log.i("asfasdf", "s " + text);
messageReceivedListener.onMessage(text);
}