Rename screen to DrawerItem
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -24,9 +24,9 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import me.zobrist.tichucounter.domain.*
|
||||
import me.zobrist.tichucounter.ui.AppTheme
|
||||
import me.zobrist.tichucounter.ui.DrawerContent
|
||||
import me.zobrist.tichucounter.ui.layout.DrawerContent
|
||||
import me.zobrist.tichucounter.ui.MainViewModel
|
||||
import me.zobrist.tichucounter.ui.TopBar
|
||||
import me.zobrist.tichucounter.ui.layout.TopBar
|
||||
import me.zobrist.tichucounter.ui.composables.DropDownMenu
|
||||
import me.zobrist.tichucounter.ui.counter.*
|
||||
import me.zobrist.tichucounter.ui.history.HistoryList
|
||||
@@ -95,9 +95,9 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
||||
val navController = rememberNavController()
|
||||
|
||||
val items = listOf(
|
||||
Screen(Route.COUNTER, Icons.Outlined.Calculate, R.string.app_name),
|
||||
Screen(Route.HISTORY, Icons.Outlined.List, R.string.menu_history),
|
||||
Screen(Route.SETTINGS, Icons.Outlined.Settings, R.string.menu_settings)
|
||||
DrawerItem(Route.COUNTER, Icons.Outlined.Calculate, stringResource(R.string.app_name)),
|
||||
DrawerItem(Route.HISTORY, Icons.Outlined.List, stringResource(R.string.menu_history)),
|
||||
DrawerItem(Route.SETTINGS, Icons.Outlined.Settings, stringResource(R.string.menu_settings))
|
||||
)
|
||||
|
||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
@@ -109,8 +109,8 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
||||
gesturesEnabled = drawerState.isOpen,
|
||||
drawerContent = {
|
||||
DrawerContent(
|
||||
screens = items,
|
||||
selectedScreen = items.first { it.route == currentDestination }) {
|
||||
drawerItems = items,
|
||||
selectedDrawerItem = items.first { it.route == currentDestination }) {
|
||||
scope.launch {
|
||||
drawerState.close()
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
|
||||
data class DrawerItem(val route: Route, val menuIcon: ImageVector, val menuName: String)
|
||||
@@ -1,6 +0,0 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
|
||||
class Screen(val route: Route, val icon: ImageVector, @StringRes val resourceId: Int)
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.zobrist.tichucounter.ui
|
||||
package me.zobrist.tichucounter.ui.layout
|
||||
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.height
|
||||
@@ -6,16 +6,15 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import me.zobrist.tichucounter.domain.Route
|
||||
import me.zobrist.tichucounter.domain.Screen
|
||||
import me.zobrist.tichucounter.domain.DrawerItem
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun DrawerContent(
|
||||
screens: List<Screen>,
|
||||
selectedScreen: Screen,
|
||||
drawerItems: List<DrawerItem>,
|
||||
selectedDrawerItem: DrawerItem,
|
||||
onElementClicked: (Route) -> Unit
|
||||
) {
|
||||
|
||||
@@ -23,11 +22,11 @@ fun DrawerContent(
|
||||
|
||||
Spacer(Modifier.height(20.dp))
|
||||
|
||||
screens.forEach { screen ->
|
||||
drawerItems.forEach { screen ->
|
||||
NavigationDrawerItem(
|
||||
icon = { Icon(screen.icon, contentDescription = null) },
|
||||
label = { Text(stringResource(screen.resourceId)) },
|
||||
selected = screen == selectedScreen,
|
||||
icon = { Icon(screen.menuIcon, contentDescription = null) },
|
||||
label = { Text(screen.menuName) },
|
||||
selected = screen == selectedDrawerItem,
|
||||
onClick = { onElementClicked(screen.route) },
|
||||
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding)
|
||||
)
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.zobrist.tichucounter.ui
|
||||
package me.zobrist.tichucounter.ui.layout
|
||||
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
Reference in New Issue
Block a user