mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-02 00:47:05 +01:00
allow removing favorites by long pressing them + Remove
This commit is contained in:
parent
d21b3e7c4d
commit
5efc2fadb6
@ -22,6 +22,7 @@ import com.simplemobiletools.contacts.helpers.ContactsHelper
|
|||||||
import com.simplemobiletools.contacts.models.Contact
|
import com.simplemobiletools.contacts.models.Contact
|
||||||
import com.simplemobiletools.interfaces.RefreshContactsListener
|
import com.simplemobiletools.interfaces.RefreshContactsListener
|
||||||
import kotlinx.android.synthetic.main.item_contact_with_number.view.*
|
import kotlinx.android.synthetic.main.item_contact_with_number.view.*
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Contact>, val listener: RefreshContactsListener?,
|
class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Contact>, val listener: RefreshContactsListener?,
|
||||||
val isFavoritesFragment: Boolean, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
|
val isFavoritesFragment: Boolean, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
|
||||||
@ -119,7 +120,20 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun removeFavorites() {
|
private fun removeFavorites() {
|
||||||
|
if (selectedPositions.isEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val favoritesToRemove = ArrayList<Contact>()
|
||||||
|
selectedPositions.sortedDescending().forEach {
|
||||||
|
favoritesToRemove.add(contactItems[it])
|
||||||
|
}
|
||||||
|
contactItems.removeAll(favoritesToRemove)
|
||||||
|
|
||||||
|
val favoriteIDsToRemove = HashSet<String>()
|
||||||
|
favoritesToRemove.map { favoriteIDsToRemove.add(it.id.toString()) }
|
||||||
|
activity.config.removeFavorites(favoriteIDsToRemove)
|
||||||
|
removeSelectedItems()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addToFavorites() {
|
private fun addToFavorites() {
|
||||||
|
@ -44,4 +44,20 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
var favorites: Set<String>
|
var favorites: Set<String>
|
||||||
get() = prefs.getStringSet(FAVORITES, HashSet<String>())
|
get() = prefs.getStringSet(FAVORITES, HashSet<String>())
|
||||||
set(favorites) = prefs.edit().remove(FAVORITES).putStringSet(FAVORITES, favorites).apply()
|
set(favorites) = prefs.edit().remove(FAVORITES).putStringSet(FAVORITES, favorites).apply()
|
||||||
|
|
||||||
|
fun addFavorite(id: String) {
|
||||||
|
addFavorites(HashSet<String>(Arrays.asList(id)))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addFavorites(favs: Set<String>) {
|
||||||
|
val currFavorites = HashSet<String>(favs)
|
||||||
|
currFavorites.addAll(favs)
|
||||||
|
favorites = currFavorites
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeFavorites(favs: Set<String>) {
|
||||||
|
val currFavorites = HashSet<String>(favorites)
|
||||||
|
currFavorites.removeAll(favs)
|
||||||
|
favorites = currFavorites
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user