Browse Source

BoardActivity fixes

pull/70/head
Ezerous 5 years ago
parent
commit
423573cbc1
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 42
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
  2. 11
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java

42
app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java

@ -236,6 +236,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
if (!Objects.equals(subBoardRow.className(), "titlebg")) { if (!Objects.equals(subBoardRow.className(), "titlebg")) {
String pUrl = "", pTitle = "", pMods = "", pStats = "", String pUrl = "", pTitle = "", pMods = "", pStats = "",
pLastPost = "No posts yet", pLastPostUrl = ""; pLastPost = "No posts yet", pLastPostUrl = "";
boolean parsingFailed = false;
Elements subBoardColumns = subBoardRow.select(">td"); Elements subBoardColumns = subBoardRow.select(">td");
for (Element subBoardCol : subBoardColumns) { for (Element subBoardCol : subBoardColumns) {
if (Objects.equals(subBoardCol.className(), "windowbg")){ if (Objects.equals(subBoardCol.className(), "windowbg")){
@ -246,20 +247,22 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
else if (Objects.equals(subBoardCol.className(), "smalltext")) { else if (Objects.equals(subBoardCol.className(), "smalltext")) {
pLastPost = subBoardCol.text(); pLastPost = subBoardCol.text();
if (pLastPost.contains(" in ")) { if (pLastPost.contains(" in ") || pLastPost.contains(" σε ")) {
pLastPost = pLastPost.substring(0, pLastPost.indexOf(" in ")) + Pattern pattern = Pattern.compile("(?:Last post on |Τελευταίο μήνυμα στις )((?:(?!(?:in|σε)).)*)\\s(?:in|σε)\\s.*");
"\n" + Matcher matcher = pattern.matcher(pLastPost);
pLastPost.substring(pLastPost.indexOf(" in ") + 1, pLastPost.indexOf(" by ")) + if (matcher.find()){
"\n" + String pLastPostDateTime = matcher.group(1);
pLastPost.substring(pLastPost.lastIndexOf(" by ") + 1); String pSubject = subBoardCol.select("a").first().attr("title");
pLastPostUrl = subBoardCol.select("a").first().attr("href"); String pLastUser = subBoardCol.select("a").last().text();
} else if (pLastPost.contains(" σε ")) { pLastPost = "Last post on: " + pLastPostDateTime + "\nin: " + pSubject + "\nby " +pLastUser;
pLastPost = pLastPost.substring(0, pLastPost.indexOf(" σε ")) +
"\n" + pLastPostUrl = subBoardCol.select("a").first().attr("href");
pLastPost.substring(pLastPost.indexOf(" σε ") + 1, pLastPost.indexOf(" από ")) + }
"\n" + else{
pLastPost.substring(pLastPost.lastIndexOf(" από ") + 1); parsingFailed = true;
pLastPostUrl = subBoardCol.select("a").first().attr("href"); break;
}
} else if (pLastPost.contains("redirected clicks")||pLastPost.contains("N/A")) } else if (pLastPost.contains("redirected clicks")||pLastPost.contains("N/A"))
pLastPost = ""; pLastPost = "";
else else
@ -271,7 +274,10 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
pMods = subBoardCol.select("div.smalltext").first().text(); pMods = subBoardCol.select("div.smalltext").first().text();
} }
} }
tempSubboards.add(new Board(pUrl, pTitle, pMods, pStats, pLastPost, pLastPostUrl)); if(!parsingFailed)
tempSubboards.add(new Board(pUrl, pTitle, pMods, pStats, pLastPost, pLastPostUrl));
else
Timber.e("Parsing failed (pLastPost came with: \"%s\", subBoardColumns html was \"%s\")", pLastPost, subBoardColumns);
} }
} }
} }
@ -300,14 +306,14 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
pStats = "Replies: " + topicColumns.get(4).text() + ", Views: " + topicColumns.get(5).text(); pStats = "Replies: " + topicColumns.get(4).text() + ", Views: " + topicColumns.get(5).text();
pLastPost = topicColumns.last().text(); pLastPost = topicColumns.last().text();
Pattern pattern = Pattern.compile("(.+)\\s(by|από)\\s(.+)$"); Pattern pattern = Pattern.compile("((?:(?!(?:by|από)).)*)\\s(?:by|από)\\s(.*)");
Matcher matcher = pattern.matcher(pLastPost); Matcher matcher = pattern.matcher(pLastPost);
if (matcher.find()){ if (matcher.find()){
pLastPostDateTime = matcher.group(1); pLastPostDateTime = matcher.group(1);
pLastUser = matcher.group(3); pLastUser = matcher.group(2);
} }
else{ else{
Timber.e("Parsing failed (pLastPost came with: \"%s\", html was \"%s\")", pLastPost, topicColumns); Timber.e("Parsing failed (pLastPost came with: \"%s\", topicColumns html was \"%s\")", pLastPost, topicColumns);
continue; continue;
} }

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

@ -18,7 +18,6 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.model.Poll; import gr.thmmy.mthmmy.model.Poll;
import gr.thmmy.mthmmy.model.Post; import gr.thmmy.mthmmy.model.Post;
import gr.thmmy.mthmmy.model.ThmmyFile; import gr.thmmy.mthmmy.model.ThmmyFile;
@ -26,8 +25,6 @@ import gr.thmmy.mthmmy.model.TopicItem;
import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers;
import timber.log.Timber; import timber.log.Timber;
import static gr.thmmy.mthmmy.utils.parsing.ThmmyDateTimeParser.convertToTimestamp;
/** /**
* Singleton used for parsing a topic. * Singleton used for parsing a topic.
@ -178,7 +175,6 @@ public class TopicParser {
p_specialRank, p_gender, p_personalText, p_numberOfPosts, p_postLastEditDate, p_specialRank, p_gender, p_personalText, p_numberOfPosts, p_postLastEditDate,
p_postURL, p_deletePostURL, p_editPostURL; p_postURL, p_deletePostURL, p_editPostURL;
int p_postNum, p_postIndex, p_numberOfStars, p_userColor; int p_postNum, p_postIndex, p_numberOfStars, p_userColor;
long p_timestamp;
boolean p_isDeleted = false, p_isUserMentionedInPost = false; boolean p_isDeleted = false, p_isUserMentionedInPost = false;
ArrayList<ThmmyFile> p_attachedFiles; ArrayList<ThmmyFile> p_attachedFiles;
@ -195,7 +191,6 @@ public class TopicParser {
p_postLastEditDate = null; p_postLastEditDate = null;
p_deletePostURL = null; p_deletePostURL = null;
p_editPostURL = null; p_editPostURL = null;
p_timestamp = 0;
//Language independent parsing //Language independent parsing
//Finds thumbnail url //Finds thumbnail url
@ -272,12 +267,6 @@ public class TopicParser {
p_postDate = p_postDate.substring(p_postDate.indexOf("στις:") + 6 p_postDate = p_postDate.substring(p_postDate.indexOf("στις:") + 6
, p_postDate.indexOf(" »")); , p_postDate.indexOf(" »"));
if (BaseApplication.getInstance().isDisplayRelativeTimeEnabled()) {
String timestamp = convertToTimestamp(p_postDate);
if(timestamp!=null)
p_timestamp = Long.valueOf(timestamp);
}
//Finds post's reply index number //Finds post's reply index number
Element postNum = thisRow.select("div.smalltext:matches(Απάντηση #)").first(); Element postNum = thisRow.select("div.smalltext:matches(Απάντηση #)").first();
if (postNum == null) { //Topic starter if (postNum == null) { //Topic starter

Loading…
Cancel
Save