From e68cfc851ae64119d4bddf565388352435e427be Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 19 Jan 2020 22:54:28 +0100 Subject: [PATCH] allow clicking the numbers at Manager speedDial setting --- .../pro/activities/ManageSpeedDialActivity.kt | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ManageSpeedDialActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ManageSpeedDialActivity.kt index 4f12804e..db5faa36 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ManageSpeedDialActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ManageSpeedDialActivity.kt @@ -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() + private var allContacts = ArrayList() + private var speedDialValues = ArrayList() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -16,5 +22,35 @@ class ManageSpeedDialActivity : SimpleActivity() { val speedDialType = object : TypeToken>() {}.type speedDialValues = Gson().fromJson>(config.speedDial, speedDialType) ?: ArrayList(1) + + ContactsHelper(this).getContacts { contacts -> + allContacts = contacts + + val views = HashMap().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}" + } + } } }