11package com.simplemobiletools.notes.adapters
22
3+ import android.content.Context
34import android.os.Bundle
45import android.support.v4.app.Fragment
56import android.support.v4.app.FragmentManager
67import android.support.v4.app.FragmentStatePagerAdapter
78import android.util.SparseArray
9+ import android.view.ViewGroup
10+ import com.simplemobiletools.commons.extensions.toast
11+ import com.simplemobiletools.notes.R
812import com.simplemobiletools.notes.fragments.NoteFragment
913import com.simplemobiletools.notes.helpers.NOTE_ID
1014import com.simplemobiletools.notes.models.Note
1115
12- class NotesPagerAdapter (fm : FragmentManager , private val notes : List <Note >) : FragmentStatePagerAdapter(fm) {
16+ class NotesPagerAdapter (fm : FragmentManager , val notes : List <Note >, val context : Context ) : FragmentStatePagerAdapter(fm) {
1317 var fragments: SparseArray <NoteFragment > = SparseArray (5 )
1418
1519 override fun getCount () = notes.size
@@ -35,4 +39,12 @@ class NotesPagerAdapter(fm: FragmentManager, private val notes: List<Note>) : Fr
3539 fun saveCurrentNote (position : Int ) = fragments[position]?.saveText()
3640
3741 fun showKeyboard (position : Int ) = fragments[position]?.showKeyboard()
42+
43+ override fun finishUpdate (container : ViewGroup ? ) {
44+ try {
45+ super .finishUpdate(container)
46+ } catch (e: Exception ) {
47+ context.toast(R .string.unknown_error_occurred)
48+ }
49+ }
3850}
0 commit comments