Skip to content

Commit 0d79291

Browse files
committed
replace NoteFragments array with hashmap
1 parent 7ba767c commit 0d79291

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,26 @@ package com.simplemobiletools.notes.adapters
22

33
import android.app.Activity
44
import android.os.Bundle
5-
import android.support.v4.app.Fragment
65
import android.support.v4.app.FragmentManager
76
import android.support.v4.app.FragmentStatePagerAdapter
8-
import android.util.SparseArray
97
import android.view.ViewGroup
108
import com.simplemobiletools.commons.extensions.showErrorToast
119
import com.simplemobiletools.notes.fragments.NoteFragment
1210
import com.simplemobiletools.notes.helpers.NOTE_ID
1311
import com.simplemobiletools.notes.models.Note
1412

1513
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()
1715

1816
override fun getCount() = notes.size
1917

20-
override fun getItem(position: Int): Fragment {
18+
override fun getItem(position: Int): NoteFragment {
2119
val bundle = Bundle()
2220
val id = notes[position].id
2321
bundle.putInt(NOTE_ID, id)
2422

25-
if (fragments.get(position) != null)
26-
return fragments[position]
23+
if (fragments.containsKey(position))
24+
return fragments[position]!!
2725

2826
val fragment = NoteFragment()
2927
fragment.arguments = bundle
@@ -53,6 +51,6 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
5351

5452
override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
5553
super.destroyItem(container, position, `object`)
56-
fragments.removeAt(position)
54+
fragments.remove(position)
5755
}
5856
}

0 commit comments

Comments
 (0)