From c5b32494b79ce0566faccd88272482523dd5d4d3 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 3 Aug 2021 12:21:38 +0800 Subject: Copy markdown in sidebar. --- .../CopyTextBottomSheetFragment.java | 29 ++++++++++++---------- .../fragments/SidebarFragment.java | 17 +++++++++++-- .../fragments/ViewRPANBroadcastFragment.java | 1 - 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java index 6e87c4ee..7b6452ec 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java @@ -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("", "^").replaceAll("", ""); - } + String rawText = getArguments().getString(EXTRA_RAW_TEXT, null); + markdownText = getArguments().getString(EXTRA_MARKDOWN, null); - copyRawTextTextView.setOnClickListener(view -> { - showCopyDialog(rawText); - dismiss(); - }); + if (rawText != null) { + copyRawTextTextView.setOnClickListener(view -> { + showCopyDialog(rawText); + dismiss(); + }); - copyAllRawTextTextView.setOnClickListener(view -> { - copyText(rawText); - dismiss(); - }); + copyAllRawTextTextView.setOnClickListener(view -> { + copyText(rawText); + dismiss(); + }); + } else { + copyRawTextTextView.setVisibility(View.GONE); + copyAllRawTextTextView.setVisibility(View.GONE); + } if (markdownText != null) { + markdownText = markdownText.replaceAll("", "^").replaceAll("", ""); copyMarkdownTextView.setOnClickListener(view -> { showCopyDialog(markdownText); dismiss(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java index 34e1ac3c..f36c47e8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -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 { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java index 53fabb1a..94a958a5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java @@ -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); } -- cgit v1.2.3