@@ -2,15 +2,14 @@ package droidninja.filepicker.fragments |
2 | 2 |
|
3 | 3 | import android.content.Context |
4 | 4 | import android.os.Bundle |
5 | | -import com.google.android.material.tabs.TabLayout |
6 | | -import androidx.viewpager.widget.ViewPager |
7 | 5 | import android.view.LayoutInflater |
8 | 6 | import android.view.View |
9 | 7 | import android.view.ViewGroup |
10 | 8 | import android.widget.ProgressBar |
11 | 9 | import androidx.lifecycle.Observer |
12 | 10 | import androidx.lifecycle.ViewModelProvider |
13 | | - |
| 11 | +import androidx.viewpager.widget.ViewPager |
| 12 | +import com.google.android.material.tabs.TabLayout |
14 | 13 | import droidninja.filepicker.PickerManager |
15 | 14 | import droidninja.filepicker.R |
16 | 15 | import droidninja.filepicker.adapters.SectionsPagerAdapter |
@@ -84,14 +83,14 @@ class DocPickerFragment : BaseFragment() { |
84 | 83 | val sectionsPagerAdapter = viewPager.adapter as SectionsPagerAdapter? |
85 | 84 | if (sectionsPagerAdapter != null) { |
86 | 85 | for (index in 0 until sectionsPagerAdapter.count) { |
87 | | - val docFragment = childFragmentManager |
88 | | - .findFragmentByTag( |
89 | | - "android:switcher:" + R.id.viewPager + ":" + index) as DocFragment |
90 | | - val fileType = docFragment.fileType |
91 | | - if (fileType != null) { |
92 | | - val filesFilteredByType = filesMap[fileType] |
93 | | - if (filesFilteredByType != null) |
94 | | - docFragment.updateList(filesFilteredByType) |
| 86 | + val docFragment = sectionsPagerAdapter.getItem(index) |
| 87 | + if (docFragment is DocFragment) { |
| 88 | + val fileType = docFragment.fileType |
| 89 | + if (fileType != null) { |
| 90 | + val filesFilteredByType = filesMap[fileType] |
| 91 | + if (filesFilteredByType != null) |
| 92 | + docFragment.updateList(filesFilteredByType) |
| 93 | + } |
95 | 94 | } |
96 | 95 | } |
97 | 96 | } |
@@ -102,7 +101,7 @@ class DocPickerFragment : BaseFragment() { |
102 | 101 | val adapter = SectionsPagerAdapter(childFragmentManager) |
103 | 102 | val supportedTypes = PickerManager.getFileTypes() |
104 | 103 | for (index in supportedTypes.indices) { |
105 | | - adapter.addFragment(DocFragment.newInstance(supportedTypes.get(index)), supportedTypes.get(index).title) |
| 104 | + adapter.addFragment(DocFragment.newInstance(supportedTypes[index]), supportedTypes[index].title) |
106 | 105 | } |
107 | 106 |
|
108 | 107 | viewPager.offscreenPageLimit = supportedTypes.size |
|