EasyPrefs

General

Category
Free
Tag
Preferences
License
MIT License
Min SDK
16 (Android 4.1 Jelly Bean)
Registered
Sep 30, 2020
Favorites
0
Link
https://github.com/kishandonga/EasyPrefs
See also
armadillo
PrefPin
Remember
ColorPrefUtil
Preffy

Additional

Language
Kotlin
Version
1.1 (Sep 13, 2020)
Created
Jul 5, 2020
Updated
Sep 29, 2020
Owner
Kishan Donga (kishandonga)
Contributor
Kishan Donga (kishandonga)
1
Activity
Badge
Generate
Download
Source code

Blurb

Android EasyPrefs

  

EasyPrefs is library for the android SharedPreferences or we can say it wrapper on it. It is provided easy access to the SharedPreferences API, also it will need only one-time initialization and used in the whole project without context also facility to provide context if necessary with support encryption and decryption.

It support all Primitive Data Type and String Set more api will be added soon.

For, the secure operation used AES encryption <= 20 API Level, and for 21 >= used android provided encrypted shared preferences in both case you got same output your key and value both are stored securly.

This library is developed in the Kotlin and supported both language Kotlin as well as Java with the same practices.

Default file name is prefs_<package_name> and custom file name like prefs_<given_filename> there is no need to give file extension. it is automatically append at the end of the name.

Installation

Gradle:

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.github.kishandonga:EasyPrefs:1.1'
}

Examples

Refer This Sample Test Suite in the suite package For, the more information refer this test case code here

Initialize App

Prefs.initializeApp(context) this line of code add into the main Application Class, as like this.

class MainApp : Application() {
    override fun onCreate() {
        super.onCreate()
        Prefs.initializeApp(this)
    }
}

Write Operation

Prefs.write().content("KEY", "VALUE")
      .content("KEY", "VALUE")
      .commit() or .apply()
Prefs.write(fileName)
             .content("KEY", "VALUE")
      .content("KEY", "VALUE")
      .commit() or .apply()
Prefs.write(context)
             .content("KEY", "VALUE")
             .content("KEY", "VALUE")
             .commit() or .apply()
Prefs.write(context, fileName)
             .content("KEY", "VALUE")
             .content("KEY", "VALUE")
             .commit() or .apply()

Read Operation

Prefs.read().content("KEY", "")
Prefs.read(fileName).content("KEY", "")
Prefs.read(context).content("KEY", "")
Prefs.read(context, fileName).content("KEY", "")

Secure Operation

Prefs.securely().write()
             .content("KEY", "VALUE")
             .content("KEY", "VALUE")
             .commit() or .apply()

Prefs.securely().read().content("KEY",  "")

Has Operation

Prefs.has().key("KEY");
Prefs.has(fileName).key("KEY");
Prefs.has(context).key("KEY");
Prefs.has(context, fileName).key("KEY");
  • Give boolean value if key exists then true else false.

Remove Operation

Prefs.remove().key("KEY").
Prefs.remove(fileName).key("KEY").
Prefs.remove(context).key("KEY").
Prefs.remove(context, fileName).key("KEY").

commit() or .apply()
  • After the remove operation commit and apply call mandatory.

Clear Operation

Prefs.clear().all().
Prefs.clear(fileName).all().
Prefs.clear(context).all().
Prefs.clear(context, fileName).all().

.commit() or .apply()
  • After the clear operation commit and apply call mandatory.

For, all the read, write, clear, has, remove support context and file name manually so you can used your preferences with multiple files with the same api use just need to change file name when you call.

If you pass context manually then no need to initialize lib on the application class, For, more information refer here

Future Scope

  • has and remove support provided to secure operations.
  • add sorting on the Set so get direct sorted data.
  • to make life easier adding more api in near future
  • callback extend as we already have in the preferences.