|
|
@ -7,17 +7,18 @@ import org.floens.chan.model.Post; |
|
|
|
import org.floens.chan.model.PostLinkable; |
|
|
|
import org.floens.chan.model.PostLinkable; |
|
|
|
import org.floens.chan.net.ChanUrls; |
|
|
|
import org.floens.chan.net.ChanUrls; |
|
|
|
import org.floens.chan.utils.IconCache; |
|
|
|
import org.floens.chan.utils.IconCache; |
|
|
|
|
|
|
|
import org.floens.chan.utils.ViewUtils; |
|
|
|
|
|
|
|
|
|
|
|
import android.app.Activity; |
|
|
|
import android.app.Activity; |
|
|
|
import android.content.Context; |
|
|
|
import android.content.Context; |
|
|
|
import android.content.res.Resources; |
|
|
|
import android.content.res.Resources; |
|
|
|
import android.graphics.Color; |
|
|
|
import android.graphics.Color; |
|
|
|
import android.graphics.drawable.Drawable; |
|
|
|
|
|
|
|
import android.text.SpannableString; |
|
|
|
import android.text.SpannableString; |
|
|
|
import android.text.TextUtils; |
|
|
|
import android.text.TextUtils; |
|
|
|
import android.text.format.DateUtils; |
|
|
|
import android.text.format.DateUtils; |
|
|
|
import android.text.method.LinkMovementMethod; |
|
|
|
import android.text.method.LinkMovementMethod; |
|
|
|
import android.text.style.AbsoluteSizeSpan; |
|
|
|
import android.text.style.AbsoluteSizeSpan; |
|
|
|
|
|
|
|
import android.text.style.BackgroundColorSpan; |
|
|
|
import android.text.style.ForegroundColorSpan; |
|
|
|
import android.text.style.ForegroundColorSpan; |
|
|
|
import android.util.AttributeSet; |
|
|
|
import android.util.AttributeSet; |
|
|
|
import android.view.View; |
|
|
|
import android.view.View; |
|
|
@ -80,7 +81,6 @@ public class PostView extends LinearLayout implements View.OnClickListener, View |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation") |
|
|
|
|
|
|
|
public void setPost(final Post post, final ThreadManager manager) { |
|
|
|
public void setPost(final Post post, final ThreadManager manager) { |
|
|
|
this.post = post; |
|
|
|
this.post = post; |
|
|
|
this.manager = manager; |
|
|
|
this.manager = manager; |
|
|
@ -116,6 +116,22 @@ public class PostView extends LinearLayout implements View.OnClickListener, View |
|
|
|
total = TextUtils.concat(total, tripcode, " "); |
|
|
|
total = TextUtils.concat(total, tripcode, " "); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(post.id)) { |
|
|
|
|
|
|
|
SpannableString id = new SpannableString(" ID: " + post.id + " "); |
|
|
|
|
|
|
|
IDColor c = computeIDColor(post.id); |
|
|
|
|
|
|
|
id.setSpan(new ForegroundColorSpan(c.color), 0, id.length(), 0); |
|
|
|
|
|
|
|
id.setSpan(new BackgroundColorSpan(c.backgroundColor), 0, id.length(), 0); |
|
|
|
|
|
|
|
id.setSpan(new AbsoluteSizeSpan(10, true), 0, id.length(), 0); |
|
|
|
|
|
|
|
total = TextUtils.concat(total, id, " "); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(post.capcode)) { |
|
|
|
|
|
|
|
SpannableString tripcode = new SpannableString("Capcode: " + post.capcode); |
|
|
|
|
|
|
|
tripcode.setSpan(new ForegroundColorSpan(Color.argb(255, 255, 0, 0)), 0, tripcode.length(), 0); |
|
|
|
|
|
|
|
tripcode.setSpan(new AbsoluteSizeSpan(10, true), 0, tripcode.length(), 0); |
|
|
|
|
|
|
|
total = TextUtils.concat(total, tripcode, " "); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CharSequence relativeTime = DateUtils.getRelativeTimeSpanString(post.time * 1000L, System.currentTimeMillis(), |
|
|
|
CharSequence relativeTime = DateUtils.getRelativeTimeSpanString(post.time * 1000L, System.currentTimeMillis(), |
|
|
|
DateUtils.SECOND_IN_MILLIS, 0); |
|
|
|
DateUtils.SECOND_IN_MILLIS, 0); |
|
|
|
|
|
|
|
|
|
|
@ -207,10 +223,7 @@ public class PostView extends LinearLayout implements View.OnClickListener, View |
|
|
|
setClickable(true); |
|
|
|
setClickable(true); |
|
|
|
setFocusable(true); |
|
|
|
setFocusable(true); |
|
|
|
|
|
|
|
|
|
|
|
int[] attr = new int[] {android.R.attr.selectableItemBackground}; |
|
|
|
ViewUtils.setPressedDrawable(this); |
|
|
|
Drawable drawable = context.obtainStyledAttributes(attr).getDrawable(0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setBackgroundDrawable(drawable); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -224,8 +237,9 @@ public class PostView extends LinearLayout implements View.OnClickListener, View |
|
|
|
isBuild = true; |
|
|
|
isBuild = true; |
|
|
|
|
|
|
|
|
|
|
|
Resources resources = context.getResources(); |
|
|
|
Resources resources = context.getResources(); |
|
|
|
|
|
|
|
int postPadding = resources.getDimensionPixelSize(R.dimen.post_padding); |
|
|
|
int commentPadding = resources.getDimensionPixelSize(R.dimen.post_comment_padding); |
|
|
|
int commentPadding = resources.getDimensionPixelSize(R.dimen.post_comment_padding); |
|
|
|
int textPadding = resources.getDimensionPixelSize(R.dimen.post_text_padding); |
|
|
|
int iconPadding = resources.getDimensionPixelSize(R.dimen.post_icon_padding); |
|
|
|
int iconWidth = resources.getDimensionPixelSize(R.dimen.post_icon_width); |
|
|
|
int iconWidth = resources.getDimensionPixelSize(R.dimen.post_icon_width); |
|
|
|
int iconHeight = resources.getDimensionPixelSize(R.dimen.post_icon_height); |
|
|
|
int iconHeight = resources.getDimensionPixelSize(R.dimen.post_icon_height); |
|
|
|
int imageSize = resources.getDimensionPixelSize(R.dimen.thumbnail_size); |
|
|
|
int imageSize = resources.getDimensionPixelSize(R.dimen.thumbnail_size); |
|
|
@ -257,21 +271,20 @@ public class PostView extends LinearLayout implements View.OnClickListener, View |
|
|
|
|
|
|
|
|
|
|
|
LinearLayout right = new LinearLayout(context); |
|
|
|
LinearLayout right = new LinearLayout(context); |
|
|
|
right.setOrientation(VERTICAL); |
|
|
|
right.setOrientation(VERTICAL); |
|
|
|
right.setPadding(commentPadding, commentPadding, commentPadding, commentPadding); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(0, 0, 0, textPadding); |
|
|
|
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(0, 0, 0, textPadding); |
|
|
|
iconView.setPadding(postPadding, iconPadding, postPadding, 0); |
|
|
|
|
|
|
|
|
|
|
|
stickyView = new ImageView(context); |
|
|
|
stickyView = new ImageView(context); |
|
|
|
stickyView.setImageBitmap(IconCache.stickyIcon); |
|
|
|
stickyView.setImageBitmap(IconCache.stickyIcon); |
|
|
@ -285,18 +298,34 @@ public class PostView extends LinearLayout implements View.OnClickListener, View |
|
|
|
|
|
|
|
|
|
|
|
commentView = new TextView(context); |
|
|
|
commentView = new TextView(context); |
|
|
|
commentView.setTextSize(15); |
|
|
|
commentView.setTextSize(15); |
|
|
|
|
|
|
|
commentView.setPadding(postPadding, commentPadding, postPadding, commentPadding); |
|
|
|
right.addView(commentView, matchWrapParams); |
|
|
|
right.addView(commentView, matchWrapParams); |
|
|
|
|
|
|
|
|
|
|
|
repliesCountView = new TextView(context); |
|
|
|
repliesCountView = new TextView(context); |
|
|
|
repliesCountView.setTextColor(Color.argb(255, 100, 100, 100)); |
|
|
|
repliesCountView.setTextColor(Color.argb(255, 100, 100, 100)); |
|
|
|
repliesCountView.setPadding(0, textPadding, 0, 0); |
|
|
|
repliesCountView.setPadding(postPadding, postPadding, postPadding, postPadding); |
|
|
|
repliesCountView.setTextSize(14); |
|
|
|
repliesCountView.setTextSize(14); |
|
|
|
|
|
|
|
ViewUtils.setPressedDrawable(repliesCountView); |
|
|
|
|
|
|
|
|
|
|
|
right.addView(repliesCountView, matchWrapParams); |
|
|
|
right.addView(repliesCountView, wrapParams); |
|
|
|
|
|
|
|
|
|
|
|
full.addView(right, matchWrapParams); |
|
|
|
full.addView(right, matchWrapParams); |
|
|
|
|
|
|
|
|
|
|
|
addView(full, wrapParams); |
|
|
|
addView(full, matchParams); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private IDColor computeIDColor(String id) { |
|
|
|
|
|
|
|
// Stolen from the 4chan extension
|
|
|
|
|
|
|
|
int hash = post.id.hashCode(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int r = (hash >> 24) & 0xff; |
|
|
|
|
|
|
|
int g = (hash >> 16) & 0xff; |
|
|
|
|
|
|
|
int b = (hash >> 8) & 0xff; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IDColor c = new IDColor(); |
|
|
|
|
|
|
|
c.color = (0xff << 24) + (r << 16) + (g << 8) + b; |
|
|
|
|
|
|
|
c.backgroundColor = ((r * 0.299f) + (g * 0.587f) + (b * 0.114f)) > 125 ? 0xff636363 : 0x00000000; |
|
|
|
|
|
|
|
return c; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void onLinkableClick(PostLinkable linkable) { |
|
|
|
public void onLinkableClick(PostLinkable linkable) { |
|
|
@ -314,6 +343,11 @@ public class PostView extends LinearLayout implements View.OnClickListener, View |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class IDColor { |
|
|
|
|
|
|
|
public int color; |
|
|
|
|
|
|
|
public int backgroundColor; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|