From 9319c934e080f82e861144ccffac8ff476bf0699 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 6 Dec 2019 21:01:25 +0100 Subject: [PATCH] pass available fragments to the adapter in a list --- .../pro/activities/InsertOrEditContactActivity.kt | 3 ++- .../contacts/pro/activities/MainActivity.kt | 3 ++- .../contacts/pro/adapters/ViewPagerAdapter.kt | 9 ++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt index 2c2c9f18..8758a294 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt @@ -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 -> diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt index b052eed5..b80fa62b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt @@ -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 } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/ViewPagerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/ViewPagerAdapter.kt index ab141e80..ed2f6019 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/ViewPagerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/ViewPagerAdapter.kt @@ -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, val showTabs: Int) : PagerAdapter() { +class ViewPagerAdapter(val activity: SimpleActivity, val currTabsList: ArrayList, val showTabs: Int, val pagerFragments: ArrayList) : 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() 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]