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
				
			
		| 
						 | 
				
			
			@ -0,0 +1,90 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.drawer
 | 
			
		||||
 | 
			
		||||
import androidx.compose.foundation.clickable
 | 
			
		||||
import androidx.compose.foundation.layout.*
 | 
			
		||||
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.hilt.navigation.compose.hiltViewModel
 | 
			
		||||
import be.ugent.sel.studeez.R
 | 
			
		||||
import be.ugent.sel.studeez.resources
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun Drawer(
 | 
			
		||||
    openAndPopUp: (String, String) -> Unit,
 | 
			
		||||
    viewModel: DrawerViewModel = hiltViewModel()
 | 
			
		||||
) {
 | 
			
		||||
 | 
			
		||||
    Column(modifier = Modifier.fillMaxSize()) {
 | 
			
		||||
        DrawerEntry(
 | 
			
		||||
            icon = Icons.Default.Home,
 | 
			
		||||
            text = resources().getString(R.string.home)
 | 
			
		||||
        ) {
 | 
			
		||||
            // TODO Go to home
 | 
			
		||||
        }
 | 
			
		||||
        DrawerEntry(
 | 
			
		||||
            icon = ImageVector.vectorResource(id = R.drawable.ic_timer),
 | 
			
		||||
            text = resources().getString(R.string.timers)
 | 
			
		||||
        ) {
 | 
			
		||||
            viewModel.onTimersClick(openAndPopUp)
 | 
			
		||||
        }
 | 
			
		||||
        DrawerEntry(
 | 
			
		||||
            icon = Icons.Default.Settings,
 | 
			
		||||
            text = resources().getString(R.string.settings)
 | 
			
		||||
        ) {
 | 
			
		||||
            viewModel.onSettingsClick(openAndPopUp)
 | 
			
		||||
        }
 | 
			
		||||
        DrawerEntry(
 | 
			
		||||
            icon = ImageVector.vectorResource(id = R.drawable.ic_logout),
 | 
			
		||||
            text = resources().getString(R.string.log_out)
 | 
			
		||||
        ) {
 | 
			
		||||
            viewModel.onLogoutClick(openAndPopUp)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        DrawerEntry(
 | 
			
		||||
            icon = Icons.Outlined.Info,
 | 
			
		||||
            text = resources().getString(R.string.about)
 | 
			
		||||
        ) {
 | 
			
		||||
            viewModel.onAboutClick(openAndPopUp)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun DrawerEntry(
 | 
			
		||||
    icon: ImageVector,
 | 
			
		||||
    text: String,
 | 
			
		||||
    onClick: () -> Unit
 | 
			
		||||
) {
 | 
			
		||||
    Row(
 | 
			
		||||
        horizontalArrangement = Arrangement.Center,
 | 
			
		||||
        modifier = Modifier
 | 
			
		||||
            .clickable(onClick = { onClick() })
 | 
			
		||||
            .fillMaxWidth()
 | 
			
		||||
    ) {
 | 
			
		||||
        Box(modifier = Modifier.fillMaxWidth(0.25f)) {
 | 
			
		||||
            Icon(imageVector = icon, contentDescription = text)
 | 
			
		||||
        }
 | 
			
		||||
        Box(modifier = Modifier.fillMaxWidth(0.75f)) {
 | 
			
		||||
            Text(text = text)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//@Preview
 | 
			
		||||
//@Composable
 | 
			
		||||
//fun DrawerPreview() {
 | 
			
		||||
//    StudeezTheme {
 | 
			
		||||
//        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,63 @@
 | 
			
		|||
package be.ugent.sel.studeez.common.composable
 | 
			
		||||
 | 
			
		||||
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.ui.theme.StudeezTheme
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun NavigationBar() {
 | 
			
		||||
    // 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, "Home") },
 | 
			
		||||
            label = { Text(text = "Home") },
 | 
			
		||||
            selected = false, // TODO
 | 
			
		||||
            onClick = { /* TODO */ }
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        BottomNavigationItem(
 | 
			
		||||
            icon = { Icon(imageVector = Icons.Default.Check, "Tasks") },
 | 
			
		||||
            label = { Text(text = "Tasks") },
 | 
			
		||||
            selected = false, // TODO
 | 
			
		||||
            onClick = { /* TODO */ }
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        // 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, "Sessions") },
 | 
			
		||||
            label = { Text(text = "Sessions") },
 | 
			
		||||
            selected = false, // TODO
 | 
			
		||||
            onClick = { /* TODO */ }
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        BottomNavigationItem(
 | 
			
		||||
            icon = { Icon(imageVector = Icons.Default.Person, "Profile") },
 | 
			
		||||
            label = { Text(text = "Profile") },
 | 
			
		||||
            selected = false, // TODO
 | 
			
		||||
            onClick = { /* TODO */ }
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Preview(showBackground = true)
 | 
			
		||||
@Composable
 | 
			
		||||
fun NavigationBarPreview() {
 | 
			
		||||
    StudeezTheme { NavigationBar() }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,4 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.navbar
 | 
			
		||||
 | 
			
		||||
class NavigationBarViewModel {
 | 
			
		||||
}
 | 
			
		||||
		Reference in a new issue