Skip to content

Commit

Permalink
Merge branch 'develop' into feature/communication/message-area-listing
Browse files Browse the repository at this point in the history
  • Loading branch information
eylulnc authored Dec 29, 2024
2 parents b7c485a + 276f859 commit e338e6c
Show file tree
Hide file tree
Showing 18 changed files with 452 additions and 311 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package de.tum.informatics.www1.artemis.native_app.core.ui.navigation

import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.togetherWith


object DefaultTransition {
const val duration = 220

val fadeIn = fadeIn(tween(duration))
val fadeOut = fadeOut(tween(duration))

val navigateForward = enter togetherWith exit
val navigateBack = popEnter togetherWith popExit
val navigateNeutral = fadeIn togetherWith fadeOut

val enter
get() = slideIn(AnimatedContentTransitionScope.SlideDirection.Left)

val exit
get() = slideOut(AnimatedContentTransitionScope.SlideDirection.Left)

val popEnter
get() = slideIn(AnimatedContentTransitionScope.SlideDirection.Right)

val popExit
get() = slideOut(AnimatedContentTransitionScope.SlideDirection.Right)

fun slideIn(
direction: AnimatedContentTransitionScope.SlideDirection
): EnterTransition = slideInHorizontally(
animationSpec = tween(duration)
) { width ->
return@slideInHorizontally when(direction) {
AnimatedContentTransitionScope.SlideDirection.Left -> width
else -> - width
}
} + fadeIn

fun slideOut(
direction: AnimatedContentTransitionScope.SlideDirection
): ExitTransition = slideOutHorizontally(
animationSpec = tween(duration)
) { width ->
return@slideOutHorizontally when(direction) {
AnimatedContentTransitionScope.SlideDirection.Left -> - width
else -> width
}
} + fadeOut
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package de.tum.informatics.www1.artemis.native_app.core.ui.navigation

import androidx.compose.animation.AnimatedContentScope
import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.SizeTransform
import androidx.compose.runtime.Composable
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavDeepLink
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import kotlin.reflect.KType


inline fun <reified T : Any> NavGraphBuilder.animatedComposable(
typeMap: Map<KType, @JvmSuppressWildcards NavType<*>> = emptyMap(),
deepLinks: List<NavDeepLink> = emptyList(),
noinline enterTransition:
(AnimatedContentTransitionScope<NavBackStackEntry>.() -> @JvmSuppressWildcards
EnterTransition?)? = { DefaultTransition.enter },
noinline exitTransition:
(AnimatedContentTransitionScope<NavBackStackEntry>.() -> @JvmSuppressWildcards
ExitTransition?)? = { DefaultTransition.exit },
noinline popEnterTransition:
(AnimatedContentTransitionScope<NavBackStackEntry>.() -> @JvmSuppressWildcards
EnterTransition?)? = { DefaultTransition.popEnter },
noinline popExitTransition:
(AnimatedContentTransitionScope<NavBackStackEntry>.() -> @JvmSuppressWildcards
ExitTransition?)? = { DefaultTransition.popExit },
noinline sizeTransform:
(AnimatedContentTransitionScope<NavBackStackEntry>.() -> @JvmSuppressWildcards
SizeTransform?)? =
null,
noinline content: @Composable AnimatedContentScope.(NavBackStackEntry) -> Unit
) = composable<T>(
enterTransition = enterTransition,
exitTransition = exitTransition,
popEnterTransition = popEnterTransition,
popExitTransition = popExitTransition,
sizeTransform = sizeTransform,
typeMap = typeMap,
deepLinks = deepLinks,
content = content
)
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptionsBuilder
import androidx.navigation.compose.composable
import de.tum.informatics.www1.artemis.native_app.core.data.DataState
import de.tum.informatics.www1.artemis.native_app.core.model.Course
import de.tum.informatics.www1.artemis.native_app.core.ui.AwaitDeferredCompletion
Expand All @@ -63,6 +62,7 @@ import de.tum.informatics.www1.artemis.native_app.core.ui.common.course.computeC
import de.tum.informatics.www1.artemis.native_app.core.ui.common.course.computeCourseItemModifier
import de.tum.informatics.www1.artemis.native_app.core.ui.getWindowSizeClass
import de.tum.informatics.www1.artemis.native_app.core.ui.markdown.MarkdownText
import de.tum.informatics.www1.artemis.native_app.core.ui.navigation.animatedComposable
import kotlinx.coroutines.Deferred
import kotlinx.serialization.Serializable
import org.koin.androidx.compose.koinViewModel
Expand All @@ -82,7 +82,7 @@ fun NavGraphBuilder.courseRegistration(
onNavigateUp: () -> Unit,
onRegisteredInCourse: (courseId: Long) -> Unit
) {
composable<CourseRegistrationScreen> {
animatedComposable<CourseRegistrationScreen> {
RegisterForCourseScreen(
modifier = Modifier.fillMaxSize(),
viewModel = koinViewModel(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package de.tum.informatics.www1.artemis.native_app.feature.courseview.ui.course_

import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.SizeTransform
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.consumeWindowInsets
Expand All @@ -20,7 +17,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
Expand All @@ -33,9 +29,6 @@ import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptionsBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import androidx.navigation.navDeepLink
import androidx.navigation.toRoute
import de.tum.informatics.www1.artemis.native_app.core.data.DataState
Expand All @@ -46,17 +39,19 @@ import de.tum.informatics.www1.artemis.native_app.core.ui.common.BasicDataStateU
import de.tum.informatics.www1.artemis.native_app.core.ui.common.EmptyDataStateUi
import de.tum.informatics.www1.artemis.native_app.core.ui.exercise.BoundExerciseActions
import de.tum.informatics.www1.artemis.native_app.core.ui.generateLinks
import de.tum.informatics.www1.artemis.native_app.core.ui.navigation.DefaultTransition
import de.tum.informatics.www1.artemis.native_app.core.ui.navigation.animatedComposable
import de.tum.informatics.www1.artemis.native_app.feature.courseview.GroupedByWeek
import de.tum.informatics.www1.artemis.native_app.feature.courseview.R
import de.tum.informatics.www1.artemis.native_app.feature.courseview.ui.CourseViewModel
import de.tum.informatics.www1.artemis.native_app.feature.courseview.ui.LectureListUi
import de.tum.informatics.www1.artemis.native_app.feature.courseview.ui.exercise_list.ExerciseListUi
import de.tum.informatics.www1.artemis.native_app.feature.metis.NavigateToUserConversation
import de.tum.informatics.www1.artemis.native_app.feature.metis.NothingOpened
import de.tum.informatics.www1.artemis.native_app.feature.metis.OpenedConversation
import de.tum.informatics.www1.artemis.native_app.feature.metis.OpenedThread
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.StandalonePostId
import de.tum.informatics.www1.artemis.native_app.feature.metis.ui.ConversationFacadeUi
import de.tum.informatics.www1.artemis.native_app.feature.metis.ui.NavigateToUserConversation
import de.tum.informatics.www1.artemis.native_app.feature.metis.ui.NothingOpened
import de.tum.informatics.www1.artemis.native_app.feature.metis.ui.OpenedConversation
import de.tum.informatics.www1.artemis.native_app.feature.metis.ui.OpenedThread
import kotlinx.serialization.Serializable
import org.koin.androidx.compose.koinViewModel
import org.koin.core.parameter.parametersOf
Expand Down Expand Up @@ -98,7 +93,7 @@ fun NavGraphBuilder.course(
generateLinks("courses/{courseId}/exercises") +
generateLinks("courses/{courseId}/messages?conversationId={conversationId}") +
generateLinks("courses/{courseId}/messages?username={username}")
composable<CourseUiScreen>(
animatedComposable<CourseUiScreen>(
deepLinks = deepLinks
) { backStackEntry ->
val route: CourseUiScreen = backStackEntry.toRoute()
Expand Down Expand Up @@ -346,11 +341,9 @@ internal fun CourseUiScreen(
targetState = selectedTabIndex,
transitionSpec = {
if (targetState > initialState) {
slideInHorizontally { width -> width } togetherWith
slideOutHorizontally { width -> -width }
DefaultTransition.navigateForward
} else {
slideInHorizontally { width -> -width } togetherWith
slideOutHorizontally { width -> width }
DefaultTransition.navigateBack
}.using(
SizeTransform(clip = false)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptionsBuilder
import androidx.navigation.compose.composable
import de.tum.informatics.www1.artemis.native_app.core.model.Dashboard
import de.tum.informatics.www1.artemis.native_app.core.ui.common.BasicDataStateUi
import de.tum.informatics.www1.artemis.native_app.core.ui.navigation.animatedComposable
import de.tum.informatics.www1.artemis.native_app.feature.dashboard.BuildConfig
import de.tum.informatics.www1.artemis.native_app.feature.dashboard.R
import de.tum.informatics.www1.artemis.native_app.feature.dashboard.service.BetaHintService
Expand All @@ -71,7 +71,7 @@ fun NavGraphBuilder.dashboard(
onClickRegisterForCourse: () -> Unit,
onViewCourse: (courseId: Long) -> Unit
) {
composable<DashboardScreen> {
animatedComposable<DashboardScreen> {
CoursesOverview(
modifier = Modifier.fillMaxSize(),
viewModel = koinViewModel(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptionsBuilder
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navDeepLink
import androidx.navigation.toRoute
Expand All @@ -25,6 +24,7 @@ import de.tum.informatics.www1.artemis.native_app.core.ui.common.BasicDataStateU
import de.tum.informatics.www1.artemis.native_app.core.ui.common.EmptyDataStateUi
import de.tum.informatics.www1.artemis.native_app.core.ui.generateLinks
import de.tum.informatics.www1.artemis.native_app.core.ui.navigation.KSerializableNavType
import de.tum.informatics.www1.artemis.native_app.core.ui.navigation.animatedComposable
import de.tum.informatics.www1.artemis.native_app.feature.exerciseview.home.ExerciseScreen
import de.tum.informatics.www1.artemis.native_app.feature.exerciseview.participate.textexercise.TextExerciseParticipationScreen
import de.tum.informatics.www1.artemis.native_app.feature.exerciseview.viewresult.ViewResultScreen
Expand Down Expand Up @@ -82,7 +82,7 @@ fun NavGraphBuilder.exercise(
onParticipateInQuiz: (courseId: Long, exerciseId: Long, isPractice: Boolean) -> Unit,
onClickViewQuizResults: (courseId: Long, exerciseId: Long) -> Unit
) {
composable<ExerciseViewUi>(
animatedComposable<ExerciseViewUi>(
typeMap = mapOf(
typeOf<ExerciseViewMode>() to KSerializableNavType(
isNullableAllowed = false,
Expand Down Expand Up @@ -131,7 +131,7 @@ fun NavGraphBuilder.exercise(
}

NavHost(navController = nestedNavController, startDestination = startDestination) {
composable<ExerciseViewUiNestedNavigation.Home> {
animatedComposable<ExerciseViewUiNestedNavigation.Home> {
ExerciseScreen(
modifier = Modifier.fillMaxSize(),
viewModel = exerciseViewModel,
Expand All @@ -156,15 +156,15 @@ fun NavGraphBuilder.exercise(
)
}

composable<ExerciseViewUiNestedNavigation.Result> {
animatedComposable<ExerciseViewUiNestedNavigation.Result> {
ViewResultScreen(
modifier = Modifier.fillMaxSize(),
viewModel = exerciseViewModel,
onCloseResult = nestedNavigateUp
)
}

composable<ExerciseViewUiNestedNavigation.ParticipateTextExercise> { backStackEntry ->
animatedComposable<ExerciseViewUiNestedNavigation.ParticipateTextExercise> { backStackEntry ->
val nestedRoute: ExerciseViewUiNestedNavigation.ParticipateTextExercise =
backStackEntry.toRoute()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,16 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptionsBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import androidx.navigation.navDeepLink
import androidx.navigation.toRoute
import io.github.fornewid.placeholder.material3.placeholder
import de.tum.informatics.www1.artemis.native_app.core.model.lecture.Attachment
import de.tum.informatics.www1.artemis.native_app.core.ui.LocalLinkOpener
import de.tum.informatics.www1.artemis.native_app.core.ui.alert.TextAlertDialog
import de.tum.informatics.www1.artemis.native_app.core.ui.generateLinks
import de.tum.informatics.www1.artemis.native_app.core.ui.navigation.animatedComposable
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.content.MetisContext
import de.tum.informatics.www1.artemis.native_app.feature.metis.ui.canDisplayMetisOnDisplaySide
import io.github.fornewid.placeholder.material3.placeholder
import io.ktor.http.HttpHeaders
import io.ktor.http.URLBuilder
import io.ktor.http.appendPathSegments
Expand Down Expand Up @@ -71,7 +69,7 @@ fun NavGraphBuilder.lecture(
onParticipateInQuiz: (courseId: Long, exerciseId: Long, isPractice: Boolean) -> Unit,
onClickViewQuizResults: (courseId: Long, exerciseId: Long) -> Unit,
) {
composable<LectureScreenUi>(
animatedComposable<LectureScreenUi>(
deepLinks = listOf(
navDeepLink {
uriPattern = "artemis://lectures/{lectureId}"
Expand Down
Loading

0 comments on commit e338e6c

Please sign in to comment.