create an interface for all fragments

This commit is contained in:
tibbi 2018-03-19 10:11:58 +01:00
parent 4294228bfd
commit f74376e8ac
5 changed files with 45 additions and 19 deletions

View File

@ -115,8 +115,8 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
if (storedPrimaryColor != configPrimaryColor) {
main_tabs_holder.setSelectedTabIndicatorColor(getAdjustedPrimaryColor())
main_tabs_holder.getTabAt(viewpager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor())
contacts_fragment?.primaryColorChanged()
favorites_fragment?.primaryColorChanged()
contacts_fragment?.primaryColorChanged(configPrimaryColor)
favorites_fragment?.primaryColorChanged(configPrimaryColor)
}
val configStartNameWithSurname = config.startNameWithSurname
@ -130,9 +130,9 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
initFragments()
}
contacts_fragment?.initContacts()
contacts_fragment?.refreshContacts()
contacts_fragment?.onActivityResume()
favorites_fragment?.initContacts()
favorites_fragment?.refreshContacts()
favorites_fragment?.onActivityResume()
}
@ -306,15 +306,15 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
private fun showSortingDialog() {
ChangeSortingDialog(this) {
contacts_fragment?.initContacts()
favorites_fragment?.initContacts()
contacts_fragment?.refreshContacts()
favorites_fragment?.refreshContacts()
}
}
fun showFilterDialog() {
FilterContactSourcesDialog(this) {
contacts_fragment?.forceListRedraw = true
contacts_fragment?.initContacts()
contacts_fragment?.refreshContacts()
}
}
@ -400,12 +400,12 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
}
override fun refreshContacts() {
contacts_fragment.initContacts()
favorites_fragment.initContacts()
contacts_fragment.refreshContacts()
favorites_fragment.refreshContacts()
}
override fun refreshFavorites() {
favorites_fragment?.initContacts()
favorites_fragment?.refreshContacts()
}
private fun checkWhatsNewDialog() {

View File

@ -16,7 +16,7 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
private fun showAddFavoritesDialog() {
AddFavoritesDialog(activity!!) {
initContacts()
refreshContacts()
}
}
}

View File

@ -3,7 +3,19 @@ package com.simplemobiletools.contacts.fragments
import android.content.Context
import android.support.design.widget.CoordinatorLayout
import android.util.AttributeSet
import com.simplemobiletools.contacts.activities.MainActivity
import com.simplemobiletools.contacts.interfaces.FragmentInterface
class GroupsFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet) {
class GroupsFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet), FragmentInterface {
override fun setupFragment(activity: MainActivity) {
}
override fun textColorChanged(color: Int) {
}
override fun primaryColorChanged(color: Int) {
}
override fun refreshContacts() {
}
}

View File

@ -16,10 +16,11 @@ import com.simplemobiletools.contacts.extensions.editContact
import com.simplemobiletools.contacts.extensions.tryStartCall
import com.simplemobiletools.contacts.extensions.viewContact
import com.simplemobiletools.contacts.helpers.*
import com.simplemobiletools.contacts.interfaces.FragmentInterface
import com.simplemobiletools.contacts.models.Contact
import kotlinx.android.synthetic.main.fragment_layout.view.*
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet) {
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet), FragmentInterface {
protected var activity: MainActivity? = null
private var lastHashCode = 0
private var contactsIgnoringSearch = ArrayList<Contact>()
@ -27,7 +28,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
var forceListRedraw = false
fun setupFragment(activity: MainActivity) {
override fun setupFragment(activity: MainActivity) {
config = activity.config
if (this.activity == null) {
this.activity = activity
@ -48,17 +49,17 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
}
}
initContacts()
refreshContacts()
}
fun textColorChanged(color: Int) {
override fun textColorChanged(color: Int) {
(fragment_list.adapter as ContactsAdapter).apply {
updateTextColor(color)
initDrawables()
}
}
fun primaryColorChanged() {
override fun primaryColorChanged(color: Int) {
fragment_fastscroller.updatePrimaryColor()
fragment_fastscroller.updateBubblePrimaryColor()
}
@ -66,11 +67,11 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
fun startNameWithSurnameChanged(startNameWithSurname: Boolean) {
(fragment_list.adapter as ContactsAdapter).apply {
config.sorting = if (startNameWithSurname) SORT_BY_SURNAME else SORT_BY_FIRST_NAME
initContacts()
refreshContacts()
}
}
fun initContacts() {
override fun refreshContacts() {
if (activity == null || activity!!.isActivityDestroyed()) {
return
}

View File

@ -0,0 +1,13 @@
package com.simplemobiletools.contacts.interfaces
import com.simplemobiletools.contacts.activities.MainActivity
interface FragmentInterface {
fun setupFragment(activity: MainActivity)
fun textColorChanged(color: Int)
fun primaryColorChanged(color: Int)
fun refreshContacts()
}