SharedPreferenceHelper

Additional

Language
Kotlin
Version
2.0 (Jan 3, 2021)
Created
Dec 14, 2019
Updated
Jan 3, 2021
Owner
George Samir (georgesamirmansour)
Contributor
George Samir (georgesamirmansour)
1
Activity
Badge
Generate
Download
Source code

Advertising

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

object SharedPrefKey {
    lateinit var appName: EnumEntry
}

You can use any type of mode.

class BaseApp : Application() {

    override fun onCreate() {
        super.onCreate()
        PrefHelper.sharedPreferences = getSharedPreferences(SharedPrefKey.appName.name, Context.MODE_PRIVATE)
        PrefHelper().getIntFromShared(SharedPrefKey.appName)
    }
}

Example

   PrefHelper().getIntFromShared(SharedPrefKey.appName)

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