-
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.
Adding Bottom Navigation and reorganizing code
- Loading branch information
1 parent
07b7cf2
commit 8d2e33b
Showing
21 changed files
with
183 additions
and
83 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/debanshu777/compose_github/ui/base/MainScreen.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,43 @@ | ||
package com.debanshu777.compose_github.ui.base | ||
|
||
import androidx.compose.material.Scaffold | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.navigation.compose.rememberNavController | ||
import com.debanshu777.compose_github.network.dataSource.githubViewModel | ||
import com.debanshu777.compose_github.ui.base.components.BottomBar | ||
import com.debanshu777.compose_github.ui.feature_search.components.MainAppBar | ||
import com.debanshu777.compose_github.ui.feature_search.state.SearchState | ||
import com.debanshu777.compose_github.ui.feature_search.state.SearchWidgetState | ||
|
||
@Composable | ||
fun MainScreen(viewModel: githubViewModel){ | ||
val navController = rememberNavController() | ||
val searchWidgetState by viewModel.searchWidgetState | ||
val searchTextState by viewModel.searchTextState | ||
Scaffold( | ||
topBar = { | ||
MainAppBar( | ||
searchWidgetState = searchWidgetState, | ||
searchTextState = searchTextState, | ||
onTextChange = { | ||
viewModel.updateSearchTextState(it) | ||
}, | ||
onCloseClicked = { | ||
viewModel.updateSearchTextState("") | ||
viewModel.updateSearchWidgetState(SearchWidgetState.CLOSED) | ||
viewModel.searchState.value= SearchState(data= emptyList()) | ||
}, | ||
onSearchClick = { | ||
viewModel.searchUser(it) | ||
}, | ||
onSearchTriggered={ | ||
viewModel.updateSearchWidgetState(SearchWidgetState.OPENED) | ||
} | ||
) | ||
}, | ||
bottomBar = { BottomBar(navController = navController)} | ||
) { | ||
Navigation(viewModel,navController) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/debanshu777/compose_github/ui/base/Navigation.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,29 @@ | ||
package com.debanshu777.compose_github.ui.base | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.composable | ||
import com.debanshu777.compose_github.network.dataSource.githubViewModel | ||
import com.debanshu777.compose_github.ui.feature_follow.FollowScreen | ||
import com.debanshu777.compose_github.ui.feature_profile.ProfileScreen | ||
import com.debanshu777.compose_github.ui.feature_search.SearchScreen | ||
import com.debanshu777.compose_github.ui.feature_trending.TrendingScreen | ||
|
||
@Composable | ||
fun Navigation(viewModel: githubViewModel, navController: NavHostController) { | ||
NavHost(navController = navController, startDestination = Screen.TrendingScreen.route) { | ||
composable(route = Screen.SearchScreen.route){ | ||
SearchScreen(viewModel,navController) | ||
} | ||
composable(route = Screen.ProfileScreen.route){ | ||
ProfileScreen(viewModel) | ||
} | ||
composable(route= Screen.TrendingScreen.route){ | ||
TrendingScreen() | ||
} | ||
composable(route = Screen.FollowScreen.route){ | ||
FollowScreen() | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/debanshu777/compose_github/ui/base/Screen.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,12 @@ | ||
package com.debanshu777.compose_github.ui.base | ||
|
||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.* | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
|
||
sealed class Screen(val route:String, val title:String, val icon:ImageVector){ | ||
object SearchScreen: Screen("search_screen","Search", Icons.Default.Search) | ||
object ProfileScreen: Screen("profile_screen","Profile", Icons.Default.Person) | ||
object TrendingScreen: Screen("trending_screen","Trending", Icons.Default.DateRange) | ||
object FollowScreen: Screen("follow_screen","Follow", Icons.Default.Favorite) | ||
} |
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/debanshu777/compose_github/ui/base/components/AddItem.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,39 @@ | ||
package com.debanshu777.compose_github.ui.base.components | ||
|
||
import androidx.compose.foundation.layout.RowScope | ||
import androidx.compose.material.* | ||
import androidx.compose.runtime.Composable | ||
import androidx.navigation.NavDestination | ||
import androidx.navigation.NavDestination.Companion.hierarchy | ||
import androidx.navigation.NavGraph.Companion.findStartDestination | ||
import androidx.navigation.NavHostController | ||
import com.debanshu777.compose_github.ui.base.Screen | ||
|
||
@Composable | ||
fun RowScope.AddItem( | ||
screen: Screen, | ||
currentDestination: NavDestination?, | ||
navController: NavHostController | ||
){ | ||
BottomNavigationItem( | ||
label={ | ||
Text(text = screen.title) | ||
}, | ||
icon = { | ||
Icon( | ||
imageVector = screen.icon, | ||
contentDescription = "Navigation Icon" | ||
) | ||
}, | ||
selected = currentDestination?.hierarchy?.any{ | ||
it.route == screen.route | ||
} == true, | ||
unselectedContentColor = LocalContentColor.current.copy(alpha = ContentAlpha.disabled), | ||
onClick = { | ||
navController.navigate(screen.route){ | ||
popUpTo(navController.graph.findStartDestination().id) | ||
launchSingleTop =true | ||
} | ||
} | ||
) | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/debanshu777/compose_github/ui/base/components/BottomBar.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,23 @@ | ||
package com.debanshu777.compose_github.ui.base.components | ||
|
||
import androidx.compose.material.BottomNavigation | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.currentBackStackEntryAsState | ||
import com.debanshu777.compose_github.ui.base.Screen | ||
|
||
@Composable | ||
fun BottomBar(navController: NavHostController){ | ||
val screens = listOf( | ||
Screen.TrendingScreen, | ||
Screen.FollowScreen | ||
) | ||
val navBackStackEntry by navController.currentBackStackEntryAsState() | ||
val currentDestination=navBackStackEntry?.destination | ||
BottomNavigation { | ||
screens.forEach{ screen -> | ||
AddItem(screen = screen, currentDestination = currentDestination, navController = navController) | ||
} | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...ui/feature_search/components/SearchBar.kt → ...se_github/ui/base/components/SearchBar.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
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/debanshu777/compose_github/ui/feature_follow/FollowScreen.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,9 @@ | ||
package com.debanshu777.compose_github.ui.feature_follow | ||
|
||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
|
||
@Composable | ||
fun FollowScreen(){ | ||
Text("Follow Screen") | ||
} |
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
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/debanshu777/compose_github/ui/feature_trending/TrendingScreen.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,9 @@ | ||
package com.debanshu777.compose_github.ui.feature_trending | ||
|
||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
|
||
@Composable | ||
fun TrendingScreen() { | ||
Text("Trending Screen") | ||
} |
22 changes: 0 additions & 22 deletions
22
app/src/main/java/com/debanshu777/compose_github/ui/navigation/Navigation.kt
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
app/src/main/java/com/debanshu777/compose_github/ui/navigation/Screen.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