islamdidarmd / Kpref

A class that saves time of writing boilerplate code for saving any kind of data in shared preferences

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Kpref

A class that saves time of writing boilerplate code for saving any kind of data in shared preferences

Installation (with Gradle)

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

   allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Step 2. Add the dependency

dependencies {
		implementation 'com.github.islamdidarmd:Kpref:0.1.1'
	}

How to use

                //save values in a default sharedPreference
                Kprefs.initDefault(this)

                Kprefs.save("test", 10)

                val x: Int? = Kprefs.get("")


                //save values in your preference
                val pref = getSharedPreferences("my_preference", Context.MODE_PRIVATE)
                Kprefs.init(pref)

                Kprefs.save("testMyPref", "Saved")

                val value: String? = Kprefs.get("")

You must call Kprefs.initDefault(this) or Kprefs.init(pref) before calling any methods For a complete example, see the sample app

About

A class that saves time of writing boilerplate code for saving any kind of data in shared preferences

License:MIT License


Languages

Language:Kotlin 72.6%Language:Java 27.4%