From b4ada2f1655d7326e3e37c2132316e01fc2597d3 Mon Sep 17 00:00:00 2001 From: Ashutosh Gupta <68068357+Ashutoshgupta22@users.noreply.github.com> Date: Fri, 6 Oct 2023 16:36:05 +0530 Subject: [PATCH 1/5] implement redial feature --- .../dialer/activities/DialpadActivity.kt | 29 +++++++++++++++++++ .../dialer/fragments/RecentsFragment.kt | 3 +- 2 files changed, 31 insertions(+), 1 deletion(-) 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..93d71d145 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.* @@ -347,6 +351,31 @@ class DialpadActivity : SimpleActivity() { } } } + 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) + } + } } private fun speedDial(id: Int): Boolean { 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 } From ba162a3c3759bf1b7f6a5befc8c3b8db912d1d25 Mon Sep 17 00:00:00 2001 From: Ashutosh Gupta <68068357+Ashutoshgupta22@users.noreply.github.com> Date: Fri, 6 Oct 2023 16:36:05 +0530 Subject: [PATCH 2/5] implement redial feature --- .../dialer/activities/DialpadActivity.kt | 30 +++++++++++++++++++ .../dialer/fragments/RecentsFragment.kt | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) 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..e3893e64e 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,32 @@ 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..8cfc99d14 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/RecentsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/RecentsFragment.kt @@ -176,7 +176,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 } From 14d1c98c7f1342796b676110a445624d48d63da9 Mon Sep 17 00:00:00 2001 From: Ashutosh Gupta <68068357+Ashutoshgupta22@users.noreply.github.com> Date: Sat, 7 Oct 2023 01:10:55 +0530 Subject: [PATCH 3/5] reformat code --- .../dialer/activities/DialpadActivity.kt | 25 ------------------- 1 file changed, 25 deletions(-) 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 2c7eafede..e3893e64e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/activities/DialpadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/activities/DialpadActivity.kt @@ -377,31 +377,6 @@ class DialpadActivity : SimpleActivity() { .newEditable(it) } } - 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) - } - } } private fun speedDial(id: Int): Boolean { From c477e8a232627ff4958dd549f82b1db93e6b1534 Mon Sep 17 00:00:00 2001 From: Ashutosh Gupta <68068357+Ashutoshgupta22@users.noreply.github.com> Date: Sat, 7 Oct 2023 01:10:55 +0530 Subject: [PATCH 4/5] reformat code --- .../com/simplemobiletools/dialer/activities/DialpadActivity.kt | 2 -- 1 file changed, 2 deletions(-) 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 e3893e64e..7126c6fdf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/activities/DialpadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/activities/DialpadActivity.kt @@ -356,9 +356,7 @@ class DialpadActivity : SimpleActivity() { } private fun setLastDialedNumber() { - var lastDialed: String? - val privateCursor = this.getMyContactsCursor(false, true) val groupSubsequentCalls = this.config.groupSubsequentCalls val querySize = MIN_RECENTS_THRESHOLD From 46fff029deeb6a1435cd8a4b5650e262bf250fd1 Mon Sep 17 00:00:00 2001 From: Ashutosh Gupta <68068357+Ashutoshgupta22@users.noreply.github.com> Date: Sat, 7 Oct 2023 14:39:48 +0530 Subject: [PATCH 5/5] remove extra lines --- .../com/simplemobiletools/dialer/activities/DialpadActivity.kt | 3 --- 1 file changed, 3 deletions(-) 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 7126c6fdf..c2cacbea4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/activities/DialpadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/activities/DialpadActivity.kt @@ -361,15 +361,12 @@ class DialpadActivity : SimpleActivity() { 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)