|
|
@ -36,6 +36,7 @@ public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
|
private static final int TYPE_POST = 0; |
|
|
|
private static final int TYPE_POST = 0; |
|
|
|
private static final int TYPE_STATUS = 1; |
|
|
|
private static final int TYPE_STATUS = 1; |
|
|
|
private static final int TYPE_POST_STUB = 2; |
|
|
|
private static final int TYPE_POST_STUB = 2; |
|
|
|
|
|
|
|
private static final int TYPE_LAST_SEEN = 3; |
|
|
|
|
|
|
|
|
|
|
|
private final PostAdapterCallback postAdapterCallback; |
|
|
|
private final PostAdapterCallback postAdapterCallback; |
|
|
|
private final PostCellInterface.PostCellCallback postCellCallback; |
|
|
|
private final PostCellInterface.PostCellCallback postCellCallback; |
|
|
@ -50,6 +51,8 @@ public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
|
private String highlightedPostId; |
|
|
|
private String highlightedPostId; |
|
|
|
private int highlightedPostNo = -1; |
|
|
|
private int highlightedPostNo = -1; |
|
|
|
private String highlightedPostTripcode; |
|
|
|
private String highlightedPostTripcode; |
|
|
|
|
|
|
|
private int lastSeenIndicatorPosition = -1; |
|
|
|
|
|
|
|
private boolean bound; |
|
|
|
|
|
|
|
|
|
|
|
private PostCellInterface.PostViewMode postViewMode; |
|
|
|
private PostCellInterface.PostViewMode postViewMode; |
|
|
|
|
|
|
|
|
|
|
@ -64,58 +67,86 @@ public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
|
|
|
if (viewType == TYPE_POST) { |
|
|
|
switch (viewType) { |
|
|
|
int layout = 0; |
|
|
|
case TYPE_POST: |
|
|
|
switch (postViewMode) { |
|
|
|
int layout = 0; |
|
|
|
case LIST: |
|
|
|
switch (postViewMode) { |
|
|
|
layout = R.layout.cell_post; |
|
|
|
case LIST: |
|
|
|
break; |
|
|
|
layout = R.layout.cell_post; |
|
|
|
case CARD: |
|
|
|
break; |
|
|
|
layout = R.layout.cell_post_card; |
|
|
|
case CARD: |
|
|
|
break; |
|
|
|
layout = R.layout.cell_post_card; |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
PostCellInterface postCell = (PostCellInterface) LayoutInflater.from(parent.getContext()).inflate(layout, parent, false); |
|
|
|
|
|
|
|
return new PostViewHolder(postCell); |
|
|
|
PostCellInterface postCell = (PostCellInterface) LayoutInflater.from(parent.getContext()).inflate(layout, parent, false); |
|
|
|
} else if (viewType == TYPE_POST_STUB) { |
|
|
|
return new PostViewHolder(postCell); |
|
|
|
return new PostViewHolder((PostCellInterface) LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_post_stub, parent, false)); |
|
|
|
case TYPE_POST_STUB: |
|
|
|
} else { |
|
|
|
return new PostViewHolder((PostCellInterface) LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_post_stub, parent, false)); |
|
|
|
StatusViewHolder statusViewHolder = new StatusViewHolder((ThreadStatusCell) LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_thread_status, parent, false)); |
|
|
|
case TYPE_LAST_SEEN: |
|
|
|
statusViewHolder.threadStatusCell.setCallback(statusCellCallback); |
|
|
|
return new LastSeenViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_post_last_seen, parent, false)); |
|
|
|
statusViewHolder.threadStatusCell.setError(error); |
|
|
|
case TYPE_STATUS: |
|
|
|
return statusViewHolder; |
|
|
|
StatusViewHolder statusViewHolder = new StatusViewHolder((ThreadStatusCell) LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_thread_status, parent, false)); |
|
|
|
|
|
|
|
statusViewHolder.threadStatusCell.setCallback(statusCellCallback); |
|
|
|
|
|
|
|
statusViewHolder.threadStatusCell.setError(error); |
|
|
|
|
|
|
|
return statusViewHolder; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
throw new IllegalStateException(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { |
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { |
|
|
|
int itemViewType = getItemViewType(position); |
|
|
|
int itemViewType = getItemViewType(position); |
|
|
|
if (itemViewType == TYPE_POST || itemViewType == TYPE_POST_STUB) { |
|
|
|
switch (itemViewType) { |
|
|
|
PostViewHolder postViewHolder = (PostViewHolder) holder; |
|
|
|
case TYPE_POST: |
|
|
|
Post post = displayList.get(position); |
|
|
|
case TYPE_POST_STUB: |
|
|
|
boolean highlight = post == highlightedPost || post.id.equals(highlightedPostId) || post.no == highlightedPostNo || post.tripcode.equals(highlightedPostTripcode); |
|
|
|
PostViewHolder postViewHolder = (PostViewHolder) holder; |
|
|
|
postViewHolder.postView.setPost(null, post, postCellCallback, highlight, -1, postViewMode); |
|
|
|
Post post = displayList.get(getPostPosition(position)); |
|
|
|
} else if (itemViewType == TYPE_STATUS) { |
|
|
|
boolean highlight = post == highlightedPost || post.id.equals(highlightedPostId) || post.no == highlightedPostNo || post.tripcode.equals(highlightedPostTripcode); |
|
|
|
((StatusViewHolder) holder).threadStatusCell.update(); |
|
|
|
postViewHolder.postView.setPost(null, post, postCellCallback, highlight, -1, postViewMode); |
|
|
|
onScrolledToBottom(); |
|
|
|
break; |
|
|
|
|
|
|
|
case TYPE_STATUS: |
|
|
|
|
|
|
|
((StatusViewHolder) holder).threadStatusCell.update(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Avoid calling in the RecyclerView layout pass
|
|
|
|
|
|
|
|
holder.itemView.post(new Runnable() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
|
|
|
|
onScrolledToBottom(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case TYPE_LAST_SEEN: |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public int getItemCount() { |
|
|
|
public int getItemCount() { |
|
|
|
|
|
|
|
int size = displayList.size(); |
|
|
|
|
|
|
|
|
|
|
|
if (showStatusView()) { |
|
|
|
if (showStatusView()) { |
|
|
|
return displayList.size() + 1; |
|
|
|
size++; |
|
|
|
} else { |
|
|
|
|
|
|
|
return displayList.size(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (lastSeenIndicatorPosition >= 0) { |
|
|
|
|
|
|
|
size++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return size; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public int getItemViewType(int position) { |
|
|
|
public int getItemViewType(int position) { |
|
|
|
if (showStatusView() && position == getItemCount() - 1) { |
|
|
|
if (position == lastSeenIndicatorPosition) { |
|
|
|
|
|
|
|
return TYPE_LAST_SEEN; |
|
|
|
|
|
|
|
} else if (showStatusView() && position == getItemCount() - 1) { |
|
|
|
return TYPE_STATUS; |
|
|
|
return TYPE_STATUS; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Post post = displayList.get(position); |
|
|
|
Post post = displayList.get(getPostPosition(position)); |
|
|
|
if (post.filterStub) { |
|
|
|
if (post.filterStub) { |
|
|
|
return TYPE_POST_STUB; |
|
|
|
return TYPE_POST_STUB; |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -129,12 +160,15 @@ public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
|
int itemViewType = getItemViewType(position); |
|
|
|
int itemViewType = getItemViewType(position); |
|
|
|
if (itemViewType == TYPE_STATUS) { |
|
|
|
if (itemViewType == TYPE_STATUS) { |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
|
|
|
|
} else if (itemViewType == TYPE_LAST_SEEN) { |
|
|
|
|
|
|
|
return -2; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return displayList.get(position).no; |
|
|
|
return displayList.get(getPostPosition(position)).no; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setThread(ChanThread thread, PostsFilter filter) { |
|
|
|
public void setThread(ChanThread thread, PostsFilter filter) { |
|
|
|
|
|
|
|
bound = true; |
|
|
|
showError(null); |
|
|
|
showError(null); |
|
|
|
sourceList.clear(); |
|
|
|
sourceList.clear(); |
|
|
|
sourceList.addAll(thread.posts); |
|
|
|
sourceList.addAll(thread.posts); |
|
|
@ -142,6 +176,18 @@ public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
|
displayList.clear(); |
|
|
|
displayList.clear(); |
|
|
|
displayList.addAll(filter.apply(sourceList)); |
|
|
|
displayList.addAll(filter.apply(sourceList)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lastSeenIndicatorPosition = -1; |
|
|
|
|
|
|
|
if (thread.loadable.lastViewed >= 0) { |
|
|
|
|
|
|
|
// Do not process the last post, the indicator does not have to appear at the bottom
|
|
|
|
|
|
|
|
for (int i = 0, displayListSize = displayList.size() - 1; i < displayListSize; i++) { |
|
|
|
|
|
|
|
Post post = displayList.get(i); |
|
|
|
|
|
|
|
if (post.no == thread.loadable.lastViewed) { |
|
|
|
|
|
|
|
lastSeenIndicatorPosition = i + 1; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Update all, recyclerview will figure out all the animations
|
|
|
|
// Update all, recyclerview will figure out all the animations
|
|
|
|
notifyDataSetChanged(); |
|
|
|
notifyDataSetChanged(); |
|
|
|
} |
|
|
|
} |
|
|
@ -160,6 +206,8 @@ public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
|
highlightedPostNo = -1; |
|
|
|
highlightedPostNo = -1; |
|
|
|
highlightedPostTripcode = null; |
|
|
|
highlightedPostTripcode = null; |
|
|
|
lastPostCount = 0; |
|
|
|
lastPostCount = 0; |
|
|
|
|
|
|
|
lastSeenIndicatorPosition = -1; |
|
|
|
|
|
|
|
bound = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void showError(String error) { |
|
|
|
public void showError(String error) { |
|
|
@ -211,8 +259,16 @@ public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
|
this.postViewMode = postViewMode; |
|
|
|
this.postViewMode = postViewMode; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int getPostPosition(int position) { |
|
|
|
|
|
|
|
int postPosition = position; |
|
|
|
|
|
|
|
if (lastSeenIndicatorPosition >= 0 && position > lastSeenIndicatorPosition) { |
|
|
|
|
|
|
|
postPosition--; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return postPosition; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void onScrolledToBottom() { |
|
|
|
private void onScrolledToBottom() { |
|
|
|
if (lastPostCount < sourceList.size()) { |
|
|
|
if (bound && lastPostCount < sourceList.size()) { |
|
|
|
lastPostCount = sourceList.size(); |
|
|
|
lastPostCount = sourceList.size(); |
|
|
|
postAdapterCallback.onListScrolledToBottom(); |
|
|
|
postAdapterCallback.onListScrolledToBottom(); |
|
|
|
} |
|
|
|
} |
|
|
@ -240,6 +296,12 @@ public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static class LastSeenViewHolder extends RecyclerView.ViewHolder { |
|
|
|
|
|
|
|
public LastSeenViewHolder(View itemView) { |
|
|
|
|
|
|
|
super(itemView); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public interface PostAdapterCallback { |
|
|
|
public interface PostAdapterCallback { |
|
|
|
Loadable getLoadable(); |
|
|
|
Loadable getLoadable(); |
|
|
|
|
|
|
|
|
|
|
|