Skip to content

mirrajabi/kotlin-preferences-extensions

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
app
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

kotlin-preferences-extensions

A set of Rx Extensions to get/set values of SharedPreferences in a super simple way

Usage

First add jitpack to your projects build.gradle file

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

Then add the dependency in modules build.gradle file

dependencies {
    compile 'com.github.mirrajabi:kotlin-preferences-extensions:1.0.1'
}

Now initialize it in your application or activity etc...

override fun onCreate() {
        super.onCreate()
        KotlinPreferences.init(this)
        // Or with your custom preference name
        KotlinPreferences.init(this, "custom_pref")
    }

Then use these extensions on the key strings like below samples

Sample

companion object {
    val keyForString = "key_some_string"
}

keyForString.putString("Kotlin extensions")
            .subscribe()
            
"another_key".putBoolean(true)
             .subscribe({
                Log.v(packageName, "another key has been saved with $it value")
             })

keyForString.getString("No records for this key")
            .subscribe({ textView.text = it })
            
"another_key".getBoolean()
             .subscribe({
                Log.v(packageName, "Saved boolean value is $it")
             })

About

A set of RxJava2 Extensions to get/set values of SharedPreferences in a super simple way

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages