mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 12:47:26 +01:00
Show post or body (if it has) in CommentActivity.
This commit is contained in:
parent
30ce4285c9
commit
4c6902a399
@ -5,10 +5,12 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.Spanned;
|
||||||
import android.text.style.SuperscriptSpan;
|
import android.text.style.SuperscriptSpan;
|
||||||
import android.text.util.Linkify;
|
import android.text.util.Linkify;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@ -18,10 +20,14 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
|
import org.commonmark.ext.gfm.tables.TableBlock;
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
|
||||||
@ -33,8 +39,13 @@ import butterknife.ButterKnife;
|
|||||||
import io.noties.markwon.AbstractMarkwonPlugin;
|
import io.noties.markwon.AbstractMarkwonPlugin;
|
||||||
import io.noties.markwon.Markwon;
|
import io.noties.markwon.Markwon;
|
||||||
import io.noties.markwon.MarkwonConfiguration;
|
import io.noties.markwon.MarkwonConfiguration;
|
||||||
|
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
||||||
import io.noties.markwon.linkify.LinkifyPlugin;
|
import io.noties.markwon.linkify.LinkifyPlugin;
|
||||||
|
import io.noties.markwon.recycler.MarkwonAdapter;
|
||||||
|
import io.noties.markwon.recycler.table.TableEntry;
|
||||||
|
import io.noties.markwon.recycler.table.TableEntryPlugin;
|
||||||
import io.noties.markwon.simple.ext.SimpleExtPlugin;
|
import io.noties.markwon.simple.ext.SimpleExtPlugin;
|
||||||
|
import io.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute;
|
||||||
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
|
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.CommentData;
|
import ml.docilealligator.infinityforreddit.CommentData;
|
||||||
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
|
||||||
@ -47,11 +58,12 @@ import retrofit2.Retrofit;
|
|||||||
public class CommentActivity extends BaseActivity {
|
public class CommentActivity extends BaseActivity {
|
||||||
|
|
||||||
public static final String EXTRA_COMMENT_PARENT_TEXT_KEY = "ECPTK";
|
public static final String EXTRA_COMMENT_PARENT_TEXT_KEY = "ECPTK";
|
||||||
|
public static final String EXTRA_COMMENT_PARENT_BODY_KEY = "ECPBK";
|
||||||
public static final String EXTRA_PARENT_FULLNAME_KEY = "EPFK";
|
public static final String EXTRA_PARENT_FULLNAME_KEY = "EPFK";
|
||||||
public static final String EXTRA_COMMENT_DATA_KEY = "ECDK";
|
|
||||||
public static final String EXTRA_PARENT_DEPTH_KEY = "EPDK";
|
public static final String EXTRA_PARENT_DEPTH_KEY = "EPDK";
|
||||||
public static final String EXTRA_PARENT_POSITION_KEY = "EPPK";
|
public static final String EXTRA_PARENT_POSITION_KEY = "EPPK";
|
||||||
public static final String EXTRA_IS_REPLYING_KEY = "EIRK";
|
public static final String EXTRA_IS_REPLYING_KEY = "EIRK";
|
||||||
|
public static final String RETURN_EXTRA_COMMENT_DATA_KEY = "RECDK";
|
||||||
public static final int WRITE_COMMENT_REQUEST_CODE = 1;
|
public static final int WRITE_COMMENT_REQUEST_CODE = 1;
|
||||||
|
|
||||||
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
||||||
@ -63,6 +75,8 @@ public class CommentActivity extends BaseActivity {
|
|||||||
Toolbar toolbar;
|
Toolbar toolbar;
|
||||||
@BindView(R.id.comment_parent_markwon_view_comment_activity)
|
@BindView(R.id.comment_parent_markwon_view_comment_activity)
|
||||||
TextView commentParentMarkwonView;
|
TextView commentParentMarkwonView;
|
||||||
|
@BindView(R.id.content_markdown_view_comment_activity)
|
||||||
|
RecyclerView contentMarkdownRecyclerView;
|
||||||
@BindView(R.id.comment_edit_text_comment_activity)
|
@BindView(R.id.comment_edit_text_comment_activity)
|
||||||
EditText commentEditText;
|
EditText commentEditText;
|
||||||
@Inject
|
@Inject
|
||||||
@ -128,6 +142,52 @@ public class CommentActivity extends BaseActivity {
|
|||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
markwon.setMarkdown(commentParentMarkwonView, intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_KEY));
|
markwon.setMarkdown(commentParentMarkwonView, intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_KEY));
|
||||||
|
String parentBody = intent.getStringExtra(EXTRA_COMMENT_PARENT_BODY_KEY);
|
||||||
|
if (parentBody != null && !parentBody.equals("")) {
|
||||||
|
contentMarkdownRecyclerView.setVisibility(View.VISIBLE);
|
||||||
|
contentMarkdownRecyclerView.setNestedScrollingEnabled(false);
|
||||||
|
int markdownColor = ContextCompat.getColor(this, R.color.defaultTextColor);
|
||||||
|
Markwon postBodyMarkwon = Markwon.builder(this)
|
||||||
|
.usePlugin(new AbstractMarkwonPlugin() {
|
||||||
|
@Override
|
||||||
|
public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) {
|
||||||
|
textView.setTextColor(markdownColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
|
||||||
|
builder.linkResolver((view, link) -> {
|
||||||
|
Intent intent = new Intent(CommentActivity.this, LinkResolverActivity.class);
|
||||||
|
Uri uri = Uri.parse(link);
|
||||||
|
if (uri.getScheme() == null && uri.getHost() == null) {
|
||||||
|
intent.setData(LinkResolverActivity.getRedditUriByPath(link));
|
||||||
|
} else {
|
||||||
|
intent.setData(uri);
|
||||||
|
}
|
||||||
|
startActivity(intent);
|
||||||
|
}).urlProcessor(new UrlProcessorRelativeToAbsolute("https://www.reddit.com"));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.usePlugin(StrikethroughPlugin.create())
|
||||||
|
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
|
||||||
|
.usePlugin(SimpleExtPlugin.create(plugin ->
|
||||||
|
plugin.addExtension(1, '^', (configuration, props) -> {
|
||||||
|
return new SuperscriptSpan();
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.usePlugin(TableEntryPlugin.create(this))
|
||||||
|
.build();
|
||||||
|
MarkwonAdapter markwonAdapter = MarkwonAdapter.builder(R.layout.adapter_default_entry, R.id.text)
|
||||||
|
.include(TableBlock.class, TableEntry.create(builder -> builder
|
||||||
|
.tableLayout(R.layout.adapter_table_block, R.id.table_layout)
|
||||||
|
.textLayoutIsRoot(R.layout.view_table_entry_cell)))
|
||||||
|
.build();
|
||||||
|
contentMarkdownRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
contentMarkdownRecyclerView.setAdapter(markwonAdapter);
|
||||||
|
markwonAdapter.setMarkdown(postBodyMarkwon, parentBody);
|
||||||
|
markwonAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
parentFullname = intent.getStringExtra(EXTRA_PARENT_FULLNAME_KEY);
|
parentFullname = intent.getStringExtra(EXTRA_PARENT_FULLNAME_KEY);
|
||||||
parentDepth = intent.getExtras().getInt(EXTRA_PARENT_DEPTH_KEY);
|
parentDepth = intent.getExtras().getInt(EXTRA_PARENT_DEPTH_KEY);
|
||||||
parentPosition = intent.getExtras().getInt(EXTRA_PARENT_POSITION_KEY);
|
parentPosition = intent.getExtras().getInt(EXTRA_PARENT_POSITION_KEY);
|
||||||
@ -205,7 +265,7 @@ public class CommentActivity extends BaseActivity {
|
|||||||
item.getIcon().setAlpha(255);
|
item.getIcon().setAlpha(255);
|
||||||
Toast.makeText(CommentActivity.this, R.string.send_comment_success, Toast.LENGTH_SHORT).show();
|
Toast.makeText(CommentActivity.this, R.string.send_comment_success, Toast.LENGTH_SHORT).show();
|
||||||
Intent returnIntent = new Intent();
|
Intent returnIntent = new Intent();
|
||||||
returnIntent.putExtra(EXTRA_COMMENT_DATA_KEY, commentData);
|
returnIntent.putExtra(RETURN_EXTRA_COMMENT_DATA_KEY, commentData);
|
||||||
returnIntent.putExtra(EXTRA_PARENT_FULLNAME_KEY, parentFullname);
|
returnIntent.putExtra(EXTRA_PARENT_FULLNAME_KEY, parentFullname);
|
||||||
if (isReplying) {
|
if (isReplying) {
|
||||||
returnIntent.putExtra(EXTRA_PARENT_POSITION_KEY, parentPosition);
|
returnIntent.putExtra(EXTRA_PARENT_POSITION_KEY, parentPosition);
|
||||||
|
@ -87,7 +87,7 @@ import retrofit2.Callback;
|
|||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
import static ml.docilealligator.infinityforreddit.Activity.CommentActivity.EXTRA_COMMENT_DATA_KEY;
|
import static ml.docilealligator.infinityforreddit.Activity.CommentActivity.RETURN_EXTRA_COMMENT_DATA_KEY;
|
||||||
import static ml.docilealligator.infinityforreddit.Activity.CommentActivity.WRITE_COMMENT_REQUEST_CODE;
|
import static ml.docilealligator.infinityforreddit.Activity.CommentActivity.WRITE_COMMENT_REQUEST_CODE;
|
||||||
|
|
||||||
public class ViewPostDetailActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback,
|
public class ViewPostDetailActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback,
|
||||||
@ -1317,6 +1317,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
|
|||||||
|
|
||||||
Intent intent = new Intent(this, CommentActivity.class);
|
Intent intent = new Intent(this, CommentActivity.class);
|
||||||
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, mPost.getTitle());
|
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, mPost.getTitle());
|
||||||
|
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_KEY, mPost.getSelfText());
|
||||||
intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, mPost.getFullName());
|
intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, mPost.getFullName());
|
||||||
intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0);
|
intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0);
|
||||||
intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false);
|
intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false);
|
||||||
@ -1485,8 +1486,8 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
|
|||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
if (requestCode == WRITE_COMMENT_REQUEST_CODE) {
|
if (requestCode == WRITE_COMMENT_REQUEST_CODE) {
|
||||||
if (data != null && resultCode == RESULT_OK) {
|
if (data != null && resultCode == RESULT_OK) {
|
||||||
if (data.hasExtra(EXTRA_COMMENT_DATA_KEY)) {
|
if (data.hasExtra(RETURN_EXTRA_COMMENT_DATA_KEY)) {
|
||||||
CommentData comment = data.getParcelableExtra(EXTRA_COMMENT_DATA_KEY);
|
CommentData comment = data.getParcelableExtra(RETURN_EXTRA_COMMENT_DATA_KEY);
|
||||||
if (comment != null && comment.getDepth() == 0) {
|
if (comment != null && comment.getDepth() == 0) {
|
||||||
mAdapter.addComment(comment);
|
mAdapter.addComment(comment);
|
||||||
} else {
|
} else {
|
||||||
|
@ -218,7 +218,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
.tableLayout(R.layout.adapter_table_block, R.id.table_layout)
|
.tableLayout(R.layout.adapter_table_block, R.id.table_layout)
|
||||||
.textLayoutIsRoot(R.layout.view_table_entry_cell)))
|
.textLayoutIsRoot(R.layout.view_table_entry_cell)))
|
||||||
.build();
|
.build();
|
||||||
mMarkwonAdapter.setMarkdown(mPostDetailMarkwon, "");
|
|
||||||
mAccessToken = accessToken;
|
mAccessToken = accessToken;
|
||||||
mAccountName = accountName;
|
mAccountName = accountName;
|
||||||
mPost = post;
|
mPost = post;
|
||||||
@ -624,6 +623,16 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
}
|
}
|
||||||
|
|
||||||
((PostDetailViewHolder) holder).commentsCountTextView.setOnClickListener(view -> {
|
((PostDetailViewHolder) holder).commentsCountTextView.setOnClickListener(view -> {
|
||||||
|
if (mPost.isArchived()) {
|
||||||
|
Toast.makeText(mActivity, R.string.archived_post_reply_unavailable, Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mPost.isLocked()) {
|
||||||
|
Toast.makeText(mActivity, R.string.locked_post_comment_unavailable, Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mAccessToken == null) {
|
if (mAccessToken == null) {
|
||||||
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
|
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
@ -632,6 +641,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
Intent intent = new Intent(mActivity, CommentActivity.class);
|
Intent intent = new Intent(mActivity, CommentActivity.class);
|
||||||
intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, mPost.getFullName());
|
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_TEXT_KEY, mPost.getTitle());
|
||||||
|
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_KEY, mPost.getSelfText());
|
||||||
intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false);
|
intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false);
|
||||||
intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0);
|
intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0);
|
||||||
mActivity.startActivityForResult(intent, WRITE_COMMENT_REQUEST_CODE);
|
mActivity.startActivityForResult(intent, WRITE_COMMENT_REQUEST_CODE);
|
||||||
|
@ -31,21 +31,39 @@
|
|||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical">
|
||||||
android:padding="16dp">
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/comment_parent_markwon_view_comment_activity"
|
android:id="@+id/comment_parent_markwon_view_comment_activity"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="16dp"
|
||||||
|
android:textColor="@color/primaryTextColor"
|
||||||
|
android:textSize="?attr/title_font_16" />
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/content_markdown_view_comment_activity"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:textSize="?attr/content_font_16" />
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:background="@color/dividerColor" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/comment_edit_text_comment_activity"
|
android:id="@+id/comment_edit_text_comment_activity"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="top"
|
android:gravity="top"
|
||||||
|
android:paddingBottom="16dp"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
android:hint="@string/write_comment_hint"
|
android:hint="@string/write_comment_hint"
|
||||||
android:inputType="textCapSentences|textMultiLine"
|
android:inputType="textCapSentences|textMultiLine"
|
||||||
android:textSize="?attr/content_font_18"
|
android:textSize="?attr/content_font_18"
|
||||||
|
@ -124,7 +124,7 @@
|
|||||||
<string name="lazy_mode_start">Lazy Mode starts in %1$.1fs</string>
|
<string name="lazy_mode_start">Lazy Mode starts in %1$.1fs</string>
|
||||||
<string name="lazy_mode_stop">Lazy Mode stopped</string>
|
<string name="lazy_mode_stop">Lazy Mode stopped</string>
|
||||||
|
|
||||||
<string name="write_comment_hint">Your interesting thought here</string>
|
<string name="write_comment_hint">Your interesting thoughts here</string>
|
||||||
<string name="comment_content_required">Where is your interesting thought?</string>
|
<string name="comment_content_required">Where is your interesting thought?</string>
|
||||||
<string name="sending_comment">Sending</string>
|
<string name="sending_comment">Sending</string>
|
||||||
<string name="send_comment_success">Comment sent</string>
|
<string name="send_comment_success">Comment sent</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user