-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose Platform information as expect-actual (locale, system, version)
- Loading branch information
1 parent
3c3684b
commit 60f888a
Showing
17 changed files
with
112 additions
and
73 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
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
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
5 changes: 0 additions & 5 deletions
5
shared/src/androidMain/kotlin/com/mirego/kmp/boilerplate/Platform.kt
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
shared/src/androidMain/kotlin/com/mirego/kmp/boilerplate/platform/Platform.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,25 @@ | ||
package com.mirego.kmp.boilerplate.platform | ||
|
||
import android.os.Build | ||
import com.mirego.kmp.boilerplate.common.BuildConfig | ||
|
||
actual fun Platform(): Platform = IOSPlatform() | ||
|
||
private class IOSPlatform : Platform { | ||
override val system = System( | ||
name = "Android", | ||
version = Build.VERSION.SDK_INT.toString() | ||
) | ||
|
||
override val locale = java.util.Locale.getDefault().let { | ||
Locale( | ||
languageCode = it.language, | ||
regionCode = it.country | ||
) | ||
} | ||
|
||
override val version = Version( | ||
name = BuildConfig.VERSION_NAME, | ||
code = BuildConfig.VERSION_CODE | ||
) | ||
} |
14 changes: 0 additions & 14 deletions
14
shared/src/androidUnitTest/kotlin/com.mirego.kmp.boilerplate/AndroidGreetingTest.kt
This file was deleted.
Oops, something went wrong.
12 changes: 11 additions & 1 deletion
12
shared/src/commonMain/kotlin/com/mirego/kmp/boilerplate/Greeting.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 |
---|---|---|
@@ -1,9 +1,19 @@ | ||
package com.mirego.kmp.boilerplate | ||
|
||
import com.mirego.kmp.boilerplate.platform.Platform | ||
import com.mirego.kmp.boilerplate.utils.CFlow | ||
import com.mirego.kmp.boilerplate.utils.wrap | ||
import kotlinx.coroutines.flow.flowOf | ||
|
||
class Greeting { | ||
fun greeting(): CFlow<String> = flowOf("Hello, ${Platform().platform}!").wrap() | ||
private val platform = Platform() | ||
|
||
private val greetingText = buildString { | ||
appendLine("Hello! 👋") | ||
appendLine(platform.system) | ||
appendLine(platform.locale) | ||
appendLine(platform.version) | ||
} | ||
|
||
fun greeting(): CFlow<String> = flowOf(greetingText).wrap() | ||
} |
5 changes: 0 additions & 5 deletions
5
shared/src/commonMain/kotlin/com/mirego/kmp/boilerplate/Platform.kt
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
shared/src/commonMain/kotlin/com/mirego/kmp/boilerplate/platform/Platform.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 @@ | ||
package com.mirego.kmp.boilerplate.platform | ||
|
||
expect fun Platform(): Platform | ||
|
||
interface Platform { | ||
val system: System | ||
val locale: Locale | ||
val version: Version | ||
} | ||
|
||
data class Locale( | ||
val languageCode: String, | ||
val regionCode: String? | ||
) | ||
|
||
data class System( | ||
val name: String, | ||
val version: String | ||
) | ||
|
||
data class Version( | ||
val name: String, | ||
val code: Int | ||
) |
14 changes: 0 additions & 14 deletions
14
shared/src/commonTest/kotlin/com/mirego/kmp/boilerplate/CommonGreetingTest.kt
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
shared/src/iosMain/kotlin/com/mirego/kmp/boilerplate/Platform.kt
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
shared/src/iosMain/kotlin/com/mirego/kmp/boilerplate/platform/Platform.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,33 @@ | ||
package com.mirego.kmp.boilerplate.platform | ||
|
||
import platform.Foundation.NSBundle | ||
import platform.Foundation.NSLocale | ||
import platform.Foundation.currentLocale | ||
import platform.Foundation.languageCode | ||
import platform.Foundation.regionCode | ||
import platform.UIKit.UIDevice | ||
|
||
actual fun Platform(): Platform = AndroidPlatform() | ||
|
||
private class AndroidPlatform : Platform { | ||
override val system = UIDevice.currentDevice.let { | ||
System( | ||
name = it.systemName, | ||
version = it.systemVersion | ||
) | ||
} | ||
|
||
override val locale = NSLocale.currentLocale.let { | ||
Locale( | ||
languageCode = it.languageCode, | ||
regionCode = it.regionCode | ||
) | ||
} | ||
|
||
override val version = NSBundle.mainBundle().infoDictionary()!!.let { | ||
Version( | ||
name = it["CFBundleShortVersionString"] as String, | ||
code = (it["CFBundleVersion"] as String).toInt() | ||
) | ||
} | ||
} |
14 changes: 0 additions & 14 deletions
14
shared/src/iosTest/kotlin/com/mirego/kmp/boilerplate/IosGreetingTest.kt
This file was deleted.
Oops, something went wrong.