Skip to content

Commit 02a0c59

Browse files
committed
colors and search bar customization added
1 parent 6b79d81 commit 02a0c59

File tree

7 files changed

+175
-59
lines changed

7 files changed

+175
-59
lines changed

app/api/app.api

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
public final class io/androidpoet/countrypickerdemo/BuildConfig {
2+
public static final field APPLICATION_ID Ljava/lang/String;
3+
public static final field BUILD_TYPE Ljava/lang/String;
4+
public static final field DEBUG Z
5+
public static final field VERSION_CODE I
6+
public static final field VERSION_NAME Ljava/lang/String;
7+
public fun <init> ()V
8+
}
9+
10+
public final class io/androidpoet/countrypickerdemo/ComposableSingletons$MainActivityKt {
11+
public static final field INSTANCE Lio/androidpoet/countrypickerdemo/ComposableSingletons$MainActivityKt;
12+
public static field lambda-1 Lkotlin/jvm/functions/Function3;
13+
public static field lambda-2 Lkotlin/jvm/functions/Function2;
14+
public static field lambda-3 Lkotlin/jvm/functions/Function2;
15+
public fun <init> ()V
16+
public final fun getLambda-1$app_release ()Lkotlin/jvm/functions/Function3;
17+
public final fun getLambda-2$app_release ()Lkotlin/jvm/functions/Function2;
18+
public final fun getLambda-3$app_release ()Lkotlin/jvm/functions/Function2;
19+
}
20+
21+
public final class io/androidpoet/countrypickerdemo/MainActivity : androidx/activity/ComponentActivity {
22+
public static final field $stable I
23+
public fun <init> ()V
24+
}
25+
26+
public final class io/androidpoet/countrypickerdemo/ui/theme/ColorKt {
27+
public static final fun getPink40 ()J
28+
public static final fun getPink80 ()J
29+
public static final fun getPurple40 ()J
30+
public static final fun getPurple80 ()J
31+
public static final fun getPurpleGrey40 ()J
32+
public static final fun getPurpleGrey80 ()J
33+
}
34+
35+
public final class io/androidpoet/countrypickerdemo/ui/theme/ThemeKt {
36+
public static final fun CountryPickerDemoTheme (ZZLkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V
37+
}
38+
39+
public final class io/androidpoet/countrypickerdemo/ui/theme/TypeKt {
40+
public static final fun getTypography ()Landroidx/compose/material3/Typography;
41+
}
42+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public final class io/androidpoet/countrypicker/baselineprofile/app/BuildConfig {
2+
public static final field APPLICATION_ID Ljava/lang/String;
3+
public static final field BUILD_TYPE Ljava/lang/String;
4+
public static final field DEBUG Z
5+
public fun <init> ()V
6+
}
7+
8+
public final class io/androidpoet/countrypicker/baselineprofile/app/ComposableSingletons$MainActivityKt {
9+
public static final field INSTANCE Lio/androidpoet/countrypicker/baselineprofile/app/ComposableSingletons$MainActivityKt;
10+
public static field lambda-1 Lkotlin/jvm/functions/Function3;
11+
public static field lambda-2 Lkotlin/jvm/functions/Function2;
12+
public fun <init> ()V
13+
public final fun getLambda-1$baselineprofile_app_release ()Lkotlin/jvm/functions/Function3;
14+
public final fun getLambda-2$baselineprofile_app_release ()Lkotlin/jvm/functions/Function2;
15+
}
16+
17+
public final class io/androidpoet/countrypicker/baselineprofile/app/MainActivity : androidx/activity/ComponentActivity {
18+
public static final field $stable I
19+
public fun <init> ()V
20+
}
21+

countrypicker/api/android/countrypicker.api

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
public final class io/androidpoet/countrypicker/ComposableSingletons$CountryItemKt {
2-
public static final field INSTANCE Lio/androidpoet/countrypicker/ComposableSingletons$CountryItemKt;
1+
public final class io/androidpoet/countrypicker/ComposableSingletons$CountryListBottomSheetKt {
2+
public static final field INSTANCE Lio/androidpoet/countrypicker/ComposableSingletons$CountryListBottomSheetKt;
33
public static field lambda-1 Lkotlin/jvm/functions/Function2;
4+
public static field lambda-2 Lkotlin/jvm/functions/Function2;
5+
public static field lambda-3 Lkotlin/jvm/functions/Function2;
46
public fun <init> ()V
57
public final fun getLambda-1$countrypicker_release ()Lkotlin/jvm/functions/Function2;
8+
public final fun getLambda-2$countrypicker_release ()Lkotlin/jvm/functions/Function2;
9+
public final fun getLambda-3$countrypicker_release ()Lkotlin/jvm/functions/Function2;
610
}
711

812
public final class io/androidpoet/countrypicker/CountriesListKt {
@@ -53,3 +57,28 @@ public final class io/androidpoet/countrypicker/CountryPickerKt {
5357
public static final fun CountryPicker (Lkotlin/jvm/functions/Function1;ZLkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;I)V
5458
}
5559

60+
public final class io/androidpoet/countrypicker/CountryPickerState {
61+
public static final field $stable I
62+
public fun <init> ()V
63+
public fun <init> (Ljava/util/List;Lio/androidpoet/countrypicker/Country;ZLjava/lang/String;)V
64+
public synthetic fun <init> (Ljava/util/List;Lio/androidpoet/countrypicker/Country;ZLjava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
65+
public final fun component1 ()Ljava/util/List;
66+
public final fun component2 ()Lio/androidpoet/countrypicker/Country;
67+
public final fun component3 ()Z
68+
public final fun component4 ()Ljava/lang/String;
69+
public final fun copy (Ljava/util/List;Lio/androidpoet/countrypicker/Country;ZLjava/lang/String;)Lio/androidpoet/countrypicker/CountryPickerState;
70+
public static synthetic fun copy$default (Lio/androidpoet/countrypicker/CountryPickerState;Ljava/util/List;Lio/androidpoet/countrypicker/Country;ZLjava/lang/String;ILjava/lang/Object;)Lio/androidpoet/countrypicker/CountryPickerState;
71+
public fun equals (Ljava/lang/Object;)Z
72+
public final fun getCountries ()Ljava/util/List;
73+
public final fun getCurrentCountry ()Lio/androidpoet/countrypicker/Country;
74+
public final fun getError ()Ljava/lang/String;
75+
public fun hashCode ()I
76+
public final fun isLoading ()Z
77+
public fun toString ()Ljava/lang/String;
78+
}
79+
80+
public final class io/androidpoet/countrypicker/ListSaverKt {
81+
public static final fun getCountryPickerStateSaver ()Landroidx/compose/runtime/saveable/Saver;
82+
public static final fun rememberCountryPickerState (Landroidx/compose/runtime/Composer;I)Landroidx/compose/runtime/MutableState;
83+
}
84+

countrypicker/api/desktop/countrypicker.api

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
public final class io/androidpoet/countrypicker/ComposableSingletons$CountryItemKt {
2-
public static final field INSTANCE Lio/androidpoet/countrypicker/ComposableSingletons$CountryItemKt;
1+
public final class io/androidpoet/countrypicker/ComposableSingletons$CountryListBottomSheetKt {
2+
public static final field INSTANCE Lio/androidpoet/countrypicker/ComposableSingletons$CountryListBottomSheetKt;
33
public static field lambda-1 Lkotlin/jvm/functions/Function2;
4+
public static field lambda-2 Lkotlin/jvm/functions/Function2;
5+
public static field lambda-3 Lkotlin/jvm/functions/Function2;
46
public fun <init> ()V
57
public final fun getLambda-1$countrypicker ()Lkotlin/jvm/functions/Function2;
8+
public final fun getLambda-2$countrypicker ()Lkotlin/jvm/functions/Function2;
9+
public final fun getLambda-3$countrypicker ()Lkotlin/jvm/functions/Function2;
610
}
711

812
public final class io/androidpoet/countrypicker/CountriesListKt {
@@ -53,3 +57,28 @@ public final class io/androidpoet/countrypicker/CountryPickerKt {
5357
public static final fun CountryPicker (Lkotlin/jvm/functions/Function1;ZLkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;I)V
5458
}
5559

60+
public final class io/androidpoet/countrypicker/CountryPickerState {
61+
public static final field $stable I
62+
public fun <init> ()V
63+
public fun <init> (Ljava/util/List;Lio/androidpoet/countrypicker/Country;ZLjava/lang/String;)V
64+
public synthetic fun <init> (Ljava/util/List;Lio/androidpoet/countrypicker/Country;ZLjava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
65+
public final fun component1 ()Ljava/util/List;
66+
public final fun component2 ()Lio/androidpoet/countrypicker/Country;
67+
public final fun component3 ()Z
68+
public final fun component4 ()Ljava/lang/String;
69+
public final fun copy (Ljava/util/List;Lio/androidpoet/countrypicker/Country;ZLjava/lang/String;)Lio/androidpoet/countrypicker/CountryPickerState;
70+
public static synthetic fun copy$default (Lio/androidpoet/countrypicker/CountryPickerState;Ljava/util/List;Lio/androidpoet/countrypicker/Country;ZLjava/lang/String;ILjava/lang/Object;)Lio/androidpoet/countrypicker/CountryPickerState;
71+
public fun equals (Ljava/lang/Object;)Z
72+
public final fun getCountries ()Ljava/util/List;
73+
public final fun getCurrentCountry ()Lio/androidpoet/countrypicker/Country;
74+
public final fun getError ()Ljava/lang/String;
75+
public fun hashCode ()I
76+
public final fun isLoading ()Z
77+
public fun toString ()Ljava/lang/String;
78+
}
79+
80+
public final class io/androidpoet/countrypicker/ListSaverKt {
81+
public static final fun getCountryPickerStateSaver ()Landroidx/compose/runtime/saveable/Saver;
82+
public static final fun rememberCountryPickerState (Landroidx/compose/runtime/Composer;I)Landroidx/compose/runtime/MutableState;
83+
}
84+

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ internal fun CountryItem(
3535
name: String,
3636
countryCode: String,
3737
flag: String,
38+
itemBackgroundColor: Color,
39+
textColor: Color,
3840
onItemClick: () -> Unit,
3941
) {
4042
Card(
4143
onClick = onItemClick,
4244
colors =
4345
CardColors(
44-
containerColor = Color.White,
46+
containerColor = itemBackgroundColor,
4547
contentColor = Color.Transparent,
4648
disabledContainerColor = Color.Transparent,
4749
disabledContentColor = Color.Transparent,
@@ -59,19 +61,19 @@ internal fun CountryItem(
5961
text = flag,
6062
fontSize = 24.sp,
6163
modifier = Modifier.padding(end = 16.dp),
62-
color = Color.Black,
64+
color = textColor,
6365
)
6466

6567
Text(
6668
text = name,
6769
style = MaterialTheme.typography.bodyLarge,
6870
modifier = Modifier.weight(1f),
69-
color = Color.Black,
71+
color = textColor,
7072
)
7173
Text(
7274
text = countryCode,
7375
style = MaterialTheme.typography.bodyMedium,
74-
color = Color.Black,
76+
color = textColor,
7577
)
7678
}
7779
}

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

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ internal fun CountryListBottomSheet(
5353
showBottomSheet: Boolean,
5454
onDismiss: () -> Unit,
5555
onItemClick: (Country) -> Unit,
56+
searchEnabled: Boolean,
57+
itemBackgroundColor: Color,
58+
textColor: Color,
59+
searchBarBorderColor: Color
5660
) {
5761
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
5862
val coroutineScope = rememberCoroutineScope()
@@ -95,28 +99,29 @@ internal fun CountryListBottomSheet(
9599
containerColor = Color.White,
96100
) {
97101
Column(modifier = Modifier.fillMaxWidth().background(Color.White)) {
98-
// Search bar
99-
OutlinedTextField(
100-
value = searchQuery,
101-
onValueChange = { searchQuery = it },
102-
modifier = Modifier.fillMaxWidth().padding(16.dp),
103-
placeholder = { Text("Search countries") },
104-
leadingIcon = { Icon(Icons.Default.Search, contentDescription = "Search") },
105-
trailingIcon = {
106-
if (searchQuery.isNotEmpty()) {
107-
IconButton(onClick = { searchQuery = "" }) {
108-
Icon(Icons.Default.Clear, contentDescription = "Clear search")
102+
if (searchEnabled) {
103+
OutlinedTextField(
104+
value = searchQuery,
105+
onValueChange = { searchQuery = it },
106+
modifier = Modifier.fillMaxWidth().padding(16.dp),
107+
placeholder = { Text("Search countries") },
108+
leadingIcon = { Icon(Icons.Default.Search, contentDescription = "Search") },
109+
trailingIcon = {
110+
if (searchQuery.isNotEmpty()) {
111+
IconButton(onClick = { searchQuery = "" }) {
112+
Icon(Icons.Default.Clear, contentDescription = "Clear search")
113+
}
109114
}
110-
}
111-
},
112-
singleLine = true,
113-
shape = RoundedCornerShape(24.dp),
114-
colors =
115-
TextFieldDefaults.outlinedTextFieldColors(
116-
focusedBorderColor = Color.LightGray,
117-
unfocusedBorderColor = Color.LightGray,
118-
),
119-
)
115+
},
116+
singleLine = true,
117+
shape = RoundedCornerShape(24.dp),
118+
colors =
119+
TextFieldDefaults.outlinedTextFieldColors(
120+
focusedBorderColor = searchBarBorderColor,
121+
unfocusedBorderColor = searchBarBorderColor,
122+
),
123+
)
124+
}
120125

121126
// Country list
122127
LazyColumn {
@@ -133,6 +138,8 @@ internal fun CountryListBottomSheet(
133138
onItemClick(country)
134139
}
135140
},
141+
itemBackgroundColor = itemBackgroundColor,
142+
textColor = textColor
136143
)
137144
}
138145
}

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

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,20 @@ import androidx.compose.runtime.LaunchedEffect
2020
import androidx.compose.runtime.getValue
2121
import androidx.compose.runtime.rememberCoroutineScope
2222
import androidx.compose.runtime.setValue
23+
import androidx.compose.ui.graphics.Color
2324
import io.androidpoet.countrypicker.CountryUtils.getCurrentCountry
2425
import io.androidpoet.countrypicker.CountryUtils.loadCountries
2526
import kotlinx.coroutines.launch
2627

27-
// @Composable
28-
// public fun CountryPicker(
29-
// onCountryChanged: (Country) -> Unit,
30-
// showBottomSheet: Boolean,
31-
// onDismiss: () -> Unit,
32-
// ) {
33-
// var currentCountry by rememberSaveable(stateSaver = CountrySaver){ mutableStateOf<Country?>(null) }
34-
// var countries by rememberSaveable(stateSaver = CountrySaver) { mutableStateOf(emptyList<Country>()) }
35-
// LaunchedEffect(Unit) {
36-
// countries = loadCountries(countriesJsonString)
37-
// currentCountry = getCurrentCountry(countries)
38-
// currentCountry?.let { onCountryChanged(it) }
39-
// }
40-
//
41-
// CountryListBottomSheet(
42-
// countries = countries,
43-
// showBottomSheet = showBottomSheet,
44-
// onDismiss = onDismiss,
45-
// onItemClick = {
46-
// currentCountry = it
47-
// onCountryChanged(it)
48-
// },
49-
// )
50-
// }
51-
5228
@Composable
5329
public fun CountryPicker(
5430
onCountryChanged: (Country) -> Unit,
5531
showBottomSheet: Boolean,
5632
onDismiss: () -> Unit,
33+
searchEnabled: Boolean = true,
34+
itemBackgroundColor: Color = Color.White,
35+
textColor: Color = Color.Black,
36+
searchBarColor: Color = Color.LightGray
5737
) {
5838
var state by rememberCountryPickerState()
5939
val coroutineScope = rememberCoroutineScope()
@@ -63,11 +43,10 @@ public fun CountryPicker(
6343
try {
6444
val loadedCountries = loadCountries(countriesJsonString)
6545
val currentCountry = getCurrentCountry(loadedCountries)
66-
state =
67-
state.copy(
68-
countries = loadedCountries,
69-
currentCountry = currentCountry,
70-
)
46+
state = state.copy(
47+
countries = loadedCountries,
48+
currentCountry = currentCountry,
49+
)
7150
currentCountry?.let { onCountryChanged(it) }
7251
} catch (e: Exception) {
7352
}
@@ -82,5 +61,12 @@ public fun CountryPicker(
8261
state = state.copy(currentCountry = country)
8362
onCountryChanged(country)
8463
},
64+
searchEnabled = searchEnabled,
65+
itemBackgroundColor = itemBackgroundColor,
66+
textColor = textColor,
67+
searchBarBorderColor = searchBarColor,
8568
)
8669
}
70+
71+
72+

0 commit comments

Comments
 (0)