couple corrections to note saving

This commit is contained in:
tibbi 2017-03-09 21:25:03 +01:00
parent 472a75e5c9
commit c5db35da8d
2 changed files with 12 additions and 6 deletions

View File

@ -217,15 +217,15 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
out.write(content) out.write(content)
} }
} }
noteSavedSuccessfully() noteSavedSuccessfully(path.getFilenameFromPath())
} catch (e: Exception) { } catch (e: Exception) {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
} }
} }
fun noteSavedSuccessfully() { fun noteSavedSuccessfully(title: String) {
if (config.displaySuccess) { 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) toast(message)
} }
} }

View File

@ -26,8 +26,8 @@ import java.io.File
class NoteFragment : Fragment() { class NoteFragment : Fragment() {
var noteId = 0 var noteId = 0
lateinit var view: ViewGroup
lateinit var note: Note lateinit var note: Note
lateinit var view: ViewGroup
lateinit var mDb: DBHelper lateinit var mDb: DBHelper
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
@ -58,6 +58,12 @@ class NoteFragment : Fragment() {
return view return view
} }
override fun setMenuVisibility(menuVisible: Boolean) {
super.setMenuVisibility(menuVisible)
if (noteId != 0)
saveText()
}
fun saveText() { fun saveText() {
if (note.path.isNotEmpty() && !File(note.path).exists()) if (note.path.isNotEmpty() && !File(note.path).exists())
return return
@ -67,8 +73,8 @@ class NoteFragment : Fragment() {
if (newText != oldText) { if (newText != oldText) {
note.value = newText note.value = newText
saveNoteValue(note) saveNoteValue(note)
context.updateWidget()
} }
context.updateWidget()
} }
fun showKeyboard() { fun showKeyboard() {
@ -80,7 +86,7 @@ class NoteFragment : Fragment() {
private fun saveNoteValue(note: Note) { private fun saveNoteValue(note: Note) {
if (note.path.isEmpty()) { if (note.path.isEmpty()) {
mDb.updateNoteValue(note) mDb.updateNoteValue(note)
(activity as MainActivity).noteSavedSuccessfully() (activity as MainActivity).noteSavedSuccessfully(note.title)
} else { } else {
(activity as MainActivity).saveNoteValueToFile(note.path, getCurrentNoteViewText()) (activity as MainActivity).saveNoteValueToFile(note.path, getCurrentNoteViewText())
} }