mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
Merge b38f417a46
into 4b281635c2
This commit is contained in:
@@ -8,10 +8,12 @@ import com.simplemobiletools.commons.helpers.ContactsHelper
|
|||||||
import com.simplemobiletools.commons.helpers.MyContactsContentProvider
|
import com.simplemobiletools.commons.helpers.MyContactsContentProvider
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALL_LOG
|
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALL_LOG
|
||||||
import com.simplemobiletools.commons.helpers.SMT_PRIVATE
|
import com.simplemobiletools.commons.helpers.SMT_PRIVATE
|
||||||
|
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
import com.simplemobiletools.dialer.R
|
import com.simplemobiletools.dialer.R
|
||||||
import com.simplemobiletools.dialer.activities.SimpleActivity
|
import com.simplemobiletools.dialer.activities.SimpleActivity
|
||||||
import com.simplemobiletools.dialer.adapters.RecentCallsAdapter
|
import com.simplemobiletools.dialer.adapters.RecentCallsAdapter
|
||||||
import com.simplemobiletools.dialer.extensions.config
|
import com.simplemobiletools.dialer.extensions.config
|
||||||
|
import com.simplemobiletools.dialer.helpers.MIN_RECENT_TRESHOLD
|
||||||
import com.simplemobiletools.dialer.helpers.RecentsHelper
|
import com.simplemobiletools.dialer.helpers.RecentsHelper
|
||||||
import com.simplemobiletools.dialer.interfaces.RefreshItemsListener
|
import com.simplemobiletools.dialer.interfaces.RefreshItemsListener
|
||||||
import com.simplemobiletools.dialer.models.RecentCall
|
import com.simplemobiletools.dialer.models.RecentCall
|
||||||
@@ -49,7 +51,8 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
|||||||
override fun refreshItems(callback: (() -> Unit)?) {
|
override fun refreshItems(callback: (() -> Unit)?) {
|
||||||
val privateCursor = context?.getMyContactsCursor(false, true)
|
val privateCursor = context?.getMyContactsCursor(false, true)
|
||||||
val groupSubsequentCalls = context?.config?.groupSubsequentCalls ?: false
|
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 ->
|
ContactsHelper(context).getContacts(showOnlyContactsWithNumbers = true) { contacts ->
|
||||||
val privateContacts = MyContactsContentProvider.getContacts(context, privateCursor)
|
val privateContacts = MyContactsContentProvider.getContacts(context, privateCursor)
|
||||||
|
|
||||||
@@ -118,6 +121,15 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
|||||||
} else {
|
} else {
|
||||||
(currAdapter as RecentCallsAdapter).updateItems(recents)
|
(currAdapter as RecentCallsAdapter).updateItems(recents)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
recents_list.endlessScrollListener = object : MyRecyclerView.EndlessScrollListener {
|
||||||
|
override fun updateTop() {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun updateBottom() {
|
||||||
|
refreshItems()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,3 +28,5 @@ const val ACCEPT_CALL = PATH + "accept_call"
|
|||||||
const val DECLINE_CALL = PATH + "decline_call"
|
const val DECLINE_CALL = PATH + "decline_call"
|
||||||
|
|
||||||
const val DIALPAD_TONE_LENGTH_MS = 150L // The length of DTMF tones in milliseconds
|
const val DIALPAD_TONE_LENGTH_MS = 150L // The length of DTMF tones in milliseconds
|
||||||
|
|
||||||
|
const val MIN_RECENT_TRESHOLD = 30
|
||||||
|
@@ -13,10 +13,9 @@ 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, size: Int = MIN_RECENT_TRESHOLD, callback: (ArrayList<RecentCall>) -> Unit) {
|
||||||
val privateCursor = context.getMyContactsCursor(false, true)
|
val privateCursor = context.getMyContactsCursor(false, true)
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
if (!context.hasPermission(PERMISSION_READ_CALL_LOG)) {
|
if (!context.hasPermission(PERMISSION_READ_CALL_LOG)) {
|
||||||
@@ -30,13 +29,13 @@ class RecentsHelper(private val context: Context) {
|
|||||||
contacts.addAll(privateContacts)
|
contacts.addAll(privateContacts)
|
||||||
}
|
}
|
||||||
|
|
||||||
getRecents(contacts, groupSubsequentCalls, callback)
|
getRecents(contacts, groupSubsequentCalls, size, callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@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 recentCalls = ArrayList<RecentCall>()
|
||||||
var previousRecentCallFrom = ""
|
var previousRecentCallFrom = ""
|
||||||
@@ -64,12 +63,12 @@ class RecentsHelper(private val context: Context) {
|
|||||||
val cursor = if (isNougatPlus()) {
|
val cursor = if (isNougatPlus()) {
|
||||||
// https://issuetracker.google.com/issues/175198972?pli=1#comment6
|
// https://issuetracker.google.com/issues/175198972?pli=1#comment6
|
||||||
val limitedUri = uri.buildUpon()
|
val limitedUri = uri.buildUpon()
|
||||||
.appendQueryParameter(Calls.LIMIT_PARAM_KEY, QUERY_LIMIT)
|
.appendQueryParameter(Calls.LIMIT_PARAM_KEY, size.toString())
|
||||||
.build()
|
.build()
|
||||||
val sortOrder = "${Calls._ID} DESC"
|
val sortOrder = "${Calls._ID} DESC"
|
||||||
context.contentResolver.query(limitedUri, projection, null, null, sortOrder)
|
context.contentResolver.query(limitedUri, projection, null, null, sortOrder)
|
||||||
} else {
|
} else {
|
||||||
val sortOrder = "${Calls._ID} DESC LIMIT $QUERY_LIMIT"
|
val sortOrder = "${Calls._ID} DESC LIMIT $size"
|
||||||
context.contentResolver.query(uri, projection, null, null, sortOrder)
|
context.contentResolver.query(uri, projection, null, null, sortOrder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user