package com.ray650128.floatingwindow.utils

import android.content.Context
import com.ray650128.floatingwindow.MyApp
import com.ray650128.floatingwindow.R

/**
 * Shared Preferences 工具類別
 * @author Raymond Yang
 */
object PreferenceUtil {
    private const val MAIN_KEY = "PcReDiveClanBattleFrameTool"
    private const val X_AXIS_OFFSET = "X_AXIS_OFFSET"
    private const val Y_AXIS_OFFSET = "Y_AXIS_OFFSET"
    private const val GRAVITY = "GRAVITY"
    private const val ICON = "ICON"
    private const val ICON_PATH = "ICON_PATH"

    private val sharedPreferences = MyApp.appContext.getSharedPreferences(MAIN_KEY, Context.MODE_PRIVATE)

    var xOffset: Int
        get() = sharedPreferences.getInt(X_AXIS_OFFSET, 0)
        set(value) = sharedPreferences.edit().putInt(X_AXIS_OFFSET, value).apply()

    var yOffset: Int
        get() = sharedPreferences.getInt(Y_AXIS_OFFSET, 0)
        set(value) = sharedPreferences.edit().putInt(Y_AXIS_OFFSET, value).apply()

    var gravity: Int
        get() = sharedPreferences.getInt(GRAVITY, 0)
        set(value) = sharedPreferences.edit().putInt(GRAVITY, value).apply()

    var icon: Int
        get() = sharedPreferences.getInt(ICON, R.drawable.ic_chicken)
        set(value) = sharedPreferences.edit().putInt(ICON, value).apply()

    var iconPath: String?
        get() = sharedPreferences.getString(ICON_PATH, "")
        set(value) = sharedPreferences.edit().putString(ICON_PATH, value).apply()
}