Skip to content

Commit

Permalink
Do less work in grid touch listener.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbutcher committed Dec 3, 2015
1 parent a1ab54d commit ff7d3f0
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions app/src/main/java/io/plaidapp/ui/FeedAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ public void onClick(View view) {
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;
Expand All @@ -264,7 +270,7 @@ public boolean onTouch(View v, MotionEvent event) {
}
if (gif == null) return false;
// GIF found, start/stop it on press/lift
switch (event.getAction()) {
switch (action) {
case MotionEvent.ACTION_DOWN:
gif.start();
break;
Expand All @@ -287,10 +293,11 @@ private void bindDribbbleShotHolder(final Shot shot,
.listener(new RequestListener<String, GlideDrawable>() {

@Override
public boolean onResourceReady(GlideDrawable resource, String model,
Target<GlideDrawable> target, boolean
isFromMemoryCache, boolean
isFirstResource) {
public boolean onResourceReady(GlideDrawable resource,
String model,
Target<GlideDrawable> target,
boolean isFromMemoryCache,
boolean isFirstResource) {
if (!shot.hasFadedIn) {
holder.image.setHasTransientState(true);
final ObservableColorMatrix cm = new ObservableColorMatrix();
Expand Down Expand Up @@ -544,8 +551,7 @@ public long getItemId(int position) {

@Override
public int getItemCount() {
// include loading footer
return getDataItemCount() + 1;
return getDataItemCount() + 1; // include loading footer
}

/**
Expand Down Expand Up @@ -582,7 +588,7 @@ public Class[] getDividedViewHolderClasses() {
return new Class[] { DesignerNewsStoryHolder.class, ProductHuntStoryHolder.class };
}

/* protected */ class DribbbleShotHolder extends RecyclerView.ViewHolder {
/* package */ class DribbbleShotHolder extends RecyclerView.ViewHolder {

BadgedFourThreeImageView image;

Expand All @@ -593,7 +599,7 @@ public DribbbleShotHolder(View itemView) {

}

/* protected */ class DesignerNewsStoryHolder extends RecyclerView.ViewHolder {
/* package */ class DesignerNewsStoryHolder extends RecyclerView.ViewHolder {

@Bind(R.id.story_title) TextView title;
@Bind(R.id.story_comments) TextView comments;
Expand All @@ -606,7 +612,7 @@ public DesignerNewsStoryHolder(View itemView, boolean pocketIsInstalled) {
}
}

/* protected */ class ProductHuntStoryHolder extends RecyclerView.ViewHolder {
/* package */ class ProductHuntStoryHolder extends RecyclerView.ViewHolder {

@Bind(R.id.hunt_title) TextView title;
@Bind(R.id.tagline) TextView tagline;
Expand All @@ -618,7 +624,7 @@ public ProductHuntStoryHolder(View itemView) {
}
}

/* protected */ class LoadingMoreHolder extends RecyclerView.ViewHolder {
/* package */ class LoadingMoreHolder extends RecyclerView.ViewHolder {

ProgressBar progress;

Expand Down

0 comments on commit ff7d3f0

Please sign in to comment.