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. 34
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java
  3. 18
      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.content.res.AppCompatResources;
import android.support.v7.widget.AppCompatImageButton;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
@ -294,6 +295,15 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
getDrawable(R.drawable.member_of_the_month_card));
} 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
if (!currentPost.isDeleted() && viewModel.isUserExtraInfoVisible(holder.getAdapterPosition())) {
holder.userExtraInfo.setVisibility(View.VISIBLE);

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

@ -1,7 +1,9 @@
package gr.thmmy.mthmmy.activities.topic;
import android.graphics.Color;
import android.util.Log;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
@ -13,7 +15,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
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.ThmmyFile;
import gr.thmmy.mthmmy.utils.parsing.ParseHelpers;
@ -29,6 +33,10 @@ import timber.log.Timber;
* <li>{@link #parseTopic(Document, ParseHelpers.Language)}</li>
*/
public class TopicParser {
private static Pattern mentionsPattern = Pattern.
compile("<div class=\"quoteheader\">\\n\\s+?<a href=.+?>Quote from: "
+ BaseActivity.getSessionManager().getUsername());
//User colors
private static final int USER_COLOR_BLACK = Color.parseColor("#000000");
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_postURL, p_deletePostURL, p_editPostURL;
int p_postNum, p_postIndex, p_numberOfStars, p_userColor;
boolean p_isDeleted = false;
boolean p_isDeleted = false, p_isUserMentionedInPost = false;
ArrayList<ThmmyFile> p_attachedFiles;
//Initialize variables
@ -188,7 +196,7 @@ public class TopicParser {
p_subject = thisRow.select("div[id^=subject_]").first().select("a").first().text();
//Finds post's link
p_postURL = thisRow.select("div[id^=subject_]").first().select("a").first() .attr("href");
p_postURL = thisRow.select("div[id^=subject_]").first().select("a").first().attr("href");
//Finds post's text
p_post = ParseHelpers.youtubeEmbeddedFix(thisRow.select("div").select(".post").first());
@ -204,11 +212,11 @@ public class TopicParser {
if (postIndex != null) {
String tmp = postIndex.attr("name");
p_postIndex = Integer.parseInt(tmp.substring(tmp.indexOf("msg") + 3));
} else{
} else {
postIndex = thisRow.select("div[id^=subject]").first();
if (postIndex == null)
p_postIndex = NO_INDEX;
else{
else {
String tmp = postIndex.attr("id");
p_postIndex = Integer.parseInt(tmp.substring(tmp.indexOf("subject") + 8));
}
@ -237,7 +245,7 @@ public class TopicParser {
//Finds post delete url
Element postDelete = thisRow.select("a:has(img[alt='Διαγραφή'])").first();
if (postDelete!=null){
if (postDelete != null) {
p_deletePostURL = postDelete.attr("href");
}
@ -303,7 +311,7 @@ public class TopicParser {
//Finds post delete url
Element postDelete = thisRow.select("a:has(img[alt='Remove message'])").first();
if (postDelete!=null){
if (postDelete != null) {
p_deletePostURL = postDelete.attr("href");
}
@ -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
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_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
//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
, p_postLastEditDate, p_postURL, p_deletePostURL, p_editPostURL, Post.TYPE_POST));
, p_postIndex, p_postNum, p_postDate, p_userColor, p_attachedFiles
, p_postLastEditDate, p_postURL, p_deletePostURL, p_editPostURL
, p_isUserMentionedInPost, Post.TYPE_POST));
}
}
return parsedPostsList;

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

@ -45,6 +45,7 @@ public class Post {
private final String numberOfPosts;
private final String personalText;
private final int numberOfStars;
private final boolean isUserMentionedInPost;
// Suppresses default constructor
@SuppressWarnings("unused")
@ -70,6 +71,7 @@ public class Post {
postURL = null;
postDeleteURL = null;
postEditURL = null;
isUserMentionedInPost = false;
postType = -1;
}
@ -102,7 +104,8 @@ public class Post {
, @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, int postType) {
, @Nullable String postDeleteURL, @Nullable String postEditURL, boolean isUserMentionedInPost
, int postType) {
if (Objects.equals(thumbnailUrl, "")) this.thumbnailUrl = null;
else this.thumbnailUrl = thumbnailUrl;
this.author = author;
@ -125,6 +128,7 @@ public class Post {
this.postURL = postURL;
this.postDeleteURL = postDeleteURL;
this.postEditURL = postEditURL;
this.isUserMentionedInPost = isUserMentionedInPost;
this.postType = postType;
}
@ -143,12 +147,13 @@ public class Post {
* @param userColor author's user color
* @param attachedFiles post's attached files
* @param lastEdit post's last edit date
* @param postURL post's URL
* @param postURL post's URL
*/
public Post(@Nullable String thumbnailUrl, String author, String subject, String content
, int postIndex, int postNumber, String postDate, int userColor
, @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;
else this.thumbnailUrl = thumbnailUrl;
this.author = author;
@ -171,12 +176,13 @@ public class Post {
this.postURL = postURL;
this.postDeleteURL = postDeleteURL;
this.postEditURL = postEditURL;
this.isUserMentionedInPost = isUserMentionedInPost;
this.postType = postType;
}
public static Post newQuickReply() {
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
@ -390,6 +396,10 @@ public class Post {
return postType;
}
public boolean isUserMentionedInPost() {
return isUserMentionedInPost;
}
public void setPostType(int 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="divider">#8B8B8B</color>
<color name="link_color">#FF9800</color>
<color name="mention_color">#FAA61A</color>
<color name="white">#FFFFFF</color>
<color name="iron">#CCCCCC</color>

Loading…
Cancel
Save