Skip to content

Commit

Permalink
2.2.4 release prep - CI and readme improvements (#48)
Browse files Browse the repository at this point in the history
* 2.2.4 release prep - CI and readme improvements

* Refactoring, gradle config improvements
  • Loading branch information
hbmartin authored Oct 12, 2023
1 parent 5280bed commit d29fd62
Show file tree
Hide file tree
Showing 19 changed files with 130 additions and 108 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ on:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: set up JDK 17
Expand All @@ -23,11 +21,9 @@ jobs:
uses: gradle/wrapper-validation-action@v1
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Detekt
- name: Detekt (Typed)
run: ./gradlew :ccp:detektMain
- name: Lint
run: ./gradlew :ccp:lint
- name: Paparazzi snapshot test
run: ./gradlew :ccp:verifyPaparazziDebug
- name: Check (Lint and test)
run: ./gradlew :ccp:check
- name: Build with Gradle
run: ./gradlew build
run: ./gradlew assemble
29 changes: 16 additions & 13 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
Expand Down Expand Up @@ -59,8 +59,7 @@ representative at an online or offline event.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
.
reported to the community leaders responsible for enforcement.
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
Expand Down Expand Up @@ -106,7 +105,7 @@ Violating these terms may lead to a permanent ban.
### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
Expand All @@ -115,14 +114,18 @@ the community.
## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
version 2.1, available at
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].

Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).

[homepage]: https://www.contributor-covenant.org
Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].

For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
[https://www.contributor-covenant.org/translations][translations].

[homepage]: https://www.contributor-covenant.org
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
[Mozilla CoC]: https://github.com/mozilla/diversity
[FAQ]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations
29 changes: 14 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ See [MainActivity in the sample app](https://github.com/jump-sdk/jetpack_compose
Also check out the [ComposeCountryCodePicker documentation](https://jump-sdk.github.io/jetpack_compose_country_code_picker_emoji/ccp/com.togitech.ccp.component/-togi-country-code-picker.html) for all available composables and utilities.

```kotlin
var phoneNumber by rememberSaveable { mutableStateOf("") }
var fullPhoneNumber by rememberSaveable { mutableStateOf("") }
var phoneNumber: String by rememberSaveable { mutableStateOf("") }
var fullPhoneNumber: String by rememberSaveable { mutableStateOf("") }
var isNumberValid: Boolean by rememberSaveable { mutableStateOf(false) }

TogiCountryCodePicker(
Expand Down Expand Up @@ -80,35 +80,34 @@ Step 1: In the build.gradle add Jitpack repository.
In Groovy:

```groovy
repositories {
maven { url 'https://jitpack.io' }
}
repositories {
maven { url 'https://jitpack.io' }
}
```

In Kts:

```kotlin
repositories {
maven("https://jitpack.io")
}

repositories {
maven("https://jitpack.io")
}
```

Step 2. Add the dependency
Step 2. Add the dependency - n.b. this currently does not support Material 3.

```kotlin
dependencies {
implementation("com.github.jump-sdk:jetpack_compose_country_code_picker_emoji:2.2.0")
}
dependencies {
implementation("androidx.compose.material:material:1.5.3")
implementation("com.github.jump-sdk:jetpack_compose_country_code_picker_emoji:2.2.4")
}
```

## Contributing

* [PRs](https://github.com/jump-sdk/jetpack_compose_country_code_picker_emoji/pulls) and [bug reports / feature requests](https://github.com/jump-sdk/jetpack_compose_country_code_picker_emoji/issues) are welcome!
* This project is linted with [ktlint](https://github.com/pinterest/ktlint) and statically checked with [detekt](https://github.com/detekt/detekt)
* Additional checking done with [Twitter's](https://twitter.github.io/compose-rules/detekt/) and [appKODE's](https://github.com/appKODE/detekt-rules-compose) Jetpack Compose rules for Detekt
* Treat other people with helpfulness, gratitude, and consideration! See the [JetBrains CoC](https://confluence.jetbrains.com/display/ALL/JetBrains+Open+Source+and+Community+Code+of+Conduct)
* Treat other people with helpfulness, gratitude, and consideration! See the [Code of Conduct](https://github.com/jump-sdk/jetpack_compose_country_code_picker_emoji/blob/master/CODE_OF_CONDUCT.md)
* Use precommit hook `./gradlew :ccp:detektMain :ccp:lint :ccp:verifyPaparazziDebug` to check code quality before commit


Expand Down
11 changes: 5 additions & 6 deletions ccp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id("maven-publish")
id("io.gitlab.arturbosch.detekt") version libs.versions.detekt.get()
id("org.jetbrains.dokka")
id("app.cash.paparazzi") version libs.versions.paparazzi.get()
alias(libs.plugins.paparazzi)
}

kotlin {
Expand All @@ -16,8 +16,7 @@ android {
namespace = "com.togitech.ccp"

defaultConfig {
minSdk = 24
targetSdk = 33
minSdk = libs.versions.minSdk.get().toInt()
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -33,7 +32,7 @@ android {
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
jvmTarget = JavaVersion.VERSION_17.toString()
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
composeOptions {
Expand Down Expand Up @@ -67,7 +66,7 @@ dependencies {
}

detekt {
config = files(project.rootProject.file("detekt.yml"))
config.setFrom(project.rootProject.file("detekt.yml"))
allRules = true
}

Expand All @@ -79,7 +78,7 @@ afterEvaluate {
groupId = "com.togisoft"
artifactId = "jetpack_country_code_picker"
// Update version in README when changing below
version = "2.2.3"
version = "2.2.4"
}
}
}
Expand Down
43 changes: 43 additions & 0 deletions ccp/src/main/java/com/togitech/ccp/component/Autofill.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.togitech.ccp.component

import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.autofill.AutofillNode
import androidx.compose.ui.autofill.AutofillType
import androidx.compose.ui.composed
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.layout.boundsInWindow
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalAutofill
import androidx.compose.ui.platform.LocalAutofillTree

@ExperimentalComposeUiApi
internal fun Modifier.autofill(
autofillTypes: List<AutofillType>,
onFill: (String) -> Unit,
focusRequester: FocusRequester,
): Modifier = this then composed {
val autofill = LocalAutofill.current
val autofillNode = AutofillNode(onFill = onFill, autofillTypes = autofillTypes)
LocalAutofillTree.current += autofillNode

LaunchedEffect(Unit) {
focusRequester.requestFocus()
}

this
.onGloballyPositioned {
autofillNode.boundingBox = it.boundsInWindow()
}
.onFocusChanged { focusState ->
autofill?.run {
if (focusState.isFocused) {
requestAutofillForNode(autofillNode)
} else {
cancelAutofillForNode(autofillNode)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.material.TextFieldDefaults
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Clear
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -25,18 +24,11 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.autofill.AutofillNode
import androidx.compose.ui.autofill.AutofillType
import androidx.compose.ui.composed
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.layout.boundsInWindow
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalAutofill
import androidx.compose.ui.platform.LocalAutofillTree
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -91,7 +83,7 @@ private const val TAG = "TogiCountryCodePicker"
* @param [keyboardActions] An optional [KeyboardActions] to customize keyboard actions.
*/
@OptIn(ExperimentalComposeUiApi::class)
@Suppress("LongMethod", "CyclomaticComplexMethod")
@Suppress("LongMethod")
@Composable
fun TogiCountryCodePicker(
onValueChange: (Pair<PhoneCode, String>, Boolean) -> Unit,
Expand Down Expand Up @@ -192,7 +184,7 @@ fun TogiCountryCodePicker(
onValueChange(country.countryPhoneCode to phoneNumber.text, isNumberValid)
keyboardController?.hide()
coroutineScope.launch {
freeFocus(focusRequester)
focusRequester.safeFreeFocus()
}
},
focusRequester = focusRequester,
Expand Down Expand Up @@ -223,27 +215,15 @@ fun TogiCountryCodePicker(
)
},
trailingIcon = {
clearIcon?.let {
IconButton(
onClick = {
phoneNumber = TextFieldValue("")
isNumberValid = false
onValueChange(country.countryPhoneCode to phoneNumber.text, isNumberValid)
},
if (clearIcon != null) {
ClearIconButton(
imageVector = clearIcon,
colors = colors,
isNumberValid = isNumberValid,
) {
Icon(
imageVector = it,
contentDescription = "Clear",
tint = if (!isNumberValid) {
colors
.trailingIconColor(enabled = true, isError = true)
.value
} else {
colors
.trailingIconColor(enabled = true, isError = false)
.value
},
)
phoneNumber = TextFieldValue("")
isNumberValid = false
onValueChange(country.countryPhoneCode to phoneNumber.text, isNumberValid)
}
}
},
Expand All @@ -258,7 +238,7 @@ fun TogiCountryCodePicker(
onDone = {
keyboardController?.hide()
coroutineScope.launch {
freeFocus(focusRequester)
focusRequester.safeFreeFocus()
}
},
),
Expand All @@ -268,9 +248,9 @@ fun TogiCountryCodePicker(
)
}

private fun freeFocus(focusRequester: FocusRequester) {
private fun FocusRequester.safeFreeFocus() {
try {
focusRequester.freeFocus()
this.freeFocus()
} catch (exception: IllegalStateException) {
Log.e(TAG, "Unable to free focus", exception)
}
Expand All @@ -285,33 +265,18 @@ private fun PlaceholderNumberHint(countryIso: Iso31661alpha2) {
)
}

@ExperimentalComposeUiApi
internal fun Modifier.autofill(
autofillTypes: List<AutofillType>,
onFill: (String) -> Unit,
focusRequester: FocusRequester,
): Modifier = this then composed {
val autofill = LocalAutofill.current
val autofillNode = AutofillNode(onFill = onFill, autofillTypes = autofillTypes)
LocalAutofillTree.current += autofillNode

LaunchedEffect(Unit) {
focusRequester.requestFocus()
}

this
.onGloballyPositioned {
autofillNode.boundingBox = it.boundsInWindow()
}
.onFocusChanged { focusState ->
autofill?.run {
if (focusState.isFocused) {
requestAutofillForNode(autofillNode)
} else {
cancelAutofillForNode(autofillNode)
}
}
}
@Composable
private fun ClearIconButton(
imageVector: ImageVector,
colors: TextFieldColors,
isNumberValid: Boolean,
onClick: () -> Unit,
) = IconButton(onClick = onClick) {
Icon(
imageVector = imageVector,
contentDescription = stringResource(id = R.string.clear),
tint = colors.trailingIconColor(enabled = true, isError = !isNumberValid).value,
)
}

@Preview
Expand Down
1 change: 1 addition & 0 deletions ccp/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@
<string name="search">بحث</string>
<string name="select_country">أختر دولة</string>
<string name="invalid_number">رقم الهاتف غير صحيح</string>
<string name="clear">محو</string>
</resources>
1 change: 1 addition & 0 deletions ccp/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@
<string name="search">Buscar\u2026</string>
<string name="select_country">Seleccionar país</string>
<string name="invalid_number">Numero de telefono invalido</string>
<string name="clear">Borrar</string>
</resources>
Loading

0 comments on commit d29fd62

Please sign in to comment.