updating the way view colors are set
This commit is contained in:
parent
20df1db399
commit
49241363a1
|
@ -59,9 +59,6 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
private var isGettingContacts = false
|
||||
private var ignoredExportContactSources = HashSet<String>()
|
||||
|
||||
private var storedTextColor = 0
|
||||
private var storedBackgroundColor = 0
|
||||
private var storedPrimaryColor = 0
|
||||
private var storedShowContactThumbnails = false
|
||||
private var storedShowPhoneNumbers = false
|
||||
private var storedStartNameWithSurname = false
|
||||
|
@ -114,29 +111,14 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
}
|
||||
}
|
||||
|
||||
val configTextColor = config.textColor
|
||||
if (storedTextColor != configTextColor) {
|
||||
getInactiveTabIndexes(viewpager.currentItem).forEach {
|
||||
main_tabs_holder.getTabAt(it)?.icon?.applyColorFilter(configTextColor)
|
||||
}
|
||||
getAllFragments().forEach {
|
||||
it?.textColorChanged(configTextColor)
|
||||
}
|
||||
val adjustedPrimaryColor = getAdjustedPrimaryColor()
|
||||
main_tabs_holder.background = ColorDrawable(config.backgroundColor)
|
||||
main_tabs_holder.setSelectedTabIndicatorColor(adjustedPrimaryColor)
|
||||
getAllFragments().forEach {
|
||||
it?.setupColors(config.textColor, adjustedPrimaryColor)
|
||||
}
|
||||
|
||||
val configBackgroundColor = config.backgroundColor
|
||||
if (storedBackgroundColor != configBackgroundColor) {
|
||||
main_tabs_holder.background = ColorDrawable(configBackgroundColor)
|
||||
}
|
||||
|
||||
val configPrimaryColor = config.primaryColor
|
||||
if (storedPrimaryColor != configPrimaryColor) {
|
||||
main_tabs_holder.setSelectedTabIndicatorColor(getAdjustedPrimaryColor())
|
||||
main_tabs_holder.getTabAt(viewpager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor())
|
||||
getAllFragments().forEach {
|
||||
it?.primaryColorChanged()
|
||||
}
|
||||
}
|
||||
updateTabColors()
|
||||
|
||||
val configStartNameWithSurname = config.startNameWithSurname
|
||||
if (storedStartNameWithSurname != configStartNameWithSurname) {
|
||||
|
@ -156,17 +138,13 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
initFragments()
|
||||
} else {
|
||||
refreshContacts(ALL_TABS_MASK)
|
||||
|
||||
getAllFragments().forEach {
|
||||
it?.onActivityResume()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val dialpadIcon = resources.getColoredDrawableWithColor(R.drawable.ic_dialpad_vector, getFABIconColor())
|
||||
val dialpadIcon = resources.getColoredDrawableWithColor(R.drawable.ic_dialpad_vector, adjustedPrimaryColor.getContrastColor())
|
||||
main_dialpad_button.apply {
|
||||
setImageDrawable(dialpadIcon)
|
||||
background.applyColorFilter(getAdjustedPrimaryColor())
|
||||
background.applyColorFilter(adjustedPrimaryColor)
|
||||
beVisibleIf(config.showDialpadButton)
|
||||
}
|
||||
|
||||
|
@ -233,9 +211,6 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
|
||||
private fun storeStateVariables() {
|
||||
config.apply {
|
||||
storedTextColor = textColor
|
||||
storedBackgroundColor = backgroundColor
|
||||
storedPrimaryColor = primaryColor
|
||||
storedShowContactThumbnails = showContactThumbnails
|
||||
storedShowPhoneNumbers = showPhoneNumbers
|
||||
storedStartNameWithSurname = startNameWithSurname
|
||||
|
@ -280,6 +255,13 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
})
|
||||
}
|
||||
|
||||
private fun updateTabColors() {
|
||||
getInactiveTabIndexes(viewpager.currentItem).forEach {
|
||||
main_tabs_holder.getTabAt(it)?.icon?.applyColorFilter(config.textColor)
|
||||
}
|
||||
main_tabs_holder.getTabAt(viewpager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor())
|
||||
}
|
||||
|
||||
private fun getSearchString(): Int {
|
||||
return when (getCurrentFragment()) {
|
||||
favorites_fragment -> R.string.search_favorites
|
||||
|
@ -567,6 +549,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
if (viewpager.adapter == null) {
|
||||
viewpager.adapter = ViewPagerAdapter(this, tabsList, config.showTabs)
|
||||
viewpager.currentItem = getDefaultTab()
|
||||
updateTabColors()
|
||||
}
|
||||
|
||||
ContactsHelper(this).getContacts { contacts ->
|
||||
|
|
|
@ -3,11 +3,13 @@ package com.simplemobiletools.contacts.pro.adapters
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.viewpager.widget.PagerAdapter
|
||||
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
||||
import com.simplemobiletools.commons.helpers.TAB_CONTACTS
|
||||
import com.simplemobiletools.commons.helpers.TAB_FAVORITES
|
||||
import com.simplemobiletools.commons.helpers.TAB_GROUPS
|
||||
import com.simplemobiletools.contacts.pro.R
|
||||
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.pro.extensions.config
|
||||
import com.simplemobiletools.contacts.pro.fragments.MyViewPagerFragment
|
||||
|
||||
class ViewPagerAdapter(val activity: SimpleActivity, val currTabsList: ArrayList<Int>, val showTabs: Int) : PagerAdapter() {
|
||||
|
@ -19,6 +21,7 @@ class ViewPagerAdapter(val activity: SimpleActivity, val currTabsList: ArrayList
|
|||
|
||||
(view as MyViewPagerFragment).apply {
|
||||
setupFragment(activity)
|
||||
setupColors(activity.config.textColor, activity.getAdjustedPrimaryColor())
|
||||
}
|
||||
|
||||
return view
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simplemobiletools.contacts.pro.dialogs
|
|||
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||
import com.simplemobiletools.contacts.pro.R
|
||||
|
@ -51,11 +52,12 @@ class SelectGroupsDialog(val activity: SimpleActivity, val selectedGroups: Array
|
|||
item_checkbox_holder.setOnClickListener {
|
||||
item_checkbox.toggle()
|
||||
}
|
||||
|
||||
item_checkbox.apply {
|
||||
isChecked = selectedGroups.contains(group)
|
||||
text = group.title
|
||||
tag = group.id
|
||||
setColors(config.textColor, config.primaryColor, config.backgroundColor)
|
||||
setColors(config.textColor, activity.getAdjustedPrimaryColor(), config.backgroundColor)
|
||||
}
|
||||
view.dialog_groups_holder.addView(this)
|
||||
}
|
||||
|
|
|
@ -61,7 +61,6 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
}
|
||||
|
||||
fragment_placeholder_2?.underlineText()
|
||||
updateViewStuff()
|
||||
|
||||
when {
|
||||
this is FavoritesFragment -> {
|
||||
|
@ -76,22 +75,24 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
}
|
||||
}
|
||||
|
||||
fun textColorChanged(color: Int) {
|
||||
fun setupColors(textColor: Int, adjustedPrimaryColor: Int) {
|
||||
when {
|
||||
this is GroupsFragment -> (fragment_list.adapter as GroupsAdapter).updateTextColor(color)
|
||||
this is GroupsFragment -> (fragment_list.adapter as? GroupsAdapter)?.updateTextColor(textColor)
|
||||
else -> (fragment_list.adapter as? ContactsAdapter)?.apply {
|
||||
updateTextColor(color)
|
||||
updateTextColor(textColor)
|
||||
}
|
||||
}
|
||||
|
||||
letter_fastscroller?.textColor = color.getColorStateList()
|
||||
}
|
||||
|
||||
fun primaryColorChanged() {
|
||||
letter_fastscroller?.textColor = textColor.getColorStateList()
|
||||
fragment_fastscroller?.updatePrimaryColor()
|
||||
fragment_fastscroller?.updateBubblePrimaryColor()
|
||||
letter_fastscroller_thumb?.thumbColor = config.primaryColor.getColorStateList()
|
||||
letter_fastscroller_thumb?.textColor = config.primaryColor.getContrastColor()
|
||||
|
||||
letter_fastscroller_thumb?.fontSize = context.getTextSize()
|
||||
letter_fastscroller_thumb?.textColor = adjustedPrimaryColor.getContrastColor()
|
||||
letter_fastscroller_thumb?.thumbColor = adjustedPrimaryColor.getColorStateList()
|
||||
|
||||
context.updateTextColors(fragment_wrapper.parent as ViewGroup)
|
||||
fragment_placeholder_2?.setTextColor(adjustedPrimaryColor)
|
||||
}
|
||||
|
||||
fun startNameWithSurnameChanged(startNameWithSurname: Boolean) {
|
||||
|
@ -143,11 +144,8 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
} else {
|
||||
setupContactsFavoritesAdapter(contacts)
|
||||
contactsIgnoringSearch = (fragment_list?.adapter as? ContactsAdapter)?.contactItems ?: ArrayList()
|
||||
|
||||
letter_fastscroller.textColor = config.textColor.getColorStateList()
|
||||
setupLetterFastscroller(contacts)
|
||||
letter_fastscroller_thumb.setupWithFastScroller(letter_fastscroller)
|
||||
letter_fastscroller_thumb.textColor = config.primaryColor.getContrastColor()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -274,10 +272,6 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
}
|
||||
}
|
||||
|
||||
fun onActivityResume() {
|
||||
updateViewStuff()
|
||||
}
|
||||
|
||||
fun finishActMode() {
|
||||
(fragment_list.adapter as? MyRecyclerViewAdapter)?.finishActMode()
|
||||
}
|
||||
|
@ -288,18 +282,18 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
val shouldNormalize = text.normalizeString() == text
|
||||
val filtered = contactsIgnoringSearch.filter {
|
||||
getProperText(it.getNameToDisplay(), shouldNormalize).contains(text, true) ||
|
||||
getProperText(it.nickname, shouldNormalize).contains(text, true) ||
|
||||
it.phoneNumbers.any {
|
||||
text.normalizePhoneNumber().isNotEmpty() && (it.normalizedNumber
|
||||
?: it.value).contains(text.normalizePhoneNumber(), true)
|
||||
} ||
|
||||
it.emails.any { it.value.contains(text, true) } ||
|
||||
it.addresses.any { getProperText(it.value, shouldNormalize).contains(text, true) } ||
|
||||
it.IMs.any { it.value.contains(text, true) } ||
|
||||
getProperText(it.notes, shouldNormalize).contains(text, true) ||
|
||||
getProperText(it.organization.company, shouldNormalize).contains(text, true) ||
|
||||
getProperText(it.organization.jobPosition, shouldNormalize).contains(text, true) ||
|
||||
it.websites.any { it.contains(text, true) }
|
||||
getProperText(it.nickname, shouldNormalize).contains(text, true) ||
|
||||
it.phoneNumbers.any {
|
||||
text.normalizePhoneNumber().isNotEmpty() && (it.normalizedNumber
|
||||
?: it.value).contains(text.normalizePhoneNumber(), true)
|
||||
} ||
|
||||
it.emails.any { it.value.contains(text, true) } ||
|
||||
it.addresses.any { getProperText(it.value, shouldNormalize).contains(text, true) } ||
|
||||
it.IMs.any { it.value.contains(text, true) } ||
|
||||
getProperText(it.notes, shouldNormalize).contains(text, true) ||
|
||||
getProperText(it.organization.company, shouldNormalize).contains(text, true) ||
|
||||
getProperText(it.organization.jobPosition, shouldNormalize).contains(text, true) ||
|
||||
it.websites.any { it.contains(text, true) }
|
||||
} as ArrayList
|
||||
|
||||
filtered.sortBy {
|
||||
|
@ -348,13 +342,6 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
}
|
||||
}
|
||||
|
||||
private fun updateViewStuff() {
|
||||
context.updateTextColors(fragment_wrapper.parent as ViewGroup)
|
||||
fragment_fastscroller?.updateBubbleColors()
|
||||
fragment_placeholder_2?.setTextColor(context.getAdjustedPrimaryColor())
|
||||
letter_fastscroller_thumb?.fontSize = context.getTextSize()
|
||||
}
|
||||
|
||||
private fun setupViewVisibility(hasItemsToShow: Boolean) {
|
||||
fragment_placeholder_2?.beVisibleIf(!hasItemsToShow)
|
||||
fragment_placeholder?.beVisibleIf(!hasItemsToShow)
|
||||
|
|
Loading…
Reference in New Issue