Skip to content

Commit bab506a

Browse files
committed
v2.4.1 feat(fixes) stability improvements and fixes
Summary of Fixes: 1. Fixed Data Loss (Persistence): ◦ Removed fallbackToDestructiveMigration(dropAllTables = true) from the Room database builder in AppModule.kt. ◦ This prevents the app from automatically wiping all your notes and data whenever a database schema change occurs during an update. 2. Enabled Image Loading: ◦ Integrated the Coil image loading library into the project. ◦ Updated the EditorScreen to use AsyncImage. Images attached to your notes will now render correctly instead of showing a placeholder icon. 3. Default to Read Mode: ◦ Updated the EditorScreen logic to automatically open existing notes in Preview (Read) Mode. ◦ New notes will still open in Edit Mode by default so you can start typing immediately. ◦ You can toggle between modes using the Edit/Preview icon in the top toolbar. Technical Details: • Dependencies: Added coil-compose and coil-network-okhttp to libs.versions.toml and build.gradle.kts. • ViewModel: Added isExistingNote property to EditorViewModel to help the UI decide the initial view mode. • Database: Stabilized NoteDatabase initialization in app/src/main/kotlin/com/example/notesapp/di/AppModule.kt. Signed-off-by: Magpiny <magpinyb@gmail.com>
1 parent 6038e2f commit bab506a

6 files changed

Lines changed: 22 additions & 6 deletions

File tree

.idea/misc.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.

app/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ dependencies {
7171
implementation(libs.androidx.compose.material.icons.extended)
7272
implementation(libs.androidx.navigation.compose)
7373

74+
implementation(libs.coil.compose)
75+
implementation(libs.coil.network)
76+
7477
implementation(libs.androidx.room.runtime)
7578
implementation(libs.androidx.room.ktx)
7679
ksp(libs.androidx.room.compiler)

app/src/main/kotlin/com/example/notesapp/di/AppModule.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ abstract class AppModule {
5656
context,
5757
NoteDatabase::class.java,
5858
"notes_db"
59-
).fallbackToDestructiveMigration(dropAllTables = true)
60-
.build()
59+
).build()
6160
}
6261

6362
@Provides

app/src/main/kotlin/com/example/notesapp/presentation/editor/EditorScreen.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import com.mikepenz.markdown.m3.markdownColor
4646
import com.mikepenz.markdown.m3.markdownTypography
4747
import com.example.notesapp.presentation.components.ColorPicker
4848
import com.example.notesapp.presentation.components.WaveformVisualizer
49+
import coil3.compose.AsyncImage
4950

5051
/**
5152
* Full-screen editor for creating and modifying notes.
@@ -60,7 +61,12 @@ fun EditorScreen(
6061
val context = LocalContext.current
6162
val (showLabelDialog, setShowLabelDialog) = remember { mutableStateOf(value = false) }
6263
val (showDeleteDialog, setShowDeleteDialog) = remember { mutableStateOf(value = false) }
63-
var isPreviewMode by remember { mutableStateOf(value = false) }
64+
65+
// Default to Preview mode for existing notes, Edit mode for new ones
66+
var isPreviewMode by remember {
67+
mutableStateOf<Boolean>(viewModel.isExistingNote)
68+
}
69+
6470
var showMenu by remember { mutableStateOf(value = false) }
6571
val scrollState = rememberScrollState()
6672

@@ -326,8 +332,12 @@ fun EditorScreen(
326332
.background(MaterialTheme.colorScheme.surfaceVariant)
327333
) {
328334
if (attachment.type == AttachmentType.IMAGE) {
329-
// In a real app, use Coils/Glide to load URI. Placeholder for now.
330-
Icon(Icons.Default.Image, null, modifier = Modifier.align(Alignment.Center))
335+
AsyncImage(
336+
model = attachment.localPath,
337+
contentDescription = null,
338+
modifier = Modifier.fillMaxSize(),
339+
contentScale = androidx.compose.ui.layout.ContentScale.Crop
340+
)
331341
} else if (attachment.type == AttachmentType.AUDIO) {
332342
IconButton(
333343
onClick = { viewModel.playAudio(attachment) },

app/src/main/kotlin/com/example/notesapp/presentation/editor/EditorViewModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class EditorViewModel @Inject constructor(
6666
) : ViewModel() {
6767

6868
private val noteId: String? = savedStateHandle["noteId"]
69+
val isExistingNote = !noteId.isNullOrBlank()
6970

7071
private val _uiState = MutableStateFlow(EditorUiState())
7172
val uiState = _uiState.asStateFlow()

gradle/libs.versions.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ testExtJunit = "1.2.1"
2828
espressoCore = "3.6.1"
2929
ksp = "2.3.9"
3030
arch-testing = "2.2.0"
31+
coil = "3.0.4"
3132

3233
[libraries]
3334
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
@@ -78,6 +79,8 @@ androidx-compose-ui-test = { group = "androidx.compose.ui", name = "ui-test" }
7879
androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
7980
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
8081
androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
82+
coil-compose = { group = "io.coil-kt.coil3", name = "coil-compose", version.ref = "coil" }
83+
coil-network = { group = "io.coil-kt.coil3", name = "coil-network-okhttp", version.ref = "coil" }
8184

8285
[plugins]
8386
androidApplication = { id = "com.android.application", version.ref = "agp" }

0 commit comments

Comments
 (0)