mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
lets just restart the activity at Shown Tabs change to avoid glitches
This commit is contained in:
parent
8be0b1ab9a
commit
6044dab0c9
@ -8,6 +8,7 @@ import android.content.pm.PackageManager
|
|||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Handler
|
||||||
import android.support.v4.app.ActivityCompat
|
import android.support.v4.app.ActivityCompat
|
||||||
import android.support.v4.content.ContextCompat
|
import android.support.v4.content.ContextCompat
|
||||||
import android.support.v4.view.MenuItemCompat
|
import android.support.v4.view.MenuItemCompat
|
||||||
@ -102,7 +103,9 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (storedShowTabs != config.showTabs) {
|
if (storedShowTabs != config.showTabs) {
|
||||||
viewpager.adapter = null
|
config.lastUsedViewPagerPage = 0
|
||||||
|
System.exit(0)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val configShowContactThumbnails = config.showContactThumbnails
|
val configShowContactThumbnails = config.showContactThumbnails
|
||||||
@ -220,7 +223,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
|
|
||||||
override fun onQueryTextChange(newText: String): Boolean {
|
override fun onQueryTextChange(newText: String): Boolean {
|
||||||
if (isSearchOpen) {
|
if (isSearchOpen) {
|
||||||
getCurrentFragment().onSearchQueryChanged(newText)
|
getCurrentFragment()?.onSearchQueryChanged(newText)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -229,20 +232,20 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
|
|
||||||
MenuItemCompat.setOnActionExpandListener(searchMenuItem, object : MenuItemCompat.OnActionExpandListener {
|
MenuItemCompat.setOnActionExpandListener(searchMenuItem, object : MenuItemCompat.OnActionExpandListener {
|
||||||
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
||||||
getCurrentFragment().onSearchOpened()
|
getCurrentFragment()?.onSearchOpened()
|
||||||
isSearchOpen = true
|
isSearchOpen = true
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
|
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
|
||||||
getCurrentFragment().onSearchClosed()
|
getCurrentFragment()?.onSearchClosed()
|
||||||
isSearchOpen = false
|
isSearchOpen = false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCurrentFragment(): MyViewPagerFragment {
|
private fun getCurrentFragment(): MyViewPagerFragment? {
|
||||||
val showTabs = config.showTabs
|
val showTabs = config.showTabs
|
||||||
val fragments = arrayListOf<MyViewPagerFragment>()
|
val fragments = arrayListOf<MyViewPagerFragment>()
|
||||||
if (showTabs and CONTACTS_TAB_MASK != 0) {
|
if (showTabs and CONTACTS_TAB_MASK != 0) {
|
||||||
@ -297,14 +300,14 @@ 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, 3).filter { it != activeIndex }
|
||||||
|
|
||||||
private fun initFragments() {
|
private fun initFragments() {
|
||||||
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) {
|
||||||
if (isSearchOpen) {
|
if (isSearchOpen) {
|
||||||
getCurrentFragment().onSearchQueryChanged("")
|
getCurrentFragment()?.onSearchQueryChanged("")
|
||||||
searchMenuItem?.collapseActionView()
|
searchMenuItem?.collapseActionView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -331,7 +334,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
},
|
},
|
||||||
tabSelectedAction = {
|
tabSelectedAction = {
|
||||||
if (isSearchOpen) {
|
if (isSearchOpen) {
|
||||||
getCurrentFragment().onSearchQueryChanged("")
|
getCurrentFragment()?.onSearchQueryChanged("")
|
||||||
searchMenuItem?.collapseActionView()
|
searchMenuItem?.collapseActionView()
|
||||||
}
|
}
|
||||||
viewpager.currentItem = it.position
|
viewpager.currentItem = it.position
|
||||||
@ -354,6 +357,13 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// selecting the proper tab sometimes glitches, add an extra selector to make sure we have it right
|
||||||
|
main_tabs_holder.onGlobalLayout {
|
||||||
|
Handler().postDelayed({
|
||||||
|
main_tabs_holder.getTabAt(config.lastUsedViewPagerPage)?.select()
|
||||||
|
}, 100L)
|
||||||
|
}
|
||||||
|
|
||||||
main_tabs_holder.beVisibleIf(skippedTabs < 3)
|
main_tabs_holder.beVisibleIf(skippedTabs < 3)
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user