diff --git a/app/src/main/java/com/example/notesai/MainActivity.kt b/app/src/main/java/com/example/notesai/MainActivity.kt index c538c94..70f355a 100644 --- a/app/src/main/java/com/example/notesai/MainActivity.kt +++ b/app/src/main/java/com/example/notesai/MainActivity.kt @@ -4,7 +4,6 @@ import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.animation.* -import androidx.compose.animation.core.* import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -38,7 +37,6 @@ import java.text.SimpleDateFormat import java.util.Date import java.util.Locale import java.util.UUID -import androidx.compose.material.icons.outlined.Star import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material3.HorizontalDivider as Divider @@ -56,6 +54,7 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.zIndex +import com.example.notesai.data.local.DataStoreManager import kotlinx.coroutines.delay // Data Classes diff --git a/app/src/main/java/com/example/notesai/DataStoreManager.kt b/app/src/main/java/com/example/notesai/data/local/DataStoreManager.kt similarity index 83% rename from app/src/main/java/com/example/notesai/DataStoreManager.kt rename to app/src/main/java/com/example/notesai/data/local/DataStoreManager.kt index 216ec9f..7c8fc61 100644 --- a/app/src/main/java/com/example/notesai/DataStoreManager.kt +++ b/app/src/main/java/com/example/notesai/data/local/DataStoreManager.kt @@ -1,16 +1,20 @@ -@file:OptIn(kotlinx.serialization.InternalSerializationApi::class) +@file:OptIn(InternalSerializationApi::class) -package com.example.notesai +package com.example.notesai.data.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.emptyPreferences import androidx.datastore.preferences.core.stringPreferencesKey import androidx.datastore.preferences.preferencesDataStore +import com.example.notesai.Category +import com.example.notesai.Note import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.map +import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import kotlinx.serialization.Serializable @@ -53,7 +57,7 @@ class DataStoreManager(private val context: Context) { val categoriesFlow: Flow> = context.dataStore.data .catch { exception -> if (exception is IOException) { - emit(androidx.datastore.preferences.core.emptyPreferences()) + emit(emptyPreferences()) } else { throw exception } @@ -72,7 +76,7 @@ class DataStoreManager(private val context: Context) { val notesFlow: Flow> = context.dataStore.data .catch { exception -> if (exception is IOException) { - emit(androidx.datastore.preferences.core.emptyPreferences()) + emit(emptyPreferences()) } else { throw exception } @@ -81,7 +85,16 @@ class DataStoreManager(private val context: Context) { val jsonString = preferences[NOTES_KEY] ?: "[]" try { json.decodeFromString>(jsonString).map { - Note(it.id, it.categoryId, it.title, it.content, it.timestamp, it.isArchived, it.isDeleted, it.isPinned) + Note( + it.id, + it.categoryId, + it.title, + it.content, + it.timestamp, + it.isArchived, + it.isDeleted, + it.isPinned + ) } } catch (e: Exception) { emptyList() diff --git a/app/src/main/java/com/example/notesai/data/local/PreferencesKeys.kt b/app/src/main/java/com/example/notesai/data/local/PreferencesKeys.kt new file mode 100644 index 0000000..55bc145 --- /dev/null +++ b/app/src/main/java/com/example/notesai/data/local/PreferencesKeys.kt @@ -0,0 +1,9 @@ +// File: data/local/PreferencesKeys.kt +package com.example.notesai.data.local + +import androidx.datastore.preferences.core.stringPreferencesKey + +object PreferencesKeys { + val CATEGORIES_KEY = stringPreferencesKey("categories") + val NOTES_KEY = stringPreferencesKey("notes") +} \ No newline at end of file