Skip to content

Commit

Permalink
Merge branch 'release/3.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitletondor committed Jul 31, 2024
2 parents b2351f8 + 8b1f789 commit 1a2103b
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 112 deletions.
20 changes: 12 additions & 8 deletions Android/EasyBudget/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ android {
compileSdk = 34
minSdk = 23
targetSdk = 35
versionCode = 148
versionName = "3.3.1"
versionCode = 149
versionName = "3.3.2"
vectorDrawables.useSupportLibrary = true
}

Expand Down Expand Up @@ -122,10 +122,10 @@ dependencies {

implementation("androidx.appcompat:appcompat:1.7.0")
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.activity:activity-ktx:1.9.0")
implementation("androidx.activity:activity-ktx:1.9.1")
implementation("com.google.android.material:material:1.12.0")
implementation("androidx.lifecycle:lifecycle-extensions:2.2.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.3")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.4")
implementation("androidx.work:work-runtime-ktx:2.9.0")
implementation("androidx.work:work-gcm:2.9.0")
implementation("com.google.android.play:review-ktx:2.0.1")
Expand All @@ -148,9 +148,13 @@ dependencies {
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
implementation("androidx.compose.ui:ui")
implementation("androidx.activity:activity-compose:1.9.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.3")
implementation("androidx.navigation:navigation-compose:2.8.0-beta05")
implementation("androidx.activity:activity-compose:1.9.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.4")

// TODO migrate to bom when 1.7.0 is stable
implementation("androidx.compose.foundation:foundation:1.7.0-beta06")
implementation("androidx.navigation:navigation-compose:2.8.0-beta06")

implementation("com.google.accompanist:accompanist-themeadapter-material3:0.34.0")
implementation("com.google.accompanist:accompanist-permissions:0.34.0")
implementation("androidx.hilt:hilt-navigation-compose:1.2.0")
Expand All @@ -170,7 +174,7 @@ dependencies {

implementation("io.realm.kotlin:library-sync:$realmVersion")

implementation("com.kizitonwose.calendar:compose:2.6.0-beta02")
implementation("com.kizitonwose.calendar:compose:2.6.0-beta03")
implementation("net.sf.biweekly:biweekly:0.6.8")

implementation("net.lingala.zip4j:zip4j:2.11.5")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.text.input.KeyboardActionHandler
import androidx.compose.foundation.text.input.TextFieldLineLimits
import androidx.compose.foundation.text.input.TextFieldState
import androidx.compose.foundation.text.selection.LocalTextSelectionColors
import androidx.compose.foundation.text.selection.TextSelectionColors
import androidx.compose.material3.ExperimentalMaterial3Api
Expand All @@ -37,7 +39,6 @@ import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -46,8 +47,7 @@ import com.benoitletondor.easybudgetapp.R
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ExpenseEditTextField(
value: TextFieldValue,
onValueChange: (TextFieldValue) -> Unit,
state: TextFieldState,
modifier: Modifier = Modifier,
enabled: Boolean = true,
readOnly: Boolean = false,
Expand All @@ -65,10 +65,7 @@ fun ExpenseEditTextField(
isError: Boolean = false,
visualTransformation: VisualTransformation = VisualTransformation.None,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
singleLine: Boolean = true,
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
minLines: Int = 1,
onKeyboardAction: KeyboardActionHandler? = null,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
shape: Shape = TextFieldDefaults.shape,
colors: TextFieldColors = TextFieldDefaults.colors(
Expand Down Expand Up @@ -97,28 +94,24 @@ fun ExpenseEditTextField(

CompositionLocalProvider(LocalTextSelectionColors provides customTextSelectionColors) {
BasicTextField(
value = value,
state = state,
modifier = modifier
.defaultMinSize(
minWidth = TextFieldDefaults.MinWidth,
minHeight = TextFieldDefaults.MinHeight + 4.dp,
),
onValueChange = onValueChange,
enabled = enabled,
readOnly = readOnly,
textStyle = mergedTextStyle,
cursorBrush = SolidColor(Color.White),
visualTransformation = visualTransformation,
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
onKeyboardAction = onKeyboardAction,
interactionSource = interactionSource,
singleLine = singleLine,
maxLines = maxLines,
minLines = minLines,
decorationBox = @Composable { innerTextField ->
lineLimits = TextFieldLineLimits.SingleLine,
decorator = @Composable { innerTextField ->
// places leading icon, text field with label and placeholder, trailing icon
TextFieldDefaults.DecorationBox(
value = value.text,
value = state.text.toString(),
visualTransformation = visualTransformation,
innerTextField = innerTextField,
placeholder = placeholder,
Expand All @@ -135,7 +128,7 @@ fun ExpenseEditTextField(
suffix = suffix,
supportingText = supportingText,
shape = shape,
singleLine = singleLine,
singleLine = true,
enabled = enabled,
isError = isError,
interactionSource = interactionSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ 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.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.text.input.delete
import androidx.compose.foundation.text.input.insert
import androidx.compose.foundation.text.input.rememberTextFieldState
import androidx.compose.material3.Button
import androidx.compose.material3.DatePicker
import androidx.compose.material3.DatePickerDialog
Expand All @@ -49,6 +51,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand All @@ -64,7 +67,6 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -80,6 +82,7 @@ import com.benoitletondor.easybudgetapp.model.Expense
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.serialization.Serializable
import java.time.LocalDate
import java.time.ZoneId
Expand Down Expand Up @@ -214,31 +217,27 @@ private fun ExpenseEditView(
.padding(horizontal = 26.dp)
.padding(top = 10.dp, bottom = 20.dp),
) {
var descriptionTextFieldValue by remember { mutableStateOf(
TextFieldValue(
text = state.expense.title,
selection = TextRange(index = state.expense.title.length),
)
) }
val descriptionTextFieldState = rememberTextFieldState(initialText = state.expense.title)

LaunchedEffect(key1 = "descriptionTextFieldStateWatcher") {
snapshotFlow { descriptionTextFieldState.text }
.collectLatest { text ->
titleValueError = null
onTitleUpdate(text.toString())
}
}

ExpenseEditTextField(
modifier = Modifier
.fillMaxWidth()
.focusRequester(titleFocusRequester),
value = descriptionTextFieldValue,
onValueChange = {
descriptionTextFieldValue = it
titleValueError = null
onTitleUpdate(it.text)
},
state = descriptionTextFieldState,
isError = titleValueError != null,
label = if (titleValueError != null ) "${stringResource(R.string.description)}: $titleValueError" else stringResource(R.string.description),
keyboardActions = KeyboardActions(
onNext = {
titleFocusRequester.freeFocus()
amountFocusRequester.requestFocus()
},
),
onKeyboardAction = {
titleFocusRequester.freeFocus()
amountFocusRequester.requestFocus()
},
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.Next,
keyboardType = KeyboardType.Text,
Expand All @@ -250,29 +249,33 @@ private fun ExpenseEditView(

val currency by userCurrencyFlow.collectAsState()

var currentAmountTextFieldValue by remember { mutableStateOf(
TextFieldValue(
text = if (state.expense.amount == 0.0) "" else CurrencyHelper.getFormattedAmountValue(abs(state.expense.amount)),
selection = TextRange(index = if (state.expense.amount == 0.0) 0 else CurrencyHelper.getFormattedAmountValue(abs(state.expense.amount)).length),
)
) }
val currentAmountTextFieldState = rememberTextFieldState(
initialText = if (state.expense.amount == 0.0) "" else CurrencyHelper.getFormattedAmountValue(abs(state.expense.amount)),
initialSelection = TextRange(index = if (state.expense.amount == 0.0) 0 else CurrencyHelper.getFormattedAmountValue(abs(state.expense.amount)).length),
)

LaunchedEffect(key1 = "currentAmountTextFieldStateWatcher") {
snapshotFlow { currentAmountTextFieldState.text }
.collectLatest { text ->
val newText = text.toString().sanitizeFromUnsupportedInputForDecimals(supportsNegativeValue = false)

if (newText !== text) {
currentAmountTextFieldState.edit {
delete(0, text.length)
insert(0, newText)
}
}

amountValueError = null
onAmountUpdate(newText)
}
}

ExpenseEditTextField(
modifier = Modifier
.fillMaxWidth(0.5f)
.focusRequester(amountFocusRequester),
value = currentAmountTextFieldValue,
onValueChange = { newValue ->
val newText = newValue.text.sanitizeFromUnsupportedInputForDecimals(supportsNegativeValue = false)

currentAmountTextFieldValue = TextFieldValue(
text = newText,
selection = newValue.selection,
)

amountValueError = null
onAmountUpdate(newText)
},
state = currentAmountTextFieldState,
isError = amountValueError != null,
label = if (amountValueError != null) "${stringResource(R.string.amount, currency.symbol)}: $amountValueError" else stringResource(R.string.amount, currency.symbol),
keyboardOptions = KeyboardOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ private fun MainView(
)
),
actionLabel = context.getString(R.string.undo),
duration = SnackbarDuration.Long,
duration = SnackbarDuration.Short,
)

if (result === SnackbarResult.ActionPerformed) {
Expand Down Expand Up @@ -401,7 +401,7 @@ private fun MainView(
val result = snackbarHostState.showSnackbar(
message = context.getString(if (deletedExpense.isRevenue()) R.string.income_delete_snackbar_text else R.string.expense_delete_snackbar_text),
actionLabel = context.getString(R.string.undo),
duration = SnackbarDuration.Long,
duration = SnackbarDuration.Short,
)

if (result === SnackbarResult.ActionPerformed) {
Expand Down Expand Up @@ -447,7 +447,7 @@ private fun MainView(
val result = snackbarHostState.showSnackbar(
message = context.getString(R.string.recurring_expense_delete_success_message),
actionLabel = context.getString(R.string.undo),
duration = SnackbarDuration.Long,
duration = SnackbarDuration.Short,
)

if (result === SnackbarResult.ActionPerformed) {
Expand All @@ -474,7 +474,7 @@ private fun MainView(
snackbarHostState.showSnackbar(
message = context.getString(R.string.recurring_expense_restored_success_message),
actionLabel = context.getString(R.string.undo),
duration = SnackbarDuration.Long,
duration = SnackbarDuration.Short,
)
}
}
Expand Down
Loading

0 comments on commit 1a2103b

Please sign in to comment.