package com.simplemobiletools.dialer.helpers import android.content.Context import android.net.Uri import com.google.gson.Gson import com.google.gson.reflect.TypeToken import com.simplemobiletools.commons.helpers.BaseConfig import com.simplemobiletools.dialer.models.SpeedDial class Config(context: Context) : BaseConfig(context) { companion object { fun newInstance(context: Context) = Config(context) } var speedDial: String get() = prefs.getString(SPEED_DIAL, "")!! set(speedDial) = prefs.edit().putString(SPEED_DIAL, speedDial).apply() fun getSpeedDialValues(): ArrayList { val speedDialType = object : TypeToken>() {}.type val speedDialValues = Gson().fromJson>(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 } fun saveCustomSIM(number: String, SIMlabel: String) { prefs.edit().putString(REMEMBER_SIM_PREFIX + number, Uri.encode(SIMlabel)).apply() } fun getCustomSIM(number: String) = prefs.getString(REMEMBER_SIM_PREFIX + number, "") fun removeCustomSIM(number: String) { prefs.edit().remove(REMEMBER_SIM_PREFIX + number).apply() } var groupSubsequentCalls: Boolean get() = prefs.getBoolean(GROUP_SUBSEQUENT_CALLS, true) set(groupSubsequentCalls) = prefs.edit().putBoolean(GROUP_SUBSEQUENT_CALLS, groupSubsequentCalls).apply() var openDialPadAtLaunch: Boolean get() = prefs.getBoolean(OPEN_DIAL_PAD_AT_LAUNCH, false) set(openDialPad) = prefs.edit().putBoolean(OPEN_DIAL_PAD_AT_LAUNCH, openDialPad).apply() }