mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-02-19 04:50:53 +01:00
properly handle limiting Recent items in the call log on Android O+
This commit is contained in:
parent
6973f86399
commit
3d144dfc60
@ -1,8 +1,12 @@
|
|||||||
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.Build
|
||||||
|
import android.os.Bundle
|
||||||
import android.provider.CallLog.Calls
|
import android.provider.CallLog.Calls
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.*
|
import com.simplemobiletools.commons.helpers.*
|
||||||
import com.simplemobiletools.commons.models.SimpleContact
|
import com.simplemobiletools.commons.models.SimpleContact
|
||||||
@ -34,6 +38,7 @@ class RecentsHelper(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
private fun getRecents(contacts: ArrayList<SimpleContact>, groupSubsequentCalls: Boolean, callback: (ArrayList<RecentCall>) -> Unit) {
|
private fun getRecents(contacts: ArrayList<SimpleContact>, groupSubsequentCalls: Boolean, callback: (ArrayList<RecentCall>) -> Unit) {
|
||||||
var recentCalls = ArrayList<RecentCall>()
|
var recentCalls = ArrayList<RecentCall>()
|
||||||
var previousRecentCallFrom = ""
|
var previousRecentCallFrom = ""
|
||||||
@ -55,8 +60,21 @@ class RecentsHelper(private val context: Context) {
|
|||||||
numberToSimIDMap[it.phoneNumber] = it.id
|
numberToSimIDMap[it.phoneNumber] = 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)
|
||||||
|
putInt(ContentResolver.QUERY_ARG_LIMIT, 20)
|
||||||
|
}
|
||||||
|
|
||||||
|
context.contentResolver.query(uri, projection, bundle, null)
|
||||||
|
} else {
|
||||||
val sortOrder = "${Calls._ID} DESC LIMIT 100"
|
val sortOrder = "${Calls._ID} DESC LIMIT 100"
|
||||||
context.queryCursor(uri, projection, sortOrder = sortOrder, showErrors = true) { cursor ->
|
context.contentResolver.query(uri, projection, null, null, sortOrder)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cursor?.moveToFirst() == true) {
|
||||||
|
do {
|
||||||
val id = cursor.getIntValue(Calls._ID)
|
val id = cursor.getIntValue(Calls._ID)
|
||||||
val number = cursor.getStringValue(Calls.NUMBER)
|
val number = cursor.getStringValue(Calls.NUMBER)
|
||||||
var name = cursor.getStringValue(Calls.CACHED_NAME)
|
var name = cursor.getStringValue(Calls.CACHED_NAME)
|
||||||
@ -105,6 +123,7 @@ class RecentsHelper(private val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
previousRecentCallFrom = "$number$name"
|
previousRecentCallFrom = "$number$name"
|
||||||
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
|
|
||||||
val blockedNumbers = context.getBlockedNumbers()
|
val blockedNumbers = context.getBlockedNumbers()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user