mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-04-16 19:07:21 +02:00
reuse the Favorites stored on device, don't create an own list
This commit is contained in:
parent
8e3eee5106
commit
3cd116ada8
@ -298,7 +298,7 @@ class ContactActivity : SimpleActivity() {
|
|||||||
private fun setupNewContact() {
|
private fun setupNewContact() {
|
||||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
|
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
|
||||||
supportActionBar?.title = resources.getString(R.string.new_contact)
|
supportActionBar?.title = resources.getString(R.string.new_contact)
|
||||||
contact = Contact(0, "", "", "", "", ArrayList(), ArrayList(), ArrayList(), "")
|
contact = Contact(0, "", "", "", "", ArrayList(), ArrayList(), ArrayList(), "", 0)
|
||||||
contact_source.text = config.lastUsedContactSource
|
contact_source.text = config.lastUsedContactSource
|
||||||
contact_source.setOnClickListener { showAccountSourcePicker() }
|
contact_source.setOnClickListener { showAccountSourcePicker() }
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class SelectContactActivity : SimpleActivity() {
|
|||||||
contacts.sort()
|
contacts.sort()
|
||||||
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
select_contact_list.adapter = SelectContactsAdapter(this, contacts, HashSet(), false) {
|
select_contact_list.adapter = SelectContactsAdapter(this, contacts, ArrayList(), false) {
|
||||||
confirmSelection(it)
|
confirmSelection(it)
|
||||||
}
|
}
|
||||||
select_contact_fastscroller.allowBubbleDisplay = baseConfig.showInfoBubble
|
select_contact_fastscroller.allowBubbleDisplay = baseConfig.showInfoBubble
|
||||||
|
@ -139,7 +139,6 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
|
|||||||
|
|
||||||
val favoriteIDsToRemove = HashSet<String>()
|
val favoriteIDsToRemove = HashSet<String>()
|
||||||
favoritesToRemove.mapTo(favoriteIDsToRemove, { it.id.toString() })
|
favoritesToRemove.mapTo(favoriteIDsToRemove, { it.id.toString() })
|
||||||
activity.config.removeFavorites(favoriteIDsToRemove)
|
|
||||||
if (contactItems.isEmpty()) {
|
if (contactItems.isEmpty()) {
|
||||||
listener?.refreshFavorites()
|
listener?.refreshFavorites()
|
||||||
finishActMode()
|
finishActMode()
|
||||||
@ -155,8 +154,6 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
|
|||||||
|
|
||||||
val newFavorites = HashSet<String>()
|
val newFavorites = HashSet<String>()
|
||||||
selectedPositions.forEach { newFavorites.add(contactItems[it].id.toString()) }
|
selectedPositions.forEach { newFavorites.add(contactItems[it].id.toString()) }
|
||||||
newFavorites.addAll(activity.config.favorites)
|
|
||||||
activity.config.favorites = newFavorites
|
|
||||||
listener?.refreshFavorites()
|
listener?.refreshFavorites()
|
||||||
finishActMode()
|
finishActMode()
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import com.simplemobiletools.contacts.models.Contact
|
|||||||
import kotlinx.android.synthetic.main.item_add_favorite_with_number.view.*
|
import kotlinx.android.synthetic.main.item_add_favorite_with_number.view.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class SelectContactsAdapter(val activity: SimpleActivity, val contacts: List<Contact>, val selectedContacts: Set<String>, val allowPickMultiple: Boolean,
|
class SelectContactsAdapter(val activity: SimpleActivity, val contacts: List<Contact>, val selectedContacts: ArrayList<String>, val allowPickMultiple: Boolean,
|
||||||
val itemClick: ((Contact) -> Unit)? = null) : RecyclerView.Adapter<SelectContactsAdapter.ViewHolder>() {
|
val itemClick: ((Contact) -> Unit)? = null) : RecyclerView.Adapter<SelectContactsAdapter.ViewHolder>() {
|
||||||
private val itemViews = SparseArray<View>()
|
private val itemViews = SparseArray<View>()
|
||||||
private val selectedPositions = HashSet<Int>()
|
private val selectedPositions = HashSet<Int>()
|
||||||
|
@ -28,12 +28,14 @@ class AddFavoritesDialog(val activity: SimpleActivity, val callback: () -> Unit)
|
|||||||
allContacts = allContacts.filter { contactSources.contains(it.source) } as ArrayList<Contact>
|
allContacts = allContacts.filter { contactSources.contains(it.source) } as ArrayList<Contact>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val favorites = allContacts.filter { it.starred == 1 }.map { it.id.toString() } as ArrayList<String>
|
||||||
|
|
||||||
Contact.sorting = config.sorting
|
Contact.sorting = config.sorting
|
||||||
allContacts.sort()
|
allContacts.sort()
|
||||||
|
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
view.apply {
|
view.apply {
|
||||||
select_contact_list.adapter = SelectContactsAdapter(activity, allContacts, config.favorites, true)
|
select_contact_list.adapter = SelectContactsAdapter(activity, allContacts, favorites, true)
|
||||||
select_contact_fastscroller.allowBubbleDisplay = activity.baseConfig.showInfoBubble
|
select_contact_fastscroller.allowBubbleDisplay = activity.baseConfig.showInfoBubble
|
||||||
select_contact_fastscroller.setViews(select_contact_list) {
|
select_contact_fastscroller.setViews(select_contact_list) {
|
||||||
select_contact_fastscroller.updateBubbleText(allContacts[it].getBubbleText())
|
select_contact_fastscroller.updateBubbleText(allContacts[it].getBubbleText())
|
||||||
@ -54,12 +56,10 @@ class AddFavoritesDialog(val activity: SimpleActivity, val callback: () -> Unit)
|
|||||||
val allDisplayedIDs = ArrayList<String>()
|
val allDisplayedIDs = ArrayList<String>()
|
||||||
allContacts.mapTo(allDisplayedIDs, { it.id.toString() })
|
allContacts.mapTo(allDisplayedIDs, { it.id.toString() })
|
||||||
val selectedItems = (view.select_contact_list.adapter as SelectContactsAdapter).getSelectedItemsSet()
|
val selectedItems = (view.select_contact_list.adapter as SelectContactsAdapter).getSelectedItemsSet()
|
||||||
config.addFavorites(selectedItems)
|
|
||||||
allDisplayedIDs.removeAll(selectedItems)
|
allDisplayedIDs.removeAll(selectedItems)
|
||||||
|
|
||||||
val favoriteIDsToRemove = HashSet<String>()
|
val favoriteIDsToRemove = HashSet<String>()
|
||||||
allDisplayedIDs.mapTo(favoriteIDsToRemove, { it })
|
allDisplayedIDs.mapTo(favoriteIDsToRemove, { it })
|
||||||
config.removeFavorites(favoriteIDsToRemove)
|
|
||||||
callback()
|
callback()
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
}
|
}
|
||||||
|
@ -89,8 +89,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||||||
}
|
}
|
||||||
|
|
||||||
contacts = if (this is FavoritesFragment) {
|
contacts = if (this is FavoritesFragment) {
|
||||||
val favorites = config.favorites
|
contacts.filter { it.starred == 1 } as ArrayList<Contact>
|
||||||
contacts.filter { favorites.contains(it.id.toString()) } as ArrayList<Contact>
|
|
||||||
} else {
|
} else {
|
||||||
val contactSources = config.displayContactSources
|
val contactSources = config.displayContactSources
|
||||||
if (config.showAllContacts()) {
|
if (config.showAllContacts()) {
|
||||||
|
@ -4,7 +4,6 @@ import android.content.Context
|
|||||||
import com.simplemobiletools.commons.helpers.BaseConfig
|
import com.simplemobiletools.commons.helpers.BaseConfig
|
||||||
import com.simplemobiletools.commons.helpers.SORTING
|
import com.simplemobiletools.commons.helpers.SORTING
|
||||||
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class Config(context: Context) : BaseConfig(context) {
|
class Config(context: Context) : BaseConfig(context) {
|
||||||
companion object {
|
companion object {
|
||||||
@ -40,24 +39,4 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
var lastUsedViewPagerPage: Int
|
var lastUsedViewPagerPage: Int
|
||||||
get() = prefs.getInt(LAST_USED_VIEW_PAGER_PAGE, 0)
|
get() = prefs.getInt(LAST_USED_VIEW_PAGER_PAGE, 0)
|
||||||
set(lastUsedViewPagerPage) = prefs.edit().putInt(LAST_USED_VIEW_PAGER_PAGE, lastUsedViewPagerPage).apply()
|
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 START_NAME_WITH_SURNAME = "start_name_with_surname"
|
||||||
val LAST_USED_CONTACT_SOURCE = "last_used_contact_source"
|
val LAST_USED_CONTACT_SOURCE = "last_used_contact_source"
|
||||||
val LAST_USED_VIEW_PAGER_PAGE = "last_used_view_pager_page"
|
val LAST_USED_VIEW_PAGER_PAGE = "last_used_view_pager_page"
|
||||||
val FAVORITES = "favorites"
|
|
||||||
|
|
||||||
val CONTACT_ID = "contact_id"
|
val CONTACT_ID = "contact_id"
|
||||||
|
|
||||||
|
@ -54,7 +54,8 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
val emails = ArrayList<Email>()
|
val emails = ArrayList<Email>()
|
||||||
val events = ArrayList<Event>()
|
val events = ArrayList<Event>()
|
||||||
val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME)
|
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)
|
contacts.put(id, contact)
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
@ -208,7 +209,8 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
val emails = getEmails(id)[id] ?: ArrayList()
|
val emails = getEmails(id)[id] ?: ArrayList()
|
||||||
val events = getEvents(id)[id] ?: ArrayList()
|
val events = getEvents(id)[id] ?: ArrayList()
|
||||||
val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME)
|
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 {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
@ -264,6 +266,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME,
|
ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME,
|
||||||
ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME,
|
ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME,
|
||||||
ContactsContract.CommonDataKinds.StructuredName.PHOTO_URI,
|
ContactsContract.CommonDataKinds.StructuredName.PHOTO_URI,
|
||||||
|
ContactsContract.CommonDataKinds.StructuredName.STARRED,
|
||||||
ContactsContract.RawContacts.ACCOUNT_NAME
|
ContactsContract.RawContacts.ACCOUNT_NAME
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -557,7 +560,6 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
|
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
|
||||||
activity.config.removeFavorites(contactIDs)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
activity.showErrorToast(e)
|
activity.showErrorToast(e)
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,8 @@ import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME
|
|||||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||||
|
|
||||||
data class Contact(val id: Int, var firstName: String, var middleName: String, var surname: String, var photoUri: String,
|
data class Contact(val id: Int, var firstName: String, var middleName: String, var surname: String, var photoUri: String,
|
||||||
var phoneNumbers: ArrayList<PhoneNumber>, var emails: ArrayList<Email>, var events: ArrayList<Event>, var source: String) : Comparable<Contact> {
|
var phoneNumbers: ArrayList<PhoneNumber>, var emails: ArrayList<Email>, var events: ArrayList<Event>, var source: String,
|
||||||
|
var starred: Int) : Comparable<Contact> {
|
||||||
companion object {
|
companion object {
|
||||||
var sorting: Int = 0
|
var sorting: Int = 0
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user