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