Skip to content

Commit

Permalink
Update Ui of Base64 Tools
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Dec 26, 2024
1 parent efd9d25 commit f0e555c
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 123 deletions.
1 change: 1 addition & 0 deletions core/resources/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1523,4 +1523,5 @@
<string name="options">Options</string>
<string name="actions">Actions</string>
<string name="import_base_64">Import Base64</string>
<string name="base_64_actions">Base64 Actions</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ fun Base64ToolsContent(
controls = {
if (isPortrait) Spacer(Modifier.height(8.dp))
Base64ToolsTiles(component)
Spacer(Modifier.height(16.dp))
Spacer(Modifier.height(8.dp))
if (component.uri != null) {
if (component.imageFormat.canChangeCompressionValue) {
Spacer(Modifier.height(8.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedContent
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
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.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Save
Expand All @@ -37,7 +38,11 @@ import androidx.compose.material.icons.rounded.CopyAll
import androidx.compose.material.icons.rounded.FileOpen
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.PlainTooltip
import androidx.compose.material3.Text
import androidx.compose.material3.TooltipBox
import androidx.compose.material3.TooltipDefaults
import androidx.compose.material3.rememberTooltipState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -55,8 +60,8 @@ import ru.tech.imageresizershrinker.core.domain.utils.trimToBase64
import ru.tech.imageresizershrinker.core.resources.R
import ru.tech.imageresizershrinker.core.resources.icons.Base64
import ru.tech.imageresizershrinker.core.ui.utils.provider.rememberLocalEssentials
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedIconButton
import ru.tech.imageresizershrinker.core.ui.widget.haptics.hapticsClickable
import ru.tech.imageresizershrinker.core.ui.widget.modifier.ContainerShapeDefaults
import ru.tech.imageresizershrinker.core.ui.widget.modifier.container
import ru.tech.imageresizershrinker.core.ui.widget.text.AutoSizeText
import ru.tech.imageresizershrinker.feature.base64_tools.presentation.screenLogic.Base64ToolsComponent
Expand All @@ -82,7 +87,8 @@ internal fun Base64ToolsTiles(component: Base64ToolsComponent) {
},
shape = shape,
icon = Icons.Rounded.ContentPaste,
textRes = R.string.paste_base_64
textRes = R.string.paste_base_64,
isButton = component.uri != null
)
}

Expand All @@ -109,7 +115,8 @@ internal fun Base64ToolsTiles(component: Base64ToolsComponent) {
},
shape = shape,
icon = Icons.Rounded.FileOpen,
textRes = R.string.import_base_64
textRes = R.string.import_base_64,
isButton = component.uri != null
)
}

Expand Down Expand Up @@ -139,109 +146,88 @@ internal fun Base64ToolsTiles(component: Base64ToolsComponent) {
} else {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.container(
shape = RoundedCornerShape(20.dp),
resultPadding = 8.dp
)
modifier = Modifier
.container(
shape = RoundedCornerShape(28.dp),
resultPadding = 0.dp
)
.padding(
horizontal = 12.dp
)
.padding(
top = 4.dp,
bottom = 8.dp
)
) {
Text(
text = stringResource(R.string.actions),
text = stringResource(R.string.base_64_actions),
textAlign = TextAlign.Center,
fontWeight = FontWeight.Medium,
modifier = Modifier.padding(8.dp)
)
Spacer(Modifier.height(8.dp))
Column(
verticalArrangement = Arrangement.spacedBy(4.dp)
Row(
horizontalArrangement = Arrangement.spacedBy(4.dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(4.dp)
) {
pasteTile(
RoundedCornerShape(
topStart = 16.dp,
topEnd = 4.dp,
bottomStart = 4.dp,
bottomEnd = 4.dp
)
)
pasteTile(CircleShape)
importTile(CircleShape)

Tile(
onClick = {
val text = buildAnnotatedString {
append(component.base64String)
}
if (isBase64(component.base64String)) {
clipboardManager.setText(text)
} else {
essentials.showToast(
message = context.getString(R.string.copy_not_a_valid_base_64),
icon = Icons.Rounded.Base64
)
}
},
shape = RoundedCornerShape(
topStart = 4.dp,
topEnd = 16.dp,
bottomStart = 4.dp,
bottomEnd = 4.dp
),
icon = Icons.Rounded.CopyAll,
textRes = R.string.copy_base_64
)
}
Row(
modifier = Modifier.fillMaxWidth()
) {
importTile(ContainerShapeDefaults.centerShape)
Tile(
onClick = {
val text = buildAnnotatedString {
append(component.base64String)
}
if (isBase64(component.base64String)) {
clipboardManager.setText(text)
essentials.showToast(
message = context.getString(R.string.copied),
icon = Icons.Rounded.CopyAll
)
} else {
essentials.showToast(
message = context.getString(R.string.copy_not_a_valid_base_64),
icon = Icons.Rounded.Base64
)
}
},
icon = Icons.Rounded.CopyAll,
textRes = R.string.copy_base_64
)

val shareText = {
component.shareText(essentials::showConfetti)
}
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(4.dp)
) {
val shareText = {
component.shareText(essentials::showConfetti)
}

Tile(
onClick = shareText,
shape = RoundedCornerShape(
topStart = 4.dp,
topEnd = 4.dp,
bottomStart = 16.dp,
bottomEnd = 4.dp
),
icon = Icons.Outlined.Share,
textRes = R.string.share_base_64
)
Tile(
onClick = shareText,
shape = RoundedCornerShape(
topStart = 4.dp,
topEnd = 4.dp,
bottomStart = 16.dp,
bottomEnd = 4.dp
),
icon = Icons.Outlined.Share,
textRes = R.string.share_base_64
)

val saveLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.CreateDocument("text/plain")
) { uri ->
uri?.let {
component.saveContentToTxt(
uri = uri,
onResult = essentials::parseFileSaveResult
)
}
}
val saveText: () -> Unit = {
saveLauncher.launch(component.generateTextFilename())
val saveLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.CreateDocument("text/plain")
) { uri ->
uri?.let {
component.saveContentToTxt(
uri = uri,
onResult = essentials::parseFileSaveResult
)
}

Tile(
onClick = saveText,
shape = RoundedCornerShape(
topStart = 4.dp,
topEnd = 4.dp,
bottomStart = 4.dp,
bottomEnd = 16.dp
),
icon = Icons.Outlined.Save,
textRes = R.string.save_base_64
)
}
val saveText: () -> Unit = {
saveLauncher.launch(component.generateTextFilename())
}

Tile(
onClick = saveText,
icon = Icons.Outlined.Save,
textRes = R.string.save_base_64
)
}
}
}
Expand All @@ -251,36 +237,66 @@ internal fun Base64ToolsTiles(component: Base64ToolsComponent) {
@Composable
private fun RowScope.Tile(
onClick: () -> Unit,
shape: Shape,
shape: Shape = CircleShape,
icon: ImageVector,
textRes: Int
textRes: Int,
isButton: Boolean = true
) {
Row(
modifier = Modifier
.weight(1f)
.height(56.dp)
.container(
color = MaterialTheme.colorScheme.secondaryContainer.copy(0.5f),
shape = shape,
resultPadding = 0.dp
if (isButton) {
val tooltipState = rememberTooltipState()
Box(
modifier = Modifier.weight(1f)
) {
TooltipBox(
positionProvider = TooltipDefaults.rememberTooltipPositionProvider(),
tooltip = {
PlainTooltip {
Text(stringResource(id = textRes))
}
},
state = tooltipState
) {
EnhancedIconButton(
containerColor = MaterialTheme.colorScheme.secondaryContainer.copy(0.5f),
contentColor = MaterialTheme.colorScheme.onSecondaryContainer,
onClick = onClick,
modifier = Modifier.fillMaxWidth()
) {
Icon(
imageVector = icon,
contentDescription = null
)
}
}
}
} else {
Row(
modifier = Modifier
.weight(1f)
.height(56.dp)
.container(
color = MaterialTheme.colorScheme.secondaryContainer.copy(0.5f),
shape = shape,
resultPadding = 0.dp
)
.hapticsClickable(onClick = onClick)
.padding(8.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(
space = 8.dp,
alignment = Alignment.CenterHorizontally
)
.hapticsClickable(onClick = onClick)
.padding(8.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(
space = 8.dp,
alignment = Alignment.CenterHorizontally
)
) {
Icon(
imageVector = icon,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSecondaryContainer
)
AutoSizeText(
text = stringResource(id = textRes),
color = MaterialTheme.colorScheme.onSecondaryContainer,
textAlign = TextAlign.Center
)
) {
Icon(
imageVector = icon,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSecondaryContainer
)
AutoSizeText(
text = stringResource(id = textRes),
color = MaterialTheme.colorScheme.onSecondaryContainer,
textAlign = TextAlign.Center
)
}
}
}

0 comments on commit f0e555c

Please sign in to comment.