Browse Source

More BoardActivity style changes

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
e9f8b629a7
  1. 36
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
  2. 24
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java
  3. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java
  4. 9
      app/src/main/java/gr/thmmy/mthmmy/data/Board.java
  5. 29
      app/src/main/java/gr/thmmy/mthmmy/data/Topic.java
  6. 15
      app/src/main/res/layout/activity_board_sub_board.xml
  7. 19
      app/src/main/res/layout/activity_board_topic.xml

36
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));
}
}

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

@ -164,6 +164,18 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
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<RecyclerView.ViewHolder> {
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);

2
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);
}
}

9
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;
}
}

29
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;
}
}

15
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"/>
<TextView
android:id="@+id/child_board_stats"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:text="@string/child_board_stats"
android:textColor="@color/secondary_text"/>
android:textColor="@color/secondary_text"
android:textSize="12sp"/>
<TextView
android:id="@+id/child_board_last_post"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:clickable="true"
android:text="@string/child_board_last_post"
android:textColor="@color/secondary_text"/>
android:textColor="@color/primary_text"
android:textSize="12sp"/>
</LinearLayout>
</LinearLayout>

19
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"/>
<TextView
android:id="@+id/topic_stats"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:text="@string/topic_stats"
android:textColor="@color/secondary_text"/>
android:textColor="@color/secondary_text"
android:textSize="12sp"/>
<TextView
android:id="@+id/topic_last_post"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:clickable="true"
android:text="@string/topic_last_post"
android:textColor="@color/secondary_text"/>
android:textColor="@color/primary_text"
android:textSize="12sp"/>
</LinearLayout>
</LinearLayout>
Loading…
Cancel
Save