Skip to content

Commit 2350a52

Browse files
authored
Revert "Chore: Update compose navigation and use type safe navigati… (#67)
1 parent d8a8980 commit 2350a52

File tree

14 files changed

+244
-244
lines changed

14 files changed

+244
-244
lines changed

app/src/main/java/de/tum/informatics/www1/artemis/native_app/android/ui/MainActivity.kt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import androidx.compose.ui.res.stringResource
2121
import androidx.core.net.toUri
2222
import androidx.lifecycle.lifecycleScope
2323
import androidx.navigation.NavHostController
24+
import androidx.navigation.NavOptions
2425
import androidx.navigation.compose.NavHost
2526
import androidx.navigation.compose.rememberNavController
26-
import androidx.navigation.navOptions
2727
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
2828
import de.tum.informatics.www1.artemis.native_app.android.BuildConfig
2929
import de.tum.informatics.www1.artemis.native_app.android.R
@@ -40,18 +40,16 @@ import de.tum.informatics.www1.artemis.native_app.feature.courseregistration.cou
4040
import de.tum.informatics.www1.artemis.native_app.feature.courseregistration.navigateToCourseRegistration
4141
import de.tum.informatics.www1.artemis.native_app.feature.courseview.ui.course_overview.course
4242
import de.tum.informatics.www1.artemis.native_app.feature.courseview.ui.course_overview.navigateToCourse
43-
import de.tum.informatics.www1.artemis.native_app.feature.dashboard.DashboardScreen
43+
import de.tum.informatics.www1.artemis.native_app.feature.dashboard.DASHBOARD_DESTINATION
4444
import de.tum.informatics.www1.artemis.native_app.feature.dashboard.dashboard
4545
import de.tum.informatics.www1.artemis.native_app.feature.dashboard.navigateToDashboard
4646
import de.tum.informatics.www1.artemis.native_app.feature.exerciseview.ExerciseViewDestination
4747
import de.tum.informatics.www1.artemis.native_app.feature.exerciseview.ExerciseViewMode
48-
import de.tum.informatics.www1.artemis.native_app.feature.exerciseview.ExerciseViewUi
49-
import de.tum.informatics.www1.artemis.native_app.feature.exerciseview.ExerciseViewUiNestedNavigation
5048
import de.tum.informatics.www1.artemis.native_app.feature.exerciseview.exercise
5149
import de.tum.informatics.www1.artemis.native_app.feature.exerciseview.navigateToExercise
5250
import de.tum.informatics.www1.artemis.native_app.feature.lectureview.lecture
5351
import de.tum.informatics.www1.artemis.native_app.feature.lectureview.navigateToLecture
54-
import de.tum.informatics.www1.artemis.native_app.feature.login.LoginScreen
52+
import de.tum.informatics.www1.artemis.native_app.feature.login.LOGIN_DESTINATION
5553
import de.tum.informatics.www1.artemis.native_app.feature.login.loginScreen
5654
import de.tum.informatics.www1.artemis.native_app.feature.login.navigateToLogin
5755
import de.tum.informatics.www1.artemis.native_app.feature.metis.shared.visiblemetiscontextreporter.ProvideLocalVisibleMetisContextManager
@@ -97,8 +95,8 @@ class MainActivity : AppCompatActivity(),
9795
// When the user is logged in, immediately display the course overview.
9896
val startDestination = runBlocking {
9997
when (accountService.authenticationData.first()) {
100-
is AccountService.AuthenticationData.LoggedIn -> DashboardScreen
101-
AccountService.AuthenticationData.NotLoggedIn -> LoginScreen
98+
is AccountService.AuthenticationData.LoggedIn -> DASHBOARD_DESTINATION
99+
AccountService.AuthenticationData.NotLoggedIn -> LOGIN_DESTINATION
102100
}
103101
}
104102

@@ -192,7 +190,7 @@ class MainActivity : AppCompatActivity(),
192190
}
193191

194192
@Composable
195-
private fun MainActivityComposeUi(startDestination: Any, navController: NavHostController) {
193+
private fun MainActivityComposeUi(startDestination: String, navController: NavHostController) {
196194
// Listen for when the user get logged out (e.g. because their token has expired)
197195
// This only happens when the user has the app running for multiple days or the user logged out manually
198196
LaunchedEffect(Unit) {
@@ -201,7 +199,7 @@ class MainActivity : AppCompatActivity(),
201199
.collect { (wasLoggedIn, isLoggedIn) ->
202200
if (wasLoggedIn == true && !isLoggedIn) {
203201
navController.navigateToLogin {
204-
popUpTo(DashboardScreen) {
202+
popUpTo(DASHBOARD_DESTINATION) {
205203
inclusive = true
206204
}
207205
}
@@ -261,17 +259,15 @@ class MainActivity : AppCompatActivity(),
261259
if (deepLink == null) {
262260
// Navigate to the course overview and remove the login screen from the navigation stack.
263261
navController.navigateToDashboard {
264-
popUpTo(LoginScreen) {
262+
popUpTo(LOGIN_DESTINATION) {
265263
inclusive = true
266264
}
267265
}
268266
} else {
269267
try {
270268
navController.navigate(
271269
Uri.parse(deepLink),
272-
navOptions {
273-
popUpTo<LoginScreen>()
274-
}
270+
NavOptions.Builder().setPopUpTo(LOGIN_DESTINATION, true).build()
275271
)
276272
} catch (_: IllegalArgumentException) {
277273
navController.navigateToDashboard {
@@ -351,7 +347,7 @@ class MainActivity : AppCompatActivity(),
351347
quizParticipation(
352348
onLeaveQuiz = {
353349
val previousBackStackEntry = navController.previousBackStackEntry
354-
if (previousBackStackEntry?.destination?.route == ExerciseViewUi::class.qualifiedName.orEmpty()) {
350+
if (previousBackStackEntry?.destination?.route == ExerciseViewDestination.EXERCISE_VIEW_ROUTE) {
355351
previousBackStackEntry.savedStateHandle[ExerciseViewDestination.REQUIRE_RELOAD_KEY] =
356352
true
357353
}

build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import org.gradle.api.artifacts.VersionCatalogsExtension
77
import org.gradle.kotlin.dsl.configure
88
import org.gradle.kotlin.dsl.dependencies
99
import org.gradle.kotlin.dsl.getByType
10-
import org.gradle.kotlin.dsl.kotlin
1110
import kotlin.Suppress
1211
import kotlin.apply
1312
import kotlin.with
@@ -19,7 +18,6 @@ class AndroidFeatureConventionPlugin : Plugin<Project> {
1918
pluginManager.apply {
2019
apply("artemis.android.library")
2120
apply("org.gradle.jacoco")
22-
apply("org.jetbrains.kotlin.plugin.serialization")
2321
}
2422

2523
extensions.configure<LibraryExtension> {

core/ui/src/main/kotlin/de/tum/informatics/www1/artemis/native_app/core/ui/navigation/KSerializableNavType.kt

Lines changed: 0 additions & 30 deletions
This file was deleted.

feature/course-registration/src/main/kotlin/de/tum/informatics/www1/artemis/native_app/feature/courseregistration/RegisterForCourseUi.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,23 @@ import de.tum.informatics.www1.artemis.native_app.core.ui.common.course.computeC
6060
import de.tum.informatics.www1.artemis.native_app.core.ui.getWindowSizeClass
6161
import de.tum.informatics.www1.artemis.native_app.core.ui.markdown.MarkdownText
6262
import kotlinx.coroutines.Deferred
63-
import kotlinx.serialization.Serializable
6463
import org.koin.androidx.compose.getViewModel
6564

6665
internal const val TEST_TAG_REGISTRABLE_COURSE_LIST = "registrable course list"
6766

6867
internal fun testTagForRegistrableCourse(courseId: Long) = "registrableCourse$courseId"
6968

70-
@Serializable
71-
private data object CourseRegistrationScreen
69+
private const val COURSE_REGISTRATION_DESTINATION = "courseRegistration"
7270

7371
fun NavController.navigateToCourseRegistration(builder: NavOptionsBuilder.() -> Unit) {
74-
navigate(CourseRegistrationScreen, builder)
72+
navigate(COURSE_REGISTRATION_DESTINATION, builder)
7573
}
7674

7775
fun NavGraphBuilder.courseRegistration(
7876
onNavigateUp: () -> Unit,
7977
onRegisteredInCourse: (courseId: Long) -> Unit
8078
) {
81-
composable<CourseRegistrationScreen> {
79+
composable(COURSE_REGISTRATION_DESTINATION) {
8280
RegisterForCourseScreen(
8381
modifier = Modifier.fillMaxSize(),
8482
viewModel = getViewModel(),

feature/course-view/src/main/kotlin/de/tum/informatics/www1/artemis/native_app/feature/courseview/ui/course_overview/CourseUiScreen.kt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import androidx.navigation.NavType
3434
import androidx.navigation.compose.composable
3535
import androidx.navigation.navArgument
3636
import androidx.navigation.navDeepLink
37-
import androidx.navigation.toRoute
3837
import de.tum.informatics.www1.artemis.native_app.core.data.DataState
3938
import de.tum.informatics.www1.artemis.native_app.core.model.Course
4039
import de.tum.informatics.www1.artemis.native_app.core.model.exercise.Exercise
@@ -54,7 +53,6 @@ import de.tum.informatics.www1.artemis.native_app.feature.metis.ui.NavigateToUse
5453
import de.tum.informatics.www1.artemis.native_app.feature.metis.ui.NothingOpened
5554
import de.tum.informatics.www1.artemis.native_app.feature.metis.ui.OpenedConversation
5655
import de.tum.informatics.www1.artemis.native_app.feature.metis.ui.OpenedThread
57-
import kotlinx.serialization.Serializable
5856
import org.koin.androidx.compose.koinViewModel
5957
import org.koin.core.parameter.parametersOf
6058

@@ -65,16 +63,8 @@ internal const val TAB_COMMUNICATION = 2
6563
internal const val DEFAULT_CONVERSATION_ID = -1L
6664
internal const val DEFAULT_POST_ID = -1L
6765

68-
@Serializable
69-
private data class CourseUiScreen(
70-
val courseId: Long,
71-
val conversationId: Long = DEFAULT_CONVERSATION_ID,
72-
val postId: Long = DEFAULT_POST_ID,
73-
val username: String = ""
74-
)
75-
7666
fun NavController.navigateToCourse(courseId: Long, builder: NavOptionsBuilder.() -> Unit) {
77-
navigate(CourseUiScreen(courseId), builder)
67+
navigate("course/$courseId", builder)
7868
}
7969

8070
fun NavGraphBuilder.course(
@@ -95,15 +85,25 @@ fun NavGraphBuilder.course(
9585
generateLinks("courses/{courseId}/exercises") +
9686
generateLinks("courses/{courseId}/messages?conversationId={conversationId}") +
9787
generateLinks("courses/{courseId}/messages?username={username}")
98-
composable<CourseUiScreen>(
88+
composable(
89+
route = "course/{courseId}",
90+
arguments = listOf(
91+
navArgument("courseId") { type = NavType.LongType; nullable = false },
92+
navArgument("conversationId") {
93+
type = NavType.LongType; defaultValue = DEFAULT_CONVERSATION_ID
94+
},
95+
navArgument("postId") { type = NavType.LongType; defaultValue = DEFAULT_POST_ID },
96+
navArgument("username") { type = NavType.StringType; defaultValue = "" }
97+
),
9998
deepLinks = deepLinks
10099
) { backStackEntry ->
101-
val route: CourseUiScreen = backStackEntry.toRoute()
102-
val courseId = route.courseId
100+
val courseId = backStackEntry.arguments?.getLong("courseId")
101+
checkNotNull(courseId)
103102

104-
val conversationId = route.conversationId
105-
val postId = route.postId
106-
val username = route.username
103+
val conversationId =
104+
backStackEntry.arguments?.getLong("conversationId") ?: DEFAULT_CONVERSATION_ID
105+
val postId = backStackEntry.arguments?.getLong("postId") ?: DEFAULT_POST_ID
106+
val username = backStackEntry.arguments?.getString("username").orEmpty()
107107

108108
CourseUiScreen(
109109
modifier = Modifier.fillMaxSize(),

feature/dashboard/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id("artemis.android.feature")
33
id("artemis.android.library.compose")
4+
kotlin("plugin.serialization")
45
}
56

67
android {

feature/dashboard/src/main/kotlin/de/tum/informatics/www1/artemis/native_app/feature/dashboard/CoursesOverview.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,25 @@ import de.tum.informatics.www1.artemis.native_app.core.ui.common.course.Expanded
7171
import de.tum.informatics.www1.artemis.native_app.core.ui.exercise.CoursePointsDecimalFormat
7272
import de.tum.informatics.www1.artemis.native_app.feature.dashboard.service.BetaHintService
7373
import kotlinx.coroutines.launch
74-
import kotlinx.serialization.Serializable
7574
import org.koin.androidx.compose.getViewModel
7675
import org.koin.compose.koinInject
7776
import java.text.DecimalFormat
7877

78+
const val DASHBOARD_DESTINATION = "dashboard"
7979
internal const val TEST_TAG_COURSE_LIST = "TEST_TAG_COURSE_LIST"
8080

8181
internal fun testTagForCourse(courseId: Long) = "Course$courseId"
8282

83-
@Serializable
84-
data object DashboardScreen
85-
8683
fun NavController.navigateToDashboard(builder: NavOptionsBuilder.() -> Unit) {
87-
navigate(DashboardScreen, builder)
84+
navigate(DASHBOARD_DESTINATION, builder)
8885
}
8986

9087
fun NavGraphBuilder.dashboard(
9188
onOpenSettings: () -> Unit,
9289
onClickRegisterForCourse: () -> Unit,
9390
onViewCourse: (courseId: Long) -> Unit
9491
) {
95-
composable<DashboardScreen> {
92+
composable(DASHBOARD_DESTINATION) {
9693
CoursesOverview(
9794
modifier = Modifier.fillMaxSize(),
9895
viewModel = getViewModel(),

0 commit comments

Comments
 (0)