properly show the placeholders if all contacts are removed

This commit is contained in:
tibbi 2017-12-30 20:05:59 +01:00
parent 4184abff80
commit bc0b4a9622
4 changed files with 19 additions and 5 deletions

View File

@ -186,7 +186,8 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_MULTISELECT or LICENSE_JODA or LICENSE_GLIDE, BuildConfig.VERSION_NAME)
}
override fun refreshItems() {
override fun refreshContacts() {
contacts_fragment.initContacts()
}
override fun refreshFavorites() {

View File

@ -115,8 +115,14 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
contactsToRemove.add(contactItems[it])
}
contactItems.removeAll(contactsToRemove)
ContactsHelper(activity).deleteContacts(contactsToRemove)
removeSelectedItems()
if (contactItems.isEmpty()) {
listener?.refreshContacts()
finishActMode()
} else {
removeSelectedItems()
}
}
private fun removeFavorites() {
@ -133,7 +139,12 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
val favoriteIDsToRemove = HashSet<String>()
favoritesToRemove.mapTo(favoriteIDsToRemove, { it.id.toString() })
activity.config.removeFavorites(favoriteIDsToRemove)
removeSelectedItems()
if (contactItems.isEmpty()) {
listener?.refreshFavorites()
finishActMode()
} else {
removeSelectedItems()
}
}
private fun addToFavorites() {

View File

@ -24,6 +24,7 @@ import kotlinx.android.synthetic.main.fragment_layout.view.*
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet) {
var activity: MainActivity? = null
var lastHashCode = 0
lateinit var config: Config
fun setupFragment(activity: MainActivity) {
@ -101,7 +102,8 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
}
}
if (contacts.hashCode() != (fragment_list.adapter as? ContactsAdapter)?.contactItems?.hashCode()) {
if (contacts.hashCode() != lastHashCode) {
lastHashCode = contacts.hashCode()
activity!!.runOnUiThread {
setupContacts(contacts)
}

View File

@ -1,7 +1,7 @@
package com.simplemobiletools.interfaces
interface RefreshContactsListener {
fun refreshItems()
fun refreshContacts()
fun refreshFavorites()
}