Browse Source

add a filled circle next to unread topics

pull/24/head
Thodoris1999 7 years ago
parent
commit
e9538f4000
  1. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
  2. 5
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java
  3. 18
      app/src/main/java/gr/thmmy/mthmmy/model/Topic.java

6
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) { for (Element topicRow : topicRows) {
if (!Objects.equals(topicRow.className(), "titlebg")) { if (!Objects.equals(topicRow.className(), "titlebg")) {
String pTopicUrl, pSubject, pStartedBy, pLastPost, pLastPostUrl, pStats; String pTopicUrl, pSubject, pStartedBy, pLastPost, pLastPostUrl, pStats;
boolean pLocked = false, pSticky = false; boolean pLocked = false, pSticky = false, pUnread = false;
Elements topicColumns = topicRow.select(">td"); Elements topicColumns = topicRow.select(">td");
{ {
Element column = topicColumns.get(2); Element column = topicColumns.get(2);
@ -276,6 +276,8 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
pSticky = true; pSticky = true;
if (column.select("img[id^=lockicon]").first() != null) if (column.select("img[id^=lockicon]").first() != null)
pLocked = true; pLocked = true;
if (column.select("a[id^=newicon]").first() != null)
pUnread = true;
} }
pStartedBy = topicColumns.get(3).text(); pStartedBy = topicColumns.get(3).text();
pStats = "Replies " + topicColumns.get(4).text() + ", Views " + topicColumns.get(5).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"); pLastPostUrl = topicColumns.last().select("a:has(img)").first().attr("href");
parsedTopics.add(new Topic(pTopicUrl, pSubject, pStartedBy, pLastPost, pLastPostUrl, parsedTopics.add(new Topic(pTopicUrl, pSubject, pStartedBy, pLastPost, pLastPostUrl,
pStats, pLocked, pSticky)); pStats, pLocked, pSticky, pUnread));
} }
} }
} }

5
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.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -231,7 +232,9 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}); });
topicViewHolder.topicSubject.setTypeface(Typeface.createFromAsset(context.getAssets() topicViewHolder.topicSubject.setTypeface(Typeface.createFromAsset(context.getAssets()
, "fonts/fontawesome-webfont.ttf")); , "fonts/fontawesome-webfont.ttf"));
String lockedSticky = topic.getSubject(); String lockedSticky = topic.isUnread() ?
Html.fromHtml("<font size=\"1\">" + context.getString(R.string.fa_circle) + "</font> ").toString() : "";
lockedSticky += topic.getSubject();
if (topic.isLocked()) if (topic.isLocked())
lockedSticky += " " + context.getResources().getString(R.string.fa_lock); lockedSticky += " " + context.getResources().getString(R.string.fa_lock);
if (topic.isSticky()) { if (topic.isSticky()) {

18
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. * Class has one constructor and getter methods for all variables.
* <p>A topic is described by its url, subject, username of creator, its date and time of this * <p>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 * 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.</b>. * not, whether it's sticky or not and whether it contains an unread post or not.</b>.
*/ */
public class Topic extends TopicSummary { public class Topic extends TopicSummary {
private final String lastPostUrl, stats; private final String lastPostUrl, stats;
private final boolean locked, sticky; private final boolean locked, sticky, unread;
// Suppresses default constructor // Suppresses default constructor
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -19,6 +19,7 @@ public class Topic extends TopicSummary {
this.stats = null; this.stats = null;
this.locked = false; this.locked = false;
this.sticky = 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 stats this topic's view and reply stats
* @param locked whether this topic is locked or not * @param locked whether this topic is locked or not
* @param sticky whether this topic is sticky 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, 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); super(topicUrl, subject, starter, lastPost);
this.lastPostUrl = lastPostUrl; this.lastPostUrl = lastPostUrl;
this.stats = stats; this.stats = stats;
this.locked = locked; this.locked = locked;
this.sticky = sticky; this.sticky = sticky;
this.unread = unread;
} }
/** /**
@ -114,4 +117,13 @@ public class Topic extends TopicSummary {
public boolean isSticky() { public boolean isSticky() {
return sticky; 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;
}
} }

Loading…
Cancel
Save