-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from Infomaniak/polish-import-screen
refactor: Polish import screen
- Loading branch information
Showing
12 changed files
with
335 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
app/src/main/java/com/infomaniak/swisstransfer/ui/components/SinglePaneScaffold.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Infomaniak SwissTransfer - Android | ||
* Copyright (C) 2024 Infomaniak Network SA | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.swisstransfer.ui.components | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import com.infomaniak.swisstransfer.ui.theme.Dimens | ||
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme | ||
import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow | ||
import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark | ||
|
||
@Composable | ||
fun SinglePaneScaffold( | ||
topBar: @Composable () -> Unit = {}, | ||
bottomBar: @Composable () -> Unit = {}, | ||
snackbarHost: @Composable () -> Unit = {}, | ||
content: @Composable (PaddingValues) -> Unit, | ||
) { | ||
Scaffold( | ||
topBar = topBar, | ||
bottomBar = bottomBar, | ||
snackbarHost = snackbarHost, | ||
) { contentPadding -> | ||
Box( | ||
contentAlignment = Alignment.TopCenter, | ||
modifier = Modifier.fillMaxWidth(), | ||
) { | ||
Box(Modifier.widthIn(max = Dimens.MaxSinglePaneScreenWidth)) { | ||
content(contentPadding) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@PreviewLightAndDark | ||
@PreviewLargeWindow | ||
@Composable | ||
private fun Preview() { | ||
SwissTransferTheme { | ||
Surface { | ||
SinglePaneScaffold { | ||
Box( | ||
Modifier | ||
.fillMaxSize() | ||
.background(Color.Cyan) | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,8 +46,12 @@ import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme | |
|
||
/** | ||
* Wrapper for Material's [OutlinedTextField] that enforce our design needs. | ||
* | ||
* By default, this TextField is single lined. You can specify [maxLineNumber] or [minLineNumber] to make it multi-lined | ||
* | ||
* If [isPassword] value is true, the [keyboardType] field will be ignored to force [KeyboardType.Password] | ||
* | ||
* To set an error message, you need to pass this message as [supportingText] and set [isError] to true | ||
*/ | ||
@Composable | ||
fun SwissTransferTextField( | ||
|
@@ -62,8 +66,8 @@ fun SwissTransferTextField( | |
imeAction: ImeAction = ImeAction.Default, | ||
keyboardActions: KeyboardActions = KeyboardActions.Default, | ||
isReadOnly: Boolean = false, | ||
errorMessage: @Composable () -> String? = { null }, | ||
supportingText: String? = null, | ||
isError: Boolean = false, | ||
supportingText: @Composable (() -> Unit)? = null, | ||
onValueChange: ((String) -> Unit)? = null, | ||
) { | ||
|
||
|
@@ -80,17 +84,6 @@ fun SwissTransferTextField( | |
disabledTrailingIconColor = SwissTransferTheme.colors.iconColor, | ||
) | ||
|
||
@Composable | ||
fun getSupportingText(): (@Composable () -> Unit)? { | ||
val displayText = if (text.isEmpty()) { | ||
supportingText | ||
} else { | ||
errorMessage() ?: supportingText | ||
} | ||
|
||
return displayText?.let { @Composable { Text(it) } } | ||
} | ||
|
||
OutlinedTextField( | ||
modifier = modifier, | ||
readOnly = isReadOnly, | ||
|
@@ -119,8 +112,8 @@ fun SwissTransferTextField( | |
imeAction = imeAction, | ||
), | ||
keyboardActions = keyboardActions, | ||
isError = errorMessage() != null && text.isNotEmpty(), | ||
supportingText = getSupportingText(), | ||
isError = isError, | ||
supportingText = supportingText, | ||
) | ||
} | ||
|
||
|
@@ -139,18 +132,21 @@ private fun getShowPasswordButton(shouldShowPassword: Boolean, onClick: () -> Un | |
@Composable | ||
@Preview | ||
private fun Preview() { | ||
val supportingText = "supporting Text" | ||
val initialValue = "initialValue" | ||
|
||
SwissTransferTheme { | ||
Surface { | ||
Column(Modifier.padding(Margin.Medium)) { | ||
SwissTransferTextField( | ||
label = stringResource(R.string.transferMessagePlaceholder), | ||
initialValue = "test", | ||
errorMessage = { null }, | ||
) | ||
SwissTransferTextField( | ||
keyboardType = KeyboardType.Email, | ||
initialValue = "a@[email protected]", | ||
errorMessage = { "Invalid address" }, | ||
supportingText = { Text("Invalid address") }, | ||
isError = true, | ||
label = stringResource(R.string.transferRecipientAddressPlaceholder), | ||
) | ||
SwissTransferTextField( | ||
|
@@ -160,25 +156,25 @@ private fun Preview() { | |
) | ||
SwissTransferTextField( | ||
maxLineNumber = 10, | ||
initialValue = "initial value", | ||
initialValue = initialValue, | ||
isRequired = false, | ||
label = stringResource(R.string.transferMessagePlaceholder), | ||
supportingText = "supporting Text", | ||
supportingText = { Text(supportingText) }, | ||
) | ||
SwissTransferTextField( | ||
maxLineNumber = 10, | ||
initialValue = "initial value", | ||
initialValue = initialValue, | ||
isPassword = true, | ||
label = stringResource(R.string.settingsOptionPassword), | ||
supportingText = "supporting Text", | ||
supportingText = { Text(supportingText) }, | ||
) | ||
SwissTransferTextField( | ||
maxLineNumber = 10, | ||
initialValue = "initial value", | ||
initialValue = initialValue, | ||
isPassword = true, | ||
label = stringResource(R.string.settingsOptionPassword), | ||
errorMessage = { "Wrong password" }, | ||
supportingText = "supporting Text", | ||
isError = true, | ||
supportingText = { Text("Wrong password") }, | ||
) | ||
} | ||
} | ||
|
Oops, something went wrong.