use of com.ferg.awfulapp.provider.ColorProvider in project Awful.apk by Awful.
the class AwfulThread method setDataOnThreadListItem.
@SuppressWarnings("deprecation")
public static void setDataOnThreadListItem(View item, AwfulPreferences prefs, Cursor data, AwfulFragment parent) {
AwfulThread thread = fromCursorRow(data);
if (thread == null) {
Timber.w("setDataOnThreadView: unable to get data for thread!");
return;
}
Resources resources = item.getResources();
Context context = item.getContext();
// get the forum ID for getting themed resources
Integer forumId = null;
if (ForumDisplayFragment.class.isInstance(parent)) {
forumId = ((ForumDisplayFragment) parent).getForumId();
}
// thread title
TextView title = findById(item, R.id.title);
title.setText(thread.title != null ? thread.title : "UNKNOWN");
title.setTextColor(ColorProvider.PRIMARY_TEXT.getColor(forumId));
// main thread tag
final ImageView threadTag = findById(item, R.id.thread_tag);
threadTag.setVisibility(GONE);
if (prefs.threadInfo_Tag) {
if (!TextUtils.isEmpty(thread.tagCacheFile)) {
threadTag.setVisibility(VISIBLE);
String url = thread.tagUrl;
String localFileName = "@drawable/" + url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('.')).replace('-', '_').toLowerCase();
int imageID = resources.getIdentifier(localFileName, null, context.getPackageName());
if (imageID == 0) {
NetworkUtils.getImageLoader().get(url, new ImageLoader.ImageListener() {
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
threadTag.setImageBitmap(response.getBitmap());
}
@Override
public void onErrorResponse(VolleyError error) {
threadTag.setImageResource(R.drawable.empty_thread_tag);
}
});
} else {
threadTag.setImageResource(imageID);
}
}
}
// tag overlay (secondary tags etc)
ImageView forumTagOverlay = findById(item, R.id.thread_tag_overlay);
ImageView inlineForumTagOverlay = findById(item, R.id.thread_tag_overlay_optional);
forumTagOverlay.setVisibility(GONE);
inlineForumTagOverlay.setVisibility(GONE);
if (ExtraTags.getType(thread.tagExtra) != ExtraTags.TYPE_NO_TAG) {
Drawable tagIcon = ExtraTags.getDrawable(thread.tagExtra, resources);
if (tagIcon != null) {
if (prefs.threadInfo_Tag) {
showImage(forumTagOverlay, tagIcon);
} else {
showImage(inlineForumTagOverlay, tagIcon);
}
}
}
// page count / author / last poster info line
TextView info = findById(item, R.id.thread_info);
info.setVisibility(VISIBLE);
String tmp = String.format(Locale.US, "%d pgs | %s: %s", thread.getPageCount(prefs.postPerPage), thread.hasBeenViewed ? "Last" : "OP", NetworkUtils.unencodeHtml(thread.hasBeenViewed ? thread.lastPoster : thread.author));
info.setText(tmp.trim());
info.setTextColor(ColorProvider.ALT_TEXT.getColor(forumId));
// ratings
ImageView threadRating = findById(item, R.id.thread_rating);
ImageView inlineThreadRating = findById(item, R.id.thread_rating_optional);
threadRating.setVisibility(GONE);
inlineThreadRating.setVisibility(GONE);
// if we're showing ratings...
if (prefs.threadInfo_Rating) {
Drawable ratingIcon = AwfulRatings.getDrawable(thread.rating, resources);
// Film Dump replaces the actual thread tag, instead of using the separate rating view
if (AwfulRatings.getType(thread.rating) == AwfulRatings.TYPE_FILM_DUMP) {
showImage(threadTag, ratingIcon);
} else {
showImage(prefs.threadInfo_Tag ? threadRating : inlineThreadRating, ratingIcon);
}
}
// locked and sticky status
ImageView threadLocked = findById(item, R.id.thread_locked);
ImageView threadSticky = findById(item, R.id.thread_sticky);
threadSticky.setVisibility(thread.isSticky ? VISIBLE : GONE);
threadLocked.setVisibility(thread.isLocked && !thread.isSticky ? VISIBLE : GONE);
if (thread.isLocked && !thread.isSticky) {
// TODO: 03/06/2017 what's this about?
item.setBackgroundColor(ColorProvider.BACKGROUND.getColor(forumId));
}
// unread counter
TextView unread = findById(item, R.id.unread_count);
unread.setVisibility(GONE);
if (thread.hasBeenViewed) {
unread.setVisibility(VISIBLE);
unread.setTextColor(ColorProvider.UNREAD_TEXT.getColor(forumId));
unread.setText(Integer.toString(thread.unreadCount));
GradientDrawable counter = (GradientDrawable) resources.getDrawable(R.drawable.unread_counter);
if (counter != null) {
counter.mutate();
boolean dim = !thread.hasNewPosts();
if (thread.bookmarkType > 0 && prefs.coloredBookmarks) {
counter.setColor(ColorProvider.getBookmarkColor(thread.bookmarkType, dim));
} else {
ColorProvider colorAttr = dim ? ColorProvider.UNREAD_BACKGROUND_DIM : ColorProvider.UNREAD_BACKGROUND;
counter.setColor(colorAttr.getColor(forumId));
}
unread.setBackgroundDrawable(counter);
}
}
}
Aggregations