Skip to content

Commit 60e56b8

Browse files
authored
Merge pull request #70 from swingmx/search
Make Bottom Navigation Visible on All Screens πŸ‘¨β€πŸ”§
2 parents 3bbf755 + 57b854f commit 60e56b8

26 files changed

Lines changed: 376 additions & 656 deletions

File tree

β€Žapp/src/main/java/com/android/swingmusic/presentation/activity/MainActivity.ktβ€Ž

Lines changed: 88 additions & 229 deletions
Large diffs are not rendered by default.
Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,39 @@
11
package com.android.swingmusic.presentation.navigator
22

33
import androidx.annotation.DrawableRes
4-
import com.ramcosta.composedestinations.spec.NavGraphSpec
4+
import com.android.swingmusic.album.presentation.screen.destinations.AllAlbumScreenDestination
5+
import com.android.swingmusic.artist.presentation.screen.destinations.AllArtistsScreenDestination
6+
import com.android.swingmusic.folder.presentation.screen.destinations.FoldersAndTracksScreenDestination
7+
import com.android.swingmusic.search.presentation.screen.destinations.SearchScreenDestination
8+
import com.ramcosta.composedestinations.spec.DestinationSpec
59
import com.android.swingmusic.uicomponent.R as UiComponent
610

711
sealed class BottomNavItem(
812
var title: String,
913
@DrawableRes var icon: Int,
10-
var navGraph: NavGraphSpec
14+
var destination: DestinationSpec<*>
1115
) {
12-
/*data object Home : BottomNavItem(
13-
title = "Home",
14-
icon = UiComponent.drawable.ic_home,
15-
navGraph = null
16-
)*/
17-
1816
data object Folder : BottomNavItem(
1917
title = "Folders",
2018
icon = UiComponent.drawable.folder_filled,
21-
navGraph = NavGraphs.folder
19+
destination = FoldersAndTracksScreenDestination
2220
)
2321

2422
data object Album : BottomNavItem(
2523
title = "Albums",
2624
icon = UiComponent.drawable.ic_album,
27-
navGraph = NavGraphs.album
25+
destination = AllAlbumScreenDestination
2826
)
2927

30-
/*data object Playlist : BottomNavItem(
31-
title = "Playlists",
32-
icon = UiComponent.drawable.play_list,
33-
navGraph = null
34-
)*/
35-
3628
data object Artist : BottomNavItem(
3729
title = "Artists",
3830
icon = UiComponent.drawable.ic_artist,
39-
navGraph = NavGraphs.artist
31+
destination = AllArtistsScreenDestination
4032
)
4133

4234
data object Search : BottomNavItem(
4335
title = "Search",
4436
icon = UiComponent.drawable.ic_search,
45-
navGraph = NavGraphs.search
37+
destination = SearchScreenDestination
4638
)
4739
}
Lines changed: 66 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,86 @@
11
package com.android.swingmusic.presentation.navigator
22

33
import androidx.navigation.NavController
4-
import androidx.navigation.NavOptionsBuilder
54
import com.android.swingmusic.album.presentation.screen.destinations.AlbumWithInfoScreenDestination
65
import com.android.swingmusic.artist.presentation.screen.destinations.ArtistInfoScreenDestination
76
import com.android.swingmusic.artist.presentation.screen.destinations.ViewAllScreenOnArtistDestination
87
import com.android.swingmusic.auth.presentation.screen.destinations.LoginWithQrCodeDestination
98
import com.android.swingmusic.auth.presentation.screen.destinations.LoginWithUsernameScreenDestination
10-
import com.android.swingmusic.auth.presentation.viewmodel.AuthViewModel
119
import com.android.swingmusic.common.presentation.navigator.CommonNavigator
1210
import com.android.swingmusic.folder.presentation.screen.destinations.FoldersAndTracksScreenDestination
11+
import com.android.swingmusic.home.presentation.destinations.HomeDestination
1312
import com.android.swingmusic.player.presentation.screen.destinations.QueueScreenDestination
14-
import com.android.swingmusic.player.presentation.viewmodel.MediaControllerViewModel
1513
import com.android.swingmusic.search.presentation.screen.destinations.ViewAllSearchResultsDestination
16-
import com.ramcosta.composedestinations.dynamic.within
1714
import com.ramcosta.composedestinations.navigation.navigate
18-
import com.ramcosta.composedestinations.spec.NavGraphSpec
1915

2016
class CoreNavigator(
21-
private val navGraph: NavGraphSpec,
22-
private val navController: NavController,
23-
private val mediaControllerViewModel: MediaControllerViewModel,
24-
private val authViewModel: AuthViewModel
17+
private val navController: NavController
2518
) : CommonNavigator {
19+
2620
/**----------------------------------- Auth Navigator ----------------------------------------*/
2721
override fun gotoLoginWithUsername() {
28-
val currentDestination = navController.currentDestination?.route
2922
val targetDestination = LoginWithUsernameScreenDestination
3023

31-
if (currentDestination != targetDestination.route) {
32-
navController.navigate(targetDestination within navGraph,
33-
fun NavOptionsBuilder.() {
34-
launchSingleTop = true
35-
restoreState = false
36-
37-
popUpTo(navController.graph.startDestinationId) {
38-
saveState = false
39-
inclusive = true
40-
}
41-
}
42-
)
24+
navController.navigate(targetDestination) {
25+
launchSingleTop = true
26+
restoreState = false
27+
28+
popUpTo(navController.graph.startDestinationId) {
29+
inclusive = true
30+
saveState = false
31+
}
4332
}
4433
}
4534

4635
override fun gotoLoginWithQrCode() {
47-
val currentDestination = navController.currentDestination?.route
4836
val targetDestination = LoginWithQrCodeDestination
4937

50-
if (currentDestination != targetDestination.route) {
51-
navController.navigate(targetDestination within navGraph,
52-
fun NavOptionsBuilder.() {
53-
launchSingleTop = true
54-
restoreState = false
55-
56-
popUpTo(navController.graph.startDestinationId) {
57-
saveState = false
58-
inclusive = true
59-
}
60-
}
61-
)
38+
navController.navigate(targetDestination) {
39+
launchSingleTop = true
40+
restoreState = false
41+
42+
popUpTo(navController.graph.startDestinationId) {
43+
inclusive = true
44+
saveState = false
45+
}
6246
}
6347
}
6448

65-
override fun gotoHomeNavGraph() {
66-
mediaControllerViewModel.refreshBaseUrl()
67-
authViewModel.updateIsUserLoggedInFlow() // flow collected in the main activity
68-
69-
val currentDestination = navController.currentDestination?.route
70-
val homeNavGraph = NavGraphs.home
71-
72-
if (currentDestination != homeNavGraph.route) {
73-
navController.navigate(
74-
homeNavGraph,
75-
fun NavOptionsBuilder.() {
76-
launchSingleTop = true
77-
restoreState = true
78-
79-
popUpTo(navController.graph.startDestinationId) {
80-
saveState = true
81-
inclusive = true
82-
}
83-
}
84-
)
49+
override fun gotoHome() {
50+
val targetDestination = HomeDestination()
51+
52+
navController.navigate(targetDestination) {
53+
launchSingleTop = true
54+
restoreState = false
55+
56+
popUpTo(navController.graph.startDestinationId) {
57+
inclusive = true
58+
saveState = false
59+
}
8560
}
8661
}
8762

8863
// Todo: Remove this after adding home content
89-
// REMEMBER: Bug -> Sometimes the app enters ANR state after this method is called
90-
override fun gotoFolderNavGraph() {
91-
mediaControllerViewModel.refreshBaseUrl()
92-
authViewModel.updateIsUserLoggedInFlow() // flow collected in the main activity
93-
94-
val currentDestination = navController.currentDestination?.route
95-
val folderNavGraph = NavGraphs.folder
96-
97-
if (currentDestination != folderNavGraph.route) {
98-
navController.navigate(
99-
folderNavGraph,
100-
fun NavOptionsBuilder.() {
101-
launchSingleTop = true
102-
restoreState = true
103-
104-
popUpTo(navController.graph.startDestinationId) {
105-
saveState = true
106-
inclusive = true
107-
}
108-
}
109-
)
64+
override fun gotoFolders() {
65+
val targetDestination = FoldersAndTracksScreenDestination()
66+
67+
navController.navigate(targetDestination) {
68+
launchSingleTop = true
69+
restoreState = false
70+
71+
popUpTo(navController.graph.startDestinationId) {
72+
inclusive = true
73+
saveState = false
74+
}
11075
}
11176
}
11277

11378
/**----------------------------------- Album Navigator --------------------------------------*/
11479
override fun gotoAlbumWithInfo(albumHash: String) {
115-
val currentDestination = navController.currentDestination?.route
11680
val targetDestination = AlbumWithInfoScreenDestination(albumHash)
11781

118-
if (currentDestination != targetDestination.route) {
119-
navController.navigate(
120-
targetDestination within navGraph,
121-
fun NavOptionsBuilder.() {
122-
launchSingleTop = true
123-
restoreState = true
124-
}
125-
)
82+
navController.navigate(targetDestination) {
83+
launchSingleTop = true
12684
}
12785
}
12886

@@ -132,29 +90,22 @@ class CoreNavigator(
13290

13391
/**----------------------------------- Player Navigator -------------------------------------*/
13492
override fun gotoQueueScreen() {
135-
val currentDestination = navController.currentDestination?.route
13693
val targetDestination = QueueScreenDestination
13794

138-
if (currentDestination != targetDestination.route) {
139-
navController.navigate(targetDestination within navGraph)
95+
navController.navigate(targetDestination) {
96+
launchSingleTop = true
14097
}
98+
14199
}
142100

143101
override fun gotoArtistInfo(artistHash: String) {
144-
val currentDestination = navController.currentDestination?.route
145102
val targetDestination = ArtistInfoScreenDestination(
146103
artistHash = artistHash,
147104
loadNewArtist = true
148105
)
149106

150-
if (currentDestination != targetDestination.route) {
151-
navController.navigate(
152-
targetDestination within navGraph,
153-
fun NavOptionsBuilder.() {
154-
launchSingleTop = true
155-
restoreState = true
156-
}
157-
)
107+
navController.navigate(targetDestination) {
108+
launchSingleTop = true
158109
}
159110
}
160111

@@ -163,56 +114,35 @@ class CoreNavigator(
163114
artistName: String,
164115
baseUrl: String
165116
) {
166-
val currentDestination = navController.currentDestination?.route
167-
val targetDestination =
168-
ViewAllScreenOnArtistDestination(viewAllType, artistName, baseUrl)
169-
170-
if (currentDestination != targetDestination.route) {
171-
navController.navigate(
172-
targetDestination within navGraph,
173-
fun NavOptionsBuilder.() {
174-
launchSingleTop = true
175-
restoreState = true
176-
}
177-
)
117+
val targetDestination = ViewAllScreenOnArtistDestination(
118+
viewAllType = viewAllType,
119+
artistName = artistName,
120+
baseUrl = baseUrl
121+
)
122+
123+
navController.navigate(targetDestination) {
124+
launchSingleTop = true
178125
}
179126
}
180127

181128
override fun gotoViewAllSearchResultsScreen(
182129
viewAllType: String,
183130
searchParams: String
184131
) {
185-
val currentDestination = navController.currentDestination?.route
186-
val targetDestination =
187-
ViewAllSearchResultsDestination(
188-
searchParams = searchParams,
189-
viewAllType = viewAllType
190-
)
191-
192-
if (currentDestination != targetDestination.route) {
193-
navController.navigate(
194-
targetDestination within navGraph,
195-
fun NavOptionsBuilder.() {
196-
launchSingleTop = true
197-
restoreState = true
198-
}
199-
)
132+
val targetDestination = ViewAllSearchResultsDestination(
133+
searchParams = searchParams,
134+
viewAllType = viewAllType
135+
)
136+
137+
navController.navigate(targetDestination) {
138+
launchSingleTop = true
200139
}
201140
}
202141

203142
override fun gotoSourceFolder(name: String, path: String) {
204-
val currentDestination = navController.currentDestination?.route
205-
val targetDestination =
206-
FoldersAndTracksScreenDestination(gotoFolderName = name, gotoFolderPath = path)
207-
208-
if (currentDestination != targetDestination.route) {
209-
navController.navigate(
210-
targetDestination within navGraph,
211-
fun NavOptionsBuilder.() {
212-
launchSingleTop = true
213-
restoreState = true
214-
}
215-
)
143+
val targetDestination = FoldersAndTracksScreenDestination(name, path)
144+
navController.navigate(targetDestination) {
145+
launchSingleTop = true
216146
}
217147
}
218148
}

0 commit comments

Comments
Β (0)