Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pauljohanneskraft committed Nov 26, 2024
1 parent 6566ef5 commit 004be47
Show file tree
Hide file tree
Showing 29 changed files with 178 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package edu.stanford.spezi.module.account.login
package edu.stanford.spezi.module.account

import edu.stanford.spezi.core.coroutines.di.Dispatching
import kotlinx.coroutines.CoroutineScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Account(
val configuration: AccountValueConfiguration = AccountValueConfiguration.default,
details: AccountDetails? = null,
) {
private val logger by speziLogger()
internal val logger by speziLogger()

var details: AccountDetails?
private set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import kotlin.time.Duration.Companion.seconds
class InMemoryAccountStorageProvider @Inject constructor(
@Dispatching.IO private val scope: CoroutineScope,
) : AccountStorageProvider {
private var records = mutableMapOf<String, AccountDetails>()
private var cache = mutableMapOf<String, AccountDetails>() // simulates an in-memory cache
private val records = mutableMapOf<String, AccountDetails>()
private val cache = mutableMapOf<String, AccountDetails>() // simulates an in-memory cache

@Inject internal lateinit var storage: ExternalAccountStorage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ private object MockBoolKey : AccountKey<Boolean> {
override val serializer = Boolean.serializer()

@Composable
override fun DisplayComposable(value: Boolean) {
override fun Display(value: Boolean) {
BooleanDisplay(key = this, value = value)
}

@Composable
override fun EntryComposable(value: Boolean, onValueChanged: (Boolean) -> Unit) {
override fun Entry(value: Boolean, onValueChanged: (Boolean) -> Unit) {
BooleanEntry(key = this, value = value, onValueChanged = onValueChanged)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ private object MockDoubleKey : AccountKey<Double> {
override val serializer = Double.serializer()

@Composable
override fun DisplayComposable(value: Double) {
override fun Display(value: Double) {
NumberDisplay(key = this, value = value)
}

@Composable
override fun EntryComposable(value: Double, onValueChanged: (Double) -> Unit) {
override fun Entry(value: Double, onValueChanged: (Double) -> Unit) {
NumberEntry(
key = this,
value = value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ private object MockNumericKey : AccountKey<Long> {
override val serializer = Long.serializer()

@Composable
override fun DisplayComposable(value: Long) {
override fun Display(value: Long) {
NumberDisplay(key = this, value = value)
}

@Composable
override fun EntryComposable(value: Long, onValueChanged: (Long) -> Unit) {
override fun Entry(value: Long, onValueChanged: (Long) -> Unit) {
NumberEntry(
key = this,
value = value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ interface AccountKey<Value : Any> : KnowledgeSource<AccountAnchor, Value> {
val serializer: KSerializer<Value>

@Composable
fun DisplayComposable(value: Value)
fun Display(value: Value)

@Composable
fun EntryComposable(value: Value, onValueChanged: (Value) -> Unit)
fun Entry(value: Value, onValueChanged: (Value) -> Unit)

@Composable
fun EntryComposable(state: MutableState<Value>) {
EntryComposable(state.value, onValueChanged = { state.value = it })
fun Entry(state: MutableState<Value>) {
Entry(state.value, onValueChanged = { state.value = it })
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ package edu.stanford.spezi.module.account.account.value

import androidx.compose.runtime.Composable
import edu.stanford.spezi.module.account.account.value.collections.AccountDetails
import edu.stanford.spezi.module.account.account.views.entry.GeneralizedEntryComposable
import edu.stanford.spezi.module.account.account.views.entry.GeneralizedEntry
import edu.stanford.spezi.module.account.account.views.overview.AccountOverviewFormViewModel
import edu.stanford.spezi.module.account.account.views.overview.SingleEntryComposable
import edu.stanford.spezi.module.account.account.views.overview.SingleEntry

@Composable
internal fun <Value : Any> AccountKey<Value>.EntryComposableWithEmptyValue() {
GeneralizedEntryComposable(this, initialValue = initialValue.value)
internal fun <Value : Any> AccountKey<Value>.EntryWithEmptyValue() {
GeneralizedEntry(this, initialValue = initialValue.value)
}

@Composable
internal fun <Value : Any> AccountKey<Value>.EntryComposableWithStoredOrInitialValue(details: AccountDetails) {
internal fun <Value : Any> AccountKey<Value>.EntryWithStoredOrInitialValue(details: AccountDetails) {
val value = details[this] ?: initialValue.value
GeneralizedEntryComposable(this, initialValue = value)
GeneralizedEntry(this, initialValue = value)
}

@Composable
internal fun <Value : Any> AccountKey<Value>.SingleEntryComposable(
internal fun <Value : Any> AccountKey<Value>.SingleEntry(
model: AccountOverviewFormViewModel,
details: AccountDetails,
) {
SingleEntryComposable(this, model = model, details = details)
SingleEntry(this, model = model, details = details)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ private object AccountIdKey : RequiredAccountKey<String> {
override val serializer = String.serializer()

@Composable
override fun DisplayComposable(value: String) {
override fun Display(value: String) {
Text("The internal account identifier is not meant to be user facing!")
}

@Composable
override fun EntryComposable(value: String, onValueChanged: (String) -> Unit) {
override fun Entry(value: String, onValueChanged: (String) -> Unit) {
Text("The internal account identifier is meant to be generated!")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ private object AccountDateOfBirthKey : AccountKey<Date> {
}

@Composable
override fun DisplayComposable(value: Date) {
override fun Display(value: Date) {
val format = remember { DateFormat.getDateInstance(DateFormat.MEDIUM) }
ListRow(AccountKeys.dateOfBirth.name.text()) {
Text(format.format(value))
}
}

@Composable
override fun EntryComposable(value: Date, onValueChanged: (Date) -> Unit) {
override fun Entry(value: Date, onValueChanged: (Date) -> Unit) {
val account = LocalAccount.current
val accountViewType = LocalAccountViewType.current

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ private object AccountEmailKey : OptionalComputedAccountKey<String> {
override val serializer = String.serializer()

@Composable
override fun DisplayComposable(value: String) {
override fun Display(value: String) {
StringDisplay(this, value)
}

@Composable
override fun EntryComposable(value: String, onValueChanged: (String) -> Unit) {
override fun Entry(value: String, onValueChanged: (String) -> Unit) {
VerifiableTextField(
name.text(),
value = value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ private object AccountGenderIdentityKey : AccountKey<GenderIdentity> {
}

@Composable
override fun DisplayComposable(value: GenderIdentity) {
override fun Display(value: GenderIdentity) {
StringResourceDisplay(this, value)
}

@Composable
override fun EntryComposable(value: GenderIdentity, onValueChanged: (GenderIdentity) -> Unit) {
override fun Entry(value: GenderIdentity, onValueChanged: (GenderIdentity) -> Unit) {
EnumEntry(
this,
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ private object AccountPasswordKey : AccountKey<String> {
override val serializer = String.serializer()

@Composable
override fun DisplayComposable(value: String) {
override fun Display(value: String) {
StringDisplay(this, value)
}

@Composable
override fun EntryComposable(value: String, onValueChanged: (String) -> Unit) {
override fun Entry(value: String, onValueChanged: (String) -> Unit) {
val accountViewType = LocalAccountViewType.current
val fieldType = LocalPasswordFieldType.current
val validation = LocalValidationEngine.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ private object AccountNameKey : AccountKey<PersonNameComponents> {
}

@Composable
override fun DisplayComposable(value: PersonNameComponents) {
override fun Display(value: PersonNameComponents) {
ListRow(name.text()) {
Text(value.formatted())
}
}

@Composable
override fun EntryComposable(value: PersonNameComponents, onValueChanged: (PersonNameComponents) -> Unit) {
override fun Entry(value: PersonNameComponents, onValueChanged: (PersonNameComponents) -> Unit) {
val account = LocalAccount.current
val nameIsRequired = account?.configuration?.get(AccountKeys.name)?.requirement == AccountKeyRequirement.REQUIRED
val validationRules = if (nameIsRequired) listOf(ValidationRule.nonEmpty) else listOf(ValidationRule.acceptAll)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ private object AccountUserIdKey : ComputedAccountKey<String> {
override val serializer = String.serializer()

@Composable
override fun DisplayComposable(value: String) {
override fun Display(value: String) {
val configuration = LocalAccountServiceConfiguration.current
ListRow(configuration.userIdConfiguration.idType.stringResource.text()) {
Text(value)
}
}

@Composable
override fun EntryComposable(value: String, onValueChanged: (String) -> Unit) {
override fun Entry(value: String, onValueChanged: (String) -> Unit) {
val configuration = LocalAccountServiceConfiguration.current

VerifiableTextField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal fun AccountSummaryBox(
}
}

class AccountDetailsProvider : PreviewParameterProvider<AccountDetails> {
private class AccountSummaryBoxPreviewProvider : PreviewParameterProvider<AccountDetails> {
override val values: Sequence<AccountDetails> = sequenceOf(
AccountDetails().also {
it.userId = "[email protected]"
Expand All @@ -97,8 +97,8 @@ class AccountDetailsProvider : PreviewParameterProvider<AccountDetails> {

@ThemePreviews
@Composable
fun AccountDialogPreview(
@PreviewParameter(AccountDetailsProvider::class) details: AccountDetails,
private fun AccountSummaryBoxPreviews(
@PreviewParameter(AccountSummaryBoxPreviewProvider::class) details: AccountDetails,
) {
SpeziTheme(isPreview = true) {
Box(Modifier.padding(8.dp)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import kotlinx.coroutines.launch
import kotlin.time.Duration.Companion.milliseconds

@Composable
fun PasswordResetComposable(
fun PasswordReset(
success: @Composable () -> Unit = { SuccessfulPasswordResetComposable() },
resetPassword: suspend (String) -> Unit,
) {
Expand Down Expand Up @@ -125,7 +125,7 @@ private fun PasswordResetForm(
@Composable
private fun PasswordResetComposablePreview() {
SpeziTheme(isPreview = true) {
PasswordResetComposable {
PasswordReset {
println("Reset password for $it")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import edu.stanford.spezi.core.design.component.ListRow
import edu.stanford.spezi.core.design.component.StringResource
import edu.stanford.spezi.core.design.theme.SpeziTheme
import edu.stanford.spezi.core.design.theme.ThemePreviews
import edu.stanford.spezi.module.account.account.model.GenderIdentity
import edu.stanford.spezi.module.account.account.value.AccountKey
Expand All @@ -27,5 +28,8 @@ fun <Value> StringResourceDisplay(
@ThemePreviews
@Composable
private fun StringResourceDisplayPreview() {
AccountKeys.genderIdentity.DisplayComposable(GenderIdentity.PREFER_NOT_TO_STATE)
SpeziTheme(isPreview = true) {
AccountKeys.genderIdentity
.Display(GenderIdentity.PREFER_NOT_TO_STATE)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import edu.stanford.spezi.module.account.account.value.InitialValue
import edu.stanford.spezi.module.account.account.value.configuration.AccountKeyRequirement

@Composable
fun <Value : Any> GeneralizedEntryComposable(
fun <Value : Any> GeneralizedEntry(
key: AccountKey<Value>,
initialValue: Value,
) {
Expand All @@ -21,7 +21,7 @@ fun <Value : Any> GeneralizedEntryComposable(
(state.value as? String)?.let { stringValue ->
// TODO: Figure out how to get validation rules!
Validate(stringValue, emptyList()) {
key.EntryComposable(state.value, onValueChanged = { state.value = it })
key.Entry(state.value, onValueChanged = { state.value = it })
}
} ?: run {
val isRequiredNonEmpty = (
Expand All @@ -31,10 +31,10 @@ fun <Value : Any> GeneralizedEntryComposable(

if (isRequiredNonEmpty) {
ValidateRequired(key, state) {
key.EntryComposable(state)
key.Entry(state)
}
} else {
key.EntryComposable(state)
key.Entry(state)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal fun PasswordChangeSheet(
.fieldValidationRules(AccountKeys.password) ?: emptyList()
}
Validate(newPassword.value, rules = newPasswordRules) {
AccountKeys.password.EntryComposable(newPassword)
AccountKeys.password.Entry(newPassword)
}

val validationEngineConfiguration = remember {
Expand All @@ -70,7 +70,7 @@ internal fun PasswordChangeSheet(
LocalValidationEngineConfiguration provides validationEngineConfiguration,
) {
Validate(newPasswordRepeat.value, rules = newPasswordRepeatRules) {
AccountKeys.password.EntryComposable(newPasswordRepeat)
AccountKeys.password.Entry(newPasswordRepeat)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import edu.stanford.spezi.core.design.views.validation.state.ValidationContext
import edu.stanford.spezi.core.design.views.views.model.ViewState
import edu.stanford.spezi.module.account.account.compositionLocal.LocalAccount
import edu.stanford.spezi.module.account.account.value.AccountKey
import edu.stanford.spezi.module.account.account.value.EntryComposableWithStoredOrInitialValue
import edu.stanford.spezi.module.account.account.value.EntryWithStoredOrInitialValue
import edu.stanford.spezi.module.account.account.value.collections.AccountDetails

@Composable
internal fun <Value : Any> SingleEntryComposable(
internal fun <Value : Any> SingleEntry(
key: AccountKey<Value>,
model: AccountOverviewFormViewModel,
details: AccountDetails,
Expand All @@ -36,7 +36,7 @@ internal fun <Value : Any> SingleEntryComposable(
ReceiveValidation(validation) {
// TODO: ViewStateAlert
Column {
key.EntryComposableWithStoredOrInitialValue(details)
key.EntryWithStoredOrInitialValue(details)
// TODO: .focused($isFocused)
// TODO: .environment(\.accountViewType, .overview(mode: .existing))
// TODO: .injectEnvironmentObjects(configuration: accountDetails.accountServiceConfiguration, model: model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import edu.stanford.spezi.core.design.views.views.views.button.SuspendButton

@Composable
fun AccountServiceButton(
title: StringResource,
title: String,
modifier: Modifier = Modifier,
image: ImageResource = remember { ImageResource.Vector(Icons.Default.Person, StringResource("User Profile")) },
colors: ButtonColors = ButtonDefaults.buttonColors(),
Expand All @@ -46,7 +46,7 @@ fun AccountServiceButton(
) {
ImageResourceComposable(image)
Spacer(Modifier.width(8.dp))
Text(title.text())
Text(title)
}
}
}
Expand Down Expand Up @@ -78,7 +78,7 @@ fun AccountServiceButton(
@Composable
private fun AccountServiceButtonPreview() {
SpeziTheme(isPreview = true) {
AccountServiceButton(StringResource("E-Mail and Password")) {
AccountServiceButton("E-Mail and Password") {
println("Pressed")
}
}
Expand Down
Loading

0 comments on commit 004be47

Please sign in to comment.