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 date_time module
  • Loading branch information
DatL4g committed Apr 11, 2024
commit 2a6a65869144b960f176c9f5838462b91452cf15
69 changes: 61 additions & 8 deletions date_time/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.vanniktech.maven.publish.SonatypeHost

/*
* Copyright (C) 2022-2024. Maximilian Keppeler (https://www.maxkeppeler.com)
*
Expand All @@ -14,23 +16,74 @@
* limitations under the License.
*/
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.DATE_TIME.namespace
namespace = Modules.CALENDAR.namespace
compileSdk = 34

defaultConfig {
minSdk = 21
}
compileOptions {
// Flag to enable support for the new language APIs
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}

kotlin {
androidTarget {
publishAllLibraryVariants()
}
jvm()

iosX64()
iosArm64()
iosSimulatorArm64()

macosX64()
macosArm64()

js(IR) {
browser()
binaries.executable()
}

applyDefaultHierarchyTemplate()

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

implementation(libs.datetime)
implementation(libs.serialization)

api(project(":core"))
}

val nonJvmMain by creating {
dependsOn(commonMain.get())

nativeMain.orNull?.dependsOn(this)
jsMain.orNull?.dependsOn(this)
}
}
}

dependencies {
implementations(Dependencies.SNAPPER)
coreLibraryDesugaring(Dependencies.DESUGAR)
coreLibraryDesugaring(libs.desugar)
}

mavenPublishing {
publishToMavenCentral()
signAllPublications()
}
publishToMavenCentral(SonatypeHost.S01, automaticRelease = true)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.maxkeppeler.sheets.date_time.utils

import java.time.chrono.Chronology
import java.time.format.DateTimeFormatterBuilder
import java.util.Locale

internal fun FormatStyle.toJava(): java.time.format.FormatStyle {
return when (this) {
FormatStyle.FULL -> java.time.format.FormatStyle.FULL
FormatStyle.LONG -> java.time.format.FormatStyle.LONG
FormatStyle.MEDIUM -> java.time.format.FormatStyle.MEDIUM
FormatStyle.SHORT -> java.time.format.FormatStyle.SHORT
}
}

internal actual fun getLocalizedPattern(
isDate: Boolean,
formatStyle: FormatStyle
): String {
val locale = Locale.getDefault()
return DateTimeFormatterBuilder.getLocalizedDateTimePattern(
if (isDate) formatStyle.toJava() else null,
if (!isDate) formatStyle.toJava() else null, Chronology.ofLocale(locale), locale
).toString()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.maxkeppeler.sheets.date_time.utils

import platform.Foundation.*

internal fun FormatStyle.toSwift(isAbsent: Boolean): NSDateFormatterStyle {
if (isAbsent) {
return NSDateFormatterNoStyle
}
return when (this) {
FormatStyle.FULL -> NSDateFormatterFullStyle
FormatStyle.LONG -> NSDateFormatterLongStyle
FormatStyle.MEDIUM -> NSDateFormatterMediumStyle
FormatStyle.SHORT -> NSDateFormatterShortStyle
}
}

internal actual fun getLocalizedPattern(
isDate: Boolean,
formatStyle: FormatStyle
): String {
val formatter = NSDateFormatter()
formatter.setDateStyle(formatStyle.toSwift(!isDate))
formatter.setTimeStyle(formatStyle.toSwift(isDate))
return formatter.dateFormat()
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.maxkeppeler.sheets.date_time.models.DateTimeSelection
* @param header The header to be displayed at the top of the dialog.
* @param properties DialogProperties for further customization of this dialog's behavior.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DateTimeDialog(
state: UseCaseState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import androidx.compose.runtime.setValue
import com.maxkeppeker.sheets.core.views.BaseTypeState
import com.maxkeppeler.sheets.date_time.models.*
import com.maxkeppeler.sheets.date_time.utils.*
import java.io.Serializable
import java.time.LocalDate
import java.time.LocalTime
import com.maxkeppeker.sheets.core.utils.JvmSerializable
import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalTime
import kotlinx.datetime.atTime

/**
* Handles the date time state.
Expand Down Expand Up @@ -128,15 +129,13 @@ internal class DateTimeState(
private fun getDatePatternValue(): String? = selection.dateFormatStyle?.let {
getLocalizedPattern(
isDate = true,
locale = config.locale,
formatStyle = it
)
}

private fun getTimePatternValue(): String? = selection.timeFormatStyle?.let {
getLocalizedPattern(
isDate = false,
locale = config.locale,
formatStyle = it
)
}
Expand Down Expand Up @@ -200,7 +199,7 @@ internal class DateTimeState(
val dateSelection: LocalDate?,
val timeSelection: LocalTime?,
val typeValues: MutableMap<UnitType, UnitOptionEntry?>
) : Serializable
) : JvmSerializable
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.maxkeppeker.sheets.core.models.base.BaseBehaviors
import com.maxkeppeker.sheets.core.models.base.Header
import com.maxkeppeker.sheets.core.models.base.StateHandler
Expand All @@ -36,6 +35,12 @@ import com.maxkeppeker.sheets.core.views.base.FrameBase
import com.maxkeppeler.sheets.date_time.models.DateTimeConfig
import com.maxkeppeler.sheets.date_time.models.DateTimeSelection
import com.maxkeppeler.sheets.date_time.views.PickerComponent
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.StringResource
import org.jetbrains.compose.resources.stringResource
import sheets_compose_dialogs.date_time.generated.resources.Res
import sheets_compose_dialogs.date_time.generated.resources.sheets_compose_dialogs_set_date
import sheets_compose_dialogs.date_time.generated.resources.sheets_compose_dialogs_set_time

/**
* Date Time dialog for the use-case to select a date, time or both in a quick way.
Expand All @@ -44,6 +49,7 @@ import com.maxkeppeler.sheets.date_time.views.PickerComponent
* @param config The general configuration for the dialog view.
* @param header The header to be displayed at the top of the dialog view.
*/
@OptIn(ExperimentalResourceApi::class)
@ExperimentalMaterial3Api
@Composable
fun DateTimeView(
Expand All @@ -70,7 +76,7 @@ fun DateTimeView(
LaunchedEffect(state.isDateValid) { processSelection() }
LaunchedEffect(state.isDateValid) { processSelection() }

val skipButton: @Composable ColumnScope.(Int, Boolean) -> Unit = @Composable { labelRes, error ->
val skipButton: @Composable ColumnScope.(StringResource, Boolean) -> Unit = @Composable { labelRes, error ->
Button(
modifier = Modifier.align(Alignment.CenterHorizontally),
onClick = state::skipSelection,
Expand Down Expand Up @@ -112,18 +118,18 @@ fun DateTimeView(
if (selection.startWithTime) {
if (!state.firstSkipped) {
timePicker()
skipButton(R.string.sheets_compose_dialogs_set_date, !state.isDateValid)
skipButton(Res.string.sheets_compose_dialogs_set_date, !state.isDateValid)
} else {
datePicker()
skipButton(R.string.sheets_compose_dialogs_set_time, !state.isTimeValid)
skipButton(Res.string.sheets_compose_dialogs_set_time, !state.isTimeValid)
}
} else {
if (!state.firstSkipped) {
datePicker()
skipButton(R.string.sheets_compose_dialogs_set_time, !state.isTimeValid)
skipButton(Res.string.sheets_compose_dialogs_set_time, !state.isTimeValid)
} else {
timePicker()
skipButton(R.string.sheets_compose_dialogs_set_date, !state.isDateValid)
skipButton(Res.string.sheets_compose_dialogs_set_date, !state.isDateValid)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import com.maxkeppeker.sheets.core.icons.LibIcons
import com.maxkeppeker.sheets.core.models.base.BaseConfigs
import com.maxkeppeker.sheets.core.utils.BaseConstants.DEFAULT_ICON_STYLE
import com.maxkeppeler.sheets.date_time.utils.Constants
import java.util.*

/**
* The general configuration for the date time dialog.
Expand All @@ -31,7 +30,6 @@ import java.util.*
* @param icons The style of icons that are used for dialog/ view-specific icons.
*/
class DateTimeConfig(
val locale: Locale = Locale.getDefault(),
val hideDateCharacters: Boolean = false,
val hideTimeCharacters: Boolean = false,
val minYear: Int = Constants.DEFAULT_MIN_YEAR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ package com.maxkeppeler.sheets.date_time.models
import com.maxkeppeker.sheets.core.models.base.BaseSelection
import com.maxkeppeker.sheets.core.models.base.SelectionButton
import com.maxkeppeker.sheets.core.utils.BaseConstants
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime
import java.time.format.FormatStyle
import com.maxkeppeler.sheets.date_time.utils.FormatStyle
import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.LocalTime
import kotlinx.datetime.format.DateTimeFormat

/**
* The selection configuration for the date time dialog.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
*/
package com.maxkeppeler.sheets.date_time.models

import androidx.annotation.StringRes
import java.io.Serializable
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.StringResource
import com.maxkeppeker.sheets.core.utils.JvmSerializable

/**
* A class that acts as a value item that can be selected for a unit.
* @param value The actual value.
* @param label The textual representation of the value.
* @param labelRes The textual representation of the value by resource.
*/
data class UnitOptionEntry(
@OptIn(ExperimentalResourceApi::class)
data class UnitOptionEntry constructor(
val value: Int,
val label: String? = null,
@StringRes val labelRes: Int? = null
) : Serializable
val labelRes: StringResource? = null
) : JvmSerializable
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
*/
package com.maxkeppeler.sheets.date_time.models

import androidx.annotation.StringRes
import com.maxkeppeler.sheets.date_time.R
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.StringResource
import sheets_compose_dialogs.date_time.generated.resources.*
import sheets_compose_dialogs.date_time.generated.resources.Res
import sheets_compose_dialogs.date_time.generated.resources.sheets_compose_dialogs_date_time_hour
import sheets_compose_dialogs.date_time.generated.resources.sheets_compose_dialogs_date_time_minutes
import sheets_compose_dialogs.date_time.generated.resources.sheets_compose_dialogs_date_time_seconds

enum class UnitType(val isDate: Boolean) {
DAY(true),
Expand All @@ -34,8 +39,9 @@ enum class UnitType(val isDate: Boolean) {
* @param options The list of of options that can be selected.
* @param value The current selected value.
*/
@OptIn(ExperimentalResourceApi::class)
internal sealed class UnitSelection(
@StringRes open val placeholderRes: Int? = null,
open val placeholderRes: StringResource? = null,
open val options: List<UnitOptionEntry> = listOf(),
open val value: UnitOptionEntry? = null,
open val type: UnitType? = null
Expand All @@ -60,7 +66,7 @@ internal sealed class UnitSelection(
override val value: UnitOptionEntry? = null,
override val options: List<UnitOptionEntry>,
) : UnitSelection(
placeholderRes = R.string.sheets_compose_dialogs_date_time_hour,
placeholderRes = Res.string.sheets_compose_dialogs_date_time_hour,
type = UnitType.HOUR
)

Expand All @@ -73,7 +79,7 @@ internal sealed class UnitSelection(
override val value: UnitOptionEntry? = null,
override val options: List<UnitOptionEntry>,
) : UnitSelection(
placeholderRes = R.string.sheets_compose_dialogs_date_time_minutes,
placeholderRes = Res.string.sheets_compose_dialogs_date_time_minutes,
type = UnitType.MINUTE
)

Expand All @@ -86,7 +92,7 @@ internal sealed class UnitSelection(
override val value: UnitOptionEntry? = null,
override val options: List<UnitOptionEntry>,
) : UnitSelection(
placeholderRes = R.string.sheets_compose_dialogs_date_time_seconds,
placeholderRes = Res.string.sheets_compose_dialogs_date_time_seconds,
type = UnitType.SECOND
)

Expand All @@ -99,7 +105,7 @@ internal sealed class UnitSelection(
override val value: UnitOptionEntry? = null,
override val options: List<UnitOptionEntry>
) : UnitSelection(
placeholderRes = R.string.sheets_compose_dialogs_date_time_day,
placeholderRes = Res.string.sheets_compose_dialogs_date_time_day,
type = UnitType.DAY
)

Expand All @@ -112,7 +118,7 @@ internal sealed class UnitSelection(
override val value: UnitOptionEntry? = null,
override val options: List<UnitOptionEntry>,
) : UnitSelection(
placeholderRes = R.string.sheets_compose_dialogs_date_time_month,
placeholderRes = Res.string.sheets_compose_dialogs_date_time_month,
type = UnitType.MONTH
)

Expand All @@ -125,7 +131,7 @@ internal sealed class UnitSelection(
override val value: UnitOptionEntry? = null,
override val options: List<UnitOptionEntry>
) : UnitSelection(
placeholderRes = R.string.sheets_compose_dialogs_date_time_year,
placeholderRes = Res.string.sheets_compose_dialogs_date_time_year,
type = UnitType.YEAR
)
}
Loading