use of net.dean.jraw.models.Thumbnails in project Slide by ccrama.
the class ListViewRemoteViewsFactory method getViewAt.
// Given the position (index) of a WidgetItem in the array, use the item's text value in
// combination with the app widget item XML file to construct a RemoteViews object.
public RemoteViews getViewAt(int position) {
// position will always range from 0 to getCount() - 1.
// Construct a RemoteViews item based on the app widget item XML file, and set the
// text based on the position.
int view = R.layout.submission_widget_light;
switch(SubredditWidgetProvider.getViewType(id, mContext)) {
case 1:
case 0:
if (SubredditWidgetProvider.getThemeFromId(id, mContext) == 2) {
view = R.layout.submission_widget_light;
} else {
view = R.layout.submission_widget;
}
break;
case 2:
if (SubredditWidgetProvider.getThemeFromId(id, mContext) == 2) {
view = R.layout.submission_widget_compact_light;
} else {
view = R.layout.submission_widget_compact;
}
break;
}
final RemoteViews rv = new RemoteViews(mContext.getPackageName(), view);
try {
// feed row
Submission data = records.get(position);
rv.setTextViewText(R.id.title, Html.fromHtml(data.getTitle()));
rv.setTextViewText(R.id.score, data.getScore() + "");
rv.setTextViewText(R.id.comments, data.getCommentCount() + "");
rv.setTextViewText(R.id.information, data.getAuthor() + " " + TimeUtils.getTimeAgo(data.getCreated().getTime(), mContext));
rv.setTextViewText(R.id.subreddit, data.getSubredditName());
rv.setTextColor(R.id.subreddit, Palette.getColor(data.getSubredditName()));
if (SubredditWidgetProvider.getViewType(id, mContext) == 1) {
Thumbnails s = data.getThumbnails();
rv.setViewVisibility(R.id.thumbimage2, View.GONE);
if (s != null && s.getVariations() != null && s.getSource() != null) {
rv.setImageViewBitmap(R.id.bigpic, ((Reddit) mContext.getApplicationContext()).getImageLoader().loadImageSync(Html.fromHtml(data.getThumbnails().getSource().getUrl()).toString()));
rv.setViewVisibility(R.id.bigpic, View.VISIBLE);
} else {
rv.setViewVisibility(R.id.bigpic, View.GONE);
}
} else {
if (SubredditWidgetProvider.getViewType(id, mContext) != 2) {
rv.setViewVisibility(R.id.bigpic, View.GONE);
}
if (data.getThumbnailType() == Submission.ThumbnailType.URL) {
rv.setImageViewBitmap(R.id.thumbimage2, ((Reddit) mContext.getApplicationContext()).getImageLoader().loadImageSync(data.getThumbnail()));
rv.setViewVisibility(R.id.thumbimage2, View.VISIBLE);
} else {
rv.setViewVisibility(R.id.thumbimage2, View.GONE);
}
}
switch(SubredditWidgetProvider.getViewType(id, mContext)) {
case 1:
case 0:
if (SubredditWidgetProvider.getThemeFromId(id, mContext) == 2) {
} else {
rv.setTextColor(R.id.title, Color.WHITE);
rv.setTextColor(R.id.score, Color.WHITE);
rv.setTextColor(R.id.comments, Color.WHITE);
rv.setTextColor(R.id.information, Color.WHITE);
}
break;
case 2:
if (SubredditWidgetProvider.getThemeFromId(id, mContext) == 2) {
} else {
rv.setTextColor(R.id.title, Color.WHITE);
rv.setTextColor(R.id.score, Color.WHITE);
rv.setTextColor(R.id.comments, Color.WHITE);
rv.setTextColor(R.id.information, Color.WHITE);
}
break;
}
Bundle infos = new Bundle();
infos.putString(OpenContent.EXTRA_URL, data.getPermalink());
infos.putBoolean("popup", true);
final Intent activityIntent = new Intent();
activityIntent.putExtras(infos);
activityIntent.setAction(data.getTitle());
rv.setOnClickFillInIntent(R.id.card, activityIntent);
} catch (Exception e) {
}
return rv;
}
Aggregations