From e9538f40002289a6a950a2a15dbc1998a5b1758d Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Sat, 7 Jul 2018 18:37:55 +0300 Subject: [PATCH] add a filled circle next to unread topics --- .../mthmmy/activities/board/BoardActivity.java | 6 ++++-- .../mthmmy/activities/board/BoardAdapter.java | 5 ++++- .../main/java/gr/thmmy/mthmmy/model/Topic.java | 18 +++++++++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java index 251c7c2b..728a642b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java @@ -265,7 +265,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo for (Element topicRow : topicRows) { if (!Objects.equals(topicRow.className(), "titlebg")) { String pTopicUrl, pSubject, pStartedBy, pLastPost, pLastPostUrl, pStats; - boolean pLocked = false, pSticky = false; + boolean pLocked = false, pSticky = false, pUnread = false; Elements topicColumns = topicRow.select(">td"); { Element column = topicColumns.get(2); @@ -276,6 +276,8 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo pSticky = true; if (column.select("img[id^=lockicon]").first() != null) pLocked = true; + if (column.select("a[id^=newicon]").first() != null) + pUnread = true; } pStartedBy = topicColumns.get(3).text(); pStats = "Replies " + topicColumns.get(4).text() + ", Views " + topicColumns.get(5).text(); @@ -290,7 +292,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo } pLastPostUrl = topicColumns.last().select("a:has(img)").first().attr("href"); parsedTopics.add(new Topic(pTopicUrl, pSubject, pStartedBy, pLastPost, pLastPostUrl, - pStats, pLocked, pSticky)); + pStats, pLocked, pSticky, pUnread)); } } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java index bb43c065..3c7b8945 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java @@ -6,6 +6,7 @@ import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; import android.support.v7.widget.RecyclerView; +import android.text.Html; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -231,7 +232,9 @@ class BoardAdapter extends RecyclerView.Adapter { }); topicViewHolder.topicSubject.setTypeface(Typeface.createFromAsset(context.getAssets() , "fonts/fontawesome-webfont.ttf")); - String lockedSticky = topic.getSubject(); + String lockedSticky = topic.isUnread() ? + Html.fromHtml("" + context.getString(R.string.fa_circle) + " ").toString() : ""; + lockedSticky += topic.getSubject(); if (topic.isLocked()) lockedSticky += " " + context.getResources().getString(R.string.fa_lock); if (topic.isSticky()) { diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Topic.java b/app/src/main/java/gr/thmmy/mthmmy/model/Topic.java index 27f22c31..207e2c2e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Topic.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Topic.java @@ -5,11 +5,11 @@ package gr.thmmy.mthmmy.model; * Class has one constructor and getter methods for all variables. *

A topic is described by its url, subject, username of creator, its date and time of this * topic's last post, url of this topic's last post, its view and reply stats, whether it's locked or - * not and whether it's sticky or not.. + * not, whether it's sticky or not and whether it contains an unread post or not.. */ public class Topic extends TopicSummary { private final String lastPostUrl, stats; - private final boolean locked, sticky; + private final boolean locked, sticky, unread; // Suppresses default constructor @SuppressWarnings("unused") @@ -19,6 +19,7 @@ public class Topic extends TopicSummary { this.stats = null; this.locked = false; this.sticky = false; + this.unread = false; } /** @@ -33,14 +34,16 @@ public class Topic extends TopicSummary { * @param stats this topic's view and reply stats * @param locked whether this topic is locked or not * @param sticky whether this topic is sticky or not + * @param unread whether this topic contains an unread post or not */ public Topic(String topicUrl, String subject, String starter, String lastPost, String lastPostUrl, - String stats, boolean locked, boolean sticky) { + String stats, boolean locked, boolean sticky, boolean unread) { super(topicUrl, subject, starter, lastPost); this.lastPostUrl = lastPostUrl; this.stats = stats; this.locked = locked; this.sticky = sticky; + this.unread = unread; } /** @@ -114,4 +117,13 @@ public class Topic extends TopicSummary { public boolean isSticky() { return sticky; } + + /** + * Gets this topic's unread status. True if it contains an unread post, false otherwise. + * + * @return this topic's unread status + */ + public boolean isUnread() { + return unread; + } }