/rocket

Easy Shared Preferences for Android with Kotlin Coroutines support

Primary LanguageKotlinApache License 2.0Apache-2.0

Rocket 🚀 🚀 🚀

A SharedPreferences library for Android , to speed up development

Download

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

implementation 'com.github.stavro96:Rocket:1.3.0'

Usage

Note: New version of Rocket now works only with coroutine support therefore you must include suspend implementation and run it inside a CoroutineScope. Example:

suspend fun writeData(data: String){
 rocketInstance.writeString(DATA_KEY, data)
}

When launching the method inside a coroutine there is no need to specify the Dispatchers.IO dispatcher. It's handled by the library.

Just call the rocket instance like :

private val rocket = Rocket.launch(mContext, SHARED_PREFERENCES_FILE_NAME , Context.MODE_PRIVATE)

Saving a value :

rocket.writeString(YOUR_DESIRED_KEY_NAME , YOUR_DESIRED_VALUE)

Reading a value :

rocket.readString(YOUR_DESIRED_KEY_NAME , YOUR_DESIRED_VALUE)

Deleting all saved SharedPreferences :

rocket.crash()

Deleting one particular value :

rocket.drop(YOUR_DESIRED_KEY)

Note : The Mode is by default Context.MODE_PRIVATE , if you want to specify different mode , apply it as a third parameter in the launch() method

Extension functions:

SOME_INT_KEY.isDefaultInt(rocketInstance)

Licence

Copyright 2019 stavro96.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.