fix some glitches at managing favorites
This commit is contained in:
parent
5efc2fadb6
commit
4184abff80
|
@ -131,7 +131,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
|
|||
contactItems.removeAll(favoritesToRemove)
|
||||
|
||||
val favoriteIDsToRemove = HashSet<String>()
|
||||
favoritesToRemove.map { favoriteIDsToRemove.add(it.id.toString()) }
|
||||
favoritesToRemove.mapTo(favoriteIDsToRemove, { it.id.toString() })
|
||||
activity.config.removeFavorites(favoriteIDsToRemove)
|
||||
removeSelectedItems()
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ import com.simplemobiletools.contacts.extensions.config
|
|||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.models.Contact
|
||||
import kotlinx.android.synthetic.main.dialog_add_favorites.view.*
|
||||
import java.util.HashSet
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class AddFavoritesDialog(val activity: SimpleActivity, val callback: () -> Unit) {
|
||||
private var dialog: AlertDialog? = null
|
||||
|
@ -38,11 +40,16 @@ class AddFavoritesDialog(val activity: SimpleActivity, val callback: () -> Unit)
|
|||
}
|
||||
|
||||
private fun dialogConfirmed() {
|
||||
val allDisplayedIDs = ArrayList<String>()
|
||||
allContacts.mapTo(allDisplayedIDs, { it.id.toString() })
|
||||
val selectedItems = (view.add_favorites_list.adapter as AddFavoritesAdapter).getSelectedItemsSet()
|
||||
if (config.favorites != selectedItems) {
|
||||
config.favorites = selectedItems
|
||||
callback()
|
||||
}
|
||||
config.addFavorites(selectedItems)
|
||||
allDisplayedIDs.removeAll(selectedItems)
|
||||
|
||||
val favoriteIDsToRemove = HashSet<String>()
|
||||
allDisplayedIDs.mapTo(favoriteIDsToRemove, { it })
|
||||
config.removeFavorites(favoriteIDsToRemove)
|
||||
callback()
|
||||
dialog?.dismiss()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,8 +49,8 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
addFavorites(HashSet<String>(Arrays.asList(id)))
|
||||
}
|
||||
|
||||
private fun addFavorites(favs: Set<String>) {
|
||||
val currFavorites = HashSet<String>(favs)
|
||||
fun addFavorites(favs: Set<String>) {
|
||||
val currFavorites = HashSet<String>(favorites)
|
||||
currFavorites.addAll(favs)
|
||||
favorites = currFavorites
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
android:layout_alignBottom="@+id/contact_tmb"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignTop="@+id/contact_tmb"
|
||||
android:clickable="false"
|
||||
android:gravity="center_vertical"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in New Issue