SP

Project Url: z-zghiba/SP
Introduction: Simple way to manage SharedPreferences for Android
More: Author   ReportBugs   
Tags:

Simple way to manage SharedPreferences for Android whith kotlin

Usage

Init Preference

@CorePreference(fileName = "SP_Z")
open class App  : Application(){

    override fun onCreate() {
        super.onCreate()
        Preference.init(this)
    }
}

Create an enum class which contains the attributes to manage like this :

enum class SP  constructor(private val type: Type) {
    //create attributes with their type
    ENV(Type.STRING),
    IS_GOOD(Type.BOOLEAN),
    AGE(Type.INTEGER),
    FLOAT_VALUE(Type.FLOAT),
    ID(Type.LONG);

    fun put(value: Any) {
        Preference.put(this.name, type, value)
    }

    fun  get(): Any? {
        return Preference[this.name, type]
    }

    companion object{
        fun clearAll (){
            Preference.clear()
        }
    }
}
Apps
About Me
GitHub: Trinea
Facebook: Dev Tools