Skip to content

Commit

Permalink
Fill with more functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
pauljohanneskraft committed Nov 12, 2024
1 parent 47b8841 commit 22c3e6d
Show file tree
Hide file tree
Showing 30 changed files with 786 additions and 384 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@ data class PersonNameComponents(
.filter { it.isUpperCase() }
}
}

companion object {
operator fun invoke(string: String): PersonNameComponents {
val components = string.split(" ")
// TODO: Vastly improve this implementation!
return PersonNameComponents(
givenName = components.firstOrNull(),
familyName = components.drop(1).joinToString(" ")
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.TextFieldValue

Check warning on line 17 in core/design/src/main/kotlin/edu/stanford/spezi/core/design/views/validation/views/VerifiableTextField.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/main/kotlin/edu/stanford/spezi/core/design/views/validation/views/VerifiableTextField.kt#L17 <detekt.NoUnusedImports>

Unused import
Raw output
/github/workspace/core/design/src/main/kotlin/edu/stanford/spezi/core/design/views/validation/views/VerifiableTextField.kt:17:1: warning: Unused import (detekt.NoUnusedImports)

Check warning on line 17 in core/design/src/main/kotlin/edu/stanford/spezi/core/design/views/validation/views/VerifiableTextField.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/main/kotlin/edu/stanford/spezi/core/design/views/validation/views/VerifiableTextField.kt#L17 <detekt.UnusedImports>

The import 'androidx.compose.ui.text.input.TextFieldValue' is unused.
Raw output
/github/workspace/core/design/src/main/kotlin/edu/stanford/spezi/core/design/views/validation/views/VerifiableTextField.kt:17:1: warning: The import 'androidx.compose.ui.text.input.TextFieldValue' is unused. (detekt.UnusedImports)
import edu.stanford.spezi.core.design.component.StringResource
import edu.stanford.spezi.core.design.theme.SpeziTheme
import edu.stanford.spezi.core.design.theme.ThemePreviews
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import kotlinx.coroutines.runBlocking
import javax.inject.Inject

class Account(
val configuration: AccountValueConfiguration = AccountValueConfiguration.default,
service: AccountService,
val configuration: AccountValueConfiguration = AccountValueConfiguration.default,
details: AccountDetails? = null,
) {
val logger by speziLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@ import edu.stanford.spezi.module.account.account.service.configuration.Supported
import edu.stanford.spezi.module.account.account.service.configuration.supportedAccountKeys
import edu.stanford.spezi.module.account.account.service.configuration.unsupportedAccountKeys
import edu.stanford.spezi.module.account.account.value.AccountKeys
import edu.stanford.spezi.module.account.account.value.collections.AccountDetails
import edu.stanford.spezi.module.account.account.value.configuration.AccountValueConfiguration
import edu.stanford.spezi.module.account.account.value.keys.accountId
import javax.inject.Inject
import kotlin.system.exitProcess

class AccountConfiguration<Service : AccountService> {
private val logger by speziLogger()

@Inject lateinit var account: Account
interface Standard

@Inject internal lateinit var externalStorage: ExternalAccountStorage

@Inject internal lateinit var accountService: Service
// TODO: Expose those properties!!!!
class AccountConfiguration<Service : AccountService>(
private val accountService: Service,
private val storageProvider: AccountStorageProvider? = null,
configuration: AccountValueConfiguration = AccountValueConfiguration.default,
defaultActiveDetails: AccountDetails? = null,
) {
private val logger by speziLogger()

@Inject internal lateinit var storageProvider: List<Module> // TODO: This is never going to work
val account = Account(
accountService,
configuration,
defaultActiveDetails
)
val externalStorage = ExternalAccountStorage(storageProvider)

@Inject internal lateinit var standard: Standard

Expand All @@ -44,7 +52,7 @@ class AccountConfiguration<Service : AccountService> {

if (unmappedAccountKeys.isEmpty()) return // we are fine, nothing unsupported

storageProvider.firstOrNull()?.let {
storageProvider?.let {
logger.w {
"""
The storage provider $it is used to store the following account values that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.onCompletion
import java.util.UUID

class ExternalAccountStorage {
class ExternalAccountStorage internal constructor(
private var storageProvider: AccountStorageProvider?

Check warning on line 15 in modules/account/src/main/kotlin/edu/stanford/spezi/module/account/account/ExternalAccountStorage.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] modules/account/src/main/kotlin/edu/stanford/spezi/module/account/account/ExternalAccountStorage.kt#L15 <detekt.TrailingCommaOnDeclarationSite>

Missing trailing comma before ")"
Raw output
/github/workspace/modules/account/src/main/kotlin/edu/stanford/spezi/module/account/account/ExternalAccountStorage.kt:15:57: warning: Missing trailing comma before ")" (detekt.TrailingCommaOnDeclarationSite)
) {
data class ExternallyStoredDetails internal constructor(
val accountId: String,
val details: AccountDetails,
)

private var subscriptions = mutableMapOf<UUID, FlowCollector<ExternallyStoredDetails>>()
private var storageProvider: AccountStorageProvider? = null

val updatedDetails: Flow<ExternallyStoredDetails>
get() = UUID().let { id ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package edu.stanford.spezi.module.account.account.compositionLocal

import androidx.compose.runtime.compositionLocalOf
import edu.stanford.spezi.module.account.account.service.configuration.AccountServiceConfiguration
import edu.stanford.spezi.module.account.account.service.configuration.SupportedAccountKeys

val LocalAccountServiceConfiguration = compositionLocalOf {
AccountServiceConfiguration(SupportedAccountKeys.Arbitrary)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package edu.stanford.spezi.module.account.account.compositionLocal

import androidx.compose.runtime.compositionLocalOf

sealed interface AccountViewType {
data object Signup : AccountViewType
data class Overview(val mode: OverviewEntryMode) : AccountViewType

enum class OverviewEntryMode {
NEW, EXISTING, DISPLAY
}
}

val LocalAccountViewType = compositionLocalOf<AccountViewType?> { null }
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package edu.stanford.spezi.module.account.account.compositionLocal

import androidx.compose.runtime.compositionLocalOf
import edu.stanford.spezi.core.design.component.StringResource
import edu.stanford.spezi.module.account.account.value.AccountKeys
import edu.stanford.spezi.module.account.account.value.keys.password

enum class PasswordFieldType {
PASSWORD, NEW, REPEAT;

val text: StringResource get() = when (this) {
PASSWORD -> AccountKeys.password.name
NEW -> StringResource("NEW_PASSWORD")
REPEAT -> StringResource("REPEAT_PASSWORD")
}

val prompt: StringResource get() = when (this) {
PASSWORD -> AccountKeys.password.name
NEW -> StringResource("NEW_PASSWORD_PROMPT")
REPEAT -> StringResource("REPEAT_PASSWORD_PROMPT")
}
}

val LocalPasswordFieldType = compositionLocalOf { PasswordFieldType.PASSWORD }
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package edu.stanford.spezi.module.account.account.compositionLocal

import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.remember
import edu.stanford.spezi.module.account.account.value.AccountKey
import java.util.Date

Expand All @@ -21,4 +26,43 @@ data class SignUpProviderCompliance internal constructor(
}
}

// TODO: Find equivalent to SwiftUI preferences and implement inject functionality
private data class SignupProviderComplianceReader(
var entry: Entry? = null,
) {
data class Entry(
val compliance: SignUpProviderCompliance,
val date: Date = Date(),
)
}

private val LocalSignupProviderComplianceReaders = compositionLocalOf { emptyList<SignupProviderComplianceReader>() }

@Composable
fun ReportSignupProviderCompliance(compliance: SignUpProviderCompliance?) {
compliance?.let {
val newEntry = SignupProviderComplianceReader.Entry(it)
LocalSignupProviderComplianceReaders.current.forEach { reader ->
val oldEntry = reader.entry
if (oldEntry == null || oldEntry.date > newEntry.date) {
reader.entry = newEntry
}
}
}
}

@Composable
internal fun ReceiveSignupProviderCompliance(
action: (SignUpProviderCompliance?) -> Unit,
content: @Composable () -> Unit

Check warning on line 56 in modules/account/src/main/kotlin/edu/stanford/spezi/module/account/account/compositionLocal/SignUpProviderCompliance.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] modules/account/src/main/kotlin/edu/stanford/spezi/module/account/account/compositionLocal/SignUpProviderCompliance.kt#L56 <detekt.TrailingCommaOnDeclarationSite>

Missing trailing comma before ")"
Raw output
/github/workspace/modules/account/src/main/kotlin/edu/stanford/spezi/module/account/account/compositionLocal/SignUpProviderCompliance.kt:56:36: warning: Missing trailing comma before ")" (detekt.TrailingCommaOnDeclarationSite)
) {
val newReader = remember { SignupProviderComplianceReader() }
val existingReaders = LocalSignupProviderComplianceReaders.current
CompositionLocalProvider(
LocalSignupProviderComplianceReaders provides (existingReaders + newReader)
) {
content()
}
LaunchedEffect(newReader.entry) {
action(newReader.entry?.compliance)
}
}
Loading

0 comments on commit 22c3e6d

Please sign in to comment.