<commit_before>package com.ghstudios.android.features.search

import android.content.Context
import android.graphics.drawable.Drawable
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.TextView
import com.ghstudios.android.*
import com.ghstudios.android.ClickListeners.ItemClickListener
import com.ghstudios.android.ClickListeners.MonsterClickListener
import com.ghstudios.android.ClickListeners.QuestClickListener
import com.ghstudios.android.ClickListeners.SkillClickListener
import com.ghstudios.android.data.classes.*
import com.ghstudios.android.mhgendatabase.R
import com.hannesdorfmann.adapterdelegates3.AbsListItemAdapterDelegate


/**
 * A simple handler class used to create mappings for the Universal Search results.
 * Handler should override getImageResource or the T data object should implement the ITintedIcon
 * interface so that getImage() will handle the rest.
 * @param <T>
 */
abstract class ResultHandler<in T> {
    open fun getImageResource(obj: T): Int {
        return -1
    }

    abstract fun getName(obj: T): String
    abstract fun getType(obj: T): String
    abstract fun createListener(ctx: Context, obj: T): View.OnClickListener

    fun setImage(imgView:ImageView, obj: T) {
        val resource = this.getImageResource(obj)
        if (resource == -1) {
            if (obj is ITintedIcon)
                AssetLoader.setIcon(imgView, obj)
        } else {
            imgView.setImageResource(getImageResource(obj))
            imgView.setColorFilter(0xFFFFFF)
        }
    }
}

/**
 * Creates a mapping of data type -> handler. Context is used to retrieve the localized type names
 */<commit_msg>Fixed icons bleaching in search<commit_after>package com.ghstudios.android.features.search

import android.content.Context
import android.graphics.drawable.Drawable
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.TextView
import com.ghstudios.android.*
import com.ghstudios.android.ClickListeners.ItemClickListener
import com.ghstudios.android.ClickListeners.MonsterClickListener
import com.ghstudios.android.ClickListeners.QuestClickListener
import com.ghstudios.android.ClickListeners.SkillClickListener
import com.ghstudios.android.data.classes.*
import com.ghstudios.android.mhgendatabase.R
import com.hannesdorfmann.adapterdelegates3.AbsListItemAdapterDelegate


/**
 * A simple handler class used to create mappings for the Universal Search results.
 * Handler should override getImageResource or the T data object should implement the ITintedIcon
 * interface so that getImage() will handle the rest.
 * @param <T>
 */
abstract class ResultHandler<in T> {
    open fun getImageResource(obj: T): Int {
        return -1
    }

    abstract fun getName(obj: T): String
    abstract fun getType(obj: T): String
    abstract fun createListener(ctx: Context, obj: T): View.OnClickListener

    fun setImage(imgView:ImageView, obj: T) {
        val resource = this.getImageResource(obj)
        if (resource == -1) {
            if (obj is ITintedIcon)
                AssetLoader.setIcon(imgView, obj)
        } else {
            imgView.setImageResource(getImageResource(obj))
        }
    }
}

/**
 * Creates a mapping of data type -> handler. Context is used to retrieve the localized type names
 */
{'fraction_non_alphanumeric': 0.080896962815782, 'fraction_numerical': 0.002554640931024695, 'mean_word_length': 4.012802275960171, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2657902', 'n_tokens_mistral': 972, 'n_tokens_neox': 953, 'n_words': 269}