From e176b6827a68302ac888676c37a53da45bae0da3 Mon Sep 17 00:00:00 2001 From: Thomas Andres Gomez Date: Sun, 16 Oct 2022 08:43:15 +0200 Subject: [PATCH] Fix wording issue + add authentication autofil. --- app/build.gradle | 3 +- .../authentication/AuthenticationScreen.kt | 45 ++++++++++++++++++- .../home/page/search/FilterSearchPage.kt | 2 +- .../screen/home/page/search/SearchToolbar.kt | 5 ++- app/src/main/res/values-fr/strings.xml | 4 ++ app/src/main/res/values/strings.xml | 4 ++ 6 files changed, 57 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 980a5ff..21c4173 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -91,12 +91,13 @@ dependencies { implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1' implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.5.1" - implementation 'androidx.core:core-ktx:+' debugImplementation "androidx.activity:activity-ktx:1.6.0-rc01" implementation 'androidx.activity:activity-compose:1.5.1' // Android Compose implementation "androidx.compose.ui:ui:1.2.1" + implementation "androidx.compose.ui:ui-util:1.2.1" + implementation "androidx.compose.foundation:foundation:1.2.1" implementation "androidx.compose.material:material:1.2.1" implementation "androidx.constraintlayout:constraintlayout-compose:1.0.1" implementation "androidx.compose.runtime:runtime-livedata:1.2.1" diff --git a/app/src/main/java/com/pixelized/biblib/ui/screen/authentication/AuthenticationScreen.kt b/app/src/main/java/com/pixelized/biblib/ui/screen/authentication/AuthenticationScreen.kt index 6b651af..a293e36 100644 --- a/app/src/main/java/com/pixelized/biblib/ui/screen/authentication/AuthenticationScreen.kt +++ b/app/src/main/java/com/pixelized/biblib/ui/screen/authentication/AuthenticationScreen.kt @@ -16,7 +16,16 @@ import androidx.compose.material.icons.sharp.Visibility import androidx.compose.material.icons.sharp.VisibilityOff import androidx.compose.runtime.* import androidx.compose.ui.Alignment +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.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 import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.AnnotatedString @@ -228,6 +237,7 @@ fun AuthenticationHandler( ////////////////////////////////////// // region: Content Helper Composable +@OptIn(ExperimentalComposeUiApi::class) @Composable private fun LoginField( modifier: Modifier = Modifier, @@ -237,7 +247,10 @@ private fun LoginField( keyboardActions: KeyboardActions = KeyboardActions(), ) { TextField( - modifier = modifier, + modifier = modifier.autofill( + autofillTypes = listOf(AutofillType.Username, AutofillType.EmailAddress), + onFill = onValueChange, + ), value = value, onValueChange = onValueChange, label = { Text(text = stringResource(id = R.string.authentication_login)) }, @@ -249,6 +262,7 @@ private fun LoginField( ) } +@OptIn(ExperimentalComposeUiApi::class) @Composable private fun PasswordField( modifier: Modifier = Modifier, @@ -259,7 +273,10 @@ private fun PasswordField( ) { var passwordVisibility by remember { mutableStateOf(false) } TextField( - modifier = modifier, + modifier = modifier.autofill( + autofillTypes = listOf(AutofillType.Password), + onFill = onValueChange, + ), value = value, onValueChange = onValueChange, label = { Text(text = stringResource(id = R.string.authentication_password)) }, @@ -366,6 +383,30 @@ fun googleStringResource(): AnnotatedString = buildAnnotatedString { // endregion +@OptIn(ExperimentalComposeUiApi::class) +fun Modifier.autofill( + autofillTypes: List, + onFill: ((String) -> Unit), +) = composed { + val autofill = LocalAutofill.current + val autofillNode = AutofillNode(onFill = onFill, autofillTypes = autofillTypes) + LocalAutofillTree.current += autofillNode + + this + .onGloballyPositioned { + autofillNode.boundingBox = it.boundsInWindow() + } + .onFocusChanged { focusState -> + autofill?.run { + if (focusState.isFocused) { + requestAutofillForNode(autofillNode) + } else { + cancelAutofillForNode(autofillNode) + } + } + } +} + @Composable @Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO) @Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) diff --git a/app/src/main/java/com/pixelized/biblib/ui/screen/home/page/search/FilterSearchPage.kt b/app/src/main/java/com/pixelized/biblib/ui/screen/home/page/search/FilterSearchPage.kt index 21077c7..07e0052 100644 --- a/app/src/main/java/com/pixelized/biblib/ui/screen/home/page/search/FilterSearchPage.kt +++ b/app/src/main/java/com/pixelized/biblib/ui/screen/home/page/search/FilterSearchPage.kt @@ -145,7 +145,7 @@ fun CategorySearchPageContent( label = { Text( color = MaterialTheme.colors.onSurface, - text = "Rechercher" + text = stringResource(id = R.string.search_filter_title) ) }, value = search() ?: "", diff --git a/app/src/main/java/com/pixelized/biblib/ui/screen/home/page/search/SearchToolbar.kt b/app/src/main/java/com/pixelized/biblib/ui/screen/home/page/search/SearchToolbar.kt index 2807177..60b12e9 100644 --- a/app/src/main/java/com/pixelized/biblib/ui/screen/home/page/search/SearchToolbar.kt +++ b/app/src/main/java/com/pixelized/biblib/ui/screen/home/page/search/SearchToolbar.kt @@ -21,6 +21,7 @@ import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import com.pixelized.biblib.R import com.pixelized.biblib.ui.scaffold.SearchScaffoldState @@ -79,9 +80,9 @@ fun Search( Text( color = MaterialTheme.colors.onSurface, text = if (state.content != ContentState.PROFILE) { - "Rechercher sur BibLib" + stringResource(id = R.string.search_title) } else { - "Profile" + stringResource(id = R.string.profile_title) } ) }, diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 051b699..f87c2d6 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -42,9 +42,13 @@ Séries Envoyer cet eBook à : + Rechercher sur Biblib + Rechercher Auteur Série Genre Langue + Profile + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5eb55b9..d664c7e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -48,9 +48,13 @@ Series Send this eBook to: + Search on Biblib + Search Author Serie Genre Language + Profil + \ No newline at end of file