Skip to content

Commit 9782e82

Browse files
committed
fixed compatibility issues
1 parent 516232b commit 9782e82

File tree

4 files changed

+18
-24
lines changed

4 files changed

+18
-24
lines changed

buildSrc/src/main/kotlin/io/androidpoet/countrypicker/Configuration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object Configuration {
66
const val minSdk = 21
77
const val majorVersion = 0
88
const val minorVersion = 1
9-
const val patchVersion = 2
9+
const val patchVersion = 3
1010
const val versionName = "$majorVersion.$minorVersion.$patchVersion"
1111
const val versionCode = 1
1212
const val snapshotVersionName = "$majorVersion.$minorVersion.${patchVersion + 1}-SNAPSHOT"

countrypicker/src/commonMain/kotlin/io/androidpoet/countrypicker/CountryPicker.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import androidx.compose.runtime.setValue
2323
import androidx.compose.ui.graphics.Color
2424
import io.androidpoet.countrypicker.CountryUtils.getCurrentCountry
2525
import io.androidpoet.countrypicker.CountryUtils.loadCountries
26+
import kotlinx.coroutines.Dispatchers
2627
import kotlinx.coroutines.launch
2728

2829
@Composable
@@ -39,7 +40,8 @@ public fun CountryPicker(
3940
val coroutineScope = rememberCoroutineScope()
4041

4142
LaunchedEffect(Unit) {
42-
coroutineScope.launch {
43+
coroutineScope.launch(Dispatchers.Default) {
44+
4345
try {
4446
val loadedCountries = loadCountries(countriesJsonString)
4547
val currentCountry = getCurrentCountry(loadedCountries)

countrypicker/src/commonMain/kotlin/io/androidpoet/countrypicker/ListSaver.kt

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,25 @@ import androidx.compose.runtime.mutableStateOf
2121
import androidx.compose.runtime.saveable.Saver
2222
import androidx.compose.runtime.saveable.listSaver
2323
import androidx.compose.runtime.saveable.rememberSaveable
24-
24+
import kotlinx.serialization.Serializable
25+
import kotlinx.serialization.encodeToString
26+
import kotlinx.serialization.json.Json
27+
@Serializable
2528
public data class CountryPickerState(
2629
val countries: List<Country> = emptyList(),
2730
val currentCountry: Country? = null,
2831
val isLoading: Boolean = false,
2932
val error: String? = null,
3033
)
3134

32-
public val CountryPickerStateSaver: Saver<CountryPickerState, Any> =
33-
listSaver(
34-
save = { state ->
35-
listOf(
36-
state.countries,
37-
state.currentCountry,
38-
state.isLoading,
39-
state.error,
40-
)
41-
},
42-
restore = { items ->
43-
CountryPickerState(
44-
countries = items[0] as List<Country>,
45-
currentCountry = items[1] as? Country,
46-
isLoading = items[2] as Boolean,
47-
error = items[3] as? String,
48-
)
49-
},
50-
)
35+
public val CountryPickerStateSaver: Saver<CountryPickerState, String> = Saver(
36+
save = { state ->
37+
Json.encodeToString(state)
38+
},
39+
restore = { jsonString ->
40+
Json.decodeFromString<CountryPickerState>(jsonString)
41+
}
42+
)
5143

5244
@Composable
5345
public fun rememberCountryPickerState(): MutableState<CountryPickerState> =

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ nexusPlugin = "0.29.0"
55
kotlin = "2.0.20"
66
kotlinBinaryCompatibility = "0.16.3"
77
jvmTarget = "11"
8-
androidxComposeBom = "2024.09.01"
9-
androidxActivity = "1.9.1"
8+
androidxComposeBom = "2024.05.00"
9+
androidxActivity = "1.9.2"
1010
androidxTest = "1.6.2"
1111
baselineProfiles = "1.3.1"
1212
uiAutomator = "2.3.0"

0 commit comments

Comments
 (0)