From 747a0298947530d1b392679d6b6bcc5bc13e80f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9luchu?= Date: Sun, 31 Oct 2021 11:53:26 +0100 Subject: [PATCH] Rename networkBoundResource and include SearchField --- .../ui/lists/{LazyGridFor.kt => LazyGrid.kt} | 0 .../ui/modifier/Modifier.kt | 12 +- .../ui/textfields/SearchWithLabelTexField.kt | 107 ++++++++++++++++++ .../utils/network/NetworkBoundResource.kt | 2 +- 4 files changed, 119 insertions(+), 2 deletions(-) rename jchucomponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/ui/lists/{LazyGridFor.kt => LazyGrid.kt} (100%) create mode 100644 jchucomponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/ui/textfields/SearchWithLabelTexField.kt diff --git a/jchucomponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/ui/lists/LazyGridFor.kt b/jchucomponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/ui/lists/LazyGrid.kt similarity index 100% rename from jchucomponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/ui/lists/LazyGridFor.kt rename to jchucomponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/ui/lists/LazyGrid.kt diff --git a/jchucomponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/ui/modifier/Modifier.kt b/jchucomponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/ui/modifier/Modifier.kt index f3d7de72..f7bfbb6f 100644 --- a/jchucomponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/ui/modifier/Modifier.kt +++ b/jchucomponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/ui/modifier/Modifier.kt @@ -1,8 +1,18 @@ package com.jeluchu.jchucomponentscompose.ui.modifier +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp @Composable -fun Int.cornerRadius() = RoundedCornerShape(this.dp) \ No newline at end of file +fun Int.cornerRadius() = RoundedCornerShape(this.dp) + +@Composable +fun Int.Height() = Spacer(modifier = Modifier.height(this.dp)) + +@Composable +fun Int.Width() = Spacer(modifier = Modifier.width(this.dp)) \ No newline at end of file diff --git a/jchucomponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/ui/textfields/SearchWithLabelTexField.kt b/jchucomponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/ui/textfields/SearchWithLabelTexField.kt new file mode 100644 index 00000000..3925163c --- /dev/null +++ b/jchucomponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/ui/textfields/SearchWithLabelTexField.kt @@ -0,0 +1,107 @@ +package com.jeluchu.jchucomponentscompose.ui.textfields + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.text.KeyboardActions +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.material.* +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Search +import androidx.compose.runtime.Composable +import androidx.compose.runtime.MutableState +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalFocusManager +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.TextFieldValue +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import com.jeluchu.jchucomponentscompose.core.extensions.strings.empty + +@Composable +fun SearchView( + modifier: Modifier = Modifier, + state: MutableState, + labelText: String = String.empty(), + styleLabel: TextStyle = LocalTextStyle.current, + colorLabelText: Color = Color.DarkGray, + cornerRadious: Dp = 15.dp, + bgContent: Color = Color.DarkGray, + bgCard: Color = Color.White +) { + + val focusManager = LocalFocusManager.current + + Row( + modifier = modifier + ) { + + TextField( + label = { + Text( + text = labelText, + style = styleLabel, + color = colorLabelText + ) + }, + value = state.value, + modifier = Modifier + .clip(RoundedCornerShape(cornerRadious)) + .background(bgCard) + .fillMaxWidth() + .height(53.dp), + textStyle = TextStyle( + fontSize = 16.sp, + fontWeight = FontWeight.Bold + ), + onValueChange = { value -> + state.value = value + }, colors = TextFieldDefaults.textFieldColors( + textColor = bgContent, + disabledTextColor = Color.Transparent, + backgroundColor = bgCard, + focusedIndicatorColor = Color.Transparent, + errorIndicatorColor = Color.Transparent, + unfocusedIndicatorColor = Color.Transparent, + disabledIndicatorColor = Color.Transparent, + cursorColor = bgContent + ), + leadingIcon = { + Icon( + Icons.Default.Search, + tint = bgContent, + contentDescription = "", + modifier = Modifier + .padding(15.dp) + .size(24.dp) + ) + }, + singleLine = true, + keyboardActions = KeyboardActions( + onDone = { + focusManager.clearFocus() + } + ), + keyboardOptions = KeyboardOptions.Default.copy( + imeAction = ImeAction.Done + ) + ) + + } + +} + +@Preview(showBackground = true) +@Composable +fun SearchViewPreview() { + val textState = remember { mutableStateOf(TextFieldValue("")) } + SearchView(state = textState) +} \ No newline at end of file diff --git a/jchucomponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/utils/network/NetworkBoundResource.kt b/jchucomponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/utils/network/NetworkBoundResource.kt index 7e487009..b3d1d71b 100644 --- a/jchucomponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/utils/network/NetworkBoundResource.kt +++ b/jchucomponentscompose/src/main/java/com/jeluchu/jchucomponentscompose/utils/network/NetworkBoundResource.kt @@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.map import retrofit2.HttpException import java.io.IOException -inline fun networkBoundResourceNew( +inline fun networkBoundResource( crossinline query: () -> Flow, crossinline fetch: suspend () -> RequestType, crossinline saveFetchResult: suspend (RequestType) -> Unit,