use of io.plaidapp.data.api.dribbble.model.Shot in project plaid by nickbutcher.
the class PlayerActivity method bindPlayer.
void bindPlayer() {
if (player == null)
return;
final Resources res = getResources();
final NumberFormat nf = NumberFormat.getInstance();
Glide.with(this).load(player.getHighQualityAvatarUrl()).placeholder(R.drawable.avatar_placeholder).transform(circleTransform).into(avatar);
playerName.setText(player.name.toLowerCase());
if (!TextUtils.isEmpty(player.bio)) {
DribbbleUtils.parseAndSetText(bio, player.bio);
} else {
bio.setVisibility(View.GONE);
}
shotCount.setText(res.getQuantityString(R.plurals.shots, player.shots_count, nf.format(player.shots_count)));
if (player.shots_count == 0) {
shotCount.setCompoundDrawablesRelativeWithIntrinsicBounds(null, getDrawable(R.drawable.avd_no_shots), null, null);
}
setFollowerCount(player.followers_count);
likesCount.setText(res.getQuantityString(R.plurals.likes, player.likes_count, nf.format(player.likes_count)));
// load the users shots
dataManager = new PlayerShotsDataManager(this, player) {
@Override
public void onDataLoaded(List<Shot> data) {
if (data != null && data.size() > 0) {
if (adapter.getDataItemCount() == 0) {
loading.setVisibility(View.GONE);
ViewUtils.setPaddingTop(shots, likesCount.getBottom());
}
adapter.addAndResort(data);
}
}
};
adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this));
shots.setAdapter(adapter);
shots.setItemAnimator(new SlideInItemAnimator());
shots.setVisibility(View.VISIBLE);
layoutManager = new GridLayoutManager(this, columns);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return adapter.getItemColumnSpan(position);
}
});
shots.setLayoutManager(layoutManager);
shots.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {
@Override
public void onLoadMore() {
dataManager.loadData();
}
});
shots.setHasFixedSize(true);
// forward on any clicks above the first item in the grid (i.e. in the paddingTop)
// to 'pass through' to the view behind
shots.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int firstVisible = layoutManager.findFirstVisibleItemPosition();
if (firstVisible > 0)
return false;
// if no data loaded then pass through
if (adapter.getDataItemCount() == 0) {
return container.dispatchTouchEvent(event);
}
final RecyclerView.ViewHolder vh = shots.findViewHolderForAdapterPosition(0);
if (vh == null)
return false;
final int firstTop = vh.itemView.getTop();
if (event.getY() < firstTop) {
return container.dispatchTouchEvent(event);
}
return false;
}
});
// check if following
if (dataManager.getDribbblePrefs().isLoggedIn()) {
if (player.id == dataManager.getDribbblePrefs().getUserId()) {
TransitionManager.beginDelayedTransition(container);
follow.setVisibility(View.GONE);
ViewUtils.setPaddingTop(shots, container.getHeight() - follow.getHeight() - ((ViewGroup.MarginLayoutParams) follow.getLayoutParams()).bottomMargin);
} else {
final Call<Void> followingCall = dataManager.getDribbbleApi().following(player.id);
followingCall.enqueue(new Callback<Void>() {
@Override
public void onResponse(Call<Void> call, Response<Void> response) {
following = response.isSuccessful();
if (!following)
return;
TransitionManager.beginDelayedTransition(container);
follow.setText(R.string.following);
follow.setActivated(true);
}
@Override
public void onFailure(Call<Void> call, Throwable t) {
}
});
}
}
if (player.shots_count > 0) {
// kick off initial load
dataManager.loadData();
} else {
loading.setVisibility(View.GONE);
}
}
use of io.plaidapp.data.api.dribbble.model.Shot in project plaid by nickbutcher.
the class DribbbleSearchConverter method convert.
@Override
public List<Shot> convert(ResponseBody value) throws IOException {
final Elements shotElements = Jsoup.parse(value.string(), HOST).select("li[id^=screenshot]");
final List<Shot> shots = new ArrayList<>(shotElements.size());
for (Element element : shotElements) {
final Shot shot = parseShot(element, DATE_FORMAT);
if (shot != null) {
shots.add(shot);
}
}
return shots;
}
use of io.plaidapp.data.api.dribbble.model.Shot in project plaid by nickbutcher.
the class ShotWeigher method weigh.
@Override
public void weigh(List<Shot> shots) {
float maxLikes = 0f;
for (Shot shot : shots) {
maxLikes = Math.max(maxLikes, shot.likes_count);
}
for (Shot shot : shots) {
float weight = 1f - ((float) shot.likes_count / maxLikes);
shot.weight = shot.page + weight;
}
}
use of io.plaidapp.data.api.dribbble.model.Shot in project sbt-android by scala-android.
the class FeedAdapter method sort.
protected void sort() {
// calculate the 'weight' for each data type and then sort by that. Each data type has a
// different metric for weighing it e.g. Dribbble uses likes etc. Weights are 'scoped' to
// the page they belong to and lower weights are sorted higher in the grid.
int count = getDataItemCount();
int maxDesignNewsVotes = 0;
int maxDesignNewsComments = 0;
long maxDribbleLikes = 0;
int maxProductHuntVotes = 0;
int maxProductHuntComments = 0;
// work out some maximum values to weigh individual items against
for (int i = 0; i < count; i++) {
PlaidItem item = getItem(i);
if (item instanceof Story) {
maxDesignNewsComments = Math.max(((Story) item).comment_count, maxDesignNewsComments);
maxDesignNewsVotes = Math.max(((Story) item).vote_count, maxDesignNewsVotes);
} else if (item instanceof Shot) {
maxDribbleLikes = Math.max(((Shot) item).likes_count, maxDribbleLikes);
} else if (item instanceof Post) {
maxProductHuntComments = Math.max(((Post) item).comments_count, maxProductHuntComments);
maxProductHuntVotes = Math.max(((Post) item).votes_count, maxProductHuntVotes);
}
}
// now go through and set the weight of each item
for (int i = 0; i < count; i++) {
PlaidItem item = getItem(i);
if (item instanceof Story) {
((Story) item).weigh(maxDesignNewsComments, maxDesignNewsVotes);
} else if (item instanceof Shot) {
((Shot) item).weigh(maxDribbleLikes);
} else if (item instanceof Post) {
((Post) item).weigh(maxProductHuntComments, maxProductHuntVotes);
}
// scope it to the page it came from
item.weight += item.page;
}
// sort by weight
Collections.sort(items, comparator);
// TODO call the more specific RV variants
notifyDataSetChanged();
}
use of io.plaidapp.data.api.dribbble.model.Shot in project sbt-android by scala-android.
the class DribbbleSearch method search.
@WorkerThread
public static List<Shot> search(String query, @SortOrder String sort, int page) {
String html = null;
// e.g https://dribbble.com/search?q=material+design&page=7&per_page=12
HttpUrl url = new HttpUrl.Builder().scheme("https").host("dribbble.com").addPathSegment("search").addQueryParameter("q", query).addQueryParameter("s", sort).addQueryParameter("page", String.valueOf(page)).addQueryParameter("per_page", "12").build();
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(url).build();
try {
Response response = client.newCall(request).execute();
html = response.body().string();
} catch (IOException ioe) {
return null;
}
if (html == null)
return null;
Elements shotElements = Jsoup.parse(html, HOST).select("li[id^=screenshot]");
SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy");
List<Shot> shots = new ArrayList<>(shotElements.size());
for (Element element : shotElements) {
Shot shot = parseShot(element, dateFormat);
if (shot != null) {
shots.add(shot);
}
}
return shots;
}
Aggregations