adding some crashfixes

This commit is contained in:
tibbi 2019-12-07 15:22:32 +01:00
parent bf3f02461d
commit a66d5c0e89
4 changed files with 20 additions and 14 deletions

View File

@ -412,19 +412,23 @@ class MainActivity : SimpleActivity() {
private fun openPath(path: String) {
openFile(path, false) {
val title = path.getFilenameFromPath()
val fileText = it.readText().trim()
val checklistItems = fileText.parseChecklistItems()
val note = if (checklistItems != null) {
Note(null, title.substringBeforeLast('.'), fileText, TYPE_CHECKLIST)
} else {
Note(null, title, "", TYPE_TEXT, path)
}
try {
val fileText = it.readText().trim()
val checklistItems = fileText.parseChecklistItems()
val note = if (checklistItems != null) {
Note(null, title.substringBeforeLast('.'), fileText, TYPE_CHECKLIST)
} else {
Note(null, title, "", TYPE_TEXT, path)
}
if (mNotes.any { it.title.equals(note.title, true) }) {
note.title += " (file)"
}
if (mNotes.any { it.title.equals(note.title, true) }) {
note.title += " (file)"
}
addNewNote(note)
addNewNote(note)
} catch (e: Exception) {
showErrorToast(e)
}
}
}

View File

@ -22,7 +22,9 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
val bundle = Bundle()
val note = notes[position]
val id = note.id
bundle.putLong(NOTE_ID, id!!)
if (id != null) {
bundle.putLong(NOTE_ID, id)
}
if (fragments.containsKey(position)) {
return fragments[position]!!

View File

@ -31,7 +31,7 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
view = inflater.inflate(R.layout.fragment_checklist, container, false) as ViewGroup
noteId = arguments!!.getLong(NOTE_ID)
noteId = arguments!!.getLong(NOTE_ID, 0L)
return view
}

View File

@ -42,7 +42,7 @@ class TextFragment : NoteFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
view = inflater.inflate(R.layout.fragment_text, container, false) as ViewGroup
noteId = arguments!!.getLong(NOTE_ID)
noteId = arguments!!.getLong(NOTE_ID, 0L)
retainInstance = true
val layoutToInflate = if (config!!.enableLineWrap) R.layout.note_view_static else R.layout.note_view_horiz_scrollable