speed up SMS loading by caching blocked numbers

This commit is contained in:
tibbi 2020-05-08 22:49:54 +02:00
parent f1edebb2dc
commit ff0cc0b005
1 changed files with 11 additions and 1 deletions

View File

@ -46,10 +46,20 @@ fun Context.getMessages(threadId: Int): ArrayList<Message> {
val selectionArgs = arrayOf(threadId.toString())
val sortOrder = "${Sms._ID} DESC LIMIT 100"
val blockStatus = HashMap<String, Boolean>()
var messages = ArrayList<Message>()
queryCursor(uri, projection, selection, selectionArgs, sortOrder, showErrors = true) { cursor ->
val senderNumber = cursor.getStringValue(Sms.ADDRESS)
if (isNumberBlocked(senderNumber)) {
val isNumberBlocked = if (blockStatus.containsKey(senderNumber)) {
blockStatus[senderNumber] ?: false
} else {
val isBlocked = isNumberBlocked(senderNumber)
blockStatus[senderNumber] = isBlocked
isBlocked
}
if (isNumberBlocked) {
return@queryCursor
}