refactor drawer to not need viewmodel in constructor
This commit is contained in:
parent
0df2b93851
commit
2b2cc879b3
4 changed files with 36 additions and 40 deletions
2
.idea/compiler.xml
generated
2
.idea/compiler.xml
generated
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="CompilerConfiguration">
|
<component name="CompilerConfiguration">
|
||||||
<bytecodeTargetLevel target="11" />
|
<bytecodeTargetLevel target="17" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
2
.idea/kotlinc.xml
generated
2
.idea/kotlinc.xml
generated
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="KotlinJpsPluginSettings">
|
<component name="KotlinJpsPluginSettings">
|
||||||
<option name="version" value="1.8.0-release" />
|
<option name="version" value="1.7.0" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
package be.ugent.sel.studeez.screens.drawer
|
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.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.Icon
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
@ -14,8 +19,6 @@ 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.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
||||||
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
|
import be.ugent.sel.studeez.ui.theme.StudeezTheme
|
||||||
|
@ -23,56 +26,53 @@ import be.ugent.sel.studeez.ui.theme.StudeezTheme
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Drawer(
|
fun Drawer(
|
||||||
open: (String) -> Unit,
|
onHomeButtonClick: () -> Unit,
|
||||||
openAndPopUp: (String, String) -> Unit,
|
onTimersClick: () -> Unit,
|
||||||
viewModel: DrawerViewModel = hiltViewModel()
|
onSettingsClick: () -> Unit,
|
||||||
|
onLogoutClick: () -> Unit,
|
||||||
|
onAboutClick: () -> Unit,
|
||||||
) {
|
) {
|
||||||
Column (
|
Column(
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Column (
|
Column(
|
||||||
modifier = Modifier.fillMaxWidth().weight(1f)
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.weight(1f)
|
||||||
) {
|
) {
|
||||||
DrawerEntry(
|
DrawerEntry(
|
||||||
icon = Icons.Default.Home,
|
icon = Icons.Default.Home,
|
||||||
text = resources().getString(R.string.home)
|
text = resources().getString(R.string.home),
|
||||||
) {
|
onClick = onHomeButtonClick,
|
||||||
viewModel.onHomeButtonClick(open)
|
)
|
||||||
}
|
|
||||||
DrawerEntry(
|
DrawerEntry(
|
||||||
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),
|
||||||
) {
|
onClick = onTimersClick,
|
||||||
viewModel.onTimersClick(open)
|
)
|
||||||
}
|
|
||||||
DrawerEntry(
|
DrawerEntry(
|
||||||
icon = Icons.Default.Settings,
|
icon = Icons.Default.Settings,
|
||||||
text = resources().getString(R.string.settings)
|
text = resources().getString(R.string.settings),
|
||||||
) {
|
onClick = onSettingsClick,
|
||||||
viewModel.onSettingsClick(open)
|
)
|
||||||
}
|
|
||||||
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),
|
||||||
) {
|
onClick = 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),
|
||||||
) {
|
onClick = onAboutClick,
|
||||||
viewModel.onAboutClick(open)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DrawerEntry(
|
fun DrawerEntry(
|
||||||
icon: ImageVector,
|
icon: ImageVector, text: String, onClick: () -> Unit
|
||||||
text: String,
|
|
||||||
onClick: () -> Unit
|
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.Center,
|
horizontalArrangement = Arrangement.Center,
|
||||||
|
@ -101,10 +101,6 @@ fun DrawerEntry(
|
||||||
@Composable
|
@Composable
|
||||||
fun DrawerPreview() {
|
fun DrawerPreview() {
|
||||||
StudeezTheme {
|
StudeezTheme {
|
||||||
Drawer(
|
Drawer({}, {}, {}, {}, {})
|
||||||
{ _, -> {} },
|
|
||||||
{ _, _ -> {} },
|
|
||||||
hiltViewModel()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in a new issue