SimpleKeyValueStorage
A simple Shared preference wrapper to store POJO objects in Android, serialized with gson.
Library Objectives
Tired of having to manually serialize/unserialize objects content into shared preferences this library uses gson to automate object serialization and make painless object storage into shared preferences. Objects are stored json encoded.
Installation
Grab via Gradle:
compile 'com.quinientoscuarenta:simplekeyvaluestorage:1.0.1'
or Maven:
<dependency>
<groupId>com.quinientoscuarenta</groupId>
<artifactId>simplekeyvaluestorage</artifactId>
<version>1.0.1</version>
</dependency>
Usage
Initialize:
You can initialize it with default name 'skvs_default_prefs'
SimpleKeyValueStorage.initDefault(context);
Or with custom name
SimpleKeyValueStorage.builder().withName('custom_name').init(context);
You will have to provide a context, it can be application or activity context.
Use:
Set method accepts any type such as list, object, primitive...
Locale locale = Locale.ENGLISH;
simpleKeyValueStorage.set("key", locale);
Get or get list and specify the content type to retrieve the saved value
Locale savedLocale = simpleKeyValueStorage.get("key", Locale.class);
List<String> savedStrings = simpleKeyValueStorage.getList("key", String[].class);
Delete value
simpleKeyValueStorage.delete("key");
Check data availability
boolean available = simpleKeyValueStorage.isSet("key");
Clear all storage
simpleKeyValueStorage.clear();
Proguard
#Gson
-keep class com.google.gson.** { *; }
-keepattributes Signature
License
Copyright 2015 Gorka Moreno Asín 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.