Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compose Multiplatform #89

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
487261f
refactor core module to multiplatform
DatL4g Mar 29, 2024
58908fb
multiplatform core module
DatL4g Mar 29, 2024
1d38e02
fix old android targets
DatL4g Mar 29, 2024
2f65c32
prepare calendar multiplatform
DatL4g Mar 29, 2024
392641f
calendar multiplatform compatible
DatL4g Mar 29, 2024
afa6178
rating multiplatform compatible
DatL4g Mar 30, 2024
5393ed2
option multiplatform compatible
DatL4g Mar 30, 2024
50dcb48
list multiplatform compatible
DatL4g Mar 30, 2024
83dde05
multiplatform landscape check
DatL4g Mar 30, 2024
8e11b75
prepare snapshot release
DatL4g Mar 30, 2024
75d6893
fix snapshot release
DatL4g Mar 30, 2024
0cd7fa2
added release workflow
DatL4g Mar 30, 2024
da08075
api core library
DatL4g Mar 30, 2024
8ecc373
make states fully serializable
DatL4g Mar 30, 2024
14e7852
added missing java serialization
DatL4g Mar 30, 2024
981caa0
skip workflows
DatL4g Mar 30, 2024
3da43ed
fix calendar module
DatL4g Mar 30, 2024
4efdbde
fix calendar module
DatL4g Mar 30, 2024
879f669
fix calendar resources
DatL4g Mar 30, 2024
87bb4a0
fix calendar arrow size
DatL4g Mar 30, 2024
ba08232
added default selection for rating
DatL4g Apr 3, 2024
a8ba838
fix resources
DatL4g Apr 3, 2024
b795aa9
added possibility to deselect rating and rating of 0 is valid
DatL4g Apr 4, 2024
47a5cca
migrate state module
DatL4g Apr 4, 2024
8d3262e
migrate input module
DatL4g Apr 4, 2024
adeb1c0
migrate info module
DatL4g Apr 4, 2024
6f30cb1
migrate color module
DatL4g Apr 4, 2024
446bdd0
migrate emoji module
DatL4g Apr 11, 2024
37bc03c
migrate emoji module
DatL4g Apr 11, 2024
2a6a658
migrate date_time module
DatL4g Apr 11, 2024
dcc5d95
migrate date_time module
DatL4g Apr 11, 2024
7b2940a
migrate date_time module
DatL4g Apr 11, 2024
0d1f94e
migrate duration module
DatL4g Apr 12, 2024
38d3372
migrate clock module
DatL4g Apr 12, 2024
1d5bfa7
added missing configuration
DatL4g Apr 12, 2024
b29bc84
changed readme as core module is not required to add manually anymore
DatL4g Apr 12, 2024
02dbb78
added wasm target
DatL4g Apr 12, 2024
a6a90ff
added missing wasm implementations
DatL4g Apr 12, 2024
5f185b5
chore(deps): ⬆️ Upgraded Compose versions
maicol07 Apr 15, 2024
fb7d802
refactor: Moved dependency management from buildSrc to Version Catalog
maicol07 Apr 16, 2024
1c81161
Merge pull request #1 from maicol07/main
DatL4g Apr 16, 2024
da9f1f1
updated compose
DatL4g Apr 17, 2024
3886da0
ignore some fields from java serialization
DatL4g Apr 18, 2024
8c34770
roll back compose version
DatL4g Apr 18, 2024
e53bb5f
update to latest compose version
DatL4g Apr 29, 2024
cee7dbe
update to latest compose version
DatL4g Apr 30, 2024
90b23af
option invoke click listener
DatL4g Apr 30, 2024
01e57b0
option icon size
DatL4g May 12, 2024
b022d95
rating body max width
DatL4g May 12, 2024
dd2451a
revert sizing
DatL4g May 12, 2024
f16d2d3
revert LocalDate calculations and fix visual error
DatL4g May 13, 2024
dce4cd0
removed unused file
DatL4g May 13, 2024
f21cd3d
apply system locale on jvm
DatL4g May 14, 2024
24de041
added missing localization
DatL4g May 14, 2024
27692e6
added body for option
DatL4g May 14, 2024
ed2ba8c
added missing body dependency injection
DatL4g May 14, 2024
d2848f5
updated compose
DatL4g May 17, 2024
01f3361
updated dependencies
DatL4g May 22, 2024
3518cc7
fix crash on android
DatL4g May 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
migrate color module
  • Loading branch information
DatL4g committed Apr 4, 2024
commit 6f30cb1e935dc3ab5d12d568323f9044ebf6530b
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fun ClockView(
PortraitTimeValueComponent(
modifier = Modifier
.fillMaxWidth()
.padding(bottom = dimensionResource(R.dimen.scd_normal_100)),
.padding(bottom = 16.dp),
unitValues = clockState.timeTextValues,
isAm = clockState.isAm,
is24hourFormat = clockState.is24HourFormat,
Expand Down
62 changes: 42 additions & 20 deletions color/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,27 +1,49 @@
/*
* Copyright (C) 2022-2024. Maximilian Keppeler (https://www.maxkeppeler.com)
*
* 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:https://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.
*/
import com.vanniktech.maven.publish.SonatypeHost

plugins {
id(Plugins.CUSTOM_LIBRARY_MODULE.id)
alias(libs.plugins.android.library)
alias(libs.plugins.compose)
alias(libs.plugins.multiplatform)
alias(libs.plugins.serialization)
alias(libs.plugins.publish)
`maven-publish`
}

android {
namespace = Modules.COLOR.namespace
namespace = Modules.OPTION.namespace
compileSdk = 34

defaultConfig {
minSdk = 21
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}

kotlin {
androidTarget {
publishAllLibraryVariants()
}
jvm()

applyDefaultHierarchyTemplate()

sourceSets {
commonMain.dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.components.resources)

implementation(libs.serialization)

api(project(":core"))
}
}
}

mavenPublishing {
publishToMavenCentral()
signAllPublications()
}
publishToMavenCentral(SonatypeHost.S01, automaticRelease = true)
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.maxkeppeler.sheets.color

import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -36,7 +35,6 @@ import java.io.Serializable
* @param stateData The data of the state when the state is required to be restored.
*/
internal class ColorState(
private val context: Context,
val selection: ColorSelection,
val config: ColorConfig = ColorConfig(),
stateData: ColorStateData? = null,
Expand All @@ -48,10 +46,10 @@ internal class ColorState(
var valid by mutableStateOf(isValid())

private fun getInitColor(): Int? =
selection.selectedColor?.colorInInt(context)
selection.selectedColor?.colorInInt()

private fun getInitColors(): List<Int> =
config.templateColors.getColorsAsInt(context)
config.templateColors.getColorsAsInt()

private fun getInitDisplayMode(): ColorSelectionMode =
config.defaultDisplayMode.takeUnless {
Expand Down Expand Up @@ -86,12 +84,11 @@ internal class ColorState(
* @param config The general configuration for the dialog view.
*/
fun Saver(
context: Context,
selection: ColorSelection,
config: ColorConfig
): Saver<ColorState, *> = Saver(
save = { state -> ColorStateData(state.color, state.displayMode) },
restore = { data -> ColorState(context, selection, config, data) }
restore = { data -> ColorState(selection, config, data) }
)
}

Expand All @@ -113,11 +110,10 @@ internal class ColorState(
*/
@Composable
internal fun rememberColorState(
context: Context,
selection: ColorSelection,
config: ColorConfig,
): ColorState = rememberSaveable(
inputs = arrayOf(selection, config),
saver = ColorState.Saver(context, selection, config),
init = { ColorState(context, selection, config) }
saver = ColorState.Saver(selection, config),
init = { ColorState(selection, config) }
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import com.maxkeppeker.sheets.core.models.base.*
import com.maxkeppeker.sheets.core.views.ButtonsComponent
import com.maxkeppeker.sheets.core.views.base.FrameBase
Expand All @@ -48,8 +47,7 @@ fun ColorView(
config: ColorConfig = ColorConfig(),
header: Header? = null,
) {
val context = LocalContext.current
val colorState = rememberColorState(context, selection, config)
val colorState = rememberColorState(selection, config)
StateHandler(useCaseState, colorState)

val coroutine = rememberCoroutineScope()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@

package com.maxkeppeler.sheets.color.models

import android.content.Context
import android.graphics.Color
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb

/**
* Holds various colors of a specific type.
Expand All @@ -30,29 +27,10 @@ import androidx.core.content.ContextCompat
* @param colorsHex color as String value, #RRGGBB or #AARRGGBB.
*/
sealed class MultipleColors(
@ColorInt private var colorsInt: Array<Int>? = null,
@ColorRes private var colorsRes: Array<Int>? = null,
private var colorsInt: Array<Int>? = null,
private var colorsHex: Array<String>? = null,
) {

/**
* Define a variety of color integers.
*/
class ColorsRes : MultipleColors {

/**
* Define dynamic amount of colors.
* @param colors The color integers
*/
constructor(@ColorRes vararg colors: Int) : super(colorsRes = colors.toTypedArray())

/**
* Define a list of colors.
* @param colors The color integers
*/
constructor(@ColorRes colors: List<Int>) : super(colorsRes = colors.toTypedArray())
}

/**
* Define a variety of color resource references.
*/
Expand All @@ -62,13 +40,13 @@ sealed class MultipleColors(
* Define dynamic amount of colors.
* @param colors The color resource references
*/
constructor(@ColorInt vararg colors: Int) : super(colorsInt = colors.toTypedArray())
constructor(vararg colors: Int) : super(colorsInt = colors.toTypedArray())

/**
* Define an array of colors.
* @param colors The color resource references
*/
constructor(@ColorInt colors: List<Int>) : super(colorsInt = colors.toTypedArray())
constructor(colors: List<Int>) : super(colorsInt = colors.toTypedArray())
}

/**
Expand All @@ -93,10 +71,12 @@ sealed class MultipleColors(
* Resolve the defined colors as color integers.
* @param context the Context to resolve the colors.
*/
fun getColorsAsInt(context: Context): List<Int> {
@OptIn(ExperimentalStdlibApi::class)
fun getColorsAsInt(): List<Int> {
return colorsInt?.toList()
?: colorsRes?.map { ContextCompat.getColor(context, it) }
?: colorsHex?.map { Color.parseColor(it) }
?: colorsHex?.map {
Color(it.substringAfter('#').hexToLong()).toArgb()
}
?: throw IllegalStateException("No colors available for color templates view. Either disabled template view or add colors.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
*/
package com.maxkeppeler.sheets.color.models

import android.content.Context
import android.graphics.Color
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb


/**
* Helper class to simplify passing colors.
Expand All @@ -28,11 +26,12 @@ import androidx.core.content.ContextCompat
* @param colorHex Color value as Hex-String.
*/
data class SingleColor(
@ColorInt val colorInt: Int? = null,
@ColorRes val colorRes: Int? = null,
val colorInt: Int? = null,
val colorHex: String? = null,
) {
fun colorInInt(context: Context): Int? = colorInt
?: colorRes?.let { ContextCompat.getColor(context, it) }
?: colorHex?.let { Color.parseColor(it) }
@OptIn(ExperimentalStdlibApi::class)
fun colorInInt(): Int? = colorInt
?: colorHex?.let {
Color(it.substringAfter('#').hexToLong()).toArgb()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2022-2024. Maximilian Keppeler (https://www.maxkeppeler.com)
*
* 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:https://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.maxkeppeler.sheets.color.utils

/** Receive the clipboard data. */
@OptIn(ExperimentalStdlibApi::class)
internal fun getFormattedColor(color: Int): String {
return "#" + (0xFFFFFFFF and color.toLong()).toHexString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.core.graphics.alpha
import androidx.core.graphics.blue
import androidx.core.graphics.green
import androidx.core.graphics.red
import com.maxkeppeker.sheets.core.models.base.LibOrientation
import com.maxkeppeker.sheets.core.utils.TestTags
import com.maxkeppeker.sheets.core.utils.testSequenceTagOf
import com.maxkeppeker.sheets.core.views.Grid
import com.maxkeppeler.sheets.color.R
import com.maxkeppeler.sheets.color.models.ColorConfig
import com.maxkeppeler.sheets.core.R as RC
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.stringResource
import sheets_compose_dialogs.color.generated.resources.*
import sheets_compose_dialogs.color.generated.resources.Res
import sheets_compose_dialogs.color.generated.resources.scd_color_dialog_alpha
import sheets_compose_dialogs.color.generated.resources.scd_color_dialog_blue
import sheets_compose_dialogs.color.generated.resources.scd_color_dialog_green

/**
* The control component to build up a custom color.
* @param config The general configuration for the dialog view.
* @param color The color that is currently selected.
* @param onColorChange The listener that returns a selected color.
*/
@OptIn(ExperimentalResourceApi::class)
@Composable
internal fun ColorCustomControlComponent(
config: ColorConfig,
Expand All @@ -50,13 +50,18 @@ internal fun ColorCustomControlComponent(
onColorChange: (Int) -> Unit
) {

val composeColor = Color(color)
val alphaValue = remember(color) {
val value = if (config.allowCustomColorAlphaValues) color.alpha else 255
val value = if (config.allowCustomColorAlphaValues) {
composeColor.alpha
} else {
1F
}
mutableStateOf(value)
}
val redValue = remember(color) { mutableStateOf(color.red) }
val greenValue = remember(color) { mutableStateOf(color.green) }
val blueValue = remember(color) { mutableStateOf(color.blue) }
val redValue = remember(color) { mutableStateOf(composeColor.red) }
val greenValue = remember(color) { mutableStateOf(composeColor.green) }
val blueValue = remember(color) { mutableStateOf(composeColor.blue) }

val newColor by remember(alphaValue.value, redValue.value, greenValue.value, blueValue.value) {
mutableStateOf(Color(redValue.value, greenValue.value, blueValue.value, alphaValue.value))
Expand All @@ -68,10 +73,10 @@ internal fun ColorCustomControlComponent(
val colorValueLabelWidth = remember { mutableStateOf<Int?>(null) }

val colorItems = mutableListOf(
if (config.allowCustomColorAlphaValues) stringResource(R.string.scd_color_dialog_alpha) to alphaValue else null,
stringResource(R.string.scd_color_dialog_red) to redValue,
stringResource(R.string.scd_color_dialog_green) to greenValue,
stringResource(R.string.scd_color_dialog_blue) to blueValue
if (config.allowCustomColorAlphaValues) stringResource(Res.string.scd_color_dialog_alpha) to alphaValue else null,
stringResource(Res.string.scd_color_dialog_red) to redValue,
stringResource(Res.string.scd_color_dialog_green) to greenValue,
stringResource(Res.string.scd_color_dialog_blue) to blueValue
).filterNotNull()

Grid(
Expand All @@ -87,7 +92,9 @@ internal fun ColorCustomControlComponent(
columnSpacing = 24.dp
) { entry ->
val index = colorItems.indexOf(entry)
val onValueChange: (Int) -> Unit = { entry.second.value = it }
val onValueChange: (Int) -> Unit = {
entry.second.value = it.toFloat()
}
val sliderTestTag = testSequenceTagOf(
TestTags.COLOR_CUSTOM_VALUE_SLIDER,
index.toString()
Expand All @@ -96,7 +103,7 @@ internal fun ColorCustomControlComponent(
LibOrientation.PORTRAIT ->
ColorCustomControlListItemComponent(
label = entry.first,
value = entry.second.value,
value = entry.second.value.toInt(),
onValueChange = onValueChange,
colorItemLabelWidth = colorItemLabelWidth,
colorValueLabelWidth = colorValueLabelWidth,
Expand All @@ -105,7 +112,7 @@ internal fun ColorCustomControlComponent(
LibOrientation.LANDSCAPE ->
ColorCustomControlGridItemComponent(
label = entry.first,
value = entry.second.value,
value = entry.second.value.toInt(),
onValueChange = onValueChange,
sliderTestTag = sliderTestTag,
)
Expand Down
Loading