From 4d3dfc6601917598fbb74547432c09e7d26d5944 Mon Sep 17 00:00:00 2001 From: Dmitrii Rubtsov Date: Wed, 5 Feb 2025 16:14:12 +0200 Subject: [PATCH] Color picker for compose --- .../ui/ds/colorpicker/ColorPickerDialog.kt | 74 --------- .../ui/ds/dialog/ColorPickerDialog.kt | 152 ++++++++++++++++++ .../ui/ds/extensions/Extensions.kt | 11 +- .../ui/ds/preference/ColorPreference.kt | 54 ++----- .../ui/ds/preference/Preference.kt | 6 +- .../ui/ds/preference/PreferenceHeader.kt | 5 +- .../main/res/layout/dialog_color_picker.xml | 63 -------- common-ui/src/main/res/values-de/strings.xml | 2 + common-ui/src/main/res/values-en/strings.xml | 2 + common-ui/src/main/res/values-fr/strings.xml | 2 + common-ui/src/main/res/values-pt/strings.xml | 2 + common-ui/src/main/res/values-ru/strings.xml | 2 + common-ui/src/main/res/values-tr/strings.xml | 1 + common-ui/src/main/res/values-uk/strings.xml | 2 + .../src/main/res/values-zh-rTW/strings.xml | 2 + common-ui/src/main/res/values-zh/strings.xml | 2 + common-ui/src/main/res/values/strings.xml | 3 + feature-editor/impl/build.gradle.kts | 10 ++ .../editor/ui/dialog/InsertColorDialog.kt | 44 +++-- .../impl/src/main/res/values-de/strings.xml | 1 - .../impl/src/main/res/values-en/strings.xml | 1 - .../impl/src/main/res/values-fr/strings.xml | 1 - .../impl/src/main/res/values-pt/strings.xml | 1 - .../impl/src/main/res/values-ru/strings.xml | 1 - .../impl/src/main/res/values-tr/strings.xml | 1 - .../impl/src/main/res/values-uk/strings.xml | 1 - .../src/main/res/values-zh-rTW/strings.xml | 1 - .../impl/src/main/res/values-zh/strings.xml | 1 - .../impl/src/main/res/values/strings.xml | 1 - .../fonts/ui/composable/FontOverview.kt | 2 +- .../impl/src/main/res/values-de/strings.xml | 1 - .../impl/src/main/res/values-en/strings.xml | 1 - .../impl/src/main/res/values-fr/strings.xml | 1 - .../impl/src/main/res/values-pt/strings.xml | 1 - .../impl/src/main/res/values-ru/strings.xml | 1 - .../impl/src/main/res/values-uk/strings.xml | 1 - .../src/main/res/values-zh-rTW/strings.xml | 1 - .../impl/src/main/res/values-zh/strings.xml | 1 - .../impl/src/main/res/values/strings.xml | 2 - .../feature/themes/data/mapper/ThemeMapper.kt | 2 +- .../themes/ui/composable/ThemeOverview.kt | 2 +- .../themes/ui/fragment/EditThemeScreen.kt | 12 +- .../themes/ui/viewmodel/EditThemeViewModel.kt | 2 +- .../impl/src/main/res/values-de/strings.xml | 3 - .../impl/src/main/res/values-en/strings.xml | 2 - .../impl/src/main/res/values-fr/strings.xml | 3 - .../impl/src/main/res/values-pt/strings.xml | 3 - .../impl/src/main/res/values-ru/strings.xml | 2 - .../impl/src/main/res/values-uk/strings.xml | 2 - .../src/main/res/values-zh-rTW/strings.xml | 2 - .../impl/src/main/res/values-zh/strings.xml | 2 - .../impl/src/main/res/values/strings.xml | 3 - gradle/libs.versions.toml | 4 +- 53 files changed, 257 insertions(+), 248 deletions(-) delete mode 100644 common-ui/src/main/kotlin/com/blacksquircle/ui/ds/colorpicker/ColorPickerDialog.kt create mode 100644 common-ui/src/main/kotlin/com/blacksquircle/ui/ds/dialog/ColorPickerDialog.kt delete mode 100644 common-ui/src/main/res/layout/dialog_color_picker.xml diff --git a/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/colorpicker/ColorPickerDialog.kt b/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/colorpicker/ColorPickerDialog.kt deleted file mode 100644 index 24500083b..000000000 --- a/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/colorpicker/ColorPickerDialog.kt +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2023 Squircle CE contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.blacksquircle.ui.ds.colorpicker - -import android.app.Dialog -import android.graphics.Color -import android.os.Bundle -import androidx.appcompat.app.AlertDialog -import androidx.core.graphics.toColorInt -import androidx.core.view.doOnPreDraw -import androidx.core.widget.doOnTextChanged -import androidx.fragment.app.DialogFragment -import com.blacksquircle.ui.ds.databinding.DialogColorPickerBinding -import com.blacksquircle.ui.ds.extensions.toHexString -import com.skydoves.colorpickerview.listeners.ColorListener - -abstract class ColorPickerDialog : DialogFragment() { - - abstract val titleRes: Int - abstract val positiveRes: Int - abstract val negativeRes: Int - abstract val initialColor: String - - private var updatingText = false - - override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val binding = DialogColorPickerBinding.inflate(layoutInflater) - binding.colorPicker.attachAlphaSlider(binding.alphaSlideBar) - binding.colorPicker.attachBrightnessSlider(binding.brightnessSlideBar) - binding.colorPicker.colorListener = ColorListener { color, fromUser -> - if (fromUser) { - updatingText = true - binding.colorInput.setText(color.toHexString()) - updatingText = false - } - } - binding.colorInput.doOnTextChanged { text, _, _, _ -> - if (!updatingText) { - try { - val color = Color.parseColor(text.toString()) - binding.colorPicker.selectByHsvColor(color) - } catch (e: Exception) { - // ignored - } - } - } - binding.colorPicker.doOnPreDraw { - binding.colorPicker.setInitialColor(initialColor.toColorInt()) - binding.colorInput.setText(initialColor) - } - return AlertDialog.Builder(requireContext()) - .setTitle(titleRes) - .setView(binding.root) - .setPositiveButton(positiveRes) { _, _ -> onColorSelected(binding.colorPicker.color) } - .setNegativeButton(negativeRes, null) - .create() - } - - abstract fun onColorSelected(color: Int) -} \ No newline at end of file diff --git a/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/dialog/ColorPickerDialog.kt b/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/dialog/ColorPickerDialog.kt new file mode 100644 index 000000000..7873ea581 --- /dev/null +++ b/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/dialog/ColorPickerDialog.kt @@ -0,0 +1,152 @@ +/* + * Copyright 2023 Squircle CE contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.blacksquircle.ui.ds.dialog + +import android.graphics.Typeface +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.aspectRatio +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.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.compose.ui.window.DialogProperties +import androidx.core.graphics.toColorInt +import com.blacksquircle.ui.ds.SquircleTheme +import com.blacksquircle.ui.ds.extensions.toHexString +import com.blacksquircle.ui.ds.textfield.TextField +import com.github.skydoves.colorpicker.compose.AlphaSlider +import com.github.skydoves.colorpicker.compose.BrightnessSlider +import com.github.skydoves.colorpicker.compose.HsvColorPicker +import com.github.skydoves.colorpicker.compose.rememberColorPickerController + +@Composable +fun ColorPickerDialog( + title: String, + onDismiss: () -> Unit, + modifier: Modifier = Modifier, + confirmButton: String? = null, + dismissButton: String? = null, + alphaSlider: Boolean = true, + brightnessSlider: Boolean = true, + initialColor: Color = Color.White, + onColorSelected: (Color) -> Unit = {}, + onDismissClicked: () -> Unit = {}, + properties: DialogProperties = DialogProperties(), +) { + val controller = rememberColorPickerController() + var textColor by rememberSaveable { + mutableStateOf(initialColor.toHexString()) + } + + AlertDialog( + title = title, + content = { + Column { + HsvColorPicker( + initialColor = initialColor, + onColorChanged = { colorEnvelope -> + if (colorEnvelope.fromUser) { + textColor = "#" + colorEnvelope.hexCode + } + }, + controller = controller, + modifier = Modifier + .aspectRatio(1f / 1f) + .padding(24.dp), + ) + + if (alphaSlider) { + AlphaSlider( + initialColor = initialColor, + controller = controller, + modifier = Modifier + .fillMaxWidth() + .height(28.dp), + ) + Spacer(Modifier.height(16.dp)) + } + + if (brightnessSlider) { + BrightnessSlider( + initialColor = initialColor, + controller = controller, + modifier = Modifier + .fillMaxWidth() + .height(28.dp), + ) + Spacer(Modifier.height(16.dp)) + } + + TextField( + inputText = textColor, + onInputChanged = { input -> + textColor = input + try { + val color = Color(input.toColorInt()) + controller.selectByColor(color, fromUser = false) + } catch (e: Exception) { + // ignored + } + }, + textStyle = TextStyle( + fontFamily = FontFamily(Typeface.MONOSPACE), + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + ), + modifier = Modifier + .align(Alignment.CenterHorizontally) + .width(150.dp) + ) + } + }, + onDismiss = onDismiss, + modifier = modifier, + verticalScroll = true, + horizontalPadding = true, + confirmButton = confirmButton, + dismissButton = dismissButton, + onConfirmClicked = { onColorSelected(controller.selectedColor.value) }, + onDismissClicked = onDismissClicked, + properties = properties, + ) +} + +@Preview +@Composable +private fun ColorPickerDialogPreview() { + SquircleTheme { + ColorPickerDialog( + title = "Color Picker", + onDismiss = {}, + ) + } +} \ No newline at end of file diff --git a/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/extensions/Extensions.kt b/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/extensions/Extensions.kt index e7b875103..8e6b24d5a 100644 --- a/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/extensions/Extensions.kt +++ b/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/extensions/Extensions.kt @@ -18,11 +18,20 @@ package com.blacksquircle.ui.ds.extensions import android.content.res.Resources import android.graphics.Color +import androidx.compose.ui.graphics.Color as ComposeColor fun Int.dpToPx(): Int = (this * Resources.getSystem().displayMetrics.density).toInt() fun Int.pxToDp(): Int = (this / Resources.getSystem().displayMetrics.density).toInt() -fun Int.toHexString(fallbackColor: String = "#000000"): String { +fun ComposeColor.toHexString(): String { + val red = this.red * 255 + val green = this.green * 255 + val blue = this.blue * 255 + val alpha = this.alpha * 255 + return String.format("#%02x%02x%02x%02x", alpha.toInt(), red.toInt(), green.toInt(), blue.toInt()) +} + +fun Int.toHexString(fallbackColor: String = "#FFFFFF"): String { return try { "#" + Integer.toHexString(this) } catch (e: Exception) { diff --git a/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/preference/ColorPreference.kt b/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/preference/ColorPreference.kt index c906aa4f7..6a693fd9f 100644 --- a/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/preference/ColorPreference.kt +++ b/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/preference/ColorPreference.kt @@ -22,38 +22,18 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.saveable.mapSaver import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import com.blacksquircle.ui.ds.R import com.blacksquircle.ui.ds.SquircleTheme -import com.blacksquircle.ui.ds.dialog.AlertDialog - -private const val RedKey = "red" -private const val GreenKey = "green" -private const val BlueKey = "blue" - -private val ColorSaver = mapSaver( - save = { - mapOf( - RedKey to it.red, - GreenKey to it.green, - BlueKey to it.blue, - ) - }, - restore = { - Color( - red = it[RedKey] as Float, - green = it[GreenKey] as Float, - blue = it[BlueKey] as Float - ) - } -) +import com.blacksquircle.ui.ds.dialog.ColorPickerDialog @Composable fun ColorPreference( @@ -63,10 +43,8 @@ fun ColorPreference( initialColor: Color = Color.Black, onColorSelected: (Color) -> Unit = {}, enabled: Boolean = true, - dialogTitle: String? = null, + dialogTitle: String = stringResource(R.string.dialog_title_color_picker), dialogShown: Boolean = false, - confirmButton: String? = null, - dismissButton: String? = null, ) { var showDialog by rememberSaveable { mutableStateOf(dialogShown) @@ -89,23 +67,17 @@ fun ColorPreference( modifier = modifier, ) if (showDialog) { - val color = rememberSaveable(stateSaver = ColorSaver) { - mutableStateOf(initialColor) - } - AlertDialog( - title = dialogTitle ?: title, - content = { - // TODO ColorLayout - }, - confirmButton = confirmButton, - onConfirmClicked = { - showDialog = false - onColorSelected(color.value) - }, - dismissButton = dismissButton, - onDismissClicked = { + ColorPickerDialog( + title = dialogTitle, + confirmButton = stringResource(R.string.common_select), + dismissButton = stringResource(android.R.string.cancel), + alphaSlider = false, + initialColor = initialColor, + onColorSelected = { color -> showDialog = false + onColorSelected(color) }, + onDismissClicked = { showDialog = false }, onDismiss = { showDialog = false }, ) } diff --git a/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/preference/Preference.kt b/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/preference/Preference.kt index e02a6522f..2e93165b2 100644 --- a/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/preference/Preference.kt +++ b/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/preference/Preference.kt @@ -25,7 +25,7 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment @@ -57,7 +57,7 @@ fun Preference( ) { if (leadingContent != null) { leadingContent() - Spacer(modifier = Modifier.size(16.dp)) + Spacer(modifier = Modifier.width(16.dp)) } Column(modifier = Modifier.weight(1f)) { Text( @@ -86,7 +86,7 @@ fun Preference( } } if (trailingContent != null) { - Spacer(modifier = Modifier.size(16.dp)) + Spacer(modifier = Modifier.width(16.dp)) trailingContent() } } diff --git a/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/preference/PreferenceHeader.kt b/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/preference/PreferenceHeader.kt index 7113526b9..215f24062 100644 --- a/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/preference/PreferenceHeader.kt +++ b/common-ui/src/main/kotlin/com/blacksquircle/ui/ds/preference/PreferenceHeader.kt @@ -40,7 +40,10 @@ fun PreferenceHeader( modifier = modifier .fillMaxWidth() .clickable(onClick = onClick) - .padding(horizontal = 18.dp, vertical = 8.dp) + .padding( + horizontal = 24.dp, + vertical = 8.dp + ) ) { Text( text = title, diff --git a/common-ui/src/main/res/layout/dialog_color_picker.xml b/common-ui/src/main/res/layout/dialog_color_picker.xml deleted file mode 100644 index 3ab6b1bf5..000000000 --- a/common-ui/src/main/res/layout/dialog_color_picker.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/common-ui/src/main/res/values-de/strings.xml b/common-ui/src/main/res/values-de/strings.xml index 6053747c0..d48ae53e0 100644 --- a/common-ui/src/main/res/values-de/strings.xml +++ b/common-ui/src/main/res/values-de/strings.xml @@ -22,5 +22,7 @@ Speichern Löschen Continue + Auswählen + Farbauswahl \ No newline at end of file diff --git a/common-ui/src/main/res/values-en/strings.xml b/common-ui/src/main/res/values-en/strings.xml index 63b622e9c..b74dd5af7 100644 --- a/common-ui/src/main/res/values-en/strings.xml +++ b/common-ui/src/main/res/values-en/strings.xml @@ -20,4 +20,6 @@ Save Delete Continue + Select + Color Picker diff --git a/common-ui/src/main/res/values-fr/strings.xml b/common-ui/src/main/res/values-fr/strings.xml index 44d571a53..95cc28e30 100644 --- a/common-ui/src/main/res/values-fr/strings.xml +++ b/common-ui/src/main/res/values-fr/strings.xml @@ -20,4 +20,6 @@ Sauvegarde Supprimer Continuer + Sélectionner + Sélecteur de Couleurs diff --git a/common-ui/src/main/res/values-pt/strings.xml b/common-ui/src/main/res/values-pt/strings.xml index 8d5c10c06..3773a52fa 100644 --- a/common-ui/src/main/res/values-pt/strings.xml +++ b/common-ui/src/main/res/values-pt/strings.xml @@ -20,4 +20,6 @@ Salvar Deletar Continuar + Selecionar + Paleta de cores diff --git a/common-ui/src/main/res/values-ru/strings.xml b/common-ui/src/main/res/values-ru/strings.xml index b072bee11..6fd4667a8 100644 --- a/common-ui/src/main/res/values-ru/strings.xml +++ b/common-ui/src/main/res/values-ru/strings.xml @@ -20,4 +20,6 @@ Сохранить Удалить Продолжить + Выбрать + Выберите цвет diff --git a/common-ui/src/main/res/values-tr/strings.xml b/common-ui/src/main/res/values-tr/strings.xml index c7439e11d..a0045c68c 100644 --- a/common-ui/src/main/res/values-tr/strings.xml +++ b/common-ui/src/main/res/values-tr/strings.xml @@ -20,4 +20,5 @@ Kaydet Sil Devam et + Renk Seç diff --git a/common-ui/src/main/res/values-uk/strings.xml b/common-ui/src/main/res/values-uk/strings.xml index 120554927..e742ecf19 100644 --- a/common-ui/src/main/res/values-uk/strings.xml +++ b/common-ui/src/main/res/values-uk/strings.xml @@ -20,4 +20,6 @@ Зберегти Видалити Продовжити + Вибрати + Вибір кольору diff --git a/common-ui/src/main/res/values-zh-rTW/strings.xml b/common-ui/src/main/res/values-zh-rTW/strings.xml index 87c0cb693..977c97ecb 100644 --- a/common-ui/src/main/res/values-zh-rTW/strings.xml +++ b/common-ui/src/main/res/values-zh-rTW/strings.xml @@ -20,4 +20,6 @@ 儲存 刪除 繼續 + 選擇 + 顏色選擇器 diff --git a/common-ui/src/main/res/values-zh/strings.xml b/common-ui/src/main/res/values-zh/strings.xml index e3782c224..5f7355c37 100644 --- a/common-ui/src/main/res/values-zh/strings.xml +++ b/common-ui/src/main/res/values-zh/strings.xml @@ -20,4 +20,6 @@ 保存 删除 继续 + 选择 + 颜色选择器 diff --git a/common-ui/src/main/res/values/strings.xml b/common-ui/src/main/res/values/strings.xml index 72abce5cb..d0ae49a82 100644 --- a/common-ui/src/main/res/values/strings.xml +++ b/common-ui/src/main/res/values/strings.xml @@ -22,6 +22,7 @@ Save Delete Continue + Select untitled @@ -31,4 +32,6 @@ Space Tab + Color Picker + \ No newline at end of file diff --git a/feature-editor/impl/build.gradle.kts b/feature-editor/impl/build.gradle.kts index ea6a50a8d..f633325f3 100644 --- a/feature-editor/impl/build.gradle.kts +++ b/feature-editor/impl/build.gradle.kts @@ -16,6 +16,7 @@ plugins { id("com.blacksquircle.feature") + alias(libs.plugins.kotlin.compose) } android { @@ -23,6 +24,7 @@ android { buildFeatures { viewBinding = true + compose = true } } @@ -40,6 +42,14 @@ dependencies { implementation(libs.androidx.constraintlayout) implementation(libs.materialdesign) + // Compose + implementation(libs.compose.ui) + implementation(libs.compose.foundation) + implementation(libs.compose.material) + implementation(libs.compose.preview) + debugImplementation(libs.compose.tooling) + debugImplementation(libs.compose.manifest) + // AAC implementation(libs.androidx.viewmodel) implementation(libs.androidx.lifecycle) diff --git a/feature-editor/impl/src/main/kotlin/com/blacksquircle/ui/feature/editor/ui/dialog/InsertColorDialog.kt b/feature-editor/impl/src/main/kotlin/com/blacksquircle/ui/feature/editor/ui/dialog/InsertColorDialog.kt index eb31cc9e4..6739bb6a5 100644 --- a/feature-editor/impl/src/main/kotlin/com/blacksquircle/ui/feature/editor/ui/dialog/InsertColorDialog.kt +++ b/feature-editor/impl/src/main/kotlin/com/blacksquircle/ui/feature/editor/ui/dialog/InsertColorDialog.kt @@ -16,26 +16,50 @@ package com.blacksquircle.ui.feature.editor.ui.dialog -import android.graphics.Color +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.compose.ui.platform.ComposeView +import androidx.compose.ui.platform.ViewCompositionStrategy +import androidx.compose.ui.res.stringResource +import androidx.core.graphics.toColorInt +import androidx.fragment.app.DialogFragment import androidx.fragment.app.activityViewModels -import com.blacksquircle.ui.ds.colorpicker.ColorPickerDialog +import com.blacksquircle.ui.ds.dialog.ColorPickerDialog import com.blacksquircle.ui.ds.extensions.toHexString import com.blacksquircle.ui.feature.editor.R import com.blacksquircle.ui.feature.editor.ui.mvi.EditorIntent import com.blacksquircle.ui.feature.editor.ui.viewmodel.EditorViewModel import dagger.hilt.android.AndroidEntryPoint +import com.blacksquircle.ui.ds.R as UiR @AndroidEntryPoint -class InsertColorDialog : ColorPickerDialog() { - - override val titleRes = R.string.dialog_title_color_picker - override val positiveRes = R.string.action_insert - override val negativeRes = android.R.string.cancel - override val initialColor = Color.WHITE.toHexString() +class InsertColorDialog : DialogFragment() { private val viewModel by activityViewModels() - override fun onColorSelected(color: Int) { - viewModel.obtainEvent(EditorIntent.InsertColor(color)) + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + return ComposeView(requireContext()).apply { + setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) + setContent { + ColorPickerDialog( + title = stringResource(UiR.string.dialog_title_color_picker), + confirmButton = stringResource(R.string.action_insert), + dismissButton = stringResource(android.R.string.cancel), + onColorSelected = { color -> + val colorInt = color.toHexString().toColorInt() + viewModel.obtainEvent(EditorIntent.InsertColor(colorInt)) + dismiss() + }, + onDismissClicked = { dismiss() }, + onDismiss = { dismiss() }, + ) + } + } } } \ No newline at end of file diff --git a/feature-editor/impl/src/main/res/values-de/strings.xml b/feature-editor/impl/src/main/res/values-de/strings.xml index 864e83492..c2e999f9d 100644 --- a/feature-editor/impl/src/main/res/values-de/strings.xml +++ b/feature-editor/impl/src/main/res/values-de/strings.xml @@ -44,7 +44,6 @@ Tools Gehe zu Zeile… - Farbauswahl Syntax Highlighting Sind Sie sicher, dass Sie die Datei schließen wollen? Alle ungespeicherten Änderungen werden verworfen diff --git a/feature-editor/impl/src/main/res/values-en/strings.xml b/feature-editor/impl/src/main/res/values-en/strings.xml index 963d168a3..96e37bcb3 100644 --- a/feature-editor/impl/src/main/res/values-en/strings.xml +++ b/feature-editor/impl/src/main/res/values-en/strings.xml @@ -40,7 +40,6 @@ Settings Tools Go to Line… - Color Picker Syntax Highlighting Are you sure you want to close this file? All unsaved changes will be discarded No open files diff --git a/feature-editor/impl/src/main/res/values-fr/strings.xml b/feature-editor/impl/src/main/res/values-fr/strings.xml index 0b63000db..e8f3b38f6 100644 --- a/feature-editor/impl/src/main/res/values-fr/strings.xml +++ b/feature-editor/impl/src/main/res/values-fr/strings.xml @@ -44,7 +44,6 @@ Outils Aller à la ligne… - Sélecteur de Couleurs Syntax Highlighting Voulez-vous vraiment fermer ce fichier? Toutes les modifications non enregistrées seront supprimées diff --git a/feature-editor/impl/src/main/res/values-pt/strings.xml b/feature-editor/impl/src/main/res/values-pt/strings.xml index d4c30ebd4..619f5839a 100644 --- a/feature-editor/impl/src/main/res/values-pt/strings.xml +++ b/feature-editor/impl/src/main/res/values-pt/strings.xml @@ -44,7 +44,6 @@ Ferramentas Ir para a linha… - Paleta de cores Syntax Highlighting Você tem certeza de que quer fechar este arquivo? Todas as mudanças serão discartadas diff --git a/feature-editor/impl/src/main/res/values-ru/strings.xml b/feature-editor/impl/src/main/res/values-ru/strings.xml index 675386222..c4c71e881 100644 --- a/feature-editor/impl/src/main/res/values-ru/strings.xml +++ b/feature-editor/impl/src/main/res/values-ru/strings.xml @@ -40,7 +40,6 @@ Настройки Инструменты Перейти к строке… - Выберите цвет Подсветка синтаксиса Вы уверены что хотите закрыть этот файл? Все несохраненные изменения будут сброшены Нет файлов diff --git a/feature-editor/impl/src/main/res/values-tr/strings.xml b/feature-editor/impl/src/main/res/values-tr/strings.xml index 43d464399..2e371d1a7 100644 --- a/feature-editor/impl/src/main/res/values-tr/strings.xml +++ b/feature-editor/impl/src/main/res/values-tr/strings.xml @@ -40,7 +40,6 @@ Ayarlar Araçlar Satıra Git… - Renk Seç Sözdizimi\'ni Vurgula Oturumunuzu kapatmak istediğinize emin misiniz? Kaydedilmemiş değişiklikler kaybedilecek Dosya açılmadı diff --git a/feature-editor/impl/src/main/res/values-uk/strings.xml b/feature-editor/impl/src/main/res/values-uk/strings.xml index 2f44caed3..c9f29923e 100644 --- a/feature-editor/impl/src/main/res/values-uk/strings.xml +++ b/feature-editor/impl/src/main/res/values-uk/strings.xml @@ -40,7 +40,6 @@ Налаштування Інструменти Перейти до рядка… - Палітра кольорів Підсвічування синтаксису Ви впевнені, що хочете закрити цей файл? Усі незбережені зміни буде втрачено Немає відкритих файлів diff --git a/feature-editor/impl/src/main/res/values-zh-rTW/strings.xml b/feature-editor/impl/src/main/res/values-zh-rTW/strings.xml index 161ba7f94..6e2e6cb90 100644 --- a/feature-editor/impl/src/main/res/values-zh-rTW/strings.xml +++ b/feature-editor/impl/src/main/res/values-zh-rTW/strings.xml @@ -40,7 +40,6 @@ 設定 工具 跳到行 - 顏色選擇器 語法重點標示 確定要關閉該檔案嗎?所有未儲存的更改將會遺失 還沒有開啟任何檔案 diff --git a/feature-editor/impl/src/main/res/values-zh/strings.xml b/feature-editor/impl/src/main/res/values-zh/strings.xml index e03681511..57ca6f98c 100644 --- a/feature-editor/impl/src/main/res/values-zh/strings.xml +++ b/feature-editor/impl/src/main/res/values-zh/strings.xml @@ -40,7 +40,6 @@ 设置 工具 跳转到行 - 颜色选择器 语法高亮 确定要关闭该文件吗?所有未保存的更改将会丢失 还没有打开任何文件 diff --git a/feature-editor/impl/src/main/res/values/strings.xml b/feature-editor/impl/src/main/res/values/strings.xml index db50786d4..0cc6e789d 100644 --- a/feature-editor/impl/src/main/res/values/strings.xml +++ b/feature-editor/impl/src/main/res/values/strings.xml @@ -45,7 +45,6 @@ Tools Go to Line… - Color Picker Syntax Highlighting Are you sure you want to close this file? All unsaved changes will be discarded diff --git a/feature-fonts/impl/src/main/kotlin/com/blacksquircle/ui/feature/fonts/ui/composable/FontOverview.kt b/feature-fonts/impl/src/main/kotlin/com/blacksquircle/ui/feature/fonts/ui/composable/FontOverview.kt index 15a258ad7..2ff5b56ae 100644 --- a/feature-fonts/impl/src/main/kotlin/com/blacksquircle/ui/feature/fonts/ui/composable/FontOverview.kt +++ b/feature-fonts/impl/src/main/kotlin/com/blacksquircle/ui/feature/fonts/ui/composable/FontOverview.kt @@ -85,7 +85,7 @@ internal fun FontOverview( modifier = Modifier.padding(horizontal = 12.dp) ) OutlinedButton( - text = stringResource(R.string.action_select), + text = stringResource(UiR.string.common_select), onClick = onSelectClicked, modifier = Modifier .padding(8.dp) diff --git a/feature-fonts/impl/src/main/res/values-de/strings.xml b/feature-fonts/impl/src/main/res/values-de/strings.xml index 6c22f6579..37e57a78f 100644 --- a/feature-fonts/impl/src/main/res/values-de/strings.xml +++ b/feature-fonts/impl/src/main/res/values-de/strings.xml @@ -16,7 +16,6 @@ --> Schriftarten - Auswählen Ausgewählt «%1$s» Neue Schriftart verfügar Schriftart «%1$s» entfernt diff --git a/feature-fonts/impl/src/main/res/values-en/strings.xml b/feature-fonts/impl/src/main/res/values-en/strings.xml index 53eb9a579..d22f81937 100644 --- a/feature-fonts/impl/src/main/res/values-en/strings.xml +++ b/feature-fonts/impl/src/main/res/values-en/strings.xml @@ -16,7 +16,6 @@ --> Fonts - Select Selected «%1$s» New font available Font «%1$s» removed diff --git a/feature-fonts/impl/src/main/res/values-fr/strings.xml b/feature-fonts/impl/src/main/res/values-fr/strings.xml index 63e50f537..f8a65a410 100644 --- a/feature-fonts/impl/src/main/res/values-fr/strings.xml +++ b/feature-fonts/impl/src/main/res/values-fr/strings.xml @@ -16,7 +16,6 @@ --> Polices - sélectionner «%1$s» Sélectionnée Nouvelle police disponible Police «%1$s» supprimée diff --git a/feature-fonts/impl/src/main/res/values-pt/strings.xml b/feature-fonts/impl/src/main/res/values-pt/strings.xml index 12ab5a157..5abbcb3d9 100644 --- a/feature-fonts/impl/src/main/res/values-pt/strings.xml +++ b/feature-fonts/impl/src/main/res/values-pt/strings.xml @@ -16,7 +16,6 @@ --> Fontes - Selecionar «%1$s» selecionado Nova fonte disponível A fonte «%1$s» foi removida diff --git a/feature-fonts/impl/src/main/res/values-ru/strings.xml b/feature-fonts/impl/src/main/res/values-ru/strings.xml index d6ac3b148..e172b967d 100644 --- a/feature-fonts/impl/src/main/res/values-ru/strings.xml +++ b/feature-fonts/impl/src/main/res/values-ru/strings.xml @@ -16,7 +16,6 @@ --> Шрифты - Выбрать Выбран «%1$s» Добавлен новый шрифт Шрифт «%1$s» удален diff --git a/feature-fonts/impl/src/main/res/values-uk/strings.xml b/feature-fonts/impl/src/main/res/values-uk/strings.xml index ba3764e11..7fbc1afb0 100644 --- a/feature-fonts/impl/src/main/res/values-uk/strings.xml +++ b/feature-fonts/impl/src/main/res/values-uk/strings.xml @@ -16,7 +16,6 @@ --> Шрифти - Вибрати Вибрано «%1$s» Доступний новий шрифт Шрифт «%1$s» видалено diff --git a/feature-fonts/impl/src/main/res/values-zh-rTW/strings.xml b/feature-fonts/impl/src/main/res/values-zh-rTW/strings.xml index e47d24c38..d05118e6a 100644 --- a/feature-fonts/impl/src/main/res/values-zh-rTW/strings.xml +++ b/feature-fonts/impl/src/main/res/values-zh-rTW/strings.xml @@ -16,7 +16,6 @@ --> 字體 - 選擇 已選擇 «%1$s» 新字體可用 字體 «%1$s» 已移除 diff --git a/feature-fonts/impl/src/main/res/values-zh/strings.xml b/feature-fonts/impl/src/main/res/values-zh/strings.xml index 1d6c60329..34a071e39 100644 --- a/feature-fonts/impl/src/main/res/values-zh/strings.xml +++ b/feature-fonts/impl/src/main/res/values-zh/strings.xml @@ -16,7 +16,6 @@ --> 字体 - 选择 已选择 «%1$s» 新字体可用 字体 «%1$s» 已移除 diff --git a/feature-fonts/impl/src/main/res/values/strings.xml b/feature-fonts/impl/src/main/res/values/strings.xml index 70a6750ac..1ab23ed6f 100644 --- a/feature-fonts/impl/src/main/res/values/strings.xml +++ b/feature-fonts/impl/src/main/res/values/strings.xml @@ -19,8 +19,6 @@ Fonts - Select - Selected «%1$s» New font available Font «%1$s» removed diff --git a/feature-themes/impl/src/main/kotlin/com/blacksquircle/ui/feature/themes/data/mapper/ThemeMapper.kt b/feature-themes/impl/src/main/kotlin/com/blacksquircle/ui/feature/themes/data/mapper/ThemeMapper.kt index b352f89f9..918fd5271 100644 --- a/feature-themes/impl/src/main/kotlin/com/blacksquircle/ui/feature/themes/data/mapper/ThemeMapper.kt +++ b/feature-themes/impl/src/main/kotlin/com/blacksquircle/ui/feature/themes/data/mapper/ThemeMapper.kt @@ -27,7 +27,7 @@ import java.util.* internal object ThemeMapper { - const val FALLBACK_COLOR = "#000000" + const val FALLBACK_COLOR = "#FFFFFF" fun toModel(themeEntity: ThemeEntity): ThemeModel { return ThemeModel( diff --git a/feature-themes/impl/src/main/kotlin/com/blacksquircle/ui/feature/themes/ui/composable/ThemeOverview.kt b/feature-themes/impl/src/main/kotlin/com/blacksquircle/ui/feature/themes/ui/composable/ThemeOverview.kt index e40fbc5b4..a65fbd607 100644 --- a/feature-themes/impl/src/main/kotlin/com/blacksquircle/ui/feature/themes/ui/composable/ThemeOverview.kt +++ b/feature-themes/impl/src/main/kotlin/com/blacksquircle/ui/feature/themes/ui/composable/ThemeOverview.kt @@ -165,7 +165,7 @@ internal fun ThemeOverview( .padding(horizontal = 8.dp) ) OutlinedButton( - text = stringResource(R.string.action_select), + text = stringResource(UiR.string.common_select), onClick = onSelectClicked, ) } diff --git a/feature-themes/impl/src/main/kotlin/com/blacksquircle/ui/feature/themes/ui/fragment/EditThemeScreen.kt b/feature-themes/impl/src/main/kotlin/com/blacksquircle/ui/feature/themes/ui/fragment/EditThemeScreen.kt index e29c79cc9..f71cdca0e 100644 --- a/feature-themes/impl/src/main/kotlin/com/blacksquircle/ui/feature/themes/ui/fragment/EditThemeScreen.kt +++ b/feature-themes/impl/src/main/kotlin/com/blacksquircle/ui/feature/themes/ui/fragment/EditThemeScreen.kt @@ -44,6 +44,7 @@ import com.blacksquircle.ui.ds.SquircleTheme import com.blacksquircle.ui.ds.button.IconButton import com.blacksquircle.ui.ds.button.IconButtonSize import com.blacksquircle.ui.ds.button.OutlinedButton +import com.blacksquircle.ui.ds.extensions.toHexString import com.blacksquircle.ui.ds.preference.ColorPreference import com.blacksquircle.ui.ds.textfield.TextField import com.blacksquircle.ui.ds.toolbar.Toolbar @@ -63,7 +64,7 @@ internal fun EditThemeScreen(viewModel: EditThemeViewModel) { onThemeNameChanged = viewModel::onThemeNameChanged, onThemeAuthorChanged = viewModel::onThemeAuthorChanged, onSaveClicked = viewModel::onSaveClicked, - onColorChanged = viewModel::onColorChanged, + onColorSelected = viewModel::onColorSelected, ) } @@ -75,7 +76,7 @@ private fun EditThemeScreen( onThemeNameChanged: (String) -> Unit, onThemeAuthorChanged: (String) -> Unit, onSaveClicked: () -> Unit, - onColorChanged: (Property, String) -> Unit, + onColorSelected: (Property, String) -> Unit, ) { Scaffold( topBar = { @@ -142,11 +143,8 @@ private fun EditThemeScreen( subtitle = propertyResource(propertyItem.propertyKey), initialColor = Color(propertyItem.propertyValue.toColorInt()), onColorSelected = { color -> - // TODO onColorSelected(propertyItem, color) + onColorSelected(propertyItem.propertyKey, color.toHexString()) }, - dialogTitle = stringResource(R.string.dialog_title_color_picker), - confirmButton = null, - dismissButton = null, ) } } @@ -198,7 +196,7 @@ private fun EditThemeScreenPreview() { onThemeNameChanged = {}, onThemeAuthorChanged = {}, onSaveClicked = {}, - onColorChanged = { _, _ -> }, + onColorSelected = { _, _ -> }, ) } } \ No newline at end of file diff --git a/feature-themes/impl/src/main/kotlin/com/blacksquircle/ui/feature/themes/ui/viewmodel/EditThemeViewModel.kt b/feature-themes/impl/src/main/kotlin/com/blacksquircle/ui/feature/themes/ui/viewmodel/EditThemeViewModel.kt index 1adbd3bb4..029710a5a 100644 --- a/feature-themes/impl/src/main/kotlin/com/blacksquircle/ui/feature/themes/ui/viewmodel/EditThemeViewModel.kt +++ b/feature-themes/impl/src/main/kotlin/com/blacksquircle/ui/feature/themes/ui/viewmodel/EditThemeViewModel.kt @@ -171,7 +171,7 @@ internal class EditThemeViewModel @AssistedInject constructor( } } - fun onColorChanged(property: Property, color: String) { + fun onColorSelected(property: Property, color: String) { _viewState.update { it.copy( properties = it.properties.map { propertyItem -> diff --git a/feature-themes/impl/src/main/res/values-de/strings.xml b/feature-themes/impl/src/main/res/values-de/strings.xml index 1d6ddd81e..31d099bcc 100644 --- a/feature-themes/impl/src/main/res/values-de/strings.xml +++ b/feature-themes/impl/src/main/res/values-de/strings.xml @@ -23,14 +23,11 @@ Geben Sie einen Theme-Namen ein Geben Sie einen Theme-Autor ein - Auswählen Importieren Exportieren Bearbeiten Entfernen - Farbauswahl - Gespeichert «%1$s» ausgewählt Neues Thema verfügbar: %1$s diff --git a/feature-themes/impl/src/main/res/values-en/strings.xml b/feature-themes/impl/src/main/res/values-en/strings.xml index 0954b9230..390d4ad18 100644 --- a/feature-themes/impl/src/main/res/values-en/strings.xml +++ b/feature-themes/impl/src/main/res/values-en/strings.xml @@ -19,12 +19,10 @@ New Theme Enter theme name Enter theme author - Select Import Export Edit Remove - Color Picker Saved Selected «%1$s» New theme available: %1$s diff --git a/feature-themes/impl/src/main/res/values-fr/strings.xml b/feature-themes/impl/src/main/res/values-fr/strings.xml index 9491c9554..78273fa91 100644 --- a/feature-themes/impl/src/main/res/values-fr/strings.xml +++ b/feature-themes/impl/src/main/res/values-fr/strings.xml @@ -23,14 +23,11 @@ Entrer le nom du thème Entrer l\'auteur du thème - Sélectionner Importer Exporter Éditer Retirer - Sélecteur de Couleurs - Sauvegardé «%1$s» sélectionné Nouveau thème disponible: %1$s diff --git a/feature-themes/impl/src/main/res/values-pt/strings.xml b/feature-themes/impl/src/main/res/values-pt/strings.xml index 0db4aa6d0..422b4488c 100644 --- a/feature-themes/impl/src/main/res/values-pt/strings.xml +++ b/feature-themes/impl/src/main/res/values-pt/strings.xml @@ -23,14 +23,11 @@ Insira o nome do tema Insira o nome do autor do tema - Selecionar Importar Exportar Editar Remover - Paleta de cores - Salvo «%1$s» selecionado Nova tema disponível: %1$s diff --git a/feature-themes/impl/src/main/res/values-ru/strings.xml b/feature-themes/impl/src/main/res/values-ru/strings.xml index c45dc41f2..4e1dd0ba8 100644 --- a/feature-themes/impl/src/main/res/values-ru/strings.xml +++ b/feature-themes/impl/src/main/res/values-ru/strings.xml @@ -19,12 +19,10 @@ Новая тема Название темы Автор темы - Выбрать Импорт Экспорт Изменить Удалить - Выберите цвет Сохранено Выбран «%1$s» Добавлена новая тема: %1$s diff --git a/feature-themes/impl/src/main/res/values-uk/strings.xml b/feature-themes/impl/src/main/res/values-uk/strings.xml index ae7b5d4a8..7dcf217c1 100644 --- a/feature-themes/impl/src/main/res/values-uk/strings.xml +++ b/feature-themes/impl/src/main/res/values-uk/strings.xml @@ -19,12 +19,10 @@ Нова тема Введіть назву теми Введіть автора теми - Вибрати Імпорт Експорт Редагувати Видалити - Вибір кольору Збережено Вибрано «%1$s» Доступна нова тема: %1$s diff --git a/feature-themes/impl/src/main/res/values-zh-rTW/strings.xml b/feature-themes/impl/src/main/res/values-zh-rTW/strings.xml index 4fae0d29a..80a513740 100644 --- a/feature-themes/impl/src/main/res/values-zh-rTW/strings.xml +++ b/feature-themes/impl/src/main/res/values-zh-rTW/strings.xml @@ -19,12 +19,10 @@ 新增主題 輸入主題名稱 輸入主題作者 - 選擇 匯入 匯出 編輯 移除 - 顏色選擇器 已儲存 已選擇 «%1$s» 新主題可用: %1$s diff --git a/feature-themes/impl/src/main/res/values-zh/strings.xml b/feature-themes/impl/src/main/res/values-zh/strings.xml index 28e593708..fabff003c 100644 --- a/feature-themes/impl/src/main/res/values-zh/strings.xml +++ b/feature-themes/impl/src/main/res/values-zh/strings.xml @@ -19,12 +19,10 @@ 新建主题 输入主题名称 输入主题作者 - 选择 导入 导出 编辑 移除 - 颜色选择器 已保存 已选择 «%1$s» 新主题可用: %1$s diff --git a/feature-themes/impl/src/main/res/values/strings.xml b/feature-themes/impl/src/main/res/values/strings.xml index 738474b7e..82d1504e3 100644 --- a/feature-themes/impl/src/main/res/values/strings.xml +++ b/feature-themes/impl/src/main/res/values/strings.xml @@ -25,14 +25,11 @@ Darcula Squircle CE - Select Import Export Edit Remove - Color Picker - Saved Selected «%1$s» New theme available: %1$s diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c0933dbdc..7b7db3e7d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,7 +15,7 @@ material = "1.12.0" compose = "1.7.7" constraintlayout = "2.2.0" swiperefreshlayout = "1.2.0-alpha01" -colorpicker = "2.3.0" +colorpicker = "1.1.2" recyclerview-selection = "1.1.0" vectordrawable = "1.2.0" lifecycle = "2.8.7" @@ -58,7 +58,7 @@ plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version. kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" } materialdesign = { module = "com.google.android.material:material", version.ref = "material" } -colorpicker = { module = "com.github.skydoves:colorpickerview", version.ref = "colorpicker" } +colorpicker = { module = "com.github.skydoves:colorpicker-compose", version.ref = "colorpicker" } timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" } appupdate = { module = "com.google.android.play:app-update-ktx", version.ref = "appupdate" } superuser = { module = "com.github.topjohnwu.libsu:io", version.ref = "superuser" }