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

Commit

Permalink
added tap speed check for example card onClick
Browse files Browse the repository at this point in the history
  • Loading branch information
langsmith committed Sep 30, 2019
1 parent 79054ad commit 0d16b77
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.Menu;
Expand Down Expand Up @@ -202,6 +203,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
private boolean loggedIn;
private int currentCategory = R.id.nav_basics;
private boolean showJavaExamples = true;
private long clickTimeOfLastSelectedExample = 0;
public static final long CLICK_SPEED_THRESHOLD_MS = 1000;

@Override
@AddTrace(name = "onCreateMainActivity")
Expand Down Expand Up @@ -251,14 +254,19 @@ public void onItemClicked(RecyclerView recyclerView, int position, View view) {

// in case it's an info tile
if (model != null) {
if (showJavaExamples) {
startActivity(model.getJavaActivity());
} else {
startActivity(model.getKotlinActivity());
}

analytics.clickedOnIndividualExample(getString(model.getTitle()), loggedIn);
analytics.viewedScreen(getString(model.getTitle()), loggedIn);
// Prevents rapid double click.
if (SystemClock.elapsedRealtime() - clickTimeOfLastSelectedExample > CLICK_SPEED_THRESHOLD_MS){
clickTimeOfLastSelectedExample = SystemClock.elapsedRealtime();
if (showJavaExamples) {
startActivity(model.getJavaActivity());
} else {
startActivity(model.getKotlinActivity());
}

analytics.clickedOnIndividualExample(getString(model.getTitle()), loggedIn);
analytics.viewedScreen(getString(model.getTitle()), loggedIn);
}
}
}
});
Expand Down

0 comments on commit 0d16b77

Please sign in to comment.