<commit_before>package jp.toastkid.yobidashi.search.favorite

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import androidx.annotation.LayoutRes
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import jp.toastkid.yobidashi.R
import jp.toastkid.yobidashi.databinding.ActivityEmptyBinding
import jp.toastkid.yobidashi.libs.ImageLoader
import jp.toastkid.yobidashi.libs.preference.PreferenceApplier
import jp.toastkid.yobidashi.libs.view.ToolbarColorApplier

/**
 * Search history list activity.
 *
 * @author toastkidjp
 */
class FavoriteSearchActivity : AppCompatActivity() {

    private lateinit var binding: ActivityEmptyBinding

    private lateinit var preferenceApplier: PreferenceApplier

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(LAYOUT_ID)

        preferenceApplier = PreferenceApplier(this)

        binding = DataBindingUtil.setContentView<ActivityEmptyBinding>(this, LAYOUT_ID)

        binding.toolbar.also { toolbar ->
            toolbar.setNavigationIcon(R.drawable.ic_back)
            toolbar.setNavigationOnClickListener { finish() }
            toolbar.setTitle(titleId())
            toolbar.inflateMenu(R.menu.settings_toolbar_menu)
            toolbar.setOnMenuItemClickListener{ clickMenu(it) }
        }

        val fragment = FavoriteSearchFragment()
        val transaction = supportFragmentManager.beginTransaction()
        transaction.replace(R.id.content, fragment)
        transaction.commitAllowingStateLoss()
    }

    override fun onResume() {
        super.onResume()

        ToolbarColorApplier()(window, binding.toolbar, preferenceApplier.colorPair())

        ImageLoader.setImageToImageView(binding.background, preferenceApplier.backgroundImagePath)
    }

    private fun clickMenu(item: MenuItem) = when (item.itemId) {
        R.id.menu_exit -> {
            moveTaskToBack(true)
            true
        }
        R.id.menu_close -> {
            finish()
            true
        }
        else -> true
    }

    @StringRes
    private fun titleId(): Int = R.string.title_favorite_search

    companion object {

        @LayoutRes
        private const val LAYOUT_ID: Int = R.layout.activity_empty
<commit_msg>refactor #442 Move to constant.<commit_after>package jp.toastkid.yobidashi.search.favorite

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import androidx.annotation.LayoutRes
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import jp.toastkid.yobidashi.R
import jp.toastkid.yobidashi.databinding.ActivityEmptyBinding
import jp.toastkid.yobidashi.libs.ImageLoader
import jp.toastkid.yobidashi.libs.preference.PreferenceApplier
import jp.toastkid.yobidashi.libs.view.ToolbarColorApplier

/**
 * Search history list activity.
 *
 * @author toastkidjp
 */
class FavoriteSearchActivity : AppCompatActivity() {

    private lateinit var binding: ActivityEmptyBinding

    private lateinit var preferenceApplier: PreferenceApplier

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(LAYOUT_ID)

        preferenceApplier = PreferenceApplier(this)

        binding = DataBindingUtil.setContentView<ActivityEmptyBinding>(this, LAYOUT_ID)

        binding.toolbar.also { toolbar ->
            toolbar.setNavigationIcon(R.drawable.ic_back)
            toolbar.setNavigationOnClickListener { finish() }
            toolbar.setTitle(titleId)
            toolbar.inflateMenu(R.menu.settings_toolbar_menu)
            toolbar.setOnMenuItemClickListener{ clickMenu(it) }
        }

        val fragment = FavoriteSearchFragment()
        val transaction = supportFragmentManager.beginTransaction()
        transaction.replace(R.id.content, fragment)
        transaction.commitAllowingStateLoss()
    }

    override fun onResume() {
        super.onResume()

        ToolbarColorApplier()(window, binding.toolbar, preferenceApplier.colorPair())

        ImageLoader.setImageToImageView(binding.background, preferenceApplier.backgroundImagePath)
    }

    private fun clickMenu(item: MenuItem) = when (item.itemId) {
        R.id.menu_exit -> {
            moveTaskToBack(true)
            true
        }
        R.id.menu_close -> {
            finish()
            true
        }
        else -> true
    }

    companion object {

        @LayoutRes
        private const val LAYOUT_ID: Int = R.layout.activity_empty

        @StringRes
        private const val titleId: Int = R.string.title_favorite_search

{'fraction_non_alphanumeric': 0.07945091514143095, 'fraction_numerical': 0.0006239600665557404, 'mean_word_length': 3.222124670763828, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '7253199', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1311, 'n_words': 233}