adding a helper function for retrieving a prefilled SpeedDial arraylist
This commit is contained in:
parent
7c2ca77e7a
commit
474f22be38
|
@ -2,7 +2,6 @@ package com.simplemobiletools.contacts.pro.activities
|
|||
|
||||
import android.os.Bundle
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.contacts.pro.R
|
||||
import com.simplemobiletools.contacts.pro.adapters.SpeedDialAdapter
|
||||
import com.simplemobiletools.contacts.pro.dialogs.SelectContactsDialog
|
||||
|
@ -21,16 +20,7 @@ class ManageSpeedDialActivity : SimpleActivity(), RemoveSpeedDialListener {
|
|||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_manage_speed_dial)
|
||||
|
||||
val speedDialType = object : TypeToken<List<SpeedDial>>() {}.type
|
||||
speedDialValues = Gson().fromJson<ArrayList<SpeedDial>>(config.speedDial, speedDialType) ?: ArrayList(1)
|
||||
|
||||
for (i in 1..9) {
|
||||
val speedDial = SpeedDial(i, "", "")
|
||||
if (speedDialValues.firstOrNull { it.id == i } == null) {
|
||||
speedDialValues.add(speedDial)
|
||||
}
|
||||
}
|
||||
|
||||
speedDialValues = config.getSpeedDialValues()
|
||||
updateAdapter()
|
||||
ContactsHelper(this).getContacts { contacts ->
|
||||
allContacts = contacts
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package com.simplemobiletools.contacts.pro.helpers
|
||||
|
||||
import android.content.Context
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.commons.helpers.BaseConfig
|
||||
import com.simplemobiletools.contacts.pro.models.SpeedDial
|
||||
|
||||
class Config(context: Context) : BaseConfig(context) {
|
||||
companion object {
|
||||
|
@ -60,4 +63,18 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
var speedDial: String
|
||||
get() = prefs.getString(SPEED_DIAL, "")!!
|
||||
set(speedDial) = prefs.edit().putString(SPEED_DIAL, speedDial).apply()
|
||||
|
||||
fun getSpeedDialValues(): ArrayList<SpeedDial> {
|
||||
val speedDialType = object : TypeToken<List<SpeedDial>>() {}.type
|
||||
val speedDialValues = Gson().fromJson<ArrayList<SpeedDial>>(speedDial, speedDialType) ?: ArrayList(1)
|
||||
|
||||
for (i in 1..9) {
|
||||
val speedDial = SpeedDial(i, "", "")
|
||||
if (speedDialValues.firstOrNull { it.id == i } == null) {
|
||||
speedDialValues.add(speedDial)
|
||||
}
|
||||
}
|
||||
|
||||
return speedDialValues
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue