Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Added tap speed check for example card onClick #1228

Merged
merged 1 commit into from
Oct 11, 2019

Conversation

langsmith
Copy link
Contributor

Resolves #1227 by adding a check of the tap speed on a single example card. Right now on master, tapping quickly will open a duplicate activity.

Before:
65902426-44673400-e36f-11e9-9d19-9b0d848ad9f1

After:

ezgif com-resize

analytics.clickedOnIndividualExample(getString(model.getTitle()), loggedIn);
analytics.viewedScreen(getString(model.getTitle()), loggedIn);
// Prevents rapid double click.
if (SystemClock.elapsedRealtime() - clickTimeOfLastSelectedExample > CLICK_SPEED_THRESHOLD_MS) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to me like a device-dependent way to resolve the issue. How about leveraging onPause/onResume to remove/add recycler click listener? Is the timing of those lifecycle callbacks correct?

@langsmith langsmith force-pushed the ls-fixing-example-card-double-tap branch from 9a8d037 to 1dae115 Compare October 3, 2019 18:24
@langsmith langsmith force-pushed the ls-fixing-example-card-double-tap branch 2 times, most recently from 1304eae to d06740a Compare October 5, 2019 00:12
@LukasPaczos
Copy link
Member

First of all, there's a bug in the ItemClickSupport that it sets an irreversible click listener on the recycler view after the view is attached:

private OnChildAttachStateChangeListener attachListener = new OnChildAttachStateChangeListener() {
@Override
public void onChildViewAttachedToWindow(View view) {
if (onItemClickListener != null) {
view.setOnClickListener(onClickListener);
}
if (onItemLongClickListener != null) {
view.setOnLongClickListener(onLongClickListener);
}
}

Calling removeFrom after the recycler has been attached to the window has no effect at all, the view still has a set listener that's going to get notified. This whole setup should be refactored.

Currently, it can be worked around by removing the listener itself instead of the view:

// keep the reference to the created `ItemClickSupport`
itemClickSupport = ItemClickSupport.addTo(recyclerView);
itemClickSupport.setOnItemClickListener(this);
// when item is clicked, remove the listener
itemClickSupport.setOnItemClickListener(null);
// when activity is resumed, reattach the listener
itemClickSupport.setOnItemClickListener(this);

Locally I can confirm that this resolved the issue.

}

@Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause: ");
ItemClickSupport.removeFrom(recyclerView);
itemClickSupport.setOnItemClickListener(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this enough to resolve the issue? I was testing with this invocation in onItemClicked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Override
  protected void onPause() {
    super.onPause();
    itemClickSupport.setOnItemClickListener(null);
  }

is working 💯 for me

@langsmith langsmith force-pushed the ls-fixing-example-card-double-tap branch from 61e9d15 to 6678f8f Compare October 9, 2019 21:53
Copy link
Member

@LukasPaczos LukasPaczos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

}
});
itemClickSupport = ItemClickSupport.addTo(recyclerView);
itemClickSupport.setOnItemClickListener(this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Since we are always setting the listener in the onResume, this is redundant.

@langsmith langsmith force-pushed the ls-fixing-example-card-double-tap branch from 6678f8f to 1ff7cf2 Compare October 11, 2019 13:45
@langsmith langsmith merged commit 5ea36af into master Oct 11, 2019
@langsmith langsmith deleted the ls-fixing-example-card-double-tap branch October 11, 2019 13:58
@langsmith langsmith mentioned this pull request Nov 12, 2019
5 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix example double tapping
2 participants