Skip to content

Commit

Permalink
Merge pull request #511 from splendo/release/0.4.0
Browse files Browse the repository at this point in the history
Release/0.4.0
  • Loading branch information
thoutbeckers authored May 11, 2022
2 parents 45e2d24 + 08b3b2c commit a0f3207
Show file tree
Hide file tree
Showing 95 changed files with 1,323 additions and 1,084 deletions.
12 changes: 12 additions & 0 deletions DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ if this property is not set the version string is a combination of the version n

For example if the version in `ext.gradle` is `1.1` and `feature/123_fix_bug` is the current branch the resulting version will be `1.1-feature-123_fix_bug-SNAPSHOT`.

#### Local Testing

Before doing any publishing, make sure that changes are working with the one available in [Nexus Repository Manager](`oss.sonatype.org`). Test both on Android and iOS example app just adding the following code inside the `local.properties` file:
```
kaluga.exampleEmbeddingMethod=composite
kaluga.exampleMavenRepo=https://oss.sonatype.org/service/local/repositories/comsplendo-REPO_NUMBER/content/
kaluga.libraryVersion=LIBRARY_VERSION
```
Where
`REPO_NUMBER` is the last one created after merging to master
`LIBRARY_VERSION` is the one that we want to publish

#### Publishing locally

1. Publish to local maven:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import com.splendo.kaluga.architecture.navigation.NavigationBundleValue
import com.splendo.kaluga.architecture.navigation.SingleValueNavigationAction
import com.splendo.kaluga.architecture.navigation.SingleValueNavigationSpec
import com.splendo.kaluga.architecture.navigation.toBundle
import com.splendo.kaluga.base.text.DateFormatter
import com.splendo.kaluga.base.text.KalugaDateFormatter
import com.splendo.kaluga.base.text.iso8601Pattern
import com.splendo.kaluga.base.utils.Date
import com.splendo.kaluga.base.utils.KalugaDate
import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.BooleanArraySerializer
import kotlinx.serialization.builtins.ByteArraySerializer
Expand Down Expand Up @@ -199,13 +199,13 @@ inline fun <reified Action : SingleValueNavigationAction<List<String>>> NavGraph
) = composable(Action::class, NavigationBundleSpecType.StringArrayType, content)

@JvmName("singleValueDateComposable")
inline fun <reified Action : SingleValueNavigationAction<Date>> NavGraphBuilder.composable(
noinline content: @Composable (Date) -> Unit
inline fun <reified Action : SingleValueNavigationAction<KalugaDate>> NavGraphBuilder.composable(
noinline content: @Composable (KalugaDate) -> Unit
) = composable(Action::class, NavigationBundleSpecType.DateType, content)

@JvmName("singleValueDateArrayComposable")
inline fun <reified Action : SingleValueNavigationAction<List<Date>>> NavGraphBuilder.composable(
noinline content: @Composable (List<Date>) -> Unit
inline fun <reified Action : SingleValueNavigationAction<List<KalugaDate>>> NavGraphBuilder.composable(
noinline content: @Composable (List<KalugaDate>) -> Unit
) = composable(Action::class, NavigationBundleSpecType.DateArrayType, content)

inline fun <Value, reified Action : SingleValueNavigationAction<Value>> NavGraphBuilder.composable(
Expand Down Expand Up @@ -292,11 +292,11 @@ private fun Bundle.composableValue(
ListSerializer(String.serializer()),
nonNullableValue
).map {
DateFormatter.Companion.iso8601Pattern().parse(it) ?: throw BundleConversionError()
KalugaDateFormatter.Companion.iso8601Pattern().parse(it) ?: throw BundleConversionError()
}
)
is NavigationBundleSpecType.DateType -> specType.convertValue(
DateFormatter.Companion.iso8601Pattern().parse(nonNullableValue)
KalugaDateFormatter.Companion.iso8601Pattern().parse(nonNullableValue)
?: throw BundleConversionError()
)
is NavigationBundleSpecType.DoubleArrayType -> specType.convertValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.splendo.kaluga.architecture.navigation.NavigationBundleSpec
import com.splendo.kaluga.architecture.navigation.NavigationBundleSpecRow
import com.splendo.kaluga.architecture.navigation.NavigationBundleSpecType
import com.splendo.kaluga.architecture.navigation.NavigationBundleValue
import com.splendo.kaluga.base.text.DateFormatter
import com.splendo.kaluga.base.text.KalugaDateFormatter
import com.splendo.kaluga.base.text.iso8601Pattern
import kotlinx.serialization.builtins.BooleanArraySerializer
import kotlinx.serialization.builtins.ByteArraySerializer
Expand Down Expand Up @@ -129,9 +129,9 @@ private val NavigationBundleValue<*>.routeArgument: String?
is NavigationBundleValue.CharValue -> Json.encodeToString(Char.serializer(), value)
is NavigationBundleValue.DateArrayValue -> Json.encodeToString(
ListSerializer(String.serializer()),
value.map { DateFormatter.Companion.iso8601Pattern().format(it) }
value.map { KalugaDateFormatter.Companion.iso8601Pattern().format(it) }
)
is NavigationBundleValue.DateValue -> DateFormatter.Companion.iso8601Pattern().format(value)
is NavigationBundleValue.DateValue -> KalugaDateFormatter.Companion.iso8601Pattern().format(value)
is NavigationBundleValue.DoubleArrayValue -> Json.encodeToString(
DoubleArraySerializer(),
value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import com.splendo.kaluga.architecture.navigation.NavigationBundleSpec
import com.splendo.kaluga.architecture.navigation.NavigationBundleSpecRow
import com.splendo.kaluga.architecture.navigation.NavigationBundleSpecType
import com.splendo.kaluga.architecture.navigation.toBundle
import com.splendo.kaluga.base.text.DateFormatter
import com.splendo.kaluga.base.text.KalugaDateFormatter
import com.splendo.kaluga.base.text.iso8601Pattern
import com.splendo.kaluga.base.utils.Date
import com.splendo.kaluga.base.utils.DefaultKalugaDate
import com.splendo.kaluga.base.utils.KalugaDate
import com.splendo.kaluga.base.utils.TimeZone
import com.splendo.kaluga.base.utils.utc
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -57,7 +58,7 @@ sealed class MockSpecRow<V>(associatedType: NavigationBundleSpecType<V>) : Navig
object OptionalString : MockSpecRow<String?>(NavigationBundleSpecType.OptionalType(NavigationBundleSpecType.StringType))
object OptionalFloat : MockSpecRow<Float?>(NavigationBundleSpecType.OptionalType(NavigationBundleSpecType.FloatType))
object OptionalMockSerializable : MockSpecRow<MockSerializable?>(NavigationBundleSpecType.OptionalType(NavigationBundleSpecType.SerializedType(MockSerializable.serializer())))
object DateSpecRow : MockSpecRow<Date>(NavigationBundleSpecType.DateType)
object DateSpecRow : MockSpecRow<KalugaDate>(NavigationBundleSpecType.DateType)
}

class NestedSpec : NavigationBundleSpec<NestedSpecRow<*>>(setOf(NestedSpecRow.StringSpecRow))
Expand All @@ -73,7 +74,7 @@ class RouteTests {

@Test
fun testRoute() {
val time = Date.epoch(timeZone = TimeZone.utc)
val time = DefaultKalugaDate.epoch(timeZone = TimeZone.utc)
val bundle = MockSpec.toBundle { row ->
when (row) {
is MockSpecRow.StringSpecRow -> row.convertValue("string")
Expand All @@ -87,6 +88,6 @@ class RouteTests {
}
}
val action = TestNavigationAction(bundle)
assertEquals("TestNavigationAction/string/true/0.5/{\"value\":\"Mock\"}/${DateFormatter.iso8601Pattern().format(time)}?OptionalString={optional}&OptionalMockSerializable={{\"value\":\"OptionalMock\"}}", action.route())
assertEquals("TestNavigationAction/string/true/0.5/{\"value\":\"Mock\"}/${KalugaDateFormatter.iso8601Pattern().format(time)}?OptionalString={optional}&OptionalMockSerializable={{\"value\":\"OptionalMock\"}}", action.route())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package com.splendo.kaluga.architecture.navigation

import android.os.Bundle
import com.splendo.kaluga.base.utils.Date
import com.splendo.kaluga.base.utils.DefaultKalugaDate
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
Expand All @@ -38,10 +38,10 @@ class AndroidNavigationBundleTest {
}
val optionalString: String? = "Some String"
val optionalFloat: Float? = null
val dateValue = Date.epoch(offsetInMilliseconds = 1606204800000)
val dateValue = DefaultKalugaDate.epoch(offsetInMilliseconds = 1606204800000)
val dateArray = listOf(
Date.epoch(offsetInMilliseconds = 1606204800001),
Date.epoch(offsetInMilliseconds = 1606204800002)
DefaultKalugaDate.epoch(offsetInMilliseconds = 1606204800001),
DefaultKalugaDate.epoch(offsetInMilliseconds = 1606204800002)
)

val mockSpec = MockSpec()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package com.splendo.kaluga.architecture.navigation

import android.os.Bundle
import com.splendo.kaluga.base.utils.Date
import com.splendo.kaluga.base.utils.DefaultKalugaDate

/**
* Converts a [NavigationBundle] to a [Bundle]
Expand Down Expand Up @@ -133,10 +133,10 @@ internal fun Bundle.mapValue(key: String, specType: NavigationBundleSpecType<*>)
}
}
is NavigationBundleSpecType.DateType -> getLong(key).let { value ->
specType.convertValue(Date.epoch(value))
specType.convertValue(DefaultKalugaDate.epoch(value))
}
is NavigationBundleSpecType.DateArrayType -> getLongArray(key)?.let { array ->
specType.convertValue(array.map { Date.epoch(it) })
specType.convertValue(array.map { DefaultKalugaDate.epoch(it) })
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package com.splendo.kaluga.architecture.navigation

import com.splendo.kaluga.base.utils.Date
import com.splendo.kaluga.base.utils.KalugaDate
import kotlinx.serialization.KSerializer
import kotlinx.serialization.json.Json

Expand Down Expand Up @@ -172,8 +172,8 @@ sealed class NavigationBundleValue<T> {
data class StringValue internal constructor(override val value: String) : NavigationBundleValue<String>()
data class StringArrayValue internal constructor(override val value: List<String>) : NavigationBundleValue<List<String>>()

data class DateValue internal constructor(override val value: Date) : NavigationBundleValue<Date>()
data class DateArrayValue internal constructor(override val value: List<Date>) : NavigationBundleValue<List<Date>>()
data class DateValue internal constructor(override val value: KalugaDate) : NavigationBundleValue<KalugaDate>()
data class DateArrayValue internal constructor(override val value: List<KalugaDate>) : NavigationBundleValue<List<KalugaDate>>()

data class OptionalValue<T> internal constructor(val optionalValue: NavigationBundleValue<T>?) : NavigationBundleValue<T?>() {
override val value: T? = optionalValue?.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package com.splendo.kaluga.architecture.navigation

import com.splendo.kaluga.base.utils.Date
import com.splendo.kaluga.base.utils.KalugaDate
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerializationException
import kotlinx.serialization.json.Json
Expand Down Expand Up @@ -196,14 +196,14 @@ sealed class NavigationBundleSpecType<T> {
}
}

object DateType : NavigationBundleSpecType<Date>() {
override fun convertValue(value: Date): NavigationBundleValue<Date> {
object DateType : NavigationBundleSpecType<KalugaDate>() {
override fun convertValue(value: KalugaDate): NavigationBundleValue<KalugaDate> {
return NavigationBundleValue.DateValue(value)
}
}

object DateArrayType : NavigationBundleSpecType<List<Date>>() {
override fun convertValue(value: List<Date>): NavigationBundleValue<List<Date>> {
object DateArrayType : NavigationBundleSpecType<List<KalugaDate>>() {
override fun convertValue(value: List<KalugaDate>): NavigationBundleValue<List<KalugaDate>> {
return NavigationBundleValue.DateArrayValue(value)
}
}
Expand Down
6 changes: 3 additions & 3 deletions architecture/src/commonTest/kotlin/navigation/MockSpecRow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package com.splendo.kaluga.architecture.navigation

import com.splendo.kaluga.base.utils.Date
import com.splendo.kaluga.base.utils.KalugaDate
import kotlinx.serialization.Serializable

@Serializable
Expand All @@ -41,8 +41,8 @@ sealed class MockSpecRow<V>(associatedType: NavigationBundleSpecType<V>) : Navig
object NestedBundleSpecRow : MockSpecRow<NavigationBundle<NestedSpecRow<*>>>(NavigationBundleSpecType.BundleType(NestedSpec()))
object OptionalString : MockSpecRow<String?>(NavigationBundleSpecType.OptionalType(NavigationBundleSpecType.StringType))
object OptionalFloat : MockSpecRow<Float?>(NavigationBundleSpecType.OptionalType(NavigationBundleSpecType.FloatType))
object DateSpecRow : MockSpecRow<Date>(NavigationBundleSpecType.DateType)
object DateArraySpecRow : MockSpecRow<List<Date>>(NavigationBundleSpecType.DateArrayType)
object DateSpecRow : MockSpecRow<KalugaDate>(NavigationBundleSpecType.DateType)
object DateArraySpecRow : MockSpecRow<List<KalugaDate>>(NavigationBundleSpecType.DateArrayType)
}

class NestedSpec : NavigationBundleSpec<NestedSpecRow<*>>(setOf(NestedSpecRow.StringSpecRow))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package com.splendo.kaluga.architecture.navigation

import com.splendo.kaluga.base.utils.Date
import com.splendo.kaluga.base.utils.DefaultKalugaDate
import com.splendo.kaluga.test.BaseTest
import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -38,10 +38,10 @@ class NavigationBundleTest : BaseTest() {
}
val optionalString: String? = "Some String"
val optionalFloat: Float? = null
val dateValue = Date.epoch(offsetInMilliseconds = 1606204800000)
val dateValue = DefaultKalugaDate.epoch(offsetInMilliseconds = 1606204800000)
val dateArray = listOf(
Date.epoch(offsetInMilliseconds = 1606204800001),
Date.epoch(offsetInMilliseconds = 1606204800002)
DefaultKalugaDate.epoch(offsetInMilliseconds = 1606204800001),
DefaultKalugaDate.epoch(offsetInMilliseconds = 1606204800002)
)

val mockSpec = MockSpec()
Expand Down
4 changes: 2 additions & 2 deletions base-permissions/src/commonMain/kotlin/PermissionState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ package com.splendo.kaluga.permissions

import com.splendo.kaluga.base.flow.SpecialFlowValue
import com.splendo.kaluga.state.ColdStateFlowRepo
import com.splendo.kaluga.state.State
import com.splendo.kaluga.state.KalugaState
import kotlinx.coroutines.Dispatchers
import kotlin.coroutines.CoroutineContext

/**
* State of a [Permission]
*/
sealed class PermissionState<P : Permission> : State() {
sealed class PermissionState<P : Permission> : KalugaState {

class Unknown<P : Permission> : PermissionState<P>(), SpecialFlowValue.NotImportant

Expand Down
2 changes: 1 addition & 1 deletion base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ Use Decimals to do standard arithmetic operations. A Rounding mode or scale can

It's possible to format to and from some data types using Kaluga.

- `Date` can be formatted and parsed using a `DateFormatter`
- `Date` can be formatted and parsed using a `KalugaDateFormatter`
- `Number` can be formatted and parsed using a `NumberFormatter`
- `String` can be formatted to include different data types using `StringFormatter`
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
@file:JvmName("AndroidDateFormatter")
package com.splendo.kaluga.base.text

import com.splendo.kaluga.base.utils.Date
import com.splendo.kaluga.base.utils.DefaultKalugaDate
import com.splendo.kaluga.base.utils.KalugaDate
import com.splendo.kaluga.base.utils.Locale
import com.splendo.kaluga.base.utils.TimeZone
import java.text.DateFormat
Expand All @@ -27,33 +28,33 @@ import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.Calendar

actual class DateFormatter private constructor(private val format: SimpleDateFormat) {
actual class KalugaDateFormatter private constructor(private val format: SimpleDateFormat) {

actual companion object {

actual fun dateFormat(
style: DateFormatStyle,
timeZone: TimeZone,
locale: Locale
): DateFormatter = createDateFormatter(DateFormat.getDateInstance(style.javaStyle(), locale.locale) as SimpleDateFormat, timeZone)
): KalugaDateFormatter = createDateFormatter(DateFormat.getDateInstance(style.javaStyle(), locale.locale) as SimpleDateFormat, timeZone)

actual fun timeFormat(
style: DateFormatStyle,
timeZone: TimeZone,
locale: Locale
): DateFormatter = createDateFormatter(DateFormat.getTimeInstance(style.javaStyle(), locale.locale) as SimpleDateFormat, timeZone)
): KalugaDateFormatter = createDateFormatter(DateFormat.getTimeInstance(style.javaStyle(), locale.locale) as SimpleDateFormat, timeZone)

actual fun dateTimeFormat(
dateStyle: DateFormatStyle,
timeStyle: DateFormatStyle,
timeZone: TimeZone,
locale: Locale
): DateFormatter = createDateFormatter(DateFormat.getDateTimeInstance(dateStyle.javaStyle(), timeStyle.javaStyle(), locale.locale) as SimpleDateFormat, timeZone)
): KalugaDateFormatter = createDateFormatter(DateFormat.getDateTimeInstance(dateStyle.javaStyle(), timeStyle.javaStyle(), locale.locale) as SimpleDateFormat, timeZone)

actual fun patternFormat(pattern: String, timeZone: TimeZone, locale: Locale): DateFormatter = createDateFormatter(SimpleDateFormat(pattern, locale.locale), timeZone)
actual fun patternFormat(pattern: String, timeZone: TimeZone, locale: Locale): KalugaDateFormatter = createDateFormatter(SimpleDateFormat(pattern, locale.locale), timeZone)

private fun createDateFormatter(simpleDateFormat: SimpleDateFormat, timeZone: TimeZone): DateFormatter {
return DateFormatter(simpleDateFormat).apply {
private fun createDateFormatter(simpleDateFormat: SimpleDateFormat, timeZone: TimeZone): KalugaDateFormatter {
return KalugaDateFormatter(simpleDateFormat).apply {
this.timeZone = timeZone
}
}
Expand Down Expand Up @@ -122,13 +123,13 @@ actual class DateFormatter private constructor(private val format: SimpleDateFor
get() = symbols.amPmStrings.toList()[1]
set(value) { updateSymbols { it.amPmStrings = it.amPmStrings.toMutableList().apply { this[1] = value }.toTypedArray() } }

actual fun format(date: Date): String = format.format(date.calendar.time)
actual fun parse(string: String): Date? {
actual fun format(date: KalugaDate): String = format.format(date.date)
actual fun parse(string: String): KalugaDate? {
val currentTimeZone = timeZone
return try {
format.parse(string)?.let { date ->
val calendar = format.calendar.clone() as Calendar
Date(
DefaultKalugaDate(
calendar.apply {
time = date
timeZone = currentTimeZone.timeZone
Expand Down
Loading

0 comments on commit a0f3207

Please sign in to comment.