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()) {
// persist reply
SharedPreferences drafts = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE);
Editable cachedReply = viewModel.getCachedReply();
if (cachedReply != null)
drafts.edit().putString(String.valueOf(viewModel.getTopicId()), cachedReply.toString()).apply();
Post reply = (Post) topicItems.get(topicItems.size() - 1);
drafts.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getContent()).apply();
topicItems.remove(topicItems.size() - 1);
topicAdapter.notifyItemRemoved(topicItems.size());
@ -317,9 +316,8 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
// persist reply
if (viewModel.isWritingReply()) {
SharedPreferences drafts = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE);
Editable cachedReply = viewModel.getCachedReply();
if (cachedReply != null)
drafts.edit().putString(String.valueOf(viewModel.getTopicId()), cachedReply.toString()).apply();
Post reply = (Post) topicItems.get(topicItems.size() - 1);
drafts.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getContent()).apply();
}
}
@ -536,11 +534,10 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
break;
case NEW_REPLY_WHILE_POSTING:
Timber.i("New reply while writing a reply");
Editable subject = viewModel.getCachedSubject();
Editable message = viewModel.getCachedReply();
Post reply = (Post) topicItems.get(topicItems.size() - 1);
Runnable addReply = () -> {
viewModel.setWritingReply(true);
topicItems.add(Post.newQuickReply(subject.toString(), message.toString()));
topicItems.add(Post.newQuickReply(reply.getSubject(), reply.getContent()));
topicAdapter.notifyItemInserted(topicItems.size());
recyclerView.scrollToPosition(topicItems.size() - 1);
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
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
public void afterTextChanged(Editable editable) {
viewModel.setCachedSubject(editable);
((Post) topicItems.get(holder.getAdapterPosition())).setSubject(editable.toString());
}
});
} 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)
private final String thumbnailUrl;
private final String author;
private final String subject;
private final String content;
private String subject;
private String content;
private final int postIndex;
private final int postNumber;
private final String postDate;
@ -408,4 +408,12 @@ public class Post extends TopicItem {
public void setPostType(int 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 writingReply = false;
private Editable cachedSubject, cachedReply;
/**
* 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!");
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