This commit is contained in:
Nikola Trubitsyn 2017-06-13 22:28:59 +03:00
parent d31c918b98
commit a9e466406c
3 changed files with 16 additions and 4 deletions

View File

@ -240,7 +240,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
}
}
private fun deleteNote(deleteFile: Boolean) {
fun deleteNote(deleteFile: Boolean) {
if (mNotes.size <= 1)
return

View File

@ -8,6 +8,7 @@ import com.simplemobiletools.notes.R
import com.simplemobiletools.notes.helpers.*
import com.simplemobiletools.notes.models.Note
import java.io.File
import java.io.FileNotFoundException
fun Context.getTextSize() =
when (config.fontSize) {
@ -30,9 +31,13 @@ fun Context.updateWidget() {
val Context.config: Config get() = Config.newInstance(this)
fun Context.getNoteStoredValue(note: Note): String {
fun Context.getNoteStoredValue(note: Note): String? {
return if (note.path.isNotEmpty()) {
File(note.path).readText()
try {
return File(note.path).readText()
} catch (e: FileNotFoundException) {
return null
}
} else {
note.value
}

View File

@ -98,7 +98,14 @@ class NoteFragment : Fragment() {
val config = context.config
view.notes_view.apply {
setText(context.getNoteStoredValue(note))
val fileContents = context.getNoteStoredValue(note)
if (fileContents == null) {
(activity as MainActivity).deleteNote(false)
return
}
setText(fileContents)
setColors(config.textColor, config.primaryColor, config.backgroundColor)
setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getTextSize())
gravity = getTextGravity()