From 4406761458d00decf2c57feba8971d47b5447c67 Mon Sep 17 00:00:00 2001 From: Kyle Ivey Date: Sun, 2 Jun 2024 03:32:14 -0700 Subject: [PATCH 1/3] Update HNCommentsParser.java Update comment parsing (text and color) --- .../hn/parser/HNCommentsParser.java | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/manuelmaly/hn/parser/HNCommentsParser.java b/app/src/main/java/com/manuelmaly/hn/parser/HNCommentsParser.java index 3d62e4d9..0d0b79bc 100644 --- a/app/src/main/java/com/manuelmaly/hn/parser/HNCommentsParser.java +++ b/app/src/main/java/com/manuelmaly/hn/parser/HNCommentsParser.java @@ -42,21 +42,14 @@ public HNPostComments parseDocument(Element doc) throws Exception { if (mainRowElement == null) continue; - // The not portion of this query is meant to remove the reply link - // from the text. As far as I can tell that is the only place - // where size=1 is used. If that turns out to not be the case then - // searching for u tags is also a pretty decent option - @jmaltz - Element mainCommentDiv = mainRowElement.select("div.comment > span").first(); + Element mainCommentDiv = mainRowElement.select("div.commtext").first(); if (mainCommentDiv == null) continue; mainCommentDiv.select("div.reply").remove(); // Parse the class attribute to get the comment color - int commentColor = Color.rgb(0, 0, 0); - if (mainCommentDiv.attributes().hasKey("class")) { - commentColor = getCommentColor(mainCommentDiv.attributes().get("class")); - } + int commentColor = getCommentColor(mainCommentDiv.classNames()); // In order to eliminate whitespace at the end of multi-line comments, //

tags are replaced with double
tags. @@ -123,27 +116,29 @@ private String getVoteUrl(Element voteElement) { return null; } - private int getCommentColor(String className) { - if ("c5a".equals(className)) { + private int getCommentColor(Set classNames) { + if (classNames.contains("c00")) { + return Color.BLACK; + } else if (classNames.contains("c5a")) { return Color.rgb(0x5A, 0x5A, 0x5A); - } else if ("c73".equals(className)) { + } else if (classNames.contains("c73")) { return Color.rgb(0x73, 0x73, 0x73); - } else if ("c82".equals(className)) { + } else if (classNames.contains("c82")) { return Color.rgb(0x82, 0x82, 0x82); - } else if ("c88".equals(className)) { + } else if (classNames.contains("c88")) { return Color.rgb(0x88, 0x88, 0x88); - } else if ("c9c".equals(className)) { + } else if (classNames.contains("c9c")) { return Color.rgb(0x9C, 0x9C, 0x9C); - } else if ("cae".equals(className)) { + } else if (classNames.contains("cae")) { return Color.rgb(0xAE, 0xAE, 0xAE); - } else if ("cbe".equals(className)) { + } else if (classNames.contains("cbe")) { return Color.rgb(0xBE, 0xBE, 0xBE); - } else if ("cce".equals(className)) { + } else if (classNames.contains("cce")) { return Color.rgb(0xCE, 0xCE, 0xCE); - } else if ("cdd".equals(className)) { + } else if (classNames.contains("cdd")) { return Color.rgb(0xDD, 0xDD, 0xDD); } else { - return Color.rgb(0, 0, 0); + return Color.BLACK; } } } From ed9f2a1982cde22ac520018af366bb7cea4bf7c7 Mon Sep 17 00:00:00 2001 From: Kyle Ivey Date: Sun, 2 Jun 2024 03:36:51 -0700 Subject: [PATCH 2/3] Update HNCommentsParser.java --- app/src/main/java/com/manuelmaly/hn/parser/HNCommentsParser.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/manuelmaly/hn/parser/HNCommentsParser.java b/app/src/main/java/com/manuelmaly/hn/parser/HNCommentsParser.java index 0d0b79bc..95225258 100644 --- a/app/src/main/java/com/manuelmaly/hn/parser/HNCommentsParser.java +++ b/app/src/main/java/com/manuelmaly/hn/parser/HNCommentsParser.java @@ -12,6 +12,7 @@ import org.jsoup.select.Elements; import java.util.ArrayList; +import java.util.Set; public class HNCommentsParser extends BaseHTMLParser { From 091e4faa9955923e7f7b1ca24d6af1e4419c4fc1 Mon Sep 17 00:00:00 2001 From: Kyle Ivey Date: Sun, 2 Jun 2024 07:19:34 -0700 Subject: [PATCH 3/3] Update HNCommentsParser.java --- .../main/java/com/manuelmaly/hn/parser/HNCommentsParser.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/com/manuelmaly/hn/parser/HNCommentsParser.java b/app/src/main/java/com/manuelmaly/hn/parser/HNCommentsParser.java index 95225258..418209af 100644 --- a/app/src/main/java/com/manuelmaly/hn/parser/HNCommentsParser.java +++ b/app/src/main/java/com/manuelmaly/hn/parser/HNCommentsParser.java @@ -47,8 +47,6 @@ public HNPostComments parseDocument(Element doc) throws Exception { if (mainCommentDiv == null) continue; - mainCommentDiv.select("div.reply").remove(); - // Parse the class attribute to get the comment color int commentColor = getCommentColor(mainCommentDiv.classNames());