Skip to content

Commit

Permalink
Upgrade to AGP 8.1.0 (#16)
Browse files Browse the repository at this point in the history
* Upgrade agp 8
* Migrate to material3
  • Loading branch information
cp-radhika-s authored Aug 16, 2023
1 parent bba2e1b commit 89b55d3
Show file tree
Hide file tree
Showing 17 changed files with 240 additions and 194 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/app-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: set up JDK 11
- name: set up JDK 17
uses: actions/setup-java@v2
with:
distribution: adopt
java-version: 11
java-version: 17
- name: Build with Gradle
run: ./gradlew build
5 changes: 3 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Publish

on:
push:
tags:
Expand All @@ -11,11 +12,11 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: adopt
java-version: 11
java-version: 17

- name: Publish to MavenCentral
run: ./gradlew countrypicker:publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository
Expand Down
61 changes: 33 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,51 @@ Available on [Maven Central](https://repo1.maven.org/maven2/com/canopas/jetcount

Add the dependency
```gradle
implementation 'com.canopas.jetcountrypicker:jetcountrypicker:1.0.5'
implementation 'com.canopas.jetcountrypicker:jetcountrypicker:1.0.9'
```

## How to use ?

```kotlin
Box {
var openBottomSheet by rememberSaveable { mutableStateOf(false) }
var selectedCountry by remember { mutableStateOf<Country?>(null) }
val modalBottomSheetState = rememberModalBottomSheetState(
initialValue = ModalBottomSheetValue.Hidden
)

CountryPickerBottomSheet(
sheetState = modalBottomSheetState,
bottomSheetTitle = {
Text(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
text = stringResource(R.string.select_country_text),
textAlign = TextAlign.Center,
fontWeight = FontWeight.Bold,
fontSize = 20.sp
)
},
onItemSelected = {
selectedCountry = it
}
) {

Box {
CountryTextField(
sheetState = modalBottomSheetState,
label = stringResource(R.string.select_country_text),
modifier = Modifier
.padding(top = 50.dp)
.align(Alignment.TopCenter),
.fillMaxWidth()
.padding(top = 50.dp, start = 40.dp, end = 40.dp),
selectedCountry = selectedCountry,
defaultCountry = countryList(LocalContext.current).firstOrNull { it.code == "IN" }
defaultCountry = countryList(LocalContext.current).firstOrNull { it.code == "IN" },
onShowCountryPicker = {
openBottomSheet = true
}, isPickerVisible = openBottomSheet
)
}

if (openBottomSheet) {
CountryPickerBottomSheet(
bottomSheetTitle = {
Text(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
text = stringResource(R.string.select_country_text),
textAlign = TextAlign.Center,
fontWeight = FontWeight.Bold,
fontSize = 20.sp
)
},
containerColor = Color.White,
onItemSelected = {
selectedCountry = it
openBottomSheet = false
}, onDismissRequest = {
openBottomSheet = false
}
)
}
}
```

# Demo
Expand Down
13 changes: 7 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ plugins {

android {
compileSdk 33
namespace 'com.canopas.campose.countypickerdemo'

defaultConfig {
applicationId "com.canopas.campose.jetcountypicker"
applicationId "com.canopas.campose.countypickerdemo"
minSdk 21
targetSdk 33
versionCode 1
Expand Down Expand Up @@ -54,15 +55,15 @@ dependencies {
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"

implementation platform("androidx.compose:compose-bom:$compose_bom_version")
implementation "androidx.compose.ui:ui"
implementation "androidx.compose.material3:material3"
implementation "androidx.compose.ui:ui-tooling-preview"

implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
implementation 'androidx.activity:activity-compose:1.7.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
}
5 changes: 2 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.canopas.campose.jetcountypicker">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand All @@ -10,7 +9,7 @@
android:supportsRtl="true"
android:theme="@style/Theme.JetCountyPicker">
<activity
android:name=".MainActivity"
android:name="com.canopas.campose.jetcountypicker.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.MaterialTheme
import androidx.compose.material.ModalBottomSheetValue
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.rememberModalBottomSheetState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
Expand All @@ -30,32 +29,44 @@ import com.canopas.campose.countrypicker.CountryPickerBottomSheet
import com.canopas.campose.countrypicker.CountryTextField
import com.canopas.campose.countrypicker.countryList
import com.canopas.campose.countrypicker.model.Country
import com.canopas.campose.countypickerdemo.R
import com.canopas.campose.jetcountypicker.ui.theme.JetCountyPickerTheme

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
JetCountyPickerTheme {
Surface(color = MaterialTheme.colors.background) {
Surface(color = MaterialTheme.colorScheme.background) {
SampleCountryPicker()
}
}
}
}
}

@OptIn(ExperimentalMaterialApi::class)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SampleCountryPicker() {
var openBottomSheet by rememberSaveable { mutableStateOf(false) }
var selectedCountry by remember { mutableStateOf<Country?>(null) }

Box {
var selectedCountry by remember { mutableStateOf<Country?>(null) }
val modalBottomSheetState = rememberModalBottomSheetState(
initialValue = ModalBottomSheetValue.Hidden
CountryTextField(
label = stringResource(R.string.select_country_text),
modifier = Modifier
.fillMaxWidth()
.padding(top = 50.dp, start = 40.dp, end = 40.dp),
selectedCountry = selectedCountry,
defaultCountry = countryList(LocalContext.current).firstOrNull { it.code == "IN" },
onShowCountryPicker = {
openBottomSheet = true
}, isPickerVisible = openBottomSheet
)
}

if (openBottomSheet) {
CountryPickerBottomSheet(
sheetState = modalBottomSheetState,
bottomSheetTitle = {
Text(
modifier = Modifier
Expand All @@ -67,20 +78,14 @@ fun SampleCountryPicker() {
fontSize = 20.sp
)
},
containerColor = Color.White,
onItemSelected = {
selectedCountry = it
openBottomSheet = false
}, onDismissRequest = {
openBottomSheet = false
}
) {
CountryTextField(
sheetState = modalBottomSheetState,
label = stringResource(R.string.select_country_text),
modifier = Modifier
.padding(top = 50.dp)
.align(Alignment.TopCenter),
selectedCountry = selectedCountry,
defaultCountry = countryList(LocalContext.current).firstOrNull { it.code == "IN" }
)
}
)
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
package com.canopas.campose.jetcountypicker.ui.theme

import android.app.Activity
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat

private val DarkColorPalette = darkColors(
private val DarkColorScheme = darkColorScheme().copy(
primary = Purple200,
primaryVariant = Purple700,
secondary = Teal200
secondary = Purple700,
tertiary = Teal200
)

private val LightColorPalette = lightColors(
private val LightColorScheme = lightColorScheme().copy(
primary = Purple500,
primaryVariant = Purple700,
secondary = Teal200
secondary = Purple700,
tertiary = Teal200

/* Other default colors to override
background = Color.White,
Expand All @@ -30,18 +39,30 @@ private val LightColorPalette = lightColors(
@Composable
fun JetCountyPickerTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
dynamicColor: Boolean = true,
content: @Composable() () -> Unit
) {
val colors = if (darkTheme) {
DarkColorPalette
} else {
LightColorPalette
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}

darkTheme -> DarkColorScheme
else -> LightColorScheme
}
val view = LocalView.current
if (!view.isInEditMode) {
SideEffect {
val window = (view.context as Activity).window
window.statusBarColor = colorScheme.primary.toArgb()
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
}
}

MaterialTheme(
colors = colors,
colorScheme = colorScheme,
typography = Typography,
shapes = Shapes,
content = content
)
}
Loading

0 comments on commit 89b55d3

Please sign in to comment.