From be481ed4a07f0027d653617ee0f48bc174eeed3e Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Mon, 22 Oct 2018 17:55:36 +0300 Subject: [PATCH] maybe fix parallel posting --- .../mthmmy/activities/topic/TopicActivity.java | 6 +----- .../mthmmy/activities/topic/TopicAdapter.java | 14 ++++++++++++-- app/src/main/java/gr/thmmy/mthmmy/model/Post.java | 5 +++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index 88be719c..46c8678b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java @@ -522,15 +522,11 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo String message = replyHolder.replyEditor.getText().toString(); Runnable addReply = () -> { viewModel.setWritingReply(true); - topicItems.add(Post.newQuickReply()); + topicItems.add(Post.newQuickReply(subject, message)); topicAdapter.notifyItemInserted(topicItems.size()); recyclerView.scrollToPosition(topicItems.size() - 1); replyFAB.hide(); bottomNavBar.setVisibility(View.GONE); - TopicAdapter.QuickReplyViewHolder newReplyHolder = (TopicAdapter.QuickReplyViewHolder) - recyclerView.findViewHolderForAdapterPosition(topicItems.size() - 1); - newReplyHolder.quickReplySubject.setText(subject); - newReplyHolder.replyEditor.setText(message); AlertDialog.Builder builder = new AlertDialog.Builder(TopicActivity.this, R.style.AppCompatAlertDialogStyleAccent); builder.setMessage("A new reply was posted before you completed your new post." + diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index 53ef01cc..23073331 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -572,6 +572,7 @@ class TopicAdapter extends RecyclerView.Adapter { } } else if (currentHolder instanceof QuickReplyViewHolder) { final QuickReplyViewHolder holder = (QuickReplyViewHolder) currentHolder; + Post reply = (Post) topicItems.get(position); //noinspection ConstantConditions Picasso.with(context) @@ -585,7 +586,11 @@ class TopicAdapter extends RecyclerView.Adapter { .transform(new CircleTransform()) .into(holder.thumbnail); holder.username.setText(getSessionManager().getUsername()); - holder.quickReplySubject.setText("Re: " + viewModel.getTopicTitle().getValue()); + if (reply.getSubject() != null) { + holder.quickReplySubject.setText(reply.getSubject()); + } else { + holder.quickReplySubject.setText("Re: " + viewModel.getTopicTitle().getValue()); + } holder.quickReplySubject.setRawInputType(InputType.TYPE_CLASS_TEXT); holder.quickReplySubject.setImeOptions(EditorInfo.IME_ACTION_DONE); @@ -593,7 +598,6 @@ class TopicAdapter extends RecyclerView.Adapter { holder.replyEditor.requestEditTextFocus(); emojiKeyboard.registerEmojiInputField(holder.replyEditor); - holder.replyEditor.setText(viewModel.getBuildedQuotes()); holder.replyEditor.setOnSubmitListener(view -> { if (holder.quickReplySubject.getText().toString().isEmpty()) return; if (holder.replyEditor.getText().toString().isEmpty()) { @@ -611,6 +615,12 @@ class TopicAdapter extends RecyclerView.Adapter { }); holder.replyEditor.setOnClickListener(view -> holder.replyEditor.setError(null)); + if (reply.getContent() != null) { + holder.replyEditor.setText(reply.getContent()); + } else { + holder.replyEditor.setText(viewModel.getBuildedQuotes()); + } + if (backPressHidden) { holder.replyEditor.requestFocus(); backPressHidden = false; diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Post.java b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java index f3c9bd8d..da68d1e6 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Post.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java @@ -185,6 +185,11 @@ public class Post extends TopicItem { 0, null, null, null, null, null, false, TYPE_QUICK_REPLY); } + public static Post newQuickReply(String subject, String content) { + return new Post(null, null, subject, content, 0, 0, null, + 0, null, null, null, null, null, false, TYPE_QUICK_REPLY); + } + //Getters /**