Skip to content

Commit a66d5c0

Browse files
committed
adding some crashfixes
1 parent bf3f024 commit a66d5c0

4 files changed

Lines changed: 20 additions & 14 deletions

File tree

app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -412,19 +412,23 @@ class MainActivity : SimpleActivity() {
412412
private fun openPath(path: String) {
413413
openFile(path, false) {
414414
val title = path.getFilenameFromPath()
415-
val fileText = it.readText().trim()
416-
val checklistItems = fileText.parseChecklistItems()
417-
val note = if (checklistItems != null) {
418-
Note(null, title.substringBeforeLast('.'), fileText, TYPE_CHECKLIST)
419-
} else {
420-
Note(null, title, "", TYPE_TEXT, path)
421-
}
415+
try {
416+
val fileText = it.readText().trim()
417+
val checklistItems = fileText.parseChecklistItems()
418+
val note = if (checklistItems != null) {
419+
Note(null, title.substringBeforeLast('.'), fileText, TYPE_CHECKLIST)
420+
} else {
421+
Note(null, title, "", TYPE_TEXT, path)
422+
}
422423

423-
if (mNotes.any { it.title.equals(note.title, true) }) {
424-
note.title += " (file)"
425-
}
424+
if (mNotes.any { it.title.equals(note.title, true) }) {
425+
note.title += " (file)"
426+
}
426427

427-
addNewNote(note)
428+
addNewNote(note)
429+
} catch (e: Exception) {
430+
showErrorToast(e)
431+
}
428432
}
429433
}
430434

app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/NotesPagerAdapter.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
2222
val bundle = Bundle()
2323
val note = notes[position]
2424
val id = note.id
25-
bundle.putLong(NOTE_ID, id!!)
25+
if (id != null) {
26+
bundle.putLong(NOTE_ID, id)
27+
}
2628

2729
if (fragments.containsKey(position)) {
2830
return fragments[position]!!

app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/ChecklistFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
3131

3232
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
3333
view = inflater.inflate(R.layout.fragment_checklist, container, false) as ViewGroup
34-
noteId = arguments!!.getLong(NOTE_ID)
34+
noteId = arguments!!.getLong(NOTE_ID, 0L)
3535
return view
3636
}
3737

app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class TextFragment : NoteFragment() {
4242

4343
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
4444
view = inflater.inflate(R.layout.fragment_text, container, false) as ViewGroup
45-
noteId = arguments!!.getLong(NOTE_ID)
45+
noteId = arguments!!.getLong(NOTE_ID, 0L)
4646
retainInstance = true
4747

4848
val layoutToInflate = if (config!!.enableLineWrap) R.layout.note_view_static else R.layout.note_view_horiz_scrollable

0 commit comments

Comments
 (0)