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