Skip to content

Commit

Permalink
Merge pull request #1 from DennisBauer/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
DennisBauer authored Sep 23, 2023
2 parents add9c5e + 03ebadb commit b267d2a
Show file tree
Hide file tree
Showing 10 changed files with 284 additions and 173 deletions.
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/title_activity_main"
android:theme="@style/Theme.ExpenseTracker">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
201 changes: 111 additions & 90 deletions app/src/main/java/de/dbauer/expensetracker/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Add
import androidx.compose.material.icons.rounded.Home
import androidx.compose.material.icons.rounded.Settings
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
Expand All @@ -29,15 +27,16 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.view.WindowCompat
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import de.dbauer.expensetracker.data.BottomNavItem
import de.dbauer.expensetracker.data.NavigationRoute
import de.dbauer.expensetracker.data.BottomNavigation
import de.dbauer.expensetracker.data.RecurringExpenseData
import de.dbauer.expensetracker.ui.EditRecurringExpense
import de.dbauer.expensetracker.ui.RecurringExpenseOverview
Expand Down Expand Up @@ -68,6 +67,9 @@ class MainActivity : ComponentActivity() {
},
onRecurringExpenseEdited = {
viewModel.editRecurringExpense(it)
},
onRecurringExpenseDeleted = {
viewModel.deleteRecurringExpense(it)
}
)
}
Expand All @@ -83,6 +85,7 @@ fun MainActivityContent(
recurringExpenseData: ImmutableList<RecurringExpenseData>,
onRecurringExpenseAdded: (RecurringExpenseData) -> Unit,
onRecurringExpenseEdited: (RecurringExpenseData) -> Unit,
onRecurringExpenseDeleted: (RecurringExpenseData) -> Unit,
) {
val navController = rememberNavController()
val backStackEntry = navController.currentBackStackEntryAsState()
Expand All @@ -93,103 +96,120 @@ fun MainActivityContent(

val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()

val bottomNavItems = listOf(
BottomNavItem(
name = "Home",
route = NavigationRoute.Home,
icon = Icons.Rounded.Home,
),
BottomNavItem(
name = "Settings",
route = NavigationRoute.Settings,
icon = Icons.Rounded.Settings,
),
val bottomNavigationItems = listOf(
BottomNavigation.Home,
BottomNavigation.Settings,
)

ExpenseTrackerTheme {
Surface(
modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background,
) {
Scaffold(topBar = {
TopAppBar(
title = {
Text(
text = "Recurring Expense Tracker",
)
},
scrollBehavior = scrollBehavior,
)
}, bottomBar = {
NavigationBar {
bottomNavItems.forEach { item ->
val selected = item.route.value == backStackEntry.value?.destination?.route
Scaffold(
topBar = {
TopAppBar(
title = {
Text(
text = "Recurring Expense Tracker",
)
},
scrollBehavior = scrollBehavior,
)
},
bottomBar = {
NavigationBar {
bottomNavigationItems.forEach { item ->
val selected =
item.route == backStackEntry.value?.destination?.route

NavigationBarItem(selected = selected,
onClick = { navController.navigate(item.route.value) },
icon = {
Icon(
imageVector = item.icon,
contentDescription = "${item.name} Icon"
)
},
label = {
Text(text = item.name)
})
NavigationBarItem(
selected = selected,
onClick = {
navController.navigate(item.route) {
// Pop up to the start destination of the graph to
// avoid building up a large stack of destinations
// on the back stack as users select items
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
// Avoid multiple copies of the same destination when
// reselecting the same item
launchSingleTop = true
// Restore state when reselecting a previously selected item
restoreState = true
}
},
icon = {
Icon(
imageVector = item.icon,
contentDescription = "$item Icon",
)
},
label = {
Text(text = stringResource(id = item.name))
})
}
}
}
}, floatingActionButton = {
FloatingActionButton(onClick = {
addRecurringExpenseVisible = true
}) {
Icon(imageVector = Icons.Rounded.Add, contentDescription = "Add")
}
}, content = { paddingValues ->
NavHost(
navController = navController,
startDestination = NavigationRoute.Home.value,
modifier = Modifier
.fillMaxSize()
.padding(paddingValues),
) {
composable(NavigationRoute.Home.value) {
RecurringExpenseOverview(
weeklyExpense = weeklyExpense,
monthlyExpense = monthlyExpense,
yearlyExpense = yearlyExpense,
recurringExpenseData = recurringExpenseData,
onItemClicked = {
selectedRecurringExpense = it
},
floatingActionButton = {
FloatingActionButton(onClick = {
addRecurringExpenseVisible = true
}) {
Icon(imageVector = Icons.Rounded.Add, contentDescription = "Add")
}
},
content = { paddingValues ->
NavHost(
navController = navController,
startDestination = BottomNavigation.Home.route,
modifier = Modifier
.fillMaxSize()
.padding(paddingValues),
) {
composable(BottomNavigation.Home.route) {
RecurringExpenseOverview(
weeklyExpense = weeklyExpense,
monthlyExpense = monthlyExpense,
yearlyExpense = yearlyExpense,
recurringExpenseData = recurringExpenseData,
onItemClicked = {
selectedRecurringExpense = it
},
contentPadding = PaddingValues(top = 8.dp, bottom = 88.dp),
modifier = Modifier
.padding(horizontal = 16.dp)
.nestedScroll(scrollBehavior.nestedScrollConnection),
)
}
composable(BottomNavigation.Settings.route) {

}
}
if (addRecurringExpenseVisible) {
EditRecurringExpense(
onUpdateExpense = {
onRecurringExpenseAdded(it)
addRecurringExpenseVisible = false
},
contentPadding = PaddingValues(top = 8.dp, bottom = 88.dp),
modifier = Modifier
.padding(horizontal = 16.dp)
.nestedScroll(scrollBehavior.nestedScrollConnection),
onDismissRequest = { addRecurringExpenseVisible = false },
)
}
composable(NavigationRoute.Settings.value) {

if (selectedRecurringExpense != null) {
EditRecurringExpense(
onUpdateExpense = {
onRecurringExpenseEdited(it)
selectedRecurringExpense = null
},
onDismissRequest = { selectedRecurringExpense = null },
currentData = selectedRecurringExpense,
onDeleteExpense = {
onRecurringExpenseDeleted(it)
selectedRecurringExpense = null
}
)
}
}
if (addRecurringExpenseVisible) {
EditRecurringExpense(
onUpdateExpense = {
onRecurringExpenseAdded(it)
addRecurringExpenseVisible = false
},
onDismissRequest = { addRecurringExpenseVisible = false },
)
}
if (selectedRecurringExpense != null) {
EditRecurringExpense(
onUpdateExpense = {
onRecurringExpenseEdited(it)
selectedRecurringExpense = null
},
onDismissRequest = { selectedRecurringExpense = null },
currentData = selectedRecurringExpense,
)
}
})
})
}
}
}
Expand Down Expand Up @@ -223,5 +243,6 @@ private fun MainActivityContentPreview() {
),
onRecurringExpenseAdded = {},
onRecurringExpenseEdited = {},
onRecurringExpenseDeleted = {},
)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package de.dbauer.expensetracker.data

import androidx.annotation.StringRes
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Home
import androidx.compose.material.icons.rounded.Settings
import androidx.compose.ui.graphics.vector.ImageVector
import de.dbauer.expensetracker.R

sealed class BottomNavigation(val route: String, @StringRes val name: Int, val icon: ImageVector) {
data object Home : BottomNavigation("home", R.string.bottom_nav_home, Icons.Rounded.Home)
data object Settings :
BottomNavigation("settings", R.string.bottom_nav_settings, Icons.Rounded.Settings)
}

This file was deleted.

Loading

0 comments on commit b267d2a

Please sign in to comment.