Browse Source

BoardActivity improvements

pull/70/head
Ezerous 5 years ago
parent
commit
d767d27072
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 56
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
  2. 22
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java
  3. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  4. 9
      app/src/main/res/layout/activity_board_sub_board_row.xml

56
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(); Toast.makeText(this, "An error has occurred\nAborting.", Toast.LENGTH_SHORT).show();
finish(); finish();
} }
//Fixes url //Fixes url
{ String tmpUrlSbstr = boardUrl.replaceAll("(.+)(board=)([0-9]*)(\\.*[0-9]*).*", "$1$2$3");
String tmpUrlSbstr = boardUrl.replaceAll("(.+)(board=)([0-9]*)(\\.*[0-9]*).*", "$1$2$3"); if (!tmpUrlSbstr.substring(tmpUrlSbstr.indexOf("board=")).contains("."))
if (!tmpUrlSbstr.substring(tmpUrlSbstr.indexOf("board=")).contains(".")) boardUrl = tmpUrlSbstr + ".0";
boardUrl = tmpUrlSbstr + ".0";
}
//Initializes graphics //Initializes graphics
toolbar = findViewById(R.id.toolbar); toolbar = findViewById(R.id.toolbar);
@ -239,8 +238,12 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
pLastPost = "No posts yet", pLastPostUrl = ""; pLastPost = "No posts yet", pLastPostUrl = "";
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")){
pStats = subBoardCol.text(); pStats = subBoardCol.text();
if(pStats.equals("--"))
pStats = "";
}
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 ")) {
@ -257,16 +260,15 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
"\n" + "\n" +
pLastPost.substring(pLastPost.lastIndexOf(" από ") + 1); pLastPost.substring(pLastPost.lastIndexOf(" από ") + 1);
pLastPostUrl = subBoardCol.select("a").first().attr("href"); pLastPostUrl = subBoardCol.select("a").first().attr("href");
} else { } else if (pLastPost.contains("redirected clicks")||pLastPost.contains("N/A"))
pLastPost = "No posts yet."; pLastPost = "";
pLastPostUrl = ""; else
} pLastPost = "No posts yet";
} else { } else {
pUrl = subBoardCol.select("a").first().attr("href"); pUrl = subBoardCol.select("a").first().attr("href");
pTitle = subBoardCol.select("a").first().text(); 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(); pMods = subBoardCol.select("div.smalltext").first().text();
}
} }
} }
tempSubboards.add(new Board(pUrl, pTitle, pMods, pStats, pLastPost, pLastPostUrl)); 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; String pTopicUrl, pSubject, pStarter, pLastUser="", pLastPostDateTime="00:00:00", pLastPost, pLastPostUrl, pStats;
boolean pLocked = false, pSticky = false, pUnread = false; boolean pLocked = false, pSticky = false, pUnread = false;
Elements topicColumns = topicRow.select(">td"); Elements topicColumns = topicRow.select(">td");
{
Element column = topicColumns.get(2); Element column = topicColumns.get(2);
Element tmp = column.select("span[id^=msg_] a").first(); Element tmp = column.select("span[id^=msg_] a").first();
pTopicUrl = tmp.attr("href"); pTopicUrl = tmp.attr("href");
pSubject = tmp.text(); pSubject = tmp.text();
if (column.select("img[id^=stickyicon]").first() != null) if (column.select("img[id^=stickyicon]").first() != null)
pSticky = true; pSticky = true;
if (column.select("img[id^=lockicon]").first() != null) if (column.select("img[id^=lockicon]").first() != null)
pLocked = true; pLocked = true;
if (column.select("a[id^=newicon]").first() != null) if (column.select("a[id^=newicon]").first() != null)
pUnread = true; pUnread = true;
}
pStarter = topicColumns.get(3).text(); pStarter = topicColumns.get(3).text();
pStats = "Replies: " + topicColumns.get(4).text() + ", Views: " + topicColumns.get(5).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); pLastPostDateTime = matcher.group(1);
pLastUser = matcher.group(3); pLastUser = matcher.group(3);
} }
else else{
throw new ParseException("Parsing failed (pLastPost came with: \"" + pLastPost + "\")"); Timber.e("Parsing failed (pLastPost came with: \"%s\", html was \"%s\")", pLastPost, topicColumns);
continue;
}
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,

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

@ -161,9 +161,25 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
boardExpandableVisibility.set(subBoardViewHolder.getAdapterPosition() - 1, !visible); boardExpandableVisibility.set(subBoardViewHolder.getAdapterPosition() - 1, !visible);
}); });
subBoardViewHolder.boardTitle.setText(subBoard.getTitle()); subBoardViewHolder.boardTitle.setText(subBoard.getTitle());
subBoardViewHolder.boardMods.setText(subBoard.getMods()); String mods = subBoard.getMods();
subBoardViewHolder.boardStats.setText(subBoard.getStats()); String stats = subBoard.getStats();
subBoardViewHolder.boardLastPost.setText(subBoard.getLastPost()); 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(), "")) { if (!Objects.equals(subBoard.getLastPostUrl(), "")) {
subBoardViewHolder.boardLastPost.setOnClickListener(view -> { subBoardViewHolder.boardLastPost.setOnClickListener(view -> {
Intent intent = new Intent(context, TopicActivity.class); Intent intent = new Intent(context, TopicActivity.class);

1
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

@ -982,7 +982,6 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
for (int i = 0; i < topicItems.size(); i++) { for (int i = 0; i < topicItems.size(); i++) {
if (topicItems.get(i) instanceof Post && ((Post) topicItems.get(i)).getPostIndex() == testAgainst) { if (topicItems.get(i) instanceof Post && ((Post) topicItems.get(i)).getPostIndex() == testAgainst) {
//same page //same page
Timber.d(Integer.toString(i));
postFocusListener.onPostFocusChange(i); postFocusListener.onPostFocusChange(i);
return true; return true;
} }

9
app/src/main/res/layout/activity_board_sub_board_row.xml

@ -62,7 +62,8 @@
android:text="@string/child_board_mods" android:text="@string/child_board_mods"
android:textColor="@color/secondary_text" android:textColor="@color/secondary_text"
android:textSize="12sp" android:textSize="12sp"
android:textStyle="italic" /> android:textStyle="italic"
android:visibility="gone" />
<TextView <TextView
android:id="@+id/child_board_stats" android:id="@+id/child_board_stats"
@ -72,7 +73,8 @@
android:layout_marginBottom="1dp" android:layout_marginBottom="1dp"
android:text="@string/child_board_stats" android:text="@string/child_board_stats"
android:textColor="@color/secondary_text" android:textColor="@color/secondary_text"
android:textSize="12sp" /> android:textSize="12sp"
android:visibility="gone" />
<TextView <TextView
android:id="@+id/child_board_last_post" android:id="@+id/child_board_last_post"
@ -84,7 +86,8 @@
android:focusable="true" android:focusable="true"
android:text="@string/child_board_last_post" android:text="@string/child_board_last_post"
android:textColor="@color/primary_text" android:textColor="@color/primary_text"
android:textSize="12sp" /> android:textSize="12sp"
android:visibility="gone" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
Loading…
Cancel
Save