mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-10 16:40:40 +01:00
adding some performance improvements at initial app loading
This commit is contained in:
parent
dc23bac57f
commit
3257dc7c79
@ -283,7 +283,6 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
private fun getInactiveTabIndexes(activeIndex: Int) = arrayListOf(0, 1, 2).filter { it != activeIndex }
|
private fun getInactiveTabIndexes(activeIndex: Int) = arrayListOf(0, 1, 2).filter { it != activeIndex }
|
||||||
|
|
||||||
private fun initFragments() {
|
private fun initFragments() {
|
||||||
refreshContacts(ALL_TABS_MASK)
|
|
||||||
viewpager.offscreenPageLimit = 3
|
viewpager.offscreenPageLimit = 3
|
||||||
viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
||||||
override fun onPageScrollStateChanged(state: Int) {
|
override fun onPageScrollStateChanged(state: Int) {
|
||||||
@ -305,6 +304,10 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
viewpager.onGlobalLayout {
|
||||||
|
refreshContacts(ALL_TABS_MASK)
|
||||||
|
}
|
||||||
|
|
||||||
main_tabs_holder.onTabSelectionChanged(
|
main_tabs_holder.onTabSelectionChanged(
|
||||||
tabUnselectedAction = {
|
tabUnselectedAction = {
|
||||||
it.icon?.applyColorFilter(config.textColor)
|
it.icon?.applyColorFilter(config.textColor)
|
||||||
@ -451,19 +454,19 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
if (isActivityDestroyed() || isGettingContacts) {
|
if (isActivityDestroyed() || isGettingContacts) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
isGettingContacts = true
|
isGettingContacts = true
|
||||||
|
|
||||||
|
if (viewpager.adapter == null) {
|
||||||
|
viewpager.adapter = ViewPagerAdapter(this)
|
||||||
|
viewpager.currentItem = config.lastUsedViewPagerPage
|
||||||
|
}
|
||||||
|
|
||||||
ContactsHelper(this).getContacts {
|
ContactsHelper(this).getContacts {
|
||||||
isGettingContacts = false
|
isGettingContacts = false
|
||||||
if (isActivityDestroyed()) {
|
if (isActivityDestroyed()) {
|
||||||
return@getContacts
|
return@getContacts
|
||||||
}
|
}
|
||||||
|
|
||||||
if (viewpager.adapter == null) {
|
|
||||||
viewpager.adapter = ViewPagerAdapter(this, it)
|
|
||||||
viewpager.currentItem = config.lastUsedViewPagerPage
|
|
||||||
}
|
|
||||||
|
|
||||||
if (refreshTabsMask and CONTACTS_TAB_MASK != 0) {
|
if (refreshTabsMask and CONTACTS_TAB_MASK != 0) {
|
||||||
contacts_fragment?.refreshContacts(it)
|
contacts_fragment?.refreshContacts(it)
|
||||||
}
|
}
|
||||||
@ -478,6 +481,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
groups_fragment?.refreshContacts(it)
|
groups_fragment?.refreshContacts(it)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (refreshTabsMask and RECENTS_TAB_MASK != 0) {
|
if (refreshTabsMask and RECENTS_TAB_MASK != 0) {
|
||||||
ContactsHelper(this).getRecents {
|
ContactsHelper(this).getRecents {
|
||||||
@ -487,7 +491,6 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun getAllFragments() = arrayListOf(contacts_fragment, favorites_fragment, groups_fragment)
|
private fun getAllFragments() = arrayListOf(contacts_fragment, favorites_fragment, groups_fragment)
|
||||||
|
|
||||||
|
@ -8,10 +8,9 @@ import com.simplemobiletools.contacts.activities.MainActivity
|
|||||||
import com.simplemobiletools.contacts.extensions.config
|
import com.simplemobiletools.contacts.extensions.config
|
||||||
import com.simplemobiletools.contacts.fragments.MyViewPagerFragment
|
import com.simplemobiletools.contacts.fragments.MyViewPagerFragment
|
||||||
import com.simplemobiletools.contacts.helpers.*
|
import com.simplemobiletools.contacts.helpers.*
|
||||||
import com.simplemobiletools.contacts.models.Contact
|
|
||||||
|
|
||||||
class ViewPagerAdapter(val activity: MainActivity, val contacts: ArrayList<Contact>) : PagerAdapter() {
|
class ViewPagerAdapter(val activity: MainActivity) : PagerAdapter() {
|
||||||
val showTabs = activity.config.showTabs
|
private val showTabs = activity.config.showTabs
|
||||||
|
|
||||||
override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
||||||
val layout = getFragment(position)
|
val layout = getFragment(position)
|
||||||
@ -20,8 +19,8 @@ class ViewPagerAdapter(val activity: MainActivity, val contacts: ArrayList<Conta
|
|||||||
|
|
||||||
(view as MyViewPagerFragment).apply {
|
(view as MyViewPagerFragment).apply {
|
||||||
setupFragment(activity)
|
setupFragment(activity)
|
||||||
refreshContacts(contacts)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user