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"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="11" />
|
||||
<bytecodeTargetLevel target="17" />
|
||||
</component>
|
||||
</project>
|
2
.idea/kotlinc.xml
generated
2
.idea/kotlinc.xml
generated
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="1.8.0-release" />
|
||||
<option name="version" value="1.7.0" />
|
||||
</component>
|
||||
</project>
|
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<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" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
package be.ugent.sel.studeez.screens.drawer
|
||||
|
||||
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.Text
|
||||
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.tooling.preview.Preview
|
||||
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.resources
|
||||
import be.ugent.sel.studeez.ui.theme.StudeezTheme
|
||||
|
@ -23,56 +26,53 @@ import be.ugent.sel.studeez.ui.theme.StudeezTheme
|
|||
|
||||
@Composable
|
||||
fun Drawer(
|
||||
open: (String) -> Unit,
|
||||
openAndPopUp: (String, String) -> Unit,
|
||||
viewModel: DrawerViewModel = hiltViewModel()
|
||||
onHomeButtonClick: () -> Unit,
|
||||
onTimersClick: () -> Unit,
|
||||
onSettingsClick: () -> Unit,
|
||||
onLogoutClick: () -> Unit,
|
||||
onAboutClick: () -> Unit,
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().weight(1f)
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f)
|
||||
) {
|
||||
DrawerEntry(
|
||||
icon = Icons.Default.Home,
|
||||
text = resources().getString(R.string.home)
|
||||
) {
|
||||
viewModel.onHomeButtonClick(open)
|
||||
}
|
||||
text = resources().getString(R.string.home),
|
||||
onClick = onHomeButtonClick,
|
||||
)
|
||||
DrawerEntry(
|
||||
icon = ImageVector.vectorResource(id = R.drawable.ic_timer),
|
||||
text = resources().getString(R.string.timers)
|
||||
) {
|
||||
viewModel.onTimersClick(open)
|
||||
}
|
||||
text = resources().getString(R.string.timers),
|
||||
onClick = onTimersClick,
|
||||
)
|
||||
DrawerEntry(
|
||||
icon = Icons.Default.Settings,
|
||||
text = resources().getString(R.string.settings)
|
||||
) {
|
||||
viewModel.onSettingsClick(open)
|
||||
}
|
||||
text = resources().getString(R.string.settings),
|
||||
onClick = onSettingsClick,
|
||||
)
|
||||
DrawerEntry(
|
||||
icon = ImageVector.vectorResource(id = R.drawable.ic_logout),
|
||||
text = resources().getString(R.string.log_out)
|
||||
) {
|
||||
viewModel.onLogoutClick(openAndPopUp)
|
||||
}
|
||||
text = resources().getString(R.string.log_out),
|
||||
onClick = onLogoutClick,
|
||||
)
|
||||
}
|
||||
|
||||
DrawerEntry(
|
||||
icon = Icons.Outlined.Info,
|
||||
text = resources().getString(R.string.about)
|
||||
) {
|
||||
viewModel.onAboutClick(open)
|
||||
}
|
||||
text = resources().getString(R.string.about),
|
||||
onClick = onAboutClick,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun DrawerEntry(
|
||||
icon: ImageVector,
|
||||
text: String,
|
||||
onClick: () -> Unit
|
||||
icon: ImageVector, text: String, onClick: () -> Unit
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
|
@ -101,10 +101,6 @@ fun DrawerEntry(
|
|||
@Composable
|
||||
fun DrawerPreview() {
|
||||
StudeezTheme {
|
||||
Drawer(
|
||||
{ _, -> {} },
|
||||
{ _, _ -> {} },
|
||||
hiltViewModel()
|
||||
)
|
||||
Drawer({}, {}, {}, {}, {})
|
||||
}
|
||||
}
|
Reference in a new issue