mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-03-12 01:00:11 +01:00
make ContactsAdapter more dynamic, use it at Group Contacts
This commit is contained in:
parent
f4767421a8
commit
3c413347d6
@ -30,7 +30,10 @@ class GroupContactsActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
private fun updateContacts(contacts: ArrayList<Contact>) {
|
||||
ContactsAdapter(this, contacts, null, false, group_contacts_list, group_contacts_fastscroller) {
|
||||
Contact.sorting = config.sorting
|
||||
contacts.sort()
|
||||
|
||||
ContactsAdapter(this, contacts, null, LOCATION_GROUP_CONTACTS, group_contacts_list, group_contacts_fastscroller) {
|
||||
when (config.onContactClick) {
|
||||
ON_CLICK_CALL_CONTACT -> {
|
||||
val contact = it as Contact
|
||||
|
@ -22,13 +22,16 @@ import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.extensions.editContact
|
||||
import com.simplemobiletools.contacts.extensions.shareContacts
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.helpers.LOCATION_CONTACTS_TAB
|
||||
import com.simplemobiletools.contacts.helpers.LOCATION_FAVORITES_TAB
|
||||
import com.simplemobiletools.contacts.helpers.LOCATION_GROUP_CONTACTS
|
||||
import com.simplemobiletools.contacts.interfaces.RefreshContactsListener
|
||||
import com.simplemobiletools.contacts.models.Contact
|
||||
import kotlinx.android.synthetic.main.item_contact_with_number.view.*
|
||||
import java.util.*
|
||||
|
||||
class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Contact>, private val listener: RefreshContactsListener?,
|
||||
private val isFavoritesFragment: Boolean, recyclerView: MyRecyclerView, fastScroller: FastScroller, itemClick: (Any) -> Unit) :
|
||||
private val location: Int, recyclerView: MyRecyclerView, fastScroller: FastScroller, itemClick: (Any) -> Unit) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
|
||||
private lateinit var contactDrawable: Drawable
|
||||
@ -52,10 +55,13 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
|
||||
override fun prepareActionMode(menu: Menu) {
|
||||
menu.apply {
|
||||
findItem(R.id.cab_edit).isVisible = isOneItemSelected()
|
||||
findItem(R.id.cab_remove).isVisible = isFavoritesFragment
|
||||
findItem(R.id.cab_select_all).isVisible = isFavoritesFragment
|
||||
findItem(R.id.cab_add_to_favorites).isVisible = !isFavoritesFragment
|
||||
findItem(R.id.cab_delete).isVisible = !isFavoritesFragment
|
||||
findItem(R.id.cab_remove).isVisible = location == LOCATION_FAVORITES_TAB || location == LOCATION_GROUP_CONTACTS
|
||||
findItem(R.id.cab_add_to_favorites).isVisible = location == LOCATION_CONTACTS_TAB
|
||||
findItem(R.id.cab_delete).isVisible = location == LOCATION_CONTACTS_TAB || location == LOCATION_GROUP_CONTACTS
|
||||
|
||||
if (location == LOCATION_GROUP_CONTACTS) {
|
||||
findItem(R.id.cab_remove).title = activity.getString(R.string.remove_from_group)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,7 +81,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
|
||||
R.id.cab_select_all -> selectAll()
|
||||
R.id.cab_add_to_favorites -> addToFavorites()
|
||||
R.id.cab_share -> shareContacts()
|
||||
R.id.cab_remove -> removeFavorites()
|
||||
R.id.cab_remove -> removeContacts()
|
||||
R.id.cab_delete -> askConfirmDelete()
|
||||
}
|
||||
}
|
||||
@ -138,19 +144,23 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeFavorites() {
|
||||
val favoritesToRemove = ArrayList<Contact>()
|
||||
private fun removeContacts() {
|
||||
val contactsToRemove = ArrayList<Contact>()
|
||||
selectedPositions.sortedDescending().forEach {
|
||||
favoritesToRemove.add(contactItems[it])
|
||||
contactsToRemove.add(contactItems[it])
|
||||
}
|
||||
contactItems.removeAll(favoritesToRemove)
|
||||
contactItems.removeAll(contactsToRemove)
|
||||
|
||||
if (location == LOCATION_FAVORITES_TAB) {
|
||||
ContactsHelper(activity).removeFavorites(contactsToRemove)
|
||||
if (contactItems.isEmpty()) {
|
||||
listener?.refreshFavorites()
|
||||
finishActMode()
|
||||
} else {
|
||||
removeSelectedItems()
|
||||
}
|
||||
} else if (location == LOCATION_GROUP_CONTACTS) {
|
||||
|
||||
ContactsHelper(activity).removeFavorites(favoritesToRemove)
|
||||
if (contactItems.isEmpty()) {
|
||||
listener?.refreshFavorites()
|
||||
finishActMode()
|
||||
} else {
|
||||
removeSelectedItems()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,7 @@ import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.extensions.editContact
|
||||
import com.simplemobiletools.contacts.extensions.tryStartCall
|
||||
import com.simplemobiletools.contacts.extensions.viewContact
|
||||
import com.simplemobiletools.contacts.helpers.Config
|
||||
import com.simplemobiletools.contacts.helpers.ON_CLICK_CALL_CONTACT
|
||||
import com.simplemobiletools.contacts.helpers.ON_CLICK_EDIT_CONTACT
|
||||
import com.simplemobiletools.contacts.helpers.ON_CLICK_VIEW_CONTACT
|
||||
import com.simplemobiletools.contacts.helpers.*
|
||||
import com.simplemobiletools.contacts.interfaces.FragmentInterface
|
||||
import com.simplemobiletools.contacts.models.Contact
|
||||
import kotlinx.android.synthetic.main.fragment_layout.view.*
|
||||
@ -108,7 +105,8 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||
val currAdapter = fragment_list.adapter
|
||||
if (currAdapter == null || forceListRedraw) {
|
||||
forceListRedraw = false
|
||||
ContactsAdapter(activity as SimpleActivity, contacts, activity, this is FavoritesFragment, fragment_list, fragment_fastscroller) {
|
||||
val location = if (this is FavoritesFragment) LOCATION_FAVORITES_TAB else LOCATION_CONTACTS_TAB
|
||||
ContactsAdapter(activity as SimpleActivity, contacts, activity, location, fragment_list, fragment_fastscroller) {
|
||||
when (config.onContactClick) {
|
||||
ON_CLICK_CALL_CONTACT -> {
|
||||
val contact = it as Contact
|
||||
|
@ -15,6 +15,10 @@ const val SMT_PRIVATE = "smt_private" // used at the contact source of local c
|
||||
const val IS_PRIVATE = "is_private"
|
||||
const val GROUP = "group"
|
||||
|
||||
const val LOCATION_CONTACTS_TAB = 1
|
||||
const val LOCATION_FAVORITES_TAB = 2
|
||||
const val LOCATION_GROUP_CONTACTS = 3
|
||||
|
||||
// contact photo changes
|
||||
const val PHOTO_ADDED = 1
|
||||
const val PHOTO_REMOVED = 2
|
||||
|
@ -6,8 +6,6 @@
|
||||
<string name="updating">Aktualisiere…</string>
|
||||
<string name="phone_storage">Gerätespeicher</string>
|
||||
<string name="phone_storage_hidden">Gerätespeicher (nicht sichtbar für andere Apps)</string>
|
||||
<string name="no_groups">No groups</string>
|
||||
<string name="create_new_group">Create a new group</string>
|
||||
|
||||
<string name="new_contact">Neuer Kontakt</string>
|
||||
<string name="edit_contact">Kontakt bearbeiten</string>
|
||||
@ -17,6 +15,11 @@
|
||||
<string name="middle_name">Zweiter Vorname</string>
|
||||
<string name="surname">Familienname</string>
|
||||
|
||||
<!-- Groups -->
|
||||
<string name="no_groups">No groups</string>
|
||||
<string name="create_new_group">Create a new group</string>
|
||||
<string name="remove_from_group">Remove from group</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">Foto machen</string>
|
||||
<string name="choose_photo">Foto auswählen</string>
|
||||
|
@ -6,8 +6,6 @@
|
||||
<string name="updating">Mise à jour…</string>
|
||||
<string name="phone_storage">Stockage du téléphone</string>
|
||||
<string name="phone_storage_hidden">Stockage du téléphone (non visible par d\'autres applis)</string>
|
||||
<string name="no_groups">No groups</string>
|
||||
<string name="create_new_group">Create a new group</string>
|
||||
|
||||
<string name="new_contact">Nouveau contact</string>
|
||||
<string name="edit_contact">Modifier contact</string>
|
||||
@ -17,6 +15,11 @@
|
||||
<string name="middle_name">Nom</string>
|
||||
<string name="surname">Surnom</string>
|
||||
|
||||
<!-- Groups -->
|
||||
<string name="no_groups">No groups</string>
|
||||
<string name="create_new_group">Create a new group</string>
|
||||
<string name="remove_from_group">Remove from group</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">Prendre une photo</string>
|
||||
<string name="choose_photo">Choisir une photo</string>
|
||||
|
@ -6,8 +6,6 @@
|
||||
<string name="updating">수정중…</string>
|
||||
<string name="phone_storage">Phone storage</string>
|
||||
<string name="phone_storage_hidden">Phone storage (not visible by other apps)</string>
|
||||
<string name="no_groups">No groups</string>
|
||||
<string name="create_new_group">Create a new group</string>
|
||||
|
||||
<string name="new_contact">새로운 연락처</string>
|
||||
<string name="edit_contact">연락처 수정</string>
|
||||
@ -17,6 +15,11 @@
|
||||
<string name="middle_name">중간 이름</string>
|
||||
<string name="surname">성</string>
|
||||
|
||||
<!-- Groups -->
|
||||
<string name="no_groups">No groups</string>
|
||||
<string name="create_new_group">Create a new group</string>
|
||||
<string name="remove_from_group">Remove from group</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">사진 촬영</string>
|
||||
<string name="choose_photo">사진 선택</string>
|
||||
|
@ -6,8 +6,6 @@
|
||||
<string name="updating">Atnaujinama…</string>
|
||||
<string name="phone_storage">Telefono atmintis</string>
|
||||
<string name="phone_storage_hidden">Telefono atmintis (nematoma kitų programėlių)</string>
|
||||
<string name="no_groups">Nėra grupių</string>
|
||||
<string name="create_new_group">Sukurti naują grupę</string>
|
||||
|
||||
<string name="new_contact">Naujas kontaktas</string>
|
||||
<string name="edit_contact">Redaguoti kontaktą</string>
|
||||
@ -17,6 +15,11 @@
|
||||
<string name="middle_name">Antras vardas</string>
|
||||
<string name="surname">Pavardė</string>
|
||||
|
||||
<!-- Groups -->
|
||||
<string name="no_groups">Nėra grupių</string>
|
||||
<string name="create_new_group">Sukurti naują grupę</string>
|
||||
<string name="remove_from_group">Remove from group</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">Nufotografuoti</string>
|
||||
<string name="choose_photo">Pasirinkti nuotrauką</string>
|
||||
|
@ -6,8 +6,6 @@
|
||||
<string name="updating">A atualizar…</string>
|
||||
<string name="phone_storage">Armazenamento do telefone</string>
|
||||
<string name="phone_storage_hidden">Armazenamento do telefone (não visível por outras alicações)</string>
|
||||
<string name="no_groups">No groups</string>
|
||||
<string name="create_new_group">Create a new group</string>
|
||||
|
||||
<string name="new_contact">Novo contacto</string>
|
||||
<string name="edit_contact">Editar contacto</string>
|
||||
@ -17,6 +15,11 @@
|
||||
<string name="middle_name">Segundo nome</string>
|
||||
<string name="surname">Apelido</string>
|
||||
|
||||
<!-- Groups -->
|
||||
<string name="no_groups">No groups</string>
|
||||
<string name="create_new_group">Create a new group</string>
|
||||
<string name="remove_from_group">Remove from group</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">Tirar foto</string>
|
||||
<string name="choose_photo">Escolher foto</string>
|
||||
|
@ -6,8 +6,6 @@
|
||||
<string name="updating">Обновление…</string>
|
||||
<string name="phone_storage">Память устройства</string>
|
||||
<string name="phone_storage_hidden">Память устройства (не видна другим приложениям)</string>
|
||||
<string name="no_groups">Нет групп</string>
|
||||
<string name="create_new_group">Создать новую группу</string>
|
||||
|
||||
<string name="new_contact">Новый контакт</string>
|
||||
<string name="edit_contact">Редактировать контакт</string>
|
||||
@ -17,6 +15,11 @@
|
||||
<string name="middle_name">Отчество</string>
|
||||
<string name="surname">Фамилия</string>
|
||||
|
||||
<!-- Groups -->
|
||||
<string name="no_groups">Нет групп</string>
|
||||
<string name="create_new_group">Создать новую группу</string>
|
||||
<string name="remove_from_group">Remove from group</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">Снять фото</string>
|
||||
<string name="choose_photo">Выбрать фото</string>
|
||||
|
@ -6,8 +6,6 @@
|
||||
<string name="updating">Upravuje sa…</string>
|
||||
<string name="phone_storage">Úložisko mobilu</string>
|
||||
<string name="phone_storage_hidden">Úložisko mobilu (neviditeľné pre ostatné apky)</string>
|
||||
<string name="no_groups">Žiadne skupiny</string>
|
||||
<string name="create_new_group">Vytvoriť novú skupinu</string>
|
||||
|
||||
<string name="new_contact">Nový kontakt</string>
|
||||
<string name="edit_contact">Upraviť kontakt</string>
|
||||
@ -17,6 +15,11 @@
|
||||
<string name="middle_name">Stredné meno</string>
|
||||
<string name="surname">Priezvisko</string>
|
||||
|
||||
<!-- Groups -->
|
||||
<string name="no_groups">Žiadne skupiny</string>
|
||||
<string name="create_new_group">Vytvoriť novú skupinu</string>
|
||||
<string name="remove_from_group">Odstrániť zo skupiny</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">Vytvoriť foto</string>
|
||||
<string name="choose_photo">Zvoliť foto</string>
|
||||
|
@ -6,8 +6,6 @@
|
||||
<string name="updating">Uppdaterar…</string>
|
||||
<string name="phone_storage">Telefonens lagringsutrymme</string>
|
||||
<string name="phone_storage_hidden">Telefonens lagringsutrymme (inte synligt för andra appar)</string>
|
||||
<string name="no_groups">No groups</string>
|
||||
<string name="create_new_group">Create a new group</string>
|
||||
|
||||
<string name="new_contact">Ny kontakt</string>
|
||||
<string name="edit_contact">Redigera kontakt</string>
|
||||
@ -17,6 +15,11 @@
|
||||
<string name="middle_name">Mellannamn</string>
|
||||
<string name="surname">Efternamn</string>
|
||||
|
||||
<!-- Groups -->
|
||||
<string name="no_groups">No groups</string>
|
||||
<string name="create_new_group">Create a new group</string>
|
||||
<string name="remove_from_group">Remove from group</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">Ta foto</string>
|
||||
<string name="choose_photo">Välj foto</string>
|
||||
|
@ -6,8 +6,6 @@
|
||||
<string name="updating">更新中…</string>
|
||||
<string name="phone_storage">手機空間</string>
|
||||
<string name="phone_storage_hidden">手機空間 (其他程式不可見)</string>
|
||||
<string name="no_groups">沒有群組</string>
|
||||
<string name="create_new_group">Create a new group</string>
|
||||
|
||||
<string name="new_contact">新聯絡人</string>
|
||||
<string name="edit_contact">編輯聯絡人</string>
|
||||
@ -17,6 +15,11 @@
|
||||
<string name="middle_name">中間名</string>
|
||||
<string name="surname">姓氏</string>
|
||||
|
||||
<!-- Groups -->
|
||||
<string name="no_groups">沒有群組</string>
|
||||
<string name="create_new_group">Create a new group</string>
|
||||
<string name="remove_from_group">Remove from group</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">拍照</string>
|
||||
<string name="choose_photo">選擇相片</string>
|
||||
|
@ -6,8 +6,6 @@
|
||||
<string name="updating">Updating…</string>
|
||||
<string name="phone_storage">Phone storage</string>
|
||||
<string name="phone_storage_hidden">Phone storage (not visible by other apps)</string>
|
||||
<string name="no_groups">No groups</string>
|
||||
<string name="create_new_group">Create a new group</string>
|
||||
|
||||
<string name="new_contact">New contact</string>
|
||||
<string name="edit_contact">Edit contact</string>
|
||||
@ -17,6 +15,11 @@
|
||||
<string name="middle_name">Middle name</string>
|
||||
<string name="surname">Surname</string>
|
||||
|
||||
<!-- Groups -->
|
||||
<string name="no_groups">No groups</string>
|
||||
<string name="create_new_group">Create a new group</string>
|
||||
<string name="remove_from_group">Remove from group</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">Take photo</string>
|
||||
<string name="choose_photo">Choose photo</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user