-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from truyentd-2427/optimize_navigation
Optimize navigation
- Loading branch information
Showing
14 changed files
with
164 additions
and
63 deletions.
There are no files selected for viewing
3 changes: 0 additions & 3 deletions
3
app/src/main/java/com/truyentd/moviecompose/navigation/AppDestination.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/truyentd/moviecompose/navigation/BaseDestination.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.truyentd.moviecompose.navigation | ||
|
||
import androidx.navigation.NamedNavArgument | ||
|
||
abstract class BaseDestination(val route: String = "") { | ||
open val arguments: List<NamedNavArgument> = emptyList() | ||
|
||
open val deepLinks: List<String> = listOf( | ||
"https://moviecompose.com/$route", | ||
) | ||
|
||
open var destination: String = route | ||
|
||
open var parcelableArgument: Pair<String, Any?> = "" to null | ||
|
||
|
||
data class Up(val results: HashMap<String, Any> = hashMapOf()) : BaseDestination() { | ||
fun addResult(key: String, value: Any) = apply { | ||
results[key] = value | ||
} | ||
} | ||
|
||
data class PopToBackStack( | ||
val targetDestination: BaseDestination, | ||
val inclusive: Boolean = false, | ||
val results: HashMap<String, Any> = hashMapOf(), | ||
) : BaseDestination() { | ||
fun addResult(key: String, value: Any) = apply { | ||
results[key] = value | ||
} | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
app/src/main/java/com/truyentd/moviecompose/navigation/auth/AuthDestination.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package com.truyentd.moviecompose.navigation.auth | ||
|
||
import com.truyentd.moviecompose.navigation.AppDestination | ||
import com.truyentd.moviecompose.navigation.BaseDestination | ||
|
||
sealed class AuthDestination(route: String): AppDestination(route) { | ||
object Login : AppDestination(route = "login") | ||
} | ||
sealed class AuthDestination(route: String): BaseDestination(route) { | ||
object Login : BaseDestination(route = "login") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 14 additions & 2 deletions
16
app/src/main/java/com/truyentd/moviecompose/navigation/movie/MovieDestination.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
package com.truyentd.moviecompose.navigation.movie | ||
|
||
sealed class MovieDestination(val route: String) { | ||
object MovieDetail: MovieDestination("movie-detail/{movieId}") | ||
import androidx.navigation.NavType | ||
import androidx.navigation.navArgument | ||
import com.truyentd.moviecompose.navigation.BaseDestination | ||
|
||
sealed class MovieDestination { | ||
object MovieDetail : BaseDestination("movie/{movieId}") { | ||
override val arguments = listOf( | ||
navArgument("movieId") { type = NavType.StringType } | ||
) | ||
|
||
fun createRoute(id: String) = apply { | ||
destination = "movie/$id" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.