Skip to content

Commit

Permalink
Fixing potential crash issues if data gets corrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
BijoySingh committed Feb 21, 2019
1 parent 16b8f71 commit 61cb834
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fun sort(notes: List<Note>, sortingTechnique: SortingTechnique): List<Note> {
SortingTechnique.ALPHABETICAL -> notes.sortedBy { note ->
val content = note.getAlphabets()
if (note.pinned || content.isBlank()) 0
else content[0].toInt()
else content[0].toUpperCase().toInt()
}
else -> notes.sortedByDescending { note ->
if (note.pinned) Long.MAX_VALUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.maubis.scarlet.base.core.note.INoteContainer
import com.maubis.scarlet.base.database.room.folder.Folder
import com.maubis.scarlet.base.database.room.note.Note
import com.maubis.scarlet.base.database.room.note.NoteDao
import com.maubis.scarlet.base.note.applySanityChecks
import java.util.concurrent.ConcurrentHashMap

class NotesProvider {
Expand Down Expand Up @@ -96,6 +97,7 @@ class NotesProvider {
return
}
database().all.forEach {
it.applySanityChecks()
notes[it.uuid] = it
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.maubis.scarlet.base.note

import android.content.Context
import android.content.Intent
import android.util.Log
import com.github.bijoysingh.starter.util.DateFormatter
import com.google.gson.Gson
import com.maubis.markdown.Markdown
Expand All @@ -11,6 +12,7 @@ import com.maubis.scarlet.base.config.CoreConfig.Companion.tagsDb
import com.maubis.scarlet.base.core.format.Format
import com.maubis.scarlet.base.core.format.FormatType
import com.maubis.scarlet.base.core.note.NoteState
import com.maubis.scarlet.base.core.note.generateUUID
import com.maubis.scarlet.base.core.note.getFormats
import com.maubis.scarlet.base.core.note.getTagUUIDs
import com.maubis.scarlet.base.database.room.note.Note
Expand All @@ -20,6 +22,7 @@ import com.maubis.scarlet.base.note.creation.activity.CreateNoteActivity
import com.maubis.scarlet.base.note.creation.activity.INTENT_KEY_DISTRACTION_FREE
import com.maubis.scarlet.base.note.creation.activity.INTENT_KEY_NOTE_ID
import com.maubis.scarlet.base.note.creation.activity.ViewAdvancedNoteActivity
import com.maubis.scarlet.base.settings.sheet.sNoteDefaultColor
import com.maubis.scarlet.base.support.ui.ThemedActivity
import com.maubis.scarlet.base.support.utils.removeMarkdownHeaders
import java.util.*
Expand Down Expand Up @@ -276,11 +279,11 @@ fun Note.copy(context: Context) {
fun Note.applySanityChecks() {
folder = folder ?: ""
description = description ?: ""
timestamp = timestamp ?: 0L
color = color ?: 0
state = state ?: ""
timestamp = timestamp ?: System.currentTimeMillis()
color = color ?: sNoteDefaultColor
state = state ?: NoteState.DEFAULT.name
tags = tags ?: ""
uuid = uuid ?: ""
uuid = uuid ?: generateUUID()
}

fun Note.save(context: Context) {
Expand Down

0 comments on commit 61cb834

Please sign in to comment.