pass available fragments to the adapter in a list

This commit is contained in:
tibbi 2019-12-06 21:01:25 +01:00
parent 99eb37e51a
commit 9319c934e0
3 changed files with 8 additions and 7 deletions

View file

@ -110,7 +110,8 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
}
if (viewpager.adapter == null) {
viewpager.adapter = ViewPagerAdapter(this, contactsFavoritesList, CONTACTS_TAB_MASK or FAVORITES_TAB_MASK)
val fragments = arrayListOf(R.layout.fragment_contacts, R.layout.fragment_favorites)
viewpager.adapter = ViewPagerAdapter(this, contactsFavoritesList, CONTACTS_TAB_MASK or FAVORITES_TAB_MASK, fragments)
}
ContactsHelper(this).getContacts { contacts ->

View file

@ -532,7 +532,8 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
isGettingContacts = true
if (viewpager.adapter == null) {
viewpager.adapter = ViewPagerAdapter(this, tabsList, config.showTabs)
val fragments = arrayListOf(R.layout.fragment_contacts, R.layout.fragment_favorites, R.layout.fragment_groups)
viewpager.adapter = ViewPagerAdapter(this, tabsList, config.showTabs, fragments)
viewpager.currentItem = config.lastUsedViewPagerPage
}

View file

@ -3,14 +3,13 @@ package com.simplemobiletools.contacts.pro.adapters
import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.fragments.MyViewPagerFragment
import com.simplemobiletools.contacts.pro.helpers.CONTACTS_TAB_MASK
import com.simplemobiletools.contacts.pro.helpers.FAVORITES_TAB_MASK
import com.simplemobiletools.contacts.pro.helpers.GROUPS_TAB_MASK
class ViewPagerAdapter(val activity: SimpleActivity, val currTabsList: ArrayList<Int>, val showTabs: Int) : PagerAdapter() {
class ViewPagerAdapter(val activity: SimpleActivity, val currTabsList: ArrayList<Int>, val showTabs: Int, val pagerFragments: ArrayList<Int>) : PagerAdapter() {
override fun instantiateItem(container: ViewGroup, position: Int): Any {
val layout = getFragment(position)
@ -35,15 +34,15 @@ class ViewPagerAdapter(val activity: SimpleActivity, val currTabsList: ArrayList
private fun getFragment(position: Int): Int {
val fragments = arrayListOf<Int>()
if (showTabs and CONTACTS_TAB_MASK != 0) {
fragments.add(R.layout.fragment_contacts)
fragments.add(pagerFragments[0])
}
if (showTabs and FAVORITES_TAB_MASK != 0) {
fragments.add(R.layout.fragment_favorites)
fragments.add(pagerFragments[1])
}
if (showTabs and GROUPS_TAB_MASK != 0) {
fragments.add(R.layout.fragment_groups)
fragments.add(pagerFragments[2])
}
return fragments[position]