From 618a88a09c0f9d8fec643e2dfe2e3aca231a74f5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 25 Jul 2021 15:35:23 +0200 Subject: [PATCH] fix #184, avoid showing duplicate call log entries --- .../simplemobiletools/dialer/helpers/RecentsHelper.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/RecentsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/RecentsHelper.kt index 54e9a52e..be535d21 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/RecentsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/RecentsHelper.kt @@ -38,10 +38,11 @@ class RecentsHelper(private val context: Context) { } } - @RequiresApi(Build.VERSION_CODES.O) + @SuppressLint("NewApi") private fun getRecents(contacts: ArrayList, groupSubsequentCalls: Boolean, callback: (ArrayList) -> Unit) { var recentCalls = ArrayList() var previousRecentCallFrom = "" + var previousStartTS = 0 val contactsNumbersMap = HashMap() val uri = Calls.CONTENT_URI val projection = arrayOf( @@ -64,7 +65,7 @@ class RecentsHelper(private val context: Context) { 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) + putInt(ContentResolver.QUERY_ARG_LIMIT, 100) } context.contentResolver.query(uri, projection, bundle, null) @@ -108,6 +109,12 @@ class RecentsHelper(private val context: Context) { val photoUri = cursor.getStringValue(Calls.CACHED_PHOTO_URI) ?: "" val startTS = (cursor.getLongValue(Calls.DATE) / 1000L).toInt() + if (previousStartTS == startTS) { + continue + } else { + previousStartTS = startTS + } + val duration = cursor.getIntValue(Calls.DURATION) val type = cursor.getIntValue(Calls.TYPE) val accountAddress = cursor.getStringValue("phone_account_address")