mirror of
				https://github.com/SimpleMobileTools/Simple-Dialer.git
				synced 2025-06-05 21:49:23 +02:00 
			
		
		
		
	properly handle limiting Recent items in the call log on Android O+
This commit is contained in:
		| @@ -1,8 +1,12 @@ | ||||
| package com.simplemobiletools.dialer.helpers | ||||
|  | ||||
| import android.annotation.SuppressLint | ||||
| import android.content.ContentResolver | ||||
| import android.content.Context | ||||
| import android.os.Build | ||||
| import android.os.Bundle | ||||
| import android.provider.CallLog.Calls | ||||
| import androidx.annotation.RequiresApi | ||||
| import com.simplemobiletools.commons.extensions.* | ||||
| import com.simplemobiletools.commons.helpers.* | ||||
| 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) { | ||||
|         var recentCalls = ArrayList<RecentCall>() | ||||
|         var previousRecentCallFrom = "" | ||||
| @@ -55,8 +60,21 @@ class RecentsHelper(private val context: Context) { | ||||
|             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" | ||||
|         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 number = cursor.getStringValue(Calls.NUMBER) | ||||
|                 var name = cursor.getStringValue(Calls.CACHED_NAME) | ||||
| @@ -105,6 +123,7 @@ class RecentsHelper(private val context: Context) { | ||||
|                 } | ||||
|  | ||||
|                 previousRecentCallFrom = "$number$name" | ||||
|             } while (cursor.moveToNext()) | ||||
|         } | ||||
|  | ||||
|         val blockedNumbers = context.getBlockedNumbers() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user