mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-23 14:57:36 +01:00
properly handle saving and restoring speed dial items
This commit is contained in:
parent
e68cfc851a
commit
8dd1216176
@ -20,36 +20,48 @@ class ManageSpeedDialActivity : SimpleActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_manage_speed_dial)
|
setContentView(R.layout.activity_manage_speed_dial)
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
val speedDialType = object : TypeToken<List<SpeedDial>>() {}.type
|
val speedDialType = object : TypeToken<List<SpeedDial>>() {}.type
|
||||||
speedDialValues = Gson().fromJson<ArrayList<SpeedDial>>(config.speedDial, speedDialType) ?: ArrayList(1)
|
speedDialValues = Gson().fromJson<ArrayList<SpeedDial>>(config.speedDial, speedDialType) ?: ArrayList(1)
|
||||||
|
|
||||||
|
speedDialValues.forEach {
|
||||||
|
val view = views.get(it.id)
|
||||||
|
view!!.text = "${it.id}. ${it.displayName}"
|
||||||
|
}
|
||||||
|
|
||||||
ContactsHelper(this).getContacts { contacts ->
|
ContactsHelper(this).getContacts { contacts ->
|
||||||
allContacts = 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) {
|
for ((id, textView) in views) {
|
||||||
setupView(id, textView)
|
setupView(id, textView)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onStop() {
|
||||||
|
super.onStop()
|
||||||
|
config.speedDial = Gson().toJson(speedDialValues)
|
||||||
|
}
|
||||||
|
|
||||||
private fun setupView(id: Int, textView: MyTextView) {
|
private fun setupView(id: Int, textView: MyTextView) {
|
||||||
textView.setOnClickListener {
|
textView.setOnClickListener {
|
||||||
SelectContactsDialog(this, allContacts, false, true) { addedContacts, removedContacts ->
|
SelectContactsDialog(this, allContacts, false, true) { addedContacts, removedContacts ->
|
||||||
val selectedContact = addedContacts.first()
|
val selectedContact = addedContacts.first()
|
||||||
val speedDial = SpeedDial(id, selectedContact.phoneNumbers.first().toString(), selectedContact.getNameToDisplay())
|
val speedDial = SpeedDial(id, selectedContact.phoneNumbers.first().toString(), selectedContact.getNameToDisplay())
|
||||||
textView.text = "$id. ${speedDial.displayName}"
|
textView.text = "$id. ${speedDial.displayName}"
|
||||||
|
speedDialValues = speedDialValues.filter { it.id != id }.toMutableList() as ArrayList<SpeedDial>
|
||||||
|
speedDialValues.add(speedDial)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user