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