mirror of
				https://github.com/SimpleMobileTools/Simple-Dialer.git
				synced 2025-06-05 21:49:23 +02:00 
			
		
		
		
	properly update all colors if needed
This commit is contained in:
		| @@ -21,11 +21,15 @@ import kotlinx.android.synthetic.main.fragment_contacts.* | |||||||
| import kotlinx.android.synthetic.main.fragment_recents.* | import kotlinx.android.synthetic.main.fragment_recents.* | ||||||
|  |  | ||||||
| class MainActivity : SimpleActivity() { | class MainActivity : SimpleActivity() { | ||||||
|  |     private var storedTextColor = 0 | ||||||
|  |     private var storedPrimaryColor = 0 | ||||||
|  |  | ||||||
|     override fun onCreate(savedInstanceState: Bundle?) { |     override fun onCreate(savedInstanceState: Bundle?) { | ||||||
|         super.onCreate(savedInstanceState) |         super.onCreate(savedInstanceState) | ||||||
|         setContentView(R.layout.activity_main) |         setContentView(R.layout.activity_main) | ||||||
|         appLaunched(BuildConfig.APPLICATION_ID) |         appLaunched(BuildConfig.APPLICATION_ID) | ||||||
|         setupTabColors() |         setupTabColors() | ||||||
|  |         storeStateVariables() | ||||||
|  |  | ||||||
|         if (isDefaultDialer()) { |         if (isDefaultDialer()) { | ||||||
|             checkContactPermissions() |             checkContactPermissions() | ||||||
| @@ -41,6 +45,33 @@ class MainActivity : SimpleActivity() { | |||||||
|             setImageDrawable(dialpadIcon) |             setImageDrawable(dialpadIcon) | ||||||
|             background.applyColorFilter(getAdjustedPrimaryColor()) |             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() { |     override fun onDestroy() { | ||||||
| @@ -71,6 +102,13 @@ class MainActivity : SimpleActivity() { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     private fun storeStateVariables() { | ||||||
|  |         config.apply { | ||||||
|  |             storedTextColor = textColor | ||||||
|  |             storedPrimaryColor = primaryColor | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     private fun checkContactPermissions() { |     private fun checkContactPermissions() { | ||||||
|         handlePermission(PERMISSION_READ_CONTACTS) { |         handlePermission(PERMISSION_READ_CONTACTS) { | ||||||
|             if (it) { |             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() { |     private fun launchAbout() { | ||||||
|         val licenses = LICENSE_GLIDE or LICENSE_INDICATOR_FAST_SCROLL |         val licenses = LICENSE_GLIDE or LICENSE_INDICATOR_FAST_SCROLL | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| package com.simplemobiletools.dialer.adapters | package com.simplemobiletools.dialer.adapters | ||||||
|  |  | ||||||
|  | import android.graphics.drawable.Drawable | ||||||
| import android.provider.CallLog.Calls | import android.provider.CallLog.Calls | ||||||
| import android.util.TypedValue | import android.util.TypedValue | ||||||
| import android.view.Menu | import android.view.Menu | ||||||
| @@ -20,10 +21,14 @@ import java.util.* | |||||||
| class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<RecentCall>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : | class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<RecentCall>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : | ||||||
|         MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) { |         MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) { | ||||||
|  |  | ||||||
|     private val incomingCallIcon = activity.resources.getColoredDrawableWithColor(R.drawable.ic_incoming_call_vector, activity.config.textColor) |     private lateinit var incomingCallIcon: Drawable | ||||||
|     private val outgoingCallIcon = activity.resources.getColoredDrawableWithColor(R.drawable.ic_outgoing_call_vector, activity.config.textColor) |     private lateinit var outgoingCallIcon: Drawable | ||||||
|     private var fontSize = activity.getTextSize() |     private var fontSize = activity.getTextSize() | ||||||
|  |  | ||||||
|  |     init { | ||||||
|  |         initDrawables() | ||||||
|  |     } | ||||||
|  |  | ||||||
|     override fun getActionMenuId() = 0 |     override fun getActionMenuId() = 0 | ||||||
|  |  | ||||||
|     override fun prepareActionMode(menu: Menu) {} |     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) { |     private fun setupView(view: View, call: RecentCall) { | ||||||
|         view.apply { |         view.apply { | ||||||
|             item_recents_name.apply { |             item_recents_name.apply { | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ import android.net.Uri | |||||||
| import android.provider.ContactsContract | import android.provider.ContactsContract | ||||||
| import android.util.AttributeSet | import android.util.AttributeSet | ||||||
| import com.reddit.indicatorfastscroll.FastScrollItemIndicator | import com.reddit.indicatorfastscroll.FastScrollItemIndicator | ||||||
|  | import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter | ||||||
| import com.simplemobiletools.commons.extensions.* | import com.simplemobiletools.commons.extensions.* | ||||||
| import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS | import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS | ||||||
| import com.simplemobiletools.commons.helpers.SimpleContactsHelper | 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() |         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>) { |     fun refreshContacts(contacts: ArrayList<SimpleContact>) { | ||||||
|         setupLetterFastscroller(contacts) |         setupLetterFastscroller(contacts) | ||||||
|         if (contacts.isEmpty()) { |         if (contacts.isEmpty()) { | ||||||
|   | |||||||
| @@ -28,4 +28,8 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     abstract fun setupFragment() |     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>) { |     fun updateRecents(recents: ArrayList<RecentCall>) { | ||||||
|         if (recents.isEmpty()) { |         if (recents.isEmpty()) { | ||||||
|             recents_placeholder.beVisible() |             recents_placeholder.beVisible() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user