Skip to content

Commit

Permalink
Notepad 3.0 (release 2)
Browse files Browse the repository at this point in the history
* Work around crashes in rare cases when there could be more than one draft
* Fix logic for importing drafts from 2.x
  • Loading branch information
farmerbb committed Oct 5, 2022
1 parent 141191f commit 3a1d440
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ import com.farmerbb.notepad.model.SortOrder.TitleAscending
import com.farmerbb.notepad.model.SortOrder.TitleDescending
import com.squareup.sqldelight.runtime.coroutines.asFlow
import com.squareup.sqldelight.runtime.coroutines.mapToList
import com.squareup.sqldelight.runtime.coroutines.mapToOneOrDefault
import java.util.Date
import kotlinx.coroutines.flow.map

class NotepadRepository(
private val database: Database
) {
val savedDraftId get() = database.noteMetadataQueries.getDraftId().asFlow().mapToOneOrDefault(-1L)
val savedDraftId get() = database.noteMetadataQueries.getDraftId()
.asFlow()
.mapToList()
.map {
it.firstOrNull() ?: -1L
}

fun noteMetadataFlow(order: SortOrder) = with(database.noteMetadataQueries) {
when(order) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,19 @@ private class DataMigratorImpl(
if (!filename.isDigitsOnly() && filename != "draft") continue

val text = loadNote(filename)
val hasDraft = filename == draftFilename

val metadata = NoteMetadata(
metadataId = -1,
title = text.lines().first(),
date = Date(filename.toLong()),
hasDraft = false
hasDraft = hasDraft
)

val contents = NoteContents(
contentsId = -1,
text = text,
draftText = if (filename == draftFilename) draftText else null
draftText = if (hasDraft) draftText else null
)

with(database) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]

# Notepad
notepad-versionCode = "113"
notepad-versionCode = "114"
notepad-versionName = "3.0"

# Android SDK
Expand Down

0 comments on commit 3a1d440

Please sign in to comment.