11package com.developerbreach.developerbreach.controller
22
3+ import android.view.View
4+ import android.widget.ImageView
35import android.widget.TextView
46import androidx.navigation.NavController
7+ import androidx.navigation.NavDirections
8+ import androidx.navigation.fragment.FragmentNavigator
59import androidx.navigation.fragment.FragmentNavigatorExtras
6- import com.developerbreach.developerbreach.R
710import com.developerbreach.developerbreach.view.detail.ArticleDetailFragmentDirections
8- import com.developerbreach.developerbreach.view.favorites.FavoritesFragmentDirections
11+ import com.developerbreach.developerbreach.view.detail.ArticleDetailFragment
912import com.developerbreach.developerbreach.view.home.HomeFragmentDirections
13+ import com.developerbreach.developerbreach.view.home.HomeFragment
14+ import com.developerbreach.developerbreach.view.list.ArticleListFragment
15+ import com.developerbreach.developerbreach.view.favorites.FavoritesFragment
1016import com.developerbreach.developerbreach.view.intro.IntroFragmentDirections
11- import com.developerbreach.developerbreach.view.list.ArticleListFragmentDirections
17+ import com.developerbreach.developerbreach.view.network.NetworkFragmentDirections
1218import com.developerbreach.developerbreach.view.options.OptionsFragmentDirections
13- import com.developerbreach.developerbreach.view.search.SearchFragmentDirections
1419import com.developerbreach.developerbreach.view.settings.SettingsFragmentDirections
1520import com.google.android.material.card.MaterialCardView
1621
@@ -19,106 +24,73 @@ class AppNavDirections(
1924 private val navController : NavController ,
2025) {
2126
22- /* * IntroFragment **/
23-
24- fun introToHome () {
25- navController.navigate(IntroFragmentDirections .introToHome())
27+ private fun navigate (directions : NavDirections ) {
28+ navController.navigate(directions)
2629 }
2730
28- /* * HomeFragment **/
29-
30- fun homeToSearch () {
31- navController.navigate(HomeFragmentDirections .homeToSearch())
31+ private fun navigateWithExtras (
32+ directions : NavDirections ,
33+ extras : FragmentNavigator .Extras
34+ ) {
35+ navController.navigate(directions, extras)
3236 }
3337
34- fun homeToDetail (articleId : Int , view : MaterialCardView ) {
35- navController.navigate(
36- HomeFragmentDirections .homeToDetail(articleId),
37- FragmentNavigatorExtras (view to articleId.toString())
38- )
39- }
38+ /* * IntroFragment */
39+ fun introToHome () = navigate(IntroFragmentDirections .introToHome())
4040
41- fun homeToOptions () {
42- navController.navigate(HomeFragmentDirections .homeToOptions())
43- }
44-
45- fun homeToIntro () {
46- navController.navigate(R .id.introFragment)
47- }
41+ /* * HomeFragment */
42+ fun homeToSearch () = navigate(HomeFragmentDirections .homeToSearch())
43+ fun homeToOptions () = navigate(OptionsFragmentDirections .toOptionsFragmentGlobal())
44+ fun homeToIntro () = navigate(IntroFragmentDirections .toIntroFragmentGlobal())
45+ fun homeToArticleList () = navigate(HomeFragmentDirections .homeToArticleList())
4846
49- fun homeToArticleList () {
50- navController.navigate(HomeFragmentDirections .homeToArticleList())
51- }
47+ /* * OptionsFragment */
48+ fun optionsToAuthors () = navigate(OptionsFragmentDirections .optionsToAuthors())
49+ fun optionsToFavorites () = navigate(OptionsFragmentDirections .optionsToFavorites())
50+ fun optionsToSearch () = navigate(OptionsFragmentDirections .optionsToSearch())
51+ fun optionsToSettings () = navigate(OptionsFragmentDirections .optionsToSettings())
52+ fun optionsToIntro () = navigate(IntroFragmentDirections .toIntroFragmentGlobal())
5253
53- /* * SearchFragment **/
54+ /* * NetworkFragment */
55+ fun toNetworkFragment () = navigate(NetworkFragmentDirections .toNetworkFragmentGlobal())
5456
57+ /* * SearchFragment */
5558 fun searchToDetail (articleId : Int , view : TextView ) {
56- navController.navigate (
57- SearchFragmentDirections .searchToDetail (articleId),
59+ navigateWithExtras (
60+ ArticleDetailFragmentDirections .toDetailFragmentGlobal (articleId),
5861 FragmentNavigatorExtras (view to articleId.toString())
5962 )
6063 }
6164
62- /* * ArticleListFragment **/
63-
64- fun articlesListToDetail (articleId : Int , view : MaterialCardView ) {
65- navController.navigate(
66- ArticleListFragmentDirections .articleListToDetail(articleId),
67- FragmentNavigatorExtras (view to articleId.toString())
68- )
69- }
70-
71- /* * FavoritesFragment **/
72-
73- fun favoritesToDetail (articleId : Int , view : MaterialCardView ) {
74- navController.navigate(
75- FavoritesFragmentDirections .favoritesToDetail(articleId),
65+ /* *
66+ * [HomeFragment] [FavoritesFragment] [ArticleListFragment]
67+ * to
68+ * [ArticleDetailFragment]
69+ */
70+ fun fragmentsToDetailFragment (
71+ articleId : Int ,
72+ view : MaterialCardView
73+ ) {
74+ navigateWithExtras(
75+ ArticleDetailFragmentDirections .toDetailFragmentGlobal(articleId),
7676 FragmentNavigatorExtras (view to articleId.toString())
7777 )
7878 }
7979
80- /* * DetailFragment **/
81-
80+ /* * DetailFragment */
8281 fun detailToArticleWebView (articleUrlLink : String? ) {
83- navController. navigate(ArticleDetailFragmentDirections .detailToArticleWebView(articleUrlLink))
82+ navigate(ArticleDetailFragmentDirections .detailToArticleWebView(articleUrlLink))
8483 }
8584
86- fun detailToBanner (bannerUrl : String? ) {
87- navController.navigate(ArticleDetailFragmentDirections .detailToBanner(bannerUrl))
85+ fun detailToBanner (bannerUrl : String? , view : ImageView ) {
86+ navigateWithExtras(
87+ ArticleDetailFragmentDirections .detailToBanner(bannerUrl),
88+ FragmentNavigatorExtras (view as View to bannerUrl.toString())
89+ )
8890 }
8991
90- /* * SettingsFragment **/
91-
92+ /* * SettingsFragment */
9293 fun settingsToCommonWebView (webUrl : String ) {
93- navController.navigate(SettingsFragmentDirections .settingsToCommonWebView(webUrl))
94- }
95-
96- /* * OptionsFragment **/
97-
98- fun optionsToAuthors () {
99- navController.navigate(OptionsFragmentDirections .optionsToAuthors())
100- }
101-
102- fun optionsToFavorites () {
103- navController.navigate(OptionsFragmentDirections .optionsToFavorites())
104- }
105-
106- fun optionsToSearch () {
107- navController.navigate(OptionsFragmentDirections .optionsToSearch())
94+ navigate(SettingsFragmentDirections .settingsToCommonWebView(webUrl))
10895 }
109-
110- fun optionsToSettings () {
111- navController.navigate(OptionsFragmentDirections .optionsToSettings())
112- }
113-
114- fun optionsToIntro () {
115- navController.navigate(OptionsFragmentDirections .optionsToIntro())
116- }
117-
118- /* * NetworkFragment **/
119-
120- fun toNetworkFragment () {
121- navController.navigate(R .id.networkFragment)
122- }
123- }
124-
96+ }
0 commit comments