allow clicking the numbers at Manager speedDial setting
This commit is contained in:
parent
21029ac119
commit
e68cfc851a
|
@ -3,12 +3,18 @@ package com.simplemobiletools.contacts.pro.activities
|
|||
import android.os.Bundle
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.commons.views.MyTextView
|
||||
import com.simplemobiletools.contacts.pro.R
|
||||
import com.simplemobiletools.contacts.pro.dialogs.SelectContactsDialog
|
||||
import com.simplemobiletools.contacts.pro.extensions.config
|
||||
import com.simplemobiletools.contacts.pro.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.pro.models.Contact
|
||||
import com.simplemobiletools.contacts.pro.models.SpeedDial
|
||||
import kotlinx.android.synthetic.main.activity_manage_speed_dial.*
|
||||
|
||||
class ManageSpeedDialActivity : SimpleActivity() {
|
||||
var speedDialValues = ArrayList<SpeedDial>()
|
||||
private var allContacts = ArrayList<Contact>()
|
||||
private var speedDialValues = ArrayList<SpeedDial>()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -16,5 +22,35 @@ class ManageSpeedDialActivity : SimpleActivity() {
|
|||
|
||||
val speedDialType = object : TypeToken<List<SpeedDial>>() {}.type
|
||||
speedDialValues = Gson().fromJson<ArrayList<SpeedDial>>(config.speedDial, speedDialType) ?: ArrayList(1)
|
||||
|
||||
ContactsHelper(this).getContacts { contacts ->
|
||||
allContacts = contacts
|
||||
|
||||
val views = HashMap<Int, MyTextView>().apply {
|
||||
put(1, speed_dial_1)
|
||||
put(2, speed_dial_2)
|
||||
put(3, speed_dial_3)
|
||||
put(4, speed_dial_4)
|
||||
put(5, speed_dial_5)
|
||||
put(6, speed_dial_6)
|
||||
put(7, speed_dial_7)
|
||||
put(8, speed_dial_8)
|
||||
put(9, speed_dial_9)
|
||||
}
|
||||
|
||||
for ((id, textView) in views) {
|
||||
setupView(id, textView)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupView(id: Int, textView: MyTextView) {
|
||||
textView.setOnClickListener {
|
||||
SelectContactsDialog(this, allContacts, false, true) { addedContacts, removedContacts ->
|
||||
val selectedContact = addedContacts.first()
|
||||
val speedDial = SpeedDial(id, selectedContact.phoneNumbers.first().toString(), selectedContact.getNameToDisplay())
|
||||
textView.text = "$id. ${speedDial.displayName}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue