update search screen logic
This commit is contained in:
@@ -7,7 +7,7 @@ plugins {
|
||||
alias(libs.plugins.convention.ktor.client)
|
||||
}
|
||||
|
||||
val appVersion = "1.26.6"
|
||||
val appVersion = "1.26.7"
|
||||
|
||||
android {
|
||||
buildFeatures { buildConfig = true }
|
||||
|
||||
+4
-2
@@ -21,7 +21,8 @@ fun AppBarWithSearchPreview() {
|
||||
AppBarWithSearch(
|
||||
title = "TitleWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
|
||||
isDefault = false,
|
||||
onBack = {}
|
||||
onBack = {},
|
||||
onEdit = {}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -30,7 +31,8 @@ fun AppBarWithSearchPreview() {
|
||||
fun AppBarWithSearchWithBackPreview() {
|
||||
AppBarWithSearch(
|
||||
title = "TitleWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
|
||||
onBack = {}
|
||||
onBack = {},
|
||||
onEdit = {}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -69,7 +69,8 @@ fun VideoScreen(component: VideoScreenComponent) {
|
||||
AppBarWithSearch(
|
||||
title,
|
||||
isDefault = title == appName,
|
||||
onBack = { component.doBack() }
|
||||
onBack = { component.doBack() },
|
||||
onEdit = { component.doEdit() }
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
+4
-2
@@ -26,7 +26,8 @@ class VideoScreenComponent(
|
||||
private val dispatcherProvider: DispatcherProvider,
|
||||
val search: String? = null,
|
||||
val showOverview: (Long) -> Unit,
|
||||
val doBack: () -> Unit
|
||||
val doBack: () -> Unit,
|
||||
val doEdit: () -> Unit
|
||||
) : ComponentContext by context {
|
||||
private val componentScope = createComponentScope()
|
||||
private val _items = MutableStateFlow<List<VideoItem>?>(null)
|
||||
@@ -65,7 +66,8 @@ class VideosChildFactory(
|
||||
dispatcherProvider,
|
||||
route.request,
|
||||
showOverview = { root.nav(Route.Overview(it)) },
|
||||
doBack = { root.onBack() }
|
||||
doBack = { root.onBack() },
|
||||
doEdit = { root.navReplace(Route.SearchVideos(route.request)) }
|
||||
)
|
||||
return Child.VideosChild(comp)
|
||||
}
|
||||
|
||||
+4
-1
@@ -13,7 +13,10 @@ sealed class Route : ru.shadowsparky.ui.nav.Route() {
|
||||
) : Route()
|
||||
|
||||
@Serializable
|
||||
data class SearchVideos(override val routeId: String = RouteIds.SEARCH) : Route()
|
||||
data class SearchVideos(
|
||||
val request: String? = null,
|
||||
override val routeId: String = RouteIds.SEARCH
|
||||
) : Route()
|
||||
|
||||
@Serializable
|
||||
data class Bookmark(override val routeId: String = RouteIds.BOOKMARK) : Route()
|
||||
|
||||
+8
-9
@@ -63,6 +63,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import org.jetbrains.compose.resources.painterResource
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
import ru.shadowsparky.ui.components.AppBarWithSearch
|
||||
import ru.shadowsparky.ui.components.BackButton
|
||||
import ru.shadowsparky.ui.components.ExpressiveLazyColumn
|
||||
import ru.shadowsparky.ui.components.IconButton
|
||||
import ru.shadowsparky.vbox.shared.presentation.MainScreenScaffold
|
||||
@@ -77,7 +78,8 @@ fun SearchScreen(
|
||||
) {
|
||||
val requester by remember { mutableStateOf(FocusRequester()) }
|
||||
var textFieldValue by rememberSaveable(stateSaver = TextFieldValue.Saver) {
|
||||
mutableStateOf(TextFieldValue())
|
||||
val text = component.defaultRequest
|
||||
mutableStateOf(TextFieldValue(text, TextRange(text.length)))
|
||||
}
|
||||
MainScreenScaffold(
|
||||
appBar = {
|
||||
@@ -272,7 +274,8 @@ fun AppBarWithSearch(
|
||||
title: String,
|
||||
isDefault: Boolean = false,
|
||||
actions: @Composable RowScope.() -> Unit = {},
|
||||
onBack: (() -> Unit)
|
||||
onBack: (() -> Unit),
|
||||
onEdit: (() -> Unit)
|
||||
) {
|
||||
AppBarWithSearch(
|
||||
actions = { actions(this) },
|
||||
@@ -281,16 +284,12 @@ fun AppBarWithSearch(
|
||||
Surface(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable(enabled = !isDefault) { onBack() },
|
||||
.clickable(enabled = !isDefault) { onEdit() },
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
color = Color.Transparent
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 14.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Row(modifier = Modifier, verticalAlignment = Alignment.CenterVertically) {
|
||||
BackButton { onBack() }
|
||||
Text(text = title, maxLines = 1)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -18,6 +18,7 @@ class SearchScreenComponent(
|
||||
val search: (String) -> Unit,
|
||||
val doBack: () -> Unit,
|
||||
private val searchRepository: SearchRepository,
|
||||
val defaultRequest: String
|
||||
) : ComponentContext by context {
|
||||
val info = searchRepository.search("").map { it.reversed() }
|
||||
private val componentScope = createComponentScope()
|
||||
@@ -50,7 +51,8 @@ class SearchScreenFactory(
|
||||
child,
|
||||
search = { root.nav(Route.Videos(it)) },
|
||||
doBack = { root.onBack() },
|
||||
searchRepository
|
||||
searchRepository,
|
||||
route.request.orEmpty()
|
||||
)
|
||||
return Child.SearchChild(comp)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user