feat(settings): set bio

Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
Infi 2023-10-31 20:29:27 +01:00
parent 771fc74cc1
commit b08aaec999
4 changed files with 64 additions and 5 deletions

View File

@ -67,7 +67,7 @@ suspend fun patchSelf(
profileMap["background"] = background profileMap["background"] = background
} }
if (bio != null) { if (bio != null) {
profileMap["bio"] = bio profileMap["content"] = bio
} }
body["profile"] = RevoltJson.encodeToJsonElement( body["profile"] = RevoltJson.encodeToJsonElement(

View File

@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
@ -87,11 +86,11 @@ fun InlineMediaPicker(
onRemove() onRemove()
}, },
enabled = currentModel != null, enabled = currentModel != null,
modifier = Modifier.fillMaxWidth() modifier = Modifier.width(480.dp)
) { ) {
Icon( Icon(
imageVector = Icons.Default.Close, imageVector = Icons.Default.Close,
contentDescription = stringResource(R.string.inline_media_picker_remove) contentDescription = null
) )
Spacer(modifier = Modifier.width(8.dp)) Spacer(modifier = Modifier.width(8.dp))

View File

@ -9,14 +9,21 @@ import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawingPadding import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.material3.Icon
import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.mutableFloatStateOf
@ -191,7 +198,18 @@ class ProfileSettingsScreenViewModel @Inject constructor(@ApplicationContext val
fun removeBackground() { fun removeBackground() {
viewModelScope.launch { viewModelScope.launch {
patchSelf(remove = listOf("ProfileBackground")) patchSelf(remove = listOf("ProfileBackground"))
pfpModel = null backgroundModel = null
}
}
fun saveBio() {
viewModelScope.launch {
patchSelf(bio = pendingProfile?.content)
fetchUserProfile(RevoltAPI.selfId!!).let {
currentProfile = it
pendingProfile = it
}
} }
} }
} }
@ -301,6 +319,47 @@ fun ProfileSettingsScreen(
) )
} }
} }
Column(
modifier = Modifier
.padding(start = 20.dp, end = 20.dp, top = 0.dp, bottom = 20.dp)
) {
OutlinedTextField(
value = viewModel.pendingProfile?.content ?: "",
onValueChange = { value ->
viewModel.pendingProfile?.let {
viewModel.pendingProfile = it.copy(content = value)
}
},
label = {
Text(
text = stringResource(id = R.string.user_context_sheet_category_bio),
style = MaterialTheme.typography.labelLarge,
)
},
)
Spacer(Modifier.height(8.dp))
TextButton(
onClick = {
viewModel.saveBio()
},
enabled = viewModel.pendingProfile?.content != viewModel.currentProfile?.content,
modifier = Modifier.fillMaxWidth()
) {
Icon(
imageVector = Icons.Default.Check,
contentDescription = null
)
Spacer(modifier = Modifier.width(8.dp))
Text(
text = stringResource(id = R.string.settings_profile_save),
style = MaterialTheme.typography.bodySmall
)
}
}
} }
} }
} }

View File

@ -398,6 +398,7 @@
<string name="settings_profile">Profile</string> <string name="settings_profile">Profile</string>
<string name="settings_profile_profile_picture">Profile picture</string> <string name="settings_profile_profile_picture">Profile picture</string>
<string name="settings_profile_custom_background">Custom background</string> <string name="settings_profile_custom_background">Custom background</string>
<string name="settings_profile_save">Save</string>
<string name="settings_sessions">Sessions</string> <string name="settings_sessions">Sessions</string>
<string name="settings_sessions_this_device">This Device</string> <string name="settings_sessions_this_device">This Device</string>