Skip to content

Commit 8dc1fda

Browse files
committed
moving main screen tabs at the bottom
1 parent 9424b57 commit 8dc1fda

File tree

3 files changed

+61
-72
lines changed

3 files changed

+61
-72
lines changed

app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt

Lines changed: 48 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import android.graphics.drawable.Icon
1212
import android.graphics.drawable.LayerDrawable
1313
import android.net.Uri
1414
import android.os.Bundle
15-
import android.os.Handler
1615
import android.view.Menu
1716
import android.view.MenuItem
17+
import android.widget.ImageView
18+
import android.widget.TextView
1819
import android.widget.Toast
1920
import androidx.appcompat.widget.SearchView
2021
import androidx.core.view.MenuItemCompat
@@ -75,7 +76,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
7576
appLaunched(BuildConfig.APPLICATION_ID)
7677

7778
storeStateVariables()
78-
setupTabColors()
79+
setupTabs()
7980
checkContactPermissions()
8081
checkWhatsNewDialog()
8182
}
@@ -122,7 +123,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
122123
it?.setupColors(getProperTextColor(), properPrimaryColor)
123124
}
124125

125-
updateTabColors()
126+
setupTabColors()
126127

127128
val configStartNameWithSurname = config.startNameWithSurname
128129
if (storedStartNameWithSurname != configStartNameWithSurname) {
@@ -138,7 +139,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
138139
}
139140

140141
if (werePermissionsHandled && !isFirstResume) {
141-
if (viewpager.adapter == null) {
142+
if (view_pager.adapter == null) {
142143
initFragments()
143144
} else {
144145
refreshContacts(ALL_TABS_MASK)
@@ -159,7 +160,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
159160
override fun onPause() {
160161
super.onPause()
161162
storeStateVariables()
162-
config.lastUsedViewPagerPage = viewpager.currentItem
163+
config.lastUsedViewPagerPage = view_pager.currentItem
163164
}
164165

165166
override fun onDestroy() {
@@ -261,13 +262,6 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
261262
})
262263
}
263264

264-
private fun updateTabColors() {
265-
getInactiveTabIndexes(viewpager.currentItem).forEach {
266-
main_tabs_holder.getTabAt(it)?.icon?.applyColorFilter(getProperTextColor())
267-
}
268-
main_tabs_holder.getTabAt(viewpager.currentItem)?.icon?.applyColorFilter(getProperPrimaryColor())
269-
}
270-
271265
private fun getSearchString(): Int {
272266
return when (getCurrentFragment()) {
273267
favorites_fragment -> R.string.search_favorites
@@ -322,28 +316,28 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
322316
fragments.add(groups_fragment)
323317
}
324318

325-
return fragments.getOrNull(viewpager.currentItem)
319+
return fragments.getOrNull(view_pager.currentItem)
326320
}
327321

328322
private fun setupTabColors() {
329-
val lastUsedPage = getDefaultTab()
330-
main_tabs_holder.apply {
331-
background = ColorDrawable(getProperBackgroundColor())
332-
setSelectedTabIndicatorColor(getProperPrimaryColor())
333-
getTabAt(lastUsedPage)?.select()
334-
getTabAt(lastUsedPage)?.icon?.applyColorFilter(getProperPrimaryColor())
335-
336-
getInactiveTabIndexes(lastUsedPage).forEach {
337-
getTabAt(it)?.icon?.applyColorFilter(getProperTextColor())
338-
}
323+
val activeView = main_tabs_holder.getTabAt(view_pager.currentItem)?.customView
324+
updateBottomTabItemColors(activeView, true)
325+
326+
getInactiveTabIndexes(view_pager.currentItem).forEach { index ->
327+
val inactiveView = main_tabs_holder.getTabAt(index)?.customView
328+
updateBottomTabItemColors(inactiveView, false)
339329
}
330+
331+
val bottomBarColor = getBottomTabsBackgroundColor()
332+
main_tabs_holder.setBackgroundColor(bottomBarColor)
333+
updateNavigationBarColor(bottomBarColor)
340334
}
341335

342336
private fun getInactiveTabIndexes(activeIndex: Int) = (0 until tabsList.size).filter { it != activeIndex }
343337

344338
private fun initFragments() {
345-
viewpager.offscreenPageLimit = tabsList.size - 1
346-
viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
339+
view_pager.offscreenPageLimit = tabsList.size - 1
340+
view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
347341
override fun onPageScrollStateChanged(state: Int) {
348342
if (isSearchOpen) {
349343
getCurrentFragment()?.onSearchQueryChanged("")
@@ -362,54 +356,51 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
362356
}
363357
})
364358

365-
viewpager.onGlobalLayout {
359+
view_pager.onGlobalLayout {
366360
refreshContacts(ALL_TABS_MASK)
367361
}
368362

369-
main_tabs_holder.onTabSelectionChanged(
370-
tabUnselectedAction = {
371-
it.icon?.applyColorFilter(getProperTextColor())
372-
},
373-
tabSelectedAction = {
374-
if (isSearchOpen) {
375-
getCurrentFragment()?.onSearchQueryChanged("")
376-
searchMenuItem?.collapseActionView()
377-
}
378-
viewpager.currentItem = it.position
379-
it.icon?.applyColorFilter(getProperPrimaryColor())
380-
}
381-
)
382-
383363
if (intent?.action == Intent.ACTION_VIEW && intent.data != null) {
384364
tryImportContactsFromFile(intent.data!!)
385365
intent.data = null
386366
}
387367

368+
main_dialpad_button.setOnClickListener {
369+
launchDialpad()
370+
}
371+
}
372+
373+
private fun setupTabs() {
388374
main_tabs_holder.removeAllTabs()
389-
var skippedTabs = 0
390375
tabsList.forEachIndexed { index, value ->
391-
if (config.showTabs and value == 0) {
392-
skippedTabs++
393-
} else {
394-
val tab = main_tabs_holder.newTab().setIcon(getTabIcon(index))
395-
tab.contentDescription = getTabContentDescription(index)
396-
main_tabs_holder.addTab(tab, index - skippedTabs, getDefaultTab() == index - skippedTabs)
376+
if (config.showTabs and value != 0) {
377+
main_tabs_holder.newTab().setCustomView(R.layout.bottom_tablayout_item).apply {
378+
customView?.findViewById<ImageView>(R.id.tab_item_icon)?.setImageDrawable(getTabIcon(index))
379+
customView?.findViewById<TextView>(R.id.tab_item_label)?.text = getTabLabel(index)
380+
main_tabs_holder.addTab(this)
381+
}
397382
}
398383
}
399384

385+
main_tabs_holder.onTabSelectionChanged(
386+
tabUnselectedAction = {
387+
updateBottomTabItemColors(it.customView, false)
388+
},
389+
tabSelectedAction = {
390+
view_pager.currentItem = it.position
391+
updateBottomTabItemColors(it.customView, true)
392+
}
393+
)
394+
400395
// selecting the proper tab sometimes glitches, add an extra selector to make sure we have it right
401-
main_tabs_holder.onGlobalLayout {
396+
/*main_tabs_holder.onGlobalLayout {
402397
Handler().postDelayed({
403398
main_tabs_holder.getTabAt(getDefaultTab())?.select()
404399
invalidateOptionsMenu()
405400
}, 100L)
406-
}
401+
}*/
407402

408-
main_tabs_holder.beVisibleIf(skippedTabs < tabsList.size - 1)
409-
410-
main_dialpad_button.setOnClickListener {
411-
launchDialpad()
412-
}
403+
main_tabs_holder.beGoneIf(main_tabs_holder.tabCount == 1)
413404
}
414405

415406
private fun showSortingDialog(showCustomSorting: Boolean) {
@@ -579,10 +570,9 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
579570

580571
isGettingContacts = true
581572

582-
if (viewpager.adapter == null) {
583-
viewpager.adapter = ViewPagerAdapter(this, tabsList, config.showTabs)
584-
viewpager.currentItem = getDefaultTab()
585-
updateTabColors()
573+
if (view_pager.adapter == null) {
574+
view_pager.adapter = ViewPagerAdapter(this, tabsList, config.showTabs)
575+
view_pager.currentItem = getDefaultTab()
586576
}
587577

588578
ContactsHelper(this).getContacts { contacts ->

app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/SimpleActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ open class SimpleActivity : BaseSimpleActivity() {
7373
return resources.getColoredDrawableWithColor(drawableId, getProperTextColor())
7474
}
7575

76-
protected fun getTabContentDescription(position: Int): String {
76+
protected fun getTabLabel(position: Int): String {
7777
val stringId = when (position) {
7878
LOCATION_CONTACTS_TAB -> R.string.contacts_tab
7979
LOCATION_FAVORITES_TAB -> R.string.favorites_tab

app/src/main/res/layout/activity_main.xml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,17 @@
55
android:layout_width="match_parent"
66
android:layout_height="match_parent">
77

8-
<com.google.android.material.tabs.TabLayout
9-
android:id="@+id/main_tabs_holder"
10-
android:layout_width="match_parent"
11-
android:layout_height="48dp"
12-
app:elevation="6dp"
13-
app:tabIndicatorColor="@android:color/white"
14-
app:tabIndicatorHeight="2dp"
15-
app:tabMinWidth="150dp"
16-
app:tabSelectedTextColor="@android:color/white" />
17-
188
<com.simplemobiletools.commons.views.MyViewPager
19-
android:id="@+id/viewpager"
9+
android:id="@+id/view_pager"
2010
android:layout_width="match_parent"
2111
android:layout_height="match_parent"
22-
android:layout_below="@+id/main_tabs_holder" />
12+
android:layout_above="@+id/main_tabs_holder" />
2313

2414
<ImageView
2515
android:id="@+id/main_dialpad_button"
2616
android:layout_width="@dimen/dialpad_button_size"
2717
android:layout_height="@dimen/dialpad_button_size"
28-
android:layout_alignParentBottom="true"
18+
android:layout_above="@+id/main_tabs_holder"
2919
android:layout_centerHorizontal="true"
3020
android:layout_marginBottom="@dimen/activity_margin"
3121
android:background="@drawable/circle_background"
@@ -34,4 +24,13 @@
3424
android:padding="@dimen/activity_margin"
3525
android:src="@drawable/ic_dialpad_vector" />
3626

27+
<com.google.android.material.tabs.TabLayout
28+
android:id="@+id/main_tabs_holder"
29+
android:layout_width="match_parent"
30+
android:layout_height="wrap_content"
31+
android:layout_alignParentBottom="true"
32+
app:tabIndicator="@null"
33+
app:tabMinWidth="150dp"
34+
app:tabRippleColor="@null" />
35+
3736
</RelativeLayout>

0 commit comments

Comments
 (0)