<commit_before>/*
 * Copyright (c) 2022 toastkidjp.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html.
 */

package jp.toastkid.yobidashi.settings.view.screen

import androidx.annotation.ColorRes
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Checkbox
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Slider
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.viewmodel.compose.viewModel
import jp.toastkid.lib.ContentViewModel
import jp.toastkid.lib.color.IconColorFinder
import jp.toastkid.lib.preference.PreferenceApplier
import jp.toastkid.ui.parts.InsetDivider
import jp.toastkid.yobidashi.R
import jp.toastkid.yobidashi.settings.fragment.OverlayColorFilterUseCase
import kotlin.math.roundToInt

@Composable
internal fun ColorFilterSettingUi() {
    val activityContext = LocalContext.current
    val preferenceApplier = PreferenceApplier(activityContext)

    val sample =
        remember { mutableStateOf(preferenceApplier.filterColor(Color.Transparent.toArgb())) }
    val sliderValue =
        remember { mutableStateOf(OverlayColorFilterUseCase.getDefaultAlpha().toFloat() / 255f) }
    val check = remember { mutableStateOf(preferenceApplier.useColorFilter()) }

    val contentViewModel = (activityContext as? ViewModelStoreOwner)?.let{
        viewModel(ContentViewModel::class.java, activityContext)
    }

    val useCase = OverlayColorFilterUseCase(
        preferenceApplier,
        { ContextCompat.getColor(activityContext, it) },
        contentViewModel
    )

    Surface(elevation = 4.dp, modifier = Modifier.padding(8.dp)) {
        Column {
            val onClick = {
                val newState = !preferenceApplier.useColorFilter()
                preferenceApplier.setUseColorFilter(newState)
                contentViewModel?.refresh()

                check.value = preferenceApplier.useColorFilter()
            }
            Row(
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier
                    .fillMaxWidth()
                    .clickable(onClick = onClick)
                    .padding(start = 16.dp, end = 16.dp)
            ) {
                Icon(
                    painterResource(id = R.drawable.ic_color_filter_black),
                    contentDescription = stringResource(id = R.string.title_color_filter),
                    tint = Color(IconColorFinder.from(activityContext).invoke())
                )
                Text(
                    text = stringResource(id = R.string.title_color_filter),
                    modifier = Modifier.weight(1f)
                )
                Checkbox(
                    checked = check.value,
                    onCheckedChange = { onClick() },
                    modifier = Modifier
                        .width(44.dp)
                        .align(Alignment.CenterVertically)
                )
            }

            InsetDivider()

            Row(
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(start = 16.dp, end = 16.dp)
            ) {
                Box(
                    contentAlignment = Alignment.Center,
                    modifier = Modifier
                        .size(40.dp)<commit_msg>refactor #289 Use secondary color.<commit_after>/*
 * Copyright (c) 2022 toastkidjp.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html.
 */

package jp.toastkid.yobidashi.settings.view.screen

import androidx.annotation.ColorRes
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Checkbox
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Slider
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.viewmodel.compose.viewModel
import jp.toastkid.lib.ContentViewModel
import jp.toastkid.lib.preference.PreferenceApplier
import jp.toastkid.ui.parts.InsetDivider
import jp.toastkid.yobidashi.R
import jp.toastkid.yobidashi.settings.fragment.OverlayColorFilterUseCase
import kotlin.math.roundToInt

@Composable
internal fun ColorFilterSettingUi() {
    val activityContext = LocalContext.current
    val preferenceApplier = PreferenceApplier(activityContext)

    val sample =
        remember { mutableStateOf(preferenceApplier.filterColor(Color.Transparent.toArgb())) }
    val sliderValue =
        remember { mutableStateOf(OverlayColorFilterUseCase.getDefaultAlpha().toFloat() / 255f) }
    val check = remember { mutableStateOf(preferenceApplier.useColorFilter()) }

    val contentViewModel = (activityContext as? ViewModelStoreOwner)?.let{
        viewModel(ContentViewModel::class.java, activityContext)
    }

    val useCase = OverlayColorFilterUseCase(
        preferenceApplier,
        { ContextCompat.getColor(activityContext, it) },
        contentViewModel
    )

    Surface(elevation = 4.dp, modifier = Modifier.padding(8.dp)) {
        Column {
            val onClick = {
                val newState = !preferenceApplier.useColorFilter()
                preferenceApplier.setUseColorFilter(newState)
                contentViewModel?.refresh()

                check.value = preferenceApplier.useColorFilter()
            }
            Row(
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier
                    .fillMaxWidth()
                    .clickable(onClick = onClick)
                    .padding(start = 16.dp, end = 16.dp)
            ) {
                Icon(
                    painterResource(id = R.drawable.ic_color_filter_black),
                    contentDescription = stringResource(id = R.string.title_color_filter),
                    tint = MaterialTheme.colors.secondary
                )
                Text(
                    text = stringResource(id = R.string.title_color_filter),
                    modifier = Modifier.weight(1f)
                )
                Checkbox(
                    checked = check.value,
                    onCheckedChange = { onClick() },
                    modifier = Modifier
                        .width(44.dp)
                        .align(Alignment.CenterVertically)
                )
            }

            InsetDivider()

            Row(
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(start = 16.dp, end = 16.dp)
            ) {
                Box(
                    contentAlignment = Alignment.Center,
                    modifier = Modifier
                        .size(40.dp)
{'fraction_non_alphanumeric': 0.07869115728194319, 'fraction_numerical': 0.0055204255746261165, 'mean_word_length': 2.717910447761194, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3406899', 'n_tokens_mistral': 2783, 'n_tokens_neox': 2628, 'n_words': 467}