From 381b5aaf1b5bfa2a96ccd01fde23c25ac1d28e3e Mon Sep 17 00:00:00 2001 From: Ezerous Date: Wed, 27 May 2020 14:39:41 +0300 Subject: [PATCH] Bug fixes (BoardActivity) --- .../activities/board/BoardActivity.java | 22 ++++++++++--------- .../mthmmy/activities/board/BoardAdapter.java | 4 ++-- 2 files changed, 14 insertions(+), 12 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 b625980a..87e7d27b 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 @@ -21,6 +21,8 @@ import org.jsoup.select.Elements; import java.util.ArrayList; import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.LoginActivity; @@ -158,9 +160,9 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo @Override public void onLoadMore() { - if (pagesLoaded < numberOfPages && parsedTopics.get(parsedTopics.size() - 1) != null) { + if (pagesLoaded < numberOfPages && !parsedTopics.isEmpty() && parsedTopics.get(parsedTopics.size() - 1) != null) { parsedTopics.add(null); - boardAdapter.notifyItemInserted(parsedSubBoards.size() + parsedTopics.size()); + boardAdapter.notifyItemInserted(parsedSubBoards.size() + parsedTopics.size()); // This gets a warning and should be changed //Load data boardTask = new BoardTask(); @@ -296,15 +298,15 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo pStats = "Replies: " + topicColumns.get(4).text() + ", Views: " + topicColumns.get(5).text(); pLastPost = topicColumns.last().text(); - if (pLastPost.contains("by")) { - pLastPostDateTime = pLastPost.substring(0, pLastPost.indexOf("by") -1); - pLastUser = pLastPost.substring(pLastPost.indexOf("by") + 3); - } else if (pLastPost.contains("από")) { - pLastPostDateTime = pLastPost.substring(0, pLastPost.indexOf("από") - 1); - pLastUser = pLastPost.substring(pLastPost.indexOf("από") + 4); - } else { - Timber.wtf("Board parsing about to fail. pLastPost came with: %s", pLastPost); + Pattern pattern = Pattern.compile("(.+)\\s(by|από)\\s(.+)$"); + Matcher matcher = pattern.matcher(pLastPost); + if (matcher.find()){ + pLastPostDateTime = matcher.group(1); + pLastUser = matcher.group(3); } + else + throw new ParseException("Parsing failed (pLastPost came with: \"" + pLastPost + "\")"); + pLastPostUrl = topicColumns.last().select("a:has(img)").first().attr("href"); tempTopics.add(new Topic(pTopicUrl, pSubject, pStarter, pLastUser, pLastPostDateTime, pLastPostUrl, 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 b016c5e4..f9093cf8 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 @@ -39,8 +39,8 @@ class BoardAdapter extends RecyclerView.Adapter { private final int VIEW_TYPE_LOADING = 4; private final Context context; - private ArrayList parsedSubBoards = new ArrayList<>(); - private ArrayList parsedTopics = new ArrayList<>(); + private ArrayList parsedSubBoards; + private ArrayList parsedTopics; private final ArrayList boardExpandableVisibility = new ArrayList<>(); private final ArrayList topicExpandableVisibility = new ArrayList<>();