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
SharedPreferences drafts = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE);
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);
topicAdapter.notifyItemRemoved(topicItems.size());
@ -322,7 +322,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
if (viewModel.isWritingReply()) {
SharedPreferences drafts = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE);
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()) {
SharedPreferences drafts2 = getSharedPreferences(getString(R.string.pref_topic_drafts_key), MODE_PRIVATE);
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);
}

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 = "";
if (reply.getContent() != null)
replyText += reply.getContent();
if (reply.getBbContent() != null)
replyText += reply.getBbContent();
else {
SharedPreferences drafts = context.getSharedPreferences(context.getString(R.string.pref_topic_drafts_key),
Context.MODE_PRIVATE);
@ -666,7 +666,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@Override
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.requestEditTextFocus();
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.setOnSubmitListener(view -> {
if (holder.editSubject.getText().toString().isEmpty()) return;
@ -750,7 +753,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@Override
public void afterTextChanged(Editable editable) {
((Post) topicItems.get(holder.getAdapterPosition())).setContent(editable.toString());
((Post) topicItems.get(holder.getAdapterPosition())).setBbContent(editable.toString());
}
});
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
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_numberOfPosts, p_personalText, p_numberOfStars, p_userColor
, p_attachedFiles, p_postLastEditDate, p_postURL, p_deletePostURL, p_editPostURL
@ -470,7 +470,7 @@ public class TopicParser {
} else { //Deleted user
//Add new post in postsList, only standard information needed
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_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 String subject;
private String content;
private String bbContent;
private final int postIndex;
private final int postNumber;
private final String postDate;
@ -49,7 +50,8 @@ public class Post extends TopicItem {
// Suppresses default constructor
@SuppressWarnings("unused")
private Post() {
private Post(String bbContent) {
this.bbContent = bbContent;
thumbnailUrl = "";
author = 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
* can not change. Parameters notated as {@link Nullable} can either pass null or empty
* (strings/ArrayList).
*
* @param thumbnailUrl author's thumbnail url
* @param thumbnailUrl author's thumbnail url
* @param author author's username
* @param subject post's subject
* @param content post itself
* @param bbContent
* @param postIndex post's index on the forum
* @param postNumber posts index number on this topic
* @param postDate date of submission
@ -100,12 +102,13 @@ public class Post extends TopicItem {
* @param postURL post's URL
*/
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 personalText, int numberOfStars, int userColor
, @Nullable ArrayList<ThmmyFile> attachedFiles, @Nullable String lastEdit, String postURL
, @Nullable String postDeleteURL, @Nullable String postEditURL, boolean isUserMentionedInPost
, int postType) {
this.bbContent = bbContent;
if (Objects.equals(thumbnailUrl, "")) this.thumbnailUrl = null;
else this.thumbnailUrl = thumbnailUrl;
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
* can not change. Parameters notated as {@link Nullable} can either pass null or empty
* (strings/ArrayList).
*
* @param thumbnailUrl author's thumbnail url
* @param thumbnailUrl author's thumbnail url
* @param author author's username
* @param subject post's subject
* @param content post itself
* @param bbContent post content in bb form
* @param postIndex post's index on the forum
* @param postNumber posts index number on this topic
* @param postDate date of submission
@ -150,10 +153,11 @@ public class Post extends TopicItem {
* @param postURL post's URL
*/
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 String postDeleteURL, @Nullable String postEditURL, boolean isUserMentionedInPost
, int postType) {
this.bbContent = bbContent;
if (Objects.equals(thumbnailUrl, "")) this.thumbnailUrl = null;
else this.thumbnailUrl = thumbnailUrl;
this.author = author;
@ -181,12 +185,12 @@ public class Post extends TopicItem {
}
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);
}
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);
}
@ -212,11 +216,20 @@ public class Post extends TopicItem {
return content;
}
public String getBbContent() {
return bbContent;
}
public void setBbContent(String bbContent) {
this.bbContent = bbContent;
}
/**
* Gets this post's author.
*
* @return post's author
*/
@Nullable
public String getAuthor() {
return author;

Loading…
Cancel
Save