mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-07-29 07:43:00 +00:00
fix(profiles): activate selected profile once
This commit is contained in:
parent
237d2308f2
commit
2bca3ffa6b
3 changed files with 90 additions and 17 deletions
|
|
@ -0,0 +1,15 @@
|
|||
package com.nuvio.app.features.profiles
|
||||
|
||||
internal fun routeProfileSelection(
|
||||
profile: NuvioProfile,
|
||||
isEditMode: Boolean,
|
||||
onEditProfile: (NuvioProfile) -> Unit,
|
||||
onPinRequired: (NuvioProfile) -> Unit,
|
||||
onProfileSelected: (NuvioProfile) -> Unit,
|
||||
) {
|
||||
when {
|
||||
isEditMode -> onEditProfile(profile)
|
||||
profile.pinEnabled -> onPinRequired(profile)
|
||||
else -> onProfileSelected(profile)
|
||||
}
|
||||
}
|
||||
|
|
@ -80,6 +80,15 @@ fun ProfileSelectionScreen(
|
|||
val titleAlpha = remember { Animatable(0f) }
|
||||
val titleOffset = remember { Animatable(20f) }
|
||||
val manageAlpha = remember { Animatable(0f) }
|
||||
val onProfileClick: (NuvioProfile) -> Unit = { profile ->
|
||||
routeProfileSelection(
|
||||
profile = profile,
|
||||
isEditMode = isEditMode,
|
||||
onEditProfile = onEditProfile,
|
||||
onPinRequired = { pinDialogProfile = it },
|
||||
onProfileSelected = onProfileSelected,
|
||||
)
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
AvatarRepository.fetchAvatars()
|
||||
|
|
@ -168,14 +177,7 @@ fun ProfileSelectionScreen(
|
|||
isEditMode = isEditMode,
|
||||
animDelay = currentIndex * 80,
|
||||
onClick = {
|
||||
if (isEditMode) {
|
||||
onEditProfile(profile)
|
||||
} else if (profile.pinEnabled) {
|
||||
pinDialogProfile = profile
|
||||
} else {
|
||||
ProfileRepository.selectProfile(profile.profileIndex)
|
||||
onProfileSelected(profile)
|
||||
}
|
||||
onProfileClick(profile)
|
||||
},
|
||||
)
|
||||
} else {
|
||||
|
|
@ -209,14 +211,7 @@ fun ProfileSelectionScreen(
|
|||
isEditMode = isEditMode,
|
||||
animDelay = currentIndex * 80,
|
||||
onClick = {
|
||||
if (isEditMode) {
|
||||
onEditProfile(profile)
|
||||
} else if (profile.pinEnabled) {
|
||||
pinDialogProfile = profile
|
||||
} else {
|
||||
ProfileRepository.selectProfile(profile.profileIndex)
|
||||
onProfileSelected(profile)
|
||||
}
|
||||
onProfileClick(profile)
|
||||
},
|
||||
)
|
||||
} else {
|
||||
|
|
@ -279,7 +274,6 @@ fun ProfileSelectionScreen(
|
|||
onVerify = { pin -> ProfileRepository.verifyPin(profile.profileIndex, pin) },
|
||||
onVerified = {
|
||||
pinDialogProfile = null
|
||||
ProfileRepository.selectProfile(profile.profileIndex)
|
||||
onProfileSelected(profile)
|
||||
},
|
||||
onDismiss = { pinDialogProfile = null },
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
package com.nuvio.app.features.profiles
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class ProfileSelectionRoutingTest {
|
||||
@Test
|
||||
fun `unlocked profile emits one selection request`() {
|
||||
val profile = NuvioProfile(profileIndex = 2)
|
||||
var editRequests = 0
|
||||
var pinRequests = 0
|
||||
var selectionRequests = 0
|
||||
|
||||
routeProfileSelection(
|
||||
profile = profile,
|
||||
isEditMode = false,
|
||||
onEditProfile = { editRequests += 1 },
|
||||
onPinRequired = { pinRequests += 1 },
|
||||
onProfileSelected = { selectionRequests += 1 },
|
||||
)
|
||||
|
||||
assertEquals(0, editRequests)
|
||||
assertEquals(0, pinRequests)
|
||||
assertEquals(1, selectionRequests)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `locked profile requests verification without selecting`() {
|
||||
val profile = NuvioProfile(profileIndex = 2, pinEnabled = true)
|
||||
var pinRequests = 0
|
||||
var selectionRequests = 0
|
||||
|
||||
routeProfileSelection(
|
||||
profile = profile,
|
||||
isEditMode = false,
|
||||
onEditProfile = {},
|
||||
onPinRequired = { pinRequests += 1 },
|
||||
onProfileSelected = { selectionRequests += 1 },
|
||||
)
|
||||
|
||||
assertEquals(1, pinRequests)
|
||||
assertEquals(0, selectionRequests)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `edit mode routes only to profile editing`() {
|
||||
val profile = NuvioProfile(profileIndex = 2, pinEnabled = true)
|
||||
var editRequests = 0
|
||||
var pinRequests = 0
|
||||
var selectionRequests = 0
|
||||
|
||||
routeProfileSelection(
|
||||
profile = profile,
|
||||
isEditMode = true,
|
||||
onEditProfile = { editRequests += 1 },
|
||||
onPinRequired = { pinRequests += 1 },
|
||||
onProfileSelected = { selectionRequests += 1 },
|
||||
)
|
||||
|
||||
assertEquals(1, editRequests)
|
||||
assertEquals(0, pinRequests)
|
||||
assertEquals(0, selectionRequests)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue