adding an optional call confirmation dialog

This commit is contained in:
tibbi
2021-07-25 17:43:17 +02:00
parent 618a88a09c
commit 79b3ad0721
6 changed files with 72 additions and 18 deletions

View File

@@ -55,6 +55,6 @@ android {
} }
dependencies { dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:dcbd6eca15' implementation 'com.github.SimpleMobileTools:Simple-Commons:11c7236fdb'
implementation 'com.github.tibbi:IndicatorFastScroll:c3de1d040a' implementation 'com.github.tibbi:IndicatorFastScroll:c3de1d040a'
} }

View File

@@ -35,6 +35,7 @@ class SettingsActivity : SimpleActivity() {
setupDefaultTab() setupDefaultTab()
setupGroupSubsequentCalls() setupGroupSubsequentCalls()
setupStartNameWithSurname() setupStartNameWithSurname()
setupShowCallConfirmation()
updateTextColors(settings_holder) updateTextColors(settings_holder)
invalidateOptionsMenu() invalidateOptionsMenu()
} }
@@ -147,4 +148,12 @@ class SettingsActivity : SimpleActivity() {
config.startNameWithSurname = settings_start_with_surname.isChecked config.startNameWithSurname = settings_start_with_surname.isChecked
} }
} }
private fun setupShowCallConfirmation() {
settings_show_call_confirmation.isChecked = config.showCallConfirmation
settings_show_call_confirmation_holder.setOnClickListener {
settings_show_call_confirmation.toggle()
config.showCallConfirmation = settings_show_call_confirmation.isChecked
}
}
} }

View File

@@ -4,6 +4,7 @@ import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import com.reddit.indicatorfastscroll.FastScrollItemIndicator import com.reddit.indicatorfastscroll.FastScrollItemIndicator
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.dialogs.CallConfirmationDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.MyContactsContentProvider import com.simplemobiletools.commons.helpers.MyContactsContentProvider
@@ -14,6 +15,7 @@ import com.simplemobiletools.commons.models.SimpleContact
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.ContactsAdapter import com.simplemobiletools.dialer.adapters.ContactsAdapter
import com.simplemobiletools.dialer.extensions.config
import com.simplemobiletools.dialer.interfaces.RefreshItemsListener import com.simplemobiletools.dialer.interfaces.RefreshItemsListener
import kotlinx.android.synthetic.main.fragment_letters_layout.view.* import kotlinx.android.synthetic.main.fragment_letters_layout.view.*
import java.util.* import java.util.*
@@ -72,18 +74,12 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
val currAdapter = fragment_list.adapter val currAdapter = fragment_list.adapter
if (currAdapter == null) { if (currAdapter == null) {
ContactsAdapter(activity as SimpleActivity, contacts, fragment_list, this, showDeleteButton = false) { ContactsAdapter(activity as SimpleActivity, contacts, fragment_list, this, showDeleteButton = false) {
val phoneNumbers = (it as SimpleContact).phoneNumbers if (context.config.showCallConfirmation) {
if (phoneNumbers.size <= 1) { CallConfirmationDialog(activity as SimpleActivity, (it as SimpleContact).name) {
activity?.launchCallIntent(it.phoneNumbers.first()) callContact(it)
}
} else { } else {
val items = ArrayList<RadioItem>() callContact(it as SimpleContact)
phoneNumbers.forEachIndexed { index, phoneNumber ->
items.add(RadioItem(index, phoneNumber))
}
RadioGroupDialog(activity!!, items) {
activity?.launchCallIntent(phoneNumbers[it as Int])
}
} }
}.apply { }.apply {
fragment_list.adapter = this fragment_list.adapter = this
@@ -94,6 +90,22 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
} }
} }
private fun callContact(simpleContact: SimpleContact) {
val phoneNumbers = simpleContact.phoneNumbers
if (phoneNumbers.size <= 1) {
activity?.launchCallIntent(phoneNumbers.first())
} else {
val items = ArrayList<RadioItem>()
phoneNumbers.forEachIndexed { index, phoneNumber ->
items.add(RadioItem(index, phoneNumber))
}
RadioGroupDialog(activity!!, items) {
activity?.launchCallIntent(phoneNumbers[it as Int])
}
}
}
private fun setupLetterFastscroller(contacts: ArrayList<SimpleContact>) { private fun setupLetterFastscroller(contacts: ArrayList<SimpleContact>) {
letter_fastscroller.setupWithRecyclerView(fragment_list, { position -> letter_fastscroller.setupWithRecyclerView(fragment_list, { position ->
try { try {

View File

@@ -2,6 +2,7 @@ package com.simplemobiletools.dialer.fragments
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import com.simplemobiletools.commons.dialogs.CallConfirmationDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
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
@@ -90,7 +91,14 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
val currAdapter = recents_list.adapter val currAdapter = recents_list.adapter
if (currAdapter == null) { if (currAdapter == null) {
RecentCallsAdapter(activity as SimpleActivity, recents, recents_list, this) { RecentCallsAdapter(activity as SimpleActivity, recents, recents_list, this) {
activity?.launchCallIntent((it as RecentCall).phoneNumber) val recentCall = it as RecentCall
if (context.config.showCallConfirmation) {
CallConfirmationDialog(activity as SimpleActivity, recentCall.name) {
activity?.launchCallIntent(recentCall.phoneNumber)
}
} else {
activity?.launchCallIntent(recentCall.phoneNumber)
}
}.apply { }.apply {
recents_list.adapter = this recents_list.adapter = this
} }

View File

@@ -3,13 +3,15 @@ package com.simplemobiletools.dialer.models
import android.telephony.PhoneNumberUtils import android.telephony.PhoneNumberUtils
import com.simplemobiletools.commons.extensions.normalizePhoneNumber 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, data class RecentCall(
var neighbourIDs: ArrayList<Int>, val simID: Int) { 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
) {
fun doesContainPhoneNumber(text: String): Boolean { fun doesContainPhoneNumber(text: String): Boolean {
val normalizedText = text.normalizePhoneNumber() val normalizedText = text.normalizePhoneNumber()
return PhoneNumberUtils.compare(phoneNumber.normalizePhoneNumber(), normalizedText) || return PhoneNumberUtils.compare(phoneNumber.normalizePhoneNumber(), normalizedText) ||
phoneNumber.contains(text) || phoneNumber.contains(text) ||
phoneNumber.normalizePhoneNumber().contains(normalizedText) || phoneNumber.normalizePhoneNumber().contains(normalizedText) ||
phoneNumber.contains(normalizedText) phoneNumber.contains(normalizedText)
} }
} }

View File

@@ -248,5 +248,28 @@
app:switchPadding="@dimen/medium_margin" /> app:switchPadding="@dimen/medium_margin" />
</RelativeLayout> </RelativeLayout>
<RelativeLayout
android:id="@+id/settings_show_call_confirmation_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:paddingStart="@dimen/normal_margin"
android:paddingTop="@dimen/activity_margin"
android:paddingEnd="@dimen/normal_margin"
android:paddingBottom="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/settings_show_call_confirmation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:paddingStart="@dimen/medium_margin"
android:text="@string/show_call_confirmation_dialog"
app:switchPadding="@dimen/medium_margin" />
</RelativeLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>