<commit_before>/*
 * Copyright 2015 Google Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.uribeacon.validator;

import android.graphics.drawable.AnimatedVectorDrawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import java.util.ArrayList;

public class TestsAdapter extends RecyclerView.Adapter<TestsAdapter.ViewHolder> {

  private static final String TAG = TestsAdapter.class.getCanonicalName();
  private ArrayList<TestHelper> mDataset;

  // Provide a suitable constructor (depends on the kind of dataset)
  public TestsAdapter(ArrayList<TestHelper> uriBeaconTests) {
    mDataset = uriBeaconTests;
  }

  // Create new views (invoked by the layout manager)
  @Override
  public TestsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
      int viewType) {
    // create a new view
    View v = LayoutInflater.from(parent.getContext())
        .inflate(R.layout.test_view, parent, false);

    ViewHolder vh = new ViewHolder(v);
    return vh;
  }

  // Replace the contents of a view (invoked by the layout manager)
  @Override
  public void onBindViewHolder(ViewHolder holder, int position) {
    // - get element from your dataset at this position
    // - replace the contents of the view with that element
    TestHelper test = mDataset.get(position);
    holder.mTestName.setText(test.getName());
    setIcon(holder.mImageView, test);
    setErrorMessage(holder, test);
    if (test.isFailed()) {
      setOnClickListener(holder);
    }
  }

  private void setOnClickListener(final ViewHolder holder) {<commit_msg>Fix for recycler view, recycling too much<commit_after>/*
 * Copyright 2015 Google Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.uribeacon.validator;

import android.graphics.drawable.AnimatedVectorDrawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import java.util.ArrayList;

public class TestsAdapter extends RecyclerView.Adapter<TestsAdapter.ViewHolder> {

  private static final String TAG = TestsAdapter.class.getCanonicalName();
  private ArrayList<TestHelper> mDataset;

  // Provide a suitable constructor (depends on the kind of dataset)
  public TestsAdapter(ArrayList<TestHelper> uriBeaconTests) {
    mDataset = uriBeaconTests;
  }

  // Create new views (invoked by the layout manager)
  @Override
  public TestsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
      int viewType) {
    // create a new view
    View v = LayoutInflater.from(parent.getContext())
        .inflate(R.layout.test_view, parent, false);

    ViewHolder vh = new ViewHolder(v);
    return vh;
  }

  // Replace the contents of a view (invoked by the layout manager)
  @Override
  public void onBindViewHolder(ViewHolder holder, int position) {
    // - get element from your dataset at this position
    // - replace the contents of the view with that element
    TestHelper test = mDataset.get(position);
    holder.mTestName.setText(test.getName());
    setIcon(holder.mImageView, test);
    if (test.isFailed()) {
      setErrorMessage(holder, test);
      setOnClickListener(holder);
    } else {
      holder.mTestResult.setVisibility(View.GONE);
      holder.mTestDetails.setVisibility(View.GONE);
      holder.mLayout.setOnClickListener(null);
      holder.mLayout.setClickable(false);
    }
  }

  private void setOnClickListener(final ViewHolder holder) {
{'fraction_non_alphanumeric': 0.08386043664558253, 'fraction_numerical': 0.003672719853091206, 'mean_word_length': 4.074534161490683, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5017001', 'n_tokens_mistral': 1345, 'n_tokens_neox': 1300, 'n_words': 449}