Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search fix #48

Merged
merged 2 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions app/src/main/java/st/slex/csplashscreen/ui/InitialApp.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package st.slex.csplashscreen.ui

import android.annotation.SuppressLint
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.systemBarsPadding
Expand All @@ -17,10 +22,11 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import org.koin.androidx.compose.koinViewModel
import st.slex.csplashscreen.core.navigation.AppDestination
import st.slex.csplashscreen.navigation.NavigationHost
import st.slex.csplashscreen.ui.components.bottom_appbar.BottomAppBarResource
import st.slex.csplashscreen.ui.components.bottom_appbar.MainBottomAppBar
import org.koin.androidx.compose.koinViewModel

@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@Composable
Expand Down Expand Up @@ -51,17 +57,25 @@ fun InitialApp(
Scaffold(
modifier = modifier,
contentColor = MaterialTheme.colorScheme.onBackground,
containerColor = Color.Transparent,
containerColor = MaterialTheme.colorScheme.background,
bottomBar = {
MainBottomAppBar(
onBottomAppBarClick = viewModel::navigate,
currentDestination = currentDestination
)
AnimatedVisibility(
visible = BottomAppBarResource.isAppbar(currentDestination),
enter = slideInVertically(tween(300)) { it },
exit = slideOutVertically(tween(300)) { it }
) {
MainBottomAppBar(
onBottomAppBarClick = viewModel::navigate,
currentDestination = currentDestination
)
}
},
contentWindowInsets = WindowInsets(0.dp),
content = {
NavigationHost(
modifier = Modifier.systemBarsPadding(),
modifier = Modifier
.background(MaterialTheme.colorScheme.background)
.systemBarsPadding(),
navController = navController,
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,22 @@ fun MainBottomAppBar(
onBottomAppBarClick(item.screen)
},
icon = {
val icon = if (isSelected) {
item.selectedIcon
} else {
item.unselectedIcon
}
Icon(icon, item.appDestination.route)
Icon(
imageVector = if (isSelected) {
item.selectedIcon
} else {
item.unselectedIcon
},
contentDescription = item.appDestination.name
)
},
label = {
Text(
text = stringResource(id = item.titleResource)
)
},
label = { Text(text = stringResource(id = item.titleResource)) },
alwaysShowLabel = false
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import st.slex.csplashscreen.R
import st.slex.csplashscreen.core.navigation.AppDestination
import st.slex.csplashscreen.core.navigation.NavigationScreen

@Suppress("UNUSED")
enum class BottomAppBarResource(
val unselectedIcon: ImageVector,
val selectedIcon: ImageVector,
Expand Down Expand Up @@ -40,5 +39,12 @@ enum class BottomAppBarResource(
appDestination = AppDestination.SEARCH_PHOTOS,
titleResource = R.string.nav_title_search,
screen = NavigationScreen.SearchPhotosScreen(query = " ")
)
);

companion object {

fun isAppbar(
appDestination: AppDestination?
): Boolean = entries.any { it.appDestination == appDestination }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ enum class AppDestination(vararg val argsNames: String) {
}

companion object {

private const val SEPARATOR_ROUTE = "_"
private const val TAG_ROUTE = "route"

fun findByRoute(route: String?) = AppDestination
.entries
.firstOrNull {
it.route == route
}
fun findByRoute(route: String?) = if (route == null) {
UNDEFINED
} else {
AppDestination
.entries
.firstOrNull { destination ->
destination.navigationRoute == route
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.paging.LoadState
import androidx.paging.compose.LazyPagingItems
import kotlinx.coroutines.flow.StateFlow
import st.slex.csplashscreen.core.photos.ui.component.LazyListPhotos
import st.slex.csplashscreen.core.photos.ui.model.PhotoModel
import st.slex.csplashscreen.feature.search.ui.components.TopAppBarSearch
import st.slex.csplashscreen.feature.search.ui.components.history.LazyListHistorySearch
import st.slex.csplashscreen.feature.search.ui.model.SearchItem
import st.slex.csplashscreen.feature.search.ui.utils.UiExt.isNotLoading
import kotlinx.coroutines.flow.StateFlow

@Composable
fun SearchPhotosScreen(
Expand All @@ -39,22 +39,23 @@ fun SearchPhotosScreen(
search = onQuery
)

if (photos.loadState.isNotLoading) {
if (photos.itemCount == 0) {
LazyListHistorySearch(
modifier = Modifier.weight(1f),
items = searchHistory,
onSearchClick = remember { onQuery },
clearHistory = clearHistory
)
} else {
LazyListPhotos(
modifier = Modifier.weight(1f),
items = photos,
onUserClick = onUserClick,
onImageClick = onImageClick,
)
}
if (
photos.loadState.refresh is LoadState.NotLoading &&
photos.itemCount == 0
) {
LazyListHistorySearch(
modifier = Modifier.weight(1f),
items = searchHistory,
onSearchClick = remember { onQuery },
clearHistory = clearHistory
)
} else {
LazyListPhotos(
modifier = Modifier.weight(1f),
items = photos,
onUserClick = onUserClick,
onImageClick = onImageClick,
)
}
}
}