<commit_before>package jp.toastkid.yobidashi.launcher

import android.content.ActivityNotFoundException
import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.rxkotlin.toObservable
import io.reactivex.schedulers.Schedulers
import jp.toastkid.yobidashi.R
import jp.toastkid.yobidashi.databinding.AppLauncherItemBinding
import jp.toastkid.yobidashi.libs.Toaster
import jp.toastkid.yobidashi.libs.preference.PreferenceApplier
import timber.log.Timber
import java.util.*

/**
 * RecyclerView's adapter.
 *
 * @author toastkidjp
 */
internal class Adapter(private val context: Context, private val parent: View)
    : RecyclerView.Adapter<ViewHolder>() {

    /**
     * Master list.
     */
    private val master: List<ApplicationInfo>

    /**
     * Current list.
     */
    private val installedApps: MutableList<ApplicationInfo>

    /**
     * Preferences wrapper.
     */
    private val preferenceApplier: PreferenceApplier

    /**
     * Package manager.
     */
    private val packageManager: PackageManager = context.packageManager

    /**
     * Disposables.
     */
    private val disposables: CompositeDisposable = CompositeDisposable()

    init {
        this.master = packageManager.getInstalledApplications(PackageManager.GET_META_DATA)
        this.installedApps = ArrayList(master)
        this.preferenceApplier = PreferenceApplier(context)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val itemBinding = DataBindingUtil.inflate<AppLauncherItemBinding>(
                LayoutInflater.from(parent.context),
                R.layout.app_launcher_item,
                parent,
                false
        )
        return ViewHolder(itemBinding)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val info = installedApps[position]
        holder.setImage(info.loadIcon(packageManager))
        holder.setTitle(info.loadLabel(packageManager).toString())
        holder.setTargetSdk(info.targetSdkVersion)
        holder.setPackageName(info.packageName)
        try {
            val packageInfo = packageManager.getPackageInfo(info.packageName, PackageManager.GET_META_DATA)
            holder.setVersionInformation(packageInfo.versionName + "(" + packageInfo.versionCode + ")")
            holder.setInstalledMs(packageInfo.firstInstallTime)
        } catch (e: PackageManager.NameNotFoundException) {
            Timber.e(e)
        }

        setOnClick(holder, info)
    }

    /**
     * Set on click actions.
     *
     * @param holder [ViewHolder]
     * @param info [ApplicationInfo]
     */
    private fun setOnClick(holder: ViewHolder, info: ApplicationInfo) {
        val intent = packageManager.getLaunchIntentForPackage(info.packageName)
        if (intent == null) {
            holder.itemView.setOnClickListener { snackCannotLaunch() }<commit_msg>refactor #442 Use string template.<commit_after>package jp.toastkid.yobidashi.launcher

import android.content.ActivityNotFoundException
import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.rxkotlin.toObservable
import io.reactivex.schedulers.Schedulers
import jp.toastkid.yobidashi.R
import jp.toastkid.yobidashi.databinding.AppLauncherItemBinding
import jp.toastkid.yobidashi.libs.Toaster
import jp.toastkid.yobidashi.libs.preference.PreferenceApplier
import timber.log.Timber
import java.util.*

/**
 * RecyclerView's adapter.
 *
 * @author toastkidjp
 */
internal class Adapter(private val context: Context, private val parent: View)
    : RecyclerView.Adapter<ViewHolder>() {

    /**
     * Master list.
     */
    private val master: List<ApplicationInfo>

    /**
     * Current list.
     */
    private val installedApps: MutableList<ApplicationInfo>

    /**
     * Preferences wrapper.
     */
    private val preferenceApplier: PreferenceApplier

    /**
     * Package manager.
     */
    private val packageManager: PackageManager = context.packageManager

    /**
     * Disposables.
     */
    private val disposables: CompositeDisposable = CompositeDisposable()

    init {
        this.master = packageManager.getInstalledApplications(PackageManager.GET_META_DATA)
        this.installedApps = ArrayList(master)
        this.preferenceApplier = PreferenceApplier(context)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val itemBinding = DataBindingUtil.inflate<AppLauncherItemBinding>(
                LayoutInflater.from(parent.context),
                R.layout.app_launcher_item,
                parent,
                false
        )
        return ViewHolder(itemBinding)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val info = installedApps[position]
        holder.setImage(info.loadIcon(packageManager))
        holder.setTitle(info.loadLabel(packageManager).toString())
        holder.setTargetSdk(info.targetSdkVersion)
        holder.setPackageName(info.packageName)
        try {
            val packageInfo = packageManager.getPackageInfo(info.packageName, PackageManager.GET_META_DATA)
            holder.setVersionInformation("${packageInfo.versionName} (${packageInfo.versionCode})")
            holder.setInstalledMs(packageInfo.firstInstallTime)
        } catch (e: PackageManager.NameNotFoundException) {
            Timber.e(e)
        }

        setOnClick(holder, info)
    }

    /**
     * Set on click actions.
     *
     * @param holder [ViewHolder]
     * @param info [ApplicationInfo]
     */
    private fun setOnClick(holder: ViewHolder, info: ApplicationInfo) {
        val intent = packageManager.getLaunchIntentForPackage(info.packageName)
        if (intent == null) {
            holder.itemView.setOnClickListener { snackCannotLaunch() }
{'fraction_non_alphanumeric': 0.08751317969573731, 'fraction_numerical': 0.00045187528242205153, 'mean_word_length': 3.331376386170907, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2401598', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1833, 'n_words': 332}