wu4321 / SharedPreferenceHelper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Shared Preference helper libaray

Easy libaray to manage stored data in shared prefreance. will simple lines of code. no need to add new helper class to use it.

Leatest version

Download

Gradle

   implementation 'com.github.georgesamirmansour:SharedPrefHelper:1.x'

or Maven:

<dependency>
  <groupId>com.github.georgesamirmansour</groupId>
  <artifactId>SharedPrefHelper</artifactId>
  <version>1.x</version>
</dependency>

In order to use it. you need to make class implement InspectableProperty.EnumEntry. You can preview sample inside sample package. Preview of class below

public enum SharedPrefKeys implements InspectableProperty.EnumEntry {
    userId, sharedName;

    @Override
    public int value() {
        return 0;
    }

    @Override
    public Class<? extends Annotation> annotationType() {
        return null;
    }
}

You can use any type of mode.

public class BaseApplication extends Application {
 

	@Override
    	public void onCreate() {
        super.onCreate();
        PrefHelper.setSharedPreferences(getApplicationContext(), SharedPrefKeys.sharedName,
                Context.MODE_PRIVATE);
    	}

}

Example

 	new PrefHelper().setStringToShared(SharedPrefKeys.userId, "value");

Methods are

set value to shared

	setIntToShared(enumKey, int value)
	setStringToShared (enumKey, String value) 
	setBooleanToShared(enumKey, boolean value)
	setStringSetToShared(enumKey, Set<String> value) 
	setFloatToShared(enumKey, float value) 
	setLongToShared(enumKey, long value)

get value from shared

	getIntFromShared(enumKey) // default value is 0
	getStringFromShared(enumKey) // default value is ""
	getBoolFromShared(enumKey) // default value is false
	getStringSetFromShared(enumKey) // default value is an empty set of string
	getFloatFromShared(enumKey) // default value is 0.0f
	getLongFromShared(enumKey) // default value is 0

check if exist or not

	contain(enumKey) \\ return boolean

remove from shared

	remove(enumKey)

clear all shared

	clear()

License

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

About


Languages

Language:Java 100.0%