adding some performance improvements at initial app loading

This commit is contained in:
tibbi 2018-08-04 19:42:33 +02:00
parent dc23bac57f
commit 3257dc7c79
2 changed files with 18 additions and 16 deletions

View File

@ -283,7 +283,6 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
private fun getInactiveTabIndexes(activeIndex: Int) = arrayListOf(0, 1, 2).filter { it != activeIndex }
private fun initFragments() {
refreshContacts(ALL_TABS_MASK)
viewpager.offscreenPageLimit = 3
viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageScrollStateChanged(state: Int) {
@ -305,6 +304,10 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
}
})
viewpager.onGlobalLayout {
refreshContacts(ALL_TABS_MASK)
}
main_tabs_holder.onTabSelectionChanged(
tabUnselectedAction = {
it.icon?.applyColorFilter(config.textColor)
@ -451,19 +454,19 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
if (isActivityDestroyed() || isGettingContacts) {
return
}
isGettingContacts = true
if (viewpager.adapter == null) {
viewpager.adapter = ViewPagerAdapter(this)
viewpager.currentItem = config.lastUsedViewPagerPage
}
ContactsHelper(this).getContacts {
isGettingContacts = false
if (isActivityDestroyed()) {
return@getContacts
}
if (viewpager.adapter == null) {
viewpager.adapter = ViewPagerAdapter(this, it)
viewpager.currentItem = config.lastUsedViewPagerPage
}
if (refreshTabsMask and CONTACTS_TAB_MASK != 0) {
contacts_fragment?.refreshContacts(it)
}
@ -478,6 +481,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
}
groups_fragment?.refreshContacts(it)
}
}
if (refreshTabsMask and RECENTS_TAB_MASK != 0) {
ContactsHelper(this).getRecents {
@ -487,7 +491,6 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
}
}
}
}
private fun getAllFragments() = arrayListOf(contacts_fragment, favorites_fragment, groups_fragment)

View File

@ -8,10 +8,9 @@ import com.simplemobiletools.contacts.activities.MainActivity
import com.simplemobiletools.contacts.extensions.config
import com.simplemobiletools.contacts.fragments.MyViewPagerFragment
import com.simplemobiletools.contacts.helpers.*
import com.simplemobiletools.contacts.models.Contact
class ViewPagerAdapter(val activity: MainActivity, val contacts: ArrayList<Contact>) : PagerAdapter() {
val showTabs = activity.config.showTabs
class ViewPagerAdapter(val activity: MainActivity) : PagerAdapter() {
private val showTabs = activity.config.showTabs
override fun instantiateItem(container: ViewGroup, position: Int): Any {
val layout = getFragment(position)
@ -20,8 +19,8 @@ class ViewPagerAdapter(val activity: MainActivity, val contacts: ArrayList<Conta
(view as MyViewPagerFragment).apply {
setupFragment(activity)
refreshContacts(contacts)
}
return view
}