mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-02-22 22:37:51 +01:00
Merge pull request #379 from Naveen3Singh/limit_recents
Limit recent call logs to 100
This commit is contained in:
commit
191764b9b7
@ -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.*
|
||||||
@ -15,6 +13,7 @@ import com.simplemobiletools.dialer.models.RecentCall
|
|||||||
|
|
||||||
class RecentsHelper(private val context: Context) {
|
class RecentsHelper(private val context: Context) {
|
||||||
private val COMPARABLE_PHONE_NUMBER_LENGTH = 9
|
private val COMPARABLE_PHONE_NUMBER_LENGTH = 9
|
||||||
|
private val QUERY_LIMIT = "200"
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
fun getRecentCalls(groupSubsequentCalls: Boolean, callback: (ArrayList<RecentCall>) -> Unit) {
|
fun getRecentCalls(groupSubsequentCalls: Boolean, callback: (ArrayList<RecentCall>) -> Unit) {
|
||||||
@ -61,16 +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)
|
||||||
putInt(ContentResolver.QUERY_ARG_LIMIT, 100)
|
.build()
|
||||||
}
|
val sortOrder = "${Calls._ID} DESC"
|
||||||
|
context.contentResolver.query(limitedUri, projection, null, null, sortOrder)
|
||||||
context.contentResolver.query(uri, projection, bundle, null)
|
|
||||||
} else {
|
} else {
|
||||||
val sortOrder = "${Calls._ID} DESC LIMIT 100"
|
val sortOrder = "${Calls._ID} DESC LIMIT $QUERY_LIMIT"
|
||||||
context.contentResolver.query(uri, projection, null, null, sortOrder)
|
context.contentResolver.query(uri, projection, null, null, sortOrder)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,6 +164,7 @@ class RecentsHelper(private val context: Context) {
|
|||||||
previousRecentCallFrom = "$number$name$simID"
|
previousRecentCallFrom = "$number$name$simID"
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
|
cursor?.close()
|
||||||
|
|
||||||
val blockedNumbers = context.getBlockedNumbers()
|
val blockedNumbers = context.getBlockedNumbers()
|
||||||
recentCalls = recentCalls.filter { !context.isNumberBlocked(it.phoneNumber, blockedNumbers) }.toMutableList() as ArrayList<RecentCall>
|
recentCalls = recentCalls.filter { !context.isNumberBlocked(it.phoneNumber, blockedNumbers) }.toMutableList() as ArrayList<RecentCall>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user