Skip to content

Commit e5d03c2

Browse files
committed
feat(ui):Updated the note item composable and added the theme selector
1 parent 90781f1 commit e5d03c2

File tree

26 files changed

+991
-1414
lines changed

26 files changed

+991
-1414
lines changed

.idea/caches/deviceStreaming.xml

Lines changed: 0 additions & 969 deletions
This file was deleted.

.idea/deploymentTargetSelector.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 36 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/opennotes/di/AppModule.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import dagger.hilt.InstallIn
2424
import dagger.hilt.components.SingletonComponent
2525
import javax.inject.Singleton
2626

27-
2827
@Module
2928
@InstallIn(SingletonComponent::class)
3029
object AppModule {

app/src/main/java/com/opennotes/feature_node/data/data_source/NoteDao.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import kotlinx.coroutines.flow.Flow
1010

1111
@Dao
1212
interface NoteDao {
13-
@Query(value="SELECT*FROM note")
13+
@Query(value = "SELECT * FROM note")
1414
fun getNotes():Flow<List<Note>>
1515

16-
@Query(value="SELECT*FROM note WHERE id=:id")
16+
@Query(value = "SELECT * FROM note WHERE id=:id")
1717
suspend fun getNoteById(id:Int): Note?
1818

1919
@Insert(onConflict=OnConflictStrategy.REPLACE)

app/src/main/java/com/opennotes/feature_node/data/repository/DataStoreRepository.kt

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import androidx.datastore.preferences.core.Preferences
55
import androidx.datastore.preferences.core.booleanPreferencesKey
66
import androidx.datastore.preferences.core.edit
77
import androidx.datastore.preferences.core.emptyPreferences
8+
import androidx.datastore.preferences.core.stringPreferencesKey
89
import com.opennotes.feature_node.presentation.settings.Settings
10+
import com.opennotes.feature_node.presentation.settings.ThemeMode
911
import kotlinx.coroutines.flow.Flow
1012
import kotlinx.coroutines.flow.catch
1113
import kotlinx.coroutines.flow.first
@@ -19,19 +21,44 @@ class DataStoreRepository @Inject constructor(
1921
private val dataStore: DataStore<Preferences>
2022
) {
2123
companion object {
24+
// New theme settings
25+
private val THEME_MODE = stringPreferencesKey("theme_mode")
26+
private val BLACK_THEME = booleanPreferencesKey("black_theme")
27+
28+
// Legacy settings for backward compatibility
2229
private val DARK_THEME = booleanPreferencesKey("dark_theme")
2330
private val AUTOMATIC_THEME = booleanPreferencesKey("automatic_theme")
24-
private val LIGHT_THEME = booleanPreferencesKey("LIGHT_THEME")
31+
private val LIGHT_THEME = booleanPreferencesKey("LIGHT_THEME")
2532
}
2633

2734
/**
2835
* Save the whole Settings object
2936
*/
3037
suspend fun saveSettings(settings: Settings) {
3138
dataStore.edit { prefs ->
32-
prefs[DARK_THEME] = settings.darkTheme
33-
prefs[AUTOMATIC_THEME] = settings.systemTheme
34-
prefs[LIGHT_THEME] = settings.lightTheme
39+
prefs[THEME_MODE] = settings.themeMode.name
40+
prefs[BLACK_THEME] = settings.blackTheme
41+
42+
// Also update legacy fields for compatibility
43+
when (settings.themeMode) {
44+
ThemeMode.SYSTEM -> {
45+
prefs[AUTOMATIC_THEME] = true
46+
prefs[DARK_THEME] = false
47+
prefs[LIGHT_THEME] = false
48+
}
49+
50+
ThemeMode.LIGHT -> {
51+
prefs[AUTOMATIC_THEME] = false
52+
prefs[DARK_THEME] = false
53+
prefs[LIGHT_THEME] = true
54+
}
55+
56+
ThemeMode.DARK -> {
57+
prefs[AUTOMATIC_THEME] = false
58+
prefs[DARK_THEME] = true
59+
prefs[LIGHT_THEME] = false
60+
}
61+
}
3562
}
3663
}
3764

@@ -46,22 +73,68 @@ class DataStoreRepository @Inject constructor(
4673
} else throw exception
4774
}
4875
.map { prefs ->
49-
val defaultSettings = Settings() // Use Settings class defaults
76+
val defaultSettings = Settings()
77+
78+
// Try to read new theme mode first
79+
val themeModeString = prefs[THEME_MODE]
80+
val themeMode = if (themeModeString != null) {
81+
try {
82+
ThemeMode.valueOf(themeModeString)
83+
} catch (e: IllegalArgumentException) {
84+
// If migration needed from legacy settings
85+
migrateLegacyThemeMode(prefs, defaultSettings)
86+
}
87+
} else {
88+
// Migration from legacy settings
89+
migrateLegacyThemeMode(prefs, defaultSettings)
90+
}
91+
5092
Settings(
93+
themeMode = themeMode,
94+
blackTheme = prefs[BLACK_THEME] ?: defaultSettings.blackTheme,
95+
// Legacy fields for compatibility
5196
darkTheme = prefs[DARK_THEME] ?: defaultSettings.darkTheme,
5297
systemTheme = prefs[AUTOMATIC_THEME] ?: defaultSettings.systemTheme,
5398
lightTheme = prefs[LIGHT_THEME] ?: defaultSettings.lightTheme
5499
)
55100
}
56101
}
57102

103+
private fun migrateLegacyThemeMode(prefs: Preferences, defaultSettings: Settings): ThemeMode {
104+
val systemTheme = prefs[AUTOMATIC_THEME] ?: defaultSettings.systemTheme
105+
val darkTheme = prefs[DARK_THEME] ?: defaultSettings.darkTheme
106+
val lightTheme = prefs[LIGHT_THEME] ?: defaultSettings.lightTheme
107+
108+
return when {
109+
systemTheme -> ThemeMode.SYSTEM
110+
lightTheme -> ThemeMode.LIGHT
111+
darkTheme -> ThemeMode.DARK
112+
else -> ThemeMode.SYSTEM
113+
}
114+
}
115+
58116
/**
59117
* Read Settings once (non-Flow) - Alternative approach
60118
*/
61119
suspend fun getSettings(): Settings {
62120
val prefs = dataStore.data.first()
63-
val defaultSettings = Settings() // Use Settings class defaults
121+
val defaultSettings = Settings()
122+
123+
val themeModeString = prefs[THEME_MODE]
124+
val themeMode = if (themeModeString != null) {
125+
try {
126+
ThemeMode.valueOf(themeModeString)
127+
} catch (e: IllegalArgumentException) {
128+
migrateLegacyThemeMode(prefs, defaultSettings)
129+
}
130+
} else {
131+
migrateLegacyThemeMode(prefs, defaultSettings)
132+
}
133+
64134
return Settings(
135+
themeMode = themeMode,
136+
blackTheme = prefs[BLACK_THEME] ?: defaultSettings.blackTheme,
137+
// Legacy fields for compatibility
65138
darkTheme = prefs[DARK_THEME] ?: defaultSettings.darkTheme,
66139
systemTheme = prefs[AUTOMATIC_THEME] ?: defaultSettings.systemTheme,
67140
lightTheme = prefs[LIGHT_THEME] ?: defaultSettings.lightTheme

app/src/main/java/com/opennotes/feature_node/domain/model/Note.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import com.opennotes.ui.theme.Violet
1414
data class Note(
1515
@Expose val title:String,
1616
@Expose val content:String,
17-
@Expose val timestamp: Long,
17+
@Expose val timestamp: Long,
1818
@Expose val color:Int,
1919
@PrimaryKey val id:Int?=null
2020
){
2121
companion object{
22-
val noteColors=listOf(RedOrange, LightGreen, Violet, BabyBlue, RedPink)
22+
val noteColors = listOf(RedOrange, LightGreen, Violet, BabyBlue, RedPink)
2323
}
2424
}
2525

app/src/main/java/com/opennotes/feature_node/presentation/MainActivity.kt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import androidx.activity.ComponentActivity
55
import androidx.activity.compose.setContent
66
import androidx.activity.viewModels
77
import androidx.compose.animation.ExperimentalAnimationApi
8+
import androidx.compose.animation.core.tween
9+
import androidx.compose.animation.fadeIn
10+
import androidx.compose.animation.fadeOut
11+
import androidx.compose.animation.slideInHorizontally
12+
import androidx.compose.animation.slideOutHorizontally
813
import androidx.compose.material3.MaterialTheme
914
import androidx.compose.material3.Surface
1015
import androidx.compose.runtime.LaunchedEffect
@@ -18,6 +23,7 @@ import androidx.navigation.compose.rememberNavController
1823
import androidx.navigation.navArgument
1924
import com.opennotes.feature_node.presentation.add_edit_note.AddEditNoteScreen
2025
import com.opennotes.feature_node.presentation.notes.NotesScreen
26+
import com.opennotes.feature_node.presentation.settings.AboutScreen
2127
import com.opennotes.feature_node.presentation.settings.SettingsScreen
2228
import com.opennotes.feature_node.presentation.settings.SettingsViewModel
2329
import com.opennotes.feature_node.presentation.util.Screen
@@ -41,21 +47,14 @@ class MainActivity : ComponentActivity() {
4147
setContent {
4248
val currentSettings by settingsViewModel.settings.collectAsState()
4349

44-
45-
LaunchedEffect(currentSettings) {
46-
android.util.Log.d("MainActivity",
47-
"Settings: systemTheme=${currentSettings.systemTheme}, " +
48-
"darkTheme=${currentSettings.darkTheme}, " +
49-
"lightTheme=${currentSettings.lightTheme}")
50-
}
51-
5250
OpenNotesTheme(settings = currentSettings) {
5351
Surface(color = MaterialTheme.colorScheme.background) {
5452
val navController = rememberNavController()
5553

5654
NavHost(
5755
navController = navController,
58-
startDestination = Screen.NotesScreen.route
56+
startDestination = Screen.NotesScreen.route,
57+
5958
) {
6059
composable(route = Screen.NotesScreen.route) {
6160
NotesScreen(navController = navController)
@@ -86,6 +85,13 @@ class MainActivity : ComponentActivity() {
8685
viewModel = settingsViewModel
8786
)
8887
}
88+
composable(route = Screen.AboutScreen.route) {
89+
AboutScreen(
90+
navController = navController,
91+
settingsViewModel = settingsViewModel
92+
)
93+
}
94+
8995
}
9096
}
9197
}

0 commit comments

Comments
 (0)