Skip to content

Commit

Permalink
Improve TextFields UI
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Jan 15, 2025
1 parent 52ffc67 commit 0322629
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.rounded.HelpOutline
Expand Down Expand Up @@ -347,8 +346,10 @@ fun CipherContent(
Spacer(Modifier.height(16.dp))
RoundedTextField(
modifier = Modifier
.container(shape = RoundedCornerShape(24.dp))
.padding(8.dp),
.container(
shape = MaterialTheme.shapes.large,
resultPadding = 8.dp
),
value = key,
startIcon = {
EnhancedIconButton(
Expand Down Expand Up @@ -450,8 +451,10 @@ fun CipherContent(
RoundedTextField(
modifier = Modifier
.padding(top = 8.dp)
.container(shape = RoundedCornerShape(24.dp))
.padding(8.dp),
.container(
shape = MaterialTheme.shapes.large,
resultPadding = 8.dp
),
value = name,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
singleLine = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ fun DrawModeSelector(
.padding(horizontal = 8.dp)
.container(
shape = ContainerShapeDefaults.topShape,
color = MaterialTheme.colorScheme.surface
)
.padding(8.dp),
color = MaterialTheme.colorScheme.surface,
resultPadding = 8.dp
),
value = (value as? DrawMode.Text)?.text ?: "",
singleLine = false,
onValueChange = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package ru.tech.imageresizershrinker.feature.load_net_image.presentation.compone

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Cancel
import androidx.compose.material.icons.rounded.WifiTetheringError
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
Expand All @@ -44,8 +44,10 @@ internal fun LoadNetImageUrlTextField(

RoundedTextField(
modifier = Modifier
.container(shape = RoundedCornerShape(24.dp))
.padding(8.dp),
.container(
shape = MaterialTheme.shapes.large,
resultPadding = 8.dp
),
value = component.targetUrl,
onValueChange = {
component.updateTargetUrl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedModalBottomS
import ru.tech.imageresizershrinker.core.ui.widget.preferences.PreferenceItem
import ru.tech.imageresizershrinker.core.ui.widget.text.TitleItem
import ru.tech.imageresizershrinker.feature.pdf_tools.presentation.components.PageInputField
import ru.tech.imageresizershrinker.feature.pdf_tools.presentation.components.PagesSelectionParser
import ru.tech.imageresizershrinker.feature.pdf_tools.presentation.components.PdfToImagesPreference
import ru.tech.imageresizershrinker.feature.pdf_tools.presentation.components.PdfToolsContentImpl
import ru.tech.imageresizershrinker.feature.pdf_tools.presentation.components.PreviewPdfPreference
import ru.tech.imageresizershrinker.feature.pdf_tools.presentation.components.formatPageOutput
import ru.tech.imageresizershrinker.feature.pdf_tools.presentation.screenLogic.PdfToolsComponent

@OptIn(ExperimentalMaterial3Api::class)
Expand Down Expand Up @@ -401,7 +401,7 @@ fun PdfToolsContent(
if (it.selectedPages.size == it.pagesCount) {
context.getString(R.string.all)
} else {
formatPageOutput(it.selectedPages)
PagesSelectionParser.formatPageOutput(it.selectedPages)
}
} ?: context.getString(R.string.none)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

package ru.tech.imageresizershrinker.feature.pdf_tools.presentation.components

import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -39,14 +38,14 @@ internal fun PageInputField(
onPagesChanged: (List<Int>) -> Unit
) {
var text by remember {
mutableStateOf(formatPageOutput(selectedPages))
mutableStateOf(PagesSelectionParser.formatPageOutput(selectedPages))
}

RoundedTextField(
value = text,
onValueChange = {
text = it
val parsedPages = parsePageInput(it)
val parsedPages = PagesSelectionParser.parsePageInput(it)
onPagesChanged(parsedPages)
},
textStyle = LocalTextStyle.current.copy(
Expand All @@ -55,41 +54,10 @@ internal fun PageInputField(
label = stringResource(R.string.custom_pages),
modifier = Modifier
.container(
resultPadding = 0.dp,
shape = RoundedCornerShape(20.dp)
)
.padding(8.dp),
shape = MaterialTheme.shapes.large,
resultPadding = 8.dp
),
singleLine = false
)
}

internal fun parsePageInput(input: String): List<Int> {
val pages = mutableSetOf<Int>()
val regex = "\\d+(-\\d+)?".toRegex()
regex.findAll(input).forEach { match ->
val rangeParts = match.value.split("-").mapNotNull { it.toIntOrNull() }
when (rangeParts.size) {
1 -> pages.add(rangeParts[0] - 1)
2 -> if (rangeParts[0] <= rangeParts[1]) {
pages.addAll((rangeParts[0] - 1)..(rangeParts[1] - 1))
}
}
}
return pages.sorted()
}

internal fun formatPageOutput(pages: List<Int>): String {
if (pages.isEmpty()) return ""
val result = mutableListOf<String>()
var start = pages[0]
var prev = pages[0]
for (i in 1 until pages.size) {
if (pages[i] != prev + 1) {
result.add(if (start == prev) "${start + 1}" else "${start + 1}-${prev + 1}")
start = pages[i]
}
prev = pages[i]
}
result.add(if (start == prev) "${start + 1}" else "${start + 1}-${prev + 1}")
return result.joinToString(", ")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* ImageToolbox is an image editor for android
* Copyright (c) 2025 T8RIN (Malik Mukhametzyanov)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* You should have received a copy of the Apache License
* along with this program. If not, see <http://www.apache.org/licenses/LICENSE-2.0>.
*/

package ru.tech.imageresizershrinker.feature.pdf_tools.presentation.components

internal object PagesSelectionParser {

fun parsePageInput(input: String): List<Int> {
val pages = mutableSetOf<Int>()
val regex = "\\d+(-\\d+)?".toRegex()
regex.findAll(input).forEach { match ->
val rangeParts = match.value.split("-").mapNotNull { it.toIntOrNull() }
when (rangeParts.size) {
1 -> pages.add(rangeParts[0] - 1)
2 -> if (rangeParts[0] <= rangeParts[1]) {
pages.addAll((rangeParts[0] - 1)..(rangeParts[1] - 1))
}
}
}
return pages.sorted()
}

fun formatPageOutput(pages: List<Int>): String {
if (pages.isEmpty()) return ""
val result = mutableListOf<String>()
var start = pages[0]
var prev = pages[0]
for (i in 1 until pages.size) {
if (pages[i] != prev + 1) {
result.add(if (start == prev) "${start + 1}" else "${start + 1}-${prev + 1}")
start = pages[i]
}
prev = pages[i]
}
result.add(if (start == prev) "${start + 1}" else "${start + 1}-${prev + 1}")
return result.joinToString(", ")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,16 @@ fun ScanQrCodeContent(
)
RoundedTextField(
modifier = Modifier
.container(shape = RoundedCornerShape(24.dp))
.padding(8.dp),
.container(
shape = MaterialTheme.shapes.large,
resultPadding = 0.dp
)
.padding(
top = 8.dp,
start = 8.dp,
end = 8.dp,
bottom = 6.dp
),
value = qrContent,
onValueChange = component::updateQrContent,
maxSymbols = 2500,
Expand Down Expand Up @@ -295,9 +303,9 @@ fun ScanQrCodeContent(
shape = animateShape(
if (qrDescription.isNotEmpty()) ContainerShapeDefaults.topShape
else ContainerShapeDefaults.defaultShape
)
)
.padding(8.dp),
),
resultPadding = 8.dp
),
value = qrDescription,
onValueChange = {
qrDescription = it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -54,9 +53,9 @@ fun WatermarkDataSelector(
RoundedTextField(
modifier = modifier
.container(
shape = RoundedCornerShape(20.dp)
)
.padding(8.dp),
shape = MaterialTheme.shapes.large,
resultPadding = 8.dp
),
value = type.text,
singleLine = false,
onValueChange = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -222,8 +222,10 @@ fun WeightResizeContent(
if (handMode) {
RoundedTextField(
modifier = Modifier
.container(shape = RoundedCornerShape(24.dp))
.padding(8.dp),
.container(
shape = MaterialTheme.shapes.large,
resultPadding = 8.dp
),
enabled = component.bitmap != null,
value = (component.maxBytes / 1024).toString()
.takeIf { it != "0" } ?: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.CheckCircle
Expand Down Expand Up @@ -236,8 +235,10 @@ fun ZipContent(
RoundedTextField(
modifier = Modifier
.padding(top = 8.dp)
.container(shape = RoundedCornerShape(24.dp))
.padding(8.dp),
.container(
shape = MaterialTheme.shapes.large,
resultPadding = 8.dp
),
value = name,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
singleLine = false,
Expand Down

0 comments on commit 0322629

Please sign in to comment.