From c44a631445009b6f19e2c053da902b8eddbcae70 Mon Sep 17 00:00:00 2001 From: Florens Douwes Date: Wed, 9 Apr 2014 23:16:38 +0200 Subject: [PATCH] Added a red bar below the last seen post for pins. --- .../chan/core/manager/ThreadManager.java | 38 +++++- Chan/src/org/floens/chan/core/model/Pin.java | 8 ++ .../floens/chan/core/watch/PinWatcher.java | 9 ++ .../floens/chan/ui/adapter/PinnedAdapter.java | 3 - .../src/org/floens/chan/ui/view/PostView.java | 108 ++++++++++-------- 5 files changed, 108 insertions(+), 58 deletions(-) diff --git a/Chan/src/org/floens/chan/core/manager/ThreadManager.java b/Chan/src/org/floens/chan/core/manager/ThreadManager.java index be5cc7ac..c4d77d83 100644 --- a/Chan/src/org/floens/chan/core/manager/ThreadManager.java +++ b/Chan/src/org/floens/chan/core/manager/ThreadManager.java @@ -50,8 +50,10 @@ public class ThreadManager implements Loader.LoaderListener { private final ThreadManager.ThreadManagerListener threadManagerListener; private final List> popupQueue = new ArrayList>(); private PostRepliesFragment currentPopupFragment; - private Post highlightedPost; - + private int highlightedPost = -1; + private int lastSeenPost = -1; + private int lastPost = -1; + private Loader loader; public ThreadManager(Activity activity, final ThreadManagerListener listener) { @@ -98,7 +100,9 @@ public class ThreadManager implements Loader.LoaderListener { Logger.e(TAG, "Loader already unbinded"); } - highlightedPost = null; + highlightedPost = -1; + lastSeenPost = -1; + lastPost = -1; } public void bottomPostViewed() { @@ -107,6 +111,8 @@ public class ThreadManager implements Loader.LoaderListener { if (pin != null) { ChanApplication.getPinnedManager().onPinViewed(pin); } + + updateLastSeen(); } } @@ -144,6 +150,11 @@ public class ThreadManager implements Loader.LoaderListener { if (!shouldWatch()) { loader.setAutoLoadMore(false); } + + if (result.size() > 0) { + lastPost = result.get(result.size() - 1).no; + } + updateLastSeen(); threadManagerListener.onThreadLoaded(result, append); } @@ -245,11 +256,15 @@ public class ThreadManager implements Loader.LoaderListener { } public void highlightPost(Post post) { - highlightedPost = post; + highlightedPost = post.no; } public boolean isPostHightlighted(Post post) { - return highlightedPost != null && post.board.equals(highlightedPost.board) && post.no == highlightedPost.no; + return highlightedPost >= 0 && post.no == highlightedPost; + } + + public boolean isPostLastSeen(Post post) { + return post.no == lastSeenPost && post.no != lastPost; } private void copyToClipboard(String comment) { @@ -521,6 +536,19 @@ public class ThreadManager implements Loader.LoaderListener { } }); } + + private void updateLastSeen() { + Pin pin = ChanApplication.getPinnedManager().findPinByLoadable(loader.getLoadable()); + if (pin != null) { + Post last = pin.getLastSeenPost(); + if (last != null) { + lastSeenPost = last.no; + Logger.test("Setting as last seen post " + last.no); + } else { + lastSeenPost = -1; + } + } + } public interface ThreadManagerListener { public void onThreadLoaded(List result, boolean append); diff --git a/Chan/src/org/floens/chan/core/model/Pin.java b/Chan/src/org/floens/chan/core/model/Pin.java index 57a0c35e..ad088854 100644 --- a/Chan/src/org/floens/chan/core/model/Pin.java +++ b/Chan/src/org/floens/chan/core/model/Pin.java @@ -59,6 +59,14 @@ public class Pin { return Math.max(0, quoteNewCount - quoteLastCount); } } + + public Post getLastSeenPost() { + if (pinWatcher == null) { + return null; + } else { + return pinWatcher.getLastSeenPost(); + } + } public void updateWatch() { if (pinWatcher == null) { diff --git a/Chan/src/org/floens/chan/core/watch/PinWatcher.java b/Chan/src/org/floens/chan/core/watch/PinWatcher.java index 0bf3f915..ad8935a3 100644 --- a/Chan/src/org/floens/chan/core/watch/PinWatcher.java +++ b/Chan/src/org/floens/chan/core/watch/PinWatcher.java @@ -70,6 +70,15 @@ public class PinWatcher implements Loader.LoaderListener { return false; } } + + public Post getLastSeenPost() { + int i = posts.size() - pin.getNewPostsCount() - 1; + if (i >= 0 && i < posts.size()) { + return posts.get(i); + } else { + return null; + } + } public boolean isError() { return isError; diff --git a/Chan/src/org/floens/chan/ui/adapter/PinnedAdapter.java b/Chan/src/org/floens/chan/ui/adapter/PinnedAdapter.java index 53789235..43dfd438 100644 --- a/Chan/src/org/floens/chan/ui/adapter/PinnedAdapter.java +++ b/Chan/src/org/floens/chan/ui/adapter/PinnedAdapter.java @@ -7,7 +7,6 @@ import org.floens.chan.ChanApplication; import org.floens.chan.R; import org.floens.chan.core.ChanPreferences; import org.floens.chan.core.model.Pin; -import org.floens.chan.core.watch.PinWatcher; import android.content.Context; import android.view.LayoutInflater; @@ -51,8 +50,6 @@ public class PinnedAdapter extends ArrayAdapter { TextView itemCount = (TextView) view.findViewById(R.id.drawer_item_count); - PinWatcher watcher = item.getPinWatcher(); - if (item.isError()) { itemCount.setText("Err"); } else { diff --git a/Chan/src/org/floens/chan/ui/view/PostView.java b/Chan/src/org/floens/chan/ui/view/PostView.java index 484abfbf..170d3b76 100644 --- a/Chan/src/org/floens/chan/ui/view/PostView.java +++ b/Chan/src/org/floens/chan/ui/view/PostView.java @@ -33,10 +33,14 @@ import android.widget.TextView; import com.android.volley.toolbox.NetworkImageView; public class PostView extends LinearLayout implements View.OnClickListener, View.OnLongClickListener { - private final static LinearLayout.LayoutParams matchParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); - private final static LinearLayout.LayoutParams wrapParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - private final static LinearLayout.LayoutParams matchWrapParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); - private final static LinearLayout.LayoutParams wrapMatchParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); + private final static LinearLayout.LayoutParams matchParams = new LinearLayout.LayoutParams( + LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); + private final static LinearLayout.LayoutParams wrapParams = new LinearLayout.LayoutParams( + LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + private final static LinearLayout.LayoutParams matchWrapParams = new LinearLayout.LayoutParams( + LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); + private final static LinearLayout.LayoutParams wrapMatchParams = new LinearLayout.LayoutParams( + LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); private final Activity context; @@ -54,11 +58,12 @@ public class PostView extends LinearLayout implements View.OnClickListener, View private ImageView stickyView; private ImageView closedView; private NetworkImageView countryView; + private View lastSeen; /** - * Represents a post. - * Use setPost(Post ThreadManager) to fill it with data. + * Represents a post. Use setPost(Post ThreadManager) to fill it with data. * setPost can be called multiple times (useful for ListView). + * * @param activity */ public PostView(Context activity) { @@ -211,6 +216,12 @@ public class PostView extends LinearLayout implements View.OnClickListener, View } else { full.setBackgroundColor(0x00000000); } + + if (manager.isPostLastSeen(post)) { + lastSeen.setVisibility(View.VISIBLE); + } else { + lastSeen.setVisibility(View.GONE); + } if (manager.getLoadable().isBoardMode()) { Utils.setPressedDrawable(right); @@ -218,7 +229,8 @@ public class PostView extends LinearLayout implements View.OnClickListener, View } private void buildView(final Context context) { - if (isBuild) return; + if (isBuild) + return; isBuild = true; Resources resources = context.getResources(); @@ -257,50 +269,54 @@ public class PostView extends LinearLayout implements View.OnClickListener, View right = new LinearLayout(context); right.setOrientation(VERTICAL); - LinearLayout header = new LinearLayout(context); - header.setOrientation(HORIZONTAL); + LinearLayout header = new LinearLayout(context); + header.setOrientation(HORIZONTAL); - titleView = new TextView(context); - titleView.setTextSize(14); - titleView.setPadding(postPadding, postPadding, postPadding, 0); - header.addView(titleView, wrapParams); + titleView = new TextView(context); + titleView.setTextSize(14); + titleView.setPadding(postPadding, postPadding, postPadding, 0); + header.addView(titleView, wrapParams); - right.addView(header, matchWrapParams); + right.addView(header, matchWrapParams); - iconView = new LinearLayout(context); - iconView.setOrientation(HORIZONTAL); - iconView.setPadding(postPadding, iconPadding, postPadding, 0); + iconView = new LinearLayout(context); + iconView.setOrientation(HORIZONTAL); + iconView.setPadding(postPadding, iconPadding, postPadding, 0); - stickyView = new ImageView(context); - stickyView.setImageBitmap(IconCache.stickyIcon); - iconView.addView(stickyView, new LinearLayout.LayoutParams(iconWidth, iconHeight)); + stickyView = new ImageView(context); + stickyView.setImageBitmap(IconCache.stickyIcon); + iconView.addView(stickyView, new LinearLayout.LayoutParams(iconWidth, iconHeight)); - closedView = new ImageView(context); - closedView.setImageBitmap(IconCache.closedIcon); - iconView.addView(closedView, new LinearLayout.LayoutParams(iconWidth, iconHeight)); + closedView = new ImageView(context); + closedView.setImageBitmap(IconCache.closedIcon); + iconView.addView(closedView, new LinearLayout.LayoutParams(iconWidth, iconHeight)); - countryView = new NetworkImageView(context); - countryView.setScaleType(ImageView.ScaleType.FIT_CENTER); - iconView.addView(countryView, new LinearLayout.LayoutParams(iconWidth, iconHeight)); + countryView = new NetworkImageView(context); + countryView.setScaleType(ImageView.ScaleType.FIT_CENTER); + iconView.addView(countryView, new LinearLayout.LayoutParams(iconWidth, iconHeight)); - right.addView(iconView, matchWrapParams); + right.addView(iconView, matchWrapParams); - commentView = new TextView(context); - commentView.setTextSize(15); - commentView.setPadding(postPadding, commentPadding, postPadding, commentPadding); - right.addView(commentView, matchWrapParams); + commentView = new TextView(context); + commentView.setTextSize(15); + commentView.setPadding(postPadding, commentPadding, postPadding, commentPadding); + right.addView(commentView, matchWrapParams); - repliesCountView = new TextView(context); + repliesCountView = new TextView(context); - // Set the drawable before the padding, because setting the background resets the padding - // This behavior differs with 4.4 / 4.1 - Utils.setPressedDrawable(repliesCountView); + // Set the drawable before the padding, because setting the background resets the padding + // This behavior differs with 4.4 / 4.1 + Utils.setPressedDrawable(repliesCountView); - repliesCountView.setTextColor(Color.argb(255, 100, 100, 100)); - repliesCountView.setPadding(postPadding, postPadding, postPadding, postPadding); - repliesCountView.setTextSize(14); + repliesCountView.setTextColor(Color.argb(255, 100, 100, 100)); + repliesCountView.setPadding(postPadding, postPadding, postPadding, postPadding); + repliesCountView.setTextSize(14); - right.addView(repliesCountView, wrapParams); + right.addView(repliesCountView, wrapParams); + + lastSeen = new View(context); + lastSeen.setBackgroundColor(0xffff0000); + right.addView(lastSeen, new LayoutParams(LayoutParams.MATCH_PARENT, Utils.dp(context, 6f))); full.addView(right, matchWrapParams); @@ -336,8 +352,7 @@ public class PostView extends LinearLayout implements View.OnClickListener, View public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) { int action = event.getAction(); - if (action == MotionEvent.ACTION_UP || - action == MotionEvent.ACTION_DOWN) { + if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) { int x = (int) event.getX(); int y = (int) event.getY(); @@ -357,9 +372,7 @@ public class PostView extends LinearLayout implements View.OnClickListener, View if (action == MotionEvent.ACTION_UP) { link[0].onClick(widget); } else if (action == MotionEvent.ACTION_DOWN) { - Selection.setSelection(buffer, - buffer.getSpanStart(link[0]), - buffer.getSpanEnd(link[0])); + Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0])); } return true; @@ -375,12 +388,7 @@ public class PostView extends LinearLayout implements View.OnClickListener, View return true; } -// return Touch.onTouchEvent(widget, buffer, event); + // return Touch.onTouchEvent(widget, buffer, event); } } } - - - - -