mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-02 03:59:16 +02:00
use the Commons helper function for getting selected item positions
This commit is contained in:
parent
bdac3fba05
commit
073e759cac
@ -41,7 +41,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:5.0.21'
|
implementation 'com.simplemobiletools:commons:5.0.22'
|
||||||
implementation 'joda-time:joda-time:2.9.9'
|
implementation 'joda-time:joda-time:2.9.9'
|
||||||
implementation 'com.facebook.stetho:stetho:1.5.0'
|
implementation 'com.facebook.stetho:stetho:1.5.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
|
||||||
|
@ -153,7 +153,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
val contactsToRemove = getSelectedItems()
|
val contactsToRemove = getSelectedItems()
|
||||||
val positions = getSelectedItemPositions(contactsToRemove)
|
val positions = getSelectedItemPositions(contactsToRemove.map { it.id })
|
||||||
contactItems.removeAll(contactsToRemove)
|
contactItems.removeAll(contactsToRemove)
|
||||||
|
|
||||||
ContactsHelper(activity).deleteContacts(contactsToRemove)
|
ContactsHelper(activity).deleteContacts(contactsToRemove)
|
||||||
@ -169,7 +169,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
|
|||||||
// used for removing contacts from groups or favorites, not deleting actual contacts
|
// used for removing contacts from groups or favorites, not deleting actual contacts
|
||||||
private fun removeContacts() {
|
private fun removeContacts() {
|
||||||
val contactsToRemove = getSelectedItems()
|
val contactsToRemove = getSelectedItems()
|
||||||
val positions = getSelectedItemPositions(contactsToRemove)
|
val positions = getSelectedItemPositions(contactsToRemove.map { it.id })
|
||||||
contactItems.removeAll(contactsToRemove)
|
contactItems.removeAll(contactsToRemove)
|
||||||
|
|
||||||
if (location == LOCATION_FAVORITES_TAB) {
|
if (location == LOCATION_FAVORITES_TAB) {
|
||||||
@ -234,19 +234,6 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
|
|||||||
|
|
||||||
private fun getSelectedItems() = contactItems.filter { selectedKeys.contains(it.id) } as ArrayList<Contact>
|
private fun getSelectedItems() = contactItems.filter { selectedKeys.contains(it.id) } as ArrayList<Contact>
|
||||||
|
|
||||||
private fun getSelectedItemPositions(contacts: ArrayList<Contact>): ArrayList<Int> {
|
|
||||||
val positions = ArrayList<Int>()
|
|
||||||
contacts.forEach {
|
|
||||||
val position = getItemKeyPosition(it.id)
|
|
||||||
if (position != -1) {
|
|
||||||
positions.add(position)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
positions.sortDescending()
|
|
||||||
return positions
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewRecycled(holder: ViewHolder) {
|
override fun onViewRecycled(holder: ViewHolder) {
|
||||||
super.onViewRecycled(holder)
|
super.onViewRecycled(holder)
|
||||||
if (!activity.isDestroyed) {
|
if (!activity.isDestroyed) {
|
||||||
|
@ -102,7 +102,7 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val
|
|||||||
}
|
}
|
||||||
|
|
||||||
val groupsToRemove = groups.filter { selectedKeys.contains(it.id.toInt()) } as ArrayList<Group>
|
val groupsToRemove = groups.filter { selectedKeys.contains(it.id.toInt()) } as ArrayList<Group>
|
||||||
val positions = getSelectedItemPositions(groupsToRemove)
|
val positions = getSelectedItemPositions(groupsToRemove.map { it.id.toInt() })
|
||||||
groupsToRemove.forEach {
|
groupsToRemove.forEach {
|
||||||
if (it.isPrivateSecretGroup()) {
|
if (it.isPrivateSecretGroup()) {
|
||||||
activity.dbHelper.deleteGroup(it.id)
|
activity.dbHelper.deleteGroup(it.id)
|
||||||
@ -120,19 +120,6 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSelectedItemPositions(groups: ArrayList<Group>): ArrayList<Int> {
|
|
||||||
val positions = ArrayList<Int>()
|
|
||||||
groups.forEach {
|
|
||||||
val position = getItemKeyPosition(it.id.toInt())
|
|
||||||
if (position != -1) {
|
|
||||||
positions.add(position)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
positions.sortDescending()
|
|
||||||
return positions
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setupView(view: View, group: Group) {
|
private fun setupView(view: View, group: Group) {
|
||||||
view.apply {
|
view.apply {
|
||||||
group_frame?.isSelected = isKeySelected(group.id.toInt())
|
group_frame?.isSelected = isKeySelected(group.id.toInt())
|
||||||
|
@ -80,7 +80,7 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
val callsToRemove = getSelectedItems()
|
val callsToRemove = getSelectedItems()
|
||||||
val positions = getSelectedItemPositions(callsToRemove)
|
val positions = getSelectedItemPositions(callsToRemove.map { it.id })
|
||||||
ContactsHelper(activity).removeRecentCalls(callsToRemove.map { it.id } as ArrayList<Int>)
|
ContactsHelper(activity).removeRecentCalls(callsToRemove.map { it.id } as ArrayList<Int>)
|
||||||
recentCalls.removeAll(callsToRemove)
|
recentCalls.removeAll(callsToRemove)
|
||||||
|
|
||||||
@ -94,19 +94,6 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
|
|||||||
|
|
||||||
private fun getSelectedItems() = recentCalls.filter { selectedKeys.contains(it.id) } as ArrayList<RecentCall>
|
private fun getSelectedItems() = recentCalls.filter { selectedKeys.contains(it.id) } as ArrayList<RecentCall>
|
||||||
|
|
||||||
private fun getSelectedItemPositions(callsToRemove: ArrayList<RecentCall>): ArrayList<Int> {
|
|
||||||
val positions = ArrayList<Int>()
|
|
||||||
callsToRemove.forEach {
|
|
||||||
val position = getItemKeyPosition(it.id)
|
|
||||||
if (position != -1) {
|
|
||||||
positions.add(position)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
positions.sortDescending()
|
|
||||||
return positions
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setupView(view: View, recentCall: RecentCall) {
|
private fun setupView(view: View, recentCall: RecentCall) {
|
||||||
view.apply {
|
view.apply {
|
||||||
recent_call_frame?.isSelected = selectedKeys.contains(recentCall.id)
|
recent_call_frame?.isSelected = selectedKeys.contains(recentCall.id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user