mirror of https://github.com/ThmmyNoLife/mTHMMY
Apostolos Fanakis
8 years ago
24 changed files with 754 additions and 239 deletions
@ -0,0 +1,180 @@ |
|||
package gr.thmmy.mthmmy.activities.board; |
|||
|
|||
import android.content.Context; |
|||
import android.content.Intent; |
|||
import android.os.Bundle; |
|||
import android.support.v7.widget.RecyclerView; |
|||
import android.view.LayoutInflater; |
|||
import android.view.View; |
|||
import android.view.ViewGroup; |
|||
import android.widget.LinearLayout; |
|||
import android.widget.TextView; |
|||
|
|||
import java.util.ArrayList; |
|||
|
|||
import gr.thmmy.mthmmy.R; |
|||
import gr.thmmy.mthmmy.activities.topic.TopicActivity; |
|||
import gr.thmmy.mthmmy.data.Board; |
|||
import gr.thmmy.mthmmy.data.Topic; |
|||
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; |
|||
|
|||
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
|||
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; |
|||
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; |
|||
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; |
|||
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; |
|||
|
|||
/** |
|||
* {@link RecyclerView.Adapter} that can display a {@link gr.thmmy.mthmmy.data.Board}. |
|||
*/ |
|||
class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|||
private static final String TAG = "BoardAdapter"; |
|||
private final int VIEW_TYPE_SUB_BOARD = 0; |
|||
private final int VIEW_TYPE_TOPIC = 1; |
|||
private final int VIEW_TYPE_LOADING = 2; |
|||
|
|||
private final Context context; |
|||
private ArrayList<Board> parsedSubBoards = new ArrayList<>(); |
|||
private ArrayList<Topic> parsedTopics = new ArrayList<>(); |
|||
|
|||
BoardAdapter(Context context, ArrayList<Board> parsedSubBoards, ArrayList<Topic> parsedTopics) { |
|||
this.context = context; |
|||
this.parsedSubBoards = parsedSubBoards; |
|||
this.parsedTopics = parsedTopics; |
|||
} |
|||
|
|||
interface OnLoadMoreListener { |
|||
void onLoadMore(); |
|||
} |
|||
|
|||
@Override |
|||
public int getItemViewType(int position) { |
|||
if (position < parsedSubBoards.size()) |
|||
return VIEW_TYPE_SUB_BOARD; |
|||
else if (parsedTopics.get(position - parsedSubBoards.size()) != null) |
|||
return VIEW_TYPE_TOPIC; |
|||
else return VIEW_TYPE_LOADING; |
|||
} |
|||
|
|||
@Override |
|||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
|||
if (viewType == VIEW_TYPE_SUB_BOARD) { |
|||
View view = LayoutInflater.from(parent.getContext()). |
|||
inflate(R.layout.activity_board_sub_board, parent, false); |
|||
return new SubBoardViewHolder(view); |
|||
} else if (viewType == VIEW_TYPE_TOPIC) { |
|||
View view = LayoutInflater.from(parent.getContext()). |
|||
inflate(R.layout.activity_board_topic, parent, false); |
|||
return new TopicViewHolder(view); |
|||
} else if (viewType == VIEW_TYPE_LOADING) { |
|||
View view = LayoutInflater.from(parent.getContext()). |
|||
inflate(R.layout.recycler_loading_item, parent, false); |
|||
return new LoadingViewHolder(view); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) { |
|||
if (holder instanceof SubBoardViewHolder) { |
|||
Board subBoard = parsedSubBoards.get(position); |
|||
final SubBoardViewHolder subBoardViewHolder = (SubBoardViewHolder) holder; |
|||
|
|||
subBoardViewHolder.boardRow.setOnClickListener(new View.OnClickListener() { |
|||
@Override |
|||
public void onClick(View view) { |
|||
Intent intent = new Intent(context, BoardActivity.class); |
|||
Bundle extras = new Bundle(); |
|||
extras.putString(BUNDLE_BOARD_URL, parsedSubBoards.get(holder. |
|||
getAdapterPosition()).getUrl()); |
|||
extras.putString(BUNDLE_BOARD_TITLE, parsedSubBoards.get(holder. |
|||
getAdapterPosition()).getTitle()); |
|||
intent.putExtras(extras); |
|||
intent.setFlags(FLAG_ACTIVITY_NEW_TASK); |
|||
context.startActivity(intent); |
|||
} |
|||
}); |
|||
subBoardViewHolder.boardTitle.setText(subBoard.getTitle()); |
|||
subBoardViewHolder.boardMods.setText(context.getString(R.string.child_board_mods, subBoard.getMods())); |
|||
subBoardViewHolder.boardStats.setText(subBoard.getStats()); |
|||
subBoardViewHolder.boardLastPost.setText(subBoard.getLastPost()); |
|||
} else if (holder instanceof TopicViewHolder) { |
|||
Topic topic = parsedTopics.get(position - parsedSubBoards.size()); |
|||
final TopicViewHolder topicViewHolder = (TopicViewHolder) holder; |
|||
|
|||
topicViewHolder.topicRow.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, parsedTopics.get(holder. |
|||
getAdapterPosition()).getUrl()); |
|||
extras.putString(BUNDLE_TOPIC_TITLE, parsedTopics.get(holder. |
|||
getAdapterPosition()).getSubject()); |
|||
intent.putExtras(extras); |
|||
intent.setFlags(FLAG_ACTIVITY_NEW_TASK); |
|||
context.startActivity(intent); |
|||
} |
|||
}); |
|||
topicViewHolder.topicSubject.setText(topic.getSubject()); |
|||
String lockedSticky = ""; |
|||
if (topic.isLocked()) |
|||
lockedSticky += context.getResources().getString(R.string.fa_lock); |
|||
if (topic.isSticky()) |
|||
lockedSticky += context.getResources().getString(R.string.fa_sticky); |
|||
topicViewHolder.topicLockedSticky.setText(lockedSticky); |
|||
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())); |
|||
} else if (holder instanceof LoadingViewHolder) { |
|||
LoadingViewHolder loadingViewHolder = (LoadingViewHolder) holder; |
|||
loadingViewHolder.progressBar.setIndeterminate(true); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public int getItemCount() { |
|||
if (parsedSubBoards == null && parsedTopics == null) return 0; |
|||
else if (parsedSubBoards == null) return parsedTopics.size(); |
|||
else if (parsedTopics == null) return parsedSubBoards.size(); |
|||
else return parsedSubBoards.size() + parsedTopics.size(); |
|||
} |
|||
|
|||
private static class SubBoardViewHolder extends RecyclerView.ViewHolder { |
|||
final LinearLayout boardRow; |
|||
final TextView boardTitle, boardMods, boardStats, boardLastPost; |
|||
|
|||
SubBoardViewHolder(View itemView) { |
|||
super(itemView); |
|||
boardRow = (LinearLayout) itemView.findViewById(R.id.child_board_row); |
|||
boardTitle = (TextView) itemView.findViewById(R.id.child_board_title); |
|||
boardMods = (TextView) itemView.findViewById(R.id.child_board_mods); |
|||
boardStats = (TextView) itemView.findViewById(R.id.child_board_stats); |
|||
boardLastPost = (TextView) itemView.findViewById(R.id.child_board_last_post); |
|||
} |
|||
} |
|||
|
|||
private static class TopicViewHolder extends RecyclerView.ViewHolder { |
|||
final LinearLayout topicRow; |
|||
final TextView topicSubject, topicLockedSticky, topicStartedBy, topicStats, topicLastPost; |
|||
|
|||
TopicViewHolder(View itemView) { |
|||
super(itemView); |
|||
topicRow = (LinearLayout) itemView.findViewById(R.id.topic_row_linear); |
|||
topicSubject = (TextView) itemView.findViewById(R.id.topic_subject); |
|||
topicLockedSticky = (TextView) itemView.findViewById(R.id.topic_locked_sticky); |
|||
topicStartedBy = (TextView) itemView.findViewById(R.id.topic_started_by); |
|||
topicStats = (TextView) itemView.findViewById(R.id.topic_stats); |
|||
topicLastPost = (TextView) itemView.findViewById(R.id.topic_last_post); |
|||
} |
|||
} |
|||
|
|||
private static class LoadingViewHolder extends RecyclerView.ViewHolder { |
|||
final MaterialProgressBar progressBar; |
|||
|
|||
LoadingViewHolder(View itemView) { |
|||
super(itemView); |
|||
progressBar = (MaterialProgressBar) itemView.findViewById(R.id.recycler_progress_bar); |
|||
} |
|||
} |
|||
} |
@ -1,34 +1,33 @@ |
|||
package gr.thmmy.mthmmy.data; |
|||
|
|||
import java.util.ArrayList; |
|||
|
|||
public class Board { |
|||
private final String title; |
|||
private final String boardURL; |
|||
|
|||
private ArrayList <Board> subBoards; |
|||
private ArrayList <TopicSummary> topicSummaries; |
|||
private final String url, title, mods, stats, lastPost; |
|||
|
|||
public Board(String title, String boardURL) { |
|||
public Board(String url, String title, String mods, String stats, String lastPost) { |
|||
this.url = url; |
|||
this.title = title; |
|||
this.boardURL = boardURL; |
|||
subBoards = new ArrayList<>(); |
|||
topicSummaries = new ArrayList<>(); |
|||
this.mods = mods; |
|||
this.stats = stats; |
|||
this.lastPost = lastPost; |
|||
} |
|||
|
|||
public String getUrl() { |
|||
return url; |
|||
} |
|||
|
|||
public String getTitle() { |
|||
return title; |
|||
} |
|||
|
|||
public String getBoardURL() { |
|||
return boardURL; |
|||
public String getMods() { |
|||
return mods; |
|||
} |
|||
|
|||
public ArrayList<Board> getSubBoards() { |
|||
return subBoards; |
|||
public String getStats() { |
|||
return stats; |
|||
} |
|||
|
|||
public ArrayList<TopicSummary> getTopicSummaries() { |
|||
return topicSummaries; |
|||
public String getLastPost() { |
|||
return lastPost; |
|||
} |
|||
} |
@ -0,0 +1,30 @@ |
|||
package gr.thmmy.mthmmy.data; |
|||
|
|||
public class PostSummary { |
|||
private final String topicUrl; |
|||
private final String title; |
|||
private final String dateTime; |
|||
private final String post; |
|||
|
|||
public PostSummary(String topicUrl, String title, String dateTime, |
|||
String post) { |
|||
this.topicUrl = topicUrl; |
|||
this.title = title; |
|||
this.dateTime = dateTime; |
|||
this.post = post; |
|||
} |
|||
|
|||
public String getTopicUrl() { |
|||
return topicUrl; |
|||
} |
|||
|
|||
public String getTitle() { |
|||
return title; |
|||
} |
|||
|
|||
public String getDateTime() { |
|||
return dateTime; |
|||
} |
|||
|
|||
public String getPost(){ return post;} |
|||
} |
@ -0,0 +1,42 @@ |
|||
package gr.thmmy.mthmmy.data; |
|||
|
|||
public class Topic extends TopicSummary { |
|||
private final String stats; |
|||
private final boolean locked, sticky; |
|||
|
|||
public Topic(String topicUrl, String subject, String starter, String lastPost, |
|||
String stats, boolean locked, boolean sticky) { |
|||
super(topicUrl, subject, starter, lastPost); |
|||
this.stats = stats; |
|||
this.locked = locked; |
|||
this.sticky = sticky; |
|||
} |
|||
|
|||
public String getSubject() { |
|||
return subject; |
|||
} |
|||
|
|||
public String getStarter() { |
|||
return lastUser; |
|||
} |
|||
|
|||
public boolean isLocked() { |
|||
return locked; |
|||
} |
|||
|
|||
public boolean isSticky() { |
|||
return sticky; |
|||
} |
|||
|
|||
public String getUrl() { |
|||
return topicUrl; |
|||
} |
|||
|
|||
public String getLastPost() { |
|||
return dateTimeModified; |
|||
} |
|||
|
|||
public String getStats() { |
|||
return stats; |
|||
} |
|||
} |
@ -0,0 +1,48 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<LinearLayout |
|||
xmlns:android="http://schemas.android.com/apk/res/android" |
|||
android:id="@+id/child_board_row" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:background="@color/card_background" |
|||
android:clickable="true" |
|||
android:orientation="vertical" |
|||
android:paddingLeft="10dp" |
|||
android:paddingRight="10dp"> |
|||
|
|||
<TextView |
|||
android:id="@+id/child_board_title" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:text="@string/child_board_title" |
|||
android:textColor="@color/accent" |
|||
android:textStyle="bold"/> |
|||
|
|||
<TextView |
|||
android:id="@+id/child_board_mods" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
|
|||
android:layout_marginLeft="7dp" |
|||
android:layout_marginRight="7dp" |
|||
android:text="@string/child_board_mods" |
|||
android:textColor="@color/secondary_text"/> |
|||
|
|||
<TextView |
|||
android:id="@+id/child_board_stats" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:layout_marginLeft="7dp" |
|||
android:layout_marginRight="7dp" |
|||
android:text="@string/child_board_stats" |
|||
android:textColor="@color/secondary_text"/> |
|||
|
|||
<TextView |
|||
android:id="@+id/child_board_last_post" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:layout_marginLeft="7dp" |
|||
android:layout_marginRight="7dp" |
|||
android:text="@string/child_board_last_post" |
|||
android:textColor="@color/secondary_text"/> |
|||
</LinearLayout> |
@ -0,0 +1,60 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<LinearLayout |
|||
xmlns:android="http://schemas.android.com/apk/res/android" |
|||
android:id="@+id/topic_row_linear" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:clickable="true" |
|||
android:orientation="vertical" |
|||
android:paddingLeft="10dp" |
|||
android:paddingRight="10dp"> |
|||
|
|||
<LinearLayout |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:orientation="horizontal"> |
|||
|
|||
<TextView |
|||
android:id="@+id/topic_subject" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:text="@string/topic_subject" |
|||
android:textColor="@color/primary_text" |
|||
android:textStyle="bold"/> |
|||
|
|||
<TextView |
|||
android:id="@+id/topic_locked_sticky" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:contentDescription="@string/topic_locked_sticky" |
|||
android:textColor="@color/accent"/> |
|||
|
|||
</LinearLayout> |
|||
|
|||
<TextView |
|||
android:id="@+id/topic_started_by" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_marginLeft="7dp" |
|||
android:layout_marginRight="7dp" |
|||
android:text="@string/topic_started_by" |
|||
android:textColor="@color/secondary_text"/> |
|||
|
|||
<TextView |
|||
android:id="@+id/topic_stats" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_marginLeft="7dp" |
|||
android:layout_marginRight="7dp" |
|||
android:text="@string/topic_stats" |
|||
android:textColor="@color/secondary_text"/> |
|||
|
|||
<TextView |
|||
android:id="@+id/topic_last_post" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_marginLeft="7dp" |
|||
android:layout_marginRight="7dp" |
|||
android:text="@string/topic_last_post" |
|||
android:textColor="@color/secondary_text"/> |
|||
</LinearLayout> |
@ -1,54 +1,54 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|||
<LinearLayout |
|||
xmlns:android="http://schemas.android.com/apk/res/android" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:orientation="vertical" |
|||
> |
|||
android:layout_height="wrap_content" |
|||
android:orientation="vertical"> |
|||
|
|||
<RelativeLayout |
|||
<RelativeLayout |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:background="@color/primary_light" |
|||
android:foreground="?android:attr/selectableItemBackground" |
|||
android:paddingBottom="6dp" |
|||
android:paddingLeft="10dp" |
|||
android:paddingRight="10dp" |
|||
android:paddingTop="6dp"> |
|||
|
|||
<TextView |
|||
android:id="@+id/title" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:background="@color/primary_light" |
|||
android:foreground="?android:attr/selectableItemBackground" |
|||
android:paddingBottom="6dp" |
|||
android:paddingLeft="10dp" |
|||
android:paddingRight="10dp" |
|||
android:paddingTop="6dp"> |
|||
|
|||
<TextView |
|||
android:id="@+id/title" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:layout_alignParentStart="true" |
|||
android:layout_alignParentTop="true" |
|||
android:textAppearance="?attr/textAppearanceListItem" |
|||
android:textColor="@color/primary_text"/> |
|||
android:layout_alignParentStart="true" |
|||
android:layout_alignParentTop="true" |
|||
android:textAppearance="?attr/textAppearanceListItem" |
|||
android:textColor="@color/primary_text"/> |
|||
|
|||
<Space |
|||
android:id="@+id/spacer" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="20dp" |
|||
android:layout_alignParentBottom="@+id/title" |
|||
android:layout_below="@+id/title" |
|||
android:layout_toEndOf="@+id/dateTime"/> |
|||
<Space |
|||
android:id="@+id/spacer" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="20dp" |
|||
android:layout_alignParentBottom="@+id/title" |
|||
android:layout_below="@+id/title" |
|||
android:layout_toEndOf="@+id/dateTime"/> |
|||
|
|||
<TextView |
|||
android:id="@+id/dateTime" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_alignParentStart="true" |
|||
android:layout_below="@+id/spacer" |
|||
android:textColor="@color/secondary_text"/> |
|||
<TextView |
|||
android:id="@+id/dateTime" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_alignParentStart="true" |
|||
android:layout_below="@+id/spacer" |
|||
android:textColor="@color/secondary_text"/> |
|||
|
|||
<TextView |
|||
android:id="@+id/lastUser" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_alignBaseline="@+id/dateTime" |
|||
android:layout_alignBottom="@+id/dateTime" |
|||
android:layout_alignParentEnd="true" |
|||
android:textColor="@color/secondary_text" |
|||
android:textStyle="italic"/> |
|||
</RelativeLayout> |
|||
<TextView |
|||
android:id="@+id/lastUser" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_alignBaseline="@+id/dateTime" |
|||
android:layout_alignBottom="@+id/dateTime" |
|||
android:layout_alignParentEnd="true" |
|||
android:textColor="@color/secondary_text" |
|||
android:textStyle="italic"/> |
|||
</RelativeLayout> |
|||
|
|||
</LinearLayout> |
Loading…
Reference in new issue