mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 13:57:10 +09:00
DROID-1382 Settings | Fix | Fixed profile & space name setting
DROID-1382 Settings | Fix | Fixed profile & space name setting
This commit is contained in:
parent
7ecc34a7f1
commit
d997f29c20
3 changed files with 42 additions and 6 deletions
|
@ -24,8 +24,10 @@ import androidx.compose.material.MaterialTheme
|
|||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.TextFieldDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
|
@ -55,6 +57,10 @@ import com.anytypeio.anytype.core_ui.views.Caption1Regular
|
|||
import com.anytypeio.anytype.core_ui.views.Title1
|
||||
import com.anytypeio.anytype.presentation.profile.ProfileIconView
|
||||
import com.anytypeio.anytype.ui_settings.R
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.filter
|
||||
|
||||
@Composable
|
||||
fun ProfileScreen(
|
||||
|
@ -262,7 +268,7 @@ private fun Header(
|
|||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterialApi::class)
|
||||
@OptIn(ExperimentalMaterialApi::class, FlowPreview::class)
|
||||
@Composable
|
||||
fun ProfileNameBlock(
|
||||
modifier: Modifier = Modifier,
|
||||
|
@ -273,6 +279,16 @@ fun ProfileNameBlock(
|
|||
val nameValue = remember { mutableStateOf(name) }
|
||||
val focusManager = LocalFocusManager.current
|
||||
|
||||
LaunchedEffect(nameValue.value) {
|
||||
snapshotFlow { nameValue.value }
|
||||
.debounce(PROFILE_NAME_CHANGE_DELAY)
|
||||
.distinctUntilChanged()
|
||||
.filter { it.isNotEmpty() }
|
||||
.collect { query ->
|
||||
onNameSet(query)
|
||||
}
|
||||
}
|
||||
|
||||
Column(modifier = modifier.padding(start = 20.dp)) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.name),
|
||||
|
@ -297,7 +313,6 @@ fun ProfileNameBlock(
|
|||
),
|
||||
keyboardActions = KeyboardActions(
|
||||
onDone = {
|
||||
onNameSet.invoke(nameValue.value)
|
||||
focusManager.clearFocus()
|
||||
}
|
||||
),
|
||||
|
@ -412,4 +427,6 @@ fun ProfileImageBlock(
|
|||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const val PROFILE_NAME_CHANGE_DELAY = 300L
|
|
@ -26,6 +26,7 @@ import com.anytypeio.anytype.ui_settings.account.repo.DebugSpaceShareDownloader
|
|||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.launch
|
||||
|
@ -66,7 +67,7 @@ class ProfileViewModel(
|
|||
).map { result ->
|
||||
val obj = result.firstOrNull()
|
||||
AccountProfile.Data(
|
||||
name = obj?.name ?: "",
|
||||
name = obj?.name.orEmpty(),
|
||||
icon = obj?.profileIcon(urlBuilder, spaceGradientProvider) ?: ProfileIconView.Placeholder
|
||||
)
|
||||
}.stateIn(
|
||||
|
|
|
@ -17,8 +17,10 @@ import androidx.compose.material.ExperimentalMaterialApi
|
|||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.TextFieldDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
|
@ -44,6 +46,10 @@ import com.anytypeio.anytype.core_ui.views.Title1
|
|||
import com.anytypeio.anytype.emojifier.Emojifier
|
||||
import com.anytypeio.anytype.presentation.spaces.SpaceIconView
|
||||
import com.anytypeio.anytype.ui_settings.R
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.filter
|
||||
|
||||
@Composable
|
||||
fun Section(modifier: Modifier = Modifier, title: String) {
|
||||
|
@ -55,6 +61,7 @@ fun Section(modifier: Modifier = Modifier, title: String) {
|
|||
)
|
||||
}
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
@Composable
|
||||
fun NameBlock(
|
||||
modifier: Modifier = Modifier,
|
||||
|
@ -65,6 +72,16 @@ fun NameBlock(
|
|||
val nameValue = remember { mutableStateOf(name) }
|
||||
val focusManager = LocalFocusManager.current
|
||||
|
||||
LaunchedEffect(nameValue.value) {
|
||||
snapshotFlow { nameValue.value }
|
||||
.debounce(SPACE_NAME_CHANGE_DELAY)
|
||||
.distinctUntilChanged()
|
||||
.filter { it.isNotEmpty() }
|
||||
.collect { query ->
|
||||
onNameSet(query)
|
||||
}
|
||||
}
|
||||
|
||||
Column(modifier = modifier.padding(start = 20.dp)) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.space_name),
|
||||
|
@ -78,7 +95,6 @@ fun NameBlock(
|
|||
},
|
||||
keyboardActions = KeyboardActions(
|
||||
onDone = {
|
||||
onNameSet.invoke(nameValue.value)
|
||||
focusManager.clearFocus()
|
||||
}
|
||||
),
|
||||
|
@ -241,4 +257,6 @@ fun SettingsTextField(
|
|||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private const val SPACE_NAME_CHANGE_DELAY = 300L
|
Loading…
Add table
Add a link
Reference in a new issue