Starting to set up main UI for receiving expenses. Definitely in a FORTESTING state.

This commit is contained in:
Hyperling 2024-07-20 13:08:42 -07:00
parent 8f0b1539ec
commit 0d0d6ad90c

View File

@ -10,6 +10,7 @@ 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.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button import androidx.compose.material3.Button
import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.FloatingActionButton
@ -17,6 +18,10 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
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.platform.LocalContext import androidx.compose.ui.platform.LocalContext
@ -46,23 +51,47 @@ class MainActivity : ComponentActivity() {
fun Main() { fun Main() {
val context = LocalContext.current val context = LocalContext.current
var sumDaily by remember { mutableStateOf(0.0) }
var sumWeekly by remember { mutableStateOf(0.0) }
var sumMonthly by remember { mutableStateOf(0.0) }
var sumYearly by remember { mutableStateOf(0.0) }
val sums = mapOf(
"Daily" to sumDaily,
"Weekly" to sumWeekly,
"Monthly" to sumMonthly,
"Yearly" to sumYearly,
)
Column ( Column (
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center, verticalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxSize() modifier = Modifier.fillMaxSize()
) { ) {
Row ( Text(
verticalAlignment = Alignment.CenterVertically, text = "Current Expense Summary"
horizontalArrangement = Arrangement.Center )
) {
Text( //for ((name, value) in sums) {
text = "Main Screen" sums.forEach { (name, value) ->
) Row (
horizontalArrangement = Arrangement.End,
){
Text(text = name + ": ")
Text(text = value.toString())
}
} }
// FORTESTING
Text (text = String.format("%.2f",sumDaily))
Text (text = String.format("%.2f",sumWeekly))
Text (text = String.format("%.2f",sumMonthly))
Text (text = String.format("%.2f",sumYearly))
Row ( Row (
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center horizontalArrangement = Arrangement.Center,
) { ) {
Button(onClick = { Button(onClick = {
val intent = Intent(context, NewExpenseActivity::class.java) val intent = Intent(context, NewExpenseActivity::class.java)
@ -71,6 +100,34 @@ fun Main() {
Text(text = "Create New Expense") Text(text = "Create New Expense")
} }
} }
Text(text = "Expenses")
// https://medium.com/@rowaido.game/implementing-the-room-library-with-jetpack-compose-590d13101fa7
/* TODO:
ForEach over all DB records, show it, and add its value to the summary.
*/
val expenseArray = listOf(
Expense("Test", 180.0, 'Y', "My notes."),
Expense("Test2", 20.0, 'M', "My notes, 2!"),
)
expenseArray.forEach { expense ->
when (expense.freq) {
'D' -> sumYearly += (expense.cost * 365.25)
'W' -> sumYearly += (expense.cost * (365.25 / 7))
'M' -> sumYearly += (expense.cost * 12)
'Y' -> sumYearly += (expense.cost)
}
sumDaily = sumYearly / 365.25
sumWeekly = sumYearly / (365.25 / 7)
sumMonthly = sumYearly / 12
}
// FORTESTING
Text (text = String.format("$ %.2f",sumDaily))
Text (text = String.format("$ %.2f",sumWeekly))
Text (text = String.format("$ %.2f",sumMonthly))
Text (text = String.format("$ %.2f",sumYearly))
} }
} }