<commit_before>package jp.toastkid.yobidashi.browser.bookmark

import android.graphics.Bitmap
import android.net.Uri
import android.support.annotation.DrawableRes
import android.support.v7.widget.RecyclerView
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.disposables.Disposables
import io.reactivex.schedulers.Schedulers
import jp.toastkid.yobidashi.R
import jp.toastkid.yobidashi.browser.bookmark.model.Bookmark
import jp.toastkid.yobidashi.databinding.ItemBookmarkBinding
import jp.toastkid.yobidashi.libs.ImageLoader
import timber.log.Timber
import java.io.File

/**
 * @author toastkidjp
 */
internal class ViewHolder(private val binding: ItemBookmarkBinding)
    : RecyclerView.ViewHolder(binding.root) {

    fun setText(text: String, url: String) {
        binding.title.text = text
        binding.url.text = url
    }

    fun setImageId(@DrawableRes iconId: Int) {
        binding.icon.setImageResource(iconId)
    }

    fun setImage(faviconPath: String): Disposable {
        if (faviconPath.isEmpty()) {
            setDefaultIcon()
            return Disposables.empty()
        }
        return Single.fromCallable { File(faviconPath) }
                .subscribeOn(Schedulers.io())
                .observeOn(Schedulers.io())
                .map { ImageLoader.loadBitmap(binding.root.context, Uri.fromFile(it)) as Bitmap }
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        { binding.icon.setImageBitmap(it) },
                        { e ->
                            Timber.e(e)
                            setDefaultIcon()
                        }
                )
    }

    private fun setDefaultIcon() {
        binding.icon.setImageResource(
                R.drawable.ic_bookmark_black
        )
    }

    fun setOnClickAdd(history: Bookmark, onClickAdd: (Bookmark) -> Unit) {
        binding.delete.setOnClickListener { onClickAdd(history) }
    }

}
<commit_msg>refactor #283 Add comments in bookmark.ViewHolder.<commit_after>package jp.toastkid.yobidashi.browser.bookmark

import android.graphics.Bitmap
import android.net.Uri
import android.support.annotation.DrawableRes
import android.support.v7.widget.RecyclerView
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.disposables.Disposables
import io.reactivex.schedulers.Schedulers
import jp.toastkid.yobidashi.R
import jp.toastkid.yobidashi.browser.bookmark.model.Bookmark
import jp.toastkid.yobidashi.databinding.ItemBookmarkBinding
import jp.toastkid.yobidashi.libs.ImageLoader
import timber.log.Timber
import java.io.File

/**
 * Bookmark item [ViewHolder].
 *
 * @param binding Data Binding object
 * @author toastkidjp
 */
internal class ViewHolder(private val binding: ItemBookmarkBinding)
    : RecyclerView.ViewHolder(binding.root) {

    /**
     * Set text and URL.
     *
     * @param text text
     * @param url URL string
     */
    fun setText(text: String, url: String) {
        binding.title.text = text
        binding.url.text = url
    }

    /**
     * Set image with drawable ID.
     *
     * @param iconId Icon's drawable resource ID.
     */
    fun setImageId(@DrawableRes iconId: Int) {
        binding.icon.setImageResource(iconId)
    }

    /**
     * Set image with favicon path.
     *
     * @param faviconPath favicon path
     */
    fun setImage(faviconPath: String): Disposable {
        if (faviconPath.isEmpty()) {
            setDefaultIcon()
            return Disposables.empty()
        }
        return Single.fromCallable { File(faviconPath) }
                .subscribeOn(Schedulers.io())
                .observeOn(Schedulers.io())
                .map { ImageLoader.loadBitmap(binding.root.context, Uri.fromFile(it)) as Bitmap }
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(
                        { binding.icon.setImageBitmap(it) },
                        { e ->
                            Timber.e(e)
                            setDefaultIcon()
                        }
                )
    }

    /**
     * Set default icon.
     */
    private fun setDefaultIcon() {
        binding.icon.setImageResource(
                R.drawable.ic_bookmark_black
        )
    }

    /**
     * Set action when click add-button.
     *
     * @param history [Bookmark] item
     * @param onClickAdd click action
     */
    fun setOnClickAdd(history: Bookmark, onClickAdd: (Bookmark) -> Unit) {
        binding.delete.setOnClickListener { onClickAdd(history) }
    }

}

{'fraction_non_alphanumeric': 0.09606801275239107, 'fraction_numerical': 0.0010626992561105207, 'mean_word_length': 2.2680555555555557, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5013315', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1364, 'n_words': 246}