post: add compact mode to the card layout

reduces the padding and text size of the card when there is little space.
refactor-toolbar
Floens 8 years ago
parent 6cb1fc4e6c
commit e78d3e7a7f
  1. 24
      Clover/app/src/main/java/org/floens/chan/ui/adapter/PostAdapter.java
  2. 74
      Clover/app/src/main/java/org/floens/chan/ui/cell/CardPostCell.java
  3. 3
      Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java
  4. 3
      Clover/app/src/main/java/org/floens/chan/ui/cell/PostCellInterface.java
  5. 3
      Clover/app/src/main/java/org/floens/chan/ui/cell/PostStubCell.java
  6. 11
      Clover/app/src/main/java/org/floens/chan/ui/controller/PostRepliesController.java
  7. 13
      Clover/app/src/main/java/org/floens/chan/ui/controller/ThemeSettingsController.java
  8. 5
      Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadListLayout.java
  9. 2
      Clover/app/src/main/res/values-sw600dp/dimens.xml

@ -24,8 +24,8 @@ import android.view.ViewGroup;
import org.floens.chan.R; import org.floens.chan.R;
import org.floens.chan.core.model.ChanThread; import org.floens.chan.core.model.ChanThread;
import org.floens.chan.core.model.orm.Loadable;
import org.floens.chan.core.model.Post; import org.floens.chan.core.model.Post;
import org.floens.chan.core.model.orm.Loadable;
import org.floens.chan.core.settings.ChanSettings; import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.ui.cell.PostCellInterface; import org.floens.chan.ui.cell.PostCellInterface;
import org.floens.chan.ui.cell.ThreadStatusCell; import org.floens.chan.ui.cell.ThreadStatusCell;
@ -56,6 +56,7 @@ public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private boolean bound; private boolean bound;
private ChanSettings.PostViewMode postViewMode; private ChanSettings.PostViewMode postViewMode;
private boolean compact = false;
public PostAdapter(RecyclerView recyclerView, PostAdapterCallback postAdapterCallback, PostCellInterface.PostCellCallback postCellCallback, ThreadStatusCell.Callback statusCellCallback) { public PostAdapter(RecyclerView recyclerView, PostAdapterCallback postAdapterCallback, PostCellInterface.PostCellCallback postCellCallback, ThreadStatusCell.Callback statusCellCallback) {
this.recyclerView = recyclerView; this.recyclerView = recyclerView;
@ -106,7 +107,17 @@ public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
Post post = displayList.get(getPostPosition(position)); Post post = displayList.get(getPostPosition(position));
boolean highlight = post == highlightedPost || post.id.equals(highlightedPostId) || post.no == highlightedPostNo || boolean highlight = post == highlightedPost || post.id.equals(highlightedPostId) || post.no == highlightedPostNo ||
post.tripcode.equals(highlightedPostTripcode); post.tripcode.equals(highlightedPostTripcode);
postViewHolder.postView.setPost(null, post, postCellCallback, true, highlight, post.no == selectedPost, -1, true, postViewMode); postViewHolder.postView.setPost(null,
post,
postCellCallback,
true,
highlight,
post.no == selectedPost,
-1,
true,
postViewMode,
compact);
break; break;
case TYPE_STATUS: case TYPE_STATUS:
((StatusViewHolder) holder).threadStatusCell.update(); ((StatusViewHolder) holder).threadStatusCell.update();
@ -160,7 +171,7 @@ public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
synchronized (post.repliesFrom) { synchronized (post.repliesFrom) {
repliesFromSize = post.repliesFrom.size(); repliesFromSize = post.repliesFrom.size();
} }
return ((long) repliesFromSize << 32L) + (long) post.no; return ((long) repliesFromSize << 32L) + (long) post.no + (compact ? 1L : 0L);
} }
} }
@ -261,6 +272,13 @@ public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
this.postViewMode = postViewMode; this.postViewMode = postViewMode;
} }
public void setCompact(boolean compact) {
if (this.compact != compact) {
this.compact = compact;
notifyDataSetChanged();
}
}
public int getPostPosition(int position) { public int getPostPosition(int position) {
int postPosition = position; int postPosition = position;
if (lastSeenIndicatorPosition >= 0 && position > lastSeenIndicatorPosition) { if (lastSeenIndicatorPosition >= 0 && position > lastSeenIndicatorPosition) {

@ -43,6 +43,7 @@ import org.floens.chan.ui.view.ThumbnailView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.floens.chan.utils.AndroidUtils.dp;
import static org.floens.chan.utils.AndroidUtils.setRoundItemBackground; import static org.floens.chan.utils.AndroidUtils.setRoundItemBackground;
public class CardPostCell extends CardView implements PostCellInterface, View.OnClickListener { public class CardPostCell extends CardView implements PostCellInterface, View.OnClickListener {
@ -52,6 +53,7 @@ public class CardPostCell extends CardView implements PostCellInterface, View.On
private Theme theme; private Theme theme;
private Post post; private Post post;
private PostCellInterface.PostCellCallback callback; private PostCellInterface.PostCellCallback callback;
private boolean compact = false;
private FixedRatioLinearLayout content; private FixedRatioLinearLayout content;
private PostImageThumbnailView thumbnailView; private PostImageThumbnailView thumbnailView;
@ -78,7 +80,7 @@ public class CardPostCell extends CardView implements PostCellInterface, View.On
super.onFinishInflate(); super.onFinishInflate();
content = findViewById(R.id.card_content); content = findViewById(R.id.card_content);
content.setRatio(9f / 16f); content.setRatio(9f / 18f);
thumbnailView = findViewById(R.id.thumbnail); thumbnailView = findViewById(R.id.thumbnail);
thumbnailView.setRatio(16f / 13f); thumbnailView.setRatio(16f / 13f);
thumbnailView.setOnClickListener(this); thumbnailView.setOnClickListener(this);
@ -89,33 +91,27 @@ public class CardPostCell extends CardView implements PostCellInterface, View.On
setRoundItemBackground(options); setRoundItemBackground(options);
filterMatchColor = findViewById(R.id.filter_match_color); filterMatchColor = findViewById(R.id.filter_match_color);
int textSizeSp = Integer.parseInt(ChanSettings.fontSize.get());
title.setTextSize(textSizeSp);
comment.setTextSize(textSizeSp);
replies.setTextSize(textSizeSp);
setOnClickListener(this); setOnClickListener(this);
options.setOnClickListener(new OnClickListener() { setCompact(compact);
@Override
public void onClick(View v) { options.setOnClickListener(v -> {
List<FloatingMenuItem> items = new ArrayList<>(); List<FloatingMenuItem> items = new ArrayList<>();
callback.onPopulatePostOptions(post, items); callback.onPopulatePostOptions(post, items);
FloatingMenu menu = new FloatingMenu(getContext(), v, items); FloatingMenu menu = new FloatingMenu(getContext(), v, items);
menu.setCallback(new FloatingMenu.FloatingMenuCallback() { menu.setCallback(new FloatingMenu.FloatingMenuCallback() {
@Override @Override
public void onFloatingMenuItemClicked(FloatingMenu menu, FloatingMenuItem item) { public void onFloatingMenuItemClicked(FloatingMenu menu, FloatingMenuItem item) {
callback.onPostOptionClicked(post, item.getId()); callback.onPostOptionClicked(post, item.getId());
} }
@Override @Override
public void onFloatingMenuDismissed(FloatingMenu menu) { public void onFloatingMenuDismissed(FloatingMenu menu) {
} }
}); });
menu.show(); menu.show();
}
}); });
} }
@ -148,7 +144,8 @@ public class CardPostCell extends CardView implements PostCellInterface, View.On
public void setPost(Theme theme, final Post post, PostCellInterface.PostCellCallback callback, public void setPost(Theme theme, final Post post, PostCellInterface.PostCellCallback callback,
boolean selectable, boolean highlighted, boolean selected, int markedNo, boolean selectable, boolean highlighted, boolean selected, int markedNo,
boolean showDivider, ChanSettings.PostViewMode postViewMode) { boolean showDivider, ChanSettings.PostViewMode postViewMode,
boolean compact) {
if (this.post == post) { if (this.post == post) {
return; return;
} }
@ -167,6 +164,11 @@ public class CardPostCell extends CardView implements PostCellInterface, View.On
this.callback = callback; this.callback = callback;
bindPost(theme, post); bindPost(theme, post);
if (this.compact != compact) {
this.compact = compact;
setCompact(compact);
}
} }
public Post getPost() { public Post getPost() {
@ -225,4 +227,22 @@ public class CardPostCell extends CardView implements PostCellInterface, View.On
private void unbindPost(Post post) { private void unbindPost(Post post) {
bound = false; bound = false;
} }
private void setCompact(boolean compact) {
int textReduction = compact ? -2 : 0;
int textSizeSp = Integer.parseInt(ChanSettings.fontSize.get()) + textReduction;
title.setTextSize(textSizeSp);
comment.setTextSize(textSizeSp);
replies.setTextSize(textSizeSp);
int p = compact ? dp(3) : dp(8);
// Same as the layout.
title.setPadding(p, p, p, 0);
comment.setPadding(p, p, p, 0);
replies.setPadding(p, p / 2, p, p);
int optionsPadding = compact ? 0 : dp(5);
options.setPadding(0, optionsPadding, optionsPadding, 0);
}
} }

@ -252,7 +252,8 @@ public class PostCell extends LinearLayout implements PostCellInterface {
boolean selected, boolean selected,
int markedNo, int markedNo,
boolean showDivider, boolean showDivider,
ChanSettings.PostViewMode postViewMode) { ChanSettings.PostViewMode postViewMode,
boolean compact) {
if (this.post == post && if (this.post == post &&
this.selectable == selectable && this.selectable == selectable &&
this.highlighted == highlighted && this.highlighted == highlighted &&

@ -37,7 +37,8 @@ public interface PostCellInterface {
boolean selected, boolean selected,
int markedNo, int markedNo,
boolean showDivider, boolean showDivider,
ChanSettings.PostViewMode postViewMode); ChanSettings.PostViewMode postViewMode,
boolean compact);
Post getPost(); Post getPost();

@ -141,7 +141,8 @@ public class PostStubCell extends RelativeLayout implements PostCellInterface, V
public void setPost(Theme theme, final Post post, PostCellInterface.PostCellCallback callback, public void setPost(Theme theme, final Post post, PostCellInterface.PostCellCallback callback,
boolean selectable, boolean highlighted, boolean selected, int markedNo, boolean selectable, boolean highlighted, boolean selected, int markedNo,
boolean showDivider, ChanSettings.PostViewMode postViewMode) { boolean showDivider, ChanSettings.PostViewMode postViewMode,
boolean compact) {
if (this.post == post) { if (this.post == post) {
return; return;
} }

@ -195,7 +195,16 @@ public class PostRepliesController extends Controller {
final Post p = getItem(position); final Post p = getItem(position);
boolean showDivider = position < getCount() - 1; boolean showDivider = position < getCount() - 1;
postCell.setPost(null, p, presenter, false, false, false, data.forPost.no, showDivider, ChanSettings.PostViewMode.LIST); postCell.setPost(null,
p,
presenter,
false,
false,
false,
data.forPost.no,
showDivider,
ChanSettings.PostViewMode.LIST,
false);
return (View) postCell; return (View) postCell;
} }

@ -69,6 +69,7 @@ import static org.floens.chan.utils.AndroidUtils.getString;
public class ThemeSettingsController extends Controller implements View.OnClickListener { public class ThemeSettingsController extends Controller implements View.OnClickListener {
private Board dummyBoard; private Board dummyBoard;
{ {
dummyBoard = new Board(); dummyBoard = new Board();
dummyBoard.name = "name"; dummyBoard.name = "name";
@ -76,6 +77,7 @@ public class ThemeSettingsController extends Controller implements View.OnClickL
} }
private Loadable dummyLoadable; private Loadable dummyLoadable;
{ {
dummyLoadable = Loadable.emptyLoadable(); dummyLoadable = Loadable.emptyLoadable();
dummyLoadable.mode = Loadable.Mode.THREAD; dummyLoadable.mode = Loadable.Mode.THREAD;
@ -339,7 +341,16 @@ public class ThemeSettingsController extends Controller implements View.OnClickL
themeContext.getResources().getDimensionPixelSize(R.dimen.toolbar_height))); themeContext.getResources().getDimensionPixelSize(R.dimen.toolbar_height)));
PostCell postCell = (PostCell) LayoutInflater.from(themeContext).inflate(R.layout.cell_post, null); PostCell postCell = (PostCell) LayoutInflater.from(themeContext).inflate(R.layout.cell_post, null);
postCell.setPost(theme, post, dummyPostCallback, false, false, false, -1, true, ChanSettings.PostViewMode.LIST); postCell.setPost(theme,
post,
dummyPostCallback,
false,
false,
false,
-1,
true,
ChanSettings.PostViewMode.LIST,
false);
linearLayout.addView(postCell, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); linearLayout.addView(postCell, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
return linearLayout; return linearLayout;

@ -158,13 +158,18 @@ public class ThreadListLayout extends FrameLayout implements ReplyLayout.ReplyLa
int cardWidth = getResources().getDimensionPixelSize(R.dimen.grid_card_width); int cardWidth = getResources().getDimensionPixelSize(R.dimen.grid_card_width);
int gridCountSetting = ChanSettings.boardGridSpanCount.get(); int gridCountSetting = ChanSettings.boardGridSpanCount.get();
boolean compactMode;
if (gridCountSetting > 0) { if (gridCountSetting > 0) {
spanCount = gridCountSetting; spanCount = gridCountSetting;
compactMode = (getMeasuredWidth() / spanCount) < dp(120);
} else { } else {
spanCount = Math.max(1, Math.round(getMeasuredWidth() / cardWidth)); spanCount = Math.max(1, Math.round(getMeasuredWidth() / cardWidth));
compactMode = false;
} }
if (postViewMode == ChanSettings.PostViewMode.CARD) { if (postViewMode == ChanSettings.PostViewMode.CARD) {
postAdapter.setCompact(compactMode);
((GridLayoutManager) layoutManager).setSpanCount(spanCount); ((GridLayoutManager) layoutManager).setSpanCount(spanCount);
} }
} }

@ -18,7 +18,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<resources> <resources>
<bool name="is_tablet">true</bool> <bool name="is_tablet">true</bool>
<dimen name="grid_card_width">105dp</dimen>
<dimen name="cell_post_thumbnail_size">100dp</dimen> <dimen name="cell_post_thumbnail_size">100dp</dimen>
</resources> </resources>

Loading…
Cancel
Save