From d77d3d6ea6cafe2764b90b299ab2f0a2fdbb68d1 Mon Sep 17 00:00:00 2001 From: Floens Date: Mon, 16 Nov 2015 00:45:51 +0100 Subject: [PATCH] Highlight the selected thread in the split layout --- .../chan/core/presenter/ThreadPresenter.java | 6 +++++ .../floens/chan/ui/adapter/PostAdapter.java | 11 ++++++++-- .../org/floens/chan/ui/cell/CardPostCell.java | 2 +- .../org/floens/chan/ui/cell/PostCell.java | 8 +++++-- .../chan/ui/cell/PostCellInterface.java | 2 +- .../org/floens/chan/ui/cell/PostStubCell.java | 2 +- .../ui/controller/PostRepliesController.java | 2 +- .../controller/ThemeSettingsController.java | 2 +- .../chan/ui/controller/ThreadController.java | 4 ++++ .../ui/controller/ViewThreadController.java | 22 +++++++++++++++++++ .../floens/chan/ui/layout/ThreadLayout.java | 5 +++++ .../chan/ui/layout/ThreadListLayout.java | 4 ++++ .../org/floens/chan/ui/text/FastTextView.java | 1 - .../java/org/floens/chan/ui/theme/Theme.java | 9 +++++--- Clover/app/src/main/res/values/attrs.xml | 1 + Clover/app/src/main/res/values/styles.xml | 1 + 16 files changed, 69 insertions(+), 13 deletions(-) diff --git a/Clover/app/src/main/java/org/floens/chan/core/presenter/ThreadPresenter.java b/Clover/app/src/main/java/org/floens/chan/core/presenter/ThreadPresenter.java index 7abeabc6..6e9a4f4a 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/presenter/ThreadPresenter.java +++ b/Clover/app/src/main/java/org/floens/chan/core/presenter/ThreadPresenter.java @@ -332,6 +332,10 @@ public class ThreadPresenter implements ChanLoader.ChanLoaderCallback, PostAdapt threadPresenterCallback.highlightPost(post); } + public void selectPost(int post) { + threadPresenterCallback.selectPost(post); + } + /* * PostView callbacks */ @@ -674,6 +678,8 @@ public class ThreadPresenter implements ChanLoader.ChanLoaderCallback, PostAdapt void highlightPostTripcode(String tripcode); + void selectPost(int post); + void showSearch(boolean show); void setSearchStatus(String query, boolean setEmptyText, boolean hideKeyboard); diff --git a/Clover/app/src/main/java/org/floens/chan/ui/adapter/PostAdapter.java b/Clover/app/src/main/java/org/floens/chan/ui/adapter/PostAdapter.java index 8f53649c..167e1c9c 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/adapter/PostAdapter.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/adapter/PostAdapter.java @@ -50,6 +50,7 @@ public class PostAdapter extends RecyclerView.Adapter { private String highlightedPostId; private int highlightedPostNo = -1; private String highlightedPostTripcode; + private int selectedPost; private int lastSeenIndicatorPosition = -1; private boolean bound; @@ -102,8 +103,9 @@ public class PostAdapter extends RecyclerView.Adapter { case TYPE_POST_STUB: PostViewHolder postViewHolder = (PostViewHolder) holder; Post post = displayList.get(getPostPosition(position)); - boolean highlight = post == highlightedPost || post.id.equals(highlightedPostId) || post.no == highlightedPostNo || post.tripcode.equals(highlightedPostTripcode); - postViewHolder.postView.setPost(null, post, postCellCallback, highlight, -1, true, postViewMode); + boolean highlight = post == highlightedPost || post.id.equals(highlightedPostId) || post.no == highlightedPostNo || + post.tripcode.equals(highlightedPostTripcode); + postViewHolder.postView.setPost(null, post, postCellCallback, highlight, post.no == selectedPost, -1, true, postViewMode); break; case TYPE_STATUS: ((StatusViewHolder) holder).threadStatusCell.update(); @@ -259,6 +261,11 @@ public class PostAdapter extends RecyclerView.Adapter { notifyDataSetChanged(); } + public void selectPost(int no) { + selectedPost = no; + notifyDataSetChanged(); + } + public void setPostViewMode(PostCellInterface.PostViewMode postViewMode) { this.postViewMode = postViewMode; } diff --git a/Clover/app/src/main/java/org/floens/chan/ui/cell/CardPostCell.java b/Clover/app/src/main/java/org/floens/chan/ui/cell/CardPostCell.java index 41f7cdcd..4a53dcdb 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/cell/CardPostCell.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/cell/CardPostCell.java @@ -142,7 +142,7 @@ public class CardPostCell extends CardView implements PostCellInterface, View.On } public void setPost(Theme theme, final Post post, PostCellInterface.PostCellCallback callback, - boolean highlighted, int markedNo, boolean showDivider, PostCellInterface.PostViewMode postViewMode) { + boolean highlighted, boolean selected, int markedNo, boolean showDivider, PostCellInterface.PostViewMode postViewMode) { if (this.post == post) { return; } diff --git a/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java b/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java index e369c195..5c9b5354 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java @@ -100,6 +100,7 @@ public class PostCell extends LinearLayout implements PostCellInterface, PostLin private Post post; private PostCellCallback callback; private boolean highlighted; + private boolean selected; private int markedNo; private boolean showDivider; @@ -234,8 +235,8 @@ public class PostCell extends LinearLayout implements PostCellInterface, PostLin } public void setPost(Theme theme, final Post post, PostCellInterface.PostCellCallback callback, - boolean highlighted, int markedNo, boolean showDivider, PostCellInterface.PostViewMode postViewMode) { - if (this.post == post && this.highlighted == highlighted && this.markedNo == markedNo) { + boolean highlighted, boolean selected, int markedNo, boolean showDivider, PostCellInterface.PostViewMode postViewMode) { + if (this.post == post && this.highlighted == highlighted && this.selected == selected && this.markedNo == markedNo && this.showDivider == showDivider) { return; } @@ -252,6 +253,7 @@ public class PostCell extends LinearLayout implements PostCellInterface, PostLin this.post = post; this.callback = callback; this.highlighted = highlighted; + this.selected = selected; this.markedNo = markedNo; this.showDivider = showDivider; @@ -289,6 +291,8 @@ public class PostCell extends LinearLayout implements PostCellInterface, PostLin setBackgroundColor(theme.highlightedColor); } else if (post.isSavedReply) { setBackgroundColor(theme.savedReplyColor); + } else if (selected) { + setBackgroundColor(theme.selectedColor); } else if (threadMode) { setBackgroundResource(0); } else { diff --git a/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCellInterface.java b/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCellInterface.java index 73069999..1cb6723f 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCellInterface.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCellInterface.java @@ -27,7 +27,7 @@ import org.floens.chan.ui.view.ThumbnailView; import java.util.List; public interface PostCellInterface { - void setPost(Theme theme, Post post, PostCellCallback callback, boolean highlighted, int markedNo, boolean showDivider, PostCellInterface.PostViewMode postViewMode); + void setPost(Theme theme, Post post, PostCellCallback callback, boolean highlighted, boolean selected, int markedNo, boolean showDivider, PostCellInterface.PostViewMode postViewMode); Post getPost(); diff --git a/Clover/app/src/main/java/org/floens/chan/ui/cell/PostStubCell.java b/Clover/app/src/main/java/org/floens/chan/ui/cell/PostStubCell.java index 6b79ef6a..c73b8bd8 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/cell/PostStubCell.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/cell/PostStubCell.java @@ -139,7 +139,7 @@ public class PostStubCell extends RelativeLayout implements PostCellInterface, V } public void setPost(Theme theme, final Post post, PostCellInterface.PostCellCallback callback, - boolean highlighted, int markedNo, boolean showDivider, PostCellInterface.PostViewMode postViewMode) { + boolean highlighted, boolean selected, int markedNo, boolean showDivider, PostCellInterface.PostViewMode postViewMode) { if (this.post == post) { return; } diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/PostRepliesController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/PostRepliesController.java index cf41c244..d861961e 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/PostRepliesController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/PostRepliesController.java @@ -191,7 +191,7 @@ public class PostRepliesController extends Controller { final Post p = getItem(position); boolean showDivider = position < getCount() - 1; - postCell.setPost(null, p, presenter, false, data.forPost.no, showDivider, PostCellInterface.PostViewMode.LIST); + postCell.setPost(null, p, presenter, false, false, data.forPost.no, showDivider, PostCellInterface.PostViewMode.LIST); return (View) postCell; } diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/ThemeSettingsController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/ThemeSettingsController.java index 7e8ea4fb..f7fba8a2 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/ThemeSettingsController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/ThemeSettingsController.java @@ -255,7 +255,7 @@ public class ThemeSettingsController extends Controller implements View.OnClickL themeContext.getResources().getDimensionPixelSize(R.dimen.toolbar_height))); PostCell postCell = (PostCell) LayoutInflater.from(themeContext).inflate(R.layout.cell_post, null); - postCell.setPost(theme, post, DUMMY_POST_CALLBACK, false, -1, true, PostCellInterface.PostViewMode.LIST); + postCell.setPost(theme, post, DUMMY_POST_CALLBACK, false, false, -1, true, PostCellInterface.PostViewMode.LIST); linearLayout.addView(postCell, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); return linearLayout; diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/ThreadController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/ThreadController.java index dada6ed0..196e1375 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/ThreadController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/ThreadController.java @@ -102,6 +102,10 @@ public abstract class ThreadController extends Controller implements ThreadLayou return threadLayout.getPresenter().getLoadable(); } + public void selectPost(int post) { + threadLayout.getPresenter().selectPost(post); + } + @Override public boolean onBack() { return threadLayout.onBack(); diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/ViewThreadController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/ViewThreadController.java index 3611dc57..2acc1948 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/ViewThreadController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/ViewThreadController.java @@ -24,6 +24,8 @@ import android.support.v7.app.AlertDialog; import org.floens.chan.Chan; import org.floens.chan.R; import org.floens.chan.chan.ChanUrls; +import org.floens.chan.controller.Controller; +import org.floens.chan.controller.NavigationController; import org.floens.chan.core.manager.WatchManager; import org.floens.chan.core.model.Loadable; import org.floens.chan.core.model.Pin; @@ -93,6 +95,7 @@ public class ViewThreadController extends ThreadController implements ThreadLayo public void onDestroy() { super.onDestroy(); updateDrawerHighlighting(null); + updateLeftPaneHighlighting(null); } @Override @@ -140,6 +143,7 @@ public class ViewThreadController extends ThreadController implements ThreadLayo navigationItem.updateTitle(); setPinIconState(presenter.isPinned()); updateDrawerHighlighting(loadable); + updateLeftPaneHighlighting(loadable); presenter.requestInitialData(); } } @@ -209,6 +213,24 @@ public class ViewThreadController extends ThreadController implements ThreadLayo } } + private void updateLeftPaneHighlighting(Loadable loadable) { + if (splitNavigationController != null) { + if (splitNavigationController.leftController instanceof NavigationController) { + NavigationController leftNavigationController = (NavigationController) splitNavigationController.leftController; + ThreadController threadController = null; + for (Controller controller : leftNavigationController.childControllers) { + if (controller instanceof ThreadController) { + threadController = (ThreadController) controller; + break; + } + } + if (threadController != null) { + threadController.selectPost(loadable != null ? loadable.no : -1); + } + } + } + } + private void setPinIconState() { WatchManager wm = Chan.getWatchManager(); setPinIconState(wm.findPinByLoadable(loadable) != null); diff --git a/Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadLayout.java b/Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadLayout.java index 85fd38b3..3f49e3f8 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadLayout.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadLayout.java @@ -346,6 +346,11 @@ public class ThreadLayout extends CoordinatorLayout implements ThreadPresenter.T threadListLayout.highlightPostTripcode(tripcode); } + @Override + public void selectPost(int post) { + threadListLayout.selectPost(post); + } + @Override public void showSearch(boolean show) { threadListLayout.openSearch(show); diff --git a/Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadListLayout.java b/Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadListLayout.java index f6b598a7..a021ece0 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadListLayout.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadListLayout.java @@ -400,6 +400,10 @@ public class ThreadListLayout extends FrameLayout implements ReplyLayout.ReplyLa postAdapter.highlightPostTripcode(tripcode); } + public void selectPost(int post) { + postAdapter.selectPost(post); + } + @Override public void highlightPostNo(int no) { postAdapter.highlightPostNo(no); diff --git a/Clover/app/src/main/java/org/floens/chan/ui/text/FastTextView.java b/Clover/app/src/main/java/org/floens/chan/ui/text/FastTextView.java index 8b127f00..7296563d 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/text/FastTextView.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/text/FastTextView.java @@ -22,7 +22,6 @@ import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Paint; import android.text.Layout; -import android.text.Spannable; import android.text.Spanned; import android.text.StaticLayout; import android.text.TextPaint; diff --git a/Clover/app/src/main/java/org/floens/chan/ui/theme/Theme.java b/Clover/app/src/main/java/org/floens/chan/ui/theme/Theme.java index c17d1d2c..ecdcf78b 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/theme/Theme.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/theme/Theme.java @@ -54,6 +54,7 @@ public class Theme { public int detailsColor; public int highlightedColor; public int savedReplyColor; + public int selectedColor; public ThemeDrawable settingsDrawable; public ThemeDrawable imageDrawable; @@ -106,6 +107,7 @@ public class Theme { R.attr.post_details_color, R.attr.post_highlighted_color, R.attr.post_saved_reply_color, + R.attr.post_selected_color, R.attr.text_color_primary, R.attr.text_color_secondary, R.attr.text_color_hint @@ -124,9 +126,10 @@ public class Theme { detailsColor = ta.getColor(10, 0); highlightedColor = ta.getColor(11, 0); savedReplyColor = ta.getColor(12, 0); - textPrimary = ta.getColor(13, 0); - textSecondary = ta.getColor(14, 0); - textHint = ta.getColor(15, 0); + selectedColor = ta.getColor(13, 0); + textPrimary = ta.getColor(14, 0); + textSecondary = ta.getColor(15, 0); + textHint = ta.getColor(16, 0); ta.recycle(); } diff --git a/Clover/app/src/main/res/values/attrs.xml b/Clover/app/src/main/res/values/attrs.xml index 6d0efde4..8ccf790e 100644 --- a/Clover/app/src/main/res/values/attrs.xml +++ b/Clover/app/src/main/res/values/attrs.xml @@ -38,6 +38,7 @@ along with this program. If not, see . + diff --git a/Clover/app/src/main/res/values/styles.xml b/Clover/app/src/main/res/values/styles.xml index f3d18f2b..cd3e4948 100644 --- a/Clover/app/src/main/res/values/styles.xml +++ b/Clover/app/src/main/res/values/styles.xml @@ -56,6 +56,7 @@ along with this program. If not, see . @drawable/ic_overflow #FFBCBCBC #FFD6BAD0 + #20000000 #1e000000 #ffe1e1e1