Skip to content

Instantly share code, notes, and snippets.

@kmdupr33
Last active August 29, 2015 14:22
Show Gist options
  • Save kmdupr33/0560695307233112cf3f to your computer and use it in GitHub Desktop.
Save kmdupr33/0560695307233112cf3f to your computer and use it in GitHub Desktop.
public class SessionDetailActivity {
//...
private void tryRenderTags() {
if (mTagMetadata == null || mTagsString == null) {
return;
}
if (TextUtils.isEmpty(mTagsString)) {
mTagsContainer.setVisibility(View.GONE);
} else {
mTagsContainer.setVisibility(View.VISIBLE);
mTags.removeAllViews();
LayoutInflater inflater = LayoutInflater.from(this);
String[] tagIds = mTagsString.split(",");
List<TagMetadata.Tag> tags = new ArrayList<TagMetadata.Tag>();
for (String tagId : tagIds) {
if (Config.Tags.SESSIONS.equals(tagId) ||
Config.Tags.SPECIAL_KEYNOTE.equals(tagId)) {
continue;
}
TagMetadata.Tag tag = mTagMetadata.getTag(tagId);
if (tag == null) {
continue;
}
tags.add(tag);
}
if (tags.size() == 0) {
mTagsContainer.setVisibility(View.GONE);
return;
}
Collections.sort(tags, TagMetadata.TAG_DISPLAY_ORDER_COMPARATOR);
for (final TagMetadata.Tag tag : tags) {
TextView chipView = (TextView) inflater.inflate(
R.layout.include_session_tag_chip, mTags, false);
chipView.setText(tag.getName());
if (Config.Tags.CATEGORY_TOPIC.equals(tag.getCategory())) {
ShapeDrawable colorDrawable = new ShapeDrawable(new OvalShape());
colorDrawable.setIntrinsicWidth(mTagColorDotSize);
colorDrawable.setIntrinsicHeight(mTagColorDotSize);
colorDrawable.getPaint().setStyle(Paint.Style.FILL);
chipView.setCompoundDrawablesWithIntrinsicBounds(colorDrawable,
null, null, null);
colorDrawable.getPaint().setColor(tag.getColor());
}
chipView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish(); // TODO: better encapsulation
Intent intent = new Intent(SessionDetailActivity.this, BrowseSessionsActivity.class)
.putExtra(BrowseSessionsActivity.EXTRA_FILTER_TAG, tag.getId())
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
});
mTags.addView(chipView);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment