mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
allow deleting items from Recents
This commit is contained in:
@ -4,8 +4,9 @@ import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.provider.CallLog.Calls
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALL_LOG
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALL_LOG
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.overloads.times
|
||||
import com.simplemobiletools.dialer.models.RecentCall
|
||||
|
||||
class RecentsHelper(private val context: Context) {
|
||||
@ -13,7 +14,7 @@ class RecentsHelper(private val context: Context) {
|
||||
fun getRecentCalls(callback: (ArrayList<RecentCall>) -> Unit) {
|
||||
ensureBackgroundThread {
|
||||
val recentCalls = ArrayList<RecentCall>()
|
||||
if (!context.hasPermission(PERMISSION_READ_CALL_LOG)) {
|
||||
if (!context.hasPermission(PERMISSION_WRITE_CALL_LOG)) {
|
||||
callback(recentCalls)
|
||||
return@ensureBackgroundThread
|
||||
}
|
||||
@ -52,4 +53,19 @@ class RecentsHelper(private val context: Context) {
|
||||
callback(recentCalls)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun removeRecentCalls(ids: ArrayList<Int>, callback: () -> Unit) {
|
||||
ensureBackgroundThread {
|
||||
val uri = Calls.CONTENT_URI
|
||||
ids.chunked(30).forEach { chunk ->
|
||||
val selection = "${Calls._ID} IN (${getQuestionMarks(chunk.size)})"
|
||||
val selectionArgs = chunk.map { it.toString() }.toTypedArray()
|
||||
context.contentResolver.delete(uri, selection, selectionArgs)
|
||||
}
|
||||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getQuestionMarks(size: Int) = ("?," * size).trimEnd(',')
|
||||
}
|
||||
|
Reference in New Issue
Block a user