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