Browse Source

Bug fixes (BoardActivity)

pull/68/head
Ezerous 5 years ago
parent
commit
381b5aaf1b
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 22
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
  2. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java

22
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.ArrayList;
import java.util.Objects; import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.LoginActivity; import gr.thmmy.mthmmy.activities.LoginActivity;
@ -158,9 +160,9 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
@Override @Override
public void onLoadMore() { 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); 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 //Load data
boardTask = new BoardTask(); 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(); pStats = "Replies: " + topicColumns.get(4).text() + ", Views: " + topicColumns.get(5).text();
pLastPost = topicColumns.last().text(); pLastPost = topicColumns.last().text();
if (pLastPost.contains("by")) { Pattern pattern = Pattern.compile("(.+)\\s(by|από)\\s(.+)$");
pLastPostDateTime = pLastPost.substring(0, pLastPost.indexOf("by") -1); Matcher matcher = pattern.matcher(pLastPost);
pLastUser = pLastPost.substring(pLastPost.indexOf("by") + 3); if (matcher.find()){
} else if (pLastPost.contains("από")) { pLastPostDateTime = matcher.group(1);
pLastPostDateTime = pLastPost.substring(0, pLastPost.indexOf("από") - 1); pLastUser = matcher.group(3);
pLastUser = pLastPost.substring(pLastPost.indexOf("από") + 4);
} else {
Timber.wtf("Board parsing about to fail. pLastPost came with: %s", pLastPost);
} }
else
throw new ParseException("Parsing failed (pLastPost came with: \"" + pLastPost + "\")");
pLastPostUrl = topicColumns.last().select("a:has(img)").first().attr("href"); pLastPostUrl = topicColumns.last().select("a:has(img)").first().attr("href");
tempTopics.add(new Topic(pTopicUrl, pSubject, pStarter, pLastUser, pLastPostDateTime, pLastPostUrl, tempTopics.add(new Topic(pTopicUrl, pSubject, pStarter, pLastUser, pLastPostDateTime, pLastPostUrl,
pStats, pLocked, pSticky, pUnread)); pStats, pLocked, pSticky, pUnread));

4
app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java

@ -39,8 +39,8 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final int VIEW_TYPE_LOADING = 4; private final int VIEW_TYPE_LOADING = 4;
private final Context context; private final Context context;
private ArrayList<Board> parsedSubBoards = new ArrayList<>(); private ArrayList<Board> parsedSubBoards;
private ArrayList<Topic> parsedTopics = new ArrayList<>(); private ArrayList<Topic> parsedTopics;
private final ArrayList<Boolean> boardExpandableVisibility = new ArrayList<>(); private final ArrayList<Boolean> boardExpandableVisibility = new ArrayList<>();
private final ArrayList<Boolean> topicExpandableVisibility = new ArrayList<>(); private final ArrayList<Boolean> topicExpandableVisibility = new ArrayList<>();

Loading…
Cancel
Save