mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-02-21 22:07:44 +01:00
Use SQL style LIMIT
query before nougat
This commit is contained in:
parent
91225ba802
commit
d6025e5962
@ -1,9 +1,7 @@
|
||||
package com.simplemobiletools.dialer.helpers
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.provider.CallLog.Calls
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
@ -45,10 +43,7 @@ class RecentsHelper(private val context: Context) {
|
||||
val contactsNumbersMap = HashMap<String, String>()
|
||||
val contactPhotosMap = HashMap<String, String>()
|
||||
|
||||
val uri = Calls.CONTENT_URI.buildUpon()
|
||||
.appendQueryParameter(Calls.LIMIT_PARAM_KEY, QUERY_LIMIT)
|
||||
.build()
|
||||
|
||||
val uri = Calls.CONTENT_URI
|
||||
val projection = arrayOf(
|
||||
Calls._ID,
|
||||
Calls.NUMBER,
|
||||
@ -65,15 +60,15 @@ class RecentsHelper(private val context: Context) {
|
||||
accountIdToSimIDMap[it.handle.id] = it.id
|
||||
}
|
||||
|
||||
val cursor = if (isRPlus()) {
|
||||
val bundle = Bundle().apply {
|
||||
putStringArray(ContentResolver.QUERY_ARG_SORT_COLUMNS, arrayOf(Calls._ID))
|
||||
putInt(ContentResolver.QUERY_ARG_SORT_DIRECTION, ContentResolver.QUERY_SORT_DIRECTION_DESCENDING)
|
||||
}
|
||||
|
||||
context.contentResolver.query(uri, projection, bundle, null)
|
||||
} else {
|
||||
val cursor = if (isNougatPlus()) {
|
||||
// https://issuetracker.google.com/issues/175198972?pli=1#comment6
|
||||
val limitedUri = uri.buildUpon()
|
||||
.appendQueryParameter(Calls.LIMIT_PARAM_KEY, QUERY_LIMIT)
|
||||
.build()
|
||||
val sortOrder = "${Calls._ID} DESC"
|
||||
context.contentResolver.query(limitedUri, projection, null, null, sortOrder)
|
||||
} else {
|
||||
val sortOrder = "${Calls._ID} DESC LIMIT $QUERY_LIMIT"
|
||||
context.contentResolver.query(uri, projection, null, null, sortOrder)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user