From e9f8b629a7fd243558f2f80456e42cfd61b407aa Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sat, 14 Jan 2017 14:48:34 +0200 Subject: [PATCH] More BoardActivity style changes --- .../activities/board/BoardActivity.java | 36 +++++++++++++++---- .../mthmmy/activities/board/BoardAdapter.java | 24 +++++++++++++ .../activities/main/forum/ForumFragment.java | 2 +- .../main/java/gr/thmmy/mthmmy/data/Board.java | 9 +++-- .../main/java/gr/thmmy/mthmmy/data/Topic.java | 29 ++++++++------- .../res/layout/activity_board_sub_board.xml | 15 ++++++-- .../main/res/layout/activity_board_topic.xml | 19 +++++++--- 7 files changed, 107 insertions(+), 27 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 76eff468..f9cc6e5c 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 @@ -6,6 +6,7 @@ import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; +import android.util.Log; import android.widget.ProgressBar; import android.widget.Toast; @@ -197,20 +198,34 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo for (Element subBoardRow : subBoardRows) { if (!Objects.equals(subBoardRow.className(), "titlebg")) { String pUrl = "", pTitle = "", pMods = "", pStats = "", - pLastPost = "No posts yet"; + pLastPost = "No posts yet", pLastPostUrl = ""; Elements subBoardColumns = subBoardRow.select(">td"); for (Element subBoardCol : subBoardColumns) { if (Objects.equals(subBoardCol.className(), "windowbg")) pStats = subBoardCol.text(); - else if (Objects.equals(subBoardCol.className(), "smalltext")) + else if (Objects.equals(subBoardCol.className(), "smalltext")) { pLastPost = subBoardCol.text(); - else { + if (pLastPost.contains(" in ")) { + pLastPost = pLastPost.substring(0, pLastPost.indexOf(" in ")) + + "\n" + + pLastPost.substring(pLastPost.indexOf(" in ") + 1, pLastPost.indexOf(" by ")) + + "\n" + + pLastPost.substring(pLastPost.lastIndexOf(" by ") + 1); + } else { + pLastPost = pLastPost.substring(0, pLastPost.indexOf(" σε ")) + + "\n" + + pLastPost.substring(pLastPost.indexOf(" σε ") + 1, pLastPost.indexOf(" από ")) + + "\n" + + pLastPost.substring(pLastPost.lastIndexOf(" από ") + 1); + } + pLastPostUrl = subBoardCol.select("a").first().attr("href"); + } else { pUrl = subBoardCol.select("a").first().attr("href"); pTitle = subBoardCol.select("a").first().text(); pMods = subBoardCol.select("div.smalltext").first().text(); } } - parsedSubBoards.add(new Board(pUrl, pTitle, pMods, pStats, pLastPost)); + parsedSubBoards.add(new Board(pUrl, pTitle, pMods, pStats, pLastPost, pLastPostUrl)); } } } @@ -220,7 +235,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo if (topicRows != null && !topicRows.isEmpty()) { for (Element topicRow : topicRows) { if (!Objects.equals(topicRow.className(), "titlebg")) { - String pTopicUrl, pSubject, pStartedBy, pLastPost, pStats; + String pTopicUrl, pSubject, pStartedBy, pLastPost, pLastPostUrl, pStats; boolean pLocked = false, pSticky = false; Elements topicColumns = topicRow.select(">td"); { @@ -235,8 +250,17 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo } pStartedBy = topicColumns.get(3).text(); pStats = "Replies " + topicColumns.get(4).text() + ", Views " + topicColumns.get(5).text(); + pLastPost = topicColumns.last().text(); - parsedTopics.add(new Topic(pTopicUrl, pSubject, pStartedBy, pLastPost, + if (pLastPost.contains("by")) { + pLastPost = pLastPost.substring(0, pLastPost.indexOf("by")) + + "\n" + pLastPost.substring(pLastPost.indexOf("by")); + } else { + pLastPost = pLastPost.substring(0, pLastPost.indexOf("από")) + + "\n" + pLastPost.substring(pLastPost.indexOf("από")); + } + pLastPostUrl = topicColumns.last().select("a:has(img)").first().attr("href"); + parsedTopics.add(new Topic(pTopicUrl, pSubject, pStartedBy, pLastPost, pLastPostUrl, pStats, pLocked, pSticky)); } } 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 6ad340fd..cae5688b 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 @@ -164,6 +164,18 @@ class BoardAdapter extends RecyclerView.Adapter { subBoardViewHolder.boardMods.setText(subBoard.getMods()); subBoardViewHolder.boardStats.setText(subBoard.getStats()); subBoardViewHolder.boardLastPost.setText(subBoard.getLastPost()); + subBoardViewHolder.boardLastPost.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(context, TopicActivity.class); + Bundle extras = new Bundle(); + extras.putString(BUNDLE_TOPIC_URL, subBoard.getLastPostUrl()); + //Doesn't put an already ellipsized topic title in Bundle + intent.putExtras(extras); + intent.setFlags(FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + } + }); } else if (holder instanceof TopicViewHolder) { final Topic topic = parsedTopics.get(position - parsedSubBoards.size() - 1 - 1); final TopicViewHolder topicViewHolder = (TopicViewHolder) holder; @@ -222,6 +234,18 @@ class BoardAdapter extends RecyclerView.Adapter { topicViewHolder.topicStartedBy.setText(context.getString(R.string.topic_started_by, topic.getStarter())); topicViewHolder.topicStats.setText(topic.getStats()); topicViewHolder.topicLastPost.setText(context.getString(R.string.topic_last_post, topic.getLastPost())); + topicViewHolder.topicLastPost.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(context, TopicActivity.class); + Bundle extras = new Bundle(); + extras.putString(BUNDLE_TOPIC_URL, topic.getLastPostUrl()); + //Doesn't put an already ellipsized topic title in Bundle + intent.putExtras(extras); + intent.setFlags(FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + } + }); } else if (holder instanceof LoadingViewHolder) { LoadingViewHolder loadingViewHolder = (LoadingViewHolder) holder; loadingViewHolder.progressBar.setIndeterminate(true); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java index 28cf90c5..e586d931 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java @@ -214,7 +214,7 @@ public class ForumFragment extends BaseFragment category.setExpanded(true); Elements boardsElements = categoryBlock.select("b [name]"); for(Element boardElement: boardsElements) { - Board board = new Board(boardElement.attr("href"), boardElement.text(), null, null, null); + Board board = new Board(boardElement.attr("href"), boardElement.text(), null, null, null, null); category.getBoards().add(board); } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/data/Board.java b/app/src/main/java/gr/thmmy/mthmmy/data/Board.java index 591187a4..72b8b64d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/data/Board.java +++ b/app/src/main/java/gr/thmmy/mthmmy/data/Board.java @@ -1,14 +1,15 @@ package gr.thmmy.mthmmy.data; public class Board { - private final String url, title, mods, stats, lastPost; + private final String url, title, mods, stats, lastPost, lastPostUrl; - public Board(String url, String title, String mods, String stats, String lastPost) { + public Board(String url, String title, String mods, String stats, String lastPost, String lastPostUrl) { this.url = url; this.title = title; this.mods = mods; this.stats = stats; this.lastPost = lastPost; + this.lastPostUrl = lastPostUrl; } public String getUrl() { @@ -30,4 +31,8 @@ public class Board { public String getLastPost() { return lastPost; } + + public String getLastPostUrl() { + return lastPostUrl; + } } \ No newline at end of file diff --git a/app/src/main/java/gr/thmmy/mthmmy/data/Topic.java b/app/src/main/java/gr/thmmy/mthmmy/data/Topic.java index 0041e422..714485c4 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/data/Topic.java +++ b/app/src/main/java/gr/thmmy/mthmmy/data/Topic.java @@ -1,17 +1,22 @@ package gr.thmmy.mthmmy.data; public class Topic extends TopicSummary { - private final String stats; + private final String lastPostUrl, stats; private final boolean locked, sticky; - public Topic(String topicUrl, String subject, String starter, String lastPost, + public Topic(String topicUrl, String subject, String starter, String lastPost, String lastPostUrl, String stats, boolean locked, boolean sticky) { super(topicUrl, subject, starter, lastPost); + this.lastPostUrl = lastPostUrl; this.stats = stats; this.locked = locked; this.sticky = sticky; } + public String getUrl() { + return topicUrl; + } + public String getSubject() { return subject; } @@ -20,23 +25,23 @@ public class Topic extends TopicSummary { return lastUser; } - public boolean isLocked() { - return locked; + public String getLastPost() { + return dateTimeModified; } - public boolean isSticky() { - return sticky; + public String getLastPostUrl() { + return lastPostUrl; } - public String getUrl() { - return topicUrl; + public String getStats() { + return stats; } - public String getLastPost() { - return dateTimeModified; + public boolean isLocked() { + return locked; } - public String getStats() { - return stats; + public boolean isSticky() { + return sticky; } } diff --git a/app/src/main/res/layout/activity_board_sub_board.xml b/app/src/main/res/layout/activity_board_sub_board.xml index 07557353..b78a9c07 100644 --- a/app/src/main/res/layout/activity_board_sub_board.xml +++ b/app/src/main/res/layout/activity_board_sub_board.xml @@ -40,6 +40,7 @@ android:id="@+id/child_board_expandable" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginBottom="5dp" android:orientation="vertical" android:visibility="gone"> @@ -47,22 +48,32 @@ android:id="@+id/child_board_mods" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginBottom="1dp" + android:layout_marginTop="1dp" android:text="@string/child_board_mods" android:textColor="@color/secondary_text" + android:textSize="12sp" android:textStyle="italic"/> + android:textColor="@color/secondary_text" + android:textSize="12sp"/> + android:textColor="@color/primary_text" + android:textSize="12sp"/> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_board_topic.xml b/app/src/main/res/layout/activity_board_topic.xml index debdc311..a036f151 100644 --- a/app/src/main/res/layout/activity_board_topic.xml +++ b/app/src/main/res/layout/activity_board_topic.xml @@ -39,6 +39,7 @@ android:id="@+id/topic_expandable" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginBottom="5dp" android:orientation="vertical" android:visibility="gone"> @@ -46,21 +47,31 @@ android:id="@+id/topic_started_by" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginBottom="1dp" + android:layout_marginTop="1dp" android:text="@string/topic_started_by" - android:textColor="@color/secondary_text"/> + android:textColor="@color/secondary_text" + android:textSize="12sp"/> + android:textColor="@color/secondary_text" + android:textSize="12sp"/> + android:textColor="@color/primary_text" + android:textSize="12sp"/> \ No newline at end of file