Skip to content

Commit e82481b

Browse files
committed
moving tabs at the bottom at Insert Or Edit activity too
1 parent 8dc1fda commit e82481b

File tree

3 files changed

+86
-59
lines changed

3 files changed

+86
-59
lines changed

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

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import android.app.SearchManager
55
import android.content.ActivityNotFoundException
66
import android.content.Context
77
import android.content.Intent
8-
import android.graphics.drawable.ColorDrawable
98
import android.net.Uri
109
import android.os.Bundle
1110
import android.provider.ContactsContract
1211
import android.provider.ContactsContract.CommonDataKinds.Email
1312
import android.provider.ContactsContract.CommonDataKinds.Phone
1413
import android.view.Menu
1514
import android.view.MenuItem
15+
import android.widget.ImageView
16+
import android.widget.TextView
1617
import androidx.appcompat.widget.SearchView
1718
import androidx.core.view.MenuItemCompat
1819
import androidx.viewpager.widget.ViewPager
@@ -69,7 +70,7 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
6970
return
7071
}
7172

72-
setupTabColors()
73+
setupTabs()
7374

7475
// we do not really care about the permission request result. Even if it was denied, load private contacts
7576
handlePermission(PERMISSION_READ_CONTACTS) {
@@ -85,6 +86,11 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
8586
}
8687
}
8788

89+
override fun onResume() {
90+
super.onResume()
91+
setupTabColors()
92+
}
93+
8894
override fun onStop() {
8995
super.onStop()
9096
searchMenuItem?.collapseActionView()
@@ -115,7 +121,7 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
115121
}
116122

117123
private fun initFragments() {
118-
viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
124+
view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
119125
override fun onPageScrollStateChanged(state: Int) {
120126
if (isSearchOpen) {
121127
getCurrentFragment()?.onSearchQueryChanged("")
@@ -131,43 +137,42 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
131137
}
132138
})
133139

134-
viewpager.onGlobalLayout {
140+
view_pager.onGlobalLayout {
135141
refreshContacts(getTabsMask())
136142
}
137143

138-
insert_or_edit_tabs_holder.onTabSelectionChanged(
139-
tabUnselectedAction = {
140-
it.icon?.applyColorFilter(getProperTextColor())
141-
},
142-
tabSelectedAction = {
143-
if (isSearchOpen) {
144-
getCurrentFragment()?.onSearchQueryChanged("")
145-
searchMenuItem?.collapseActionView()
146-
}
147-
viewpager.currentItem = it.position
148-
it.icon?.applyColorFilter(getProperPrimaryColor())
149-
}
150-
)
144+
select_contact_label?.setTextColor(getProperPrimaryColor())
145+
new_contact_tmb?.setImageDrawable(resources.getColoredDrawableWithColor(R.drawable.ic_add_person_vector, getProperTextColor()))
146+
new_contact_name.setTextColor(getProperTextColor())
147+
new_contact_holder?.setOnClickListener {
148+
createNewContact()
149+
}
150+
}
151151

152+
private fun setupTabs() {
152153
insert_or_edit_tabs_holder.removeAllTabs()
153-
var skippedTabs = 0
154154
contactsFavoritesList.forEachIndexed { index, value ->
155-
if (config.showTabs and value == 0 && value == TAB_FAVORITES) {
156-
skippedTabs++
157-
} else {
158-
val tab = insert_or_edit_tabs_holder.newTab().setIcon(getTabIcon(index))
159-
insert_or_edit_tabs_holder.addTab(tab, index - skippedTabs, index == 0)
155+
if (config.showTabs and value != 0) {
156+
insert_or_edit_tabs_holder.newTab().setCustomView(R.layout.bottom_tablayout_item).apply {
157+
customView?.findViewById<ImageView>(R.id.tab_item_icon)?.setImageDrawable(getTabIcon(index))
158+
customView?.findViewById<TextView>(R.id.tab_item_label)?.text = getTabLabel(index)
159+
insert_or_edit_tabs_holder.addTab(this)
160+
}
160161
}
161162
}
162163

163-
insert_or_edit_tabs_holder.beVisibleIf(skippedTabs == 0)
164+
insert_or_edit_tabs_holder.onTabSelectionChanged(
165+
tabUnselectedAction = {
166+
updateBottomTabItemColors(it.customView, false)
167+
},
168+
tabSelectedAction = {
169+
closeSearch()
170+
view_pager.currentItem = it.position
171+
updateBottomTabItemColors(it.customView, true)
172+
}
173+
)
164174

165-
select_contact_label?.setTextColor(getProperPrimaryColor())
166-
new_contact_tmb?.setImageDrawable(resources.getColoredDrawableWithColor(R.drawable.ic_add_person_vector, getProperTextColor()))
167-
new_contact_name.setTextColor(getProperTextColor())
168-
new_contact_holder?.setOnClickListener {
169-
createNewContact()
170-
}
175+
insert_or_edit_tabs_holder.beGoneIf(insert_or_edit_tabs_holder.tabCount == 1)
171176
}
172177

173178
private fun setupSearch(menu: Menu) {
@@ -212,27 +217,38 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
212217
}
213218

214219
private fun getCurrentFragment(): MyViewPagerFragment? {
215-
return if (viewpager.currentItem == 0) {
220+
return if (view_pager.currentItem == 0) {
216221
contacts_fragment
217222
} else {
218223
favorites_fragment
219224
}
220225
}
221226

227+
private fun getAllFragments() = arrayListOf(contacts_fragment, favorites_fragment)
228+
222229
private fun setupTabColors() {
223-
insert_or_edit_tabs_holder.apply {
224-
background = ColorDrawable(getProperBackgroundColor())
225-
setSelectedTabIndicatorColor(getProperPrimaryColor())
230+
val activeView = insert_or_edit_tabs_holder.getTabAt(view_pager.currentItem)?.customView
231+
updateBottomTabItemColors(activeView, true)
232+
233+
getInactiveTabIndexes(view_pager.currentItem).forEach { index ->
234+
val inactiveView = insert_or_edit_tabs_holder.getTabAt(index)?.customView
235+
updateBottomTabItemColors(inactiveView, false)
226236
}
237+
238+
val bottomBarColor = getBottomTabsBackgroundColor()
239+
insert_or_edit_tabs_holder.setBackgroundColor(bottomBarColor)
240+
updateNavigationBarColor(bottomBarColor)
227241
}
228242

243+
private fun getInactiveTabIndexes(activeIndex: Int) = (0 until contactsFavoritesList.size).filter { it != activeIndex }
244+
229245
override fun refreshContacts(refreshTabsMask: Int) {
230246
if (isDestroyed || isFinishing) {
231247
return
232248
}
233249

234-
if (viewpager.adapter == null) {
235-
viewpager.adapter = ViewPagerAdapter(this, contactsFavoritesList, getTabsMask())
250+
if (view_pager.adapter == null) {
251+
view_pager.adapter = ViewPagerAdapter(this, contactsFavoritesList, getTabsMask())
236252
}
237253

238254
ContactsHelper(this).getContacts {
@@ -344,6 +360,15 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
344360
createNewContact()
345361
}
346362

363+
private fun closeSearch() {
364+
if (isSearchOpen) {
365+
getAllFragments().forEach {
366+
it?.onSearchQueryChanged("")
367+
}
368+
searchMenuItem?.collapseActionView()
369+
}
370+
}
371+
347372
private fun showSortingDialog() {
348373
ChangeSortingDialog(this) {
349374
refreshContacts(getTabsMask())

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,8 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
339339
view_pager.offscreenPageLimit = tabsList.size - 1
340340
view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
341341
override fun onPageScrollStateChanged(state: Int) {
342-
if (isSearchOpen) {
343-
getCurrentFragment()?.onSearchQueryChanged("")
344-
searchMenuItem?.collapseActionView()
342+
if (state == ViewPager.SCROLL_STATE_SETTLING) {
343+
closeSearch()
345344
}
346345
}
347346

@@ -387,19 +386,12 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
387386
updateBottomTabItemColors(it.customView, false)
388387
},
389388
tabSelectedAction = {
389+
closeSearch()
390390
view_pager.currentItem = it.position
391391
updateBottomTabItemColors(it.customView, true)
392392
}
393393
)
394394

395-
// selecting the proper tab sometimes glitches, add an extra selector to make sure we have it right
396-
/*main_tabs_holder.onGlobalLayout {
397-
Handler().postDelayed({
398-
main_tabs_holder.getTabAt(getDefaultTab())?.select()
399-
invalidateOptionsMenu()
400-
}, 100L)
401-
}*/
402-
403395
main_tabs_holder.beGoneIf(main_tabs_holder.tabCount == 1)
404396
}
405397

@@ -542,11 +534,13 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
542534
}
543535

544536
private fun launchSettings() {
537+
closeSearch()
545538
hideKeyboard()
546539
startActivity(Intent(applicationContext, SettingsActivity::class.java))
547540
}
548541

549542
private fun launchAbout() {
543+
closeSearch()
550544
val licenses = LICENSE_JODA or LICENSE_GLIDE or LICENSE_GSON or LICENSE_INDICATOR_FAST_SCROLL
551545

552546
val faqItems = arrayListOf(
@@ -638,6 +632,15 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
638632
}
639633
}
640634

635+
private fun closeSearch() {
636+
if (isSearchOpen) {
637+
getAllFragments().forEach {
638+
it?.onSearchQueryChanged("")
639+
}
640+
searchMenuItem?.collapseActionView()
641+
}
642+
}
643+
641644
private fun checkWhatsNewDialog() {
642645
arrayListOf<Release>().apply {
643646
add(Release(10, R.string.release_10))

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,10 @@
55
android:layout_width="match_parent"
66
android:layout_height="wrap_content">
77

8-
<com.google.android.material.tabs.TabLayout
9-
android:id="@+id/insert_or_edit_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
<RelativeLayout
199
android:id="@+id/new_contact_holder"
2010
android:layout_width="match_parent"
2111
android:layout_height="wrap_content"
22-
android:layout_below="@+id/insert_or_edit_tabs_holder"
2312
android:background="?attr/selectableItemBackground"
2413
android:paddingTop="@dimen/medium_margin"
2514
android:paddingEnd="@dimen/activity_margin"
@@ -63,9 +52,19 @@
6352
android:visibility="gone" />
6453

6554
<com.simplemobiletools.commons.views.MyViewPager
66-
android:id="@+id/viewpager"
55+
android:id="@+id/view_pager"
6756
android:layout_width="match_parent"
6857
android:layout_height="match_parent"
58+
android:layout_above="@+id/insert_or_edit_tabs_holder"
6959
android:layout_below="@+id/select_contact_label" />
7060

61+
<com.google.android.material.tabs.TabLayout
62+
android:id="@+id/insert_or_edit_tabs_holder"
63+
android:layout_width="match_parent"
64+
android:layout_height="wrap_content"
65+
android:layout_alignParentBottom="true"
66+
app:tabIndicator="@null"
67+
app:tabMinWidth="150dp"
68+
app:tabRippleColor="@null" />
69+
7170
</RelativeLayout>

0 commit comments

Comments
 (0)