Skip to content

Commit

Permalink
Merge pull request #280 from PermanentOrg/feature/VSP-1351
Browse files Browse the repository at this point in the history
"Tell us what's important" onboarding page implementation for phone and tablet.
  • Loading branch information
flaviahandrea-vsp authored Jun 12, 2024
2 parents 72b1bd6 + af9748d commit 14c617d
Show file tree
Hide file tree
Showing 5 changed files with 501 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fun ArchiveOnboardingScreen(
viewModel: ArchiveOnboardingViewModel
) {
val context = LocalContext.current

val pagerState = rememberPagerState(initialPage = OnboardingPage.WELCOME_PAGE.value,
pageCount = { OnboardingPage.values().size })
val isTablet = viewModel.isTablet()
Expand All @@ -66,15 +67,26 @@ fun ArchiveOnboardingScreen(
typeName = context.getString(R.string.personal),
name = "",
goals = mutableStateListOf(),
priorities = ""
priorities = mutableStateListOf()
)
)
}

val isFirstProgressBarEmpty by viewModel.isFirstProgressBarEmpty.collectAsState()
val isSecondProgressBarEmpty by viewModel.isSecondProgressBarEmpty.collectAsState()
val isThirdProgressBarEmpty by viewModel.isThirdProgressBarEmpty.collectAsState()

val goals = rememberSaveable(
saver = listSaver(
save = { it.map { goal -> listOf(goal.type.ordinal, goal.description, goal.isChecked.value) } },
save = {
it.map { goal ->
listOf(
goal.type.ordinal,
goal.description,
goal.isChecked.value
)
}
},
restore = { restoredGoals ->
restoredGoals.map {
OnboardingGoal(
Expand All @@ -86,54 +98,63 @@ fun ArchiveOnboardingScreen(
}
)
) {
mutableStateListOf(
OnboardingGoal(
OnboardingGoalType.CAPTURE,
context.getString(R.string.goals_capture),
mutableStateOf(false)
),
OnboardingGoal(
OnboardingGoalType.DIGITIZE,
context.getString(R.string.goals_digitize),
mutableStateOf(false)
),
OnboardingGoal(
OnboardingGoalType.COLLABORATE,
context.getString(R.string.goals_collaborate),
mutableStateOf(false)
),
OnboardingGoal(
OnboardingGoalType.CREATE_AN_ARCHIVE,
context.getString(R.string.goals_create_an_archive),
mutableStateOf(false)
),
OnboardingGoal(
OnboardingGoalType.SHARE,
context.getString(R.string.goals_share),
mutableStateOf(false)
),
viewModel.createOnboardingGoals(context).map { (ordinal, description) ->
OnboardingGoal(
OnboardingGoalType.CREATE_A_PLAN,
context.getString(R.string.goals_create_a_plan),
mutableStateOf(false)
),
OnboardingGoal(
OnboardingGoalType.ORGANIZE,
context.getString(R.string.goals_organize),
mutableStateOf(false)
),
OnboardingGoal(
OnboardingGoalType.SOMETHING_ELSE,
context.getString(R.string.goals_something_else),
mutableStateOf(false)
),
type = OnboardingGoalType.values()[ordinal],
description = description,
isChecked = mutableStateOf(false)
)
}.toMutableStateList()
}

val priorities = rememberSaveable(
saver = listSaver(
save = {
it.map { priority ->
listOf(
priority.type.ordinal,
priority.description,
priority.isChecked.value
)
}
},
restore = { restoredPriorities ->
restoredPriorities.map {
OnboardingPriority(
type = OnboardingPriorityType.values()[it[0] as Int],
description = it[1] as String,
isChecked = mutableStateOf(it[2] as Boolean)
)
}.toMutableStateList()
}
)
) {
viewModel.createOnboardingPriorities(context).map { (ordinal, description) ->
OnboardingPriority(
type = OnboardingPriorityType.values()[ordinal],
description = description,
isChecked = mutableStateOf(false)
)
}.toMutableStateList()
}

LaunchedEffect(pagerState.currentPage) {
when (pagerState.currentPage) {
OnboardingPage.ARCHIVE_NAME_PAGE.value -> viewModel.updateSecondProgressBarEmpty(true)
OnboardingPage.GOALS_PAGE.value -> viewModel.updateSecondProgressBarEmpty(false)
OnboardingPage.ARCHIVE_NAME_PAGE.value -> {
viewModel.updateFirstProgressBarEmpty(false)
viewModel.updateSecondProgressBarEmpty(true)
}

OnboardingPage.GOALS_PAGE.value -> {
viewModel.updateFirstProgressBarEmpty(true)
viewModel.updateSecondProgressBarEmpty(false)
viewModel.updateThirdProgressBarEmpty(true)
}

OnboardingPage.PRIORITIES_PAGE.value -> {
viewModel.updateSecondProgressBarEmpty(true)
viewModel.updateThirdProgressBarEmpty(false)
}
}
}

Expand Down Expand Up @@ -172,7 +193,7 @@ fun ArchiveOnboardingScreen(
progressIndicatorHeight,
horizontalPaddingDp,
spacerPaddingDp,
isEmpty = false
isFirstProgressBarEmpty
)

OnboardingProgressIndicator(
Expand All @@ -186,7 +207,7 @@ fun ArchiveOnboardingScreen(
progressIndicatorHeight,
horizontalPaddingDp,
spacerPaddingDp,
isEmpty = true
isThirdProgressBarEmpty
)
}
}
Expand Down Expand Up @@ -223,7 +244,17 @@ fun ArchiveOnboardingScreen(
horizontalPaddingDp = horizontalPaddingDp,
pagerState = pagerState,
newArchive = newArchive,
goals
goals = goals
)
}

OnboardingPage.PRIORITIES_PAGE.value -> {
PrioritiesPage(
isTablet = isTablet,
horizontalPaddingDp = horizontalPaddingDp,
pagerState = pagerState,
newArchive = newArchive,
priorities = priorities
)
}
}
Expand Down Expand Up @@ -265,7 +296,7 @@ data class NewArchive(
var typeName: String,
var name: String,
var goals: List<OnboardingGoal>,
var priorities: String?
var priorities: List<OnboardingPriority>
)

enum class OnboardingPage(val value: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ private fun PhoneBody(
buttonColor = ButtonColor.LIGHT, text = stringResource(id = R.string.next)
) {
newArchive.goals = goals
// coroutineScope.launch {
// pagerState.animateScrollToPage(OnboardingPage.PRIORITIES_PAGE.value)
// }
coroutineScope.launch {
pagerState.animateScrollToPage(OnboardingPage.PRIORITIES_PAGE.value)
}
}
}
}
Expand Down Expand Up @@ -343,9 +343,9 @@ private fun TabletBody(
buttonColor = ButtonColor.LIGHT, text = stringResource(id = R.string.next)
) {
newArchive.goals = goals
// coroutineScope.launch {
// pagerState.animateScrollToPage(OnboardingPage.PRIORITIES_PAGE.value)
// }
coroutineScope.launch {
pagerState.animateScrollToPage(OnboardingPage.PRIORITIES_PAGE.value)
}
}
}
}
Expand Down
Loading

0 comments on commit 14c617d

Please sign in to comment.