Skip to content

Simplify usage of Android Shared Prefrences in Kotlin :)

License

Notifications You must be signed in to change notification settings

HossainCo/PrefKot

Repository files navigation

Android PrefKot Library

License: MIT

pipeline status coverage report

Build Status Coverage Status

Github All Releases Download

Simplify usage of Android SharedPreferences in Kotlin by Delegates :)

How to use

Usage

/* if default is provided then there is no need to provide Type for function */
var pref by pref(
	pref = mySharedPreferences,
	key = "message", // key default value is Kotlin Property name's
	cache = true, // cache is true by default: if its off always get new values from SharedPreferences instance, else cache latest download
	default = "Hossain Khademian", // default can be a simple Value like "Hi" or Provider of its type like "Hossain Khademian"::toLower or { data.getSomthing() }, these providers use for lazy loading !!:)
)

// in class [Context | Activity | Application | View | Fragment]:
var pref1 by pref<String>()
var pref2 by pref(key= "State") { default: "Hello World!" }

// or use extensions
val pref3 by context.pref<Boolean>()


// use them as normal values
pref = "new Value"

val data = pref3
pref3 = false // Error

Gradle

// in root project
allprojects {
	repositories {
		// ...
		maven { url 'https://jitpack.io' }
	}
}
 
// in project
dependencies {
	compile 'com.github.hossainco:prefkot:0.1.3'
	// ...
}

License

MIT License
 
Copyright (c) 2017 HossainCo
 
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
 
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

Simplify usage of Android Shared Prefrences in Kotlin :)

Resources

License

Stars

Watchers

Forks

Packages

No packages published