alwas recreate the viewpager tabs to avoid glitching

This commit is contained in:
tibbi 2018-08-02 13:43:59 +02:00
parent 399ae4c0b6
commit e1d21a9ed4
2 changed files with 9 additions and 67 deletions

View File

@ -318,61 +318,23 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
intent.data = null
}
val showTabs = config.showTabs
val indexesToRemove = ArrayList<Int>()
main_tabs_holder.removeAllTabs()
var skippedTabs = 0
tabsList.forEachIndexed { index, value ->
if (showTabs and value == 0) {
if (main_tabs_holder?.getTabAt(index) != null) {
indexesToRemove.add(index)
}
if (config.showTabs and value == 0) {
skippedTabs++
} else {
main_tabs_holder.addTab(main_tabs_holder.newTab().setIcon(getTabIcon(index)), index - skippedTabs, config.lastUsedViewPagerPage == index - skippedTabs)
}
}
indexesToRemove.reversed().forEach {
main_tabs_holder.removeTabAt(it)
}
tabsList.forEachIndexed { index, value ->
if (showTabs and value != 0 && handledShowTabs and value == 0) {
main_tabs_holder.addTab(main_tabs_holder.newTab().setIcon(getTabIcon(value)), getTabPosition(value, showTabs))
}
}
handledShowTabs = config.showTabs
}
private fun getTabIcon(position: Int) = resources.getDrawable(when (position) {
CONTACTS_TAB_MASK -> R.drawable.ic_person
FAVORITES_TAB_MASK -> R.drawable.ic_star_on
LOCATION_CONTACTS_TAB -> R.drawable.ic_person
LOCATION_FAVORITES_TAB -> R.drawable.ic_star_on
else -> R.drawable.ic_group
})
private fun getTabPosition(value: Int, showTabs: Int): Int {
return when (value) {
CONTACTS_TAB_MASK -> 0
FAVORITES_TAB_MASK -> {
if (showTabs and CONTACTS_TAB_MASK != 0) {
1
} else {
0
}
}
else -> {
if (showTabs and CONTACTS_TAB_MASK != 0) {
if (showTabs and FAVORITES_TAB_MASK != 0) {
2
} else {
1
}
} else if (showTabs and FAVORITES_TAB_MASK != 0) {
1
} else {
0
}
}
}
}
private fun showSortingDialog() {
ChangeSortingDialog(this) {
refreshContacts(CONTACTS_TAB_MASK or FAVORITES_TAB_MASK)

View File

@ -14,27 +14,7 @@
app:tabIndicatorColor="@android:color/white"
app:tabIndicatorHeight="2dp"
app:tabMinWidth="150dp"
app:tabSelectedTextColor="@android:color/white">
<android.support.design.widget.TabItem
android:id="@+id/tab_contacts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/ic_person"/>
<android.support.design.widget.TabItem
android:id="@+id/tab_favorites"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/ic_star_on"/>
<android.support.design.widget.TabItem
android:id="@+id/tab_groups"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/ic_group"/>
</android.support.design.widget.TabLayout>
app:tabSelectedTextColor="@android:color/white"/>
<com.booking.rtlviewpager.RtlViewPager
android:id="@+id/viewpager"