use of io.plaidapp.data.api.dribbble.PlayerShotsDataManager 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);
}
}
Aggregations