<commit_before>/*
    Copyright 2017 <NAME>

    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 com.wolandsoft.sss.activity.fragment.entries;

import android.os.Handler;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;
import com.wolandsoft.sss.R;
import com.wolandsoft.sss.entity.SecretEntry;
import com.wolandsoft.sss.service.core.CoreServiceProxy;
import com.wolandsoft.sss.util.LogEx;

import java.util.Collections;
import java.util.List;

/**
 * Adapter for {@link RecyclerView} component.
 *
 * @author <NAME>
 */
abstract class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewHolder> {
    private static final long DELAY_SEARCH_UPDATE = 1000;
    private final Handler mHandler;
    private final CoreServiceProxy mCore;
    private List<Integer> mItemIds = null;
    private String mSearchCriteria = "";
    private Runnable mSearchUpdate;
    private boolean mSearchLocked = false;

    RecyclerViewAdapter(CoreServiceProxy core) {
        mCore = core;
        mHandler = new Handler();
        mItemIds = Collections.emptyList();
    }

    void updateSearchCriteria(final String criteria) {
        LogEx.d("updateSearchCriteria(", criteria, ")");
        if (!mSearchLocked) {
            if (mSearchUpdate != null) {
                mHandler.removeCallbacks(mSearchUpdate);
            }
            mSearchUpdate = new Runnable() {
                @Override
                public void run() {
                    if (!criteria.equals(mSearchCriteria)) {
                        mSearchCriteria = criteria;
                        updateModel();
                    }
                }
            };
            mHandler.postDelayed(mSearchUpdate, DELAY_SEARCH_UPDATE);
        }
    }

    @Override
    public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LogEx.d("onCreateViewHolder(", parent, ",", viewType, ")");
        View card = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_entries_include_card, parent, false);
        return new RecyclerViewHolder(card);
    }

    @Override
    public void onBindViewHolder(RecyclerViewHolder holder, int position) {
        LogEx.d("onBindViewHolder(", holder, ",", position, ")");
        holder.itemView.setLongClickable(true);
        final SecretEntry entry = getItem(position);
        holder.mTxtTitle.setVisibility(View.INVISIBLE);
        holder.mTxtTitleSmall.setVisibility(View.GONE);<commit_msg>search clear response time<commit_after>/*
    Copyright 2017 <NAME>

    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 com.wolandsoft.sss.activity.fragment.entries;

import android.os.Handler;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;
import com.wolandsoft.sss.R;
import com.wolandsoft.sss.entity.SecretEntry;
import com.wolandsoft.sss.service.core.CoreServiceProxy;
import com.wolandsoft.sss.util.LogEx;

import java.util.Collections;
import java.util.List;

/**
 * Adapter for {@link RecyclerView} component.
 *
 * @author <NAME>
 */
abstract class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewHolder> {
    private static final long DELAY_SEARCH_UPDATE = 1000;
    private final Handler mHandler;
    private final CoreServiceProxy mCore;
    private List<Integer> mItemIds = null;
    private String mSearchCriteria = "";
    private Runnable mSearchUpdate;
    private boolean mSearchLocked = false;

    RecyclerViewAdapter(CoreServiceProxy core) {
        mCore = core;
        mHandler = new Handler();
        mItemIds = Collections.emptyList();
    }

    void updateSearchCriteria(final String criteria) {
        LogEx.d("updateSearchCriteria(", criteria, ")");
        if (!mSearchLocked) {
            if (mSearchUpdate != null) {
                mHandler.removeCallbacks(mSearchUpdate);
            }
            if(criteria.length() == 0){
                mSearchCriteria = criteria;
                updateModel();
            } else {
                mSearchUpdate = new Runnable() {
                    @Override
                    public void run() {
                        if (!criteria.equals(mSearchCriteria)) {
                            mSearchCriteria = criteria;
                            updateModel();
                        }
                    }
                };
                mHandler.postDelayed(mSearchUpdate, DELAY_SEARCH_UPDATE);
            }
        }
    }

    @Override
    public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LogEx.d("onCreateViewHolder(", parent, ",", viewType, ")");
        View card = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_entries_include_card, parent, false);
        return new RecyclerViewHolder(card);
    }

    @Override
    public void onBindViewHolder(RecyclerViewHolder holder, int position) {
        LogEx.d("onBindViewHolder(", holder, ",", position, ")");
        holder.itemView.setLongClickable(true);
        final SecretEntry entry = getItem(position);
        holder.mTxtTitle.setVisibility(View.INVISIBLE);
        holder.mTxtTitleSmall.setVisibility(View.GONE);
{'fraction_non_alphanumeric': 0.08985376149555253, 'fraction_numerical': 0.004372078998944671, 'mean_word_length': 2.861466821885914, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2375039', 'n_tokens_mistral': 1845, 'n_tokens_neox': 1766, 'n_words': 452}