Copying post title, post content and comment content is now available in CommentActivity.

This commit is contained in:
Alex Ning 2020-06-05 22:26:36 +08:00
parent 179c16d596
commit e9ffe5a13c
6 changed files with 67 additions and 18 deletions

View File

@ -265,7 +265,7 @@
android:label="@string/comment_activity_label"
android:parentActivityName=".Activity.MainActivity"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustResize" />
android:windowSoftInputMode="adjustResize"/>
<activity
android:name=".Activity.SearchResultActivity"
android:label="@string/search_activity_label"

View File

@ -51,16 +51,20 @@ import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask
import ml.docilealligator.infinityforreddit.CommentData;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.Fragment.CopyTextBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SendComment;
import ml.docilealligator.infinityforreddit.Utils.Utils;
import retrofit2.Retrofit;
public class CommentActivity extends BaseActivity {
public static final String EXTRA_COMMENT_PARENT_TEXT_KEY = "ECPTK";
public static final String EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY = "ECPTMK";
public static final String EXTRA_COMMENT_PARENT_BODY_KEY = "ECPBK";
public static final String EXTRA_COMMENT_PARENT_BODY_MARKDOWN_KEY = "ECPBMK";
public static final String EXTRA_PARENT_FULLNAME_KEY = "EPFK";
public static final String EXTRA_PARENT_DEPTH_KEY = "EPDK";
public static final String EXTRA_PARENT_POSITION_KEY = "EPPK";
@ -133,6 +137,9 @@ public class CommentActivity extends BaseActivity {
}
Intent intent = getIntent();
String parentTextMarkdown = intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY);
String parentText = intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_KEY);
CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
Markwon markwon = Markwon.builder(this)
.usePlugin(new AbstractMarkwonPlugin() {
@Override
@ -157,9 +164,25 @@ public class CommentActivity extends BaseActivity {
)
)
.build();
markwon.setMarkdown(commentParentMarkwonView, intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_KEY));
if (parentTextMarkdown != null) {
commentParentMarkwonView.setOnLongClickListener(view -> {
Utils.hideKeyboard(CommentActivity.this);
Bundle bundle = new Bundle();
if (parentText == null) {
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, parentTextMarkdown);
} else {
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, parentText);
bundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, parentTextMarkdown);
}
copyTextBottomSheetFragment.setArguments(bundle);
copyTextBottomSheetFragment.show(getSupportFragmentManager(), copyTextBottomSheetFragment.getTag());
return true;
});
markwon.setMarkdown(commentParentMarkwonView, parentTextMarkdown);
}
String parentBodyMarkdown = intent.getStringExtra(EXTRA_COMMENT_PARENT_BODY_MARKDOWN_KEY);
String parentBody = intent.getStringExtra(EXTRA_COMMENT_PARENT_BODY_KEY);
if (parentBody != null && !parentBody.equals("")) {
if (parentBodyMarkdown != null && !parentBodyMarkdown.equals("")) {
contentMarkdownRecyclerView.setVisibility(View.VISIBLE);
contentMarkdownRecyclerView.setNestedScrollingEnabled(false);
Markwon postBodyMarkwon = Markwon.builder(this)
@ -167,6 +190,15 @@ public class CommentActivity extends BaseActivity {
@Override
public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) {
textView.setTextColor(markdownColor);
textView.setOnLongClickListener(view -> {
Utils.hideKeyboard(CommentActivity.this);
Bundle bundle = new Bundle();
bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, parentBody);
bundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, parentBodyMarkdown);
copyTextBottomSheetFragment.setArguments(bundle);
copyTextBottomSheetFragment.show(getSupportFragmentManager(), copyTextBottomSheetFragment.getTag());
return true;
});
}
@Override
@ -200,7 +232,7 @@ public class CommentActivity extends BaseActivity {
.build();
contentMarkdownRecyclerView.setLayoutManager(new LinearLayoutManager(this));
contentMarkdownRecyclerView.setAdapter(markwonAdapter);
markwonAdapter.setMarkdown(postBodyMarkwon, parentBody);
markwonAdapter.setMarkdown(postBodyMarkwon, parentBodyMarkdown);
markwonAdapter.notifyDataSetChanged();
}
parentFullname = intent.getStringExtra(EXTRA_PARENT_FULLNAME_KEY);

View File

@ -1340,8 +1340,9 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
}
Intent intent = new Intent(this, CommentActivity.class);
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, mPost.getTitle());
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_KEY, mPost.getSelfText());
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY, mPost.getTitle());
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_MARKDOWN_KEY, mPost.getSelfText());
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_KEY, mPost.getSelfTextPlain());
intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, mPost.getFullName());
intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0);
intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false);

View File

@ -1832,8 +1832,9 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
Intent intent = new Intent(mActivity, CommentActivity.class);
intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, mPost.getFullName());
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, mPost.getTitle());
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_KEY, mPost.getSelfText());
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY, mPost.getTitle());
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_MARKDOWN_KEY, mPost.getSelfText());
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_KEY, mPost.getSelfTextPlain());
intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false);
intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0);
mActivity.startActivityForResult(intent, WRITE_COMMENT_REQUEST_CODE);
@ -2751,7 +2752,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
Intent intent = new Intent(mActivity, CommentActivity.class);
intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, comment.getDepth() + 1);
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, comment.getCommentMarkdown());
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY, comment.getCommentMarkdown());
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, comment.getCommentRawText());
intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, comment.getFullName());
intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, true);

View File

@ -60,20 +60,25 @@ public class CopyTextBottomSheetFragment extends RoundedBottomSheetDialogFragmen
dismiss();
});
copyMarkdownTextView.setOnClickListener(view -> {
showCopyDialog(markdownText);
dismiss();
});
copyAllRawTextTextView.setOnClickListener(view -> {
copyText(rawText);
dismiss();
});
copyAllMarkdownTextView.setOnClickListener(view -> {
copyText(markdownText);
dismiss();
});
if (markdownText != null) {
copyMarkdownTextView.setOnClickListener(view -> {
showCopyDialog(markdownText);
dismiss();
});
copyAllMarkdownTextView.setOnClickListener(view -> {
copyText(markdownText);
dismiss();
});
} else {
copyMarkdownTextView.setVisibility(View.GONE);
copyAllMarkdownTextView.setVisibility(View.GONE);
}
return rootView;
}

View File

@ -1,11 +1,13 @@
package ml.docilealligator.infinityforreddit.Utils;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkInfo;
import android.text.Html;
import android.text.Spannable;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;
@ -117,4 +119,11 @@ public class Utils {
}
}
}
public static void hideKeyboard(Activity activity) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
if (inputMethodManager != null && activity.getCurrentFocus() != null) {
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
}
}