Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions app/src/main/java/com/cornellappdev/score/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import com.cornellappdev.score.nav.root.RootNavigation
import com.cornellappdev.score.screen.FavoriteSport
import com.cornellappdev.score.screen.OnboardingFavoriteSportsScreen
import com.cornellappdev.score.screen.OnboardingProfileSelectScreen
import com.cornellappdev.score.screen.OnboardingScreen
import com.google.firebase.Firebase
Expand All @@ -20,6 +22,7 @@ import dagger.hilt.android.AndroidEntryPoint
private const val APP_PREFERENCES = "score_app_preferences"
private const val KEY_ONBOARDING_COMPLETED = "onboarding_completed"
private const val KEY_ONBOARDING_PROFILE_PICTURE = "onboarding_profile_picture"
private const val KEY_ONBOARDING_FAVORITE_SPORTS = "onboarding_favorite_sports"

private lateinit var firebaseAnalytics: FirebaseAnalytics

Expand All @@ -31,18 +34,22 @@ class MainActivity : AppCompatActivity() {

val preferences = getSharedPreferences(APP_PREFERENCES, MODE_PRIVATE)
val onboardingCompleted = preferences.getBoolean(KEY_ONBOARDING_COMPLETED, false)
val savedFavoriteSportKeys = preferences
.getStringSet(KEY_ONBOARDING_FAVORITE_SPORTS, emptySet())
.orEmpty()
.joinToString("|")

setContent {
var onboardingStep by rememberSaveable {
mutableIntStateOf(if (onboardingCompleted) 2 else 0)
mutableIntStateOf(if (onboardingCompleted) 3 else 0)
}

val completeOnboarding = remember {
{
preferences.edit()
.putBoolean(KEY_ONBOARDING_COMPLETED, true)
.apply()
onboardingStep = 2
onboardingStep = 3
}
}

Expand All @@ -57,7 +64,20 @@ class MainActivity : AppCompatActivity() {
preferences.edit()
.putString(KEY_ONBOARDING_PROFILE_PICTURE, selectedPicture.name)
.apply()
completeOnboarding()
onboardingStep = 2
}
)
2 -> OnboardingFavoriteSportsScreen(
initiallySelectedKeys = savedFavoriteSportKeys,
onFinish = { selectedSports ->
preferences.edit()
.putStringSet(
KEY_ONBOARDING_FAVORITE_SPORTS,
selectedSports.map(FavoriteSport::storageKey).toSet()
)
.putBoolean(KEY_ONBOARDING_COMPLETED, true)
.apply()
onboardingStep = 3
}
)
else -> RootNavigation()
Expand Down
Loading
Loading