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 87e7d27b..aedda58b 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 @@ -80,12 +80,11 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo Toast.makeText(this, "An error has occurred\nAborting.", Toast.LENGTH_SHORT).show(); finish(); } + //Fixes url - { - String tmpUrlSbstr = boardUrl.replaceAll("(.+)(board=)([0-9]*)(\\.*[0-9]*).*", "$1$2$3"); - if (!tmpUrlSbstr.substring(tmpUrlSbstr.indexOf("board=")).contains(".")) - boardUrl = tmpUrlSbstr + ".0"; - } + String tmpUrlSbstr = boardUrl.replaceAll("(.+)(board=)([0-9]*)(\\.*[0-9]*).*", "$1$2$3"); + if (!tmpUrlSbstr.substring(tmpUrlSbstr.indexOf("board=")).contains(".")) + boardUrl = tmpUrlSbstr + ".0"; //Initializes graphics toolbar = findViewById(R.id.toolbar); @@ -239,8 +238,12 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo pLastPost = "No posts yet", pLastPostUrl = ""; Elements subBoardColumns = subBoardRow.select(">td"); for (Element subBoardCol : subBoardColumns) { - if (Objects.equals(subBoardCol.className(), "windowbg")) + if (Objects.equals(subBoardCol.className(), "windowbg")){ pStats = subBoardCol.text(); + if(pStats.equals("--")) + pStats = ""; + } + else if (Objects.equals(subBoardCol.className(), "smalltext")) { pLastPost = subBoardCol.text(); if (pLastPost.contains(" in ")) { @@ -257,16 +260,15 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo "\n" + pLastPost.substring(pLastPost.lastIndexOf(" από ") + 1); pLastPostUrl = subBoardCol.select("a").first().attr("href"); - } else { - pLastPost = "No posts yet."; - pLastPostUrl = ""; - } + } else if (pLastPost.contains("redirected clicks")||pLastPost.contains("N/A")) + pLastPost = ""; + else + pLastPost = "No posts yet"; } else { pUrl = subBoardCol.select("a").first().attr("href"); pTitle = subBoardCol.select("a").first().text(); - if (subBoardCol.select("div.smalltext").first() != null) { + if (subBoardCol.select("div.smalltext").first() != null) pMods = subBoardCol.select("div.smalltext").first().text(); - } } } tempSubboards.add(new Board(pUrl, pTitle, pMods, pStats, pLastPost, pLastPostUrl)); @@ -282,18 +284,18 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo String pTopicUrl, pSubject, pStarter, pLastUser="", pLastPostDateTime="00:00:00", pLastPost, pLastPostUrl, pStats; boolean pLocked = false, pSticky = false, pUnread = false; Elements topicColumns = topicRow.select(">td"); - { - Element column = topicColumns.get(2); - Element tmp = column.select("span[id^=msg_] a").first(); - pTopicUrl = tmp.attr("href"); - pSubject = tmp.text(); - if (column.select("img[id^=stickyicon]").first() != null) - pSticky = true; - if (column.select("img[id^=lockicon]").first() != null) - pLocked = true; - if (column.select("a[id^=newicon]").first() != null) - pUnread = true; - } + + Element column = topicColumns.get(2); + Element tmp = column.select("span[id^=msg_] a").first(); + pTopicUrl = tmp.attr("href"); + pSubject = tmp.text(); + if (column.select("img[id^=stickyicon]").first() != null) + pSticky = true; + if (column.select("img[id^=lockicon]").first() != null) + pLocked = true; + if (column.select("a[id^=newicon]").first() != null) + pUnread = true; + pStarter = topicColumns.get(3).text(); pStats = "Replies: " + topicColumns.get(4).text() + ", Views: " + topicColumns.get(5).text(); @@ -304,8 +306,10 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo pLastPostDateTime = matcher.group(1); pLastUser = matcher.group(3); } - else - throw new ParseException("Parsing failed (pLastPost came with: \"" + pLastPost + "\")"); + else{ + Timber.e("Parsing failed (pLastPost came with: \"%s\", html was \"%s\")", pLastPost, topicColumns); + continue; + } pLastPostUrl = topicColumns.last().select("a:has(img)").first().attr("href"); tempTopics.add(new Topic(pTopicUrl, pSubject, pStarter, pLastUser, pLastPostDateTime, pLastPostUrl, 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 c508fdc2..0a697706 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 @@ -161,9 +161,25 @@ class BoardAdapter extends RecyclerView.Adapter { boardExpandableVisibility.set(subBoardViewHolder.getAdapterPosition() - 1, !visible); }); subBoardViewHolder.boardTitle.setText(subBoard.getTitle()); - subBoardViewHolder.boardMods.setText(subBoard.getMods()); - subBoardViewHolder.boardStats.setText(subBoard.getStats()); - subBoardViewHolder.boardLastPost.setText(subBoard.getLastPost()); + String mods = subBoard.getMods(); + String stats = subBoard.getStats(); + String lastPost = subBoard.getLastPost(); + + if(!mods.isEmpty()){ + subBoardViewHolder.boardMods.setText(mods); + subBoardViewHolder.boardMods.setVisibility(View.VISIBLE); + } + + if(!stats.isEmpty()){ + subBoardViewHolder.boardStats.setText(stats); + subBoardViewHolder.boardStats.setVisibility(View.VISIBLE); + } + + if(!lastPost.isEmpty()){ + subBoardViewHolder.boardLastPost.setText(lastPost); + subBoardViewHolder.boardLastPost.setVisibility(View.VISIBLE); + } + if (!Objects.equals(subBoard.getLastPostUrl(), "")) { subBoardViewHolder.boardLastPost.setOnClickListener(view -> { Intent intent = new Intent(context, TopicActivity.class); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index e0f41e8f..def64530 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -982,7 +982,6 @@ class TopicAdapter extends RecyclerView.Adapter { for (int i = 0; i < topicItems.size(); i++) { if (topicItems.get(i) instanceof Post && ((Post) topicItems.get(i)).getPostIndex() == testAgainst) { //same page - Timber.d(Integer.toString(i)); postFocusListener.onPostFocusChange(i); return true; } diff --git a/app/src/main/res/layout/activity_board_sub_board_row.xml b/app/src/main/res/layout/activity_board_sub_board_row.xml index 97335218..ac8eb60a 100644 --- a/app/src/main/res/layout/activity_board_sub_board_row.xml +++ b/app/src/main/res/layout/activity_board_sub_board_row.xml @@ -62,7 +62,8 @@ android:text="@string/child_board_mods" android:textColor="@color/secondary_text" android:textSize="12sp" - android:textStyle="italic" /> + android:textStyle="italic" + android:visibility="gone" /> + android:textSize="12sp" + android:visibility="gone" /> + android:textSize="12sp" + android:visibility="gone" /> \ No newline at end of file