use of io.plaidapp.data.api.dribbble.model.Shot in project plaid by nickbutcher.
the class FeedAdapter method createDribbbleShotHolder.
@NonNull
private DribbbleShotHolder createDribbbleShotHolder(ViewGroup parent) {
final DribbbleShotHolder holder = new DribbbleShotHolder(layoutInflater.inflate(R.layout.dribbble_shot_item, parent, false));
holder.image.setBadgeColor(initialGifBadgeColor);
holder.image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setClass(host, DribbbleShot.class);
intent.putExtra(DribbbleShot.EXTRA_SHOT, (Shot) getItem(holder.getAdapterPosition()));
setGridItemContentTransitions(holder.image);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host, Pair.create(view, host.getString(R.string.transition_shot)), Pair.create(view, host.getString(R.string.transition_shot_background)));
host.startActivityForResult(intent, REQUEST_CODE_VIEW_SHOT, options.toBundle());
}
});
// play animated GIFs whilst touched
holder.image.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// check if it's an event we care about, else bail fast
final int action = event.getAction();
if (!(action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL))
return false;
// get the image and check if it's an animated GIF
final Drawable drawable = holder.image.getDrawable();
if (drawable == null)
return false;
GifDrawable gif = null;
if (drawable instanceof GifDrawable) {
gif = (GifDrawable) drawable;
} else if (drawable instanceof TransitionDrawable) {
// we fade in images on load which uses a TransitionDrawable; check its layers
TransitionDrawable fadingIn = (TransitionDrawable) drawable;
for (int i = 0; i < fadingIn.getNumberOfLayers(); i++) {
if (fadingIn.getDrawable(i) instanceof GifDrawable) {
gif = (GifDrawable) fadingIn.getDrawable(i);
break;
}
}
}
if (gif == null)
return false;
// GIF found, start/stop it on press/lift
switch(action) {
case MotionEvent.ACTION_DOWN:
gif.start();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
gif.stop();
break;
}
return false;
}
});
return holder;
}
use of io.plaidapp.data.api.dribbble.model.Shot in project plaid by nickbutcher.
the class FeedAdapter method weighItems.
/**
* Calculate a 'weight' [0, 1] for each data type for sorting. Each data type/source has a
* different metric for weighing it e.g. Dribbble uses likes etc. but some sources should keep
* the order returned by the API. Weights are 'scoped' to the page they belong to and lower
* weights are sorted earlier in the grid (i.e. in ascending weight).
*/
private void weighItems(List<? extends PlaidItem> items) {
if (items == null || items.isEmpty())
return;
PlaidItemSorting.PlaidItemGroupWeigher weigher = null;
switch(items.get(0).dataSource) {
// have an expectation about the order they appear in
case SourceManager.SOURCE_DRIBBBLE_USER_SHOTS:
case SourceManager.SOURCE_DRIBBBLE_USER_LIKES:
case SourceManager.SOURCE_PRODUCT_HUNT:
case PlayerShotsDataManager.SOURCE_PLAYER_SHOTS:
case PlayerShotsDataManager.SOURCE_TEAM_SHOTS:
if (naturalOrderWeigher == null) {
naturalOrderWeigher = new PlaidItemSorting.NaturalOrderWeigher();
}
weigher = naturalOrderWeigher;
break;
default:
// regular pattern of items in the grid
if (items.get(0) instanceof Shot) {
if (shotWeigher == null)
shotWeigher = new ShotWeigher();
weigher = shotWeigher;
} else if (items.get(0) instanceof Story) {
if (storyWeigher == null)
storyWeigher = new StoryWeigher();
weigher = storyWeigher;
} else if (items.get(0) instanceof Post) {
if (postWeigher == null)
postWeigher = new PostWeigher();
weigher = postWeigher;
}
}
weigher.weigh(items);
}
use of io.plaidapp.data.api.dribbble.model.Shot in project plaid by nickbutcher.
the class FeedAdapter method expandPopularItems.
private void expandPopularItems() {
// for now just expand the first dribbble image per page which should be
// the most popular according to our weighing & sorting
List<Integer> expandedPositions = new ArrayList<>();
int page = -1;
final int count = items.size();
for (int i = 0; i < count; i++) {
PlaidItem item = getItem(i);
if (item instanceof Shot && item.page > page) {
item.colspan = columns;
page = item.page;
expandedPositions.add(i);
} else {
item.colspan = 1;
}
}
// so that we don't leave any gaps in the grid
for (int expandedPos = 0; expandedPos < expandedPositions.size(); expandedPos++) {
int pos = expandedPositions.get(expandedPos);
int extraSpannedSpaces = expandedPos * (columns - 1);
int rowPosition = (pos + extraSpannedSpaces) % columns;
if (rowPosition != 0) {
int swapWith = pos + (columns - rowPosition);
if (swapWith < items.size()) {
Collections.swap(items, pos, swapWith);
}
}
}
}
use of io.plaidapp.data.api.dribbble.model.Shot in project sbt-android by scala-android.
the class FeedAdapter method expandPopularItems.
private void expandPopularItems() {
// for now just expand the first dribbble image per page which should be
// the most popular according to #sort.
// TODO make this smarter & handle other item types
List<Integer> expandedPositions = new ArrayList<>();
int page = -1;
final int count = items.size();
for (int i = 0; i < count; i++) {
PlaidItem item = getItem(i);
if (item instanceof Shot && item.page > page) {
item.colspan = columns;
page = item.page;
expandedPositions.add(i);
} else {
item.colspan = 1;
}
}
// so that we don't leave any gaps in the grid
for (int expandedPos = 0; expandedPos < expandedPositions.size(); expandedPos++) {
int pos = expandedPositions.get(expandedPos);
int extraSpannedSpaces = expandedPos * (columns - 1);
int rowPosition = (pos + extraSpannedSpaces) % columns;
if (rowPosition != 0) {
int swapWith = pos + (columns - rowPosition);
Collections.swap(items, pos, swapWith);
}
}
}
use of io.plaidapp.data.api.dribbble.model.Shot in project sbt-android by scala-android.
the class DribbbleSearch method parseShot.
private static Shot parseShot(Element element, SimpleDateFormat dateFormat) {
Element descriptionBlock = element.select("a.dribbble-over").first();
// API responses wrap description in a <p> tag. Do the same for consistent display.
String description = descriptionBlock.select("span.comment").text().trim();
if (!TextUtils.isEmpty(description)) {
description = "<p>" + description + "</p>";
}
String imgUrl = element.select("img").first().attr("src");
if (imgUrl.contains("_teaser.")) {
imgUrl = imgUrl.replace("_teaser.", ".");
}
Date createdAt = null;
try {
createdAt = dateFormat.parse(descriptionBlock.select("em.timestamp").first().text());
} catch (ParseException e) {
}
return new Shot.Builder().setId(Long.parseLong(element.id().replace("screenshot-", ""))).setHtmlUrl(HOST + element.select("a.dribbble-link").first().attr("href")).setTitle(descriptionBlock.select("strong").first().text()).setDescription(description).setImages(new Images(null, imgUrl, null)).setCreatedAt(createdAt).setLikesCount(Long.parseLong(element.select("li.fav").first().child(0).text().replaceAll(",", ""))).setCommentsCount(Long.parseLong(element.select("li.cmnt").first().child(0).text().replaceAll(",", ""))).setViewsCount(Long.parseLong(element.select("li.views").first().child(0).text().replaceAll(",", ""))).setUser(parsePlayer(element.select("h2").first())).build();
}
Aggregations