Added a red bar below the last seen post for pins.

captchafix
Florens Douwes 11 years ago
parent b8f32f4406
commit c44a631445
  1. 38
      Chan/src/org/floens/chan/core/manager/ThreadManager.java
  2. 8
      Chan/src/org/floens/chan/core/model/Pin.java
  3. 9
      Chan/src/org/floens/chan/core/watch/PinWatcher.java
  4. 3
      Chan/src/org/floens/chan/ui/adapter/PinnedAdapter.java
  5. 108
      Chan/src/org/floens/chan/ui/view/PostView.java

@ -50,8 +50,10 @@ public class ThreadManager implements Loader.LoaderListener {
private final ThreadManager.ThreadManagerListener threadManagerListener; private final ThreadManager.ThreadManagerListener threadManagerListener;
private final List<List<Post>> popupQueue = new ArrayList<List<Post>>(); private final List<List<Post>> popupQueue = new ArrayList<List<Post>>();
private PostRepliesFragment currentPopupFragment; private PostRepliesFragment currentPopupFragment;
private Post highlightedPost; private int highlightedPost = -1;
private int lastSeenPost = -1;
private int lastPost = -1;
private Loader loader; private Loader loader;
public ThreadManager(Activity activity, final ThreadManagerListener listener) { public ThreadManager(Activity activity, final ThreadManagerListener listener) {
@ -98,7 +100,9 @@ public class ThreadManager implements Loader.LoaderListener {
Logger.e(TAG, "Loader already unbinded"); Logger.e(TAG, "Loader already unbinded");
} }
highlightedPost = null; highlightedPost = -1;
lastSeenPost = -1;
lastPost = -1;
} }
public void bottomPostViewed() { public void bottomPostViewed() {
@ -107,6 +111,8 @@ public class ThreadManager implements Loader.LoaderListener {
if (pin != null) { if (pin != null) {
ChanApplication.getPinnedManager().onPinViewed(pin); ChanApplication.getPinnedManager().onPinViewed(pin);
} }
updateLastSeen();
} }
} }
@ -144,6 +150,11 @@ public class ThreadManager implements Loader.LoaderListener {
if (!shouldWatch()) { if (!shouldWatch()) {
loader.setAutoLoadMore(false); loader.setAutoLoadMore(false);
} }
if (result.size() > 0) {
lastPost = result.get(result.size() - 1).no;
}
updateLastSeen();
threadManagerListener.onThreadLoaded(result, append); threadManagerListener.onThreadLoaded(result, append);
} }
@ -245,11 +256,15 @@ public class ThreadManager implements Loader.LoaderListener {
} }
public void highlightPost(Post post) { public void highlightPost(Post post) {
highlightedPost = post; highlightedPost = post.no;
} }
public boolean isPostHightlighted(Post post) { 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) { 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 interface ThreadManagerListener {
public void onThreadLoaded(List<Post> result, boolean append); public void onThreadLoaded(List<Post> result, boolean append);

@ -59,6 +59,14 @@ public class Pin {
return Math.max(0, quoteNewCount - quoteLastCount); return Math.max(0, quoteNewCount - quoteLastCount);
} }
} }
public Post getLastSeenPost() {
if (pinWatcher == null) {
return null;
} else {
return pinWatcher.getLastSeenPost();
}
}
public void updateWatch() { public void updateWatch() {
if (pinWatcher == null) { if (pinWatcher == null) {

@ -70,6 +70,15 @@ public class PinWatcher implements Loader.LoaderListener {
return false; 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() { public boolean isError() {
return isError; return isError;

@ -7,7 +7,6 @@ import org.floens.chan.ChanApplication;
import org.floens.chan.R; import org.floens.chan.R;
import org.floens.chan.core.ChanPreferences; import org.floens.chan.core.ChanPreferences;
import org.floens.chan.core.model.Pin; import org.floens.chan.core.model.Pin;
import org.floens.chan.core.watch.PinWatcher;
import android.content.Context; import android.content.Context;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -51,8 +50,6 @@ public class PinnedAdapter extends ArrayAdapter<Pin> {
TextView itemCount = (TextView) view.findViewById(R.id.drawer_item_count); TextView itemCount = (TextView) view.findViewById(R.id.drawer_item_count);
PinWatcher watcher = item.getPinWatcher();
if (item.isError()) { if (item.isError()) {
itemCount.setText("Err"); itemCount.setText("Err");
} else { } else {

@ -33,10 +33,14 @@ import android.widget.TextView;
import com.android.volley.toolbox.NetworkImageView; import com.android.volley.toolbox.NetworkImageView;
public class PostView extends LinearLayout implements View.OnClickListener, View.OnLongClickListener { 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 matchParams = new LinearLayout.LayoutParams(
private final static LinearLayout.LayoutParams wrapParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
private final static LinearLayout.LayoutParams matchWrapParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); private final static LinearLayout.LayoutParams wrapParams = new LinearLayout.LayoutParams(
private final static LinearLayout.LayoutParams wrapMatchParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); 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; private final Activity context;
@ -54,11 +58,12 @@ public class PostView extends LinearLayout implements View.OnClickListener, View
private ImageView stickyView; private ImageView stickyView;
private ImageView closedView; private ImageView closedView;
private NetworkImageView countryView; private NetworkImageView countryView;
private View lastSeen;
/** /**
* Represents a post. * Represents a post. Use setPost(Post ThreadManager) to fill it with data.
* Use setPost(Post ThreadManager) to fill it with data.
* setPost can be called multiple times (useful for ListView). * setPost can be called multiple times (useful for ListView).
*
* @param activity * @param activity
*/ */
public PostView(Context activity) { public PostView(Context activity) {
@ -211,6 +216,12 @@ public class PostView extends LinearLayout implements View.OnClickListener, View
} else { } else {
full.setBackgroundColor(0x00000000); full.setBackgroundColor(0x00000000);
} }
if (manager.isPostLastSeen(post)) {
lastSeen.setVisibility(View.VISIBLE);
} else {
lastSeen.setVisibility(View.GONE);
}
if (manager.getLoadable().isBoardMode()) { if (manager.getLoadable().isBoardMode()) {
Utils.setPressedDrawable(right); Utils.setPressedDrawable(right);
@ -218,7 +229,8 @@ public class PostView extends LinearLayout implements View.OnClickListener, View
} }
private void buildView(final Context context) { private void buildView(final Context context) {
if (isBuild) return; if (isBuild)
return;
isBuild = true; isBuild = true;
Resources resources = context.getResources(); Resources resources = context.getResources();
@ -257,50 +269,54 @@ public class PostView extends LinearLayout implements View.OnClickListener, View
right = new LinearLayout(context); right = new LinearLayout(context);
right.setOrientation(VERTICAL); right.setOrientation(VERTICAL);
LinearLayout header = new LinearLayout(context); LinearLayout header = new LinearLayout(context);
header.setOrientation(HORIZONTAL); header.setOrientation(HORIZONTAL);
titleView = new TextView(context); titleView = new TextView(context);
titleView.setTextSize(14); titleView.setTextSize(14);
titleView.setPadding(postPadding, postPadding, postPadding, 0); titleView.setPadding(postPadding, postPadding, postPadding, 0);
header.addView(titleView, wrapParams); header.addView(titleView, wrapParams);
right.addView(header, matchWrapParams); right.addView(header, matchWrapParams);
iconView = new LinearLayout(context); iconView = new LinearLayout(context);
iconView.setOrientation(HORIZONTAL); iconView.setOrientation(HORIZONTAL);
iconView.setPadding(postPadding, iconPadding, postPadding, 0); iconView.setPadding(postPadding, iconPadding, postPadding, 0);
stickyView = new ImageView(context); stickyView = new ImageView(context);
stickyView.setImageBitmap(IconCache.stickyIcon); stickyView.setImageBitmap(IconCache.stickyIcon);
iconView.addView(stickyView, new LinearLayout.LayoutParams(iconWidth, iconHeight)); iconView.addView(stickyView, new LinearLayout.LayoutParams(iconWidth, iconHeight));
closedView = new ImageView(context); closedView = new ImageView(context);
closedView.setImageBitmap(IconCache.closedIcon); closedView.setImageBitmap(IconCache.closedIcon);
iconView.addView(closedView, new LinearLayout.LayoutParams(iconWidth, iconHeight)); iconView.addView(closedView, new LinearLayout.LayoutParams(iconWidth, iconHeight));
countryView = new NetworkImageView(context); countryView = new NetworkImageView(context);
countryView.setScaleType(ImageView.ScaleType.FIT_CENTER); countryView.setScaleType(ImageView.ScaleType.FIT_CENTER);
iconView.addView(countryView, new LinearLayout.LayoutParams(iconWidth, iconHeight)); iconView.addView(countryView, new LinearLayout.LayoutParams(iconWidth, iconHeight));
right.addView(iconView, matchWrapParams); right.addView(iconView, matchWrapParams);
commentView = new TextView(context); commentView = new TextView(context);
commentView.setTextSize(15); commentView.setTextSize(15);
commentView.setPadding(postPadding, commentPadding, postPadding, commentPadding); commentView.setPadding(postPadding, commentPadding, postPadding, commentPadding);
right.addView(commentView, matchWrapParams); 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 // Set the drawable before the padding, because setting the background resets the padding
// This behavior differs with 4.4 / 4.1 // This behavior differs with 4.4 / 4.1
Utils.setPressedDrawable(repliesCountView); Utils.setPressedDrawable(repliesCountView);
repliesCountView.setTextColor(Color.argb(255, 100, 100, 100)); repliesCountView.setTextColor(Color.argb(255, 100, 100, 100));
repliesCountView.setPadding(postPadding, postPadding, postPadding, postPadding); repliesCountView.setPadding(postPadding, postPadding, postPadding, postPadding);
repliesCountView.setTextSize(14); 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); 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) { public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
int action = event.getAction(); int action = event.getAction();
if (action == MotionEvent.ACTION_UP || if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX(); int x = (int) event.getX();
int y = (int) event.getY(); int y = (int) event.getY();
@ -357,9 +372,7 @@ public class PostView extends LinearLayout implements View.OnClickListener, View
if (action == MotionEvent.ACTION_UP) { if (action == MotionEvent.ACTION_UP) {
link[0].onClick(widget); link[0].onClick(widget);
} else if (action == MotionEvent.ACTION_DOWN) { } else if (action == MotionEvent.ACTION_DOWN) {
Selection.setSelection(buffer, Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0]));
buffer.getSpanStart(link[0]),
buffer.getSpanEnd(link[0]));
} }
return true; return true;
@ -375,12 +388,7 @@ public class PostView extends LinearLayout implements View.OnClickListener, View
return true; return true;
} }
// return Touch.onTouchEvent(widget, buffer, event); // return Touch.onTouchEvent(widget, buffer, event);
} }
} }
} }

Loading…
Cancel
Save