fix #368, implementing speed dialing at the dialpad activity

This commit is contained in:
tibbi 2020-01-20 23:02:46 +01:00
parent 32b25e0e26
commit fd6497991d
1 changed files with 24 additions and 3 deletions

View File

@ -27,10 +27,12 @@ import com.simplemobiletools.contacts.pro.helpers.KEY_PHONE
import com.simplemobiletools.contacts.pro.helpers.LOCATION_DIALPAD
import com.simplemobiletools.contacts.pro.helpers.REQUEST_CODE_SET_DEFAULT_DIALER
import com.simplemobiletools.contacts.pro.models.Contact
import com.simplemobiletools.contacts.pro.models.SpeedDial
import kotlinx.android.synthetic.main.activity_dialpad.*
class DialpadActivity : SimpleActivity() {
var contacts = ArrayList<Contact>()
private var contacts = ArrayList<Contact>()
private var speedDialValues = ArrayList<SpeedDial>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -40,6 +42,8 @@ class DialpadActivity : SimpleActivity() {
return
}
speedDialValues = config.getSpeedDialValues()
dialpad_0_holder.setOnClickListener { dialpadPressed("0", it) }
dialpad_1.setOnClickListener { dialpadPressed("1", it) }
dialpad_2.setOnClickListener { dialpadPressed("2", it) }
@ -50,6 +54,17 @@ class DialpadActivity : SimpleActivity() {
dialpad_7.setOnClickListener { dialpadPressed("7", it) }
dialpad_8.setOnClickListener { dialpadPressed("8", it) }
dialpad_9.setOnClickListener { dialpadPressed("9", it) }
dialpad_1.setOnLongClickListener { speedDial(1); true }
dialpad_2.setOnLongClickListener { speedDial(2); true }
dialpad_3.setOnLongClickListener { speedDial(3); true }
dialpad_4.setOnLongClickListener { speedDial(4); true }
dialpad_5.setOnLongClickListener { speedDial(5); true }
dialpad_6.setOnLongClickListener { speedDial(6); true }
dialpad_7.setOnLongClickListener { speedDial(7); true }
dialpad_8.setOnLongClickListener { speedDial(8); true }
dialpad_9.setOnLongClickListener { speedDial(9); true }
dialpad_0_holder.setOnLongClickListener { dialpadPressed("+", null); true }
dialpad_asterisk.setOnClickListener { dialpadPressed("*", it) }
dialpad_hashtag.setOnClickListener { dialpadPressed("#", it) }
@ -204,8 +219,7 @@ class DialpadActivity : SimpleActivity() {
}
}
private fun initCall() {
val number = dialpad_input.value
private fun initCall(number: String = dialpad_input.value) {
if (number.isNotEmpty()) {
if (config.showCallConfirmation) {
CallConfirmationDialog(this, number) {
@ -216,4 +230,11 @@ class DialpadActivity : SimpleActivity() {
}
}
}
private fun speedDial(id: Int) {
val speedDial = speedDialValues.firstOrNull { it.id == id }
if (speedDial?.isValid() == true) {
initCall(speedDial.number)
}
}
}