now takes viewmodel and open function. Also uses viewmodel functions
This commit is contained in:
parent
c0bc4c24ae
commit
cee42e7758
4 changed files with 44 additions and 17 deletions
|
@ -1,4 +1,4 @@
|
||||||
package be.ugent.sel.studeez.common.composable
|
package be.ugent.sel.studeez.screens.drawer
|
||||||
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
|
@ -12,16 +12,17 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.res.vectorResource
|
import androidx.compose.ui.res.vectorResource
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import be.ugent.sel.studeez.R
|
import be.ugent.sel.studeez.R
|
||||||
import be.ugent.sel.studeez.resources
|
import be.ugent.sel.studeez.resources
|
||||||
import be.ugent.sel.studeez.ui.theme.StudeezTheme
|
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Drawer(
|
fun Drawer(
|
||||||
onLogoutClick: () -> Unit
|
openAndPopUp: (String, String) -> Unit,
|
||||||
|
viewModel: DrawerViewModel = hiltViewModel()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
Column(modifier = Modifier.fillMaxSize()) {
|
Column(modifier = Modifier.fillMaxSize()) {
|
||||||
DrawerEntry(
|
DrawerEntry(
|
||||||
icon = Icons.Default.Home,
|
icon = Icons.Default.Home,
|
||||||
|
@ -33,26 +34,26 @@ fun Drawer(
|
||||||
icon = ImageVector.vectorResource(id = R.drawable.ic_timer),
|
icon = ImageVector.vectorResource(id = R.drawable.ic_timer),
|
||||||
text = resources().getString(R.string.timers)
|
text = resources().getString(R.string.timers)
|
||||||
) {
|
) {
|
||||||
// TODO Go to timers
|
viewModel.onTimersClick(openAndPopUp)
|
||||||
}
|
}
|
||||||
DrawerEntry(
|
DrawerEntry(
|
||||||
icon = Icons.Default.Settings,
|
icon = Icons.Default.Settings,
|
||||||
text = resources().getString(R.string.settings)
|
text = resources().getString(R.string.settings)
|
||||||
) {
|
) {
|
||||||
// TODO Go to settings
|
viewModel.onSettingsClick(openAndPopUp)
|
||||||
}
|
}
|
||||||
DrawerEntry(
|
DrawerEntry(
|
||||||
icon = ImageVector.vectorResource(id = R.drawable.ic_logout),
|
icon = ImageVector.vectorResource(id = R.drawable.ic_logout),
|
||||||
text = resources().getString(R.string.log_out)
|
text = resources().getString(R.string.log_out)
|
||||||
) {
|
) {
|
||||||
onLogoutClick()
|
viewModel.onLogoutClick(openAndPopUp)
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawerEntry(
|
DrawerEntry(
|
||||||
icon = Icons.Outlined.Info,
|
icon = Icons.Outlined.Info,
|
||||||
text = resources().getString(R.string.about)
|
text = resources().getString(R.string.about)
|
||||||
) {
|
) {
|
||||||
// TODO Go to about
|
viewModel.onAboutClick(openAndPopUp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,12 +79,12 @@ fun DrawerEntry(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview
|
//@Preview
|
||||||
@Composable
|
//@Composable
|
||||||
fun DrawerPreview() {
|
//fun DrawerPreview() {
|
||||||
StudeezTheme {
|
// StudeezTheme {
|
||||||
Drawer(
|
// Drawer(
|
||||||
{}
|
// {}
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
}
|
//}
|
|
@ -0,0 +1,22 @@
|
||||||
|
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.screens.StudeezViewModel
|
||||||
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@HiltViewModel
|
||||||
|
class PrimaryScreenViewModel @Inject constructor(
|
||||||
|
private val accountDAO: AccountDAO,
|
||||||
|
logService: LogService
|
||||||
|
) : StudeezViewModel(logService) {
|
||||||
|
|
||||||
|
fun onLogoutClick(openAndPopup: (String, String) -> Unit) {
|
||||||
|
launchCatching {
|
||||||
|
accountDAO.signOut()
|
||||||
|
openAndPopup(StudeezDestinations.LOGIN_SCREEN, StudeezDestinations.HOME_SCREEN)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package be.ugent.sel.studeez.screens.navbar
|
||||||
|
|
||||||
|
class NavigationBarViewModel {
|
||||||
|
}
|
Reference in a new issue