Browse Source

Merge pull request #50 from ThmmyNoLife/katerameno

hopefully katarameno fix
pull/55/head
oogee 6 years ago
committed by GitHub
parent
commit
5893bb9c3e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 44
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java

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

@ -156,7 +156,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
@Override @Override
public void onLoadMore() { public void onLoadMore() {
if (pagesLoaded < numberOfPages) { if (pagesLoaded < numberOfPages && parsedTopics.get(parsedTopics.size() - 1) != null) {
parsedTopics.add(null); parsedTopics.add(null);
boardAdapter.notifyItemInserted(parsedSubBoards.size() + parsedTopics.size()); boardAdapter.notifyItemInserted(parsedSubBoards.size() + parsedTopics.size());
@ -185,6 +185,9 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
* parameter!</p> * parameter!</p>
*/ */
private class BoardTask extends ParseTask { private class BoardTask extends ParseTask {
ArrayList<Board> tempSubboards = new ArrayList<>();
ArrayList<Topic> tempTopics = new ArrayList<>();
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
if (!isLoadingMore) progressBar.setVisibility(ProgressBar.VISIBLE); if (!isLoadingMore) progressBar.setVisibility(ProgressBar.VISIBLE);
@ -195,10 +198,6 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
public void parse(Document boardPage) throws ParseException { public void parse(Document boardPage) throws ParseException {
parsedTitle = boardPage.select("div.nav a.nav").last().text(); parsedTitle = boardPage.select("div.nav a.nav").last().text();
//Removes loading item
if (isLoadingMore) {
if (parsedTopics.size() > 0) parsedTopics.remove(parsedTopics.size() - 1);
}
//Finds number of pages //Finds number of pages
if (numberOfPages == -1) { if (numberOfPages == -1) {
numberOfPages = 1; numberOfPages = 1;
@ -254,7 +253,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
} }
} }
} }
parsedSubBoards.add(new Board(pUrl, pTitle, pMods, pStats, pLastPost, pLastPostUrl)); tempSubboards.add(new Board(pUrl, pTitle, pMods, pStats, pLastPost, pLastPostUrl));
} }
} }
} }
@ -293,7 +292,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
Timber.wtf("Board parsing about to fail. pLastPost came with: %s", pLastPost); Timber.wtf("Board parsing about to fail. pLastPost came with: %s", pLastPost);
} }
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, tempTopics.add(new Topic(pTopicUrl, pSubject, pStartedBy, pLastPost, pLastPostUrl,
pStats, pLocked, pSticky, pUnread)); pStats, pLocked, pSticky, pUnread));
} }
} }
@ -304,18 +303,31 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
@Override @Override
protected void postExecution(ResultCode result) { protected void postExecution(ResultCode result) {
//TODO if (result == ResultCode.SUCCESS)... //TODO if (result == ResultCode.SUCCESS)...
if (boardTitle == null || Objects.equals(boardTitle, "") if (result == ResultCode.SUCCESS) {
|| !Objects.equals(boardTitle, parsedTitle)) { if (boardTitle == null || Objects.equals(boardTitle, "")
boardTitle = parsedTitle; || !Objects.equals(boardTitle, parsedTitle)) {
toolbar.setTitle(boardTitle); boardTitle = parsedTitle;
thisPageBookmark = new Bookmark(boardTitle, ThmmyPage.getBoardId(boardUrl), false); toolbar.setTitle(boardTitle);
thisPageBookmark = new Bookmark(boardTitle, ThmmyPage.getBoardId(boardUrl), false);
}
//Removes loading item
if (isLoadingMore) {
if (parsedTopics.size() > 0) parsedTopics.remove(parsedTopics.size() - 1);
}
parsedTopics.clear();
parsedSubBoards.clear();
parsedTopics.addAll(tempTopics);
parsedSubBoards.addAll(tempSubboards);
boardAdapter.notifyDataSetChanged();
//Parse was successful
++pagesLoaded;
if (newTopicFAB.getVisibility() != View.GONE) newTopicFAB.setEnabled(true);
} }
//Parse was successful
++pagesLoaded;
if (newTopicFAB.getVisibility() != View.GONE) newTopicFAB.setEnabled(true);
progressBar.setVisibility(ProgressBar.INVISIBLE); progressBar.setVisibility(ProgressBar.INVISIBLE);
boardAdapter.notifyDataSetChanged();
isLoadingMore = false; isLoadingMore = false;
} }
} }

Loading…
Cancel
Save