2023-07-12 18:51:43 +10:00

103 lines
4.3 KiB
Kotlin

package com.simplemobiletools.dialer.helpers
import android.content.ComponentName
import android.content.Context
import android.telecom.PhoneAccountHandle
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.simplemobiletools.commons.helpers.BaseConfig
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
import com.simplemobiletools.dialer.extensions.getPhoneAccountHandleModel
import com.simplemobiletools.dialer.extensions.putPhoneAccountHandle
import com.simplemobiletools.dialer.models.SpeedDial
class Config(context: Context) : BaseConfig(context) {
companion object {
fun newInstance(context: Context) = Config(context)
}
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, handle: PhoneAccountHandle) {
prefs.edit().putPhoneAccountHandle(REMEMBER_SIM_PREFIX + number, handle).apply()
}
fun getCustomSIM(number: String): PhoneAccountHandle? {
val myPhoneAccountHandle = prefs.getPhoneAccountHandleModel(REMEMBER_SIM_PREFIX + number, null)
return if (myPhoneAccountHandle != null) {
val packageName = myPhoneAccountHandle.packageName
val className = myPhoneAccountHandle.className
val componentName = ComponentName(packageName, className)
val id = myPhoneAccountHandle.id
PhoneAccountHandle(componentName, id)
} else {
null
}
}
fun removeCustomSIM(number: String) {
prefs.edit().remove(REMEMBER_SIM_PREFIX + number).apply()
}
var showTabs: Int
get() = prefs.getInt(SHOW_TABS, ALL_TABS_MASK)
set(showTabs) = prefs.edit().putInt(SHOW_TABS, showTabs).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()
var disableProximitySensor: Boolean
get() = prefs.getBoolean(DISABLE_PROXIMITY_SENSOR, false)
set(disableProximitySensor) = prefs.edit().putBoolean(DISABLE_PROXIMITY_SENSOR, disableProximitySensor).apply()
var disableSwipeToAnswer: Boolean
get() = prefs.getBoolean(DISABLE_SWIPE_TO_ANSWER, false)
set(disableSwipeToAnswer) = prefs.edit().putBoolean(DISABLE_SWIPE_TO_ANSWER, disableSwipeToAnswer).apply()
var wasOverlaySnackbarConfirmed: Boolean
get() = prefs.getBoolean(WAS_OVERLAY_SNACKBAR_CONFIRMED, false)
set(wasOverlaySnackbarConfirmed) = prefs.edit().putBoolean(WAS_OVERLAY_SNACKBAR_CONFIRMED, wasOverlaySnackbarConfirmed).apply()
var dialpadVibration: Boolean
get() = prefs.getBoolean(DIALPAD_VIBRATION, true)
set(dialpadVibration) = prefs.edit().putBoolean(DIALPAD_VIBRATION, dialpadVibration).apply()
var hideDialpadNumbers: Boolean
get() = prefs.getBoolean(HIDE_DIALPAD_NUMBERS, false)
set(hideDialpadNumbers) = prefs.edit().putBoolean(HIDE_DIALPAD_NUMBERS, hideDialpadNumbers).apply()
var dialpadBeeps: Boolean
get() = prefs.getBoolean(DIALPAD_BEEPS, true)
set(dialpadBeeps) = prefs.edit().putBoolean(DIALPAD_BEEPS, dialpadBeeps).apply()
var alwaysShowFullscreen: Boolean
get() = prefs.getBoolean(ALWAYS_SHOW_FULLSCREEN, false)
set(alwaysShowFullscreen) = prefs.edit().putBoolean(ALWAYS_SHOW_FULLSCREEN, alwaysShowFullscreen).apply()
var viewType: Int
get() = prefs.getInt(VIEW_TYPE, VIEW_TYPE_LIST)
set(viewType) = prefs.edit().putInt(VIEW_TYPE, viewType).apply()
var gridLayoutSpanCount: Int
get() = prefs.getInt(GRID_LAYOUT_SPAN_COUNT, GRID_DEFAULT_SPAN_COUNT)
set(gridLayoutSpanCount) = prefs.edit().putInt(GRID_LAYOUT_SPAN_COUNT, gridLayoutSpanCount).apply()
}