From c5db35da8dc17967038fdca48b9d31a02f5b4970 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Mar 2017 21:25:03 +0100 Subject: [PATCH] couple corrections to note saving --- .../notes/activities/MainActivity.kt | 6 +++--- .../notes/fragments/NoteFragment.kt | 12 +++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt index 68a5f649..581d8306 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt @@ -217,15 +217,15 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener { out.write(content) } } - noteSavedSuccessfully() + noteSavedSuccessfully(path.getFilenameFromPath()) } catch (e: Exception) { toast(R.string.unknown_error_occurred) } } - fun noteSavedSuccessfully() { + fun noteSavedSuccessfully(title: String) { if (config.displaySuccess) { - val message = String.format(getString(R.string.note_saved_successfully), mCurrentNote.title) + val message = String.format(getString(R.string.note_saved_successfully), title) toast(message) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt b/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt index 81750584..da6b8b92 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt @@ -26,8 +26,8 @@ import java.io.File class NoteFragment : Fragment() { var noteId = 0 - lateinit var view: ViewGroup lateinit var note: Note + lateinit var view: ViewGroup lateinit var mDb: DBHelper override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -58,6 +58,12 @@ class NoteFragment : Fragment() { return view } + override fun setMenuVisibility(menuVisible: Boolean) { + super.setMenuVisibility(menuVisible) + if (noteId != 0) + saveText() + } + fun saveText() { if (note.path.isNotEmpty() && !File(note.path).exists()) return @@ -67,8 +73,8 @@ class NoteFragment : Fragment() { if (newText != oldText) { note.value = newText saveNoteValue(note) + context.updateWidget() } - context.updateWidget() } fun showKeyboard() { @@ -80,7 +86,7 @@ class NoteFragment : Fragment() { private fun saveNoteValue(note: Note) { if (note.path.isEmpty()) { mDb.updateNoteValue(note) - (activity as MainActivity).noteSavedSuccessfully() + (activity as MainActivity).noteSavedSuccessfully(note.title) } else { (activity as MainActivity).saveNoteValueToFile(note.path, getCurrentNoteViewText()) }