Browse Source

maybe fix parallel posting

pull/61/merge
Thodoris1999 6 years ago
parent
commit
be481ed4a0
  1. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  2. 14
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  3. 5
      app/src/main/java/gr/thmmy/mthmmy/model/Post.java

6
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(); String message = replyHolder.replyEditor.getText().toString();
Runnable addReply = () -> { Runnable addReply = () -> {
viewModel.setWritingReply(true); viewModel.setWritingReply(true);
topicItems.add(Post.newQuickReply()); topicItems.add(Post.newQuickReply(subject, message));
topicAdapter.notifyItemInserted(topicItems.size()); topicAdapter.notifyItemInserted(topicItems.size());
recyclerView.scrollToPosition(topicItems.size() - 1); recyclerView.scrollToPosition(topicItems.size() - 1);
replyFAB.hide(); replyFAB.hide();
bottomNavBar.setVisibility(View.GONE); 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, AlertDialog.Builder builder = new AlertDialog.Builder(TopicActivity.this,
R.style.AppCompatAlertDialogStyleAccent); R.style.AppCompatAlertDialogStyleAccent);
builder.setMessage("A new reply was posted before you completed your new post." + builder.setMessage("A new reply was posted before you completed your new post." +

14
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

@ -572,6 +572,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
} }
} else if (currentHolder instanceof QuickReplyViewHolder) { } else if (currentHolder instanceof QuickReplyViewHolder) {
final QuickReplyViewHolder holder = (QuickReplyViewHolder) currentHolder; final QuickReplyViewHolder holder = (QuickReplyViewHolder) currentHolder;
Post reply = (Post) topicItems.get(position);
//noinspection ConstantConditions //noinspection ConstantConditions
Picasso.with(context) Picasso.with(context)
@ -585,7 +586,11 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
.transform(new CircleTransform()) .transform(new CircleTransform())
.into(holder.thumbnail); .into(holder.thumbnail);
holder.username.setText(getSessionManager().getUsername()); 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.setRawInputType(InputType.TYPE_CLASS_TEXT);
holder.quickReplySubject.setImeOptions(EditorInfo.IME_ACTION_DONE); holder.quickReplySubject.setImeOptions(EditorInfo.IME_ACTION_DONE);
@ -593,7 +598,6 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
holder.replyEditor.requestEditTextFocus(); holder.replyEditor.requestEditTextFocus();
emojiKeyboard.registerEmojiInputField(holder.replyEditor); emojiKeyboard.registerEmojiInputField(holder.replyEditor);
holder.replyEditor.setText(viewModel.getBuildedQuotes());
holder.replyEditor.setOnSubmitListener(view -> { holder.replyEditor.setOnSubmitListener(view -> {
if (holder.quickReplySubject.getText().toString().isEmpty()) return; if (holder.quickReplySubject.getText().toString().isEmpty()) return;
if (holder.replyEditor.getText().toString().isEmpty()) { if (holder.replyEditor.getText().toString().isEmpty()) {
@ -611,6 +615,12 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}); });
holder.replyEditor.setOnClickListener(view -> holder.replyEditor.setError(null)); 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) { if (backPressHidden) {
holder.replyEditor.requestFocus(); holder.replyEditor.requestFocus();
backPressHidden = false; backPressHidden = false;

5
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); 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 //Getters
/** /**

Loading…
Cancel
Save