mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-03 09:17:34 +01:00
implement Recent Call removing
This commit is contained in:
parent
4743fcd730
commit
46580c3620
@ -91,11 +91,11 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val
|
||||
|
||||
private fun askConfirmDelete() {
|
||||
ConfirmationDialog(activity) {
|
||||
deleteContacts()
|
||||
deleteGroups()
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteContacts() {
|
||||
private fun deleteGroups() {
|
||||
if (selectedPositions.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
@ -4,18 +4,22 @@ import android.view.Menu
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.views.FastScroller
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.contacts.R
|
||||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.helpers.RECENTS_TAB_MASK
|
||||
import com.simplemobiletools.contacts.interfaces.RefreshContactsListener
|
||||
import com.simplemobiletools.contacts.models.RecentCall
|
||||
import kotlinx.android.synthetic.main.item_recent_call.view.*
|
||||
import java.util.*
|
||||
|
||||
class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<RecentCall>, recyclerView: MyRecyclerView, fastScroller: FastScroller,
|
||||
itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<RecentCall>, val refreshListener: RefreshContactsListener?, recyclerView: MyRecyclerView,
|
||||
fastScroller: FastScroller, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
private val showPhoneNumbers = activity.config.showPhoneNumbers
|
||||
|
||||
init {
|
||||
@ -39,6 +43,7 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
|
||||
|
||||
when (id) {
|
||||
R.id.cab_select_all -> selectAll()
|
||||
R.id.cab_delete -> askConfirmDelete()
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,6 +70,33 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
|
||||
fastScroller?.measureRecyclerView()
|
||||
}
|
||||
|
||||
private fun askConfirmDelete() {
|
||||
ConfirmationDialog(activity) {
|
||||
deleteRecentCalls()
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteRecentCalls() {
|
||||
if (selectedPositions.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
val callsToRemove = ArrayList<RecentCall>()
|
||||
selectedPositions.sortedDescending().forEach {
|
||||
val call = recentCalls[it]
|
||||
callsToRemove.add(call)
|
||||
}
|
||||
ContactsHelper(activity).removeRecentCalls(callsToRemove.map { it.id } as ArrayList<Int>)
|
||||
recentCalls.removeAll(callsToRemove)
|
||||
|
||||
if (recentCalls.isEmpty()) {
|
||||
refreshListener?.refreshContacts(RECENTS_TAB_MASK)
|
||||
finishActMode()
|
||||
} else {
|
||||
removeSelectedItems()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupView(view: View, recentCall: RecentCall) {
|
||||
view.apply {
|
||||
recent_call_name.apply {
|
||||
|
@ -23,7 +23,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
||||
|
||||
val currAdapter = fragment_list.adapter
|
||||
if (currAdapter == null) {
|
||||
RecentCallsAdapter(activity!!, recentCalls, fragment_list, fragment_fastscroller) {
|
||||
RecentCallsAdapter(activity!!, recentCalls, activity, fragment_list, fragment_fastscroller) {
|
||||
|
||||
}.apply {
|
||||
addVerticalDividers(true)
|
||||
|
@ -1323,7 +1323,7 @@ class ContactsHelper(val activity: Activity) {
|
||||
return@Thread
|
||||
}
|
||||
|
||||
val uri = android.provider.CallLog.Calls.CONTENT_URI
|
||||
val uri = CallLog.Calls.CONTENT_URI
|
||||
val projection = arrayOf(
|
||||
CallLog.Calls._ID,
|
||||
CallLog.Calls.NUMBER,
|
||||
@ -1371,4 +1371,29 @@ class ContactsHelper(val activity: Activity) {
|
||||
callback(calls)
|
||||
}.start()
|
||||
}
|
||||
|
||||
fun removeRecentCalls(ids: ArrayList<Int>) {
|
||||
Thread {
|
||||
try {
|
||||
val operations = ArrayList<ContentProviderOperation>()
|
||||
val selection = "${CallLog.Calls._ID} = ?"
|
||||
ids.forEach {
|
||||
ContentProviderOperation.newDelete(CallLog.Calls.CONTENT_URI).apply {
|
||||
val selectionArgs = arrayOf(it.toString())
|
||||
withSelection(selection, selectionArgs)
|
||||
operations.add(build())
|
||||
}
|
||||
|
||||
if (operations.size % BATCH_SIZE == 0) {
|
||||
activity.contentResolver.applyBatch(CallLog.AUTHORITY, operations)
|
||||
operations.clear()
|
||||
}
|
||||
}
|
||||
|
||||
activity.contentResolver.applyBatch(CallLog.AUTHORITY, operations)
|
||||
} catch (e: Exception) {
|
||||
activity.showErrorToast(e)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user