diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/activities/DialpadActivity.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/activities/DialpadActivity.kt index f18bf27b4..c2cacbea4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/activities/DialpadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/activities/DialpadActivity.kt @@ -12,6 +12,7 @@ import android.os.Looper import android.provider.Telephony.Sms.Intents.SECRET_CODE_ACTION import android.telephony.PhoneNumberUtils import android.telephony.TelephonyManager +import android.text.Editable import android.util.TypedValue import android.view.KeyEvent import android.view.MotionEvent @@ -28,7 +29,10 @@ import com.simplemobiletools.dialer.R import com.simplemobiletools.dialer.adapters.ContactsAdapter import com.simplemobiletools.dialer.databinding.ActivityDialpadBinding import com.simplemobiletools.dialer.extensions.* +import com.simplemobiletools.dialer.fragments.hidePrivateContacts import com.simplemobiletools.dialer.helpers.DIALPAD_TONE_LENGTH_MS +import com.simplemobiletools.dialer.helpers.MIN_RECENTS_THRESHOLD +import com.simplemobiletools.dialer.helpers.RecentsHelper import com.simplemobiletools.dialer.helpers.ToneGeneratorHelper import com.simplemobiletools.dialer.models.SpeedDial import java.util.* @@ -346,6 +350,27 @@ class DialpadActivity : SimpleActivity() { startCallIntent(number) } } + } else { + setLastDialedNumber() + } + } + + private fun setLastDialedNumber() { + var lastDialed: String? + val privateCursor = this.getMyContactsCursor(false, true) + val groupSubsequentCalls = this.config.groupSubsequentCalls + val querySize = MIN_RECENTS_THRESHOLD + RecentsHelper(this).getRecentCalls(groupSubsequentCalls, querySize) { recents -> + val privateContacts = MyContactsContentProvider.getContacts(this, privateCursor) + lastDialed = recents + .hidePrivateContacts( + privateContacts, + SMT_PRIVATE in this.baseConfig.ignoredContactSources + ).firstOrNull()?.phoneNumber + lastDialed?.let { + binding.dialpadInput.text = Editable.Factory.getInstance() + .newEditable(it) + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/RecentsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/RecentsFragment.kt index d3e9ebc3c..931cf555e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/RecentsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/RecentsFragment.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.dialer.fragments import android.content.Context import android.util.AttributeSet +import android.util.Log import com.simplemobiletools.commons.dialogs.CallConfirmationDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.ContactsHelper @@ -176,7 +177,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage } // hide private contacts from recent calls -private fun List.hidePrivateContacts(privateContacts: List, shouldHide: Boolean): List { +fun List.hidePrivateContacts(privateContacts: List, shouldHide: Boolean): List { return if (shouldHide) { filterNot { recent -> val privateNumbers = privateContacts.flatMap { it.phoneNumbers }.map { it.value }