From 13011c01a90553b858a67b4827db9dc04c651c81 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Mon, 16 Sep 2024 20:29:57 +0300 Subject: [PATCH] feat: add online status dot to TopicActivity --- .../mthmmy/activities/topic/TopicAdapter.java | 7 ++++- .../mthmmy/activities/topic/TopicParser.java | 14 +++++++--- .../main/java/gr/thmmy/mthmmy/model/Post.java | 18 ++++++++++++- .../res/layout/activity_topic_post_row.xml | 27 ++++++++++++++----- app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/strings.xml | 7 ++--- 6 files changed, 58 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index ea5ce606..cddd7cd5 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -378,6 +378,10 @@ class TopicAdapter extends RecyclerView.Adapter { //Sets username,submit date, index number, subject, post's and attached files texts holder.username.setText(currentPost.getAuthor()); + + if(currentPost.getUserOnlineStatus()) + holder.onlineStatusDot.setVisibility(View.VISIBLE); + holder.postDate.setText(currentPost.getPostDate()); if (currentPost.getPostNumber() != 0) holder.postNum.setText(context.getString( @@ -822,7 +826,7 @@ class TopicAdapter extends RecyclerView.Adapter { final View bodyFooterDivider; final LinearLayout postFooter; - final TextView specialRank, rank, gender, numberOfPosts, personalText, stars; + final TextView specialRank, rank, gender, numberOfPosts, personalText, stars, onlineStatusDot; PostViewHolder(View view) { super(view); @@ -835,6 +839,7 @@ class TopicAdapter extends RecyclerView.Adapter { username = view.findViewById(R.id.username); subject = view.findViewById(R.id.subject); post = view.findViewById(R.id.post); + onlineStatusDot = view.findViewById(R.id.online_status_dot); post.setBackgroundColor(Color.argb(1, 255, 255, 255)); quoteToggle = view.findViewById(R.id.toggle_quote_button); overflowButton = view.findViewById(R.id.post_overflow_menu); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java index 98469a5e..205ab40c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java @@ -178,7 +178,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, p_isUserMentionedInPost = false; + boolean p_isDeleted = false, p_isUserMentionedInPost = false, p_isUserOnline = false; ArrayList p_attachedFiles; //Initialize variables @@ -403,7 +403,8 @@ public class TopicParser { final String genderMaleStr = displayedLanguageGreek ? "Φύλο: Άντρας" : "Gender: Male"; final String genderFemaleStr = displayedLanguageGreek ? "Φύλο: Γυναίκα" : "Gender: Female"; final String postsStr = displayedLanguageGreek ? "Μηνύματα:" : "Posts:"; - + final String pmTitleWithOnlineStatusStr = displayedLanguageGreek ? "title=\"Προσωπικό μήνυμα (Σε σύνδεση)\"" : "title=\"Personal Message (Online)\""; + Document starsHtml= Jsoup.parse(""); for (String line : infoList) { @@ -422,6 +423,8 @@ public class TopicParser { starsLineIndex = infoList.indexOf(line); starsHtml = Jsoup.parse(line); } + if (line.contains(pmTitleWithOnlineStatusStr)) + p_isUserOnline = true; } p_numberOfStars = starsHtml.select("img[alt]").size(); @@ -437,7 +440,10 @@ public class TopicParser { p_rank = infoList.get(1).trim(); //Second line has the rank } - p_userColor = colorPicker(starsHtml.select("img[alt]").first().attr("abs:src"), p_specialRank); + Element starsHtmlEl = starsHtml.select("img[alt]").first(); + + if (p_numberOfStars>0 && starsHtmlEl!=null) + p_userColor = colorPicker(starsHtmlEl.attr("abs:src"), p_specialRank); for (int i = postsLineIndex + 1; i < infoList.size() - 1; ++i) { //Searches under "Posts:" @@ -463,7 +469,7 @@ public class TopicParser { , 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 - , p_isUserMentionedInPost, Post.TYPE_POST)); + , p_isUserOnline, p_isUserMentionedInPost, Post.TYPE_POST)); } else { //Deleted user diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Post.java b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java index 8000e93f..4595172e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Post.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java @@ -47,6 +47,7 @@ public class Post extends TopicItem { private final String personalText; private final int numberOfStars; private final boolean isUserMentionedInPost; + private final boolean isUserOnline; // Suppresses default constructor @SuppressWarnings("unused") @@ -73,6 +74,7 @@ public class Post extends TopicItem { postURL = null; postDeleteURL = null; postEditURL = null; + isUserOnline = false; isUserMentionedInPost = false; postType = -1; } @@ -101,13 +103,14 @@ public class Post extends TopicItem { * @param attachedFiles post's attached files * @param lastEdit post's last edit date * @param postURL post's URL + * @param isUserOnline author's online status */ public Post(@Nullable String thumbnailUrl, String author, String subject, String content , 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 attachedFiles, @Nullable String lastEdit, String postURL - , @Nullable String postDeleteURL, @Nullable String postEditURL, boolean isUserMentionedInPost + , @Nullable String postDeleteURL, @Nullable String postEditURL, boolean isUserOnline, boolean isUserMentionedInPost , int postType) { this.bbContent = bbContent; if (Objects.equals(thumbnailUrl, "")) this.thumbnailUrl = null; @@ -132,6 +135,7 @@ public class Post extends TopicItem { this.postURL = postURL; this.postDeleteURL = postDeleteURL; this.postEditURL = postEditURL; + this.isUserOnline = isUserOnline; this.isUserMentionedInPost = isUserMentionedInPost; this.postType = postType; } @@ -182,6 +186,7 @@ public class Post extends TopicItem { this.postURL = postURL; this.postDeleteURL = postDeleteURL; this.postEditURL = postEditURL; + this.isUserOnline = false; this.isUserMentionedInPost = isUserMentionedInPost; this.postType = postType; } @@ -362,6 +367,17 @@ public class Post extends TopicItem { return userColor; } + /** + * Gets the online status of this post's author. + * + * @return online status of this post's author + */ + + @Nullable + public boolean getUserOnlineStatus() { + return isUserOnline; + } + /** * Gets this post's attached files. * diff --git a/app/src/main/res/layout/activity_topic_post_row.xml b/app/src/main/res/layout/activity_topic_post_row.xml index b795224e..5dbca1a3 100644 --- a/app/src/main/res/layout/activity_topic_post_row.xml +++ b/app/src/main/res/layout/activity_topic_post_row.xml @@ -9,17 +9,17 @@ android:paddingStart="4dp" tools:ignore="SmallSp"> - + app:cardBackgroundColor="@color/background_light" + app:cardCornerRadius="5dp" + app:cardElevation="2dp" + app:cardPreventCornerOverlap="false" + app:cardUseCompatPadding="true"> + + #FF9800 #FAA61A #890d0d + #4CAF50 #FFFFFF #CCCCCC diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 38263d6c..a51c55e6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -73,13 +73,14 @@ This topic is either missing or off limits to you Remove vote show results + hide results + preference-topic-drafts-key + Reply + You may only select %d option You may only select %d options - hide results - preference-topic-drafts-key - Reply Username