mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
- also account for process death of the MainActivity by persisting the state of whether the dialer had been launched by default
51 lines
1.8 KiB
Kotlin
51 lines
1.8 KiB
Kotlin
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<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
|
|
}
|
|
|
|
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()
|
|
}
|