<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.activity.ComponentActivity
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Icon
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.snapshots.SnapshotStateList
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.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.viewmodel.compose.viewModel
import jp.toastkid.lib.ContentViewModel
import jp.toastkid.lib.model.OptionMenu
import jp.toastkid.lib.preference.PreferenceApplier
import jp.toastkid.lib.scroll.rememberViewInteropNestedScrollConnection
import jp.toastkid.ui.dialog.DestructiveChangeConfirmDialog
import jp.toastkid.yobidashi.R
import jp.toastkid.yobidashi.libs.db.DatabaseFinder
import jp.toastkid.yobidashi.settings.color.DefaultColorInsertion
import jp.toastkid.yobidashi.settings.color.RandomColorInsertion
import jp.toastkid.yobidashi.settings.color.SavedColor
import jp.toastkid.yobidashi.settings.color.SavedColorRepository
import jp.toastkid.yobidashi.settings.view.ColorPaletteUi
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

@Composable
internal fun ColorSettingUi() {
    val context = LocalContext.current
    val preferenceApplier = PreferenceApplier(context)

    val repository = DatabaseFinder().invoke(context).savedColorRepository()

    val colorPair = preferenceApplier.colorPair()
    val initialBgColor = colorPair.bgColor()
    val initialFontColor = colorPair.fontColor()

    val coroutineScope = rememberCoroutineScope()

    val contentViewModel = (context as? ViewModelStoreOwner)?.let {
        ViewModelProvider(it).get(ContentViewModel::class.java)
    }

    val savedColors = remember { mutableStateListOf<List<SavedColor>>() }

    val currentBackgroundColor =
        remember { mutableStateOf(Color(preferenceApplier.color)) }

    val currentFontColor =
        remember { mutableStateOf(Color(preferenceApplier.fontColor)) }

    val openConfirmDialog = remember { mutableStateOf(false) }

    LazyColumn(
        modifier = Modifier
            .nestedScroll(rememberViewInteropNestedScrollConnection())
            .padding(start = 8.dp, end = 8.dp)
    ) {
        item {
            ColorPaletteUi(
                currentBackgroundColor,
                currentFontColor,
                initialBgColor,
                initialFontColor,
                onCommit = {
                    val bgColor = currentBackgroundColor.value
                    val fontColor = currentFontColor.value

                    commitNewColor(
                        preferenceApplier,
                        currentBackgroundColor,
                        currentFontColor,
                        bgColor,
                        fontColor
                    )
                    contentViewModel?.snackShort(R.string.settings_color_done_commit)
<commit_msg>refactor #853 Remove useless interop.<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.activity.ComponentActivity
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Icon
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.snapshots.SnapshotStateList
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.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.viewmodel.compose.viewModel
import jp.toastkid.lib.ContentViewModel
import jp.toastkid.lib.model.OptionMenu
import jp.toastkid.lib.preference.PreferenceApplier
import jp.toastkid.ui.dialog.DestructiveChangeConfirmDialog
import jp.toastkid.yobidashi.R
import jp.toastkid.yobidashi.libs.db.DatabaseFinder
import jp.toastkid.yobidashi.settings.color.DefaultColorInsertion
import jp.toastkid.yobidashi.settings.color.RandomColorInsertion
import jp.toastkid.yobidashi.settings.color.SavedColor
import jp.toastkid.yobidashi.settings.color.SavedColorRepository
import jp.toastkid.yobidashi.settings.view.ColorPaletteUi
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

@Composable
internal fun ColorSettingUi() {
    val context = LocalContext.current
    val preferenceApplier = PreferenceApplier(context)

    val repository = DatabaseFinder().invoke(context).savedColorRepository()

    val colorPair = preferenceApplier.colorPair()
    val initialBgColor = colorPair.bgColor()
    val initialFontColor = colorPair.fontColor()

    val coroutineScope = rememberCoroutineScope()

    val contentViewModel = (context as? ViewModelStoreOwner)?.let {
        ViewModelProvider(it).get(ContentViewModel::class.java)
    }

    val savedColors = remember { mutableStateListOf<List<SavedColor>>() }

    val currentBackgroundColor =
        remember { mutableStateOf(Color(preferenceApplier.color)) }

    val currentFontColor =
        remember { mutableStateOf(Color(preferenceApplier.fontColor)) }

    val openConfirmDialog = remember { mutableStateOf(false) }

    LazyColumn(
        modifier = Modifier.padding(start = 8.dp, end = 8.dp)
    ) {
        item {
            ColorPaletteUi(
                currentBackgroundColor,
                currentFontColor,
                initialBgColor,
                initialFontColor,
                onCommit = {
                    val bgColor = currentBackgroundColor.value
                    val fontColor = currentFontColor.value

                    commitNewColor(
                        preferenceApplier,
                        currentBackgroundColor,
                        currentFontColor,
                        bgColor,
                        fontColor
                    )
                    contentViewModel?.snackShort(R.string.settings_color_done_commit)

{'fraction_non_alphanumeric': 0.07376588327898347, 'fraction_numerical': 0.0025863038344765546, 'mean_word_length': 3.8548034934497815, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4643710', 'n_tokens_mistral': 2594, 'n_tokens_neox': 2486, 'n_words': 432}