Skip to content

Commit

Permalink
Remove search button from news screen (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
mars885 authored Aug 4, 2022
1 parent ef87027 commit 395f24c
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 66 deletions.
33 changes: 3 additions & 30 deletions app/src/main/java/com/paulrybitskyi/gamedge/AppNavigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import com.paulrybitskyi.gamedge.feature.info.presentation.GameInfoRoute
import com.paulrybitskyi.gamedge.feature.info.presentation.widgets.main.GameInfo
import com.paulrybitskyi.gamedge.feature.likes.presentation.LikedGames
import com.paulrybitskyi.gamedge.feature.likes.presentation.LikedGamesRoute
import com.paulrybitskyi.gamedge.feature.news.presentation.GamingNewsRoute
import com.paulrybitskyi.gamedge.feature.news.presentation.widgets.GamingNews
import com.paulrybitskyi.gamedge.feature.search.presentation.GamesSearch
import com.paulrybitskyi.gamedge.feature.search.presentation.GamesSearchRoute
Expand All @@ -63,10 +62,7 @@ internal fun AppNavigation(
navController = navController,
modifier = modifier,
)
newsScreen(
navController = navController,
modifier = modifier,
)
newsScreen(modifier = modifier)
settingsScreen(modifier = modifier)
gamesSearchScreen(navController = navController)
gamesCategoryScreen(navController = navController)
Expand Down Expand Up @@ -152,34 +148,11 @@ private fun NavGraphBuilder.likesScreen(
}
}

private fun NavGraphBuilder.newsScreen(
navController: NavHostController,
modifier: Modifier,
) {
private fun NavGraphBuilder.newsScreen(modifier: Modifier) {
composable(
route = Screen.News.route,
enterTransition = { null },
exitTransition = {
when (Screen.forRoute(targetState.destination.requireRoute())) {
Screen.GamesSearch -> OvershootScaling.exit()
else -> null
}
},
popEnterTransition = {
when (Screen.forRoute(initialState.destination.requireRoute())) {
Screen.GamesSearch -> OvershootScaling.popEnter()
else -> null
}
},
popExitTransition = { null },
) {
GamingNews(modifier) { route ->
when (route) {
is GamingNewsRoute.Search -> {
navController.navigate(Screen.GamesSearch.route)
}
}
}
GamingNews(modifier)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@
package com.paulrybitskyi.gamedge.feature.news.presentation

import com.paulrybitskyi.gamedge.common.ui.base.events.Command
import com.paulrybitskyi.gamedge.common.ui.base.events.Route

internal sealed class GamingNewsCommand : Command {
data class OpenUrl(val url: String) : GamingNewsCommand()
}

sealed class GamingNewsRoute : Route {
object Search : GamingNewsRoute()
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ internal class GamingNewsViewModel @Inject constructor(
.launchIn(viewModelScope)
}

fun onSearchButtonClicked() {
route(GamingNewsRoute.Search)
}

fun onNewsItemClicked(model: GamingNewsItemUiModel) {
dispatchCommand(GamingNewsCommand.OpenUrl(model.siteDetailUrl))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.hilt.navigation.compose.hiltViewModel
import com.paulrybitskyi.commons.ktx.showShortToast
import com.paulrybitskyi.gamedge.common.ui.CommandsHandler
import com.paulrybitskyi.gamedge.common.ui.RoutesHandler
import com.paulrybitskyi.gamedge.common.ui.LocalUrlOpener
import com.paulrybitskyi.gamedge.common.ui.NavBarColorHandler
import com.paulrybitskyi.gamedge.common.ui.base.events.Route
import com.paulrybitskyi.gamedge.common.ui.theme.GamedgeTheme
import com.paulrybitskyi.gamedge.common.ui.widgets.AnimatedContentContainer
import com.paulrybitskyi.gamedge.common.ui.widgets.FiniteUiState
Expand All @@ -57,22 +55,17 @@ import com.paulrybitskyi.gamedge.feature.news.R
import com.paulrybitskyi.gamedge.feature.news.presentation.GamingNewsViewModel

@Composable
fun GamingNews(
modifier: Modifier,
onRoute: (Route) -> Unit,
) {
fun GamingNews(modifier: Modifier) {
GamingNews(
viewModel = hiltViewModel(),
modifier = modifier,
onRoute = onRoute,
)
}

@Composable
private fun GamingNews(
viewModel: GamingNewsViewModel,
modifier: Modifier,
onRoute: (Route) -> Unit,
) {
val urlOpener = LocalUrlOpener.current
val context = LocalContext.current
Expand All @@ -87,10 +80,8 @@ private fun GamingNews(
}
}
}
RoutesHandler(viewModel = viewModel, onRoute = onRoute)
GamingNews(
uiState = viewModel.uiState.collectAsState().value,
onSearchButtonClicked = viewModel::onSearchButtonClicked,
onNewsItemClicked = viewModel::onNewsItemClicked,
onRefreshRequested = viewModel::onRefreshRequested,
modifier = modifier,
Expand All @@ -100,7 +91,6 @@ private fun GamingNews(
@Composable
private fun GamingNews(
uiState: GamingNewsUiState,
onSearchButtonClicked: () -> Unit,
onNewsItemClicked: (GamingNewsItemUiModel) -> Unit,
onRefreshRequested: () -> Unit,
modifier: Modifier = Modifier,
Expand All @@ -113,8 +103,6 @@ private fun GamingNews(
contentPadding = WindowInsets.statusBars
.only(WindowInsetsSides.Vertical + WindowInsetsSides.Horizontal)
.asPaddingValues(),
rightButtonIcon = painterResource(R.drawable.magnify),
onRightButtonClick = onSearchButtonClicked,
)
},
) { paddingValues ->
Expand Down Expand Up @@ -227,7 +215,6 @@ private fun GamingNewsSuccessStatePreview() {
uiState = GamingNewsUiState(
news = news,
),
onSearchButtonClicked = {},
onNewsItemClicked = {},
onRefreshRequested = {},
)
Expand All @@ -241,7 +228,6 @@ private fun GamingNewsEmptyStatePreview() {
GamedgeTheme {
GamingNews(
uiState = GamingNewsUiState(),
onSearchButtonClicked = {},
onNewsItemClicked = {},
onRefreshRequested = {},
)
Expand All @@ -255,7 +241,6 @@ private fun GamingNewsLoadingStatePreview() {
GamedgeTheme {
GamingNews(
uiState = GamingNewsUiState(isLoading = true),
onSearchButtonClicked = {},
onNewsItemClicked = {},
onRefreshRequested = {},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,6 @@ internal class GamingNewsViewModelTest {
}
}

@Test
fun `Routes to search screen when search button is clicked`() {
runTest {
SUT.routeFlow.test {
SUT.onSearchButtonClicked()

assertThat(awaitItem()).isInstanceOf(GamingNewsRoute.Search::class.java)
}
}
}

@Test
fun `Dispatches url opening command when clicking on news item`() {
runTest {
Expand Down

0 comments on commit 395f24c

Please sign in to comment.