Skip to content

Commit 49efed0

Browse files
committed
🐛 fixing small bug
1 parent afb2631 commit 49efed0

6 files changed

Lines changed: 20 additions & 55 deletions

File tree

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ dependencies {
5151
implementation "androidx.compose.ui:ui:$compose_version"
5252
implementation "androidx.compose.material:material:$compose_version"
5353
implementation "androidx.compose.ui:ui-tooling:$compose_version"
54-
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
55-
implementation 'androidx.activity:activity-compose:1.3.1'
54+
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
55+
implementation 'androidx.activity:activity-compose:1.4.0'
5656

5757
testImplementation 'junit:junit:4.+'
5858
androidTestImplementation 'tools.fastlane:screengrab:2.1.0'

app/src/main/java/io/github/farhanroy/codepicker/MainActivity.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ class MainActivity : ComponentActivity() {
3434
fun CountryCodeView() {
3535
Column(modifier = Modifier.padding(16.dp)) {
3636
var country by remember { mutableStateOf("") }
37-
CountryCodeField(pickedCountry = {
38-
})
37+
CountryCodeField {}
3938
Spacer(modifier = Modifier.height(24.dp))
4039
Text("")
4140
}

cccp/src/main/java/io/github/farhanroy/cccp/CountryCodeField.kt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,12 @@ import androidx.compose.ui.unit.dp
2020
import androidx.lifecycle.viewmodel.compose.viewModel
2121
import io.github.farhanroy.cccp.components.CountryCodeDialog
2222
import io.github.farhanroy.cccp.state.DialogState
23-
import io.github.farhanroy.cccp.utils.CCPCountry
2423
import io.github.farhanroy.cccp.utils.getFlagMasterResID
2524

2625
@Composable
2726
fun CountryCodeField(
2827
modifier: Modifier = Modifier,
2928
dialogState: DialogState = viewModel(),
30-
titleDefault: String = "Select Country",
31-
pickedCountry: (CCPCountry) -> Unit
3229
pickedCountry: (String) -> Unit
3330
) {
3431
val textState = remember { mutableStateOf(TextFieldValue(""))}
@@ -44,17 +41,6 @@ fun CountryCodeField(
4441
verticalAlignment = Alignment.CenterVertically
4542
) {
4643

47-
if (dialogState.getCountry().name != "null") {
48-
Image(
49-
painter = painterResource(
50-
id = getFlagMasterResID(
51-
dialogState.getCountry()
52-
)
53-
), contentDescription = null,
54-
)
55-
}
56-
Text(if (dialogState.getCountry().name == "null") titleDefault else dialogState.getCountry().name, Modifier.padding(start = 8.dp, end = 18.dp))
57-
5844
Text(dialogState.getCountry(), Modifier.padding(horizontal = 18.dp))
5945

6046
Icon(imageVector = Icons.Default.ArrowDropDown, contentDescription = null)

cccp/src/main/java/io/github/farhanroy/cccp/components/CountryCodeDialog.kt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package io.github.farhanroy.cccp.components
22

33
import androidx.compose.foundation.background
4-
import androidx.compose.foundation.layout.*
4+
import androidx.compose.foundation.layout.Box
5+
import androidx.compose.foundation.layout.padding
6+
import androidx.compose.foundation.layout.size
57
import androidx.compose.foundation.lazy.LazyColumn
68
import androidx.compose.runtime.Composable
79
import androidx.compose.runtime.MutableState
@@ -12,20 +14,16 @@ import androidx.compose.ui.unit.dp
1214
import androidx.compose.ui.window.Dialog
1315
import androidx.lifecycle.viewmodel.compose.viewModel
1416
import io.github.farhanroy.cccp.state.DialogState
15-
import io.github.farhanroy.cccp.utils.CCPCountry
16-
import io.github.farhanroy.cccp.utils.getLibraryMasterCountriesEnglish
17-
1817
import java.util.*
1918
import kotlin.collections.ArrayList
2019

21-
2220
@Composable
2321
fun CountryCodeDialog(
2422
state: MutableState<TextFieldValue>,
2523
dialogState: DialogState = viewModel()
2624
) {
27-
val countries = getLibraryMasterCountriesEnglish()
28-
var filteredCountries: List<CCPCountry>
25+
val countries = getListOfCountries()
26+
var filteredCountries: List<String>
2927

3028
if (dialogState.getState()) {
3129
Dialog(onDismissRequest = { dialogState.setState(false) }) {
@@ -40,9 +38,9 @@ fun CountryCodeDialog(
4038
filteredCountries = if (searchedText.isEmpty()) {
4139
countries
4240
} else {
43-
val resultList = ArrayList<CCPCountry>()
41+
val resultList = ArrayList<String>()
4442
for (country in countries) {
45-
if (country.name.lowercase(Locale.getDefault())
43+
if (country.lowercase(Locale.getDefault())
4644
.contains(searchedText.lowercase(Locale.getDefault()))
4745
) {
4846
resultList.add(country)
@@ -56,11 +54,12 @@ fun CountryCodeDialog(
5654
}
5755
items(filteredCountries.size) { index ->
5856
CountryItem(
59-
country = filteredCountries[index]
60-
) { selectedCountry ->
61-
dialogState.setState(false)
62-
dialogState.setCountry(selectedCountry)
63-
}
57+
countryText = filteredCountries[index],
58+
onItemClick = { selectedCountry ->
59+
dialogState.setState(false)
60+
dialogState.setCountry(selectedCountry)
61+
}
62+
)
6463
}
6564
}
6665
}
Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
11
package io.github.farhanroy.cccp.components
22

3-
import androidx.compose.foundation.Image
43
import androidx.compose.foundation.clickable
54
import androidx.compose.foundation.layout.*
65
import androidx.compose.material.Text
76
import androidx.compose.runtime.Composable
87
import androidx.compose.ui.Modifier
9-
import androidx.compose.ui.res.painterResource
10-
import androidx.compose.ui.unit.dp
11-
import androidx.compose.ui.unit.sp
12-
import io.github.farhanroy.cccp.utils.CCPCountry
13-
import io.github.farhanroy.cccp.utils.getFlagMasterResID
14-
15-
@Composable
16-
fun CountryItem(country: CCPCountry, onItemClick: (CCPCountry) -> Unit) {
17-
Row(
18-
modifier = Modifier
19-
.clickable(onClick = { onItemClick(country) })
20-
=======
218
import androidx.compose.ui.unit.dp
229
import androidx.compose.ui.unit.sp
2310

@@ -30,12 +17,6 @@ fun CountryItem(countryText: String, onItemClick: (String) -> Unit) {
3017
.fillMaxWidth()
3118
.padding(PaddingValues(8.dp, 16.dp))
3219
) {
33-
Image(
34-
painter = painterResource(
35-
id = getFlagMasterResID(country)
36-
), contentDescription = null,
37-
modifier = Modifier.padding(end = 8.dp)
38-
)
39-
Text(text = country.name, fontSize = 18.sp)
20+
Text(text = countryText, fontSize = 18.sp)
4021
}
4122
}

cccp/src/main/java/io/github/farhanroy/cccp/state/DialogState.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import io.github.farhanroy.cccp.utils.DEFAULT_FLAG_RES
1010
class DialogState: ViewModel() {
1111
private var isOpen: Boolean by mutableStateOf(false)
1212

13-
private var selectedCountry by mutableStateOf(CCPCountry("ad", "376", "null", DEFAULT_FLAG_RES))
13+
private var selectedCountry by mutableStateOf("")
1414

1515
fun setState(state: Boolean) {
1616
isOpen = state
1717
}
1818

1919
fun getState(): Boolean = isOpen
2020

21-
fun setCountry(value: CCPCountry) {
21+
fun setCountry(value: String) {
2222
selectedCountry = value
2323
}
2424

25-
fun getCountry(): CCPCountry = selectedCountry
25+
fun getCountry(): String = selectedCountry
2626
}

0 commit comments

Comments
 (0)