Skip to content

Commit

Permalink
For #283, not sure if done yet
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamantcheese committed Jul 27, 2020
1 parent a60fb88 commit 2556607
Show file tree
Hide file tree
Showing 25 changed files with 300 additions and 499 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1148,21 +1148,8 @@ public PinWatcher(Pin pin) {
pageRequestManager.addListener(this);
}

public boolean getIsSticky() {
return pin.isSticky;
}

public int getImageCount() {
if (chanLoader != null && chanLoader.getThread() != null) {
int total = 0;
List<Post> posts = chanLoader.getThread().getPosts();
if (posts == null) return 0;
for (Post p : posts) {
if (!p.isOP) total += p.images.size();
}
return total;
}
return 0;
public CharSequence getSummary() {
return chanLoader != null && chanLoader.getThread() != null ? chanLoader.getThread().summarize(true) : null;
}

public List<Post> getPosts() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@
*/
package com.github.adamantcheese.chan.core.model;

import android.graphics.Typeface;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.style.StyleSpan;

import com.github.adamantcheese.chan.R;
import com.github.adamantcheese.chan.core.manager.PageRequestManager;
import com.github.adamantcheese.chan.core.model.orm.Loadable;
import com.github.adamantcheese.chan.core.site.common.CommonDataStructs;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static com.github.adamantcheese.chan.Chan.instance;
import static com.github.adamantcheese.chan.utils.AndroidUtils.getString;

public class ChanThread {
private Loadable loadable;
// Unmodifiable list of posts. We need it to make this class "thread-safe" (it's actually
Expand Down Expand Up @@ -96,4 +107,52 @@ public synchronized Post getOp() {
public Loadable getLoadable() {
return loadable;
}

public CharSequence summarize(boolean bold) {
Post op;
try {
op = getOp();
} catch (Exception e) {
return null;
}
SpannableStringBuilder builder = new SpannableStringBuilder();
boolean hasReplies = op.getReplies() >= 0 || getPostsCount() - 1 > 0;
boolean hasImages = op.getImagesCount() >= 0 || getImagesCount() > 0;
int style = bold ? Typeface.BOLD_ITALIC : Typeface.ITALIC;
if (hasReplies && hasImages) {
boolean hasBumpLimit = loadable.board.bumpLimit > 0;
boolean hasImageLimit = loadable.board.imageLimit > 0;

SpannableString replies =
new SpannableString((op.getReplies() >= 0 ? op.getReplies() : getPostsCount() - 1) + "R");
if (hasBumpLimit && op.getReplies() >= loadable.board.bumpLimit) {
replies.setSpan(new StyleSpan(style), 0, replies.length(), 0);
}

SpannableString images =
new SpannableString((op.getImagesCount() >= 0 ? op.getImagesCount() : getImagesCount()) + "I");
if (hasImageLimit && op.getImagesCount() >= loadable.board.imageLimit) {
images.setSpan(new StyleSpan(style), 0, images.length(), 0);
}

builder.append(replies).append(" / ").append(images);

if (op.getUniqueIps() >= 0) {
String ips = op.getUniqueIps() + "P";
builder.append(" / ").append(ips);
}

if (!getLoadable().isLocal()) {
CommonDataStructs.ChanPage p = instance(PageRequestManager.class).getPage(op);
if (p != null) {
SpannableString page = new SpannableString(String.valueOf(p.page));
if (p.page >= loadable.board.pages) {
page.setSpan(new StyleSpan(style), 0, page.length(), 0);
}
builder.append(" / ").append(getString(R.string.thread_page_no)).append(' ').append(page);
}
}
}
return builder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import static com.github.adamantcheese.chan.core.model.PostLinkable.Type.QUOTE;
import static com.github.adamantcheese.chan.core.model.PostLinkable.Type.SPOILER;
import static com.github.adamantcheese.chan.utils.AndroidUtils.getContrastColor;
import static com.github.adamantcheese.chan.utils.AndroidUtils.resolveColor;
import static com.github.adamantcheese.chan.utils.AndroidUtils.resolveFloat;
import static com.github.adamantcheese.chan.utils.AndroidUtils.getAttrColor;
import static com.github.adamantcheese.chan.utils.AndroidUtils.getAttrFloat;

/**
* A Clickable span that handles post clicks. These are created in PostParser for post quotes, spoilers etc.<br>
Expand Down Expand Up @@ -63,9 +63,9 @@ public enum Type {
private int markedNo = -1;

public PostLinkable(Theme theme, CharSequence key, Object value, Type type) {
blendRatio = resolveFloat(theme.resValue, R.attr.highlight_linkable_blend);
quoteColor = resolveColor(theme.resValue, R.attr.post_quote_color);
spoilerColor = resolveColor(theme.resValue, R.attr.post_spoiler_color);
blendRatio = getAttrFloat(theme.resValue, R.attr.highlight_linkable_blend);
quoteColor = getAttrColor(theme.resValue, R.attr.post_quote_color);
spoilerColor = getAttrColor(theme.resValue, R.attr.post_spoiler_color);
this.key = key;
this.value = value;
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import com.github.adamantcheese.chan.core.settings.ChanSettings;
import com.github.adamantcheese.chan.core.site.Site;
import com.github.adamantcheese.chan.core.site.SiteActions;
import com.github.adamantcheese.chan.core.site.common.CommonDataStructs.ChanPage;
import com.github.adamantcheese.chan.core.site.http.DeleteRequest;
import com.github.adamantcheese.chan.core.site.http.DeleteResponse;
import com.github.adamantcheese.chan.core.site.loader.ChanThreadLoader;
Expand Down Expand Up @@ -1200,10 +1199,6 @@ public ChanThread getChanThread() {
return isBound() ? chanLoader.getThread() : null;
}

public ChanPage getPage(Post op) {
return pageRequestManager.getPage(op);
}

@Override
public void onListStatusClicked() {
if (!isBound()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ public String getKey() {
//region Declarations
//region THREAD WATCHER
public static final BooleanSetting watchEnabled;
public static final BooleanSetting shortPinInfo;
public static final BooleanSetting watchBackground;
public static final IntegerSetting watchBackgroundInterval;
public static final BooleanSetting removeWatchedFromCatalog;
Expand Down Expand Up @@ -335,7 +334,6 @@ public String getKey() {
//region THREAD WATCHER
watchEnabled = new BooleanSetting(p, "preference_watch_enabled", false);
watchEnabled.addCallback((setting, value) -> postToEventBus(new SettingChanged<>(watchEnabled)));
shortPinInfo = new BooleanSetting(p, "preference_short_pin_info", true);
watchBackground = new BooleanSetting(p, "preference_watch_background_enabled", false);
watchBackground.addCallback((setting, value) -> postToEventBus(new SettingChanged<>(watchBackground)));
watchBackgroundInterval =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import java.util.List;

import static com.github.adamantcheese.chan.utils.AndroidUtils.getContrastColor;
import static com.github.adamantcheese.chan.utils.AndroidUtils.resolveColor;
import static com.github.adamantcheese.chan.utils.AndroidUtils.getAttrColor;
import static com.github.adamantcheese.chan.utils.AndroidUtils.sp;

@AnyThread
Expand Down Expand Up @@ -138,7 +138,7 @@ private void parseSpans(Theme theme, Post.Builder builder) {

if (!TextUtils.isEmpty(builder.moderatorCapcode)) {
capcodeSpan = new SpannableString(StringUtils.caseAndSpace(builder.moderatorCapcode, null));
int accentColor = resolveColor(theme.accentColor.accentStyleId, R.attr.colorAccent);
int accentColor = getAttrColor(theme.accentColor.accentStyleId, R.attr.colorAccent);
capcodeSpan.setSpan(new ForegroundColorSpanHashed(accentColor), 0, capcodeSpan.length(), 0);
capcodeSpan.setSpan(new AbsoluteSizeSpanHashed(detailsSizePx), 0, capcodeSpan.length(), 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import static com.github.adamantcheese.chan.Chan.instance;
import static com.github.adamantcheese.chan.core.site.parser.StyleRule.tagRule;
import static com.github.adamantcheese.chan.utils.AndroidUtils.getAppContext;
import static com.github.adamantcheese.chan.utils.AndroidUtils.resolveColor;
import static com.github.adamantcheese.chan.utils.AndroidUtils.getAttrColor;
import static com.github.adamantcheese.chan.utils.AndroidUtils.sp;

@AnyThread
Expand Down Expand Up @@ -281,7 +281,7 @@ public CharSequence handleTable(

// Overrides the text (possibly) parsed by child nodes.
return span(TextUtils.concat(parts.toArray(new CharSequence[0])),
new ForegroundColorSpanHashed(resolveColor(theme.resValue, R.attr.post_inline_quote_color)),
new ForegroundColorSpanHashed(getAttrColor(theme.resValue, R.attr.post_inline_quote_color)),
new AbsoluteSizeSpanHashed(sp(12f))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import java.util.Arrays;
import java.util.List;

import static com.github.adamantcheese.chan.utils.AndroidUtils.resolveColor;
import static com.github.adamantcheese.chan.utils.AndroidUtils.getAttrColor;

public class StyleRule {
public enum ForegroundColor {
Expand Down Expand Up @@ -274,9 +274,9 @@ public CharSequence apply(
private int getForegroundColor(Theme theme, ForegroundColor foregroundColor) {
switch (foregroundColor) {
case INLINE_QUOTE:
return resolveColor(theme.resValue, R.attr.post_inline_quote_color);
return getAttrColor(theme.resValue, R.attr.post_inline_quote_color);
case QUOTE:
return resolveColor(theme.resValue, R.attr.post_quote_color);
return getAttrColor(theme.resValue, R.attr.post_quote_color);
case RED:
return Color.RED;
default:
Expand All @@ -286,7 +286,7 @@ private int getForegroundColor(Theme theme, ForegroundColor foregroundColor) {

private int getBackgroundColor(Theme theme, BackgroundColor backgroundColor) {
if (backgroundColor == BackgroundColor.CODE) {
return resolveColor(theme.resValue, R.attr.backcolor_secondary);
return getAttrColor(theme.resValue, R.attr.backcolor_secondary);
}
return 0;
}
Expand Down
Loading

0 comments on commit 2556607

Please sign in to comment.