diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-08-03 04:21:38 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-08-03 04:21:38 +0000 |
commit | c5b32494b79ce0566faccd88272482523dd5d4d3 (patch) | |
tree | 3915107029137eac2d4fdb4a039504c2c475ce2d /app/src/main | |
parent | 9564515d212d9adf5f16c390aa2fc6c39ed76735 (diff) | |
download | infinity-for-reddit-c5b32494b79ce0566faccd88272482523dd5d4d3.tar infinity-for-reddit-c5b32494b79ce0566faccd88272482523dd5d4d3.tar.gz infinity-for-reddit-c5b32494b79ce0566faccd88272482523dd5d4d3.tar.bz2 infinity-for-reddit-c5b32494b79ce0566faccd88272482523dd5d4d3.tar.lz infinity-for-reddit-c5b32494b79ce0566faccd88272482523dd5d4d3.tar.xz infinity-for-reddit-c5b32494b79ce0566faccd88272482523dd5d4d3.tar.zst infinity-for-reddit-c5b32494b79ce0566faccd88272482523dd5d4d3.zip |
Copy markdown in sidebar.
Diffstat (limited to 'app/src/main')
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("<sup>", "^").replaceAll("</sup>", ""); - } + 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("<sup>", "^").replaceAll("</sup>", ""); 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); } |