aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-01-29 04:43:57 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-01-29 04:43:57 +0000
commit5e401a6a96f4b83a79685907a6bee4997ff7e183 (patch)
tree57d17c810914cd7afcdce33a10e70d8ce6314284 /app
parentcb9154369070fe3773c16da0d4e7b3c33b716a1f (diff)
downloadinfinity-for-reddit-5e401a6a96f4b83a79685907a6bee4997ff7e183.tar
infinity-for-reddit-5e401a6a96f4b83a79685907a6bee4997ff7e183.tar.gz
infinity-for-reddit-5e401a6a96f4b83a79685907a6bee4997ff7e183.tar.bz2
infinity-for-reddit-5e401a6a96f4b83a79685907a6bee4997ff7e183.tar.lz
infinity-for-reddit-5e401a6a96f4b83a79685907a6bee4997ff7e183.tar.xz
infinity-for-reddit-5e401a6a96f4b83a79685907a6bee4997ff7e183.tar.zst
infinity-for-reddit-5e401a6a96f4b83a79685907a6bee4997ff7e183.zip
Copy post title and content in ViewPostDetailActivity.
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CopyTextBottomSheetFragment.java110
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTypeBottomSheetFragment.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java11
-rw-r--r--app/src/main/res/layout/copy_text_material_dialog.xml19
-rw-r--r--app/src/main/res/layout/fragment_copy_text_bottom_sheet.xml77
-rw-r--r--app/src/main/res/layout/item_post_detail.xml6
-rw-r--r--app/src/main/res/values/strings.xml6
-rw-r--r--app/src/main/res/values/styles.xml6
10 files changed, 248 insertions, 2 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
index 14dab410..b15d9416 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
@@ -74,6 +74,7 @@ import ml.docilealligator.infinityforreddit.CommentData;
import ml.docilealligator.infinityforreddit.CustomView.AspectRatioGifImageView;
import ml.docilealligator.infinityforreddit.CustomView.MarkwonLinearLayoutManager;
import ml.docilealligator.infinityforreddit.FetchComment;
+import ml.docilealligator.infinityforreddit.Fragment.CopyTextBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.ModifyCommentBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.ShareLinkBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Post.Post;
@@ -126,6 +127,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private boolean loadMoreCommentsFailed;
private int mCommentBackgroundColor;
private ShareLinkBottomSheetFragment mShareLinkBottomSheetFragment;
+ private CopyTextBottomSheetFragment mCopyTextBottomSheetFragment;
public CommentAndPostRecyclerViewAdapter(AppCompatActivity activity, Retrofit retrofit, Retrofit oauthRetrofit,
RedditDataRoomDatabase redditDataRoomDatabase, RequestManager glide,
@@ -145,6 +147,14 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
@Override
public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) {
textView.setTextColor(markdownColor);
+ textView.setOnLongClickListener(view -> {
+ Bundle bundle = new Bundle();
+ bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, mPost.getSelfTextPlain());
+ bundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, mPost.getSelfText());
+ mCopyTextBottomSheetFragment.setArguments(bundle);
+ mCopyTextBottomSheetFragment.show(mActivity.getSupportFragmentManager(), mCopyTextBottomSheetFragment.getTag());
+ return true;
+ });
}
@Override
@@ -225,6 +235,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mCommentBackgroundColor = typedValue.data;
mShareLinkBottomSheetFragment = new ShareLinkBottomSheetFragment();
+ mCopyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CopyTextBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CopyTextBottomSheetFragment.java
new file mode 100644
index 00000000..96bb671d
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CopyTextBottomSheetFragment.java
@@ -0,0 +1,110 @@
+package ml.docilealligator.infinityforreddit.Fragment;
+
+
+import android.app.Activity;
+import android.content.ClipData;
+import android.content.ClipboardManager;
+import android.content.Context;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.Fragment;
+
+import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.R;
+
+/**
+ * A simple {@link Fragment} subclass.
+ */
+public class CopyTextBottomSheetFragment extends RoundedBottomSheetDialogFragment {
+ public static final String EXTRA_RAW_TEXT = "ERT";
+ public static final String EXTRA_MARKDOWN = "EM";
+
+ @BindView(R.id.copy_raw_text_text_view_copy_text_bottom_sheet_fragment)
+ TextView copyRawTextTextView;
+ @BindView(R.id.copy_markdown_text_view_copy_text_bottom_sheet_fragment)
+ TextView copyMarkdownTextView;
+ @BindView(R.id.copy_all_raw_text_text_view_copy_text_bottom_sheet_fragment)
+ TextView copyAllRawTextTextView;
+ @BindView(R.id.copy_all_markdown_text_view_copy_text_bottom_sheet_fragment)
+ TextView copyAllMarkdownTextView;
+
+ private Activity activity;
+
+ public CopyTextBottomSheetFragment() {
+ // Required empty public constructor
+ }
+
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ View rootView = inflater.inflate(R.layout.fragment_copy_text_bottom_sheet, container, false);
+ ButterKnife.bind(this, rootView);
+
+ String rawText = getArguments().getString(EXTRA_RAW_TEXT);
+ String markdownText = getArguments().getString(EXTRA_MARKDOWN);
+
+ copyRawTextTextView.setOnClickListener(view -> {
+ showCopyDialog(rawText);
+ dismiss();
+ });
+
+ copyMarkdownTextView.setOnClickListener(view -> {
+ showCopyDialog(markdownText);
+ dismiss();
+ });
+
+ copyAllRawTextTextView.setOnClickListener(view -> {
+ copyText(rawText);
+ dismiss();
+ });
+
+ copyAllMarkdownTextView.setOnClickListener(view -> {
+ copyText(markdownText);
+ dismiss();
+ });
+
+ return rootView;
+ }
+
+ private void showCopyDialog(String text) {
+ LayoutInflater inflater = activity.getLayoutInflater();
+ View layout = inflater.inflate(R.layout.copy_text_material_dialog, null);
+ TextView textView = layout.findViewById(R.id.text_view_copy_text_material_dialog);
+ textView.setText(text);
+ new MaterialAlertDialogBuilder(activity, R.style.CopyTextMaterialAlertDialogTheme)
+ .setTitle(R.string.copy_text)
+ .setView(layout)
+ .setPositiveButton(R.string.copy_all, (dialogInterface, i) -> copyText(text))
+ .setNegativeButton(R.string.cancel, null)
+ .show();
+ }
+
+ private void copyText(String text) {
+ ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
+ if (clipboard != null) {
+ ClipData clip = ClipData.newPlainText("simple text", text);
+ clipboard.setPrimaryClip(clip);
+ Toast.makeText(activity, R.string.copy_success, Toast.LENGTH_SHORT).show();
+ } else {
+ Toast.makeText(activity, R.string.copy_failed, Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ activity = (Activity) context;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTypeBottomSheetFragment.java
index f5ee3696..ba03d93c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTypeBottomSheetFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SortTypeBottomSheetFragment.java
@@ -109,6 +109,6 @@ public class SortTypeBottomSheetFragment extends RoundedBottomSheetDialogFragmen
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
- this.activity = (Activity) context;
+ activity = (Activity) context;
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
index 25a0e1cd..435cce53 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
@@ -133,6 +133,7 @@ public class ParsePost {
} else {
String selfTextPlain = Utils.trimTrailingWhitespace(
Html.fromHtml(data.getString(JSONUtils.SELFTEXT_HTML_KEY))).toString();
+ post.setSelfTextPlain(selfTextPlain);
if (selfTextPlain.length() > 250) {
selfTextPlain = selfTextPlain.substring(0, 250);
}
@@ -234,6 +235,7 @@ public class ParsePost {
} else {
String selfTextPlain = Utils.trimTrailingWhitespace(
Html.fromHtml(data.getString(JSONUtils.SELFTEXT_HTML_KEY))).toString();
+ post.setSelfTextPlain(selfTextPlain);
if (selfTextPlain.length() > 250) {
selfTextPlain = selfTextPlain.substring(0, 250);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java
index e16893c2..8a025c97 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java
@@ -39,6 +39,7 @@ public class Post implements Parcelable {
private String postTime;
private String title;
private String selfText;
+ private String selfTextPlain;
private String selfTextPlainTrimmed;
private String previewUrl;
private String thumbnailPreviewUrl;
@@ -177,6 +178,7 @@ public class Post implements Parcelable {
postTimeMillis = in.readLong();
title = in.readString();
selfText = in.readString();
+ selfTextPlain = in.readString();
selfTextPlainTrimmed = in.readString();
previewUrl = in.readString();
thumbnailPreviewUrl = in.readString();
@@ -267,6 +269,14 @@ public class Post implements Parcelable {
this.selfText = selfText;
}
+ public String getSelfTextPlain() {
+ return selfTextPlain;
+ }
+
+ public void setSelfTextPlain(String selfTextPlain) {
+ this.selfTextPlain = selfTextPlain;
+ }
+
public String getSelfTextPlainTrimmed() {
return selfTextPlainTrimmed;
}
@@ -438,6 +448,7 @@ public class Post implements Parcelable {
parcel.writeLong(postTimeMillis);
parcel.writeString(title);
parcel.writeString(selfText);
+ parcel.writeString(selfTextPlain);
parcel.writeString(selfTextPlainTrimmed);
parcel.writeString(previewUrl);
parcel.writeString(thumbnailPreviewUrl);
diff --git a/app/src/main/res/layout/copy_text_material_dialog.xml b/app/src/main/res/layout/copy_text_material_dialog.xml
new file mode 100644
index 00000000..a8dfb7a5
--- /dev/null
+++ b/app/src/main/res/layout/copy_text_material_dialog.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:id="@+id/text_view_copy_text_material_dialog"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp"
+ android:paddingStart="24dp"
+ android:paddingEnd="24dp"
+ android:textIsSelectable="true"
+ android:enabled="true"
+ android:focusable="true"
+ android:longClickable="true" />
+
+</ScrollView> \ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_copy_text_bottom_sheet.xml b/app/src/main/res/layout/fragment_copy_text_bottom_sheet.xml
new file mode 100644
index 00000000..43044ca2
--- /dev/null
+++ b/app/src/main/res/layout/fragment_copy_text_bottom_sheet.xml
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingBottom="8dp"
+ android:overScrollMode="never"
+ tools:context=".Fragment.SortTimeBottomSheetFragment">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/copy_raw_text_text_view_copy_text_bottom_sheet_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/copy_raw_text"
+ android:textColor="@color/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:paddingStart="32dp"
+ android:paddingEnd="32dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground" />
+
+ <TextView
+ android:id="@+id/copy_markdown_text_view_copy_text_bottom_sheet_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/copy_markdown"
+ android:textColor="@color/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:paddingStart="32dp"
+ android:paddingEnd="32dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground" />
+
+ <TextView
+ android:id="@+id/copy_all_raw_text_text_view_copy_text_bottom_sheet_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/copy_all_raw_text"
+ android:textColor="@color/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:paddingStart="32dp"
+ android:paddingEnd="32dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground" />
+
+ <TextView
+ android:id="@+id/copy_all_markdown_text_view_copy_text_bottom_sheet_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/copy_all_markdown"
+ android:textColor="@color/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:paddingStart="32dp"
+ android:paddingEnd="32dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground" />
+
+ </LinearLayout>
+
+</androidx.core.widget.NestedScrollView> \ No newline at end of file
diff --git a/app/src/main/res/layout/item_post_detail.xml b/app/src/main/res/layout/item_post_detail.xml
index e23da92c..1ccdf2a1 100644
--- a/app/src/main/res/layout/item_post_detail.xml
+++ b/app/src/main/res/layout/item_post_detail.xml
@@ -79,7 +79,11 @@
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:textColor="@color/primaryTextColor"
- android:textSize="?attr/title_font_18" />
+ android:textSize="?attr/title_font_18"
+ android:textIsSelectable="true"
+ android:enabled="true"
+ android:focusable="true"
+ android:longClickable="true" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/content_markdown_view_item_post_detail"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 0e2a5b66..2b7e673b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -405,4 +405,10 @@
<string name="copy_success">Copied</string>
<string name="copy_failed">Cannot copy the link</string>
+ <string name="copy_text">Copy</string>
+ <string name="copy_all">Copy All</string>
+ <string name="copy_markdown">Copy Markdown</string>
+ <string name="copy_raw_text">Copy Raw Text</string>
+ <string name="copy_all_markdown">Copy All Markdown</string>
+ <string name="copy_all_raw_text">Copy All Raw Text</string>
</resources>
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 3248cfd4..b91ecdb1 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -58,6 +58,12 @@
<item name="buttonBarNegativeButtonStyle">@style/MaterialAlertDialogNegativeButtonStyle</item>
</style>
+ <style name="CopyTextMaterialAlertDialogTheme">
+ <item name="android:textSize">?attr/font_default</item>
+ <item name="materialAlertDialogTitleTextStyle">@style/MaterialAlertDialogTitleTextStyle</item>
+ <item name="buttonBarNegativeButtonStyle">@style/MaterialAlertDialogNegativeButtonStyle</item>
+ </style>
+
<style name="MaterialAlertDialogPositiveButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">@color/colorAccent</item>
</style>