chore: refaktoriere Veranstaltungs-UI zu Events, implementiere ZNS-Suche und verbessere Navigationslogik

Signed-off-by: StefanMoCoAt <stefan.mo.co@gmail.com>
This commit is contained in:
2026-04-21 13:41:06 +02:00
parent 9b4af2bb56
commit 574f8c470c
18 changed files with 673 additions and 174 deletions
@@ -1,6 +1,7 @@
package at.mocode.frontend.features.profile.di
import at.mocode.frontend.features.profile.data.ProfileApiClient
import at.mocode.frontend.features.profile.presentation.ProfileOnboardingViewModel
import at.mocode.frontend.features.profile.presentation.ProfileViewModel
import org.koin.core.qualifier.named
import org.koin.dsl.module
@@ -8,4 +9,5 @@ import org.koin.dsl.module
val profileModule = module {
single { ProfileApiClient(get(named("apiClient")), get()) }
single { ProfileViewModel(get()) }
factory { ProfileOnboardingViewModel(get(), get()) }
}
@@ -0,0 +1,169 @@
package at.mocode.frontend.features.profile.presentation
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material.icons.filled.Person
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import at.mocode.frontend.core.designsystem.components.MsTextField
@Composable
fun ProfileOnboardingScreen(
viewModel: ProfileOnboardingViewModel,
onFinish: () -> Unit
) {
val state = viewModel.state
Column(
modifier = Modifier.fillMaxSize().padding(24.dp),
verticalArrangement = Arrangement.spacedBy(24.dp)
) {
Text(
text = "Willkommen bei der Meldestelle",
style = MaterialTheme.typography.headlineMedium,
fontWeight = FontWeight.Bold
)
LinearProgressIndicator(
progress = {
when (state.currentStep) {
OnboardingStep.SEARCH_ZNS -> 0.33f
OnboardingStep.CONFIRM_DATA -> 0.66f
OnboardingStep.FINISHED -> 1f
}
},
modifier = Modifier.fillMaxWidth()
)
Box(modifier = Modifier.weight(1f)) {
when (state.currentStep) {
OnboardingStep.SEARCH_ZNS -> SearchStep(viewModel)
OnboardingStep.CONFIRM_DATA -> ConfirmStep(viewModel)
OnboardingStep.FINISHED -> FinishedStep(state, onFinish)
}
}
if (state.currentStep != OnboardingStep.FINISHED) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
OutlinedButton(onClick = { viewModel.back() }, enabled = state.currentStep != OnboardingStep.SEARCH_ZNS) {
Text("Zurück")
}
if (state.currentStep == OnboardingStep.CONFIRM_DATA) {
Button(onClick = { viewModel.confirmAndLink() }, enabled = !state.isLoading) {
if (state.isLoading) CircularProgressIndicator(Modifier.size(16.dp))
else Text("Daten bestätigen & Verknüpfen")
}
}
}
}
}
}
@Composable
private fun SearchStep(viewModel: ProfileOnboardingViewModel) {
val state = viewModel.state
Column(verticalArrangement = Arrangement.spacedBy(16.dp)) {
Text("Wer bist du?", style = MaterialTheme.typography.titleLarge)
Text("Suchen Sie nach Ihrer Satznummer oder Ihrem Namen in den ZNS-Stammdaten.")
MsTextField(
value = state.searchQuery,
onValueChange = { viewModel.onSearchQueryChange(it) },
label = "Suche (Name oder Satznummer)",
placeholder = "z.B. Stroblmair",
modifier = Modifier.fillMaxWidth(),
leadingIcon = Icons.Default.Search
)
if (state.isLoading) {
CircularProgressIndicator(modifier = Modifier.align(Alignment.CenterHorizontally))
}
LazyColumn(verticalArrangement = Arrangement.spacedBy(8.dp)) {
items(state.searchResults) { reiter ->
Card(
onClick = { viewModel.selectReiter(reiter) },
modifier = Modifier.fillMaxWidth()
) {
Row(
modifier = Modifier.padding(16.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(16.dp)
) {
Icon(Icons.Default.Person, null)
Column {
Text("${reiter.vorname} ${reiter.nachname}", fontWeight = FontWeight.Bold)
Text("Satznr: ${reiter.satznummer ?: "N/A"} | Lizenz: ${reiter.lizenz ?: "Keine"}")
}
}
}
}
}
}
}
@Composable
private fun ConfirmStep(viewModel: ProfileOnboardingViewModel) {
val state = viewModel.state
val reiter = state.selectedReiter ?: return
Column(verticalArrangement = Arrangement.spacedBy(16.dp)) {
Text("Daten bestätigen", style = MaterialTheme.typography.titleLarge)
Card(
modifier = Modifier.fillMaxWidth(),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant)
) {
Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
Text("Vorname: ${reiter.vorname}")
Text("Nachname: ${reiter.nachname}")
Text("Satznummer: ${reiter.satznummer ?: "N/A"}")
Text("Lizenz: ${reiter.lizenz ?: "Keine"}")
Text("Klasse: ${reiter.lizenzKlasse}")
}
}
Text(
"Durch das Verknüpfen werden Ihre Aktionen in der App mit Ihrer offiziellen ZNS-Identität hinterlegt.",
style = MaterialTheme.typography.bodyMedium
)
if (state.error != null) {
Text(state.error, color = MaterialTheme.colorScheme.error)
}
}
}
@Composable
private fun FinishedStep(state: ProfileOnboardingState, onFinish: () -> Unit) {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Icon(
Icons.Default.CheckCircle,
contentDescription = null,
modifier = Modifier.size(64.dp),
tint = MaterialTheme.colorScheme.primary
)
Spacer(Modifier.height(16.dp))
Text("Profil erfolgreich verknüpft!", style = MaterialTheme.typography.headlineSmall)
Text("Willkommen, ${state.selectedReiter?.vorname ?: ""} ${state.selectedReiter?.nachname ?: ""}!")
Spacer(Modifier.height(32.dp))
Button(onClick = onFinish) {
Text("Los geht's")
}
}
}
@@ -0,0 +1,98 @@
package at.mocode.frontend.features.profile.presentation
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import at.mocode.frontend.core.domain.zns.ZnsImportProvider
import at.mocode.frontend.core.domain.zns.ZnsRemoteReiter
import at.mocode.frontend.features.profile.data.ProfileApiClient
import at.mocode.frontend.features.profile.data.ProfileDto
import kotlinx.coroutines.launch
enum class OnboardingStep {
SEARCH_ZNS,
CONFIRM_DATA,
FINISHED
}
data class ProfileOnboardingState(
val currentStep: OnboardingStep = OnboardingStep.SEARCH_ZNS,
val searchQuery: String = "",
val searchResults: List<ZnsRemoteReiter> = emptyList(),
val selectedReiter: ZnsRemoteReiter? = null,
val isLoading: Boolean = false,
val error: String? = null,
val profile: ProfileDto? = null
)
class ProfileOnboardingViewModel(
private val znsImportProvider: ZnsImportProvider,
private val profileApiClient: ProfileApiClient
) : ViewModel() {
var state by mutableStateOf(ProfileOnboardingState())
private set
fun onSearchQueryChange(query: String) {
state = state.copy(searchQuery = query)
if (query.length >= 3) {
search()
}
}
private fun search() {
viewModelScope.launch {
state = state.copy(isLoading = true, error = null)
try {
znsImportProvider.searchRemote(state.searchQuery)
state = state.copy(
isLoading = false,
searchResults = znsImportProvider.state.remoteReiter
)
} catch (e: Exception) {
state = state.copy(isLoading = false, error = "Fehler bei der ZNS-Suche: ${e.message}")
}
}
}
fun selectReiter(reiter: ZnsRemoteReiter) {
state = state.copy(
selectedReiter = reiter,
currentStep = OnboardingStep.CONFIRM_DATA
)
}
fun confirmAndLink() {
val reiter = state.selectedReiter ?: return
viewModelScope.launch {
state = state.copy(isLoading = true, error = null)
try {
val satznr = reiter.satznummer ?: ""
val profile = profileApiClient.linkToZns(satznr)
if (profile != null) {
state = state.copy(
isLoading = false,
profile = profile,
currentStep = OnboardingStep.FINISHED
)
} else {
state = state.copy(isLoading = false, error = "Verknüpfung fehlgeschlagen.")
}
} catch (e: Exception) {
state = state.copy(isLoading = false, error = "Fehler beim Verknüpfen: ${e.message}")
}
}
}
fun back() {
state = state.copy(
currentStep = when (state.currentStep) {
OnboardingStep.SEARCH_ZNS -> OnboardingStep.SEARCH_ZNS
OnboardingStep.CONFIRM_DATA -> OnboardingStep.SEARCH_ZNS
OnboardingStep.FINISHED -> OnboardingStep.CONFIRM_DATA
}
)
}
}
@@ -231,7 +231,7 @@ private fun StepOrtZeit(state: CreateBewerbWizardState, onStateChange: (CreateBe
@Composable
private fun StepRichterTeilung(state: CreateBewerbWizardState, onStateChange: (CreateBewerbWizardState) -> Unit) {
Column(Modifier.fillMaxWidth()) {
// Warn-Logik (mock): Wenn Richter ausgewählt und Position = "C" ohne weiterer Prüfung -> TB-Hinweis
// Warn-Logik (mock): Wenn Richter ausgewählt und Position = "C" ohne weitere Prüfung TB-Hinweis
val warnTb = state.richter.isNotEmpty()
if (warnTb) {
Box(
@@ -240,6 +240,25 @@ private fun StepRichterTeilung(state: CreateBewerbWizardState, onStateChange: (C
Spacer(Modifier.height(8.dp))
}
// Abteilungs-Vorschau (§ 39 ÖTO)
val abteilungsInfo = remember(state.klasse, state.teilungsTyp) {
when {
state.klasse.contains("S", ignoreCase = true) -> "§ 39 ÖTO: Abteilungstrennung ab 35 Nennungen (R1 getrennt von R2+)"
state.klasse.contains("M", ignoreCase = true) -> "§ 39 ÖTO: Abteilungstrennung ab 50 Nennungen"
else -> "Standard-Abteilungstrennung gemäß ÖTO § 39"
}
}
Card(
modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.secondaryContainer)
) {
Column(Modifier.padding(12.dp)) {
Text("Abteilungs-Vorschau (§ 39 ÖTO)", style = MaterialTheme.typography.labelLarge, fontWeight = FontWeight.Bold)
Text(abteilungsInfo, style = MaterialTheme.typography.bodySmall)
}
}
OutlinedTextField(
value = state.teilungsTyp,
onValueChange = { onStateChange(state.copy(teilungsTyp = it)) },
@@ -1,5 +1,6 @@
package at.mocode.veranstaltung.feature.di
import at.mocode.frontend.core.domain.zns.ZnsImportProvider
import at.mocode.veranstaltung.feature.presentation.VeranstaltungManagementViewModel
import at.mocode.veranstaltung.feature.presentation.VeranstaltungWizardViewModel
import org.koin.core.qualifier.named
@@ -7,5 +8,5 @@ import org.koin.dsl.module
val veranstaltungModule = module {
factory { VeranstaltungManagementViewModel(get()) }
factory { VeranstaltungWizardViewModel(get(named("apiClient")), get(), get(), get()) }
factory { VeranstaltungWizardViewModel(get(named("apiClient")), get(), get(), get(), get<ZnsImportProvider>(), get()) }
}
@@ -49,7 +49,7 @@ fun VeranstaltungDetailScreen(
val event = veranstaltung
if (event == null) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text("Veranstaltung #$veranstaltungId nicht gefunden.")
Text("Event #$veranstaltungId nicht gefunden.")
}
return
}
@@ -95,7 +95,7 @@ fun VeranstaltungDetailScreen(
}
Text(
text = "Turniere in dieser Veranstaltung",
text = "Turniere in diesem Event",
style = MaterialTheme.typography.titleLarge,
fontWeight = FontWeight.Bold
)
@@ -18,9 +18,7 @@ import at.mocode.frontend.core.designsystem.components.MsFilePicker
import at.mocode.frontend.core.designsystem.components.MsTextField
import at.mocode.frontend.core.designsystem.theme.Dimens
import at.mocode.frontend.features.turnier.presentation.TurnierWizard
import at.mocode.frontend.features.turnier.presentation.TurnierWizardViewModel
import at.mocode.frontend.features.zns.import.presentation.StammdatenImportScreen
import org.koin.compose.koinInject
import kotlin.uuid.ExperimentalUuidApi
@OptIn(ExperimentalMaterial3Api::class, ExperimentalUuidApi::class)
@@ -37,7 +35,7 @@ fun VeranstaltungWizardScreen(
topBar = {
Column {
TopAppBar(
title = { Text("Neue Veranstaltung anlegen") },
title = { Text("Neues Event anlegen") },
navigationIcon = {
IconButton(onClick = {
if (state.currentStep == WizardStep.ZNS_CHECK) onBack()
@@ -108,7 +106,7 @@ private fun VorschauCard(state: VeranstaltungWizardState) {
Column(modifier = Modifier.weight(1f)) {
Text(
text = state.name.ifBlank { "Neue Veranstaltung" },
text = state.name.ifBlank { "Neues Event" },
style = MaterialTheme.typography.titleLarge,
fontWeight = FontWeight.Bold
)
@@ -275,7 +273,31 @@ private fun VeranstalterSelectionStep(
}
}
}
} else {
}
if (viewModel.state.znsSearchResults.isNotEmpty()) {
Text("Gefundene Vereine in den Stammdaten:", style = MaterialTheme.typography.labelMedium)
viewModel.state.znsSearchResults.forEach { znsVerein ->
Card(
modifier = Modifier.fillMaxWidth(),
onClick = { viewModel.selectZnsVerein(znsVerein) }
) {
Row(
modifier = Modifier.padding(12.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
Icon(Icons.Default.Add, null)
Column {
Text(znsVerein.name, fontWeight = FontWeight.Medium)
Text("OEPS-Nr: ${znsVerein.oepsNummer} | ${znsVerein.ort ?: ""}", style = MaterialTheme.typography.bodySmall)
}
}
}
}
}
if (viewModel.state.veranstalterId == null && viewModel.state.znsSearchResults.isEmpty()) {
Column(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
@@ -400,13 +422,13 @@ private fun MetaDataStep(viewModel: VeranstaltungWizardViewModel) {
@Composable
private fun TurnierAnlageStep(viewModel: VeranstaltungWizardViewModel) {
val state = viewModel.state
val turnierViewModel = viewModel.turnierWizardViewModel
var showWizard by remember { mutableStateOf(false) }
Column(verticalArrangement = Arrangement.spacedBy(16.dp)) {
Text("Schritt 5: Turniere & Ausschreibung", style = MaterialTheme.typography.titleLarge)
if (showWizard) {
val turnierViewModel = koinInject<TurnierWizardViewModel>()
Card(modifier = Modifier.fillMaxWidth().height(500.dp)) {
TurnierWizard(
viewModel = turnierViewModel,
@@ -414,7 +436,7 @@ private fun TurnierAnlageStep(viewModel: VeranstaltungWizardViewModel) {
onBack = { showWizard = false },
onFinish = {
showWizard = false
viewModel.addTurnier() // Dummy zum Hinzufügen im Haupt-Wizard
viewModel.addTurnier(turnierViewModel.state.turnierNr, "")
}
)
}
@@ -9,7 +9,10 @@ import at.mocode.core.domain.serialization.UuidSerializer
import at.mocode.frontend.core.auth.data.local.AuthTokenManager
import at.mocode.frontend.core.domain.repository.MasterdataRepository
import at.mocode.frontend.core.domain.repository.MasterdataStats
import at.mocode.frontend.core.domain.zns.ZnsImportProvider
import at.mocode.frontend.core.domain.zns.ZnsRemoteVerein
import at.mocode.frontend.core.network.NetworkConfig
import at.mocode.frontend.features.turnier.presentation.TurnierWizardViewModel
import at.mocode.frontend.features.verein.domain.VereinRepository
import io.ktor.client.*
import io.ktor.client.request.*
@@ -55,7 +58,8 @@ data class VeranstaltungWizardState(
val createdVeranstaltungId: Uuid? = null,
val isZnsAvailable: Boolean = false,
val stammdatenStats: MasterdataStats? = null,
val isCheckingStats: Boolean = false
val isCheckingStats: Boolean = false,
val znsSearchResults: List<ZnsRemoteVerein> = emptyList()
)
@OptIn(ExperimentalUuidApi::class)
@@ -63,7 +67,9 @@ class VeranstaltungWizardViewModel(
private val httpClient: HttpClient,
private val authTokenManager: AuthTokenManager,
private val vereinRepository: VereinRepository,
private val masterdataRepository: MasterdataRepository
private val masterdataRepository: MasterdataRepository,
private val znsImportProvider: ZnsImportProvider,
val turnierWizardViewModel: TurnierWizardViewModel // Injected Child-ViewModel
) : ViewModel() {
var state by mutableStateOf(VeranstaltungWizardState())
@@ -98,19 +104,45 @@ class VeranstaltungWizardViewModel(
fun searchVeranstalterByOepsNr(oepsNr: String) {
viewModelScope.launch {
val verein = vereinRepository.findByOepsNr(oepsNr)
if (verein != null) {
setVeranstalter(
id = Uuid.parse(verein.id),
nummer = verein.oepsNr ?: "",
name = verein.name,
standardOrt = "${verein.plz ?: ""} ${verein.ort ?: ""}".trim(),
logo = null // Hier könnte später ein Logo-Service greifen
)
try {
val verein = vereinRepository.findByOepsNr(oepsNr)
if (verein != null) {
// Robustes Parsing für Mock-Daten (z. B. "v1")
val uuid = try {
Uuid.parse(verein.id)
} catch (_: Exception) {
// Fallback für Mock-IDs während der Entwicklung
Uuid.random()
}
setVeranstalter(
id = uuid,
nummer = verein.oepsNr ?: "",
name = verein.name,
standardOrt = "${verein.plz ?: ""} ${verein.ort ?: ""}".trim(),
logo = null
)
} else if (oepsNr.length >= 3) {
// Suche in den ZNS-Stammdaten als Fallback
znsImportProvider.searchRemote(oepsNr)
state = state.copy(znsSearchResults = znsImportProvider.state.remoteResults)
}
} catch (e: Exception) {
state = state.copy(error = "Fehler bei der Veranstalter-Suche: ${e.message}")
}
}
}
fun selectZnsVerein(znsVerein: ZnsRemoteVerein) {
setVeranstalter(
id = Uuid.random(), // Neuer Veranstalter wird angelegt
nummer = znsVerein.oepsNummer,
name = znsVerein.name,
standardOrt = znsVerein.ort ?: "",
logo = null
)
}
fun nextStep() {
state = state.copy(
currentStep = when (state.currentStep) {
@@ -155,23 +187,13 @@ class VeranstaltungWizardViewModel(
state = state.copy(name = name, ort = ort, startDatum = start, endDatum = end, logoUrl = logo)
}
fun updateTurnier(index: Int, nummer: String, path: String?) {
val newList = state.turniere.toMutableList()
if (index in newList.indices) {
newList[index] = newList[index].copy(nummer = nummer, ausschreibungPath = path)
state = state.copy(turniere = newList)
}
}
fun addTurnier() {
state = state.copy(turniere = state.turniere + TurnierEntry())
fun addTurnier(nummer: String = "", pfad: String? = null) {
state = state.copy(turniere = state.turniere + TurnierEntry(nummer = nummer, ausschreibungPath = pfad))
}
fun removeTurnier(index: Int) {
if (state.turniere.size > 1) {
val newList = state.turniere.toMutableList().apply { removeAt(index) }
state = state.copy(turniere = newList)
}
val newList = state.turniere.toMutableList().apply { removeAt(index) }
state = state.copy(turniere = newList)
}
fun saveVeranstaltung() {
@@ -43,12 +43,12 @@ fun VeranstaltungenScreen(
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "Veranstaltungen - verwalten",
text = "Events - verwalten",
style = MaterialTheme.typography.headlineMedium,
fontWeight = FontWeight.Bold
)
MsButton(
text = "Neue Veranstaltung",
text = "Neues Event",
onClick = onVeranstaltungNeu
)
}
@@ -119,7 +119,7 @@ fun VeranstaltungenScreen(
)
Spacer(Modifier.height(Dimens.SpacingM))
Text(
"Keine Veranstaltungen gefunden.",
"Keine Events gefunden.",
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant
)