Skip to content

Commit

Permalink
Code refactor and break down
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Jan 9, 2025
1 parent 44f6aff commit 015eeac
Show file tree
Hide file tree
Showing 20 changed files with 803 additions and 529 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,19 @@ sealed class ImageFormat(
canChangeCompressionValue = false
)

companion object {
sealed class CompressionType(
open val compressionRange: IntRange = 0..100
) {
data class Quality(
override val compressionRange: IntRange = 0..100
) : CompressionType(compressionRange)

data class Effort(
override val compressionRange: IntRange = 0..100
) : CompressionType(compressionRange)
}
sealed class CompressionType(
open val compressionRange: IntRange = 0..100
) {
data class Quality(
override val compressionRange: IntRange = 0..100
) : CompressionType(compressionRange)

data class Effort(
override val compressionRange: IntRange = 0..100
) : CompressionType(compressionRange)
}

companion object {
val Default: ImageFormat by lazy { Jpg }

operator fun get(typeString: String?): ImageFormat = when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class AddFiltersSheetComponent @AssistedInject internal constructor(
val previewBitmap by _previewBitmap

private val _cubeLutRemoteResources: MutableState<RemoteResources> =
mutableStateOf(RemoteResources.Companion.CubeLutDefault)
mutableStateOf(RemoteResources.CubeLutDefault)
val cubeLutRemoteResources by _cubeLutRemoteResources

private val _cubeLutDownloadProgress: MutableState<RemoteResourcesDownloadProgress?> =
Expand Down Expand Up @@ -122,7 +122,7 @@ class AddFiltersSheetComponent @AssistedInject internal constructor(
) {
componentScope.launch {
remoteResourcesStore.getResources(
name = RemoteResources.Companion.CUBE_LUT,
name = RemoteResources.CUBE_LUT,
forceUpdate = forceUpdate,
onDownloadRequest = { name ->
if (startDownloadIfNeeded) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ fun ImageReorderCarousel(
.width(12.dp)
.height(edgeHeight)
.background(
brush = Brush.Companion.horizontalGradient(
brush = Brush.horizontalGradient(
0f to MaterialTheme
.colorScheme
.surfaceContainerLow,
Expand All @@ -331,7 +331,7 @@ fun ImageReorderCarousel(
.width(12.dp)
.height(edgeHeight)
.background(
brush = Brush.Companion.horizontalGradient(
brush = Brush.horizontalGradient(
0f to Color.Transparent,
1f to MaterialTheme
.colorScheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ fun QualitySelector(
}
}

val isQuality = type is ImageFormat.Companion.CompressionType.Quality
val isEffort = type is ImageFormat.Companion.CompressionType.Effort
val isQuality = type is ImageFormat.CompressionType.Quality
val isEffort = type is ImageFormat.CompressionType.Effort

val compressingLiteral = if (isQuality) "%" else ""

EnhancedSliderItem(
value = when (type) {
is ImageFormat.Companion.CompressionType.Effort -> {
is ImageFormat.CompressionType.Effort -> {
when (quality) {
is Quality.Base -> quality.qualityValue
is Quality.Jxl -> quality.effort
Expand All @@ -134,7 +134,7 @@ fun QualitySelector(
}
}

is ImageFormat.Companion.CompressionType.Quality -> quality.qualityValue
is ImageFormat.CompressionType.Quality -> quality.qualityValue
},
title = if (isQuality) {
stringResource(R.string.quality)
Expand All @@ -147,7 +147,7 @@ fun QualitySelector(
},
onValueChange = {
when (type) {
is ImageFormat.Companion.CompressionType.Effort -> {
is ImageFormat.CompressionType.Effort -> {
onQualityChange(
when (quality) {
is Quality.Base -> quality.copy(qualityValue = it.toInt())
Expand All @@ -160,7 +160,7 @@ fun QualitySelector(
)
}

is ImageFormat.Companion.CompressionType.Quality -> {
is ImageFormat.CompressionType.Quality -> {
onQualityChange(
when (quality) {
is Quality.Base -> quality.copy(qualityValue = it.toInt())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ internal fun ColorHarmonies(
contentDescription = stringResource(R.string.copy),
tint = contentColor,
modifier = Modifier
.align(Alignment.Companion.TopEnd)
.align(Alignment.TopEnd)
.padding(4.dp)
.size(28.dp)
.background(
Expand All @@ -182,7 +182,7 @@ internal fun ColorHarmonies(
text = color.toHex(),
color = contentColor,
modifier = Modifier
.align(Alignment.Companion.BottomStart)
.align(Alignment.BottomStart)
.padding(4.dp)
.background(
color = boxColor.copy(alpha = 1f),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ internal fun ColorInfo(
contentDescription = stringResource(R.string.copy),
tint = contentColor,
modifier = Modifier
.align(Alignment.Companion.TopEnd)
.align(Alignment.TopEnd)
.padding(4.dp)
.size(28.dp)
.background(
Expand All @@ -136,7 +136,7 @@ internal fun ColorInfo(
text = selectedColor.toHex(),
color = contentColor,
modifier = Modifier
.align(Alignment.Companion.BottomStart)
.align(Alignment.BottomStart)
.padding(4.dp)
.background(
color = boxColor.copy(alpha = 1f),
Expand All @@ -154,7 +154,7 @@ internal fun ColorInfo(
}.value,
color = contentColor,
modifier = Modifier
.align(Alignment.Companion.BottomEnd)
.align(Alignment.BottomEnd)
.padding(4.dp)
.background(
color = boxColor.copy(alpha = 1f),
Expand Down Expand Up @@ -196,7 +196,7 @@ internal fun ColorInfo(
delay(100)
if (wasNull) {
val temp = selectedColor
onColorChange(Color.Companion.White)
onColorChange(Color.White)
delay(100)
onColorChange(temp)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ internal fun ColorMixing(
var colorToMix by rememberSaveable(
stateSaver = ColorSaver
) {
mutableStateOf(appColorTuple.tertiary ?: Color.Companion.Yellow)
mutableStateOf(appColorTuple.tertiary ?: Color.Yellow)
}
val mixedColors by remember(selectedColor, mixingVariation, colorToMix) {
derivedStateOf {
Expand Down Expand Up @@ -142,7 +142,7 @@ internal fun ColorMixing(
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(4.dp),
horizontalAlignment = Alignment.Companion.CenterHorizontally
horizontalAlignment = Alignment.CenterHorizontally
) {
mixedColors.forEachIndexed { index, color ->
val boxColor by animateColorAsState(color)
Expand Down Expand Up @@ -183,7 +183,7 @@ internal fun ColorMixing(
contentDescription = stringResource(R.string.copy),
tint = contentColor,
modifier = Modifier
.align(Alignment.Companion.TopEnd)
.align(Alignment.TopEnd)
.padding(4.dp)
.size(28.dp)
.background(
Expand All @@ -197,7 +197,7 @@ internal fun ColorMixing(
text = color.toHex(),
color = contentColor,
modifier = Modifier
.align(Alignment.Companion.BottomStart)
.align(Alignment.BottomStart)
.padding(4.dp)
.background(
color = boxColor.copy(alpha = 1f),
Expand All @@ -217,7 +217,7 @@ internal fun ColorMixing(
}.value,
color = contentColor,
modifier = Modifier
.align(Alignment.Companion.BottomEnd)
.align(Alignment.BottomEnd)
.padding(4.dp)
.background(
color = boxColor.copy(alpha = 1f),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ internal fun ColorShading(
val shades by remember(selectedColor, shadingVariation) {
derivedStateOf {
selectedColor.mixWith(
color = Color.Companion.Black,
color = Color.Black,
variations = shadingVariation,
maxPercent = 0.9f
)
Expand All @@ -99,7 +99,7 @@ internal fun ColorShading(
val tints by remember(selectedColor, shadingVariation) {
derivedStateOf {
selectedColor.mixWith(
color = Color.Companion.White,
color = Color.White,
variations = shadingVariation,
maxPercent = 0.8f
)
Expand Down Expand Up @@ -143,7 +143,7 @@ internal fun ColorShading(
Column(
modifier = Modifier.weight(1f),
verticalArrangement = Arrangement.spacedBy(4.dp),
horizontalAlignment = Alignment.Companion.CenterHorizontally
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = stringResource(title))
data.forEachIndexed { index, color ->
Expand Down Expand Up @@ -185,7 +185,7 @@ internal fun ColorShading(
contentDescription = stringResource(R.string.copy),
tint = contentColor,
modifier = Modifier
.align(Alignment.Companion.TopEnd)
.align(Alignment.TopEnd)
.padding(4.dp)
.size(28.dp)
.background(
Expand All @@ -199,7 +199,7 @@ internal fun ColorShading(
text = color.toHex(),
color = contentColor,
modifier = Modifier
.align(Alignment.Companion.BottomStart)
.align(Alignment.BottomStart)
.padding(4.dp)
.background(
color = boxColor.copy(alpha = 1f),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ internal fun Canvas.UiPathPaintCanvasAction(
val imagePaint = remember { Paint() }
drawImage(
image = shaderSource!!,
topLeftOffset = Offset.Companion.Zero,
topLeftOffset = Offset.Zero,
paint = imagePaint
)
}
Expand All @@ -129,19 +129,19 @@ internal fun Canvas.UiPathPaintCanvasAction(
val stroke = strokeWidth.toPx(canvasSize)
val paint = Paint().apply {
if (isFilled) {
style = PaintingStyle.Companion.Fill
style = PaintingStyle.Fill
} else {
style = PaintingStyle.Companion.Stroke
style = PaintingStyle.Stroke
this.strokeWidth = stroke
if (isSharpEdge) {
strokeCap = StrokeCap.Companion.Square
strokeCap = StrokeCap.Square
} else {
strokeCap = StrokeCap.Companion.Round
strokeJoin = StrokeJoin.Companion.Round
strokeCap = StrokeCap.Round
strokeJoin = StrokeJoin.Round
}
}

color = Color.Companion.White
color = Color.White
}

var shaderSource by remember(backgroundColor) {
Expand All @@ -159,7 +159,7 @@ internal fun Canvas.UiPathPaintCanvasAction(
canvasSize.height,
Bitmap.Config.ARGB_8888
).applyCanvas {
drawColor(Color.Companion.Black.toArgb())
drawColor(Color.Black.toArgb())
drawPath(
path,
paint.asFrameworkPaint()
Expand All @@ -173,7 +173,7 @@ internal fun Canvas.UiPathPaintCanvasAction(
)?.asImageBitmap()?.clipBitmap(
path = path.asComposePath(),
paint = paint.apply {
blendMode = BlendMode.Companion.Clear
blendMode = BlendMode.Clear
}
)?.also {
it.prepareToDraw()
Expand All @@ -189,7 +189,7 @@ internal fun Canvas.UiPathPaintCanvasAction(
val imagePaint = remember { Paint() }
drawImage(
image = shaderSource!!,
topLeftOffset = Offset.Companion.Zero,
topLeftOffset = Offset.Zero,
paint = imagePaint
)
}
Expand Down
Loading

0 comments on commit 015eeac

Please sign in to comment.