Skip to content

Commit

Permalink
CompatDestination: Move to :core:compat:navigation (#456)
Browse files Browse the repository at this point in the history
This allows for reusability (#369)
  • Loading branch information
EdricChan03 committed Jul 13, 2024
1 parent 36e22ca commit cdcd6ac
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.navigation.activity
import androidx.navigation.fragment.fragment
import androidx.navigation.navigation
import com.edricchan.studybuddy.BuildConfig
import com.edricchan.studybuddy.core.compat.navigation.CompatDestination
import com.edricchan.studybuddy.features.auth.ui.LoginActivity
import com.edricchan.studybuddy.features.auth.ui.RegisterActivity
import com.edricchan.studybuddy.features.auth.ui.ResetPasswordActivity
Expand All @@ -25,104 +26,6 @@ import com.edricchan.studybuddy.ui.modules.task.ViewTaskActivity
import com.edricchan.studybuddy.ui.modules.task.fragment.TaskListFragment
import com.edricchan.studybuddy.ui.modules.tips.fragment.TipsFragment
import com.edricchan.studybuddy.ui.modules.updates.UpdatesActivity
import kotlinx.serialization.Serializable

/** Destinations that have yet to be migrated to Jetpack Compose. */
// TODO: Remove
sealed interface CompatDestination {
// Top-level destinations

/** Typed destination for the [DebugActivity] entry-point. */
@Serializable
data object Debug : CompatDestination

/** Typed destination for the [DebugModalBottomSheetActivity] entry-point. */
@Serializable
data object DebugModalBottomSheet : CompatDestination

/** Typed destination for the [UpdatesActivity] entry-point. */
@Serializable
data object Updates : CompatDestination

/** Typed destination for the [SettingsActivity] entry-point. */
@Serializable
data object Settings : CompatDestination

/** Typed destination for the [HelpActivity] entry-point. */
@Serializable
data object Help : CompatDestination

// Feature destinations

/** Typed destination for the [TipsFragment] entry-point. */
@Serializable
data object Tips : CompatDestination

/** Typed destination for the [CalendarFragment] entry-point. */
@Serializable
data object Calendar : CompatDestination

/** Destinations related to the about feature. */
@Serializable
sealed interface About : CompatDestination {
/** Typed destination for the [AboutFragment] entry-point. */
@Serializable
data object AppAbout : About

/** Typed destination for viewing the app's information in the device's settings. */
@Serializable
data object SystemAppInfo : About

/** Typed destination for viewing the app's licenses. */
@Serializable
data object ViewLicenses : About
}


/** Destinations related to the auth feature. */
@Serializable
sealed interface Auth : CompatDestination {
/** Typed destination for the [ResetPasswordActivity] entry-point. */
@Serializable
data object ResetPassword : Auth

/** Typed destination for the [AccountActivity] entry-point. */
@Serializable
data object Account : Auth

/** Typed destination for the [LoginActivity] entry-point. */
@Serializable
data object Login : Auth

/** Typed destination for the [RegisterActivity] entry-point. */
@Serializable
data object Register : Auth
}

/** Destinations related to the tasks feature. */
@Serializable
sealed interface Task : CompatDestination {
/** Top-level entry-point for the tasks feature. */
@Serializable
data object Root : Task

/** Typed destination for the [NewTaskActivity] entry-point. */
@Serializable
data object New : Task

/** Typed destination for the [TaskListFragment] entry-point. */
@Serializable
data object List : Task

/** Typed destination for the [EditTaskActivity] entry-point. */
@Serializable
data class Edit(val taskId: String) : Task

/** Typed destination for the [ViewTaskActivity] entry-point. */
@Serializable
data class View(val taskId: String) : Task
}
}

fun NavGraphBuilder.aboutGraph() {
fragment<AboutFragment, CompatDestination.About.AppAbout>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.edricchan.studybuddy.navigation.compat

import androidx.navigation.NavController
import androidx.navigation.NavOptionsBuilder
import com.edricchan.studybuddy.core.compat.navigation.CompatDestination

val DefaultNavOptionsBuilder: NavOptionsBuilder.() -> Unit = {
launchSingleTop = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.edricchan.studybuddy.navigation.compat.about

import androidx.navigation.NavController
import androidx.navigation.NavOptionsBuilder
import com.edricchan.studybuddy.navigation.compat.CompatDestination
import com.edricchan.studybuddy.core.compat.navigation.CompatDestination
import com.edricchan.studybuddy.navigation.compat.DefaultNavOptionsBuilder

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.edricchan.studybuddy.navigation.compat.auth

import androidx.navigation.NavController
import androidx.navigation.NavOptionsBuilder
import com.edricchan.studybuddy.navigation.compat.CompatDestination
import com.edricchan.studybuddy.core.compat.navigation.CompatDestination
import com.edricchan.studybuddy.navigation.compat.DefaultNavOptionsBuilder

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.edricchan.studybuddy.navigation.compat.task

import androidx.navigation.NavController
import androidx.navigation.NavOptionsBuilder
import com.edricchan.studybuddy.navigation.compat.CompatDestination
import com.edricchan.studybuddy.core.compat.navigation.CompatDestination
import com.edricchan.studybuddy.navigation.compat.DefaultNavOptionsBuilder

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import com.edricchan.studybuddy.BuildConfig
import com.edricchan.studybuddy.R
import com.edricchan.studybuddy.constants.Constants
import com.edricchan.studybuddy.constants.MimeTypeConstants
import com.edricchan.studybuddy.core.compat.navigation.CompatDestination
import com.edricchan.studybuddy.core.deeplink.AppDeepLink
import com.edricchan.studybuddy.core.deeplink.WebDeepLink
import com.edricchan.studybuddy.databinding.ActivityMainBinding
import com.edricchan.studybuddy.exts.android.startChooser
import com.edricchan.studybuddy.exts.androidx.preference.defaultSharedPreferences
import com.edricchan.studybuddy.exts.material.dialog.showMaterialAlertDialog
import com.edricchan.studybuddy.exts.material.snackbar.showSnackbar
import com.edricchan.studybuddy.navigation.compat.CompatDestination
import com.edricchan.studybuddy.navigation.compat.auth.navigateToAccountInfo
import com.edricchan.studybuddy.navigation.compat.compatGraphs
import com.edricchan.studybuddy.navigation.compat.navigateToCalendar
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.edricchan.studybuddy.core.compat.navigation

import kotlinx.serialization.Serializable

/** Destinations that have yet to be migrated to Jetpack Compose. */
// TODO: Remove
sealed interface CompatDestination {
// Top-level destinations

/** Typed destination for the `DebugActivity` entry-point. */
@Serializable
data object Debug : CompatDestination

/** Typed destination for the `DebugModalBottomSheetActivity` entry-point. */
@Serializable
data object DebugModalBottomSheet : CompatDestination

/** Typed destination for the updates entry-point. */
@Serializable
data object Updates : CompatDestination

/** Typed destination for the settings entry-point. */
@Serializable
data object Settings : CompatDestination

/** Typed destination for the help entry-point. */
@Serializable
data object Help : CompatDestination

// Feature destinations

/** Typed destination for the tips entry-point. */
@Serializable
data object Tips : CompatDestination

/** Typed destination for the calendar entry-point. */
@Serializable
data object Calendar : CompatDestination

/** Destinations related to the about feature. */
@Serializable
sealed interface About : CompatDestination {
/** Typed destination for the about entry-point. */
@Serializable
data object AppAbout : About

/** Typed destination for viewing the app's information in the device's settings. */
@Serializable
data object SystemAppInfo : About

/** Typed destination for viewing the app's source code. */
@Serializable
data object ViewSource : About

/** Typed destination for viewing the app's licenses. */
@Serializable
data object ViewLicenses : About
}


/** Destinations related to the auth feature. */
@Serializable
sealed interface Auth : CompatDestination {
/** Typed destination for the reset password entry-point. */
@Serializable
data object ResetPassword : Auth

/** Typed destination for the account entry-point. */
@Serializable
data object Account : Auth

/** Typed destination for the login entry-point. */
@Serializable
data object Login : Auth

/** Typed destination for the register entry-point. */
@Serializable
data object Register : Auth
}

/** Destinations related to the tasks feature. */
@Serializable
sealed interface Task : CompatDestination {
/** Top-level entry-point for the tasks feature. */
@Serializable
data object Root : Task

/** Typed destination for the new task entry-point. */
@Serializable
data object New : Task

/** Typed destination for the task list entry-point. */
@Serializable
data object List : Task

/** Typed destination for the edit task entry-point. */
@Serializable
data class Edit(val taskId: String) : Task

/** Typed destination for the view task entry-point. */
@Serializable
data class View(val taskId: String) : Task
}
}

0 comments on commit cdcd6ac

Please sign in to comment.