mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-03-25 15:50:14 +01:00
properly update all colors if needed
This commit is contained in:
parent
52f3acd246
commit
496a5469ae
@ -21,11 +21,15 @@ import kotlinx.android.synthetic.main.fragment_contacts.*
|
||||
import kotlinx.android.synthetic.main.fragment_recents.*
|
||||
|
||||
class MainActivity : SimpleActivity() {
|
||||
private var storedTextColor = 0
|
||||
private var storedPrimaryColor = 0
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
appLaunched(BuildConfig.APPLICATION_ID)
|
||||
setupTabColors()
|
||||
storeStateVariables()
|
||||
|
||||
if (isDefaultDialer()) {
|
||||
checkContactPermissions()
|
||||
@ -41,6 +45,33 @@ class MainActivity : SimpleActivity() {
|
||||
setImageDrawable(dialpadIcon)
|
||||
background.applyColorFilter(getAdjustedPrimaryColor())
|
||||
}
|
||||
|
||||
main_tabs_holder.setBackgroundColor(config.backgroundColor)
|
||||
|
||||
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 configPrimaryColor = config.primaryColor
|
||||
if (storedPrimaryColor != configPrimaryColor) {
|
||||
main_tabs_holder.setSelectedTabIndicatorColor(getAdjustedPrimaryColor())
|
||||
main_tabs_holder.getTabAt(viewpager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor())
|
||||
getAllFragments().forEach {
|
||||
it?.primaryColorChanged(configPrimaryColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
storeStateVariables()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
@ -71,6 +102,13 @@ class MainActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun storeStateVariables() {
|
||||
config.apply {
|
||||
storedTextColor = textColor
|
||||
storedPrimaryColor = primaryColor
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkContactPermissions() {
|
||||
handlePermission(PERMISSION_READ_CONTACTS) {
|
||||
if (it) {
|
||||
@ -186,7 +224,7 @@ class MainActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAllFragments() = arrayListOf(contacts_fragment)
|
||||
private fun getAllFragments() = arrayListOf(contacts_fragment, recents_fragment)
|
||||
|
||||
private fun launchAbout() {
|
||||
val licenses = LICENSE_GLIDE or LICENSE_INDICATOR_FAST_SCROLL
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.simplemobiletools.dialer.adapters
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.provider.CallLog.Calls
|
||||
import android.util.TypedValue
|
||||
import android.view.Menu
|
||||
@ -20,10 +21,14 @@ import java.util.*
|
||||
class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<RecentCall>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
|
||||
|
||||
private val incomingCallIcon = activity.resources.getColoredDrawableWithColor(R.drawable.ic_incoming_call_vector, activity.config.textColor)
|
||||
private val outgoingCallIcon = activity.resources.getColoredDrawableWithColor(R.drawable.ic_outgoing_call_vector, activity.config.textColor)
|
||||
private lateinit var incomingCallIcon: Drawable
|
||||
private lateinit var outgoingCallIcon: Drawable
|
||||
private var fontSize = activity.getTextSize()
|
||||
|
||||
init {
|
||||
initDrawables()
|
||||
}
|
||||
|
||||
override fun getActionMenuId() = 0
|
||||
|
||||
override fun prepareActionMode(menu: Menu) {}
|
||||
@ -61,6 +66,11 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
|
||||
}
|
||||
}
|
||||
|
||||
fun initDrawables() {
|
||||
incomingCallIcon = activity.resources.getColoredDrawableWithColor(R.drawable.ic_incoming_call_vector, activity.config.textColor)
|
||||
outgoingCallIcon = activity.resources.getColoredDrawableWithColor(R.drawable.ic_outgoing_call_vector, activity.config.textColor)
|
||||
}
|
||||
|
||||
private fun setupView(view: View, call: RecentCall) {
|
||||
view.apply {
|
||||
item_recents_name.apply {
|
||||
|
@ -5,6 +5,7 @@ import android.net.Uri
|
||||
import android.provider.ContactsContract
|
||||
import android.util.AttributeSet
|
||||
import com.reddit.indicatorfastscroll.FastScrollItemIndicator
|
||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
||||
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
|
||||
@ -46,6 +47,17 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
|
||||
letter_fastscroller_thumb.textColor = context.config.primaryColor.getContrastColor()
|
||||
}
|
||||
|
||||
override fun textColorChanged(color: Int) {
|
||||
(fragment_list?.adapter as? MyRecyclerViewAdapter)?.updateTextColor(color)
|
||||
letter_fastscroller?.textColor = color.getColorStateList()
|
||||
}
|
||||
|
||||
override fun primaryColorChanged(color: Int) {
|
||||
letter_fastscroller_thumb?.thumbColor = color.getColorStateList()
|
||||
letter_fastscroller_thumb?.textColor = color.getContrastColor()
|
||||
fragment_fab.background.applyColorFilter(context.getAdjustedPrimaryColor())
|
||||
}
|
||||
|
||||
fun refreshContacts(contacts: ArrayList<SimpleContact>) {
|
||||
setupLetterFastscroller(contacts)
|
||||
if (contacts.isEmpty()) {
|
||||
|
@ -28,4 +28,8 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||
}
|
||||
|
||||
abstract fun setupFragment()
|
||||
|
||||
abstract fun textColorChanged(color: Int)
|
||||
|
||||
abstract fun primaryColorChanged(color: Int)
|
||||
}
|
||||
|
@ -30,6 +30,15 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
||||
}
|
||||
}
|
||||
|
||||
override fun textColorChanged(color: Int) {
|
||||
(recents_list?.adapter as? RecentCallsAdapter)?.apply {
|
||||
initDrawables()
|
||||
updateTextColor(color)
|
||||
}
|
||||
}
|
||||
|
||||
override fun primaryColorChanged(color: Int) {}
|
||||
|
||||
fun updateRecents(recents: ArrayList<RecentCall>) {
|
||||
if (recents.isEmpty()) {
|
||||
recents_placeholder.beVisible()
|
||||
|
Loading…
x
Reference in New Issue
Block a user