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
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.ksp)
alias(libs.plugins.hilt)
alias(libs.plugins.detekt)
}

Expand Down Expand Up @@ -91,6 +92,9 @@ dependencies {
// time (kotlinx.datetime)
implementation(libs.kotlinx.datetime)

// DataStore
implementation(libs.androidx.datastore.preferences)

// detekt plugins
detektPlugins(libs.detekt.formatting)
detektPlugins(libs.detekt.compose)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".FeelinApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/lyrics/feelin/FeelinApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.lyrics.feelin

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class FeelinApplication : Application()
2 changes: 2 additions & 0 deletions app/src/main/java/com/lyrics/feelin/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import com.lyrics.feelin.navigation.FeelinNavHost
import com.lyrics.feelin.presentation.designsystem.theme.FeelinTheme
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.lyrics.feelin.core.data.datasource.local

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "user_preferences")

@Singleton
class UserPreferencesDataStore @Inject constructor(
@ApplicationContext private val context: Context
) {
private object Keys {
val GENDER = stringPreferencesKey("gender")
val BIRTH_YEAR = intPreferencesKey("birth_year")
val NICKNAME = stringPreferencesKey("nickname")
val PROFILE_INDEX = intPreferencesKey("profile_index")
val IS_LOGGED_IN = stringPreferencesKey("is_logged_in")
}

val userData: Flow<UserData> = context.dataStore.data.map { preferences ->
UserData(
gender = preferences[Keys.GENDER],
birthYear = preferences[Keys.BIRTH_YEAR],
nickname = preferences[Keys.NICKNAME],
profileIndex = preferences[Keys.PROFILE_INDEX],
isLoggedIn = preferences[Keys.IS_LOGGED_IN] == "true"
)
}

val isLoggedIn: Flow<Boolean> = context.dataStore.data.map { preferences ->
preferences[Keys.IS_LOGGED_IN] == "true"
}

suspend fun saveGenderAndBirthYear(gender: String, birthYear: Int) {
context.dataStore.edit { preferences ->
preferences[Keys.GENDER] = gender
preferences[Keys.BIRTH_YEAR] = birthYear
}
}

suspend fun saveProfile(nickname: String, profileIndex: Int) {
context.dataStore.edit { preferences ->
preferences[Keys.NICKNAME] = nickname
preferences[Keys.PROFILE_INDEX] = profileIndex
}
}

suspend fun completeOnboarding() {
context.dataStore.edit { preferences ->
preferences[Keys.IS_LOGGED_IN] = "true"
}
}

suspend fun logout() {
context.dataStore.edit { preferences ->
preferences.clear()
}
}
}

data class UserData(
val gender: String? = null,
val birthYear: Int? = null,
val nickname: String? = null,
val profileIndex: Int? = null,
val isLoggedIn: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ package com.lyrics.feelin.navigation
sealed class FeelinDestination(
val route: String,
) {
object Home : FeelinDestination(route = "home")

object NoteSearch : FeelinDestination(route = "note_search")

object MyPage : FeelinDestination(route = "my_page")
// Navigation Graph Routes
object OnboardingGraph : FeelinDestination(route = "onboarding_graph")
object MainGraph : FeelinDestination(route = "main_graph")

// Onboarding Flow
object Login : FeelinDestination(route = "login")

object OnboardingTerms : FeelinDestination(route = "onboarding_terms")

object OnboardingGenderAge : FeelinDestination(route = "onboarding_gender_age")
object OnboardingProfile : FeelinDestination(route = "onboarding_profile")
object OnboardingWelcome : FeelinDestination(route = "onboarding_welcome")

// Main Flow (with Bottom Navigation)
object Home : FeelinDestination(route = "home")
object NoteSearch : FeelinDestination(route = "note_search")
object MyPage : FeelinDestination(route = "my_page")
}
Loading