move drawer en navbar to common.composable
This commit is contained in:
parent
d5b62e0cb9
commit
4e501fbf92
10 changed files with 27 additions and 27 deletions
|
@ -1,124 +0,0 @@
|
|||
package be.ugent.sel.studeez.screens.drawer
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.Icon
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Home
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.material.icons.outlined.Info
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import be.ugent.sel.studeez.R
|
||||
import be.ugent.sel.studeez.resources
|
||||
import be.ugent.sel.studeez.ui.theme.StudeezTheme
|
||||
|
||||
data class DrawerActions(
|
||||
val onHomeButtonClick: () -> Unit,
|
||||
val onTimersClick: () -> Unit,
|
||||
val onSettingsClick: () -> Unit,
|
||||
val onLogoutClick: () -> Unit,
|
||||
val onAboutClick: () -> Unit,
|
||||
)
|
||||
|
||||
fun getDrawerActions(
|
||||
drawerViewModel: DrawerViewModel,
|
||||
open: (String) -> Unit,
|
||||
openAndPopUp: (String, String) -> Unit,
|
||||
): DrawerActions {
|
||||
return DrawerActions(
|
||||
onHomeButtonClick = { drawerViewModel.onHomeButtonClick(open) },
|
||||
onTimersClick = { drawerViewModel.onTimersClick(open) },
|
||||
onSettingsClick = { drawerViewModel.onSettingsClick(open) },
|
||||
onLogoutClick = { drawerViewModel.onLogoutClick(openAndPopUp) },
|
||||
onAboutClick = { drawerViewModel.onAboutClick(open) },
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Drawer(
|
||||
drawerActions: DrawerActions,
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f)
|
||||
) {
|
||||
DrawerEntry(
|
||||
icon = Icons.Default.Home,
|
||||
text = resources().getString(R.string.home),
|
||||
onClick = drawerActions.onHomeButtonClick,
|
||||
)
|
||||
DrawerEntry(
|
||||
icon = ImageVector.vectorResource(id = R.drawable.ic_timer),
|
||||
text = resources().getString(R.string.timers),
|
||||
onClick = drawerActions.onTimersClick,
|
||||
)
|
||||
DrawerEntry(
|
||||
icon = Icons.Default.Settings,
|
||||
text = resources().getString(R.string.settings),
|
||||
onClick = drawerActions.onSettingsClick,
|
||||
)
|
||||
DrawerEntry(
|
||||
icon = ImageVector.vectorResource(id = R.drawable.ic_logout),
|
||||
text = resources().getString(R.string.log_out),
|
||||
onClick = drawerActions.onLogoutClick,
|
||||
)
|
||||
}
|
||||
|
||||
DrawerEntry(
|
||||
icon = Icons.Outlined.Info,
|
||||
text = resources().getString(R.string.about),
|
||||
onClick = drawerActions.onAboutClick,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun DrawerEntry(
|
||||
icon: ImageVector, text: String, onClick: () -> Unit
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
modifier = Modifier
|
||||
.clickable(onClick = { onClick() })
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(vertical = 12.dp)
|
||||
.fillMaxWidth(0.15f)
|
||||
) {
|
||||
Icon(imageVector = icon, contentDescription = text)
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(vertical = 12.dp)
|
||||
.fillMaxWidth(0.85f)
|
||||
) {
|
||||
Text(text = text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun DrawerPreview() {
|
||||
val drawerActions = DrawerActions({}, {}, {}, {}, {})
|
||||
StudeezTheme {
|
||||
Drawer(drawerActions)
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package be.ugent.sel.studeez.screens.drawer
|
||||
|
||||
import be.ugent.sel.studeez.domain.AccountDAO
|
||||
import be.ugent.sel.studeez.domain.LogService
|
||||
import be.ugent.sel.studeez.navigation.StudeezDestinations
|
||||
import be.ugent.sel.studeez.navigation.StudeezDestinations.HOME_SCREEN
|
||||
import be.ugent.sel.studeez.navigation.StudeezDestinations.LOGIN_SCREEN
|
||||
import be.ugent.sel.studeez.screens.StudeezViewModel
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class DrawerViewModel @Inject constructor(
|
||||
private val accountDAO: AccountDAO,
|
||||
logService: LogService
|
||||
) : StudeezViewModel(logService) {
|
||||
|
||||
fun onHomeButtonClick(open: (String) -> Unit) {
|
||||
open(HOME_SCREEN)
|
||||
}
|
||||
|
||||
fun onTimersClick(openAndPopup: (String) -> Unit) {
|
||||
openAndPopup(StudeezDestinations.TIMER_OVERVIEW_SCREEN)
|
||||
}
|
||||
|
||||
fun onSettingsClick(open: (String) -> Unit) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
fun onLogoutClick(openAndPopUp: (String, String) -> Unit) {
|
||||
launchCatching {
|
||||
accountDAO.signOut()
|
||||
openAndPopUp(LOGIN_SCREEN, HOME_SCREEN)
|
||||
}
|
||||
}
|
||||
|
||||
fun onAboutClick(open: (String) -> Unit) {
|
||||
// TODO
|
||||
}
|
||||
}
|
|
@ -13,12 +13,12 @@ import be.ugent.sel.studeez.common.composable.BasicButton
|
|||
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
|
||||
import be.ugent.sel.studeez.common.ext.basicButton
|
||||
import be.ugent.sel.studeez.resources
|
||||
import be.ugent.sel.studeez.screens.drawer.DrawerActions
|
||||
import be.ugent.sel.studeez.screens.drawer.DrawerViewModel
|
||||
import be.ugent.sel.studeez.screens.drawer.getDrawerActions
|
||||
import be.ugent.sel.studeez.screens.navbar.NavigationBarActions
|
||||
import be.ugent.sel.studeez.screens.navbar.NavigationBarViewModel
|
||||
import be.ugent.sel.studeez.screens.navbar.getNavigationBarActions
|
||||
import be.ugent.sel.studeez.common.composable.drawer.DrawerActions
|
||||
import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel
|
||||
import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions
|
||||
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions
|
||||
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarViewModel
|
||||
import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions
|
||||
|
||||
@Composable
|
||||
fun HomeRoute(
|
||||
|
|
|
@ -1,100 +0,0 @@
|
|||
package be.ugent.sel.studeez.screens.navbar
|
||||
|
||||
import androidx.compose.material.BottomNavigation
|
||||
import androidx.compose.material.BottomNavigationItem
|
||||
import androidx.compose.material.Icon
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material.icons.filled.List
|
||||
import androidx.compose.material.icons.filled.Person
|
||||
import androidx.compose.material.icons.outlined.DateRange
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import be.ugent.sel.studeez.resources
|
||||
import be.ugent.sel.studeez.ui.theme.StudeezTheme
|
||||
import be.ugent.sel.studeez.R.string as AppText
|
||||
|
||||
data class NavigationBarActions(
|
||||
val onHomeClick: () -> Unit,
|
||||
val onTasksClick: () -> Unit,
|
||||
val onSessionsClick: () -> Unit,
|
||||
val onProfileClick: () -> Unit,
|
||||
)
|
||||
|
||||
fun getNavigationBarActions(
|
||||
navigationBarViewModel: NavigationBarViewModel,
|
||||
open: (String) -> Unit,
|
||||
): NavigationBarActions {
|
||||
return NavigationBarActions(
|
||||
onHomeClick = { navigationBarViewModel.onHomeClick(open) },
|
||||
onTasksClick = { navigationBarViewModel.onTasksClick(open) },
|
||||
onSessionsClick = { navigationBarViewModel.onSessionsClick(open) },
|
||||
onProfileClick = { navigationBarViewModel.onProfileClick(open) },
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun NavigationBar(
|
||||
navigationBarActions: NavigationBarActions,
|
||||
) {
|
||||
// TODO Pass functions and new screens.
|
||||
// TODO Pass which screen is selected.
|
||||
// TODO Disabled -> HIGH/MEDIUM_EMPHASIS if the page is implemented
|
||||
BottomNavigation(
|
||||
elevation = 10.dp
|
||||
) {
|
||||
BottomNavigationItem(
|
||||
icon = { Icon(imageVector = Icons.Default.List, resources().getString(AppText.home)) },
|
||||
label = { Text(text = resources().getString(AppText.home)) },
|
||||
selected = false, // TODO
|
||||
onClick = navigationBarActions.onHomeClick
|
||||
)
|
||||
|
||||
BottomNavigationItem(
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Check, resources().getString(AppText.tasks)
|
||||
)
|
||||
},
|
||||
label = { Text(text = resources().getString(AppText.tasks)) },
|
||||
selected = false, // TODO
|
||||
onClick = navigationBarActions.onTasksClick
|
||||
)
|
||||
|
||||
// Hack to space the entries in the navigation bar, make space for fab
|
||||
BottomNavigationItem(icon = {}, onClick = {}, selected = false)
|
||||
|
||||
BottomNavigationItem(
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.DateRange, resources().getString(AppText.sessions)
|
||||
)
|
||||
},
|
||||
label = { Text(text = resources().getString(AppText.sessions)) },
|
||||
selected = false, // TODO
|
||||
onClick = navigationBarActions.onSessionsClick
|
||||
)
|
||||
|
||||
BottomNavigationItem(
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Person, resources().getString(AppText.profile)
|
||||
)
|
||||
},
|
||||
label = { Text(text = resources().getString(AppText.profile)) },
|
||||
selected = false, // TODO
|
||||
onClick = navigationBarActions.onProfileClick
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
fun NavigationBarPreview() {
|
||||
StudeezTheme {
|
||||
NavigationBar(NavigationBarActions({}, {}, {}, {}))
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package be.ugent.sel.studeez.screens.navbar
|
||||
|
||||
import be.ugent.sel.studeez.domain.AccountDAO
|
||||
import be.ugent.sel.studeez.domain.LogService
|
||||
import be.ugent.sel.studeez.navigation.StudeezDestinations.HOME_SCREEN
|
||||
import be.ugent.sel.studeez.navigation.StudeezDestinations.PROFILE_SCREEN
|
||||
import be.ugent.sel.studeez.screens.StudeezViewModel
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class NavigationBarViewModel @Inject constructor(
|
||||
private val accountDAO: AccountDAO,
|
||||
logService: LogService
|
||||
) : StudeezViewModel(logService) {
|
||||
|
||||
fun onHomeClick(open: (String) -> Unit) {
|
||||
open(HOME_SCREEN)
|
||||
}
|
||||
|
||||
fun onTasksClick(open: (String) -> Unit) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
fun onSessionsClick(open: (String) -> Unit) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
fun onProfileClick(open: (String) -> Unit) {
|
||||
open(PROFILE_SCREEN)
|
||||
}
|
||||
}
|
|
@ -16,10 +16,10 @@ import be.ugent.sel.studeez.R
|
|||
import be.ugent.sel.studeez.common.composable.Headline
|
||||
import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
|
||||
import be.ugent.sel.studeez.resources
|
||||
import be.ugent.sel.studeez.screens.drawer.DrawerActions
|
||||
import be.ugent.sel.studeez.screens.drawer.getDrawerActions
|
||||
import be.ugent.sel.studeez.screens.navbar.NavigationBarActions
|
||||
import be.ugent.sel.studeez.screens.navbar.getNavigationBarActions
|
||||
import be.ugent.sel.studeez.common.composable.drawer.DrawerActions
|
||||
import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions
|
||||
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions
|
||||
import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import be.ugent.sel.studeez.R.string as AppText
|
||||
|
||||
|
|
|
@ -18,10 +18,10 @@ import be.ugent.sel.studeez.common.ext.basicButton
|
|||
import be.ugent.sel.studeez.data.local.models.timer_info.CustomTimerInfo
|
||||
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
|
||||
import be.ugent.sel.studeez.resources
|
||||
import be.ugent.sel.studeez.screens.drawer.DrawerActions
|
||||
import be.ugent.sel.studeez.screens.drawer.getDrawerActions
|
||||
import be.ugent.sel.studeez.screens.navbar.NavigationBarActions
|
||||
import be.ugent.sel.studeez.screens.navbar.getNavigationBarActions
|
||||
import be.ugent.sel.studeez.common.composable.drawer.DrawerActions
|
||||
import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions
|
||||
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions
|
||||
import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
|
||||
|
|
|
@ -13,10 +13,10 @@ import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate
|
|||
import be.ugent.sel.studeez.common.composable.TimerEntry
|
||||
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
|
||||
import be.ugent.sel.studeez.resources
|
||||
import be.ugent.sel.studeez.screens.drawer.DrawerActions
|
||||
import be.ugent.sel.studeez.screens.drawer.getDrawerActions
|
||||
import be.ugent.sel.studeez.screens.navbar.NavigationBarActions
|
||||
import be.ugent.sel.studeez.screens.navbar.getNavigationBarActions
|
||||
import be.ugent.sel.studeez.common.composable.drawer.DrawerActions
|
||||
import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions
|
||||
import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions
|
||||
import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
|
||||
|
|
Reference in a new issue