From f7a79e0c2496a97cd6973ae10c1ba202dc5e149f Mon Sep 17 00:00:00 2001 From: Floens Date: Sat, 20 Jan 2018 13:39:44 +0100 Subject: [PATCH] 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. --- .../java/org/floens/chan/core/model/Post.java | 8 +- .../floens/chan/ui/cell/ThreadStatusCell.java | 77 +++++++++++-------- 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/Clover/app/src/main/java/org/floens/chan/core/model/Post.java b/Clover/app/src/main/java/org/floens/chan/core/model/Post.java index 6ef00fcd..3062a75f 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/model/Post.java +++ b/Clover/app/src/main/java/org/floens/chan/core/model/Post.java @@ -104,7 +104,7 @@ public class Post { private boolean archived = false; private int replies = -1; private int images = -1; - private int uniqueIps = 1; + private int uniqueIps = -1; private String title = ""; private Post(Builder builder) { @@ -226,9 +226,9 @@ public class Post { public int opId = -1; public boolean op; - public int replies; - public int images; - public int uniqueIps; + public int replies = -1; + public int images = -1; + public int uniqueIps = -1; public boolean sticky; public boolean closed; public boolean archived; diff --git a/Clover/app/src/main/java/org/floens/chan/ui/cell/ThreadStatusCell.java b/Clover/app/src/main/java/org/floens/chan/ui/cell/ThreadStatusCell.java index f6ec7234..d4fbf6f1 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/cell/ThreadStatusCell.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/cell/ThreadStatusCell.java @@ -17,10 +17,10 @@ */ package org.floens.chan.ui.cell; +import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Typeface; import android.os.Handler; -import android.os.Message; import android.text.SpannableString; import android.text.TextUtils; import android.text.style.StyleSpan; @@ -30,9 +30,9 @@ import android.widget.LinearLayout; import android.widget.TextView; 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.Post; +import org.floens.chan.core.model.orm.Board; import static org.floens.chan.utils.AndroidUtils.ROBOTO_MEDIUM; @@ -46,18 +46,15 @@ public class ThreadStatusCell extends LinearLayout implements View.OnClickListen private TextView text; private String error; - private Handler handler = new Handler(new Handler.Callback() { - @Override - public boolean handleMessage(Message msg) { - if (msg.what == MESSAGE_INVALIDATE) { - if (running && update()) { - schedule(); - } - - return true; - } else { - return false; + private Handler handler = new Handler(msg -> { + if (msg.what == MESSAGE_INVALIDATE) { + if (running && update()) { + schedule(); } + + return true; + } else { + return false; } }); @@ -87,14 +84,18 @@ public class ThreadStatusCell extends LinearLayout implements View.OnClickListen } } + @SuppressLint("SetTextI18n") public boolean update() { 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; } else { ChanThread chanThread = callback.getChanThread(); 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; @@ -102,39 +103,55 @@ public class ThreadStatusCell extends LinearLayout implements View.OnClickListen String statusText = ""; if (chanThread.archived) { - statusText += getContext().getString(R.string.thread_archived) + "\n"; + statusText += getContext().getString(R.string.thread_archived); } else if (chanThread.closed) { - statusText += getContext().getString(R.string.thread_closed) + "\n"; + statusText += getContext().getString(R.string.thread_closed); } if (!chanThread.archived && !chanThread.closed) { long time = callback.getTimeUntilLoadMore() / 1000L; 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) { - statusText += getContext().getString(R.string.thread_refresh_now) + "\n"; + statusText += getContext().getString(R.string.thread_refresh_now); } else { - statusText += getContext().getString(R.string.thread_refresh_countdown, time) + "\n"; + statusText += getContext().getString(R.string.thread_refresh_countdown, time); } update = true; } - Post op = chanThread.op; + CharSequence finalText = statusText; + Post op = chanThread.op; Board board = op.board; if (board != null) { - SpannableString replies = new SpannableString(op.getReplies() + "R"); - if (op.getReplies() >= board.bumpLimit) { - replies.setSpan(new StyleSpan(Typeface.ITALIC), 0, replies.length(), 0); - } - SpannableString images = new SpannableString(op.getImages() + "I"); - if (op.getImages() >= board.imageLimit) { - images.setSpan(new StyleSpan(Typeface.ITALIC), 0, images.length(), 0); - } + 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; - text.setText(TextUtils.concat(statusText, replies, " / ", images, " / ", String.valueOf(op.getUniqueIps()) + "P")); + SpannableString replies = new SpannableString(op.getReplies() + "R"); + if (hasBumpLimit && op.getReplies() >= board.bumpLimit) { + replies.setSpan(new StyleSpan(Typeface.ITALIC), 0, replies.length(), 0); + } + + SpannableString images = new SpannableString(op.getImages() + "I"); + if (hasImageLimit && op.getImages() >= board.imageLimit) { + images.setSpan(new StyleSpan(Typeface.ITALIC), 0, images.length(), 0); + } + + String ips = op.getUniqueIps() + "P"; + + finalText = TextUtils.concat(statusText, "\n", + replies, " / ", images, " / ", ips); + } } + text.setText(finalText); + return update; } }