Skip to content

Commit a295e03

Browse files
authored
Merge pull request #137 from icerockdev/develop
Release 0.13.2
2 parents 5f1cdce + 33158e3 commit a295e03

14 files changed

Lines changed: 78 additions & 83 deletions

File tree

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
![moko-resources](img/logo.png)
2-
[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0) [![Download](https://api.bintray.com/packages/icerockdev/moko/moko-resources/images/download.svg) ](https://bintray.com/icerockdev/moko/moko-resources/_latestVersion) ![kotlin-version](https://img.shields.io/badge/kotlin-1.4.0-orange)
2+
[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0) [![Download](https://api.bintray.com/packages/icerockdev/moko/moko-resources/images/download.svg) ](https://bintray.com/icerockdev/moko/moko-resources/_latestVersion) ![kotlin-version](https://img.shields.io/badge/kotlin-1.4.21-orange)
33

44
# Mobile Kotlin resources
55
This is a Kotlin MultiPlatform library that provides access to the resources on iOS & Android with the support of the default system localization.
@@ -52,6 +52,8 @@ This is a Kotlin MultiPlatform library that provides access to the resources on
5252
- kotlin 1.4.0
5353
- 0.13.0
5454
- 0.13.1
55+
- kotlin 1.4.21
56+
- 0.13.2
5557

5658
## Installation
5759
root build.gradle
@@ -62,7 +64,7 @@ buildscript {
6264
}
6365
6466
dependencies {
65-
classpath "dev.icerock.moko:resources-generator:0.13.1"
67+
classpath "dev.icerock.moko:resources-generator:0.13.2"
6668
}
6769
}
6870
@@ -79,7 +81,7 @@ project build.gradle
7981
apply plugin: "dev.icerock.mobile.multiplatform-resources"
8082
8183
dependencies {
82-
commonMainApi("dev.icerock.moko:resources:0.13.1")
84+
commonMainApi("dev.icerock.moko:resources:0.13.2")
8385
}
8486
8587
multiplatformResources {

buildSrc/build.gradle.kts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33
*/
44

55
plugins {
6-
id("org.jetbrains.kotlin.jvm") version("1.4.0")
6+
id("org.jetbrains.kotlin.jvm") version("1.4.21")
77
}
88

99
repositories {
10-
mavenLocal()
11-
1210
jcenter()
1311
google()
1412

1513
maven { url = uri("https://dl.bintray.com/icerockdev/plugins") }
1614
}
1715

1816
dependencies {
19-
implementation("dev.icerock:mobile-multiplatform:0.7.0")
20-
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0")
17+
implementation("dev.icerock:mobile-multiplatform:0.9.0")
18+
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.21")
2119
implementation("com.android.tools.build:gradle:4.0.1")
2220
}

buildSrc/src/main/kotlin/Deps.kt

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
object Deps {
6-
private const val kotlinVersion = "1.4.0"
6+
private const val kotlinVersion = "1.4.21"
77
private const val androidGradleVersion = "4.0.1"
88

99
private const val androidAppCompatVersion = "1.1.0"
@@ -13,13 +13,13 @@ object Deps {
1313

1414
private const val apacheCommonsTextVersion = "1.3"
1515
private const val kotlinPoetVersion = "1.6.0"
16-
private const val kotlinxSerializationVersion = "0.20.0"
16+
private const val kotlinxSerializationVersion = "1.0.0"
1717

1818
private const val detektVersion = "1.7.4"
1919

20-
private const val mokoGraphicsVersion = "0.4.0"
21-
private const val mokoParcelizeVersion = "0.4.0"
22-
const val mokoResourcesVersion = "0.13.1"
20+
private const val mokoGraphicsVersion = "0.5.0"
21+
private const val mokoParcelizeVersion = "0.5.0"
22+
const val mokoResourcesVersion = "0.13.2"
2323

2424
object Android {
2525
const val compileSdk = 28
@@ -79,11 +79,8 @@ object Deps {
7979
object MultiPlatform {
8080
const val mokoResources = "dev.icerock.moko:resources:$mokoResourcesVersion"
8181
const val mokoParcelize = "dev.icerock.moko:parcelize:$mokoParcelizeVersion"
82-
val mokoGraphics = MultiPlatformLibrary(
83-
common = "dev.icerock.moko:graphics:$mokoGraphicsVersion",
84-
iosX64 = "dev.icerock.moko:graphics-iosx64:$mokoGraphicsVersion",
85-
iosArm64 = "dev.icerock.moko:graphics-iosarm64:$mokoGraphicsVersion"
86-
)
82+
val mokoGraphics = "dev.icerock.moko:graphics:$mokoGraphicsVersion"
83+
.defaultMPL(ios = true)
8784

8885
object Tests {
8986
const val kotlinTest =
@@ -97,7 +94,7 @@ object Deps {
9794
const val kotlinPoet =
9895
"com.squareup:kotlinpoet:$kotlinPoetVersion"
9996
const val kotlinxSerialization =
100-
"org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlinxSerializationVersion"
97+
"org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion"
10198
const val apacheCommonsText =
10299
"org.apache.commons:commons-text:$apacheCommonsTextVersion"
103100
const val detektFormatting =
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

plugins/resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ class MultiplatformResourcesPlugin : Plugin<Project> {
7474
val androidPackage = getAndroidPackage(manifestFile)
7575

7676
val generatedDir = File(target.buildDir, "generated/moko")
77-
val mrClassPackage: String = requireNotNull(mrExtension.multiplatformResourcesPackage)
77+
val mrClassPackage: String = requireNotNull(mrExtension.multiplatformResourcesPackage) {
78+
"multiplatformResources.multiplatformResourcesPackage is required!" +
79+
" please configure moko-resources plugin correctly."
80+
}
7881
val sourceInfo = SourceInfo(
7982
generatedDir,
8083
commonResources,

plugins/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ColorsGenerator.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ abstract class ColorsGenerator(
7878
fun getColor(color: String?): String? {
7979
return if (color?.startsWith(XmlColorReferencePrefix) == true) {
8080
val colorName = color.replace(XmlColorReferencePrefix, "")
81-
colorValues[colorName]
81+
val colorValue = colorValues[colorName]
82+
getColor(colorValue)
8283
} else {
83-
color
84+
color?.removePrefix("#")?.removePrefix("0x")
8485
}
8586
}
8687

@@ -109,9 +110,7 @@ abstract class ColorsGenerator(
109110
else -> {
110111
singleColor = xmlNode.textContent
111112
singleColor?.let {
112-
if (!it.startsWith(XmlColorReferencePrefix)) {
113-
colorValues[colorName] = it
114-
}
113+
colorValues[colorName] = it
115114
}
116115
}
117116
}

plugins/resources-generator/src/main/kotlin/dev/icerock/gradle/generator/ios/IosColorsGenerator.kt

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import dev.icerock.gradle.generator.ios.IosMRGenerator.Companion.ASSETS_DIR_NAME
1313
import dev.icerock.gradle.utils.ArgbColor
1414
import dev.icerock.gradle.utils.parseRgbaColor
1515
import kotlinx.serialization.json.JsonObject
16-
import kotlinx.serialization.json.json
17-
import kotlinx.serialization.json.jsonArray
16+
import kotlinx.serialization.json.buildJsonArray
17+
import kotlinx.serialization.json.buildJsonObject
18+
import kotlinx.serialization.json.put
1819
import org.gradle.api.file.FileTree
1920
import java.io.File
2021

@@ -43,6 +44,7 @@ class IosColorsGenerator(
4344
val colorContentObj = if (colorNode.isThemed()) {
4445
@Suppress("MagicNumber")
4546
val lightColor = parseRgbaColor(colorNode.lightColor!!.toLong(16))
47+
4648
@Suppress("MagicNumber")
4749
val darkColor = parseRgbaColor(colorNode.darkColor!!.toLong(16))
4850

@@ -54,53 +56,55 @@ class IosColorsGenerator(
5456
val lightColorObj = buildAppearancesIdiomJsonBlock("light", lightColor)
5557
val darkColorObj = buildAppearancesIdiomJsonBlock("dark", darkColor)
5658

57-
jsonArray {
58-
+anyColor
59-
+lightColorObj
60-
+darkColorObj
59+
buildJsonArray {
60+
add(anyColor)
61+
add(lightColorObj)
62+
add(darkColorObj)
6163
}
6264
} else {
6365
@Suppress("MagicNumber")
6466
val singleColor = parseRgbaColor(colorNode.singleColor!!.toLong(16))
65-
jsonArray { +buildColorIdiomJsonObj(singleColor) }
67+
buildJsonArray {
68+
add(buildColorIdiomJsonObj(singleColor))
69+
}
6670
}
6771

68-
val resultObj = json {
69-
"colors" to colorContentObj
70-
"info" to json {
71-
"author" to "xcode"
72-
"version" to 1
73-
}
72+
val resultObj = buildJsonObject {
73+
put("colors", colorContentObj)
74+
put("info", buildJsonObject {
75+
put("author", "xcode")
76+
put("version", 1)
77+
})
7478
}
7579
contentsFile.writeText(resultObj.toString())
7680
}
7781
}
7882

79-
private fun buildColorJsonObj(argbColor: ArgbColor): JsonObject = json {
80-
"color-space" to "srgb"
81-
"components" to json {
82-
"alpha" to argbColor.a
83-
"red" to argbColor.r
84-
"green" to argbColor.g
85-
"blue" to argbColor.b
86-
}
83+
private fun buildColorJsonObj(argbColor: ArgbColor): JsonObject = buildJsonObject {
84+
put("color-space", "srgb")
85+
put("components", buildJsonObject {
86+
put("alpha", argbColor.a)
87+
put("red", argbColor.r)
88+
put("green", argbColor.g)
89+
put("blue", argbColor.b)
90+
})
8791
}
8892

89-
private fun buildColorIdiomJsonObj(argbColor: ArgbColor): JsonObject = json {
90-
"color" to buildColorJsonObj(argbColor)
91-
"idiom" to "universal"
93+
private fun buildColorIdiomJsonObj(argbColor: ArgbColor): JsonObject = buildJsonObject {
94+
put("color", buildColorJsonObj(argbColor))
95+
put("idiom", "universal")
9296
}
9397

9498
private fun buildAppearancesIdiomJsonBlock(valueTag: String, argbColor: ArgbColor): JsonObject {
95-
return json {
96-
"appearances" to jsonArray {
97-
+json {
98-
"appearance" to "luminosity"
99-
"value" to valueTag
100-
}
101-
}
102-
"color" to buildColorJsonObj(argbColor)
103-
"idiom" to "universal"
99+
return buildJsonObject {
100+
put("appearances", buildJsonArray {
101+
add(buildJsonObject {
102+
put("appearance", "luminosity")
103+
put("value", valueTag)
104+
})
105+
})
106+
put("color", buildColorJsonObj(argbColor))
107+
put("idiom", "universal")
104108
}
105109
}
106110
}

resources/src/commonMain/kotlin/dev/icerock/moko/resources/StringResource.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ import dev.icerock.moko.resources.desc.StringDesc
99

1010
expect class StringResource
1111

12-
fun StringResource.format(vararg args: Any) = StringDesc.ResourceFormatted(this, args)
12+
@Suppress("SpreadOperator")
13+
fun StringResource.format(vararg args: Any) = StringDesc.ResourceFormatted(this, *args)
1314
fun StringResource.format(args: List<Any>) = StringDesc.ResourceFormatted(this, args)

sample/android-app/src/androidTest/java/com/icerockdev/StringResourcesTestEn.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ class StringResourcesTestEn : StringResourcesTest() {
1515
override val locale: String = "en"
1616

1717
override val stringAndPluralsCheck: String
18-
get() = "test\ntest 2\ntest 3\nTest Project\nsome raw string\nother\none\nother\nother"
19-
// commented while not fix https://youtrack.jetbrains.com/issue/KT-41384
20-
// \nnested test"
18+
get() = "test\ntest 2\ntest 3\nTest Project\nsome raw string\nother\none\nother\nother\nnested test"
2119

2220
override val stringDescsCheck: String
2321
get() = "test\ntest\nTest data 9\nother\nother\n10 items\nraw string\nraw string" +

sample/android-app/src/androidTest/java/com/icerockdev/StringResourcesTestRu.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ class StringResourcesTestRu : StringResourcesTest() {
1515
override val locale: String = "ru"
1616

1717
override val stringAndPluralsCheck: String
18-
get() = "тест\nтест 2\nтест 3\nТестовый проект\nsome raw string\nмного\nодин\nнесколько\nнесколько"
19-
// commented while not fix https://youtrack.jetbrains.com/issue/KT-41384
20-
// \nтест вложенный"
18+
get() = "тест\nтест 2\nтест 3\nТестовый проект\nsome raw string\nмного\nодин\nнесколько\nнесколько\nтест вложенный"
2119

2220
override val stringDescsCheck: String
2321
get() = "тест\nтест\nТестовые данные 9\nмного\nмного\n10 элементов\nraw string\nraw string\n" +

0 commit comments

Comments
 (0)