@@ -2,28 +2,26 @@ package com.simplemobiletools.notes.adapters
2
2
3
3
import android.app.Activity
4
4
import android.os.Bundle
5
- import android.support.v4.app.Fragment
6
5
import android.support.v4.app.FragmentManager
7
6
import android.support.v4.app.FragmentStatePagerAdapter
8
- import android.util.SparseArray
9
7
import android.view.ViewGroup
10
8
import com.simplemobiletools.commons.extensions.showErrorToast
11
9
import com.simplemobiletools.notes.fragments.NoteFragment
12
10
import com.simplemobiletools.notes.helpers.NOTE_ID
13
11
import com.simplemobiletools.notes.models.Note
14
12
15
13
class NotesPagerAdapter (fm : FragmentManager , val notes : List <Note >, val activity : Activity ) : FragmentStatePagerAdapter(fm) {
16
- var fragments: SparseArray < NoteFragment > = SparseArray ( 5 )
14
+ private var fragments: HashMap < Int , NoteFragment > = LinkedHashMap ( )
17
15
18
16
override fun getCount () = notes.size
19
17
20
- override fun getItem (position : Int ): Fragment {
18
+ override fun getItem (position : Int ): NoteFragment {
21
19
val bundle = Bundle ()
22
20
val id = notes[position].id
23
21
bundle.putInt(NOTE_ID , id)
24
22
25
- if (fragments.get (position) != null )
26
- return fragments[position]
23
+ if (fragments.containsKey (position))
24
+ return fragments[position]!!
27
25
28
26
val fragment = NoteFragment ()
29
27
fragment.arguments = bundle
@@ -53,6 +51,6 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
53
51
54
52
override fun destroyItem (container : ViewGroup , position : Int , `object `: Any ) {
55
53
super .destroyItem(container, position, `object `)
56
- fragments.removeAt (position)
54
+ fragments.remove (position)
57
55
}
58
56
}
0 commit comments