mirror of
				https://github.com/SimpleMobileTools/Simple-Dialer.git
				synced 2025-06-05 21:49:23 +02:00 
			
		
		
		
	adding Search at Recents too
This commit is contained in:
		@@ -4,6 +4,7 @@ import android.content.Intent
 | 
			
		||||
import android.graphics.drawable.Drawable
 | 
			
		||||
import android.net.Uri
 | 
			
		||||
import android.provider.CallLog.Calls
 | 
			
		||||
import android.text.SpannableString
 | 
			
		||||
import android.text.TextUtils
 | 
			
		||||
import android.util.TypedValue
 | 
			
		||||
import android.view.Menu
 | 
			
		||||
@@ -33,6 +34,7 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
 | 
			
		||||
    private var fontSize = activity.getTextSize()
 | 
			
		||||
    private val areMultipleSIMsAvailable = activity.areMultipleSIMsAvailable()
 | 
			
		||||
    private val redColor = resources.getColor(R.color.md_red_700)
 | 
			
		||||
    private var textToHighlight = ""
 | 
			
		||||
 | 
			
		||||
    init {
 | 
			
		||||
        initDrawables()
 | 
			
		||||
@@ -203,11 +205,15 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun updateItems(newItems: ArrayList<RecentCall>) {
 | 
			
		||||
    fun updateItems(newItems: ArrayList<RecentCall>, highlightText: String = "") {
 | 
			
		||||
        if (newItems.hashCode() != recentCalls.hashCode()) {
 | 
			
		||||
            recentCalls = newItems.clone() as ArrayList<RecentCall>
 | 
			
		||||
            textToHighlight = highlightText
 | 
			
		||||
            notifyDataSetChanged()
 | 
			
		||||
            finishActMode()
 | 
			
		||||
        } else if (textToHighlight != highlightText) {
 | 
			
		||||
            textToHighlight = highlightText
 | 
			
		||||
            notifyDataSetChanged()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -216,9 +222,13 @@ class RecentCallsAdapter(activity: SimpleActivity, var recentCalls: ArrayList<Re
 | 
			
		||||
    private fun setupView(view: View, call: RecentCall) {
 | 
			
		||||
        view.apply {
 | 
			
		||||
            item_recents_frame.isSelected = selectedKeys.contains(call.id)
 | 
			
		||||
            var nameToShow = call.name
 | 
			
		||||
            var nameToShow = SpannableString(call.name)
 | 
			
		||||
            if (call.neighbourIDs.isNotEmpty()) {
 | 
			
		||||
                nameToShow += " (${call.neighbourIDs.size + 1})"
 | 
			
		||||
                nameToShow = SpannableString("$nameToShow (${call.neighbourIDs.size + 1})")
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (textToHighlight.isNotEmpty() && nameToShow.contains(textToHighlight, true)) {
 | 
			
		||||
                nameToShow = SpannableString(nameToShow.toString().highlightTextPart(textToHighlight, adjustedPrimaryColor))
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            item_recents_name.apply {
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@ import com.simplemobiletools.commons.extensions.*
 | 
			
		||||
import com.simplemobiletools.commons.helpers.MyContactsContentProvider
 | 
			
		||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALL_LOG
 | 
			
		||||
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
 | 
			
		||||
import com.simplemobiletools.commons.helpers.mydebug
 | 
			
		||||
import com.simplemobiletools.dialer.R
 | 
			
		||||
import com.simplemobiletools.dialer.activities.SimpleActivity
 | 
			
		||||
import com.simplemobiletools.dialer.adapters.RecentCallsAdapter
 | 
			
		||||
@@ -16,6 +17,8 @@ import com.simplemobiletools.dialer.models.RecentCall
 | 
			
		||||
import kotlinx.android.synthetic.main.fragment_recents.view.*
 | 
			
		||||
 | 
			
		||||
class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), RefreshItemsListener {
 | 
			
		||||
    private var allRecentCalls = ArrayList<RecentCall>()
 | 
			
		||||
 | 
			
		||||
    override fun setupFragment() {
 | 
			
		||||
        val placeholderResId = if (context.hasPermission(PERMISSION_READ_CALL_LOG)) {
 | 
			
		||||
            R.string.no_previous_calls
 | 
			
		||||
@@ -47,6 +50,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
 | 
			
		||||
        RecentsHelper(context).getRecentCalls { recents ->
 | 
			
		||||
            SimpleContactsHelper(context).getAvailableContacts(false) { contacts ->
 | 
			
		||||
                val privateContacts = MyContactsContentProvider.getSimpleContacts(context, privateCursor)
 | 
			
		||||
 | 
			
		||||
                recents.filter { it.phoneNumber == it.name }.forEach { recent ->
 | 
			
		||||
                    var wasNameFilled = false
 | 
			
		||||
                    if (privateContacts.isNotEmpty()) {
 | 
			
		||||
@@ -65,6 +69,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                allRecentCalls = recents
 | 
			
		||||
                activity?.runOnUiThread {
 | 
			
		||||
                    gotRecents(recents)
 | 
			
		||||
                }
 | 
			
		||||
@@ -111,10 +116,14 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun onSearchClosed() {
 | 
			
		||||
 | 
			
		||||
        (recents_list.adapter as? RecentCallsAdapter)?.updateItems(allRecentCalls)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun onSearchQueryChanged(text: String) {
 | 
			
		||||
        val recentCalls = allRecentCalls.filter {
 | 
			
		||||
            it.name.contains(text, true) || it.doesContainPhoneNumber(text)
 | 
			
		||||
        }.toMutableList() as ArrayList<RecentCall>
 | 
			
		||||
 | 
			
		||||
        (recents_list.adapter as? RecentCallsAdapter)?.updateItems(recentCalls, text)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,15 @@
 | 
			
		||||
package com.simplemobiletools.dialer.models
 | 
			
		||||
 | 
			
		||||
import android.telephony.PhoneNumberUtils
 | 
			
		||||
import com.simplemobiletools.commons.extensions.normalizePhoneNumber
 | 
			
		||||
 | 
			
		||||
data class RecentCall(var id: Int, var phoneNumber: String, var name: String, var photoUri: String, var startTS: Int, var duration: Int, var type: Int,
 | 
			
		||||
                      var neighbourIDs: ArrayList<Int>, val simID: Int)
 | 
			
		||||
                      var neighbourIDs: ArrayList<Int>, val simID: Int) {
 | 
			
		||||
    fun doesContainPhoneNumber(text: String): Boolean {
 | 
			
		||||
        val normalizedText = text.normalizePhoneNumber()
 | 
			
		||||
        return PhoneNumberUtils.compare(phoneNumber.normalizePhoneNumber(), normalizedText) ||
 | 
			
		||||
                phoneNumber.contains(text) ||
 | 
			
		||||
                phoneNumber.normalizePhoneNumber().contains(normalizedText) ||
 | 
			
		||||
                phoneNumber.contains(normalizedText)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user