Browse Source

save post content and bbcontent in a separate variable

pull/61/merge
oogee 6 years ago
parent
commit
d61600dfba
  1. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  2. 13
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  3. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java
  4. 31
      app/src/main/java/gr/thmmy/mthmmy/model/Post.java

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

@ -278,7 +278,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
// 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);
Post reply = (Post) topicItems.get(topicItems.size() - 1); Post reply = (Post) topicItems.get(topicItems.size() - 1);
drafts.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getContent()).apply(); drafts.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getBbContent()).apply();
topicItems.remove(topicItems.size() - 1); topicItems.remove(topicItems.size() - 1);
topicAdapter.notifyItemRemoved(topicItems.size()); topicAdapter.notifyItemRemoved(topicItems.size());
@ -322,7 +322,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
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);
Post reply = (Post) topicItems.get(topicItems.size() - 1); Post reply = (Post) topicItems.get(topicItems.size() - 1);
drafts.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getContent()).apply(); drafts.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getBbContent()).apply();
} }
} }
@ -550,7 +550,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
if (viewModel.isWritingReply()) { if (viewModel.isWritingReply()) {
SharedPreferences drafts2 = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE); SharedPreferences drafts2 = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE);
Post reply = (Post) topicItems.get(topicItems.size() - 1); Post reply = (Post) topicItems.get(topicItems.size() - 1);
drafts2.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getContent()).apply(); drafts2.edit().putString(String.valueOf(viewModel.getTopicId()), reply.getBbContent()).apply();
viewModel.setWritingReply(false); viewModel.setWritingReply(false);
} }

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

@ -642,8 +642,8 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
String replyText = ""; String replyText = "";
if (reply.getContent() != null) if (reply.getBbContent() != null)
replyText += reply.getContent(); replyText += reply.getBbContent();
else { else {
SharedPreferences drafts = context.getSharedPreferences(context.getString(R.string.pref_topic_drafts_key), SharedPreferences drafts = context.getSharedPreferences(context.getString(R.string.pref_topic_drafts_key),
Context.MODE_PRIVATE); Context.MODE_PRIVATE);
@ -666,7 +666,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@Override @Override
public void afterTextChanged(Editable editable) { public void afterTextChanged(Editable editable) {
((Post) topicItems.get(holder.getAdapterPosition())).setContent(editable.toString()); ((Post) topicItems.get(holder.getAdapterPosition())).setBbContent(editable.toString());
} }
}); });
@ -704,7 +704,10 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
holder.editEditor.setEmojiKeyboard(emojiKeyboard); holder.editEditor.setEmojiKeyboard(emojiKeyboard);
holder.editEditor.requestEditTextFocus(); holder.editEditor.requestEditTextFocus();
emojiKeyboard.registerEmojiInputField(holder.editEditor); emojiKeyboard.registerEmojiInputField(holder.editEditor);
holder.editEditor.setText(viewModel.getPostBeingEditedText()); if (currentPost.getBbContent() == null)
holder.editEditor.setText(viewModel.getPostBeingEditedText());
else
holder.editEditor.setText(currentPost.getBbContent());
holder.editEditor.getEditText().setSelection(holder.editEditor.getText().length()); holder.editEditor.getEditText().setSelection(holder.editEditor.getText().length());
holder.editEditor.setOnSubmitListener(view -> { holder.editEditor.setOnSubmitListener(view -> {
if (holder.editSubject.getText().toString().isEmpty()) return; if (holder.editSubject.getText().toString().isEmpty()) return;
@ -750,7 +753,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@Override @Override
public void afterTextChanged(Editable editable) { public void afterTextChanged(Editable editable) {
((Post) topicItems.get(holder.getAdapterPosition())).setContent(editable.toString()); ((Post) topicItems.get(holder.getAdapterPosition())).setBbContent(editable.toString());
} }
}); });
if (backPressHidden) { if (backPressHidden) {

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

@ -461,7 +461,7 @@ public class TopicParser {
} }
//Add new post in postsList, extended information needed //Add new post in postsList, extended information needed
parsedPostsList.add(new Post(p_thumbnailURL, p_userName, p_subject, p_post, p_postIndex parsedPostsList.add(new Post(p_thumbnailURL, p_userName, p_subject, p_post, null, p_postIndex
, p_postNum, p_postDate, p_profileURL, p_rank, p_specialRank, p_gender , p_postNum, p_postDate, p_profileURL, p_rank, p_specialRank, p_gender
, p_numberOfPosts, p_personalText, p_numberOfStars, p_userColor , p_numberOfPosts, p_personalText, p_numberOfStars, p_userColor
, p_attachedFiles, p_postLastEditDate, p_postURL, p_deletePostURL, p_editPostURL , p_attachedFiles, p_postLastEditDate, p_postURL, p_deletePostURL, p_editPostURL
@ -470,7 +470,7 @@ public class TopicParser {
} else { //Deleted user } else { //Deleted user
//Add new post in postsList, only standard information needed //Add new post in postsList, only standard information needed
parsedPostsList.add(new Post(p_thumbnailURL, p_userName, p_subject, p_post parsedPostsList.add(new Post(p_thumbnailURL, p_userName, p_subject, p_post
, p_postIndex, p_postNum, p_postDate, p_userColor, p_attachedFiles , null, p_postIndex, p_postNum, p_postDate, p_userColor, p_attachedFiles
, p_postLastEditDate, p_postURL, p_deletePostURL, p_editPostURL , p_postLastEditDate, p_postURL, p_deletePostURL, p_editPostURL
, p_isUserMentionedInPost, Post.TYPE_POST)); , p_isUserMentionedInPost, Post.TYPE_POST));
} }

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

@ -25,6 +25,7 @@ public class Post extends TopicItem {
private final String author; private final String author;
private String subject; private String subject;
private String content; private String content;
private String bbContent;
private final int postIndex; private final int postIndex;
private final int postNumber; private final int postNumber;
private final String postDate; private final String postDate;
@ -49,7 +50,8 @@ public class Post extends TopicItem {
// Suppresses default constructor // Suppresses default constructor
@SuppressWarnings("unused") @SuppressWarnings("unused")
private Post() { private Post(String bbContent) {
this.bbContent = bbContent;
thumbnailUrl = ""; thumbnailUrl = "";
author = null; author = null;
subject = null; subject = null;
@ -79,11 +81,11 @@ public class Post extends TopicItem {
* Constructor for active user's posts. All variables are declared final, once assigned they * Constructor for active user's posts. All variables are declared final, once assigned they
* can not change. Parameters notated as {@link Nullable} can either pass null or empty * can not change. Parameters notated as {@link Nullable} can either pass null or empty
* (strings/ArrayList). * (strings/ArrayList).
* * @param thumbnailUrl author's thumbnail url
* @param thumbnailUrl author's thumbnail url
* @param author author's username * @param author author's username
* @param subject post's subject * @param subject post's subject
* @param content post itself * @param content post itself
* @param bbContent
* @param postIndex post's index on the forum * @param postIndex post's index on the forum
* @param postNumber posts index number on this topic * @param postNumber posts index number on this topic
* @param postDate date of submission * @param postDate date of submission
@ -100,12 +102,13 @@ public class Post extends TopicItem {
* @param postURL post's URL * @param postURL post's URL
*/ */
public Post(@Nullable String thumbnailUrl, String author, String subject, String content public Post(@Nullable String thumbnailUrl, String author, String subject, String content
, int postIndex, int postNumber, String postDate, String profileURl, @Nullable String rank , String bbContent, int postIndex, int postNumber, String postDate, String profileURl, @Nullable String rank
, @Nullable String special_rank, @Nullable String gender, @Nullable String numberOfPosts , @Nullable String special_rank, @Nullable String gender, @Nullable String numberOfPosts
, @Nullable String personalText, int numberOfStars, int userColor , @Nullable String personalText, int numberOfStars, int userColor
, @Nullable ArrayList<ThmmyFile> attachedFiles, @Nullable String lastEdit, String postURL , @Nullable ArrayList<ThmmyFile> attachedFiles, @Nullable String lastEdit, String postURL
, @Nullable String postDeleteURL, @Nullable String postEditURL, boolean isUserMentionedInPost , @Nullable String postDeleteURL, @Nullable String postEditURL, boolean isUserMentionedInPost
, int postType) { , int postType) {
this.bbContent = bbContent;
if (Objects.equals(thumbnailUrl, "")) this.thumbnailUrl = null; if (Objects.equals(thumbnailUrl, "")) this.thumbnailUrl = null;
else this.thumbnailUrl = thumbnailUrl; else this.thumbnailUrl = thumbnailUrl;
this.author = author; this.author = author;
@ -136,11 +139,11 @@ public class Post extends TopicItem {
* Constructor for deleted user's posts. All variables are declared final, once assigned they * Constructor for deleted user's posts. All variables are declared final, once assigned they
* can not change. Parameters notated as {@link Nullable} can either pass null or empty * can not change. Parameters notated as {@link Nullable} can either pass null or empty
* (strings/ArrayList). * (strings/ArrayList).
* * @param thumbnailUrl author's thumbnail url
* @param thumbnailUrl author's thumbnail url
* @param author author's username * @param author author's username
* @param subject post's subject * @param subject post's subject
* @param content post itself * @param content post itself
* @param bbContent post content in bb form
* @param postIndex post's index on the forum * @param postIndex post's index on the forum
* @param postNumber posts index number on this topic * @param postNumber posts index number on this topic
* @param postDate date of submission * @param postDate date of submission
@ -150,10 +153,11 @@ public class Post extends TopicItem {
* @param postURL post's URL * @param postURL post's URL
*/ */
public Post(@Nullable String thumbnailUrl, String author, String subject, String content public Post(@Nullable String thumbnailUrl, String author, String subject, String content
, int postIndex, int postNumber, String postDate, int userColor , String bbContent, int postIndex, int postNumber, String postDate, int userColor
, @Nullable ArrayList<ThmmyFile> attachedFiles, @Nullable String lastEdit, String postURL , @Nullable ArrayList<ThmmyFile> attachedFiles, @Nullable String lastEdit, String postURL
, @Nullable String postDeleteURL, @Nullable String postEditURL, boolean isUserMentionedInPost , @Nullable String postDeleteURL, @Nullable String postEditURL, boolean isUserMentionedInPost
, int postType) { , int postType) {
this.bbContent = bbContent;
if (Objects.equals(thumbnailUrl, "")) this.thumbnailUrl = null; if (Objects.equals(thumbnailUrl, "")) this.thumbnailUrl = null;
else this.thumbnailUrl = thumbnailUrl; else this.thumbnailUrl = thumbnailUrl;
this.author = author; this.author = author;
@ -181,12 +185,12 @@ public class Post extends TopicItem {
} }
public static Post newQuickReply() { public static Post newQuickReply() {
return new Post(null, null, null, null, 0, 0, null, return new Post(null, null, null, null, null, 0, 0, null,
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) { public static Post newQuickReply(String subject, String content) {
return new Post(null, null, subject, content, 0, 0, null, return new Post(null, null, subject, null, content, 0, 0, null,
0, null, null, null, null, null, false, TYPE_QUICK_REPLY); 0, null, null, null, null, null, false, TYPE_QUICK_REPLY);
} }
@ -212,11 +216,20 @@ public class Post extends TopicItem {
return content; return content;
} }
public String getBbContent() {
return bbContent;
}
public void setBbContent(String bbContent) {
this.bbContent = bbContent;
}
/** /**
* Gets this post's author. * Gets this post's author.
* *
* @return post's author * @return post's author
*/ */
@Nullable @Nullable
public String getAuthor() { public String getAuthor() {
return author; return author;

Loading…
Cancel
Save