Compare commits
9 Commits
develop
...
79551ab69d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79551ab69d | ||
|
|
38f3760cef | ||
|
|
9225f2275f | ||
|
|
aad0de1499 | ||
|
|
5fb54bf18e | ||
|
|
bf9309a155 | ||
|
|
cc10ddabbe | ||
|
|
3286bcf87a | ||
| dfe9dbd08b |
@@ -12,7 +12,6 @@ import androidx.compose.material3.DrawerValue
|
|||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.rememberDrawerState
|
import androidx.compose.material3.rememberDrawerState
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
@@ -26,6 +25,7 @@ import androidx.navigation.compose.NavHost
|
|||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
|
import androidx.navigation.navArgument
|
||||||
import cc.n0th1ng.tripmoney.data.entity.Category
|
import cc.n0th1ng.tripmoney.data.entity.Category
|
||||||
import cc.n0th1ng.tripmoney.data.entity.Trip
|
import cc.n0th1ng.tripmoney.data.entity.Trip
|
||||||
import cc.n0th1ng.tripmoney.navigation.BottomNavigation
|
import cc.n0th1ng.tripmoney.navigation.BottomNavigation
|
||||||
@@ -97,7 +97,7 @@ fun NavigationDrawer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isSearchable = current == Screens.LIST_EXPENSE,
|
isSearchable = current != null && current.contains(Screens.LIST_EXPENSE),
|
||||||
onSearchChange = { newSearch -> search = newSearch },
|
onSearchChange = { newSearch -> search = newSearch },
|
||||||
onFilterChange = { newFilter -> filter = newFilter },
|
onFilterChange = { newFilter -> filter = newFilter },
|
||||||
categories = categories,
|
categories = categories,
|
||||||
@@ -111,17 +111,20 @@ fun NavigationDrawer() {
|
|||||||
startDestination = if (currentTripId == -1) Screens.TRIP_PICKER else Screens.LIST_EXPENSE,
|
startDestination = if (currentTripId == -1) Screens.TRIP_PICKER else Screens.LIST_EXPENSE,
|
||||||
modifier = Modifier.padding(innerPadding)
|
modifier = Modifier.padding(innerPadding)
|
||||||
) {
|
) {
|
||||||
composable(Screens.LIST_EXPENSE) {
|
composable(Screens.LIST_EXPENSE+"?dateToScroll={dateToScroll}",
|
||||||
|
arguments = listOf(navArgument("dateToScroll"){defaultValue = ""})) {
|
||||||
|
backStackEntry ->
|
||||||
ListExpenseScreen(
|
ListExpenseScreen(
|
||||||
filter = filter, search = search,
|
filter = filter, search = search,
|
||||||
initialAutoOpen = shouldTriggerAutoOpen,
|
initialAutoOpen = shouldTriggerAutoOpen,
|
||||||
onAutoOpenConsumed = { hasHandledStartupOpen = true })
|
onAutoOpenConsumed = { hasHandledStartupOpen = true },
|
||||||
|
dateToScroll = backStackEntry.arguments?.getString("dateToScroll")?: "")
|
||||||
}
|
}
|
||||||
composable(Screens.TRIP_PICKER) {
|
composable(Screens.TRIP_PICKER) {
|
||||||
TripPickerScreen(navController)
|
TripPickerScreen(navController)
|
||||||
}
|
}
|
||||||
composable(Screens.STATISTICS) {
|
composable(Screens.STATISTICS) {
|
||||||
StatisticsScreen()
|
StatisticsScreen(navController)
|
||||||
}
|
}
|
||||||
composable(Screens.SETTINGS) {
|
composable(Screens.SETTINGS) {
|
||||||
SettingsScreen(navController)
|
SettingsScreen(navController)
|
||||||
|
|||||||
@@ -49,8 +49,6 @@ abstract class TripDatabase : RoomDatabase() {
|
|||||||
@Module
|
@Module
|
||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
object DatabaseModule {
|
object DatabaseModule {
|
||||||
|
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
interface ExpenseDao {
|
interface ExpenseDao {
|
||||||
|
|
||||||
@Upsert
|
@Upsert
|
||||||
suspend fun insert(expense: Expense)
|
suspend fun insert(expense: Expense): Long
|
||||||
|
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package cc.n0th1ng.tripmoney.data.dto
|
|||||||
|
|
||||||
import cc.n0th1ng.tripmoney.data.entity.Category
|
import cc.n0th1ng.tripmoney.data.entity.Category
|
||||||
import cc.n0th1ng.tripmoney.utils.Currencies
|
import cc.n0th1ng.tripmoney.utils.Currencies
|
||||||
import cc.n0th1ng.tripmoney.utils.Icons
|
import java.time.LocalDate
|
||||||
|
|
||||||
data class SummaryPerCategory(
|
data class SummaryPerCategory(
|
||||||
val category: Category,
|
val category: Category,
|
||||||
@@ -11,12 +11,8 @@ data class SummaryPerCategory(
|
|||||||
val currency: Currencies
|
val currency: Currencies
|
||||||
)
|
)
|
||||||
|
|
||||||
data class SummaryPerCategoryRaw(
|
data class SummaryPerDay(
|
||||||
val categoryId: Int,
|
val day: LocalDate,
|
||||||
val categoryName: String,
|
|
||||||
val icon: Icons,
|
|
||||||
val color: String,
|
|
||||||
val amount: Double,
|
val amount: Double,
|
||||||
val currency: String
|
val percent: Float
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,6 +19,10 @@ data class Trip(
|
|||||||
@ColumnInfo("currency") val currency: String,
|
@ColumnInfo("currency") val currency: String,
|
||||||
@ColumnInfo("budget") val budget: Double = 0.0
|
@ColumnInfo("budget") val budget: Double = 0.0
|
||||||
) {
|
) {
|
||||||
|
fun isDummy(): Boolean {
|
||||||
|
return this.id == -1
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
val DUMMY = Trip(
|
val DUMMY = Trip(
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ class ExpenseRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
suspend fun save(expense: Expense) {
|
suspend fun save(expense: Expense): Long {
|
||||||
expenseDao.insert(expense)
|
return expenseDao.insert(expense)
|
||||||
}
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
|
|||||||
@@ -115,10 +115,6 @@ fun AddExpenseBottomSheet(
|
|||||||
) {
|
) {
|
||||||
val currentTripId = currentTrip.id
|
val currentTripId = currentTrip.id
|
||||||
|
|
||||||
if (categories.isEmpty()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var amount by remember {
|
var amount by remember {
|
||||||
mutableStateOf(
|
mutableStateOf(
|
||||||
"%.2f".format(expenseDtoToEdit?.expense?.amount ?: 0.00)
|
"%.2f".format(expenseDtoToEdit?.expense?.amount ?: 0.00)
|
||||||
@@ -138,7 +134,11 @@ fun AddExpenseBottomSheet(
|
|||||||
expenseDtoToEdit?.expense?.currency ?: currentTrip.currency
|
expenseDtoToEdit?.expense?.currency ?: currentTrip.currency
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
var category by remember { mutableStateOf(expenseDtoToEdit?.category ?: categories[0]) }
|
var category by remember {
|
||||||
|
mutableStateOf(
|
||||||
|
expenseDtoToEdit?.category ?: if (categories.isEmpty()) null else categories[0]
|
||||||
|
)
|
||||||
|
}
|
||||||
var datetime by remember {
|
var datetime by remember {
|
||||||
mutableStateOf(
|
mutableStateOf(
|
||||||
expenseDtoToEdit?.expense?.datetime ?: LocalDateTime.now()
|
expenseDtoToEdit?.expense?.datetime ?: LocalDateTime.now()
|
||||||
@@ -273,14 +273,14 @@ fun AddExpenseBottomSheet(
|
|||||||
|
|
||||||
SaveButton(
|
SaveButton(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
enabled = enableSave,
|
enabled = enableSave && category != null,
|
||||||
onClick = {
|
onClick = {
|
||||||
val expenseToSave = Expense(
|
val expenseToSave = Expense(
|
||||||
amount = equationResult,
|
amount = equationResult,
|
||||||
currency = currency,
|
currency = currency,
|
||||||
note = note,
|
note = note,
|
||||||
datetime = datetime,
|
datetime = datetime,
|
||||||
categoryId = category.id,
|
categoryId = category!!.id,
|
||||||
tripId = currentTripId
|
tripId = currentTripId
|
||||||
)
|
)
|
||||||
onSave(
|
onSave(
|
||||||
@@ -410,7 +410,7 @@ fun CurrencyButton(modifier: Modifier = Modifier, onClick: () -> Unit, text: Str
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CategoryButton(onClick: () -> Unit, category: Category, modifier: Modifier = Modifier) {
|
fun CategoryButton(onClick: () -> Unit, category: Category?, modifier: Modifier = Modifier) {
|
||||||
Button(
|
Button(
|
||||||
contentPadding = PaddingValues(0.dp),
|
contentPadding = PaddingValues(0.dp),
|
||||||
onClick = onClick,
|
onClick = onClick,
|
||||||
@@ -422,25 +422,21 @@ fun CategoryButton(onClick: () -> Unit, category: Category, modifier: Modifier =
|
|||||||
contentColor = MaterialTheme.colorScheme.onPrimary
|
contentColor = MaterialTheme.colorScheme.onPrimary
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
// Row(modifier = modifier.fillMaxWidth()) {
|
if (category != null) {
|
||||||
Icon(
|
Icon(
|
||||||
tint = Color(category.color.toColorInt()),
|
tint = Color(category.color.toColorInt()),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(30.dp)
|
.size(30.dp)
|
||||||
// .background(
|
.padding(end = 10.dp),
|
||||||
// color = MaterialTheme.colorScheme.prima,
|
painter = painterResource(category.icon.resource),
|
||||||
// shape = MaterialTheme.shapes.small
|
contentDescription = stringResource(R.string.category),
|
||||||
// )
|
)
|
||||||
.padding(end = 10.dp),
|
}
|
||||||
painter = painterResource(category.icon.resource),
|
|
||||||
contentDescription = stringResource(R.string.category),
|
|
||||||
)
|
|
||||||
Text(
|
Text(
|
||||||
text = category.name,
|
text = category?.name ?: stringResource(R.string.pick_category),
|
||||||
style = MaterialTheme.typography.titleMedium
|
style = MaterialTheme.typography.titleMedium
|
||||||
)
|
)
|
||||||
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -484,12 +480,20 @@ fun NumberKeyboard(
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1f),
|
.weight(1f),
|
||||||
containerColor = Color.Transparent,
|
containerColor = Color.Transparent,
|
||||||
onLongClick = onLongBackspaceClick
|
onLongClick = onLongBackspaceClick,
|
||||||
|
contentColor = MaterialTheme.colorScheme.onPrimaryContainer
|
||||||
)
|
)
|
||||||
|
|
||||||
"+", "÷", "−", "×" -> KeyboardButton(
|
"+", "÷", "−", "×" -> KeyboardButton(
|
||||||
text = key,
|
text = key,
|
||||||
onClick = { onOperatorClick(key) },
|
onClick = {
|
||||||
|
when (key) {
|
||||||
|
"+" -> onOperatorClick("+")
|
||||||
|
"÷" -> onOperatorClick("/")
|
||||||
|
"−" -> onOperatorClick("-")
|
||||||
|
"×" -> onOperatorClick("*")
|
||||||
|
}
|
||||||
|
},
|
||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
containerColor = MaterialTheme.colorScheme.tertiaryContainer,
|
containerColor = MaterialTheme.colorScheme.tertiaryContainer,
|
||||||
contentColor = MaterialTheme.colorScheme.onTertiaryContainer
|
contentColor = MaterialTheme.colorScheme.onTertiaryContainer
|
||||||
@@ -500,7 +504,7 @@ fun NumberKeyboard(
|
|||||||
onClick = { onNumberClick(key) },
|
onClick = { onNumberClick(key) },
|
||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
containerColor = Color.Transparent,
|
containerColor = Color.Transparent,
|
||||||
contentColor = MaterialTheme.colorScheme.onSecondary
|
contentColor = MaterialTheme.colorScheme.onPrimaryContainer
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -532,7 +536,8 @@ fun KeyboardButton(
|
|||||||
when {
|
when {
|
||||||
text != null -> Text(
|
text != null -> Text(
|
||||||
text = text,
|
text = text,
|
||||||
style = MaterialTheme.typography.headlineMedium
|
style = MaterialTheme.typography.headlineMedium,
|
||||||
|
color = contentColor
|
||||||
)
|
)
|
||||||
|
|
||||||
icon != null -> Icon(painter = icon, contentDescription = null)
|
icon != null -> Icon(painter = icon, contentDescription = null)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import androidx.compose.ui.res.stringResource
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.core.graphics.toColorInt
|
import androidx.core.graphics.toColorInt
|
||||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||||
import cc.n0th1ng.tripmoney.R.*
|
import cc.n0th1ng.tripmoney.R.string
|
||||||
import cc.n0th1ng.tripmoney.data.entity.Category
|
import cc.n0th1ng.tripmoney.data.entity.Category
|
||||||
import cc.n0th1ng.tripmoney.screens.AddCategoryDialog
|
import cc.n0th1ng.tripmoney.screens.AddCategoryDialog
|
||||||
import cc.n0th1ng.tripmoney.viewmodel.ExpenseAndCategoryViewModel
|
import cc.n0th1ng.tripmoney.viewmodel.ExpenseAndCategoryViewModel
|
||||||
@@ -35,7 +35,7 @@ import com.composables.icons.materialsymbols.outlined.R
|
|||||||
fun CategorySelectionDialog(
|
fun CategorySelectionDialog(
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
onCategorySelected: (Category) -> Unit,
|
onCategorySelected: (Category) -> Unit,
|
||||||
selected: Category,
|
selected: Category?,
|
||||||
categories: List<Category>,
|
categories: List<Category>,
|
||||||
) {
|
) {
|
||||||
val expenseAndCategoryViewModel: ExpenseAndCategoryViewModel = hiltViewModel()
|
val expenseAndCategoryViewModel: ExpenseAndCategoryViewModel = hiltViewModel()
|
||||||
|
|||||||
@@ -1,20 +1,38 @@
|
|||||||
package cc.n0th1ng.tripmoney.screens.listexpense
|
package cc.n0th1ng.tripmoney.screens.listexpense
|
||||||
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.sizeIn
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.RadioButton
|
import androidx.compose.material3.RadioButton
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import cc.n0th1ng.tripmoney.R
|
import cc.n0th1ng.tripmoney.R
|
||||||
|
import cc.n0th1ng.tripmoney.theme.TripMoneyTheme
|
||||||
|
import cc.n0th1ng.tripmoney.utils.AllPreviews
|
||||||
import cc.n0th1ng.tripmoney.utils.Currencies
|
import cc.n0th1ng.tripmoney.utils.Currencies
|
||||||
|
import com.composables.icons.materialsymbols.outlined.R.drawable
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CurrencySelectionDialog(
|
fun CurrencySelectionDialog(
|
||||||
@@ -23,29 +41,90 @@ fun CurrencySelectionDialog(
|
|||||||
selected: String
|
selected: String
|
||||||
) {
|
) {
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
|
modifier = Modifier.sizeIn(maxHeight = 500.dp),
|
||||||
onDismissRequest = onDismiss,
|
onDismissRequest = onDismiss,
|
||||||
title = { Text(stringResource(R.string.pick_currency)) },
|
title = { Text(stringResource(R.string.pick_currency)) },
|
||||||
text = {
|
text = {
|
||||||
Column {
|
val scrollState = rememberLazyListState()
|
||||||
Currencies.names().forEach { currency ->
|
val currencies = Currencies.names()
|
||||||
Row(
|
var search by remember { mutableStateOf("") }
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
LaunchedEffect(selected) {
|
||||||
.clickable {
|
val index = currencies.indexOf(selected)
|
||||||
onCurrencySelected(currency)
|
if (index != -1) {
|
||||||
}
|
scrollState.animateScrollToItem(index)
|
||||||
.padding(vertical = 8.dp),
|
}
|
||||||
verticalAlignment = Alignment.CenterVertically) {
|
}
|
||||||
RadioButton(
|
|
||||||
selected = selected == currency, onClick = {
|
Column(verticalArrangement = Arrangement.spacedBy(5.dp)) {
|
||||||
onCurrencySelected(currency)
|
OutlinedTextField(
|
||||||
})
|
value = search,
|
||||||
Text(
|
onValueChange = { newText ->
|
||||||
text = currency, modifier = Modifier.padding(start = 8.dp)
|
search = newText
|
||||||
|
},
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
trailingIcon = {
|
||||||
|
Icon(
|
||||||
|
painter = painterResource(drawable.materialsymbols_ic_search_outlined),
|
||||||
|
contentDescription = "search"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
val filteredCurrencies = if (search.isBlank()) {
|
||||||
|
currencies
|
||||||
|
} else {
|
||||||
|
currencies.filter { currency ->
|
||||||
|
currency.lowercase().contains(search.lowercase())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LazyColumn(state = scrollState) {
|
||||||
|
items(
|
||||||
|
count = filteredCurrencies.size,
|
||||||
|
key = { index -> filteredCurrencies[index] }
|
||||||
|
) { index ->
|
||||||
|
val currency = filteredCurrencies[index]
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clickable {
|
||||||
|
onCurrencySelected(currency)
|
||||||
|
},
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
RadioButton(
|
||||||
|
selected = selected == currency,
|
||||||
|
onClick = { onCurrencySelected(currency) }
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = currency,
|
||||||
|
modifier = Modifier.padding(start = 8.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
confirmButton = {})
|
confirmButton = {},
|
||||||
|
dismissButton = {
|
||||||
|
Button(
|
||||||
|
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.secondary),
|
||||||
|
enabled = true,
|
||||||
|
onClick = onDismiss,
|
||||||
|
) { Text(stringResource(R.string.cancel)) }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@AllPreviews
|
||||||
|
@Composable
|
||||||
|
fun PreviewCurrencySelectionDialog() {
|
||||||
|
TripMoneyTheme {
|
||||||
|
CurrencySelectionDialog(
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
Currencies.names().random()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.combinedClickable
|
import androidx.compose.foundation.combinedClickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
@@ -22,6 +21,8 @@ import androidx.compose.material.icons.Icons
|
|||||||
import androidx.compose.material.icons.filled.Add
|
import androidx.compose.material.icons.filled.Add
|
||||||
import androidx.compose.material.icons.filled.Delete
|
import androidx.compose.material.icons.filled.Delete
|
||||||
import androidx.compose.material3.BasicAlertDialog
|
import androidx.compose.material3.BasicAlertDialog
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.CardDefaults
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.material3.ElevatedCard
|
import androidx.compose.material3.ElevatedCard
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
@@ -40,6 +41,7 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
@@ -47,11 +49,12 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.testTag
|
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.semantics.contentDescription
|
import androidx.compose.ui.semantics.contentDescription
|
||||||
import androidx.compose.ui.semantics.semantics
|
import androidx.compose.ui.semantics.semantics
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.core.graphics.toColorInt
|
import androidx.core.graphics.toColorInt
|
||||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||||
@@ -88,7 +91,8 @@ fun ListExpenseScreen(
|
|||||||
filter: Filter,
|
filter: Filter,
|
||||||
search: String,
|
search: String,
|
||||||
initialAutoOpen: Boolean,
|
initialAutoOpen: Boolean,
|
||||||
onAutoOpenConsumed: () -> Unit
|
onAutoOpenConsumed: () -> Unit,
|
||||||
|
dateToScroll: String
|
||||||
) {
|
) {
|
||||||
val settingsViewModel: SettingsViewModel = hiltViewModel()
|
val settingsViewModel: SettingsViewModel = hiltViewModel()
|
||||||
val tripViewModel: TripViewModel = hiltViewModel()
|
val tripViewModel: TripViewModel = hiltViewModel()
|
||||||
@@ -98,14 +102,23 @@ fun ListExpenseScreen(
|
|||||||
val expensesFlow =
|
val expensesFlow =
|
||||||
expenseAndCategoryViewModel.getExpensesWithHeadersPaged(currentTripId, search, filter)
|
expenseAndCategoryViewModel.getExpensesWithHeadersPaged(currentTripId, search, filter)
|
||||||
val isRecalculatingRate by tripViewModel.isRecalculating.collectAsState()
|
val isRecalculatingRate by tripViewModel.isRecalculating.collectAsState()
|
||||||
|
var idToScroll by remember { mutableIntStateOf(-1) }
|
||||||
|
|
||||||
ListExpenseScreen(
|
ListExpenseScreen(
|
||||||
|
currentTrip = currentTrip,
|
||||||
expensesFlow = expensesFlow,
|
expensesFlow = expensesFlow,
|
||||||
onSaveExpense = { expenseAndCategoryViewModel.save(it, currentTrip!!) },
|
onSaveExpense = {
|
||||||
|
expenseAndCategoryViewModel.save(
|
||||||
|
it,
|
||||||
|
currentTrip!!,
|
||||||
|
onComplete = { id -> idToScroll = id })
|
||||||
|
},
|
||||||
onDeleteExpense = { expenseAndCategoryViewModel.delete(it) },
|
onDeleteExpense = { expenseAndCategoryViewModel.delete(it) },
|
||||||
isRecalculatingRate = isRecalculatingRate,
|
isRecalculatingRate = isRecalculatingRate,
|
||||||
initialAutoOpen = initialAutoOpen,
|
initialAutoOpen = initialAutoOpen,
|
||||||
onAutoOpenConsumed = onAutoOpenConsumed
|
onAutoOpenConsumed = onAutoOpenConsumed,
|
||||||
|
idToScroll = idToScroll,
|
||||||
|
dateToScroll = dateToScroll
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,11 +127,14 @@ fun ListExpenseScreen(
|
|||||||
@RequiresApi(Build.VERSION_CODES.O)
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
@Composable
|
@Composable
|
||||||
fun ListExpenseScreen(
|
fun ListExpenseScreen(
|
||||||
|
currentTrip: Trip?,
|
||||||
expensesFlow: Flow<PagingData<ExpenseListItemUi>>,
|
expensesFlow: Flow<PagingData<ExpenseListItemUi>>,
|
||||||
onSaveExpense: (Expense) -> Unit, onDeleteExpense: (Expense) -> Unit,
|
onSaveExpense: (Expense) -> Unit, onDeleteExpense: (Expense) -> Unit,
|
||||||
isRecalculatingRate: Boolean,
|
isRecalculatingRate: Boolean,
|
||||||
initialAutoOpen: Boolean,
|
initialAutoOpen: Boolean,
|
||||||
onAutoOpenConsumed: () -> Unit
|
onAutoOpenConsumed: () -> Unit,
|
||||||
|
idToScroll: Int,
|
||||||
|
dateToScroll: String
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
||||||
@@ -137,18 +153,65 @@ fun ListExpenseScreen(
|
|||||||
var itemToDelete by remember { mutableStateOf<Expense?>(null) }
|
var itemToDelete by remember { mutableStateOf<Expense?>(null) }
|
||||||
|
|
||||||
Scaffold(floatingActionButtonPosition = FabPosition.EndOverlay, floatingActionButton = {
|
Scaffold(floatingActionButtonPosition = FabPosition.EndOverlay, floatingActionButton = {
|
||||||
ExtendedFloatingActionButton(
|
if (currentTrip != null && !currentTrip.isDummy()) {
|
||||||
onClick = { showBottomSheet = true },
|
ExtendedFloatingActionButton(
|
||||||
icon = { Icon(Icons.Filled.Add, stringResource(string.add_expense)) },
|
onClick = { showBottomSheet = true },
|
||||||
text = { Text(text = stringResource(string.add_expense)) },
|
icon = { Icon(Icons.Filled.Add, stringResource(string.add_expense)) },
|
||||||
)
|
text = { Text(text = stringResource(string.add_expense)) },
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
Box {
|
Box {
|
||||||
|
if (items.itemCount == 0) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(10.dp),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
val textToShow = if (currentTrip == null || currentTrip.isDummy()) {
|
||||||
|
stringResource(string.no_trip_picked)
|
||||||
|
} else {
|
||||||
|
stringResource(string.no_expenses)
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
text = textToShow,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
fontWeight = FontWeight.Light,
|
||||||
|
style = MaterialTheme.typography.headlineMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.7f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
if (dateToScroll == "") return@LaunchedEffect
|
||||||
|
for (index in 0 until items.itemCount) {
|
||||||
|
val item = items.peek(index)
|
||||||
|
if (item is ExpenseListItemUi.Header && item.date.toString() == dateToScroll) {
|
||||||
|
listState.animateScrollToItem(index)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LaunchedEffect(idToScroll) {
|
||||||
|
if (idToScroll == -1) return@LaunchedEffect
|
||||||
|
for (index in 0 until items.itemCount) {
|
||||||
|
val item = items.peek(index)
|
||||||
|
if (item is ExpenseListItemUi.Item && item.expenseDto.expense.id == idToScroll) {
|
||||||
|
listState.animateScrollToItem(index)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
modifier = Modifier.fillMaxSize().semantics {
|
modifier = Modifier
|
||||||
contentDescription = "expensesList"
|
.fillMaxSize()
|
||||||
},
|
.semantics {
|
||||||
|
contentDescription = "expensesList"
|
||||||
|
},
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
state = listState
|
state = listState
|
||||||
) {
|
) {
|
||||||
@@ -161,9 +224,7 @@ fun ListExpenseScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
) { index ->
|
) { index ->
|
||||||
|
|
||||||
when (val item = items[index]) {
|
when (val item = items[index]) {
|
||||||
|
|
||||||
is ExpenseListItemUi.Header -> {
|
is ExpenseListItemUi.Header -> {
|
||||||
CustomDivider(
|
CustomDivider(
|
||||||
date = item.date,
|
date = item.date,
|
||||||
@@ -193,33 +254,34 @@ fun ListExpenseScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemToDelete != null) {
|
}
|
||||||
DeleteConfirmationDialog(
|
|
||||||
onConfirm = {
|
|
||||||
onDeleteExpense(itemToDelete!!)
|
|
||||||
itemToDelete = null
|
|
||||||
},
|
|
||||||
onCancel = {
|
|
||||||
itemToDelete = null
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (showBottomSheet) {
|
if (itemToDelete != null) {
|
||||||
AddExpenseBottomSheet(
|
DeleteConfirmationDialog(
|
||||||
onSave = { expense ->
|
onConfirm = {
|
||||||
onSaveExpense(expense)
|
onDeleteExpense(itemToDelete!!)
|
||||||
showBottomSheet = false
|
itemToDelete = null
|
||||||
expenseDtoToEdit = null
|
},
|
||||||
},
|
onCancel = {
|
||||||
onDismiss = {
|
itemToDelete = null
|
||||||
expenseDtoToEdit = null
|
}
|
||||||
showBottomSheet = false
|
)
|
||||||
},
|
}
|
||||||
expenseDtoToEdit = expenseDtoToEdit,
|
|
||||||
state = sheetState
|
if (showBottomSheet) {
|
||||||
)
|
AddExpenseBottomSheet(
|
||||||
}
|
onSave = { expense ->
|
||||||
|
onSaveExpense(expense)
|
||||||
|
showBottomSheet = false
|
||||||
|
expenseDtoToEdit = null
|
||||||
|
},
|
||||||
|
onDismiss = {
|
||||||
|
expenseDtoToEdit = null
|
||||||
|
showBottomSheet = false
|
||||||
|
},
|
||||||
|
expenseDtoToEdit = expenseDtoToEdit,
|
||||||
|
state = sheetState
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,20 +401,22 @@ fun DeleteConfirmationDialog(
|
|||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(top = 24.dp)
|
.padding(top = 24.dp)
|
||||||
) {
|
) {
|
||||||
Text(
|
Button(
|
||||||
text = stringResource(string.cancel),
|
modifier = Modifier.padding(end = 20.dp),
|
||||||
style = MaterialTheme.typography.titleMedium,
|
onClick = onCancel
|
||||||
color = MaterialTheme.colorScheme.onSecondaryContainer,
|
) {
|
||||||
modifier = Modifier
|
Text(stringResource(string.cancel))
|
||||||
.padding(end = 24.dp)
|
}
|
||||||
.clickable { onCancel() }
|
|
||||||
)
|
Button(
|
||||||
Text(
|
onClick = onConfirm,
|
||||||
text = stringResource(string.delete),
|
colors = ButtonDefaults.buttonColors(
|
||||||
color = MaterialTheme.colorScheme.error,
|
containerColor = MaterialTheme.colorScheme.error,
|
||||||
style = MaterialTheme.typography.titleMedium,
|
contentColor = MaterialTheme.colorScheme.onError
|
||||||
modifier = Modifier.clickable { onConfirm() }
|
)
|
||||||
)
|
) {
|
||||||
|
Text(stringResource(string.delete))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -466,12 +530,69 @@ fun PreviewListExpenseScreen() {
|
|||||||
TripMoneyTheme() {
|
TripMoneyTheme() {
|
||||||
val pagingData = PagingData.from(sampleExpenseDtoWithConvertedAmountList())
|
val pagingData = PagingData.from(sampleExpenseDtoWithConvertedAmountList())
|
||||||
ListExpenseScreen(
|
ListExpenseScreen(
|
||||||
|
currentTrip = Trip(
|
||||||
|
id = 1,
|
||||||
|
name = "Vacation",
|
||||||
|
currency = "USD",
|
||||||
|
startDate = LocalDate.parse("2026-01-01"),
|
||||||
|
endDate = LocalDate.parse("2026-01-11"),
|
||||||
|
),
|
||||||
expensesFlow = MutableStateFlow(pagingData),
|
expensesFlow = MutableStateFlow(pagingData),
|
||||||
onSaveExpense = {},
|
onSaveExpense = {},
|
||||||
onDeleteExpense = {},
|
onDeleteExpense = {},
|
||||||
isRecalculatingRate = true,
|
isRecalculatingRate = true,
|
||||||
false,
|
false,
|
||||||
{}
|
{},
|
||||||
|
0,
|
||||||
|
""
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
|
@AllPreviews
|
||||||
|
@Composable
|
||||||
|
fun PreviewListExpenseScreenWithoutExpenses() {
|
||||||
|
TripMoneyTheme() {
|
||||||
|
val pagingData = PagingData.from(emptyList<ExpenseListItemUi>())
|
||||||
|
ListExpenseScreen(
|
||||||
|
currentTrip = Trip(
|
||||||
|
id = 1,
|
||||||
|
name = "Vacation",
|
||||||
|
currency = "USD",
|
||||||
|
startDate = LocalDate.parse("2026-01-01"),
|
||||||
|
endDate = LocalDate.parse("2026-01-11"),
|
||||||
|
),
|
||||||
|
expensesFlow = MutableStateFlow(pagingData),
|
||||||
|
onSaveExpense = {},
|
||||||
|
onDeleteExpense = {},
|
||||||
|
isRecalculatingRate = true,
|
||||||
|
false,
|
||||||
|
{},
|
||||||
|
0,
|
||||||
|
""
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
|
@AllPreviews
|
||||||
|
@Composable
|
||||||
|
fun PreviewListExpenseScreenWithoutTrip() {
|
||||||
|
TripMoneyTheme() {
|
||||||
|
val pagingData = PagingData.from(emptyList<ExpenseListItemUi>())
|
||||||
|
ListExpenseScreen(
|
||||||
|
currentTrip = null,
|
||||||
|
expensesFlow = MutableStateFlow(pagingData),
|
||||||
|
onSaveExpense = {},
|
||||||
|
onDeleteExpense = {},
|
||||||
|
isRecalculatingRate = true,
|
||||||
|
false,
|
||||||
|
{},
|
||||||
|
0,
|
||||||
|
""
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -480,7 +601,7 @@ fun PreviewListExpenseScreen() {
|
|||||||
@AllPreviews
|
@AllPreviews
|
||||||
@Composable
|
@Composable
|
||||||
fun PreviewDeleteConfirmationDialog() {
|
fun PreviewDeleteConfirmationDialog() {
|
||||||
TripMoneyTheme() {
|
TripMoneyTheme {
|
||||||
DeleteConfirmationDialog(
|
DeleteConfirmationDialog(
|
||||||
onConfirm = {},
|
onConfirm = {},
|
||||||
onCancel = {})
|
onCancel = {})
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.combinedClickable
|
import androidx.compose.foundation.combinedClickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
@@ -20,7 +19,6 @@ import androidx.compose.foundation.lazy.LazyColumn
|
|||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Add
|
import androidx.compose.material.icons.filled.Add
|
||||||
import androidx.compose.material.icons.filled.Delete
|
|
||||||
import androidx.compose.material3.BasicAlertDialog
|
import androidx.compose.material3.BasicAlertDialog
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.ButtonDefaults
|
import androidx.compose.material3.ButtonDefaults
|
||||||
@@ -48,7 +46,6 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.draw.alpha
|
import androidx.compose.ui.draw.alpha
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.layout.ModifierLocalBeyondBoundsLayout
|
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
@@ -63,9 +60,6 @@ import cc.n0th1ng.tripmoney.utils.AllPreviews
|
|||||||
import cc.n0th1ng.tripmoney.utils.colors
|
import cc.n0th1ng.tripmoney.utils.colors
|
||||||
import cc.n0th1ng.tripmoney.viewmodel.ExpenseAndCategoryViewModel
|
import cc.n0th1ng.tripmoney.viewmodel.ExpenseAndCategoryViewModel
|
||||||
import com.composables.icons.materialsymbols.outlined.R
|
import com.composables.icons.materialsymbols.outlined.R
|
||||||
import java.time.LocalDate
|
|
||||||
import java.time.format.DateTimeFormatter
|
|
||||||
import kotlin.collections.emptyList
|
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -159,7 +153,7 @@ fun ManageCategoriesScreen(
|
|||||||
|
|
||||||
if (itemToDelete != null) {
|
if (itemToDelete != null) {
|
||||||
DeleteConfirmationDialog(
|
DeleteConfirmationDialog(
|
||||||
bodyText = stringResource(string.delete_category_info),
|
bodyText = stringResource(string.delete_category_info).format(itemToDelete?.name),
|
||||||
onConfirm = {
|
onConfirm = {
|
||||||
onDeleteCategory(itemToDelete!!)
|
onDeleteCategory(itemToDelete!!)
|
||||||
itemToDelete = null
|
itemToDelete = null
|
||||||
@@ -236,7 +230,7 @@ fun SwipeToDeleteExpenseCard(
|
|||||||
Modifier
|
Modifier
|
||||||
.clip(CardDefaults.elevatedShape)
|
.clip(CardDefaults.elevatedShape)
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.background(MaterialTheme.colorScheme.onError)
|
.background(MaterialTheme.colorScheme.errorContainer)
|
||||||
.padding(horizontal = 20.dp),
|
.padding(horizontal = 20.dp),
|
||||||
contentAlignment = Alignment.CenterEnd
|
contentAlignment = Alignment.CenterEnd
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -4,15 +4,20 @@ import android.annotation.SuppressLint
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.horizontalScroll
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.heightIn
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
@@ -32,12 +37,18 @@ import androidx.compose.ui.graphics.Color
|
|||||||
import androidx.compose.ui.res.colorResource
|
import androidx.compose.ui.res.colorResource
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.core.graphics.toColorInt
|
import androidx.core.graphics.toColorInt
|
||||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||||
|
import androidx.navigation.NavController
|
||||||
import cc.n0th1ng.tripmoney.data.dto.SummaryPerCategory
|
import cc.n0th1ng.tripmoney.data.dto.SummaryPerCategory
|
||||||
|
import cc.n0th1ng.tripmoney.data.dto.SummaryPerDay
|
||||||
import cc.n0th1ng.tripmoney.data.entity.Category
|
import cc.n0th1ng.tripmoney.data.entity.Category
|
||||||
import cc.n0th1ng.tripmoney.data.entity.Trip
|
import cc.n0th1ng.tripmoney.data.entity.Trip
|
||||||
|
import cc.n0th1ng.tripmoney.navigation.Screens
|
||||||
import cc.n0th1ng.tripmoney.theme.TripMoneyTheme
|
import cc.n0th1ng.tripmoney.theme.TripMoneyTheme
|
||||||
import cc.n0th1ng.tripmoney.utils.AllPreviews
|
import cc.n0th1ng.tripmoney.utils.AllPreviews
|
||||||
import cc.n0th1ng.tripmoney.utils.Currencies
|
import cc.n0th1ng.tripmoney.utils.Currencies
|
||||||
@@ -47,10 +58,12 @@ import cc.n0th1ng.tripmoney.viewmodel.ExpenseAndCategoryViewModel
|
|||||||
import cc.n0th1ng.tripmoney.viewmodel.SettingsViewModel
|
import cc.n0th1ng.tripmoney.viewmodel.SettingsViewModel
|
||||||
import cc.n0th1ng.tripmoney.viewmodel.TripViewModel
|
import cc.n0th1ng.tripmoney.viewmodel.TripViewModel
|
||||||
import com.composables.icons.materialsymbols.outlined.R
|
import com.composables.icons.materialsymbols.outlined.R
|
||||||
|
import java.time.LocalDate
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
@Composable
|
@Composable
|
||||||
fun StatisticsScreen() {
|
fun StatisticsScreen(navController: NavController) {
|
||||||
val expenseAndCategoryViewModel: ExpenseAndCategoryViewModel = hiltViewModel()
|
val expenseAndCategoryViewModel: ExpenseAndCategoryViewModel = hiltViewModel()
|
||||||
val settingsViewModel: SettingsViewModel = hiltViewModel()
|
val settingsViewModel: SettingsViewModel = hiltViewModel()
|
||||||
val tripViewModel: TripViewModel = hiltViewModel()
|
val tripViewModel: TripViewModel = hiltViewModel()
|
||||||
@@ -58,14 +71,20 @@ fun StatisticsScreen() {
|
|||||||
val currentTrip by tripViewModel.getTrip(currentTripId).collectAsState(Trip.DUMMY)
|
val currentTrip by tripViewModel.getTrip(currentTripId).collectAsState(Trip.DUMMY)
|
||||||
val summaryPerCategoryList by expenseAndCategoryViewModel.getSummaryPerCategory(currentTripId)
|
val summaryPerCategoryList by expenseAndCategoryViewModel.getSummaryPerCategory(currentTripId)
|
||||||
.collectAsState(emptyList())
|
.collectAsState(emptyList())
|
||||||
|
val summaryPerDayList by expenseAndCategoryViewModel.getSummaryPerDay(currentTripId)
|
||||||
|
.collectAsState(emptyList())
|
||||||
val summaryAmount by expenseAndCategoryViewModel.getSummaryAmount(currentTripId)
|
val summaryAmount by expenseAndCategoryViewModel.getSummaryAmount(currentTripId)
|
||||||
.collectAsState(0.0)
|
.collectAsState(0.0)
|
||||||
val moneyLeft by expenseAndCategoryViewModel.getBudgetLeft(currentTripId).collectAsState(null)
|
val moneyLeft by expenseAndCategoryViewModel.getBudgetLeft(currentTripId).collectAsState(null)
|
||||||
StatisticsScreen(
|
StatisticsScreen(
|
||||||
summaryPerCategoryList,
|
summaryPerCategoryList,
|
||||||
|
summaryPerDayList,
|
||||||
summaryAmount,
|
summaryAmount,
|
||||||
Currencies.valueOf(currentTrip?.currency ?: Currencies.default().name),
|
Currencies.valueOf(currentTrip?.currency ?: Currencies.default().name),
|
||||||
moneyLeft
|
moneyLeft,
|
||||||
|
onDayClicked = {
|
||||||
|
date -> navController.navigate(Screens.LIST_EXPENSE + "?dateToScroll=$date")
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,9 +92,11 @@ fun StatisticsScreen() {
|
|||||||
@Composable
|
@Composable
|
||||||
fun StatisticsScreen(
|
fun StatisticsScreen(
|
||||||
summaryPerCategoryList: List<SummaryPerCategory>,
|
summaryPerCategoryList: List<SummaryPerCategory>,
|
||||||
|
summaryPerDayList: List<SummaryPerDay>,
|
||||||
summaryAmount: Double,
|
summaryAmount: Double,
|
||||||
tripCurrency: Currencies,
|
tripCurrency: Currencies,
|
||||||
moneyLeft: Double?
|
moneyLeft: Double?,
|
||||||
|
onDayClicked: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -85,7 +106,9 @@ fun StatisticsScreen(
|
|||||||
) {
|
) {
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||||
Summary(
|
Summary(
|
||||||
Modifier.weight(1f), -1 * summaryAmount, tripCurrency.name,
|
Modifier.weight(1f),
|
||||||
|
if (summaryAmount == 0.0) 0.0 else -1 * summaryAmount,
|
||||||
|
tripCurrency.name,
|
||||||
stringResource(cc.n0th1ng.tripmoney.R.string.total_expenses),
|
stringResource(cc.n0th1ng.tripmoney.R.string.total_expenses),
|
||||||
R.drawable.materialsymbols_ic_payment_arrow_down_outlined,
|
R.drawable.materialsymbols_ic_payment_arrow_down_outlined,
|
||||||
iconColor = MaterialTheme.colorScheme.error
|
iconColor = MaterialTheme.colorScheme.error
|
||||||
@@ -97,8 +120,11 @@ fun StatisticsScreen(
|
|||||||
iconColor = colorResource(cc.n0th1ng.tripmoney.R.color.good_green)
|
iconColor = colorResource(cc.n0th1ng.tripmoney.R.color.good_green)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
SummaryPerCategoryCard(summaryPerCategoryList)
|
SummaryPerCategoryCard(
|
||||||
|
modifier = Modifier.heightIn(max = 300.dp),
|
||||||
|
summaryPerCategoryList = summaryPerCategoryList
|
||||||
|
)
|
||||||
|
SummaryPerDayCard(modifier = Modifier.height(300.dp), summaryPerDayList = summaryPerDayList, onDayClicked = onDayClicked)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,25 +179,87 @@ fun Summary(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SummaryPerCategoryCard(summaryPerCategoryList: List<SummaryPerCategory>) {
|
fun SummaryPerCategoryCard(
|
||||||
|
summaryPerCategoryList: List<SummaryPerCategory>,
|
||||||
|
modifier: Modifier = Modifier
|
||||||
|
) {
|
||||||
ElevatedCard(
|
ElevatedCard(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = modifier.fillMaxWidth(),
|
||||||
colors = CardDefaults.elevatedCardColors()
|
colors = CardDefaults.elevatedCardColors()
|
||||||
.copy(containerColor = MaterialTheme.colorScheme.surfaceContainer)
|
.copy(containerColor = MaterialTheme.colorScheme.surfaceContainer)
|
||||||
) {
|
) {
|
||||||
Column(
|
if (summaryPerCategoryList.isEmpty()) {
|
||||||
modifier = Modifier
|
Box(
|
||||||
.padding(15.dp)
|
modifier = Modifier
|
||||||
.verticalScroll(rememberScrollState()),
|
.fillMaxSize()
|
||||||
|
.padding(10.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(5.dp)
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
summaryPerCategoryList.forEach {
|
Text(
|
||||||
CategoryCard(
|
text = stringResource(cc.n0th1ng.tripmoney.R.string.no_expenses_summary),
|
||||||
summaryPerCategory = it, modifier = Modifier
|
textAlign = TextAlign.Center,
|
||||||
.fillMaxWidth()
|
fontWeight = FontWeight.Light,
|
||||||
|
style = MaterialTheme.typography.headlineMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.7f)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(15.dp)
|
||||||
|
.verticalScroll(rememberScrollState()),
|
||||||
|
|
||||||
|
verticalArrangement = Arrangement.spacedBy(5.dp)
|
||||||
|
) {
|
||||||
|
summaryPerCategoryList.forEach {
|
||||||
|
CategoryCard(
|
||||||
|
summaryPerCategory = it, modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
|
@Composable
|
||||||
|
fun SummaryPerDayCard(modifier: Modifier = Modifier, summaryPerDayList: List<SummaryPerDay>, onDayClicked: (String) -> Unit) {
|
||||||
|
ElevatedCard(
|
||||||
|
modifier = modifier
|
||||||
|
.fillMaxWidth(),
|
||||||
|
colors = CardDefaults.elevatedCardColors()
|
||||||
|
.copy(containerColor = MaterialTheme.colorScheme.surfaceContainer)
|
||||||
|
) {
|
||||||
|
if (summaryPerDayList.isEmpty()) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(10.dp),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = stringResource(cc.n0th1ng.tripmoney.R.string.no_expenses_summary),
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
fontWeight = FontWeight.Light,
|
||||||
|
style = MaterialTheme.typography.headlineMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.7f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(15.dp)
|
||||||
|
.horizontalScroll(rememberScrollState()),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(5.dp)
|
||||||
|
) {
|
||||||
|
summaryPerDayList.forEach { it ->
|
||||||
|
DayCard(
|
||||||
|
summaryPerDay = it,
|
||||||
|
onDayClicked = {date -> onDayClicked(date)}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -234,23 +322,107 @@ fun CategoryCard(modifier: Modifier = Modifier, summaryPerCategory: SummaryPerCa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
|
@Composable
|
||||||
|
fun DayCard(modifier: Modifier = Modifier, summaryPerDay: SummaryPerDay, onDayClicked: (String) -> Unit) {
|
||||||
|
Column(
|
||||||
|
modifier = modifier.fillMaxHeight(), verticalArrangement = Arrangement.Bottom,
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
|
) {
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = "%.2f".format(summaryPerDay.amount),
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
fontSize = (MaterialTheme.typography.labelSmall.fontSize.value - 2).sp,
|
||||||
|
)
|
||||||
|
val width = 45.dp
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.width(width)
|
||||||
|
.fillMaxHeight(0.2f + (0.98f - 0.2f) * summaryPerDay.percent)
|
||||||
|
.clip(RoundedCornerShape(width / 2))
|
||||||
|
.background(MaterialTheme.colorScheme.primary)
|
||||||
|
.clickable(onClick = {onDayClicked(summaryPerDay.day.toString())})
|
||||||
|
.padding(top = 5.dp)
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.Center
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
verticalArrangement = Arrangement.Center,
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
modifier = Modifier
|
||||||
|
.size(width - 10.dp)
|
||||||
|
.background(
|
||||||
|
MaterialTheme.colorScheme.tertiaryContainer,
|
||||||
|
shape = RoundedCornerShape(width / 2)
|
||||||
|
)
|
||||||
|
.padding(vertical = 3.dp),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
lineHeight = 10.sp,
|
||||||
|
color = MaterialTheme.colorScheme.onTertiaryContainer,
|
||||||
|
text = summaryPerDay.day.format(DateTimeFormatter.ofPattern("dd"))
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
fontWeight = FontWeight.Light,
|
||||||
|
fontSize = (MaterialTheme.typography.labelSmall.fontSize.value - 2).sp,
|
||||||
|
lineHeight = 10.sp,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
color = MaterialTheme.colorScheme.onTertiaryContainer,
|
||||||
|
text = summaryPerDay.day.format(DateTimeFormatter.ofPattern("E"))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
@AllPreviews
|
@AllPreviews
|
||||||
@Composable
|
@Composable
|
||||||
fun Preview() {
|
fun PreviewStatisticScreen() {
|
||||||
TripMoneyTheme {
|
TripMoneyTheme {
|
||||||
Scaffold {
|
Scaffold {
|
||||||
StatisticsScreen(
|
StatisticsScreen(
|
||||||
summaryPerCategoryList,
|
summaryPerCategoryList,
|
||||||
|
summaryPerDayList,
|
||||||
summaryAmount = 125.24,
|
summaryAmount = 125.24,
|
||||||
Currencies.entries.random(),
|
Currencies.entries.random(),
|
||||||
432.14
|
432.14,
|
||||||
|
{}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
|
@AllPreviews
|
||||||
|
@Composable
|
||||||
|
fun PreviewStatisticScreenWithNoData() {
|
||||||
|
TripMoneyTheme {
|
||||||
|
Scaffold {
|
||||||
|
StatisticsScreen(
|
||||||
|
emptyList(),
|
||||||
|
emptyList(),
|
||||||
|
summaryAmount = 0.0,
|
||||||
|
Currencies.entries.random(),
|
||||||
|
null,
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
val categories = listOf(
|
val categories = listOf(
|
||||||
Category(name = "Jedzenie", icon = Icons.RESTAURANT, color = colors.random()),
|
Category(name = "Jedzenie", icon = Icons.RESTAURANT, color = colors.random()),
|
||||||
Category(name = "Transport", icon = Icons.FLIGHT, color = colors.random()),
|
Category(name = "Transport", icon = Icons.FLIGHT, color = colors.random()),
|
||||||
@@ -268,4 +440,26 @@ val summaryPerCategoryList = listOf(
|
|||||||
SummaryPerCategory(categories[2], 80.0, 0.2f, Currencies.PLN),
|
SummaryPerCategory(categories[2], 80.0, 0.2f, Currencies.PLN),
|
||||||
SummaryPerCategory(categories[3], 50.0, 0.1f, Currencies.PLN),
|
SummaryPerCategory(categories[3], 50.0, 0.1f, Currencies.PLN),
|
||||||
SummaryPerCategory(categories[5], 50.0, 0.0001f, Currencies.PLN),
|
SummaryPerCategory(categories[5], 50.0, 0.0001f, Currencies.PLN),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
|
val summaryPerDayListRaw = listOf(
|
||||||
|
SummaryPerDay(LocalDate.now(), 50.0, 0f),
|
||||||
|
SummaryPerDay(LocalDate.now().minusDays(1), 500.23, 0f),
|
||||||
|
SummaryPerDay(LocalDate.now().minusDays(2), 1560.53, 0f),
|
||||||
|
SummaryPerDay(LocalDate.now().minusDays(3), 700.32, 0f),
|
||||||
|
SummaryPerDay(LocalDate.now().minusDays(4), 201.3, 0f),
|
||||||
|
SummaryPerDay(LocalDate.now().minusDays(5), 2020.64, 0f),
|
||||||
|
SummaryPerDay(LocalDate.now().minusDays(6), 510.43, 0f),
|
||||||
|
SummaryPerDay(LocalDate.now().minusDays(7), 3050.12, 0f),
|
||||||
|
SummaryPerDay(LocalDate.now().minusDays(8), 264.32, 0f),
|
||||||
|
SummaryPerDay(LocalDate.now().minusDays(9), 3596.64, 0f)
|
||||||
|
)
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
|
val highestAmount = summaryPerDayListRaw.maxOf { it.amount }
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
|
val summaryPerDayList = summaryPerDayListRaw.map {
|
||||||
|
it.copy(percent = ((it.amount / highestAmount)).toFloat())
|
||||||
|
}.sortedBy { it.day.toEpochDay() }
|
||||||
@@ -38,14 +38,13 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.alpha
|
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.paging.PagingData
|
import androidx.paging.PagingData
|
||||||
@@ -113,32 +112,45 @@ fun TripPickerScreen(
|
|||||||
Icon(Icons.Filled.Add, stringResource(string.add_trip))
|
Icon(Icons.Filled.Add, stringResource(string.add_trip))
|
||||||
}
|
}
|
||||||
}) { paddingValues ->
|
}) { paddingValues ->
|
||||||
LazyColumn(
|
if (trips.itemCount == 0) {
|
||||||
modifier = Modifier
|
Box(modifier = Modifier.fillMaxSize().padding(10.dp), contentAlignment = Alignment.Center) {
|
||||||
.padding(horizontal = 15.dp)
|
Text(
|
||||||
.fillMaxSize(),
|
text = stringResource(string.no_trip_added),
|
||||||
verticalArrangement = Arrangement.Center
|
textAlign = TextAlign.Center,
|
||||||
) {
|
fontWeight = FontWeight.Light,
|
||||||
items(trips.itemCount, trips.itemKey { it.id }) { i ->
|
style = MaterialTheme.typography.headlineMedium,
|
||||||
Spacer(Modifier.height(10.dp))
|
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.7f)
|
||||||
val trip = trips[i]
|
)
|
||||||
if (trip != null) {
|
}
|
||||||
SwipeToDeleteTripCard(
|
} else {
|
||||||
trip = trip,
|
LazyColumn(
|
||||||
onDelete = {
|
modifier = Modifier
|
||||||
onDelete(trip)
|
.padding(horizontal = 15.dp)
|
||||||
}, onClick = {
|
.fillMaxSize(),
|
||||||
onClick(trip)
|
verticalArrangement = Arrangement.Center
|
||||||
}, isSelected = currentTripId == trip.id,
|
) {
|
||||||
onLongClick = { trip ->
|
items(trips.itemCount, trips.itemKey { it.id }) { i ->
|
||||||
tripToEdit = trip
|
Spacer(Modifier.height(10.dp))
|
||||||
showBottomSheet = true
|
val trip = trips[i]
|
||||||
})
|
if (trip != null) {
|
||||||
|
SwipeToDeleteTripCard(
|
||||||
|
trip = trip,
|
||||||
|
onDelete = {
|
||||||
|
onDelete(trip)
|
||||||
|
}, onClick = {
|
||||||
|
onClick(trip)
|
||||||
|
}, isSelected = currentTripId == trip.id,
|
||||||
|
onLongClick = { trip ->
|
||||||
|
tripToEdit = trip
|
||||||
|
showBottomSheet = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Spacer(Modifier.height(10.dp))
|
||||||
}
|
}
|
||||||
Spacer(Modifier.height(10.dp))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (showBottomSheet) {
|
if (showBottomSheet) {
|
||||||
AddTripBottomSheet(
|
AddTripBottomSheet(
|
||||||
onDismiss = {
|
onDismiss = {
|
||||||
@@ -250,7 +262,8 @@ fun TripCard(
|
|||||||
}
|
}
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.padding(end = 20.dp),
|
modifier = Modifier.padding(end = 20.dp),
|
||||||
horizontalAlignment = Alignment.End) {
|
horizontalAlignment = Alignment.End
|
||||||
|
) {
|
||||||
Text(
|
Text(
|
||||||
trip.currency.uppercase(),
|
trip.currency.uppercase(),
|
||||||
style = MaterialTheme.typography.titleLarge,
|
style = MaterialTheme.typography.titleLarge,
|
||||||
@@ -307,4 +320,19 @@ fun PreviewTripPickerScreen() {
|
|||||||
onSave = {}
|
onSave = {}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
|
@AllPreviews
|
||||||
|
@Composable
|
||||||
|
fun PreviewTripPickerScreenNoTrip() {
|
||||||
|
TripMoneyTheme {
|
||||||
|
TripPickerScreen(
|
||||||
|
tripsFlow = MutableStateFlow(PagingData.from(emptyList())),
|
||||||
|
currentTripId = 1,
|
||||||
|
onDelete = {},
|
||||||
|
onClick = {},
|
||||||
|
onSave = {}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,169 @@
|
|||||||
package cc.n0th1ng.tripmoney.utils
|
package cc.n0th1ng.tripmoney.utils
|
||||||
|
|
||||||
enum class Currencies {
|
enum class Currencies {
|
||||||
|
AED,
|
||||||
|
AFN,
|
||||||
|
ALL,
|
||||||
|
AMD,
|
||||||
|
ANG,
|
||||||
|
AOA,
|
||||||
|
ARS,
|
||||||
|
AUD,
|
||||||
|
AWG,
|
||||||
|
AZN,
|
||||||
|
BAM,
|
||||||
|
BBD,
|
||||||
|
BDT,
|
||||||
|
BHD,
|
||||||
|
BIF,
|
||||||
|
BMD,
|
||||||
|
BND,
|
||||||
|
BOB,
|
||||||
|
BRL,
|
||||||
|
BSD,
|
||||||
|
BTN,
|
||||||
|
BWP,
|
||||||
|
BYN,
|
||||||
|
BZD,
|
||||||
|
CAD,
|
||||||
|
CDF,
|
||||||
|
CHF,
|
||||||
|
CLP,
|
||||||
|
CNH,
|
||||||
|
CNY,
|
||||||
|
COP,
|
||||||
|
CRC,
|
||||||
|
CUP,
|
||||||
|
CVE,
|
||||||
|
CZK,
|
||||||
|
DJF,
|
||||||
|
DKK,
|
||||||
|
DOP,
|
||||||
|
DZD,
|
||||||
|
EGP,
|
||||||
|
ERN,
|
||||||
|
ETB,
|
||||||
|
FJD,
|
||||||
|
FKP,
|
||||||
|
GBP,
|
||||||
|
GEL,
|
||||||
|
GGP,
|
||||||
|
GHS,
|
||||||
|
GIP,
|
||||||
|
GMD,
|
||||||
|
GNF,
|
||||||
|
GTQ,
|
||||||
|
GYD,
|
||||||
|
HKD,
|
||||||
|
HNL,
|
||||||
|
HTG,
|
||||||
|
HUF,
|
||||||
|
IDR,
|
||||||
|
ILS,
|
||||||
|
IMP,
|
||||||
|
INR,
|
||||||
|
IQD,
|
||||||
|
IRR,
|
||||||
|
ISK,
|
||||||
|
JEP,
|
||||||
|
JMD,
|
||||||
|
JOD,
|
||||||
|
JPY,
|
||||||
|
KES,
|
||||||
|
KGS,
|
||||||
|
KHR,
|
||||||
|
KMF,
|
||||||
|
KRW,
|
||||||
|
KWD,
|
||||||
|
KYD,
|
||||||
|
KZT,
|
||||||
|
LAK,
|
||||||
|
LBP,
|
||||||
|
LKR,
|
||||||
|
LRD,
|
||||||
|
LSL,
|
||||||
|
LYD,
|
||||||
|
MAD,
|
||||||
|
MDL,
|
||||||
|
MGA,
|
||||||
|
MKD,
|
||||||
|
MMK,
|
||||||
|
MNT,
|
||||||
|
MOP,
|
||||||
|
MRO,
|
||||||
|
MRU,
|
||||||
|
MUR,
|
||||||
|
MVR,
|
||||||
|
MWK,
|
||||||
|
MXN,
|
||||||
|
MYR,
|
||||||
|
MZN,
|
||||||
|
NAD,
|
||||||
|
NGN,
|
||||||
|
NIO,
|
||||||
|
NOK,
|
||||||
|
NPR,
|
||||||
|
NZD,
|
||||||
|
OMR,
|
||||||
|
PAB,
|
||||||
|
PEN,
|
||||||
|
PGK,
|
||||||
|
PHP,
|
||||||
|
PKR,
|
||||||
PLN,
|
PLN,
|
||||||
EUR,
|
PYG,
|
||||||
|
QAR,
|
||||||
|
RON,
|
||||||
|
RSD,
|
||||||
|
RUB,
|
||||||
|
RWF,
|
||||||
|
SAR,
|
||||||
|
SBD,
|
||||||
|
SCR,
|
||||||
|
SDG,
|
||||||
|
SEK,
|
||||||
|
SGD,
|
||||||
|
SHP,
|
||||||
|
SLE,
|
||||||
|
SOS,
|
||||||
|
SRD,
|
||||||
|
SSP,
|
||||||
|
STN,
|
||||||
|
SVC,
|
||||||
|
SYP,
|
||||||
|
SZL,
|
||||||
|
THB,
|
||||||
|
TJS,
|
||||||
|
TMT,
|
||||||
|
TND,
|
||||||
|
TOP,
|
||||||
|
TRY,
|
||||||
|
TTD,
|
||||||
|
TWD,
|
||||||
|
TZS,
|
||||||
|
UAH,
|
||||||
|
UGX,
|
||||||
USD,
|
USD,
|
||||||
RON;
|
UYU,
|
||||||
|
UZS,
|
||||||
|
VES,
|
||||||
|
VND,
|
||||||
|
VUV,
|
||||||
|
WST,
|
||||||
|
XAF,
|
||||||
|
XAG,
|
||||||
|
XAU,
|
||||||
|
XCD,
|
||||||
|
XCG,
|
||||||
|
XDR,
|
||||||
|
XOF,
|
||||||
|
XPD,
|
||||||
|
XPF,
|
||||||
|
XPT,
|
||||||
|
YER,
|
||||||
|
ZAR,
|
||||||
|
ZMW,
|
||||||
|
ZWG;
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun default(): Currencies {
|
fun default(): Currencies {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import androidx.paging.insertSeparators
|
|||||||
import androidx.paging.map
|
import androidx.paging.map
|
||||||
import cc.n0th1ng.tripmoney.Filter
|
import cc.n0th1ng.tripmoney.Filter
|
||||||
import cc.n0th1ng.tripmoney.data.dto.SummaryPerCategory
|
import cc.n0th1ng.tripmoney.data.dto.SummaryPerCategory
|
||||||
|
import cc.n0th1ng.tripmoney.data.dto.SummaryPerDay
|
||||||
import cc.n0th1ng.tripmoney.data.entity.Category
|
import cc.n0th1ng.tripmoney.data.entity.Category
|
||||||
import cc.n0th1ng.tripmoney.data.entity.Expense
|
import cc.n0th1ng.tripmoney.data.entity.Expense
|
||||||
import cc.n0th1ng.tripmoney.data.entity.ExpenseDto
|
import cc.n0th1ng.tripmoney.data.entity.ExpenseDto
|
||||||
@@ -44,7 +45,11 @@ open class ExpenseAndCategoryViewModel @Inject constructor(
|
|||||||
return expenseRepo.getBudgetLeft(tripId)
|
return expenseRepo.getBudgetLeft(tripId)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getExpensesDtoPaged(tripId: Int, search: String = "", filter: Filter = Filter()): Flow<PagingData<ExpenseDto>> =
|
fun getExpensesDtoPaged(
|
||||||
|
tripId: Int,
|
||||||
|
search: String = "",
|
||||||
|
filter: Filter = Filter()
|
||||||
|
): Flow<PagingData<ExpenseDto>> =
|
||||||
expenseRepo.getExpensesDtoPaged(tripId, search, filter).cachedIn(viewModelScope)
|
expenseRepo.getExpensesDtoPaged(tripId, search, filter).cachedIn(viewModelScope)
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
@@ -86,18 +91,23 @@ open class ExpenseAndCategoryViewModel @Inject constructor(
|
|||||||
}.cachedIn(viewModelScope)
|
}.cachedIn(viewModelScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getExpensesDto(tripId: Int, search: String = "", filter: Filter = Filter()): Flow<List<ExpenseDto>> =
|
fun getExpensesDto(
|
||||||
|
tripId: Int,
|
||||||
|
search: String = "",
|
||||||
|
filter: Filter = Filter()
|
||||||
|
): Flow<List<ExpenseDto>> =
|
||||||
expenseRepo.getExpensesDto(tripId, search, filter)
|
expenseRepo.getExpensesDto(tripId, search, filter)
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
fun save(expense: Expense, trip: Trip) {
|
fun save(expense: Expense, trip: Trip, onComplete: (Int) -> Unit) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val rate = exchangeRateRepository.getRate(
|
val rate = exchangeRateRepository.getRate(
|
||||||
Currencies.valueOf(expense.currency),
|
Currencies.valueOf(expense.currency),
|
||||||
Currencies.valueOf(trip.currency),
|
Currencies.valueOf(trip.currency),
|
||||||
expense.datetime.toLocalDate()
|
expense.datetime.toLocalDate()
|
||||||
)
|
)
|
||||||
expenseRepo.save(expense.copy(rate = rate))
|
val id = expenseRepo.save(expense.copy(rate = rate))
|
||||||
|
onComplete(id.toInt())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,6 +194,32 @@ open class ExpenseAndCategoryViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
|
fun getSummaryPerDay(tripId: Int): Flow<List<SummaryPerDay>> {
|
||||||
|
val tripFlow = tripRepo.getTrip(tripId)
|
||||||
|
val expensesFlow = getExpensesDto(tripId)
|
||||||
|
|
||||||
|
return tripFlow.combine(expensesFlow) { trip, expenses ->
|
||||||
|
val summaryPerDayRaw = expenses.groupBy { it.expense.datetime.toLocalDate() }
|
||||||
|
.map { (day, expensesForDay) ->
|
||||||
|
val total = expensesForDay.sumOf { it.expense.convertedAmount() }
|
||||||
|
SummaryPerDay(
|
||||||
|
amount = total,
|
||||||
|
day = day,
|
||||||
|
percent = 0.0f
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.sortedByDescending { it.day }
|
||||||
|
|
||||||
|
|
||||||
|
val highestAmount =
|
||||||
|
if (summaryPerDayRaw.isEmpty()) 1.0 else summaryPerDayRaw.maxOf { it.amount }
|
||||||
|
summaryPerDayRaw.map {
|
||||||
|
it.copy(percent = ((it.amount / highestAmount)).toFloat())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
fun clearOldRates() {
|
fun clearOldRates() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
|||||||
@@ -32,4 +32,17 @@
|
|||||||
<string name="export_csv_subttext">Zapisz wydatki z %s do pliku</string>
|
<string name="export_csv_subttext">Zapisz wydatki z %s do pliku</string>
|
||||||
<string name="add_new_category">Dodaj kategorie</string>
|
<string name="add_new_category">Dodaj kategorie</string>
|
||||||
<string name="edit_category">Edytuj kategorie</string>
|
<string name="edit_category">Edytuj kategorie</string>
|
||||||
|
<string name="archive">Archiwizuj</string>
|
||||||
|
<string name="you_want_archive">Chcesz zarchiwizować?</string>
|
||||||
|
<string name="archive_category_info">Żadne wydatki nie będą usunięte.</string>
|
||||||
|
<string name="delete_category_info">Wszystkie wydatki z kategorii %s zostaną usunięte.</string>
|
||||||
|
<string name="budget">Budżet</string>
|
||||||
|
<string name="money_left">Pozostałe środki</string>
|
||||||
|
<string name="add_expense_settings">Pokaż dodawanie wydatku na starcie</string>
|
||||||
|
<string name="yesterday">Wczoraj</string>
|
||||||
|
<string name="clear">Wyczyść</string>
|
||||||
|
<string name="no_expenses">Zacznij budżetowanie od dodania wydatków</string>
|
||||||
|
<string name="no_trip_picked">Wybierz wycieczkę żeby zobaczyć wydatki</string>
|
||||||
|
<string name="no_trip_added">Zacznij budżetowanie od dodania wycieczki</string>
|
||||||
|
<string name="no_expenses_summary">Brak wydatków do podsumowania</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -35,10 +35,14 @@
|
|||||||
<string name="archive">Archive</string>
|
<string name="archive">Archive</string>
|
||||||
<string name="you_want_archive">Do you want to archive?</string>
|
<string name="you_want_archive">Do you want to archive?</string>
|
||||||
<string name="archive_category_info">No expense will be deleted.</string>
|
<string name="archive_category_info">No expense will be deleted.</string>
|
||||||
<string name="delete_category_info">Your all expenses with category Hotel will be removed.</string>
|
<string name="delete_category_info">Your all expenses with category %s will be removed.</string>
|
||||||
<string name="budget">Budget</string>
|
<string name="budget">Budget</string>
|
||||||
<string name="money_left">Money left</string>
|
<string name="money_left">Money left</string>
|
||||||
<string name="add_expense_settings">Open add expense form on startup</string>
|
<string name="add_expense_settings">Open add expense form on startup</string>
|
||||||
<string name="yesterday">Yesterday</string>
|
<string name="yesterday">Yesterday</string>
|
||||||
<string name="clear">Clear</string>
|
<string name="clear">Clear</string>
|
||||||
|
<string name="no_expenses">Start budgeting by adding expenses</string>
|
||||||
|
<string name="no_trip_picked">Select trip to see expenses</string>
|
||||||
|
<string name="no_trip_added">Start budgeting by adding your trip</string>
|
||||||
|
<string name="no_expenses_summary">No expenses to summarize</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user