Skip to content

Commit

Permalink
add course page
Browse files Browse the repository at this point in the history
  • Loading branch information
X1nto committed Dec 23, 2023
1 parent 7182850 commit 567e1cc
Show file tree
Hide file tree
Showing 75 changed files with 2,833 additions and 180 deletions.
15 changes: 11 additions & 4 deletions androidApp/src/main/java/dev/xinto/argos/di/UiModule.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package dev.xinto.argos.di

import dev.xinto.argos.ui.screen.course.page.classmates.ClassmatesViewModel
import dev.xinto.argos.ui.screen.course.page.groups.GroupsViewModel
import dev.xinto.argos.ui.screen.course.page.materials.MaterialsViewModel
import dev.xinto.argos.ui.screen.course.page.scores.ScoresViewModel
import dev.xinto.argos.ui.screen.course.page.syllabus.SyllabusViewModel
import dev.xinto.argos.ui.screen.login.LoginViewModel
import dev.xinto.argos.ui.screen.main.MainViewModel
import dev.xinto.argos.ui.screen.main.dialog.user.UserViewModel
Expand All @@ -8,7 +13,6 @@ import dev.xinto.argos.ui.screen.main.page.messages.MessagesViewModel
import dev.xinto.argos.ui.screen.main.page.news.NewsViewModel
import dev.xinto.argos.ui.screen.message.MessageViewModel
import dev.xinto.argos.ui.screen.notifications.NotificationsViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.androidx.viewmodel.dsl.viewModelOf
import org.koin.dsl.module

Expand All @@ -20,7 +24,10 @@ val UiModule = module {
viewModelOf(::NewsViewModel)
viewModelOf(::NotificationsViewModel)
viewModelOf(::UserViewModel)
viewModel {
MessageViewModel(it.get(), get())
}
viewModelOf(::MessageViewModel)
viewModelOf(::SyllabusViewModel)
viewModelOf(::GroupsViewModel)
viewModelOf(::ScoresViewModel)
viewModelOf(::MaterialsViewModel)
viewModelOf(::ClassmatesViewModel)
}
39 changes: 30 additions & 9 deletions androidApp/src/main/java/dev/xinto/argos/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import dev.olshevski.navigation.reimagined.rememberNavController
import dev.olshevski.navigation.reimagined.replaceAll
import dev.xinto.argos.domain.user.UserRepository
import dev.xinto.argos.ui.screen.ArgosNavigation
import dev.xinto.argos.ui.screen.course.CourseScreen
import dev.xinto.argos.ui.screen.login.LoginScreen
import dev.xinto.argos.ui.screen.main.MainScreen
import dev.xinto.argos.ui.screen.message.MessageScreen
Expand All @@ -40,43 +41,63 @@ class MainActivity : ComponentActivity() {
color = MaterialTheme.colorScheme.background
) {
val rootNavController = rememberNavController<ArgosNavigation>(listOf())
val isLoggedIn by userRepository.observeLoggedIn().collectAsStateWithLifecycle(initialValue = false)
val isLoggedIn by userRepository.observeLoggedIn()
.collectAsStateWithLifecycle(initialValue = false)
LaunchedEffect(isLoggedIn) {
if (isLoggedIn) {
rootNavController.replaceAll(ArgosNavigation.Main)
} else {
rootNavController.replaceAll(ArgosNavigation.Login)
}
}
AnimatedNavHost(controller = rootNavController) {
when (it) {
AnimatedNavHost(
modifier = Modifier.fillMaxSize(),
controller = rootNavController
) { destination ->
when (destination) {
is ArgosNavigation.Login -> {
LoginScreen(modifier = Modifier.fillMaxSize())
}

is ArgosNavigation.Main -> {
MainScreen(
modifier = Modifier.fillMaxSize(),
onNotificationsClick = {
rootNavController.navigate(ArgosNavigation.Notifications)
},
onMessageClick = { messageId, semesterId ->
rootNavController.navigate(ArgosNavigation.Message(
id = messageId,
semesterId = semesterId
))
rootNavController.navigate(
ArgosNavigation.Message(
id = messageId,
semesterId = semesterId
)
)
},
onCourseClick = {
rootNavController.navigate(ArgosNavigation.Course(it))
}
)
}

is ArgosNavigation.Notifications -> {
NotificationsScreen(
onBackClick = rootNavController::pop
)
}

is ArgosNavigation.Message -> {
MessageScreen(
modifier = Modifier.fillMaxSize(),
messageId = it.id,
semesterId = it.semesterId,
messageId = destination.id,
semesterId = destination.semesterId,
onBackClick = rootNavController::pop
)
}

is ArgosNavigation.Course -> {
CourseScreen(
modifier = Modifier.fillMaxSize(),
courseId = destination.id,
onBackClick = rootNavController::pop
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package dev.xinto.argos.ui.component

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.spring
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.unit.dp
import dev.xinto.argos.R
import dev.xinto.argos.ui.theme.ArgosTheme

@Composable
fun ExpandableListItem(
expanded: Boolean,
onExpandedChange: (Boolean) -> Unit,
expandedContent: @Composable () -> Unit,
modifier: Modifier = Modifier,
headlineContent: @Composable () -> Unit,
overlineContent: @Composable (() -> Unit)? = null,
supportingContent: @Composable (() -> Unit)? = null,
leadingContent: @Composable (() -> Unit)? = null,
shape: Shape = MaterialTheme.shapes.medium,
enabled: Boolean = true,
) {
Column(
modifier = modifier
.clip(shape)
.width(IntrinsicSize.Min)
) {
ListItem2(
modifier = Modifier.fillMaxWidth(),
checked = expanded,
onCheckedChange = onExpandedChange,
enabled = enabled,
headlineContent = headlineContent,
overlineContent = overlineContent,
supportingContent = supportingContent,
leadingContent = leadingContent,
trailingContent = {
val iconRotation by animateFloatAsState(
targetValue = if (expanded) 270f else 90f,
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
),
label = "ExpandableListItem arrow"
)
Icon(
modifier = Modifier.graphicsLayer {
rotationZ = iconRotation
},
painter = painterResource(R.drawable.ic_navigate_next),
contentDescription = null
)
},
shape = MaterialTheme.shapes.extraSmall
)
AnimatedVisibility(visible = expanded) {
Surface(
modifier = Modifier
.fillMaxWidth()
.padding(top = 2.dp),
tonalElevation = 1.dp,
shape = MaterialTheme.shapes.extraSmall
) {
expandedContent()
}
}
}
}

@Composable
@PreviewLightDark
fun ExpandableCard_Preview() {
ArgosTheme {
val (expanded, setExpanded) = remember { mutableStateOf(false) }
ExpandableListItem(
modifier = Modifier.width(300.dp),
expanded = expanded,
onExpandedChange = setExpanded,
headlineContent = {
Text("Main content")
},
expandedContent = {
Box(
modifier = Modifier.padding(12.dp),
contentAlignment = Alignment.Center
) {
Text("Expanded content")
}
}
)
}
}
Loading

0 comments on commit 567e1cc

Please sign in to comment.