Skip to content

Commit 4739034

Browse files
added screen to onboarding flow
1 parent ae1b752 commit 4739034

5 files changed

Lines changed: 84 additions & 11 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

app/src/main/java/com/cornellappdev/uplift/ui/MainNavigationWrapper.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import com.cornellappdev.uplift.ui.screens.classes.ClassDetailScreen
4040
import com.cornellappdev.uplift.ui.screens.classes.ClassScreen
4141
import com.cornellappdev.uplift.ui.screens.gyms.GymDetailScreen
4242
import com.cornellappdev.uplift.ui.screens.gyms.HomeScreen
43+
import com.cornellappdev.uplift.ui.screens.onboarding.GoalPromptScreen
4344
import com.cornellappdev.uplift.ui.screens.onboarding.ProfileCreationScreen
4445
import com.cornellappdev.uplift.ui.screens.onboarding.SignInPromptScreen
4546
import com.cornellappdev.uplift.ui.screens.profile.ProfileScreen
@@ -237,6 +238,9 @@ fun MainNavigationWrapper(
237238
composable<UpliftRootRoute.ProfileCreation> {
238239
ProfileCreationScreen()
239240
}
241+
composable<UpliftRootRoute.GoalsPrompt> {
242+
GoalPromptScreen()
243+
}
240244
composable<UpliftRootRoute.CapacityReminders> {
241245
CapacityReminderScreen()
242246
}
@@ -329,6 +333,10 @@ sealed class UpliftRootRoute {
329333
@Serializable
330334
data object Profile : UpliftRootRoute()
331335

336+
@Serializable
337+
data object GoalsPrompt : UpliftRootRoute()
338+
339+
332340
@Serializable
333341
data object CapacityReminders : UpliftRootRoute()
334342

app/src/main/java/com/cornellappdev/uplift/ui/screens/onboarding/GoalsPromptScreen.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ import androidx.compose.ui.tooling.preview.Preview
3030
import androidx.compose.ui.unit.dp
3131
import androidx.compose.ui.unit.sp
3232
import androidx.credentials.Credential
33+
import androidx.hilt.navigation.compose.hiltViewModel
34+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
3335
import com.cornellappdev.uplift.ui.components.goalsetting.GoalSlider
3436
import com.cornellappdev.uplift.ui.components.onboarding.auth.LogInButton
37+
import com.cornellappdev.uplift.ui.viewmodels.onboarding.GoalsPromptViewModel
3538
import com.cornellappdev.uplift.util.GRAY01
3639
import com.cornellappdev.uplift.util.montserratFamily
3740

@@ -43,12 +46,11 @@ import com.cornellappdev.uplift.util.montserratFamily
4346
@OptIn(ExperimentalMaterial3Api::class)
4447
@Composable
4548
fun GoalPromptScreen(
46-
/* TODO: Replace functions with viewmodel calls */
47-
goalValue: Float,
48-
onGoalValueChange: (Float) -> Unit,
49-
onSignInWithGoogle: (credential: Credential) -> Unit,
50-
onSkip: () -> Unit
49+
viewModel: GoalsPromptViewModel = hiltViewModel(),
5150
) {
51+
52+
val currentGoal by viewModel.goalValue.collectAsStateWithLifecycle()
53+
5254
Scaffold(
5355
topBar = {
5456
TopAppBar(
@@ -90,7 +92,7 @@ fun GoalPromptScreen(
9092
.verticalScroll(rememberScrollState()),
9193
horizontalAlignment = Alignment.CenterHorizontally
9294
) {
93-
GoalSlider(value = goalValue, onValueChange = onGoalValueChange)
95+
GoalSlider(value = currentGoal, onValueChange = { viewModel.onGoalValueChange(it) })
9496
}
9597

9698
// Buttons pinned to the bottom
@@ -101,8 +103,8 @@ fun GoalPromptScreen(
101103
horizontalAlignment = Alignment.CenterHorizontally,
102104
verticalArrangement = Arrangement.spacedBy(8.dp)
103105
) {
104-
LogInButton { onSignInWithGoogle }
105-
SkipButton { onSkip }
106+
LogInButton { viewModel.onSignInWithGoogle() }
107+
SkipButton { viewModel.onSkip() }
106108
}
107109
}
108110
}
@@ -111,6 +113,6 @@ fun GoalPromptScreen(
111113
@Preview(showBackground = true)
112114
@Composable
113115
fun GoalPromptScreenPreview() {
114-
var sliderVal by remember { mutableFloatStateOf(1f) }
115-
GoalPromptScreen(goalValue = sliderVal, onGoalValueChange = { sliderVal = it }, {}, {})
116+
var sliderVal by remember { mutableFloatStateOf(0f) }
117+
GoalPromptScreen()
116118
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.cornellappdev.uplift.ui.viewmodels.onboarding
2+
3+
import android.net.Uri
4+
import android.util.Log
5+
import androidx.lifecycle.viewModelScope
6+
import com.cornellappdev.uplift.data.repositories.UserInfoRepository
7+
import com.cornellappdev.uplift.ui.UpliftRootRoute
8+
import com.cornellappdev.uplift.ui.nav.RootNavigationRepository
9+
import com.cornellappdev.uplift.ui.viewmodels.UpliftViewModel
10+
import dagger.hilt.android.lifecycle.HiltViewModel
11+
import kotlinx.coroutines.flow.MutableStateFlow
12+
import kotlinx.coroutines.flow.StateFlow
13+
import kotlinx.coroutines.flow.asStateFlow
14+
import kotlinx.coroutines.launch
15+
import javax.inject.Inject
16+
17+
data class GoalsPromptUiState(
18+
val name: String = "",
19+
val imageUri: Uri? = null
20+
)
21+
22+
@HiltViewModel
23+
class GoalsPromptViewModel @Inject constructor(
24+
private val userInfoRepository: UserInfoRepository,
25+
private val rootNavigationRepository: RootNavigationRepository,
26+
) : UpliftViewModel<GoalsPromptUiState>(GoalsPromptUiState()) {
27+
28+
private val _goalValue = MutableStateFlow(0f)
29+
val goalValue: StateFlow<Float> = _goalValue.asStateFlow()
30+
31+
init {
32+
viewModelScope.launch {
33+
// TODO: Change this later to reflect correct inputs
34+
val user = userInfoRepository.getFirebaseUser()
35+
val name = user?.displayName ?: ""
36+
applyMutation {
37+
copy(name = name)
38+
}
39+
}
40+
}
41+
42+
fun onGoalValueChange(newValue: Float) {
43+
_goalValue.value = newValue
44+
}
45+
46+
// TODO: Change skip and google sign in to reflect correct behavior
47+
fun onSkip() {
48+
navigateToHome()
49+
}
50+
51+
fun onSignInWithGoogle() {
52+
navigateToHome()
53+
}
54+
55+
fun navigateToHome() {
56+
rootNavigationRepository.navigate(UpliftRootRoute.Home)
57+
}
58+
}

app/src/main/java/com/cornellappdev/uplift/ui/viewmodels/onboarding/ProfileCreationViewModel.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ProfileCreationViewModel @Inject constructor(
3838
val email = user?.email ?: ""
3939
val netId = email.substring(0, email.indexOf('@'))
4040
if (userInfoRepository.createUser(email, name, netId)) {
41-
navigateToHome()
41+
navigateToGoals()
4242
} else {
4343
//TODO: Add error handling
4444
Log.e("Error", "User not created")
@@ -53,6 +53,11 @@ class ProfileCreationViewModel @Inject constructor(
5353
}
5454
}
5555

56+
private fun navigateToGoals() {
57+
rootNavigationRepository.navigate(UpliftRootRoute.GoalsPrompt)
58+
}
59+
60+
// Possibly get rid of this function
5661
private fun navigateToHome() {
5762
rootNavigationRepository.navigate(UpliftRootRoute.Home)
5863
}

0 commit comments

Comments
 (0)