Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ba7d4aae4 |
No files matched your search
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Nextcloud Talk - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2026 Marcel Hibbe <[email protected]>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.components
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.text.input.rememberTextFieldState
|
||||
import androidx.compose.foundation.text.input.setTextAndPlaceCursorAtEnd
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.ProvideTextStyle
|
||||
import androidx.compose.material3.SearchBarDefaults
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.material3.rememberSearchBarState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.nextcloud.talk.R
|
||||
import kotlinx.coroutines.flow.drop
|
||||
|
||||
/**
|
||||
* Search input meant for the title slot of a TopAppBar while search is active. [initialQuery] only sets the text the
|
||||
* field starts with; afterwards the field owns its text and reports edits through [onQueryChange]. It takes focus when
|
||||
* shown, hides the soft keyboard when removed, and both its back button and the system back gesture call
|
||||
* [onSearchDismiss].
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun AppBarSearchField(
|
||||
initialQuery: String,
|
||||
onQueryChange: (String) -> Unit,
|
||||
onSearchDismiss: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val searchBarState = rememberSearchBarState()
|
||||
val textFieldState = rememberTextFieldState(initialQuery)
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
val keyboardController = LocalSoftwareKeyboardController.current
|
||||
val currentOnQueryChange by rememberUpdatedState(onQueryChange)
|
||||
|
||||
BackHandler(onBack = onSearchDismiss)
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
focusRequester.requestFocus()
|
||||
}
|
||||
|
||||
DisposableEffect(Unit) {
|
||||
onDispose { keyboardController?.hide() }
|
||||
}
|
||||
|
||||
LaunchedEffect(textFieldState) {
|
||||
snapshotFlow { textFieldState.text.toString() }
|
||||
.drop(1)
|
||||
.collect { currentOnQueryChange(it) }
|
||||
}
|
||||
|
||||
// The TopAppBar title slot provides a title text style, which is too large for an input field.
|
||||
ProvideTextStyle(MaterialTheme.typography.bodyLarge) {
|
||||
// A Surface instead of SearchBar: the collapsed SearchBar blocks the soft keyboard, as typing is meant to
|
||||
// happen in an expanded search bar, which is not used here.
|
||||
Surface(
|
||||
shape = SearchBarDefaults.inputFieldShape,
|
||||
color = SearchBarDefaults.colors().containerColor,
|
||||
modifier = modifier.fillMaxWidth()
|
||||
) {
|
||||
SearchBarDefaults.InputField(
|
||||
textFieldState = textFieldState,
|
||||
searchBarState = searchBarState,
|
||||
onSearch = { keyboardController?.hide() },
|
||||
placeholder = { Text(stringResource(R.string.nc_search)) },
|
||||
leadingIcon = {
|
||||
IconButton(onClick = onSearchDismiss) {
|
||||
Icon(
|
||||
imageVector = ImageVector.vectorResource(R.drawable.ic_chevron_backward_24px),
|
||||
contentDescription = stringResource(R.string.back_button)
|
||||
)
|
||||
}
|
||||
},
|
||||
trailingIcon = {
|
||||
if (textFieldState.text.isNotEmpty()) {
|
||||
IconButton(onClick = { textFieldState.setTextAndPlaceCursorAtEnd("") }) {
|
||||
Icon(
|
||||
imageVector = ImageVector.vectorResource(R.drawable.ic_close_search),
|
||||
contentDescription = stringResource(R.string.nc_search_clear)
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier.focusRequester(focusRequester)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(name = "Light", showBackground = true)
|
||||
@Preview(name = "Dark", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
@Preview(name = "RTL – Arabic", showBackground = true, locale = "ar")
|
||||
@Composable
|
||||
private fun PreviewAppBarSearchField() {
|
||||
val colorScheme = if (isSystemInDarkTheme()) darkColorScheme() else lightColorScheme()
|
||||
MaterialTheme(colorScheme = colorScheme) {
|
||||
Surface {
|
||||
AppBarSearchField(
|
||||
initialQuery = "design",
|
||||
onQueryChange = {},
|
||||
onSearchDismiss = {},
|
||||
modifier = Modifier.padding(16.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Talk - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2025 Marcel Hibbe <[email protected]>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.components
|
||||
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
|
||||
@Composable
|
||||
fun VerticallyCenteredRow(content: @Composable RowScope.() -> Unit) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxHeight(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
@@ -22,8 +22,9 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.contacts.components.ContactsAppBar
|
||||
import com.nextcloud.talk.contacts.components.ContactsAppBarListenerInput
|
||||
import com.nextcloud.talk.contacts.components.ContactsAppBarState
|
||||
import com.nextcloud.talk.contacts.components.ContactsList
|
||||
import com.nextcloud.talk.contacts.components.ContactsSearchAppBar
|
||||
import com.nextcloud.talk.contacts.components.ConversationCreationOptions
|
||||
|
||||
@Composable
|
||||
@@ -39,10 +40,17 @@ fun ContactsScreen(contactsViewModel: ContactsViewModel, uiState: ContactsViewMo
|
||||
.statusBarsPadding()
|
||||
.displayCutoutPadding(),
|
||||
topBar = {
|
||||
if (isSearchActive) {
|
||||
ContactsSearchAppBar(
|
||||
ContactsAppBar(
|
||||
state = ContactsAppBarState(
|
||||
isAddParticipants = isAddParticipants,
|
||||
isSearchActive = isSearchActive,
|
||||
searchQuery = searchQuery,
|
||||
onTextChange = {
|
||||
enableAddButton = enableAddButton
|
||||
),
|
||||
autocompleteUsers = autocompleteUsers,
|
||||
listenerInput = ContactsAppBarListenerInput(
|
||||
onStartSearch = { contactsViewModel.setSearchActive(true) },
|
||||
onSearchQueryChange = {
|
||||
contactsViewModel.updateSearchQuery(it)
|
||||
contactsViewModel.getContactsFromSearchParams()
|
||||
},
|
||||
@@ -51,17 +59,9 @@ fun ContactsScreen(contactsViewModel: ContactsViewModel, uiState: ContactsViewMo
|
||||
contactsViewModel.setSearchActive(false)
|
||||
contactsViewModel.getContactsFromSearchParams()
|
||||
},
|
||||
enableAddButton = enableAddButton,
|
||||
isAddParticipants = isAddParticipants,
|
||||
clickAddButton = { contactsViewModel.modifyClickAddButton(true) }
|
||||
onAddSelected = { contactsViewModel.modifyClickAddButton(true) }
|
||||
)
|
||||
} else {
|
||||
ContactsAppBar(
|
||||
isAddParticipants = isAddParticipants,
|
||||
autocompleteUsers = autocompleteUsers,
|
||||
onStartSearch = { contactsViewModel.setSearchActive(true) }
|
||||
)
|
||||
}
|
||||
)
|
||||
},
|
||||
content = { paddingValues ->
|
||||
Column(
|
||||
|
||||
@@ -10,15 +10,16 @@ package com.nextcloud.talk.contacts.components
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import androidx.compose.foundation.clickable
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
@@ -28,85 +29,195 @@ import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.components.VerticallyCenteredRow
|
||||
import com.nextcloud.talk.components.AppBarSearchField
|
||||
import com.nextcloud.talk.models.json.autocomplete.AutocompleteUserDto
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ContactsAppBar(
|
||||
isAddParticipants: Boolean,
|
||||
state: ContactsAppBarState,
|
||||
autocompleteUsers: List<AutocompleteUserDto>,
|
||||
onStartSearch: () -> Unit
|
||||
listenerInput: ContactsAppBarListenerInput
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
TopAppBar(
|
||||
modifier = Modifier
|
||||
.height(60.dp),
|
||||
title = {
|
||||
VerticallyCenteredRow {
|
||||
Text(
|
||||
text = if (isAddParticipants) {
|
||||
stringResource(R.string.nc_participants_add)
|
||||
} else {
|
||||
stringResource(R.string.nc_new_conversation)
|
||||
}
|
||||
)
|
||||
}
|
||||
},
|
||||
navigationIcon = {
|
||||
VerticallyCenteredRow {
|
||||
if (!state.isSearchActive) {
|
||||
IconButton(onClick = { (context as? Activity)?.finish() }) {
|
||||
Icon(
|
||||
ImageVector.vectorResource(R.drawable.ic_arrow_back_black_24dp),
|
||||
imageVector = ImageVector.vectorResource(R.drawable.ic_arrow_back_black_24dp),
|
||||
contentDescription = stringResource(R.string.back_button)
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
VerticallyCenteredRow {
|
||||
IconButton(onClick = onStartSearch) {
|
||||
Icon(
|
||||
ImageVector.vectorResource(R.drawable.ic_search_grey),
|
||||
contentDescription = stringResource(R.string.search_icon)
|
||||
)
|
||||
}
|
||||
if (isAddParticipants) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.nc_contacts_done),
|
||||
modifier = Modifier.clickable {
|
||||
val resultIntent = Intent().apply {
|
||||
putParcelableArrayListExtra("selectedParticipants", ArrayList(autocompleteUsers))
|
||||
}
|
||||
(context as? Activity)?.setResult(Activity.RESULT_OK, resultIntent)
|
||||
(context as? Activity)?.finish()
|
||||
}
|
||||
)
|
||||
}
|
||||
title = {
|
||||
if (state.isSearchActive) {
|
||||
AppBarSearchField(
|
||||
initialQuery = state.searchQuery,
|
||||
onQueryChange = listenerInput.onSearchQueryChange,
|
||||
onSearchDismiss = listenerInput.onCloseSearch,
|
||||
modifier = Modifier.padding(end = if (state.isAddParticipants) 0.dp else 16.dp)
|
||||
)
|
||||
} else {
|
||||
Text(
|
||||
text = if (state.isAddParticipants) {
|
||||
stringResource(R.string.nc_participants_add)
|
||||
} else {
|
||||
stringResource(R.string.nc_new_conversation)
|
||||
},
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
ContactsAppBarActions(
|
||||
state = state,
|
||||
autocompleteUsers = autocompleteUsers,
|
||||
listenerInput = listenerInput
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Preview(name = "Light Mode")
|
||||
@Preview(
|
||||
name = "Dark Mode",
|
||||
uiMode = android.content.res.Configuration.UI_MODE_NIGHT_YES
|
||||
)
|
||||
@Preview(name = "RTL / Arabic", locale = "ar")
|
||||
@Composable
|
||||
fun ContactsAppBarNewConversationPreview() {
|
||||
private fun ContactsAppBarActions(
|
||||
state: ContactsAppBarState,
|
||||
autocompleteUsers: List<AutocompleteUserDto>,
|
||||
listenerInput: ContactsAppBarListenerInput
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
if (state.isSearchActive) {
|
||||
if (state.isAddParticipants) {
|
||||
TextButton(
|
||||
onClick = {
|
||||
listenerInput.onCloseSearch()
|
||||
listenerInput.onAddSelected()
|
||||
},
|
||||
enabled = state.enableAddButton
|
||||
) {
|
||||
Text(text = stringResource(R.string.add_participants))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
IconButton(onClick = listenerInput.onStartSearch) {
|
||||
Icon(
|
||||
imageVector = ImageVector.vectorResource(R.drawable.ic_search_white_24dp),
|
||||
contentDescription = stringResource(R.string.search_icon)
|
||||
)
|
||||
}
|
||||
if (state.isAddParticipants) {
|
||||
TextButton(
|
||||
onClick = {
|
||||
val resultIntent = Intent().apply {
|
||||
putParcelableArrayListExtra("selectedParticipants", ArrayList(autocompleteUsers))
|
||||
}
|
||||
(context as? Activity)?.setResult(Activity.RESULT_OK, resultIntent)
|
||||
(context as? Activity)?.finish()
|
||||
}
|
||||
) {
|
||||
Text(text = stringResource(R.string.nc_contacts_done))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class ContactsAppBarState(
|
||||
val isAddParticipants: Boolean,
|
||||
val isSearchActive: Boolean,
|
||||
val searchQuery: String,
|
||||
val enableAddButton: Boolean
|
||||
)
|
||||
|
||||
class ContactsAppBarListenerInput(
|
||||
val onStartSearch: () -> Unit,
|
||||
val onSearchQueryChange: (String) -> Unit,
|
||||
val onCloseSearch: () -> Unit,
|
||||
val onAddSelected: () -> Unit
|
||||
)
|
||||
|
||||
private val previewListenerInput = ContactsAppBarListenerInput(
|
||||
onStartSearch = {},
|
||||
onSearchQueryChange = {},
|
||||
onCloseSearch = {},
|
||||
onAddSelected = {}
|
||||
)
|
||||
|
||||
@Composable
|
||||
private fun ContactsAppBarPreview(state: ContactsAppBarState) {
|
||||
val colorScheme = if (isSystemInDarkTheme()) darkColorScheme() else lightColorScheme()
|
||||
MaterialTheme(colorScheme = colorScheme) {
|
||||
Surface {
|
||||
ContactsAppBar(
|
||||
isAddParticipants = false,
|
||||
state = state,
|
||||
autocompleteUsers = emptyList(),
|
||||
onStartSearch = {}
|
||||
listenerInput = previewListenerInput
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(name = "Light Mode")
|
||||
@Preview(name = "Dark Mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
@Preview(name = "RTL / Arabic", locale = "ar")
|
||||
@Composable
|
||||
private fun ContactsAppBarNewConversationPreview() {
|
||||
ContactsAppBarPreview(
|
||||
ContactsAppBarState(
|
||||
isAddParticipants = false,
|
||||
isSearchActive = false,
|
||||
searchQuery = "",
|
||||
enableAddButton = false
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Preview(name = "Light Mode")
|
||||
@Preview(name = "Dark Mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
@Preview(name = "RTL / Arabic", locale = "ar")
|
||||
@Composable
|
||||
private fun ContactsAppBarAddParticipantsPreview() {
|
||||
ContactsAppBarPreview(
|
||||
ContactsAppBarState(
|
||||
isAddParticipants = true,
|
||||
isSearchActive = false,
|
||||
searchQuery = "",
|
||||
enableAddButton = false
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Preview(name = "Light Mode")
|
||||
@Preview(name = "Dark Mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
@Preview(name = "RTL / Arabic", locale = "ar")
|
||||
@Composable
|
||||
private fun ContactsAppBarSearchPreview() {
|
||||
ContactsAppBarPreview(
|
||||
ContactsAppBarState(
|
||||
isAddParticipants = false,
|
||||
isSearchActive = true,
|
||||
searchQuery = "Alice",
|
||||
enableAddButton = false
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Preview(name = "Light Mode")
|
||||
@Preview(name = "Dark Mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
@Preview(name = "RTL / Arabic", locale = "ar")
|
||||
@Composable
|
||||
private fun ContactsAppBarSearchAddParticipantsPreview() {
|
||||
ContactsAppBarPreview(
|
||||
ContactsAppBarState(
|
||||
isAddParticipants = true,
|
||||
isSearchActive = true,
|
||||
searchQuery = "Alice",
|
||||
enableAddButton = true
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -1,163 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Talk - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2024 Sowjanya Kota <[email protected]>
|
||||
* SPDX-FileCopyrightText: 2025 Marcel Hibbe <[email protected]>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.contacts.components
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.material3.TextFieldDefaults
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.platform.SoftwareKeyboardController
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.components.VerticallyCenteredRow
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ContactsSearchAppBar(
|
||||
searchQuery: String,
|
||||
onTextChange: (String) -> Unit,
|
||||
onCloseSearch: () -> Unit,
|
||||
enableAddButton: Boolean,
|
||||
isAddParticipants: Boolean,
|
||||
clickAddButton: (Boolean) -> Unit
|
||||
) {
|
||||
val keyboardController = LocalSoftwareKeyboardController.current
|
||||
|
||||
Surface(
|
||||
modifier = Modifier.height(60.dp)
|
||||
) {
|
||||
VerticallyCenteredRow {
|
||||
IconButton(
|
||||
modifier = Modifier.padding(start = 4.dp),
|
||||
onClick = onCloseSearch
|
||||
) {
|
||||
Icon(
|
||||
imageVector = ImageVector.vectorResource(R.drawable.ic_arrow_back_black_24dp),
|
||||
contentDescription = stringResource(R.string.back_button)
|
||||
)
|
||||
}
|
||||
|
||||
TextField(
|
||||
value = searchQuery,
|
||||
onValueChange = onTextChange,
|
||||
placeholder = { Text(text = stringResource(R.string.nc_search)) },
|
||||
singleLine = true,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(horizontal = 8.dp),
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
|
||||
keyboardActions = searchKeyboardActions(searchQuery, keyboardController),
|
||||
colors = searchTextFieldColors(),
|
||||
trailingIcon = {
|
||||
if (searchQuery.isNotEmpty()) {
|
||||
IconButton(onClick = { onTextChange("") }) {
|
||||
Icon(
|
||||
imageVector = ImageVector.vectorResource(R.drawable.ic_close_search),
|
||||
contentDescription = stringResource(R.string.nc_search_clear)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
if (isAddParticipants) {
|
||||
TextButton(
|
||||
onClick = {
|
||||
onCloseSearch()
|
||||
clickAddButton(true)
|
||||
},
|
||||
enabled = enableAddButton
|
||||
) {
|
||||
Text(text = stringResource(R.string.add_participants))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun searchTextFieldColors() =
|
||||
TextFieldDefaults.colors(
|
||||
focusedIndicatorColor = Color.Transparent,
|
||||
unfocusedIndicatorColor = Color.Transparent,
|
||||
disabledIndicatorColor = Color.Transparent
|
||||
)
|
||||
|
||||
fun searchKeyboardActions(text: String, keyboardController: SoftwareKeyboardController?) =
|
||||
KeyboardActions(
|
||||
onSearch = {
|
||||
if (text.trim().isNotEmpty()) {
|
||||
keyboardController?.hide()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@Preview(name = "Light Mode")
|
||||
@Preview(
|
||||
name = "Dark Mode",
|
||||
uiMode = android.content.res.Configuration.UI_MODE_NIGHT_YES
|
||||
)
|
||||
@Preview(name = "RTL / Arabic", locale = "ar")
|
||||
@Composable
|
||||
fun ContactsSearchAppBarPreview() {
|
||||
val colorScheme = if (isSystemInDarkTheme()) darkColorScheme() else lightColorScheme()
|
||||
MaterialTheme(colorScheme = colorScheme) {
|
||||
ContactsSearchAppBar(
|
||||
searchQuery = "Alice",
|
||||
onTextChange = {},
|
||||
onCloseSearch = {},
|
||||
enableAddButton = false,
|
||||
isAddParticipants = false,
|
||||
clickAddButton = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(name = "Light Mode")
|
||||
@Preview(
|
||||
name = "Dark Mode",
|
||||
uiMode = android.content.res.Configuration.UI_MODE_NIGHT_YES
|
||||
)
|
||||
@Preview(name = "RTL / Arabic", locale = "ar")
|
||||
@Composable
|
||||
fun ContactsSearchAppBarAddParticipantsPreview() {
|
||||
val colorScheme = if (isSystemInDarkTheme()) darkColorScheme() else lightColorScheme()
|
||||
MaterialTheme(colorScheme = colorScheme) {
|
||||
ContactsSearchAppBar(
|
||||
searchQuery = "Alice",
|
||||
onTextChange = {},
|
||||
onCloseSearch = {},
|
||||
enableAddButton = true,
|
||||
isAddParticipants = true,
|
||||
clickAddButton = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -32,17 +32,12 @@ import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.text.input.TextFieldState
|
||||
import androidx.compose.foundation.text.input.rememberTextFieldState
|
||||
import androidx.compose.foundation.text.input.setTextAndPlaceCursorAtEnd
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SearchBarDefaults
|
||||
import androidx.compose.material3.SearchBarState
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.Surface
|
||||
@@ -50,7 +45,6 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.material3.rememberSearchBarState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -58,15 +52,11 @@ import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.res.colorResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
@@ -83,12 +73,12 @@ import coil.request.ImageRequest
|
||||
import coil.transform.CircleCropTransformation
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||
import com.nextcloud.talk.components.AppBarSearchField
|
||||
import com.nextcloud.talk.models.json.conversations.ConversationDto
|
||||
import com.nextcloud.talk.models.json.conversations.ConversationEnums
|
||||
import com.nextcloud.talk.openconversations.viewmodels.OpenConversationsViewModel
|
||||
import com.nextcloud.talk.utils.ApiUtils
|
||||
import com.nextcloud.talk.utils.DisplayUtils
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import com.nextcloud.talk.ui.withAuthHeader
|
||||
import com.nextcloud.talk.ui.LocalImageAuthHeader
|
||||
|
||||
@@ -130,12 +120,6 @@ private fun OpenConversationsScreenContent(
|
||||
listenerInput: OpenConversationsScreenListenerInput
|
||||
) {
|
||||
var isSearchActive by rememberSaveable { mutableStateOf(false) }
|
||||
val keyboardController = LocalSoftwareKeyboardController.current
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
|
||||
LaunchedEffect(isSearchActive) {
|
||||
if (isSearchActive) focusRequester.requestFocus()
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
snackbarHost = { SnackbarHost(snackbarHostState, modifier = Modifier.navigationBarsPadding()) },
|
||||
@@ -144,14 +128,12 @@ private fun OpenConversationsScreenContent(
|
||||
OpenConversationsTopBar(
|
||||
isSearchActive = isSearchActive,
|
||||
searchTerm = searchTerm,
|
||||
focusRequester = focusRequester,
|
||||
listenerInput = OpenConversationsTopBarListenerInput(
|
||||
onSearchTermChange = listenerInput.onSearchTermChange,
|
||||
onSearchActivate = { isSearchActive = true },
|
||||
onSearchDismiss = {
|
||||
isSearchActive = false
|
||||
listenerInput.onSearchTermChange("")
|
||||
keyboardController?.hide()
|
||||
},
|
||||
onBackClick = listenerInput.onBackClick
|
||||
)
|
||||
@@ -175,25 +157,8 @@ private fun OpenConversationsScreenContent(
|
||||
private fun OpenConversationsTopBar(
|
||||
isSearchActive: Boolean,
|
||||
searchTerm: String,
|
||||
focusRequester: FocusRequester,
|
||||
listenerInput: OpenConversationsTopBarListenerInput
|
||||
) {
|
||||
val searchBarState = rememberSearchBarState()
|
||||
val textFieldState = rememberTextFieldState()
|
||||
val keyboardController = LocalSoftwareKeyboardController.current
|
||||
|
||||
LaunchedEffect(textFieldState) {
|
||||
snapshotFlow { textFieldState.text.toString() }
|
||||
.distinctUntilChanged()
|
||||
.collect { listenerInput.onSearchTermChange(it) }
|
||||
}
|
||||
|
||||
LaunchedEffect(searchTerm) {
|
||||
if (searchTerm != textFieldState.text.toString()) {
|
||||
textFieldState.setTextAndPlaceCursorAtEnd(searchTerm)
|
||||
}
|
||||
}
|
||||
|
||||
TopAppBar(
|
||||
navigationIcon = {
|
||||
if (!isSearchActive) {
|
||||
@@ -207,12 +172,11 @@ private fun OpenConversationsTopBar(
|
||||
},
|
||||
title = {
|
||||
if (isSearchActive) {
|
||||
OpenConversationsSearchBar(
|
||||
searchBarState = searchBarState,
|
||||
textFieldState = textFieldState,
|
||||
focusRequester = focusRequester,
|
||||
AppBarSearchField(
|
||||
initialQuery = searchTerm,
|
||||
onQueryChange = listenerInput.onSearchTermChange,
|
||||
onSearchDismiss = listenerInput.onSearchDismiss,
|
||||
onSearch = { keyboardController?.hide() }
|
||||
modifier = Modifier.padding(end = 16.dp)
|
||||
)
|
||||
} else {
|
||||
Text(text = stringResource(R.string.openConversations))
|
||||
@@ -231,52 +195,6 @@ private fun OpenConversationsTopBar(
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun OpenConversationsSearchBar(
|
||||
searchBarState: SearchBarState,
|
||||
textFieldState: TextFieldState,
|
||||
focusRequester: FocusRequester,
|
||||
onSearchDismiss: () -> Unit,
|
||||
onSearch: () -> Unit
|
||||
) {
|
||||
// A Surface instead of SearchBar: the collapsed SearchBar blocks the soft keyboard, as typing is meant to happen in
|
||||
// an expanded search bar, which this screen does not use.
|
||||
Surface(
|
||||
shape = SearchBarDefaults.inputFieldShape,
|
||||
color = SearchBarDefaults.colors().containerColor,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(end = 16.dp)
|
||||
) {
|
||||
SearchBarDefaults.InputField(
|
||||
textFieldState = textFieldState,
|
||||
searchBarState = searchBarState,
|
||||
onSearch = { onSearch() },
|
||||
placeholder = { Text(stringResource(R.string.nc_search)) },
|
||||
leadingIcon = {
|
||||
IconButton(onClick = onSearchDismiss) {
|
||||
Icon(
|
||||
imageVector = ImageVector.vectorResource(R.drawable.ic_chevron_backward_24px),
|
||||
contentDescription = stringResource(R.string.back_button)
|
||||
)
|
||||
}
|
||||
},
|
||||
trailingIcon = {
|
||||
if (textFieldState.text.isNotEmpty()) {
|
||||
IconButton(onClick = { textFieldState.setTextAndPlaceCursorAtEnd("") }) {
|
||||
Icon(
|
||||
imageVector = ImageVector.vectorResource(R.drawable.ic_close_search),
|
||||
contentDescription = stringResource(R.string.nc_search_clear)
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier.focusRequester(focusRequester)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ConversationsBody(
|
||||
viewState: OpenConversationsViewModel.ViewState,
|
||||
@@ -459,7 +377,6 @@ private fun PreviewOpenConversationsTopBar() {
|
||||
OpenConversationsTopBar(
|
||||
isSearchActive = true,
|
||||
searchTerm = "design",
|
||||
focusRequester = remember { FocusRequester() },
|
||||
listenerInput = OpenConversationsTopBarListenerInput(
|
||||
onSearchTermChange = {},
|
||||
onSearchActivate = {},
|
||||
@@ -479,7 +396,6 @@ private fun PreviewOpenConversationsTopBarRtl() {
|
||||
OpenConversationsTopBar(
|
||||
isSearchActive = true,
|
||||
searchTerm = "تصميم",
|
||||
focusRequester = remember { FocusRequester() },
|
||||
listenerInput = OpenConversationsTopBarListenerInput(
|
||||
onSearchTermChange = {},
|
||||
onSearchActivate = {},
|
||||
|
||||
Reference in new issue
Block a user