-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from icerockdev/develop
release 0.6.0
- Loading branch information
Showing
28 changed files
with
354 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: KMP library compilation check | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
runs-on: macOS-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Set up JDK 1.8 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 1.8 | ||
- name: Build and publish local | ||
run: ./gradlew -PlibraryPublish :gradle-plugin:publishPluginPublicationToMavenLocal :resources:publishToMavenLocal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: KMP library publish | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
build: | ||
runs-on: macOS-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Set up JDK 1.8 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 1.8 | ||
- name: Build and publish to Bintray | ||
run: ./gradlew -PlibraryPublish :gradle-plugin:publishPluginPublicationToBintrayRepository :resources:publishAllPublicationsToBintrayRepository -DBINTRAY_USER=${{ secrets.BINTRAY_USER }} -DBINTRAY_KEY=${{ secrets.BINTRAY_KEY }} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
![moko-resources](img/logo.png) | ||
[![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.3.60-orange) | ||
[![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.3.61-orange) | ||
|
||
# Mobile Kotlin resources | ||
This is a Kotlin MultiPlatform library that provides access to the resources on iOS & Android with the support of the default system localization. | ||
|
@@ -16,7 +16,7 @@ This is a Kotlin MultiPlatform library that provides access to the resources on | |
- [License](#license) | ||
|
||
## Features | ||
- **Strings, Plurals, Drawables** to access the corresponding resources from common code; | ||
- **Strings, Plurals, Images** to access the corresponding resources from common code; | ||
- **StringDesc** for lifecycle-aware access to resources and unified localization on both platforms. | ||
|
||
## Requirements | ||
|
@@ -32,6 +32,8 @@ This is a Kotlin MultiPlatform library that provides access to the resources on | |
- 0.4.0 | ||
- kotlin 1.3.60 | ||
- 0.5.0 | ||
- kotlin 1.3.61 | ||
- 0.6.0 | ||
|
||
## Installation | ||
root build.gradle | ||
|
@@ -42,7 +44,7 @@ buildscript { | |
} | ||
dependencies { | ||
classpath "dev.icerock.moko:resources-generator:0.5.0" | ||
classpath "dev.icerock.moko:resources-generator:0.6.0" | ||
} | ||
} | ||
|
@@ -59,7 +61,7 @@ project build.gradle | |
apply plugin: "dev.icerock.mobile.multiplatform-resources" | ||
dependencies { | ||
commonMainApi("dev.icerock.moko:resources:0.5.0") | ||
commonMainApi("dev.icerock.moko:resources:0.6.0") | ||
} | ||
multiplatformResources { | ||
|
@@ -218,6 +220,25 @@ let string1 = getUserName(user: user).localized() // we got name from User model | |
let string2 = getUserName(user: null).localized() // we got name_placeholder from resources | ||
``` | ||
|
||
### Example 6 - pass image | ||
Image resources directory is `commonMain/resources/MR/images` with support of nested directories. | ||
Image name should be end with one of: | ||
- `@0.75x` - android ldpi; | ||
- `@1x` - android mdpi, ios 1x; | ||
- `@1.5x` - android hdpi; | ||
- `@2x` - android xhdpi, ios 2x; | ||
- `@3x` - android xxhdpi, ios 3x; | ||
- `@4x` - android xxxhdpi. | ||
Supported `png` and `jpg` resources for now. | ||
|
||
If we add to `commonMain/resources/MR/images` files: | ||
- `[email protected]` | ||
- `[email protected]` | ||
|
||
We got autogenerated `MR.images.home_black_18` `ImageResource` in code, that we can use: | ||
- Android: `imageView.setImageResource(image.drawableResId)` | ||
- iOS: `imageView.image = image.toUIImage()` | ||
|
||
## Samples | ||
Please see more examples in the [sample directory](sample). | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/AndroidImagesGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.gradle.generator.image | ||
|
||
import com.squareup.kotlinpoet.ClassName | ||
import com.squareup.kotlinpoet.CodeBlock | ||
import com.squareup.kotlinpoet.KModifier | ||
import org.gradle.api.file.FileTree | ||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet | ||
import java.io.File | ||
|
||
class AndroidImagesGenerator( | ||
sourceSet: KotlinSourceSet, | ||
inputFileTree: FileTree, | ||
private val androidRClassPackage: String | ||
) : ImagesGenerator( | ||
sourceSet = sourceSet, | ||
inputFileTree = inputFileTree | ||
) { | ||
override fun getClassModifiers(): Array<KModifier> = arrayOf(KModifier.ACTUAL) | ||
|
||
override fun getPropertyModifiers(): Array<KModifier> = arrayOf(KModifier.ACTUAL) | ||
|
||
override fun getPropertyInitializer(key: String): CodeBlock? { | ||
return CodeBlock.of("ImageResource(R.drawable.%L)", key) | ||
} | ||
|
||
override fun getImports(): List<ClassName> = listOf( | ||
ClassName(androidRClassPackage, "R") | ||
) | ||
|
||
override fun generateResources( | ||
resourcesGenerationDir: File, | ||
keyFileMap: Map<String, List<File>> | ||
) { | ||
keyFileMap.flatMap { (key, files) -> | ||
files.map { key to it } | ||
}.forEach { (key, file) -> | ||
val scale = file.nameWithoutExtension.substringAfter("@").substringBefore("x") | ||
val drawableDirName = "drawable-" + when (scale) { | ||
"0.75" -> "ldpi" | ||
"1" -> "mdpi" | ||
"1.5" -> "hdpi" | ||
"2" -> "xhdpi" | ||
"3" -> "xxhdpi" | ||
"4" -> "xxxhdpi" | ||
else -> { | ||
println("ignore $file - unknown scale ($scale)") | ||
return@forEach | ||
} | ||
} | ||
|
||
val drawableDir = File(resourcesGenerationDir, drawableDirName) | ||
file.copyTo(File(drawableDir, "$key.${file.extension}")) | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
gradle-plugin/src/main/kotlin/dev/icerock/gradle/generator/image/CommonImagesGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.gradle.generator.image | ||
|
||
import com.squareup.kotlinpoet.CodeBlock | ||
import com.squareup.kotlinpoet.KModifier | ||
import org.gradle.api.file.FileTree | ||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet | ||
|
||
class CommonImagesGenerator( | ||
sourceSet: KotlinSourceSet, | ||
inputFileTree: FileTree | ||
) : ImagesGenerator( | ||
sourceSet = sourceSet, | ||
inputFileTree = inputFileTree | ||
) { | ||
override fun getClassModifiers(): Array<KModifier> = emptyArray() | ||
|
||
override fun getPropertyModifiers(): Array<KModifier> = emptyArray() | ||
|
||
override fun getPropertyInitializer(key: String): CodeBlock? = null | ||
} |
Oops, something went wrong.