|
1 | 1 | # Android EasyPrefs
|
2 | 2 |
|
3 |
| -Under Development |
| 3 | +[](https://jitpack.io/#kishandonga/EasyPrefs) |
| 4 | + |
| 5 | +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. |
| 6 | + |
| 7 | +It support all Primitive Data Type and String Set more api will be added soon. |
| 8 | + |
| 9 | +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. |
| 10 | + |
| 11 | +This library is developed in the Kotlin and supported both language `Kotlin` as well as `Java` with the same practices. |
| 12 | + |
| 13 | +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. |
| 14 | + |
| 15 | +## Installation |
| 16 | +Gradle: |
| 17 | + |
| 18 | +```groovy |
| 19 | +repositories { |
| 20 | + maven { url 'https://jitpack.io' } |
| 21 | +} |
| 22 | +
|
| 23 | +dependencies { |
| 24 | + implementation 'com.github.kishandonga:EasyPrefs:1.1' |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +## Examples |
| 29 | + |
| 30 | +Refer [This](app/src/androidTest/java/com/sample/easyprefs/suite) Sample Test Suite in the suite package |
| 31 | +For, the more information refer this test case code [here](app/src/androidTest/java/com/sample/easyprefs) |
| 32 | + |
| 33 | +#### Initialize App |
| 34 | + |
| 35 | +`Prefs.initializeApp(context)` this line of code add into the main Application Class, as like this. |
| 36 | + |
| 37 | +```kotlin |
| 38 | +class MainApp : Application() { |
| 39 | + override fun onCreate() { |
| 40 | + super.onCreate() |
| 41 | + Prefs.initializeApp(this) |
| 42 | + } |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +#### Write Operation |
| 47 | + |
| 48 | +```kotlin |
| 49 | +Prefs.write().content("KEY", "VALUE") |
| 50 | + .content("KEY", "VALUE") |
| 51 | + .commit() or .apply() |
| 52 | +``` |
| 53 | + |
| 54 | +```kotlin |
| 55 | +Prefs.write(fileName) |
| 56 | + .content("KEY", "VALUE") |
| 57 | + .content("KEY", "VALUE") |
| 58 | + .commit() or .apply() |
| 59 | +``` |
| 60 | + |
| 61 | +```kotlin |
| 62 | +Prefs.write(context) |
| 63 | + .content("KEY", "VALUE") |
| 64 | + .content("KEY", "VALUE") |
| 65 | + .commit() or .apply() |
| 66 | +``` |
| 67 | + |
| 68 | +```kotlin |
| 69 | +Prefs.write(context, fileName) |
| 70 | + .content("KEY", "VALUE") |
| 71 | + .content("KEY", "VALUE") |
| 72 | + .commit() or .apply() |
| 73 | +``` |
| 74 | + |
| 75 | +#### Read Operation |
| 76 | + |
| 77 | +```kotlin |
| 78 | +Prefs.read().content("KEY", "") |
| 79 | +Prefs.read(fileName).content("KEY", "") |
| 80 | +Prefs.read(context).content("KEY", "") |
| 81 | +Prefs.read(context, fileName).content("KEY", "") |
| 82 | +``` |
| 83 | + |
| 84 | +#### Secure Operation |
| 85 | + |
| 86 | +```kotlin |
| 87 | +Prefs.securely().write() |
| 88 | + .content("KEY", "VALUE") |
| 89 | + .content("KEY", "VALUE") |
| 90 | + .commit() or .apply() |
| 91 | + |
| 92 | +Prefs.securely().read().content("KEY", "") |
| 93 | +``` |
| 94 | + |
| 95 | +#### Has Operation |
| 96 | + |
| 97 | +```kotlin |
| 98 | +Prefs.has().key("KEY"); |
| 99 | +Prefs.has(fileName).key("KEY"); |
| 100 | +Prefs.has(context).key("KEY"); |
| 101 | +Prefs.has(context, fileName).key("KEY"); |
| 102 | +``` |
| 103 | +- Give boolean value if key exists then true elase false. |
| 104 | + |
| 105 | +#### Remove Operation |
| 106 | + |
| 107 | +```kotlin |
| 108 | +Prefs.remove().key("KEY"). |
| 109 | +Prefs.remove(fileName).key("KEY"). |
| 110 | +Prefs.remove(context).key("KEY"). |
| 111 | +Prefs.remove(context, fileName).key("KEY"). |
| 112 | + |
| 113 | +commit() or .apply() |
| 114 | +``` |
| 115 | +- After the remove operation commit and apply call mandatory. |
| 116 | + |
| 117 | +#### Clear Operation |
| 118 | + |
| 119 | +```kotlin |
| 120 | +Prefs.clear().all(). |
| 121 | +Prefs.clear(fileName).all(). |
| 122 | +Prefs.clear(context).all(). |
| 123 | +Prefs.clear(context, fileName).all(). |
| 124 | + |
| 125 | +.commit() or .apply() |
| 126 | +``` |
| 127 | +- After the clear operation commit and apply call mandatory. |
| 128 | + |
| 129 | +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. |
| 130 | + |
| 131 | +If you pass context manually then no need to initialize lib on the application class, For, more information refer [here](app/src/androidTest/java/com/sample/easyprefs) |
| 132 | + |
| 133 | +## Future Scope |
| 134 | +- has and remove support provided to secure operations. |
| 135 | +- add sorting on the Set so get direct sorted data. |
| 136 | +- to make life easier adding more api in near future |
| 137 | +- callback extend as we already have in the preferences. |
| 138 | + |
| 139 | +--- |
| 140 | + |
| 141 | +### Contributing |
| 142 | + |
| 143 | +Contributions are welcome! If you find a bug please report it and if you want add new feature then please suggest to me. If you want to contribute code please file an issue and create a branch off of the current dev branch and post a pull request. |
| 144 | + |
| 145 | +### About me |
| 146 | + |
| 147 | +I'm Kishan Donga and you can connect with me via twitter [@ikishan92](https://twitter.com/ikishan92) and instagram [@ikishan92](https://www.instagram.com/ikishan92/), I am a mobility developer and I love to do some innovation. |
| 148 | + |
| 149 | +### License |
| 150 | + |
| 151 | +[EasyPrefs](https://github.com/kishandonga/EasyPrefs) is released under the [MIT License](https://github.com/kishandonga/EasyPrefs/blob/master/LICENSE.md). |
0 commit comments