mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
reuse the Favorites stored on device, don't create an own list
This commit is contained in:
@ -4,7 +4,6 @@ import android.content.Context
|
||||
import com.simplemobiletools.commons.helpers.BaseConfig
|
||||
import com.simplemobiletools.commons.helpers.SORTING
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
||||
import java.util.*
|
||||
|
||||
class Config(context: Context) : BaseConfig(context) {
|
||||
companion object {
|
||||
@ -40,24 +39,4 @@ class Config(context: Context) : BaseConfig(context) {
|
||||
var lastUsedViewPagerPage: Int
|
||||
get() = prefs.getInt(LAST_USED_VIEW_PAGER_PAGE, 0)
|
||||
set(lastUsedViewPagerPage) = prefs.edit().putInt(LAST_USED_VIEW_PAGER_PAGE, lastUsedViewPagerPage).apply()
|
||||
|
||||
var favorites: Set<String>
|
||||
get() = prefs.getStringSet(FAVORITES, HashSet<String>())
|
||||
set(favorites) = prefs.edit().remove(FAVORITES).putStringSet(FAVORITES, favorites).apply()
|
||||
|
||||
fun addFavorite(id: String) {
|
||||
addFavorites(HashSet<String>(Arrays.asList(id)))
|
||||
}
|
||||
|
||||
fun addFavorites(favs: Set<String>) {
|
||||
val currFavorites = HashSet<String>(favorites)
|
||||
currFavorites.addAll(favs)
|
||||
favorites = currFavorites
|
||||
}
|
||||
|
||||
fun removeFavorites(favs: Set<String>) {
|
||||
val currFavorites = HashSet<String>(favorites)
|
||||
currFavorites.removeAll(favs)
|
||||
favorites = currFavorites
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ val DISPLAY_CONTACT_SOURCES = "display_contact_sources"
|
||||
val START_NAME_WITH_SURNAME = "start_name_with_surname"
|
||||
val LAST_USED_CONTACT_SOURCE = "last_used_contact_source"
|
||||
val LAST_USED_VIEW_PAGER_PAGE = "last_used_view_pager_page"
|
||||
val FAVORITES = "favorites"
|
||||
|
||||
val CONTACT_ID = "contact_id"
|
||||
|
||||
|
@ -54,7 +54,8 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||
val emails = ArrayList<Email>()
|
||||
val events = ArrayList<Event>()
|
||||
val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME)
|
||||
val contact = Contact(id, firstName, middleName, surname, photoUri, number, emails, events, accountName)
|
||||
val starred = cursor.getIntValue(ContactsContract.CommonDataKinds.StructuredName.STARRED)
|
||||
val contact = Contact(id, firstName, middleName, surname, photoUri, number, emails, events, accountName, starred)
|
||||
contacts.put(id, contact)
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
@ -208,7 +209,8 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||
val emails = getEmails(id)[id] ?: ArrayList()
|
||||
val events = getEvents(id)[id] ?: ArrayList()
|
||||
val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME)
|
||||
return Contact(id, firstName, middleName, surname, photoUri, number, emails, events, accountName)
|
||||
val starred = cursor.getIntValue(ContactsContract.CommonDataKinds.StructuredName.STARRED)
|
||||
return Contact(id, firstName, middleName, surname, photoUri, number, emails, events, accountName, starred)
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
@ -264,6 +266,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||
ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME,
|
||||
ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME,
|
||||
ContactsContract.CommonDataKinds.StructuredName.PHOTO_URI,
|
||||
ContactsContract.CommonDataKinds.StructuredName.STARRED,
|
||||
ContactsContract.RawContacts.ACCOUNT_NAME
|
||||
)
|
||||
|
||||
@ -557,7 +560,6 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||
}
|
||||
|
||||
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
|
||||
activity.config.removeFavorites(contactIDs)
|
||||
} catch (e: Exception) {
|
||||
activity.showErrorToast(e)
|
||||
}
|
||||
|
Reference in New Issue
Block a user