diff --git a/app/src/main/java/com/hyperling/expensetracker/MainActivity.kt b/app/src/main/java/com/hyperling/expensetracker/MainActivity.kt index 3b3335d..5cce765 100644 --- a/app/src/main/java/com/hyperling/expensetracker/MainActivity.kt +++ b/app/src/main/java/com/hyperling/expensetracker/MainActivity.kt @@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material3.Button import androidx.compose.material3.FloatingActionButton @@ -17,6 +18,10 @@ import androidx.compose.material3.Scaffold import androidx.compose.material3.Surface import androidx.compose.material3.Text 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.Modifier import androidx.compose.ui.platform.LocalContext @@ -46,23 +51,47 @@ class MainActivity : ComponentActivity() { fun Main() { 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 ( horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center, modifier = Modifier.fillMaxSize() ) { - Row ( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.Center - ) { - Text( - text = "Main Screen" - ) + Text( + text = "Current Expense Summary" + ) + + //for ((name, value) in sums) { + 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 ( verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.Center + horizontalArrangement = Arrangement.Center, ) { Button(onClick = { val intent = Intent(context, NewExpenseActivity::class.java) @@ -71,6 +100,34 @@ fun Main() { 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)) } }