Skip to content

Commit

Permalink
add demo activity
Browse files Browse the repository at this point in the history
  • Loading branch information
hbb20 committed Nov 18, 2023
1 parent 9b0e3a3 commit f659acf
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 20 deletions.
7 changes: 5 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ android {
versionCode = BuildData.versionCode
versionName = BuildData.versionName
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}
buildFeatures {
dataBinding = true
Expand All @@ -31,10 +34,10 @@ android {
composeOptions {
kotlinCompilerExtensionVersion = Versions.COMPOSE_COMPILER
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
jvmTarget = "1.8"
}

packagingOptions {
jniLibs {
excludes += setOf("META-INF/licenses/**")
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".CountryPickerViewDemoActivity"></activity>
<activity
android:name=".compose.ComposeDemoActivity"
android:exported="false"
android:label="@string/title_activity_compose_demo"
android:theme="@style/AppTheme" />
<activity android:name=".CountryPickerViewDemoActivity" />
<activity android:name=".OpenDialogDirectlyActivity" />
<activity android:name=".CustomRecyclerViewActivity" />
<activity android:name=".MainActivity"
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class DemoApplication : Application() {

override fun onCreate() {
super.onCreate()
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}
// if (BuildConfig.DEBUG) {
// Timber.plant(Timber.DebugTree())
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.hbb20.CountryPickerView
import com.hbb20.androidcountrypicker.compose.ComposeDemoActivity
import com.hbb20.androidcountrypicker.databinding.ActivityMainBinding
import com.hbb20.contrypicker.flagpack1.FlagPack1
import com.hbb20.countrypicker.flagprovider.CPFlagImageProvider
Expand Down Expand Up @@ -48,4 +49,8 @@ class MainActivity : AppCompatActivity() {
fun openCpViewDemo(view: View) {
startActivity(Intent(this, CountryPickerViewDemoActivity::class.java))
}

fun openComposeDemo(view: View) {
startActivity(Intent(this, ComposeDemoActivity::class.java))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.hbb20.androidcountrypicker.compose

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.hbb20.countrypicker.compose.CountryPicker

class ComposeDemoActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colors.background
) {
val (countryCode, setCountryCode) = remember { mutableStateOf<String?>("In") }
Column {
CountryPicker(alpha2Code = countryCode) {
setCountryCode(it?.alpha2)
}
}
}
}
}
}
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
MaterialTheme {
Greeting("Android")
}
}
12 changes: 12 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@
android:paddingLeft="8dp"
android:text="CP View Demo"
android:textStyle="bold" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
android:onClick="openComposeDemo"
android:paddingVertical="16dp"
android:paddingStart="8dp"
android:paddingLeft="8dp"
android:text="Compose Demo"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
<string name="file_icon">File icon</string>
<string name="category_icon">Category icon</string>
<string name="error_icon">Error Icon</string>
<string name="title_activity_compose_demo">ComposeDemoActivity</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ fun CountryPickerDialog(
) {
Dialog(
onDismissRequest = { onDismissRequest() },
properties = DialogProperties(usePlatformDefaultWidth = true)
properties = DialogProperties(usePlatformDefaultWidth = false)
) {
DefaultCountryPickerDialogContent(
quickAccessCountriesCodes = quickAccessCountries,
Expand Down Expand Up @@ -332,7 +332,7 @@ private fun DefaultCountryPickerDialogContent(
}
val filteredQuickAccessCountries = remember(showFilter, quickAccessCountries, searchQuery) {
if (showFilter == false) emptyList()
else quickAccessCountries.filter { queryFilter(it, searchQuery) }
else quickAccessCountries.filter { queryFilter(it, searchQuery) }.distinctBy(CPCountry::alpha2)
}
Column {
if (showFilter) {
Expand Down Expand Up @@ -460,21 +460,11 @@ private fun CountryListItemRowLayout(
}
Column(modifier = Modifier.weight(1f)) {
Text(
text = "${country.name} (${country.alpha2})",
text = country.name,
style = MaterialTheme.typography.body1,
color = MaterialTheme.colors.onSurface,
)
Text(
text = "${country.capitalEnglishName} - ${country.population}",
style = MaterialTheme.typography.body1,
color = MaterialTheme.colors.onSurface
)
}
Text(
text = "+${country.phoneCode}",
style = MaterialTheme.typography.body2,
color = MaterialTheme.colors.onBackground
)
}
}

Expand Down

0 comments on commit f659acf

Please sign in to comment.