Профиль, редактирование без аватара

This commit is contained in:
Халимов Рустам
2026-04-16 15:41:22 +03:00
parent 8409c51842
commit cea3f4d669
45 changed files with 1063 additions and 178 deletions

View File

@@ -44,23 +44,38 @@ class ProfileViewModel @Inject constructor(
}
}
fun updateProfile(displayName: String?, bio: String?, avatarUri: Uri? = null) {
fun updateProfile(displayName: String?, bio: String?, birthday: String? = null, avatarUri: Uri? = null) {
viewModelScope.launch {
_state.value = _state.value.copy(isSaving = true)
_state.value = _state.value.copy(isSaving = true, error = null)
// 1. Обновляем аватар, если он выбран
avatarUri?.let {
repository.uploadAvatar(it)
}
try {
// 1. Обновляем аватар, если он выбран
avatarUri?.let { uri ->
repository.uploadAvatar(uri).onFailure { error ->
throw Exception(error.message ?: "Failed to upload avatar")
}
}
// 2. Обновляем текстовые данные
repository.updateProfile(displayName, bio)
.onSuccess { updatedProfile ->
_state.value = _state.value.copy(profile = updatedProfile, isSaving = false)
}
.onFailure { error ->
_state.value = _state.value.copy(error = error.message, isSaving = false)
}
// 2. Обновляем текстовые данные
// Пустую строку преобразуем в null для даты рождения
val birthdayToSend = if (birthday.isNullOrBlank()) null else birthday
// Логирование для отладки
android.util.Log.d("ProfileViewModel", "updateProfile: displayName=$displayName, bio=$bio, birthday=$birthday, birthdayToSend=$birthdayToSend")
repository.updateProfile(displayName, bio, birthdayToSend)
.onSuccess { updatedProfile ->
android.util.Log.d("ProfileViewModel", "updateProfile success: birthday=${updatedProfile.birthday}")
_state.value = _state.value.copy(profile = updatedProfile, isSaving = false)
}
.onFailure { error ->
android.util.Log.e("ProfileViewModel", "updateProfile error: ${error.message}")
_state.value = _state.value.copy(error = error.message, isSaving = false)
}
} catch (e: Exception) {
android.util.Log.e("ProfileViewModel", "updateProfile exception: ${e.message}")
_state.value = _state.value.copy(error = e.message, isSaving = false)
}
}
}