Dolly for SharedPreferences

Additional

Language
Java
Version
1.0.0 (Nov 10, 2020)
Created
Nov 10, 2020
Updated
Nov 10, 2020
Owner
Amit kremer (Amit7474)
Contributor
amit-kremer93
1
Activity
Badge
Generate
Download
Source code

Show card


Dolly for SharedPreferences

Dolly is a library that combines 2 types of sharedPreferences in one place:SharedPreferences - Regular sharedPreferences EncryptedSharedPreferences - AES256 encrypted key:value SharedPreferences



Dolly implements the logic for you, you just need to use it.

Download

Requirement

minSdkVersion 23

Repository

Add this in your root build.gradle file (not your module build.gradle file):

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

Dependency

Add this to your module's build.gradle file (Note: version should match the jitpack badge above)

dependencies {
 implementation 'com.github.Amit7474:Dolly-SharedPreferences:1.0.0'
}

Usage

Get the instance of Dolly:

Dolly dolly = Dolly.getInstance(context);

Start use Dolly:

dolly.getInt("age", 20, Type.ENCRYPT);

API

putInt(key, value, type)

store Int values.

dolly.putInt("Age", 23, Type.ENCRYPT);
dolly.putInt("Age", 20, Type.NOT_ENCRYPT);

getInt(key, defaultValue, type)

get Int values. defaultValue is optional! in case that its not supplied and the key is missing will return -1


dolly.getInt("Age", 5, Type.ENCRYPT);
dolly.getInt("Age", Type.NOT_ENCRYPT);

putBoolean(key, value, type)

store boolean values.

dolly.putBoolean("isSingle", true, Type.ENCRYPT);
dolly.putBoolean("isSingle", true, Type.NOT_ENCRYPT);

getBoolean(key, defaultValue, type)

get Boolean values. defaultValue is optional! in case that its not supplied and the key is missing will return false


dolly.getBoolean("isSingle", Type.ENCRYPT);
dolly.getBoolean("isSingle", true, Type.NOT_ENCRYPT);

putFloat(key, value, type)

store float values.

dolly.putFloat("hight", 6, Type.ENCRYPT);
dolly.putFloat("hight", 8, Type.NOT_ENCRYPT);

getFloat(key, defaultValue, type)

get float values. defaultValue is optional! in case that its not supplied and the key is missing will return -1


dolly.getFloat("hight", 50, Type.ENCRYPT);
dolly.getFloat("hight", Type.NOT_ENCRYPT);

putLong(key, value, type)

store long values.

dolly.putLong("hight", 6, Type.ENCRYPT);
dolly.putLong("hight", 8, Type.NOT_ENCRYPT);

getLong(key, defaultValue, type)

get long values. defaultValue is optional! in case that its not supplied and the key is missing will return -1


dolly.getLong("hight", 50, Type.ENCRYPT);
dolly.getLong("hight", Type.NOT_ENCRYPT);

putDouble(key, value, type)

store double values.

dolly.putDouble("length", 6.5, Type.ENCRYPT);
dolly.putDouble("hight",10.0, Type.NOT_ENCRYPT);

getDouble(key, defaultValue, type)

get double values. defaultValue is optional! in case that its not supplied and the key is missing will return -1


dolly.getDouble("hight", 50, Type.ENCRYPT);
dolly.getDouble("hight", Type.NOT_ENCRYPT);

putString(key, value, type)

store string values.

dolly.putString("name", "Dani", Type.ENCRYPT);
dolly.putString("name","Dani", Type.NOT_ENCRYPT);

getString(key, defaultValue, type)

get string values. defaultValue is optional! in case that its not supplied and the key is missing will return "null"


dolly.getString("hight", "null", Type.ENCRYPT);
dolly.getString("hight", Type.NOT_ENCRYPT);

putStringSet(key, value, type)

store string set values.

Set<String> set = new Set();
dolly.putStringSet("set", set, Type.ENCRYPT);
dolly.putStringSet("set",set, Type.NOT_ENCRYPT);

getStringSet(key, defaultValue, type)

get string values. defaultValue is optional! in case that its not supplied and the key is missing will return null


dolly.getStringSet("set", null, Type.ENCRYPT);
dolly.getStringSet("set", Type.NOT_ENCRYPT);

putJsonObject(key, value, type)

store JSONObject values.

JSONObject obj = new JSONObject;
obj.put("name", "Dani");
dolly.putJsonObject("json", obj, Type.ENCRYPT);
dolly.putJsonObject("json",obj, Type.NOT_ENCRYPT);

getJsonObject(key, defaultValue, type)

get JSONObject values. defaultValue is optional! in case that its not supplied and the key is missing will return null


dolly.getJsonObject("json", null, Type.ENCRYPT);
dolly.getJsonObject("json", Type.NOT_ENCRYPT);

remove(key, type)

use this to remove a key:value pair from storage. It will remove ONLY from the storage that you specify! (ENCRYPT/NPT_ENCRYPT)

dolly.remove("name", Type.ENCRYPT);

contains(key)

checks if a key is already stored in storage (BOTH encrypt/not encrypt) .

dolly.contains("json");

removeAll()

Clears the entire storage (BOTH encrypt/not encrypt) .

dolly.removeAll();

License

Copyright (C) 2020, Amit kremer

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.