This commit is contained in:
Mahendra Liya
2023-06-01 11:25:04 -07:00
committed by GitHub
3 changed files with 20 additions and 7 deletions

View File

@@ -8,10 +8,12 @@ import com.simplemobiletools.commons.helpers.ContactsHelper
import com.simplemobiletools.commons.helpers.MyContactsContentProvider
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALL_LOG
import com.simplemobiletools.commons.helpers.SMT_PRIVATE
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.dialer.R
import com.simplemobiletools.dialer.activities.SimpleActivity
import com.simplemobiletools.dialer.adapters.RecentCallsAdapter
import com.simplemobiletools.dialer.extensions.config
import com.simplemobiletools.dialer.helpers.MIN_RECENT_TRESHOLD
import com.simplemobiletools.dialer.helpers.RecentsHelper
import com.simplemobiletools.dialer.interfaces.RefreshItemsListener
import com.simplemobiletools.dialer.models.RecentCall
@@ -49,7 +51,8 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
override fun refreshItems(callback: (() -> Unit)?) {
val privateCursor = context?.getMyContactsCursor(false, true)
val groupSubsequentCalls = context?.config?.groupSubsequentCalls ?: false
RecentsHelper(context).getRecentCalls(groupSubsequentCalls) { recents ->
val size = allRecentCalls.count() + MIN_RECENT_TRESHOLD
RecentsHelper(context).getRecentCalls(groupSubsequentCalls, size) { recents ->
ContactsHelper(context).getContacts(showOnlyContactsWithNumbers = true) { contacts ->
val privateContacts = MyContactsContentProvider.getContacts(context, privateCursor)
@@ -118,6 +121,15 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
} else {
(currAdapter as RecentCallsAdapter).updateItems(recents)
}
recents_list.endlessScrollListener = object : MyRecyclerView.EndlessScrollListener {
override fun updateTop() {
}
override fun updateBottom() {
refreshItems()
}
}
}
}

View File

@@ -28,3 +28,5 @@ const val ACCEPT_CALL = PATH + "accept_call"
const val DECLINE_CALL = PATH + "decline_call"
const val DIALPAD_TONE_LENGTH_MS = 150L // The length of DTMF tones in milliseconds
const val MIN_RECENT_TRESHOLD = 30

View File

@@ -13,10 +13,9 @@ import com.simplemobiletools.dialer.models.RecentCall
class RecentsHelper(private val context: Context) {
private val COMPARABLE_PHONE_NUMBER_LENGTH = 9
private val QUERY_LIMIT = "200"
@SuppressLint("MissingPermission")
fun getRecentCalls(groupSubsequentCalls: Boolean, callback: (ArrayList<RecentCall>) -> Unit) {
fun getRecentCalls(groupSubsequentCalls: Boolean, size: Int = MIN_RECENT_TRESHOLD, callback: (ArrayList<RecentCall>) -> Unit) {
val privateCursor = context.getMyContactsCursor(false, true)
ensureBackgroundThread {
if (!context.hasPermission(PERMISSION_READ_CALL_LOG)) {
@@ -30,13 +29,13 @@ class RecentsHelper(private val context: Context) {
contacts.addAll(privateContacts)
}
getRecents(contacts, groupSubsequentCalls, callback)
getRecents(contacts, groupSubsequentCalls, size, callback)
}
}
}
@SuppressLint("NewApi")
private fun getRecents(contacts: ArrayList<Contact>, groupSubsequentCalls: Boolean, callback: (ArrayList<RecentCall>) -> Unit) {
private fun getRecents(contacts: ArrayList<Contact>, groupSubsequentCalls: Boolean, size: Int, callback: (ArrayList<RecentCall>) -> Unit) {
var recentCalls = ArrayList<RecentCall>()
var previousRecentCallFrom = ""
@@ -64,12 +63,12 @@ class RecentsHelper(private val context: Context) {
val cursor = if (isNougatPlus()) {
// https://issuetracker.google.com/issues/175198972?pli=1#comment6
val limitedUri = uri.buildUpon()
.appendQueryParameter(Calls.LIMIT_PARAM_KEY, QUERY_LIMIT)
.appendQueryParameter(Calls.LIMIT_PARAM_KEY, size.toString())
.build()
val sortOrder = "${Calls._ID} DESC"
context.contentResolver.query(limitedUri, projection, null, null, sortOrder)
} else {
val sortOrder = "${Calls._ID} DESC LIMIT $QUERY_LIMIT"
val sortOrder = "${Calls._ID} DESC LIMIT $size"
context.contentResolver.query(uri, projection, null, null, sortOrder)
}