Browse Source

draft fixes

pull/61/merge
oogee 6 years ago
parent
commit
ecd1b1f92c
  1. 15
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  2. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  3. 12
      app/src/main/java/gr/thmmy/mthmmy/model/Post.java
  4. 17
      app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java

15
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java

@ -274,9 +274,8 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
} else if (viewModel.isWritingReply()) { } else if (viewModel.isWritingReply()) {
// persist reply // persist reply
SharedPreferences drafts = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE); SharedPreferences drafts = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE);
Editable cachedReply = viewModel.getCachedReply(); Post reply = (Post) topicItems.get(topicItems.size() - 1);
if (cachedReply != null) drafts.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getContent()).apply();
drafts.edit().putString(String.valueOf(viewModel.getTopicId()), cachedReply.toString()).apply();
topicItems.remove(topicItems.size() - 1); topicItems.remove(topicItems.size() - 1);
topicAdapter.notifyItemRemoved(topicItems.size()); topicAdapter.notifyItemRemoved(topicItems.size());
@ -317,9 +316,8 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
// persist reply // persist reply
if (viewModel.isWritingReply()) { if (viewModel.isWritingReply()) {
SharedPreferences drafts = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE); SharedPreferences drafts = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE);
Editable cachedReply = viewModel.getCachedReply(); Post reply = (Post) topicItems.get(topicItems.size() - 1);
if (cachedReply != null) drafts.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getContent()).apply();
drafts.edit().putString(String.valueOf(viewModel.getTopicId()), cachedReply.toString()).apply();
} }
} }
@ -536,11 +534,10 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
break; break;
case NEW_REPLY_WHILE_POSTING: case NEW_REPLY_WHILE_POSTING:
Timber.i("New reply while writing a reply"); Timber.i("New reply while writing a reply");
Editable subject = viewModel.getCachedSubject(); Post reply = (Post) topicItems.get(topicItems.size() - 1);
Editable message = viewModel.getCachedReply();
Runnable addReply = () -> { Runnable addReply = () -> {
viewModel.setWritingReply(true); viewModel.setWritingReply(true);
topicItems.add(Post.newQuickReply(subject.toString(), message.toString())); topicItems.add(Post.newQuickReply(reply.getSubject(), reply.getContent()));
topicAdapter.notifyItemInserted(topicItems.size()); topicAdapter.notifyItemInserted(topicItems.size());
recyclerView.scrollToPosition(topicItems.size() - 1); recyclerView.scrollToPosition(topicItems.size() - 1);
replyFAB.hide(); replyFAB.hide();

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

@ -672,7 +672,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@Override @Override
public void afterTextChanged(Editable editable) { public void afterTextChanged(Editable editable) {
viewModel.setCachedReply(editable); ((Post) topicItems.get(holder.getAdapterPosition())).setContent(editable.toString());
} }
}); });
@ -693,7 +693,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@Override @Override
public void afterTextChanged(Editable editable) { public void afterTextChanged(Editable editable) {
viewModel.setCachedSubject(editable); ((Post) topicItems.get(holder.getAdapterPosition())).setSubject(editable.toString());
} }
}); });
} else if (currentHolder instanceof EditMessageViewHolder) { } else if (currentHolder instanceof EditMessageViewHolder) {

12
app/src/main/java/gr/thmmy/mthmmy/model/Post.java

@ -23,8 +23,8 @@ public class Post extends TopicItem {
//Standard info (exists in every post) //Standard info (exists in every post)
private final String thumbnailUrl; private final String thumbnailUrl;
private final String author; private final String author;
private final String subject; private String subject;
private final String content; private String content;
private final int postIndex; private final int postIndex;
private final int postNumber; private final int postNumber;
private final String postDate; private final String postDate;
@ -408,4 +408,12 @@ public class Post extends TopicItem {
public void setPostType(int postType) { public void setPostType(int postType) {
this.postType = postType; this.postType = postType;
} }
public void setContent(String content) {
this.content = content;
}
public void setSubject(String subject) {
this.subject = subject;
}
} }

17
app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java

@ -41,7 +41,6 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
*/ */
private boolean editingPost = false; private boolean editingPost = false;
private boolean writingReply = false; private boolean writingReply = false;
private Editable cachedSubject, cachedReply;
/** /**
* A list of {@link Post#getPostIndex()} for building quotes for replying * A list of {@link Post#getPostIndex()} for building quotes for replying
*/ */
@ -488,20 +487,4 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
throw new NullPointerException("No page has been loaded yet!"); throw new NullPointerException("No page has been loaded yet!");
return topicItems.getValue().size(); return topicItems.getValue().size();
} }
public Editable getCachedSubject() {
return cachedSubject;
}
public void setCachedSubject(Editable cachedSubject) {
this.cachedSubject = cachedSubject;
}
public Editable getCachedReply() {
return cachedReply;
}
public void setCachedReply(Editable cachedReply) {
this.cachedReply = cachedReply;
}
} }

Loading…
Cancel
Save