thread status: do not show info if board does not have support.

does now show the replies/images/ips if the op doesn't have info
about it. and if it does, only make the text italic if we know what
the limits are.
refactor-toolbar
Floens 8 years ago
parent 7e2f5feba0
commit f7a79e0c24
  1. 8
      Clover/app/src/main/java/org/floens/chan/core/model/Post.java
  2. 51
      Clover/app/src/main/java/org/floens/chan/ui/cell/ThreadStatusCell.java

@ -104,7 +104,7 @@ public class Post {
private boolean archived = false; private boolean archived = false;
private int replies = -1; private int replies = -1;
private int images = -1; private int images = -1;
private int uniqueIps = 1; private int uniqueIps = -1;
private String title = ""; private String title = "";
private Post(Builder builder) { private Post(Builder builder) {
@ -226,9 +226,9 @@ public class Post {
public int opId = -1; public int opId = -1;
public boolean op; public boolean op;
public int replies; public int replies = -1;
public int images; public int images = -1;
public int uniqueIps; public int uniqueIps = -1;
public boolean sticky; public boolean sticky;
public boolean closed; public boolean closed;
public boolean archived; public boolean archived;

@ -17,10 +17,10 @@
*/ */
package org.floens.chan.ui.cell; package org.floens.chan.ui.cell;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Handler; import android.os.Handler;
import android.os.Message;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
@ -30,9 +30,9 @@ import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import org.floens.chan.R; import org.floens.chan.R;
import org.floens.chan.core.model.orm.Board;
import org.floens.chan.core.model.ChanThread; import org.floens.chan.core.model.ChanThread;
import org.floens.chan.core.model.Post; import org.floens.chan.core.model.Post;
import org.floens.chan.core.model.orm.Board;
import static org.floens.chan.utils.AndroidUtils.ROBOTO_MEDIUM; import static org.floens.chan.utils.AndroidUtils.ROBOTO_MEDIUM;
@ -46,9 +46,7 @@ public class ThreadStatusCell extends LinearLayout implements View.OnClickListen
private TextView text; private TextView text;
private String error; private String error;
private Handler handler = new Handler(new Handler.Callback() { private Handler handler = new Handler(msg -> {
@Override
public boolean handleMessage(Message msg) {
if (msg.what == MESSAGE_INVALIDATE) { if (msg.what == MESSAGE_INVALIDATE) {
if (running && update()) { if (running && update()) {
schedule(); schedule();
@ -58,7 +56,6 @@ public class ThreadStatusCell extends LinearLayout implements View.OnClickListen
} else { } else {
return false; return false;
} }
}
}); });
public ThreadStatusCell(Context context, AttributeSet attrs) { public ThreadStatusCell(Context context, AttributeSet attrs) {
@ -87,14 +84,18 @@ public class ThreadStatusCell extends LinearLayout implements View.OnClickListen
} }
} }
@SuppressLint("SetTextI18n")
public boolean update() { public boolean update() {
if (error != null) { if (error != null) {
text.setText(error + "\n" + getContext().getString(R.string.thread_refresh_bar_inactive)); text.setText(error + "\n" + getContext()
.getString(R.string.thread_refresh_bar_inactive));
return false; return false;
} else { } else {
ChanThread chanThread = callback.getChanThread(); ChanThread chanThread = callback.getChanThread();
if (chanThread == null) { if (chanThread == null) {
return false; // Recyclerview not clearing immediately or view didn't receive onDetachedFromWindow // Recyclerview not clearing immediately or view didn't receive
// onDetachedFromWindow.
return false;
} }
boolean update = false; boolean update = false;
@ -102,39 +103,55 @@ public class ThreadStatusCell extends LinearLayout implements View.OnClickListen
String statusText = ""; String statusText = "";
if (chanThread.archived) { if (chanThread.archived) {
statusText += getContext().getString(R.string.thread_archived) + "\n"; statusText += getContext().getString(R.string.thread_archived);
} else if (chanThread.closed) { } else if (chanThread.closed) {
statusText += getContext().getString(R.string.thread_closed) + "\n"; statusText += getContext().getString(R.string.thread_closed);
} }
if (!chanThread.archived && !chanThread.closed) { if (!chanThread.archived && !chanThread.closed) {
long time = callback.getTimeUntilLoadMore() / 1000L; long time = callback.getTimeUntilLoadMore() / 1000L;
if (!callback.isWatching()) { if (!callback.isWatching()) {
statusText += getContext().getString(R.string.thread_refresh_bar_inactive) + "\n"; statusText += getContext().getString(R.string.thread_refresh_bar_inactive);
} else if (time <= 0) { } else if (time <= 0) {
statusText += getContext().getString(R.string.thread_refresh_now) + "\n"; statusText += getContext().getString(R.string.thread_refresh_now);
} else { } else {
statusText += getContext().getString(R.string.thread_refresh_countdown, time) + "\n"; statusText += getContext().getString(R.string.thread_refresh_countdown, time);
} }
update = true; update = true;
} }
Post op = chanThread.op; CharSequence finalText = statusText;
Post op = chanThread.op;
Board board = op.board; Board board = op.board;
if (board != null) { if (board != null) {
boolean hasReplies = op.getReplies() >= 0;
boolean hasImages = op.getImages() >= 0;
boolean hasIps = op.getUniqueIps() >= 0;
if (hasReplies && hasImages && hasIps) {
boolean hasBumpLimit = board.bumpLimit > 0;
boolean hasImageLimit = board.imageLimit > 0;
SpannableString replies = new SpannableString(op.getReplies() + "R"); SpannableString replies = new SpannableString(op.getReplies() + "R");
if (op.getReplies() >= board.bumpLimit) { if (hasBumpLimit && op.getReplies() >= board.bumpLimit) {
replies.setSpan(new StyleSpan(Typeface.ITALIC), 0, replies.length(), 0); replies.setSpan(new StyleSpan(Typeface.ITALIC), 0, replies.length(), 0);
} }
SpannableString images = new SpannableString(op.getImages() + "I"); SpannableString images = new SpannableString(op.getImages() + "I");
if (op.getImages() >= board.imageLimit) { if (hasImageLimit && op.getImages() >= board.imageLimit) {
images.setSpan(new StyleSpan(Typeface.ITALIC), 0, images.length(), 0); images.setSpan(new StyleSpan(Typeface.ITALIC), 0, images.length(), 0);
} }
text.setText(TextUtils.concat(statusText, replies, " / ", images, " / ", String.valueOf(op.getUniqueIps()) + "P")); String ips = op.getUniqueIps() + "P";
finalText = TextUtils.concat(statusText, "\n",
replies, " / ", images, " / ", ips);
}
} }
text.setText(finalText);
return update; return update;
} }
} }

Loading…
Cancel
Save