Browse Source

Add yellow border to posts that mention logged in user

pull/44/head
Apostolos Fanakis 6 years ago
parent
commit
497d57681a
  1. 10
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  2. 22
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java
  3. 16
      app/src/main/java/gr/thmmy/mthmmy/model/Post.java
  4. 13
      app/src/main/res/drawable/mention_card.xml
  5. 1
      app/src/main/res/values/colors.xml

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

@ -16,6 +16,7 @@ import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.content.res.AppCompatResources; import android.support.v7.content.res.AppCompatResources;
import android.support.v7.widget.AppCompatImageButton; import android.support.v7.widget.AppCompatImageButton;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -294,6 +295,15 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
getDrawable(R.drawable.member_of_the_month_card)); getDrawable(R.drawable.member_of_the_month_card));
} else holder.cardChildLinear.setBackground(null); } else holder.cardChildLinear.setBackground(null);
if (currentPost.isUserMentionedInPost()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
holder.cardChildLinear.setBackground(context.getResources().
getDrawable(R.drawable.mention_card, null));
} else //noinspection deprecation
holder.cardChildLinear.setBackground(context.getResources().
getDrawable(R.drawable.mention_card));
} else holder.cardChildLinear.setBackground(null);
//Avoid's view's visibility recycling //Avoid's view's visibility recycling
if (!currentPost.isDeleted() && viewModel.isUserExtraInfoVisible(holder.getAdapterPosition())) { if (!currentPost.isDeleted() && viewModel.isUserExtraInfoVisible(holder.getAdapterPosition())) {
holder.userExtraInfo.setVisibility(View.VISIBLE); holder.userExtraInfo.setVisibility(View.VISIBLE);

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

@ -1,7 +1,9 @@
package gr.thmmy.mthmmy.activities.topic; package gr.thmmy.mthmmy.activities.topic;
import android.graphics.Color; import android.graphics.Color;
import android.util.Log;
import org.jsoup.Connection;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
@ -13,7 +15,9 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.regex.Pattern;
import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.model.Post; import gr.thmmy.mthmmy.model.Post;
import gr.thmmy.mthmmy.model.ThmmyFile; import gr.thmmy.mthmmy.model.ThmmyFile;
import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers;
@ -29,6 +33,10 @@ import timber.log.Timber;
* <li>{@link #parseTopic(Document, ParseHelpers.Language)}</li> * <li>{@link #parseTopic(Document, ParseHelpers.Language)}</li>
*/ */
public class TopicParser { public class TopicParser {
private static Pattern mentionsPattern = Pattern.
compile("<div class=\"quoteheader\">\\n\\s+?<a href=.+?>Quote from: "
+ BaseActivity.getSessionManager().getUsername());
//User colors //User colors
private static final int USER_COLOR_BLACK = Color.parseColor("#000000"); private static final int USER_COLOR_BLACK = Color.parseColor("#000000");
private static final int USER_COLOR_RED = Color.parseColor("#F44336"); private static final int USER_COLOR_RED = Color.parseColor("#F44336");
@ -159,7 +167,7 @@ public class TopicParser {
p_specialRank, p_gender, p_personalText, p_numberOfPosts, p_postLastEditDate, p_specialRank, p_gender, p_personalText, p_numberOfPosts, p_postLastEditDate,
p_postURL, p_deletePostURL, p_editPostURL; p_postURL, p_deletePostURL, p_editPostURL;
int p_postNum, p_postIndex, p_numberOfStars, p_userColor; int p_postNum, p_postIndex, p_numberOfStars, p_userColor;
boolean p_isDeleted = false; boolean p_isDeleted = false, p_isUserMentionedInPost = false;
ArrayList<ThmmyFile> p_attachedFiles; ArrayList<ThmmyFile> p_attachedFiles;
//Initialize variables //Initialize variables
@ -434,17 +442,25 @@ public class TopicParser {
} }
} }
//Checks post for mentions of this user (if the user is logged in)
if (BaseActivity.getSessionManager().isLoggedIn() &&
mentionsPattern.matcher(p_post).find()) {
p_isUserMentionedInPost = true;
}
//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, 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, Post.TYPE_POST)); , p_attachedFiles, p_postLastEditDate, p_postURL, p_deletePostURL, p_editPostURL
, p_isUserMentionedInPost, Post.TYPE_POST));
} 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 , p_postIndex, p_postNum, p_postDate, p_userColor, p_attachedFiles
, p_postLastEditDate, p_postURL, p_deletePostURL, p_editPostURL, Post.TYPE_POST)); , p_postLastEditDate, p_postURL, p_deletePostURL, p_editPostURL
, p_isUserMentionedInPost, Post.TYPE_POST));
} }
} }
return parsedPostsList; return parsedPostsList;

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

@ -45,6 +45,7 @@ public class Post {
private final String numberOfPosts; private final String numberOfPosts;
private final String personalText; private final String personalText;
private final int numberOfStars; private final int numberOfStars;
private final boolean isUserMentionedInPost;
// Suppresses default constructor // Suppresses default constructor
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -70,6 +71,7 @@ public class Post {
postURL = null; postURL = null;
postDeleteURL = null; postDeleteURL = null;
postEditURL = null; postEditURL = null;
isUserMentionedInPost = false;
postType = -1; postType = -1;
} }
@ -102,7 +104,8 @@ public class Post {
, @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, int postType) { , @Nullable String postDeleteURL, @Nullable String postEditURL, boolean isUserMentionedInPost
, int postType) {
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;
@ -125,6 +128,7 @@ public class Post {
this.postURL = postURL; this.postURL = postURL;
this.postDeleteURL = postDeleteURL; this.postDeleteURL = postDeleteURL;
this.postEditURL = postEditURL; this.postEditURL = postEditURL;
this.isUserMentionedInPost = isUserMentionedInPost;
this.postType = postType; this.postType = postType;
} }
@ -148,7 +152,8 @@ public class Post {
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 , 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, int postType) { , @Nullable String postDeleteURL, @Nullable String postEditURL, boolean isUserMentionedInPost
, int postType) {
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;
@ -171,12 +176,13 @@ public class Post {
this.postURL = postURL; this.postURL = postURL;
this.postDeleteURL = postDeleteURL; this.postDeleteURL = postDeleteURL;
this.postEditURL = postEditURL; this.postEditURL = postEditURL;
this.isUserMentionedInPost = isUserMentionedInPost;
this.postType = postType; this.postType = postType;
} }
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, 0, 0, null,
0, null, null, null, null, null, TYPE_QUICK_REPLY); 0, null, null, null, null, null, false, TYPE_QUICK_REPLY);
} }
//Getters //Getters
@ -390,6 +396,10 @@ public class Post {
return postType; return postType;
} }
public boolean isUserMentionedInPost() {
return isUserMentionedInPost;
}
public void setPostType(int postType) { public void setPostType(int postType) {
this.postType = postType; this.postType = postType;
} }

13
app/src/main/res/drawable/mention_card.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/card_background"/>
<stroke
android:width="1dip"
android:color="@color/mention_color"/>
<corners android:radius="5dip"/>
<padding
android:bottom="0dip"
android:left="0dip"
android:right="0dip"
android:top="0dip"/>
</shape>

1
app/src/main/res/values/colors.xml

@ -17,6 +17,7 @@
<color name="card_background">#3C3F41</color> <color name="card_background">#3C3F41</color>
<color name="divider">#8B8B8B</color> <color name="divider">#8B8B8B</color>
<color name="link_color">#FF9800</color> <color name="link_color">#FF9800</color>
<color name="mention_color">#FAA61A</color>
<color name="white">#FFFFFF</color> <color name="white">#FFFFFF</color>
<color name="iron">#CCCCCC</color> <color name="iron">#CCCCCC</color>

Loading…
Cancel
Save