properly update Groups tab whenever necessary
This commit is contained in:
parent
d2daf6efdb
commit
244955e333
|
@ -104,13 +104,10 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener, Refresh
|
|||
}
|
||||
}
|
||||
|
||||
override fun refreshContacts(refreshContactsTab: Boolean, refreshFavoritesTab: Boolean) {
|
||||
override fun refreshContacts(refreshTabsMask: Int) {
|
||||
refreshContacts()
|
||||
}
|
||||
|
||||
override fun refreshFavorites() {
|
||||
}
|
||||
|
||||
override fun removeFromGroup(contacts: ArrayList<Contact>) {
|
||||
ContactsHelper(this).removeContactsFromGroup(contacts, group.id)
|
||||
if (groupContacts.size == 0) {
|
||||
|
|
|
@ -26,8 +26,7 @@ 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.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.helpers.VcfExporter
|
||||
import com.simplemobiletools.contacts.helpers.*
|
||||
import com.simplemobiletools.contacts.interfaces.RefreshContactsListener
|
||||
import com.simplemobiletools.contacts.models.Contact
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
|
@ -117,7 +116,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
main_tabs_holder.setSelectedTabIndicatorColor(getAdjustedPrimaryColor())
|
||||
main_tabs_holder.getTabAt(viewpager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor())
|
||||
getAllFragments().forEach {
|
||||
it?.primaryColorChanged(configPrimaryColor)
|
||||
it?.primaryColorChanged()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,7 +134,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
getAllFragments().forEach {
|
||||
it?.onActivityResume()
|
||||
}
|
||||
refreshContacts(true, true)
|
||||
refreshContacts(ALL_TABS_MASK)
|
||||
}
|
||||
|
||||
if (hasPermission(PERMISSION_WRITE_CONTACTS)) {
|
||||
|
@ -269,7 +268,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
private fun getInactiveTabIndexes(activeIndex: Int) = arrayListOf(0, 1, 2).filter { it != activeIndex }
|
||||
|
||||
private fun initFragments() {
|
||||
refreshContacts(true, true)
|
||||
refreshContacts(ALL_TABS_MASK)
|
||||
viewpager.offscreenPageLimit = 2
|
||||
viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
||||
override fun onPageScrollStateChanged(state: Int) {
|
||||
|
@ -308,14 +307,14 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
|
||||
private fun showSortingDialog() {
|
||||
ChangeSortingDialog(this) {
|
||||
refreshContacts(true, true)
|
||||
refreshContacts(CONTACTS_TAB_MASK or FAVORITES_TAB_MASK)
|
||||
}
|
||||
}
|
||||
|
||||
fun showFilterDialog() {
|
||||
FilterContactSourcesDialog(this) {
|
||||
contacts_fragment?.forceListRedraw = true
|
||||
refreshContacts(true, false)
|
||||
refreshContacts(CONTACTS_TAB_MASK)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -337,7 +336,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
ImportContactsDialog(this, path) {
|
||||
if (it) {
|
||||
runOnUiThread {
|
||||
refreshContacts(true, true)
|
||||
refreshContacts(ALL_TABS_MASK)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -400,7 +399,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
BuildConfig.VERSION_NAME, faqItems)
|
||||
}
|
||||
|
||||
override fun refreshContacts(refreshContactsTab: Boolean, refreshFavoritesTab: Boolean) {
|
||||
override fun refreshContacts(refreshTabsMask: Int) {
|
||||
if (isActivityDestroyed()) {
|
||||
return
|
||||
}
|
||||
|
@ -415,22 +414,25 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
viewpager.currentItem = config.lastUsedViewPagerPage
|
||||
}
|
||||
|
||||
if (refreshContactsTab) {
|
||||
if (refreshTabsMask and CONTACTS_TAB_MASK != 0) {
|
||||
contacts_fragment?.refreshContacts(it)
|
||||
}
|
||||
|
||||
if (refreshFavoritesTab) {
|
||||
if (refreshTabsMask and FAVORITES_TAB_MASK != 0) {
|
||||
favorites_fragment?.refreshContacts(it)
|
||||
}
|
||||
|
||||
if (refreshTabsMask and GROUPS_TAB_MASK != 0) {
|
||||
if (refreshTabsMask == GROUPS_TAB_MASK) {
|
||||
groups_fragment.skipHashComparing = true
|
||||
}
|
||||
groups_fragment?.refreshContacts(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAllFragments() = arrayListOf(contacts_fragment, favorites_fragment, groups_fragment)
|
||||
|
||||
override fun refreshFavorites() {
|
||||
refreshContacts(false, true)
|
||||
}
|
||||
|
||||
private fun checkWhatsNewDialog() {
|
||||
arrayListOf<Release>().apply {
|
||||
add(Release(10, R.string.release_10))
|
||||
|
|
|
@ -21,10 +21,7 @@ import com.simplemobiletools.contacts.activities.SimpleActivity
|
|||
import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.extensions.editContact
|
||||
import com.simplemobiletools.contacts.extensions.shareContacts
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.helpers.LOCATION_CONTACTS_TAB
|
||||
import com.simplemobiletools.contacts.helpers.LOCATION_FAVORITES_TAB
|
||||
import com.simplemobiletools.contacts.helpers.LOCATION_GROUP_CONTACTS
|
||||
import com.simplemobiletools.contacts.helpers.*
|
||||
import com.simplemobiletools.contacts.interfaces.RefreshContactsListener
|
||||
import com.simplemobiletools.contacts.interfaces.RemoveFromGroupListener
|
||||
import com.simplemobiletools.contacts.models.Contact
|
||||
|
@ -140,11 +137,11 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
|
|||
|
||||
ContactsHelper(activity).deleteContacts(contactsToRemove)
|
||||
if (contactItems.isEmpty()) {
|
||||
refreshListener?.refreshContacts(true, true)
|
||||
refreshListener?.refreshContacts(ALL_TABS_MASK)
|
||||
finishActMode()
|
||||
} else {
|
||||
removeSelectedItems()
|
||||
refreshListener?.refreshFavorites()
|
||||
refreshListener?.refreshContacts(FAVORITES_TAB_MASK)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,7 +155,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
|
|||
if (location == LOCATION_FAVORITES_TAB) {
|
||||
ContactsHelper(activity).removeFavorites(contactsToRemove)
|
||||
if (contactItems.isEmpty()) {
|
||||
refreshListener?.refreshFavorites()
|
||||
refreshListener?.refreshContacts(FAVORITES_TAB_MASK)
|
||||
finishActMode()
|
||||
} else {
|
||||
removeSelectedItems()
|
||||
|
@ -173,7 +170,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
|
|||
val newFavorites = ArrayList<Contact>()
|
||||
selectedPositions.forEach { newFavorites.add(contactItems[it]) }
|
||||
ContactsHelper(activity).addFavorites(newFavorites)
|
||||
refreshListener?.refreshFavorites()
|
||||
refreshListener?.refreshContacts(FAVORITES_TAB_MASK)
|
||||
finishActMode()
|
||||
}
|
||||
|
||||
|
|
|
@ -13,12 +13,14 @@ import com.simplemobiletools.contacts.R
|
|||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.helpers.GROUPS_TAB_MASK
|
||||
import com.simplemobiletools.contacts.interfaces.RefreshContactsListener
|
||||
import com.simplemobiletools.contacts.models.Group
|
||||
import kotlinx.android.synthetic.main.item_group.view.*
|
||||
import java.util.*
|
||||
|
||||
class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, recyclerView: MyRecyclerView, fastScroller: FastScroller,
|
||||
itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val refreshListener: RefreshContactsListener?, recyclerView: MyRecyclerView,
|
||||
fastScroller: FastScroller, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
|
||||
private var config = activity.config
|
||||
private var smallPadding = activity.resources.getDimension(R.dimen.small_margin).toInt()
|
||||
|
@ -94,7 +96,13 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, recy
|
|||
ContactsHelper(activity).deleteGroup(group.id)
|
||||
}
|
||||
groups.removeAll(groupsToRemove)
|
||||
removeSelectedItems()
|
||||
|
||||
if (groups.isEmpty()) {
|
||||
refreshListener?.refreshContacts(GROUPS_TAB_MASK)
|
||||
finishActMode()
|
||||
} else {
|
||||
removeSelectedItems()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupView(view: View, group: Group) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.util.AttributeSet
|
|||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.dialogs.SelectContactsDialog
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.helpers.FAVORITES_TAB_MASK
|
||||
|
||||
class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
|
||||
override fun fabClicked() {
|
||||
|
@ -23,7 +24,7 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
|
|||
removeFavorites(removedContacts)
|
||||
}
|
||||
|
||||
activity!!.refreshContacts(false, true)
|
||||
activity!!.refreshContacts(FAVORITES_TAB_MASK)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import android.util.AttributeSet
|
||||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.dialogs.CreateNewGroupDialog
|
||||
import com.simplemobiletools.contacts.helpers.GROUPS_TAB_MASK
|
||||
|
||||
class GroupsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
|
||||
override fun fabClicked() {
|
||||
|
@ -17,7 +18,7 @@ class GroupsFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
|
|||
|
||||
private fun showNewGroupsDialog() {
|
||||
CreateNewGroupDialog(activity as SimpleActivity) {
|
||||
refreshContacts(allContacts)
|
||||
activity!!.refreshContacts(GROUPS_TAB_MASK)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
private var contactsIgnoringSearch = ArrayList<Contact>()
|
||||
private lateinit var config: Config
|
||||
|
||||
var skipHashComparing = false
|
||||
var forceListRedraw = false
|
||||
|
||||
fun setupFragment(activity: MainActivity) {
|
||||
|
@ -70,7 +71,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
}
|
||||
}
|
||||
|
||||
fun primaryColorChanged(color: Int) {
|
||||
fun primaryColorChanged() {
|
||||
fragment_fastscroller.updatePrimaryColor()
|
||||
fragment_fastscroller.updateBubblePrimaryColor()
|
||||
}
|
||||
|
@ -79,7 +80,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
if (this !is GroupsFragment) {
|
||||
(fragment_list.adapter as ContactsAdapter).apply {
|
||||
config.sorting = if (startNameWithSurname) SORT_BY_SURNAME else SORT_BY_FIRST_NAME
|
||||
this@MyViewPagerFragment.activity!!.refreshContacts(true, true)
|
||||
this@MyViewPagerFragment.activity!!.refreshContacts(CONTACTS_TAB_MASK or FAVORITES_TAB_MASK)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +106,8 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
}
|
||||
}
|
||||
|
||||
if (filtered.hashCode() != lastHashCode) {
|
||||
if (filtered.hashCode() != lastHashCode || skipHashComparing) {
|
||||
skipHashComparing = false
|
||||
lastHashCode = filtered.hashCode()
|
||||
activity?.runOnUiThread {
|
||||
setupContacts(filtered)
|
||||
|
@ -131,7 +133,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
}
|
||||
}
|
||||
|
||||
storedGroups = storedGroups.sortedWith(compareBy { it.title }).toList() as? ArrayList<Group> ?: ArrayList()
|
||||
storedGroups = storedGroups.sortedWith(compareBy { it.title }).toMutableList() as ArrayList<Group>
|
||||
|
||||
fragment_placeholder_2.beVisibleIf(storedGroups.isEmpty())
|
||||
fragment_placeholder.beVisibleIf(storedGroups.isEmpty())
|
||||
|
@ -139,7 +141,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
|
||||
val currAdapter = fragment_list.adapter
|
||||
if (currAdapter == null) {
|
||||
GroupsAdapter(activity as SimpleActivity, storedGroups, fragment_list, fragment_fastscroller) {
|
||||
GroupsAdapter(activity as SimpleActivity, storedGroups, activity, fragment_list, fragment_fastscroller) {
|
||||
Intent(activity, GroupContactsActivity::class.java).apply {
|
||||
putExtra(GROUP, it as Group)
|
||||
activity!!.startActivity(this)
|
||||
|
|
|
@ -19,6 +19,11 @@ const val LOCATION_CONTACTS_TAB = 1
|
|||
const val LOCATION_FAVORITES_TAB = 2
|
||||
const val LOCATION_GROUP_CONTACTS = 3
|
||||
|
||||
const val CONTACTS_TAB_MASK = 1
|
||||
const val FAVORITES_TAB_MASK = 2
|
||||
const val GROUPS_TAB_MASK = 4
|
||||
const val ALL_TABS_MASK = 7
|
||||
|
||||
// contact photo changes
|
||||
const val PHOTO_ADDED = 1
|
||||
const val PHOTO_REMOVED = 2
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simplemobiletools.contacts.interfaces
|
||||
|
||||
interface RefreshContactsListener {
|
||||
fun refreshContacts(refreshContactsTab: Boolean, refreshFavoritesTab: Boolean)
|
||||
|
||||
fun refreshFavorites()
|
||||
fun refreshContacts(refreshTabsMask: Int)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue