add some null checks at getting current text

This commit is contained in:
tibbi 2017-06-16 20:22:37 +02:00
parent 45e2e0c530
commit de13dbd5c8
2 changed files with 4 additions and 3 deletions

View File

@ -214,7 +214,8 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
private fun exportAsFile() { private fun exportAsFile() {
ExportAsDialog(this, mCurrentNote) { ExportAsDialog(this, mCurrentNote) {
exportNoteValueToFile(it, getCurrentNoteText()) if (getCurrentNoteText()?.isNotEmpty() == true)
exportNoteValueToFile(it, getCurrentNoteText()!!)
} }
} }
@ -307,7 +308,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
private fun shareText() { private fun shareText() {
val text = getCurrentNoteText() val text = getCurrentNoteText()
if (text.isEmpty()) { if (text == null || text.isEmpty()) {
toast(R.string.cannot_share_empty_text) toast(R.string.cannot_share_empty_text)
return return
} }

View File

@ -34,7 +34,7 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
override fun getPageTitle(position: Int) = notes[position].title override fun getPageTitle(position: Int) = notes[position].title
fun getCurrentNoteViewText(position: Int) = fragments[position].getCurrentNoteViewText() fun getCurrentNoteViewText(position: Int) = fragments[position]?.getCurrentNoteViewText()
fun saveCurrentNote(position: Int) = fragments[position]?.saveText() fun saveCurrentNote(position: Int) = fragments[position]?.saveText()