mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-17 03:51:03 +01:00
add a couple more functions in FragmentInterface
This commit is contained in:
parent
6e77d3cd51
commit
e33fe588c2
@ -26,9 +26,9 @@ import com.simplemobiletools.contacts.dialogs.ImportContactsDialog
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.extensions.dbHelper
|
||||
import com.simplemobiletools.contacts.extensions.getTempFile
|
||||
import com.simplemobiletools.contacts.fragments.MyViewPagerFragment
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.helpers.VcfExporter
|
||||
import com.simplemobiletools.contacts.interfaces.FragmentInterface
|
||||
import com.simplemobiletools.contacts.interfaces.RefreshContactsListener
|
||||
import com.simplemobiletools.contacts.models.Contact
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
@ -93,9 +93,9 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||
|
||||
val configShowContactThumbnails = config.showContactThumbnails
|
||||
if (storedShowContactThumbnails != configShowContactThumbnails) {
|
||||
contacts_fragment?.showContactThumbnailsChanged(configShowContactThumbnails)
|
||||
favorites_fragment?.showContactThumbnailsChanged(configShowContactThumbnails)
|
||||
groups_fragment?.showContactThumbnailsChanged(configShowContactThumbnails)
|
||||
getAllFragments().forEach {
|
||||
(it as? FragmentInterface)?.showContactThumbnailsChanged(configShowContactThumbnails)
|
||||
}
|
||||
}
|
||||
|
||||
val configTextColor = config.textColor
|
||||
@ -103,9 +103,9 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||
getInactiveTabIndexes(viewpager.currentItem).forEach {
|
||||
main_tabs_holder.getTabAt(it)?.icon?.applyColorFilter(configTextColor)
|
||||
}
|
||||
contacts_fragment?.textColorChanged(configTextColor)
|
||||
favorites_fragment?.textColorChanged(configTextColor)
|
||||
groups_fragment?.textColorChanged(configTextColor)
|
||||
getAllFragments().forEach {
|
||||
(it as? FragmentInterface)?.textColorChanged(configTextColor)
|
||||
}
|
||||
}
|
||||
|
||||
val configBackgroundColor = config.backgroundColor
|
||||
@ -117,9 +117,9 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||
if (storedPrimaryColor != configPrimaryColor) {
|
||||
main_tabs_holder.setSelectedTabIndicatorColor(getAdjustedPrimaryColor())
|
||||
main_tabs_holder.getTabAt(viewpager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor())
|
||||
contacts_fragment?.primaryColorChanged(configPrimaryColor)
|
||||
favorites_fragment?.primaryColorChanged(configPrimaryColor)
|
||||
groups_fragment?.primaryColorChanged(configPrimaryColor)
|
||||
getAllFragments().forEach {
|
||||
(it as? FragmentInterface)?.primaryColorChanged(configPrimaryColor)
|
||||
}
|
||||
}
|
||||
|
||||
val configStartNameWithSurname = config.startNameWithSurname
|
||||
@ -133,9 +133,9 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||
initFragments()
|
||||
}
|
||||
|
||||
contacts_fragment?.onActivityResume()
|
||||
favorites_fragment?.onActivityResume()
|
||||
groups_fragment?.onActivityResume()
|
||||
getAllFragments().forEach {
|
||||
(it as? FragmentInterface)?.onActivityResume()
|
||||
}
|
||||
refreshContacts(true, true)
|
||||
}
|
||||
|
||||
@ -197,7 +197,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||
|
||||
override fun onQueryTextChange(newText: String): Boolean {
|
||||
if (isSearchOpen) {
|
||||
(getCurrentFragment() as? MyViewPagerFragment)?.onSearchQueryChanged(newText)
|
||||
getCurrentFragment()?.onSearchQueryChanged(newText)
|
||||
}
|
||||
return true
|
||||
}
|
||||
@ -206,20 +206,20 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||
|
||||
MenuItemCompat.setOnActionExpandListener(searchMenuItem, object : MenuItemCompat.OnActionExpandListener {
|
||||
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
||||
(getCurrentFragment() as? MyViewPagerFragment)?.onSearchOpened()
|
||||
getCurrentFragment()?.onSearchOpened()
|
||||
isSearchOpen = true
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
|
||||
(getCurrentFragment() as? MyViewPagerFragment)?.onSearchClosed()
|
||||
getCurrentFragment()?.onSearchClosed()
|
||||
isSearchOpen = false
|
||||
return true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun getCurrentFragment() = when (viewpager.currentItem) {
|
||||
private fun getCurrentFragment(): FragmentInterface? = when (viewpager.currentItem) {
|
||||
0 -> contacts_fragment
|
||||
1 -> favorites_fragment
|
||||
else -> groups_fragment
|
||||
@ -275,7 +275,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||
viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
||||
override fun onPageScrollStateChanged(state: Int) {
|
||||
if (isSearchOpen) {
|
||||
(getCurrentFragment() as? MyViewPagerFragment)?.onSearchQueryChanged("")
|
||||
getCurrentFragment()?.onSearchQueryChanged("")
|
||||
searchMenuItem?.collapseActionView()
|
||||
}
|
||||
}
|
||||
@ -285,8 +285,9 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||
|
||||
override fun onPageSelected(position: Int) {
|
||||
main_tabs_holder.getTabAt(position)?.select()
|
||||
contacts_fragment?.finishActMode()
|
||||
favorites_fragment?.finishActMode()
|
||||
getAllFragments().forEach {
|
||||
(it as? FragmentInterface)?.finishActMode()
|
||||
}
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
})
|
||||
@ -425,6 +426,8 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAllFragments() = arrayListOf(contacts_fragment, favorites_fragment, groups_fragment)
|
||||
|
||||
override fun refreshFavorites() {
|
||||
refreshContacts(false, true)
|
||||
}
|
||||
|
@ -88,10 +88,23 @@ class GroupsFragment(context: Context, attributeSet: AttributeSet) : Coordinator
|
||||
}
|
||||
}
|
||||
|
||||
fun onActivityResume() {
|
||||
override fun onActivityResume() {
|
||||
updateViewStuff()
|
||||
}
|
||||
|
||||
override fun finishActMode() {
|
||||
(groups_list.adapter as? GroupsAdapter)?.finishActMode()
|
||||
}
|
||||
|
||||
override fun onSearchQueryChanged(text: String) {
|
||||
}
|
||||
|
||||
override fun onSearchOpened() {
|
||||
}
|
||||
|
||||
override fun onSearchClosed() {
|
||||
}
|
||||
|
||||
private fun updateViewStuff() {
|
||||
context.updateTextColors(groups_wrapper.parent as ViewGroup)
|
||||
groups_fastscroller.updateBubbleColors()
|
||||
|
@ -149,15 +149,15 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||
}
|
||||
}
|
||||
|
||||
fun onActivityResume() {
|
||||
override fun onActivityResume() {
|
||||
updateViewStuff()
|
||||
}
|
||||
|
||||
fun finishActMode() {
|
||||
override fun finishActMode() {
|
||||
(fragment_list.adapter as? ContactsAdapter)?.finishActMode()
|
||||
}
|
||||
|
||||
fun onSearchQueryChanged(text: String) {
|
||||
override fun onSearchQueryChanged(text: String) {
|
||||
(fragment_list.adapter as? ContactsAdapter)?.apply {
|
||||
val filtered = contactsIgnoringSearch.filter {
|
||||
it.getFullName(startNameWithSurname).contains(text, true) ||
|
||||
@ -180,11 +180,11 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||
}
|
||||
}
|
||||
|
||||
fun onSearchOpened() {
|
||||
override fun onSearchOpened() {
|
||||
contactsIgnoringSearch = (fragment_list?.adapter as? ContactsAdapter)?.contactItems ?: ArrayList()
|
||||
}
|
||||
|
||||
fun onSearchClosed() {
|
||||
override fun onSearchClosed() {
|
||||
(fragment_list.adapter as? ContactsAdapter)?.updateItems(contactsIgnoringSearch)
|
||||
if (this is FavoritesFragment) {
|
||||
fragment_placeholder.text = activity?.getString(R.string.no_favorites)
|
||||
|
@ -6,6 +6,8 @@ import com.simplemobiletools.contacts.models.Contact
|
||||
interface FragmentInterface {
|
||||
fun setupFragment(activity: MainActivity)
|
||||
|
||||
fun onActivityResume()
|
||||
|
||||
fun textColorChanged(color: Int)
|
||||
|
||||
fun primaryColorChanged(color: Int)
|
||||
@ -13,4 +15,12 @@ interface FragmentInterface {
|
||||
fun refreshContacts(contacts: ArrayList<Contact>)
|
||||
|
||||
fun showContactThumbnailsChanged(showThumbnails: Boolean)
|
||||
|
||||
fun finishActMode()
|
||||
|
||||
fun onSearchQueryChanged(text: String)
|
||||
|
||||
fun onSearchOpened()
|
||||
|
||||
fun onSearchClosed()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user