From ffbee9ec6eb7dd152134444654618c0d9c98a3de Mon Sep 17 00:00:00 2001 From: T8RIN Date: Wed, 16 Aug 2023 10:56:49 +0300 Subject: [PATCH] color picker sheet added and creash fix --- app/build.gradle.kts | 4 +- .../presentation/draw_screen/DrawScreen.kt | 172 ++-------------- .../components/ColorPickerSheet.kt | 183 ++++++++++++++++++ .../components/DrawBackgroundSelector.kt | 4 +- .../components/DrawColorSelector.kt | 4 +- .../draw_screen/components/DrawHost.kt | 10 +- .../components/OpenColorPickerCard.kt | 31 +++ .../components/ColorPickerDialog.kt | 8 +- 8 files changed, 250 insertions(+), 166 deletions(-) create mode 100644 app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/ColorPickerSheet.kt create mode 100644 app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/OpenColorPickerCard.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 87be9083d8..d6e5f6230c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -18,8 +18,8 @@ android { applicationId = "ru.tech.imageresizershrinker" minSdk = 21 targetSdk = 34 - versionCode = 78 - versionName = "2.2.2-beta02" + versionCode = 80 + versionName = "2.2.2-beta03" resourceConfigurations += setOf( "en", "ar", diff --git a/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/DrawScreen.kt b/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/DrawScreen.kt index 4132fbd871..deb6824366 100644 --- a/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/DrawScreen.kt +++ b/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/DrawScreen.kt @@ -11,9 +11,6 @@ import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.animation.togetherWith import androidx.compose.foundation.BorderStroke -import androidx.compose.foundation.background -import androidx.compose.foundation.border -import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues @@ -28,18 +25,14 @@ import androidx.compose.foundation.layout.navigationBars import androidx.compose.foundation.layout.navigationBarsPadding import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.statusBarsPadding import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Delete import androidx.compose.material.icons.outlined.Share import androidx.compose.material.icons.rounded.AddPhotoAlternate import androidx.compose.material.icons.rounded.ArrowBack import androidx.compose.material.icons.rounded.Build -import androidx.compose.material.icons.rounded.Colorize -import androidx.compose.material.icons.rounded.ContentPaste import androidx.compose.material.icons.rounded.Draw import androidx.compose.material.icons.rounded.Redo import androidx.compose.material.icons.rounded.Save @@ -47,7 +40,6 @@ import androidx.compose.material.icons.rounded.Undo import androidx.compose.material.icons.rounded.ZoomIn import androidx.compose.material3.BottomAppBar import androidx.compose.material3.BottomSheetScaffold -import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.FloatingActionButtonDefaults @@ -56,9 +48,7 @@ import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.IconButtonDefaults import androidx.compose.material3.LargeTopAppBar -import androidx.compose.material3.LocalTextStyle import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.OutlinedButton import androidx.compose.material3.OutlinedIconButton import androidx.compose.material3.SheetValue import androidx.compose.material3.Switch @@ -81,61 +71,48 @@ 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.graphics.RectangleShape -import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.max -import androidx.compose.ui.zIndex -import com.smarttoolfactory.colordetector.ImageColorDetector import com.t8rin.dynamic.theme.LocalDynamicThemeState import com.t8rin.dynamic.theme.getAppColorTuple import com.t8rin.dynamic.theme.observeAsState import dev.olshevski.navigation.reimagined.hilt.hiltViewModel -import dev.olshevski.navigation.reimagined.navigate -import dev.olshevski.navigation.reimagined.pop import kotlinx.coroutines.launch import ru.tech.imageresizershrinker.R +import ru.tech.imageresizershrinker.presentation.draw_screen.components.ColorPickerSheet import ru.tech.imageresizershrinker.presentation.draw_screen.components.DrawAlphaSelector import ru.tech.imageresizershrinker.presentation.draw_screen.components.DrawBackgroundSelector import ru.tech.imageresizershrinker.presentation.draw_screen.components.DrawBehavior import ru.tech.imageresizershrinker.presentation.draw_screen.components.DrawColorSelector import ru.tech.imageresizershrinker.presentation.draw_screen.components.DrawHost import ru.tech.imageresizershrinker.presentation.draw_screen.components.LineWidthSelector +import ru.tech.imageresizershrinker.presentation.draw_screen.components.OpenColorPickerCard import ru.tech.imageresizershrinker.presentation.draw_screen.viewModel.DrawViewModel -import ru.tech.imageresizershrinker.presentation.pick_color_from_image_screen.copyColorIntoClipboard -import ru.tech.imageresizershrinker.presentation.pick_color_from_image_screen.format import ru.tech.imageresizershrinker.presentation.root.theme.icons.Eraser -import ru.tech.imageresizershrinker.presentation.root.theme.icons.PaletteSwatch import ru.tech.imageresizershrinker.presentation.root.theme.mixedColor import ru.tech.imageresizershrinker.presentation.root.theme.onMixedColor -import ru.tech.imageresizershrinker.presentation.root.theme.outlineVariant import ru.tech.imageresizershrinker.presentation.root.transformation.filter.SaturationFilter import ru.tech.imageresizershrinker.presentation.root.utils.confetti.LocalConfettiController import ru.tech.imageresizershrinker.presentation.root.utils.helper.Picker import ru.tech.imageresizershrinker.presentation.root.utils.helper.localImagePickerMode import ru.tech.imageresizershrinker.presentation.root.utils.helper.parseSaveResult import ru.tech.imageresizershrinker.presentation.root.utils.helper.rememberImagePicker -import ru.tech.imageresizershrinker.presentation.root.utils.modifier.block import ru.tech.imageresizershrinker.presentation.root.utils.modifier.drawHorizontalStroke import ru.tech.imageresizershrinker.presentation.root.utils.modifier.fabBorder -import ru.tech.imageresizershrinker.presentation.root.utils.navigation.Screen import ru.tech.imageresizershrinker.presentation.root.widget.controls.ExtensionGroup import ru.tech.imageresizershrinker.presentation.root.widget.dialogs.ExitWithoutSavingDialog import ru.tech.imageresizershrinker.presentation.root.widget.other.LoadingDialog import ru.tech.imageresizershrinker.presentation.root.widget.other.LocalToastHost import ru.tech.imageresizershrinker.presentation.root.widget.other.LockScreenOrientation import ru.tech.imageresizershrinker.presentation.root.widget.other.TopAppBarEmoji -import ru.tech.imageresizershrinker.presentation.root.widget.sheets.SimpleSheet import ru.tech.imageresizershrinker.presentation.root.widget.text.Marquee -import ru.tech.imageresizershrinker.presentation.root.widget.text.TitleItem import ru.tech.imageresizershrinker.presentation.root.widget.utils.LocalSettingsState import ru.tech.imageresizershrinker.presentation.root.widget.utils.LocalWindowSizeClass @@ -238,6 +215,8 @@ fun DrawScreen( } }.value + val showPickColorSheet = rememberSaveable { mutableStateOf(false) } + val scaffoldState = rememberBottomSheetScaffoldState( bottomSheetState = rememberStandardBottomSheetState( confirmValueChange = { @@ -379,13 +358,16 @@ fun DrawScreen( uri = viewModel.uri, onPickImage = pickImage, switch = switch, - startDrawOnBackground = viewModel::startDrawOnBackground + startDrawOnBackground = viewModel::startDrawOnBackground, + onOpenColorPicker = { + viewModel.openColorPicker() + showPickColorSheet.value = true + } ) } } } - val showPickColorSheet = rememberSaveable { mutableStateOf(false) } AnimatedContent( targetState = portrait && viewModel.drawBehavior !is DrawBehavior.None, @@ -469,11 +451,12 @@ fun DrawScreen( viewModel.drawController?.let { drawController -> LazyColumn { item { - IconButton( - onClick = { viewModel.openColorPicker() } - ) { - Icon(Icons.Rounded.Colorize, null) - } + OpenColorPickerCard( + onOpen = { + viewModel.openColorPicker() + showPickColorSheet.value = true + } + ) if (viewModel.drawBehavior is DrawBehavior.Background) { DrawBackgroundSelector(drawController) } else { @@ -508,126 +491,11 @@ fun DrawScreen( LoadingDialog() } - LaunchedEffect(viewModel.colorPickerBitmap) { - showPickColorSheet.value = viewModel.colorPickerBitmap != null - } - - SimpleSheet( - sheetContent = { - Box { - remember(viewModel.colorPickerBitmap) { viewModel.colorPickerBitmap?.asImageBitmap() }?.let { - ImageColorDetector( - color = viewModel.color, - imageBitmap = it, - onColorChange = viewModel::updateColor, - modifier = Modifier - .padding(16.dp) - .align(Alignment.Center) - .block(resultPadding = 8.dp) - .clip(RoundedCornerShape(12.dp)) - ) - } - HorizontalDivider( - Modifier - .zIndex(100f) - .align(Alignment.BottomCenter) - ) - HorizontalDivider() - } - }, - confirmButton = { - OutlinedButton( - onClick = { - showPickColorSheet.value = false - }, - colors = ButtonDefaults.buttonColors( - containerColor = MaterialTheme.colorScheme.primary, - contentColor = MaterialTheme.colorScheme.onPrimary - ), - border = BorderStroke( - settingsState.borderWidth, - MaterialTheme.colorScheme.outlineVariant(onTopOf = MaterialTheme.colorScheme.primary) - ) - ) { - Text(stringResource(R.string.close)) - } - }, - title = { - val color = viewModel.color - Row( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier - .padding( - start = 16.dp, - end = 16.dp - ) - ) { - Box( - Modifier - .padding(end = 16.dp) - .background( - color = animateColorAsState(color).value, - shape = RoundedCornerShape(12.dp) - ) - .size(40.dp) - .border( - width = settingsState.borderWidth, - color = MaterialTheme.colorScheme.outlineVariant( - onTopOf = animateColorAsState(color).value - ), - shape = RoundedCornerShape(11.dp) - ) - .clip(RoundedCornerShape(12.dp)) - .clickable { - context.copyColorIntoClipboard( - context.getString(R.string.color), - color.format() - ) - scope.launch { - toastHostState.showToast( - icon = Icons.Rounded.ContentPaste, - message = context.getString(R.string.color_copied) - ) - } - } - ) - - Text(stringResource(R.string.color)) - - Text( - modifier = Modifier - .padding(horizontal = 8.dp) - .clip(RoundedCornerShape(8.dp)) - .clickable { - context.copyColorIntoClipboard( - context.getString(R.string.color), - color.format() - ) - scope.launch { - toastHostState.showToast( - icon = Icons.Rounded.ContentPaste, - message = context.getString(R.string.color_copied) - ) - } - } - .background(MaterialTheme.colorScheme.secondaryContainer) - .border( - settingsState.borderWidth, - MaterialTheme.colorScheme.outlineVariant( - onTopOf = MaterialTheme.colorScheme.secondaryContainer - ), - RoundedCornerShape(8.dp) - ) - .padding(horizontal = 6.dp), - text = color.format(), - style = LocalTextStyle.current.copy( - fontWeight = FontWeight.Bold, - color = MaterialTheme.colorScheme.onSecondaryContainer - ) - ) - } - }, - visible = showPickColorSheet + ColorPickerSheet( + visible = showPickColorSheet, + bitmap = viewModel.colorPickerBitmap, + onColorChange = viewModel::updateColor, + color = viewModel.color ) ExitWithoutSavingDialog( diff --git a/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/ColorPickerSheet.kt b/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/ColorPickerSheet.kt new file mode 100644 index 0000000000..650ad29508 --- /dev/null +++ b/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/ColorPickerSheet.kt @@ -0,0 +1,183 @@ +package ru.tech.imageresizershrinker.presentation.draw_screen.components + +import android.graphics.Bitmap +import androidx.compose.animation.animateColorAsState +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.ContentPaste +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.LocalTextStyle +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedButton +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.MutableState +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope +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.graphics.asImageBitmap +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import androidx.compose.ui.zIndex +import com.smarttoolfactory.colordetector.ImageColorDetector +import kotlinx.coroutines.launch +import ru.tech.imageresizershrinker.R +import ru.tech.imageresizershrinker.presentation.pick_color_from_image_screen.copyColorIntoClipboard +import ru.tech.imageresizershrinker.presentation.pick_color_from_image_screen.format +import ru.tech.imageresizershrinker.presentation.root.theme.outlineVariant +import ru.tech.imageresizershrinker.presentation.root.utils.modifier.block +import ru.tech.imageresizershrinker.presentation.root.utils.modifier.shimmer +import ru.tech.imageresizershrinker.presentation.root.widget.other.LocalToastHost +import ru.tech.imageresizershrinker.presentation.root.widget.sheets.SimpleSheet +import ru.tech.imageresizershrinker.presentation.root.widget.text.AutoSizeText +import ru.tech.imageresizershrinker.presentation.root.widget.utils.LocalSettingsState + +@Composable +fun ColorPickerSheet( + visible: MutableState, + bitmap: Bitmap?, + onColorChange: (Color) -> Unit, + color: Color +) { + val context = LocalContext.current + val settingsState = LocalSettingsState.current + val scope = rememberCoroutineScope() + val toastHostState = LocalToastHost.current + + SimpleSheet( + sheetContent = { + Box { + remember(bitmap) { bitmap?.asImageBitmap() }?.let { + ImageColorDetector( + color = color, + imageBitmap = it, + onColorChange = onColorChange, + modifier = Modifier + .padding(16.dp) + .align(Alignment.Center) + .block(resultPadding = 8.dp) + .clip(RoundedCornerShape(12.dp)) + ) + } ?: Box( + Modifier + .padding(16.dp) + .align(Alignment.Center) + .block(resultPadding = 8.dp) + .clip(RoundedCornerShape(12.dp)) + .fillMaxSize() + .shimmer(true) + ) + HorizontalDivider( + Modifier + .zIndex(100f) + .align(Alignment.BottomCenter) + ) + HorizontalDivider() + } + }, + confirmButton = { + OutlinedButton( + onClick = { + visible.value = false + }, + colors = ButtonDefaults.buttonColors( + containerColor = MaterialTheme.colorScheme.primary, + contentColor = MaterialTheme.colorScheme.onPrimary + ), + border = BorderStroke( + settingsState.borderWidth, + MaterialTheme.colorScheme.outlineVariant(onTopOf = MaterialTheme.colorScheme.primary) + ) + ) { + AutoSizeText(stringResource(R.string.close)) + } + }, + title = { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier + .padding( + start = 16.dp, + end = 16.dp + ) + ) { + Box( + Modifier + .padding(end = 16.dp) + .background( + color = animateColorAsState(color).value, + shape = RoundedCornerShape(12.dp) + ) + .size(40.dp) + .border( + width = settingsState.borderWidth, + color = MaterialTheme.colorScheme.outlineVariant( + onTopOf = animateColorAsState(color).value + ), + shape = RoundedCornerShape(11.dp) + ) + .clip(RoundedCornerShape(12.dp)) + .clickable { + context.copyColorIntoClipboard( + context.getString(R.string.color), + color.format() + ) + scope.launch { + toastHostState.showToast( + icon = Icons.Rounded.ContentPaste, + message = context.getString(R.string.color_copied) + ) + } + } + ) + + Text( + modifier = Modifier + .padding(horizontal = 8.dp) + .clip(RoundedCornerShape(8.dp)) + .clickable { + context.copyColorIntoClipboard( + context.getString(R.string.color), + color.format() + ) + scope.launch { + toastHostState.showToast( + icon = Icons.Rounded.ContentPaste, + message = context.getString(R.string.color_copied) + ) + } + } + .background(MaterialTheme.colorScheme.secondaryContainer) + .border( + settingsState.borderWidth, + MaterialTheme.colorScheme.outlineVariant( + onTopOf = MaterialTheme.colorScheme.secondaryContainer + ), + RoundedCornerShape(8.dp) + ), + text = color.format(), + style = LocalTextStyle.current.copy( + fontWeight = FontWeight.Bold, + color = MaterialTheme.colorScheme.onSecondaryContainer + ) + ) + } + }, + visible = visible + ) +} \ No newline at end of file diff --git a/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/DrawBackgroundSelector.kt b/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/DrawBackgroundSelector.kt index b5cc99271b..c4b9e898ff 100644 --- a/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/DrawBackgroundSelector.kt +++ b/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/DrawBackgroundSelector.kt @@ -21,8 +21,8 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.rounded.Colorize import androidx.compose.material.icons.rounded.Draw +import androidx.compose.material.icons.rounded.Palette import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon @@ -116,7 +116,7 @@ fun DrawBackgroundSelector(drawController: DrawController) { contentAlignment = Alignment.Center ) { Icon( - imageVector = Icons.Rounded.Colorize, + imageVector = Icons.Rounded.Palette, contentDescription = null, tint = (customColor ?: MaterialTheme.colorScheme.primary).inverse( fraction = { diff --git a/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/DrawColorSelector.kt b/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/DrawColorSelector.kt index c37eb33f7c..8b8d5b462c 100644 --- a/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/DrawColorSelector.kt +++ b/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/DrawColorSelector.kt @@ -21,8 +21,8 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.rounded.Colorize import androidx.compose.material.icons.rounded.Draw +import androidx.compose.material.icons.rounded.Palette import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon @@ -113,7 +113,7 @@ fun DrawColorSelector(drawController: DrawController) { contentAlignment = Alignment.Center ) { Icon( - imageVector = Icons.Rounded.Colorize, + imageVector = Icons.Rounded.Palette, contentDescription = null, tint = (customColor ?: MaterialTheme.colorScheme.primary).inverse( fraction = { diff --git a/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/DrawHost.kt b/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/DrawHost.kt index 121db1b9de..eca0ce6053 100644 --- a/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/DrawHost.kt +++ b/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/DrawHost.kt @@ -116,7 +116,8 @@ fun DrawHost( uri: Uri, onPickImage: () -> Unit, switch: @Composable () -> Unit, - startDrawOnBackground: (Int, Int, Color) -> Unit + startDrawOnBackground: (Int, Int, Color) -> Unit, + onOpenColorPicker: () -> Unit ) { val showBackgroundDrawingSetup = rememberSaveable { mutableStateOf(false) } val settingsState = LocalSettingsState.current @@ -204,7 +205,7 @@ fun DrawHost( top = if (drawBehavior is DrawBehavior.None) 20.dp else 0.dp, ), modifier = Modifier - .weight(0.5f) + .weight(0.7f) .clipToBounds() ) { item { @@ -253,6 +254,8 @@ fun DrawHost( Icon(Icons.Rounded.Eraser, null) } } + OpenColorPickerCard(onOpen = onOpenColorPicker) + Spacer(Modifier.height(16.dp)) DrawBackgroundSelector(drawController) DrawColorSelector(drawController) DrawAlphaSelector(drawController) @@ -366,7 +369,7 @@ fun DrawHost( top = if (drawBehavior is DrawBehavior.None) 20.dp else 0.dp, ), modifier = Modifier - .weight(0.5f) + .weight(0.7f) .clipToBounds() ) { item { @@ -415,6 +418,7 @@ fun DrawHost( Icon(Icons.Rounded.Eraser, null) } } + OpenColorPickerCard(onOpen = onOpenColorPicker) Spacer(Modifier.height(16.dp)) DrawColorSelector(drawController) DrawAlphaSelector(drawController) diff --git a/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/OpenColorPickerCard.kt b/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/OpenColorPickerCard.kt new file mode 100644 index 0000000000..6e8e8d5826 --- /dev/null +++ b/app/src/main/java/ru/tech/imageresizershrinker/presentation/draw_screen/components/OpenColorPickerCard.kt @@ -0,0 +1,31 @@ +package ru.tech.imageresizershrinker.presentation.draw_screen.components + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.Colorize +import androidx.compose.material3.Icon +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import ru.tech.imageresizershrinker.R +import ru.tech.imageresizershrinker.presentation.root.utils.modifier.block + +@Composable +fun OpenColorPickerCard( + onOpen: () -> Unit +) { + Row( + Modifier + .padding(start = 16.dp, end = 16.dp, top = 16.dp) + .block(applyResultPadding = false) + .clickable { onOpen() } + .padding(16.dp) + ) { + Text(stringResource(id = R.string.pick_color), modifier = Modifier.weight(1f)) + Icon(Icons.Rounded.Colorize, null) + } +} \ No newline at end of file diff --git a/app/src/main/java/ru/tech/imageresizershrinker/presentation/main_screen/components/ColorPickerDialog.kt b/app/src/main/java/ru/tech/imageresizershrinker/presentation/main_screen/components/ColorPickerDialog.kt index adb72a4c87..0eba275235 100644 --- a/app/src/main/java/ru/tech/imageresizershrinker/presentation/main_screen/components/ColorPickerDialog.kt +++ b/app/src/main/java/ru/tech/imageresizershrinker/presentation/main_screen/components/ColorPickerDialog.kt @@ -39,8 +39,6 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Delete import androidx.compose.material.icons.outlined.Palette -import androidx.compose.material.icons.outlined.Shuffle -import androidx.compose.material.icons.outlined.ShuffleOn import androidx.compose.material.icons.rounded.AddCircleOutline import androidx.compose.material.icons.rounded.ContentCopy import androidx.compose.material.icons.rounded.ContentPaste @@ -125,18 +123,18 @@ fun ColorPickerDialog( var primary by rememberSaveable(colorTuple) { mutableIntStateOf(colorTuple.primary.toArgb()) } var secondary by rememberSaveable(colorTuple) { mutableIntStateOf( - colorTuple.secondary?.toArgb()!! + colorTuple.secondary?.toArgb() ?: colorTuple.primary.calculateSecondaryColor() ) } var tertiary by rememberSaveable(colorTuple) { mutableIntStateOf( - colorTuple.tertiary?.toArgb()!! + colorTuple.tertiary?.toArgb() ?: colorTuple.primary.calculateTertiaryColor() ) } var surface by rememberSaveable(colorTuple) { mutableIntStateOf( - colorTuple.surface?.toArgb()!! + colorTuple.surface?.toArgb() ?: colorTuple.primary.calculateSurfaceColor() ) }