Skip to content

Commit

Permalink
Merge pull request #279 from PermanentOrg/VSP-1398
Browse files Browse the repository at this point in the history
Chart your path to success - tablet
  • Loading branch information
flaviahandrea-vsp authored Jun 6, 2024
2 parents 53fcb2c + 5543806 commit 72b1bd6
Show file tree
Hide file tree
Showing 11 changed files with 441 additions and 186 deletions.
8 changes: 5 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ dependencies {
//==============================================================================================

//====================================== JETPACK COMPOSE =======================================
implementation 'androidx.compose.material3:material3:1.1.1'
implementation 'androidx.compose.material3:material3:1.2.1'
// Android Studio Preview support
implementation 'androidx.compose.ui:ui-tooling-preview:1.4.3'
implementation 'androidx.compose.ui:ui-tooling:1.4.3'
implementation 'androidx.compose.ui:ui-tooling-preview:1.6.7'
implementation 'androidx.compose.ui:ui-tooling:1.6.7'
implementation "androidx.compose.ui:ui:1.6.7"
implementation "androidx.constraintlayout:constraintlayout-compose:1.0.1"
// For embedding xml code in compose
// implementation 'androidx.compose.ui:ui-viewbinding:1.4.3'
// Integration with activities
Expand Down
2 changes: 1 addition & 1 deletion app/google-services.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"api_key": [
{
"current_key": ""
"current_key": " "
}
],
"services": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private fun TabletBody(
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 64.dp),
.padding(64.dp),
horizontalArrangement = Arrangement.spacedBy(64.dp),
) {
Column(
Expand Down Expand Up @@ -251,7 +251,7 @@ private fun PhoneBody(
Column(
modifier = Modifier
.fillMaxHeight()
.padding(vertical = 32.dp),
.padding(32.dp),
verticalArrangement = Arrangement.spacedBy(24.dp)
) {
val titleText = stringResource(id = R.string.create_your_archive_title, newArchive.typeName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.listSaver
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.runtime.toMutableStateList
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
Expand All @@ -35,18 +41,19 @@ import org.permanent.permanent.R
import org.permanent.permanent.models.ArchiveType
import org.permanent.permanent.ui.composeComponents.CustomProgressIndicator
import org.permanent.permanent.viewmodels.ArchiveOnboardingViewModel
import java.util.EnumMap

@Composable
fun ArchiveOnboardingScreen(
viewModel: ArchiveOnboardingViewModel
) {
val context = LocalContext.current
val blue900Color = Color(ContextCompat.getColor(context, R.color.blue900))
val blueLighterColor = Color(ContextCompat.getColor(context, R.color.blueLighter))
val pagerState = rememberPagerState(initialPage = OnboardingPage.WELCOME_PAGE.value)
val pagerState = rememberPagerState(initialPage = OnboardingPage.WELCOME_PAGE.value,
pageCount = { OnboardingPage.values().size })
val isTablet = viewModel.isTablet()

val blue900Color = remember { Color(ContextCompat.getColor(context, R.color.blue900)) }
val blueLighterColor = remember { Color(ContextCompat.getColor(context, R.color.blueLighter)) }

val horizontalPaddingDp = if (isTablet) 64.dp else 32.dp
val topPaddingDp = if (isTablet) 32.dp else 24.dp
val spacerPaddingDp = if (isTablet) 32.dp else 8.dp
Expand All @@ -58,12 +65,78 @@ fun ArchiveOnboardingScreen(
type = ArchiveType.PERSON,
typeName = context.getString(R.string.personal),
name = "",
goals = EnumMap(OnboardingGoal::class.java),
goals = mutableStateListOf(),
priorities = ""
)
)
}

val isSecondProgressBarEmpty by viewModel.isSecondProgressBarEmpty.collectAsState()
val goals = rememberSaveable(
saver = listSaver(
save = { it.map { goal -> listOf(goal.type.ordinal, goal.description, goal.isChecked.value) } },
restore = { restoredGoals ->
restoredGoals.map {
OnboardingGoal(
type = OnboardingGoalType.values()[it[0] as Int],
description = it[1] as String,
isChecked = mutableStateOf(it[2] as Boolean)
)
}.toMutableStateList()
}
)
) {
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)
),
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)
),
)
}

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

Box(
modifier = Modifier
.fillMaxSize()
Expand All @@ -78,70 +151,81 @@ fun ArchiveOnboardingScreen(
Column(
modifier = Modifier
.fillMaxSize()
.padding(
start = horizontalPaddingDp, end = horizontalPaddingDp, top = topPaddingDp
), verticalArrangement = Arrangement.Top
.padding(top = topPaddingDp),
verticalArrangement = Arrangement.Top
) {
Image(
painter = painterResource(id = R.drawable.img_logo),
contentDescription = "Logo",
modifier = Modifier.size(40.dp)
modifier = Modifier
.size(40.dp)
.padding(horizontal = horizontalPaddingDp)
)

Box(
modifier = Modifier.padding(top = topPaddingDp)
modifier = Modifier.padding(
top = topPaddingDp, start = horizontalPaddingDp, end = horizontalPaddingDp
)
) {
Row(horizontalArrangement = Arrangement.spacedBy(spacerPaddingDp)) {
OnboardingProgressIndicator(
progressIndicatorHeight, horizontalPaddingDp, spacerPaddingDp, 100
progressIndicatorHeight,
horizontalPaddingDp,
spacerPaddingDp,
isEmpty = false
)

OnboardingProgressIndicator(
progressIndicatorHeight, horizontalPaddingDp, spacerPaddingDp, 0
progressIndicatorHeight,
horizontalPaddingDp,
spacerPaddingDp,
isSecondProgressBarEmpty
)

OnboardingProgressIndicator(
progressIndicatorHeight, horizontalPaddingDp, spacerPaddingDp, 0
progressIndicatorHeight,
horizontalPaddingDp,
spacerPaddingDp,
isEmpty = true
)
}
}

HorizontalPager(
pageCount = OnboardingPage.values().size,
state = pagerState,
userScrollEnabled = false
state = pagerState, userScrollEnabled = false
) { page ->
when (page) {
OnboardingPage.WELCOME_PAGE.value -> WelcomePage(
isTablet = isTablet,
pagerState = pagerState,
accountName = viewModel.getAccountName().value
)
OnboardingPage.WELCOME_PAGE.value -> {
WelcomePage(
isTablet = isTablet,
pagerState = pagerState,
accountName = viewModel.getAccountName().value
)
}

OnboardingPage.ARCHIVE_TYPE_PAGE.value -> ArchiveTypePage(isTablet = isTablet,
pagerState = pagerState,
onArchiveTypeClick = { type: ArchiveType, typeName: String ->
val archive = NewArchive(
type = type,
typeName = typeName,
name = "",
goals = EnumMap(OnboardingGoal::class.java),
priorities = ""
)
newArchive = archive
})

OnboardingPage.ARCHIVE_NAME_PAGE.value -> ArchiveNamePage(
isTablet = isTablet,
pagerState = pagerState,
newArchive = newArchive
)
OnboardingPage.ARCHIVE_TYPE_PAGE.value -> {
ArchiveTypePage(isTablet = isTablet,
pagerState = pagerState,
onArchiveTypeClick = { type: ArchiveType, typeName: String ->
newArchive = newArchive.copy(type = type, typeName = typeName)
})
}

OnboardingPage.GOALS_PAGE.value -> GoalsPage(
isTablet = isTablet,
pagerState = pagerState,
newArchive = newArchive
)
OnboardingPage.ARCHIVE_NAME_PAGE.value -> {
ArchiveNamePage(
isTablet = isTablet, pagerState = pagerState, newArchive = newArchive
)
}

OnboardingPage.GOALS_PAGE.value -> {
GoalsPage(
isTablet = isTablet,
horizontalPaddingDp = horizontalPaddingDp,
pagerState = pagerState,
newArchive = newArchive,
goals
)
}
}
}
}
Expand All @@ -150,7 +234,7 @@ fun ArchiveOnboardingScreen(

@Composable
fun OnboardingProgressIndicator(
height: Dp, horizontalPaddingDp: Dp, spacerPaddingDp: Dp, percent: Int
height: Dp, horizontalPaddingDp: Dp, spacerPaddingDp: Dp, isEmpty: Boolean
) {
val context = LocalContext.current
val whiteSuperTransparentColor =
Expand All @@ -172,33 +256,18 @@ fun OnboardingProgressIndicator(
purpleColor, accentColor
)
),
percent
if (isEmpty) 0 else 100
)
}

data class NewArchive(
var type: ArchiveType,
var typeName: String,
var name: String,
var goals: EnumMap<OnboardingGoal, Boolean>,
var goals: List<OnboardingGoal>,
var priorities: String?
)

enum class OnboardingGoal {
CAPTURE,
DIGITIZE,
COLLABORATE,
CREATE_AN_ARCHIVE,
SHARE,
CREATE_A_PLAN,
ORGANIZE,
SOMETHING_ELSE
}

enum class OnboardingPage(val value: Int) {
WELCOME_PAGE(0),
ARCHIVE_TYPE_PAGE(1),
ARCHIVE_NAME_PAGE(2),
GOALS_PAGE(3),
PRIORITIES_PAGE(4)
}
WELCOME_PAGE(0), ARCHIVE_TYPE_PAGE(1), ARCHIVE_NAME_PAGE(2), GOALS_PAGE(3), PRIORITIES_PAGE(4)
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private fun TabletBody(
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 64.dp),
.padding(64.dp),
horizontalArrangement = Arrangement.spacedBy(64.dp),
) {
Column(
Expand Down Expand Up @@ -177,7 +177,7 @@ private fun PhoneBody(
Column(
modifier = Modifier
.fillMaxHeight()
.padding(vertical = 32.dp),
.padding(32.dp),
verticalArrangement = Arrangement.spacedBy(24.dp)
) {
val titleText = stringResource(id = R.string.create_your_first_archive_title)
Expand Down
Loading

0 comments on commit 72b1bd6

Please sign in to comment.