|
1 | 1 | # Android EasyPrefs |
2 | 2 |
|
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 deferent file name and mode. |
6 | | - |
7 | | -This library design like write, read and edit call with synchronous and asynchronous manner when you call synchronous API then behind `commit` operation to happen and when you do asynchronous operation behind happening to `apply` |
8 | | - |
9 | | -This library is developed in the Kotlin and supported to both language `Kotlin` as well as `Java` |
10 | | - |
11 | | -Default file name as like **`prefs_<package_name>`** and custom file name like **`prefs_<given_filename>`** there is no need to give file extension. |
12 | | - |
13 | | -## Installation |
14 | | -Gradle: |
15 | | - |
16 | | -```groovy |
17 | | -repositories { |
18 | | - maven { url 'https://jitpack.io' } |
19 | | -} |
20 | | -
|
21 | | -dependencies { |
22 | | - implementation 'com.github.kishandonga:EasyPrefs:1.0' |
23 | | -} |
24 | | -``` |
25 | | - |
26 | | -## Examples |
27 | | - |
28 | | -#### Refer This Sample Test Cases and for more information refer API Document Section |
29 | | -For, the more infromation refer this test case code [here](app/src/androidTest/java/com/sample/easyprefs) |
30 | | - |
31 | | -#### Initialize App |
32 | | - |
33 | | -`Prefs.initializeApp(context)` this line of code add into the main Application Class, as like this. |
34 | | - |
35 | | -```kotlin |
36 | | -class MainApp : Application() { |
37 | | - override fun onCreate() { |
38 | | - super.onCreate() |
39 | | - Prefs.initializeApp(this) |
40 | | - } |
41 | | -} |
42 | | -``` |
43 | | - |
44 | | -#### Write Operation |
45 | | - |
46 | | -```kotlin |
47 | | -Prefs.write().string("KEY", "VALUE") |
48 | | -Prefs.write().stringAsync("KEY", "VALUE") |
49 | | -``` |
50 | | - |
51 | | -```kotlin |
52 | | -Prefs.write(context).string("KEY", "VALUE") |
53 | | -Prefs.write(context).stringAsync("KEY", "VALUE") |
54 | | -``` |
55 | | - |
56 | | -```kotlin |
57 | | -Prefs.write(context, fileName).string("KEY", "VALUE") |
58 | | -Prefs.write(context, fileName).stringAsync("KEY", "VALUE") |
59 | | -``` |
60 | | - |
61 | | -#### Read Operation |
62 | | - |
63 | | -```kotlin |
64 | | -Prefs.read().string("KEY", "") |
65 | | -``` |
66 | | - |
67 | | -```kotlin |
68 | | -Prefs.read(context).string("KEY", "") |
69 | | -``` |
70 | | - |
71 | | -```kotlin |
72 | | -Prefs.read(context, fileName).string("KEY", "") |
73 | | -``` |
74 | | - |
75 | | -#### Edit Operation |
76 | | - |
77 | | -```kotlin |
78 | | -Prefs.edit().remove("KEY") |
79 | | -Prefs.edit().removeAsync("KEY") |
80 | | -``` |
81 | | - |
82 | | -```kotlin |
83 | | -Prefs.edit(context).remove("KEY") |
84 | | -Prefs.edit(context).removeAsync("KEY") |
85 | | -``` |
86 | | - |
87 | | -```kotlin |
88 | | -Prefs.edit(context, fileName).remove("KEY") |
89 | | -Prefs.edit(context, fileName).removeAsync("KEY") |
90 | | -``` |
91 | | - |
92 | | -If you pass context manully then no need to initialize lib on the application class, For, more information refer API Document section and [here](app/src/androidTest/java/com/sample/easyprefs) |
93 | | - |
94 | | -## API Document |
95 | | - |
96 | | -#### v1.0 |
97 | | - |
98 | | -> **Write Operations** |
99 | | -
|
100 | | -### **Prefs.** |
101 | | - |
102 | | -```kotlin |
103 | | -write() |
104 | | -write(fileName: String) |
105 | | -write(fileName: String, mode: Int) |
106 | | -write(context: Context) |
107 | | -write(context: Context, fileName: String) |
108 | | -write(context: Context, fileName: String, mode: Int) |
109 | | -``` |
110 | | -**•** |
111 | | -```kotlin |
112 | | -int(key: String, value: Int): Boolean |
113 | | -intAsync(key: String, value: Int) |
114 | | - |
115 | | -string(key: String, value: String): Boolean |
116 | | -stringAsync(key: String, value: String) |
117 | | - |
118 | | -long(key: String, value: Long): Boolean |
119 | | -longAsync(key: String, value: Long) |
120 | | - |
121 | | -float(key: String, value: Float): Boolean |
122 | | -floatAsync(key: String, value: Float) |
123 | | - |
124 | | -double(key: String, value: Double): Boolean |
125 | | -doubleAsync(key: String, value: Double) |
126 | | - |
127 | | -boolean(key: String, value: Boolean): Boolean |
128 | | -booleanAsync(key: String, value: Boolean) |
129 | | - |
130 | | -stringSet(key: String, value: Set<String>): Boolean |
131 | | -stringSetAsync(key: String, value: Set<String>) |
132 | | -``` |
133 | | ---- |
134 | | -> **Read Operations** |
135 | | -
|
136 | | -### **Prefs.** |
137 | | - |
138 | | -```kotlin |
139 | | -read() |
140 | | -read(fileName: String) |
141 | | -read(fileName: String, mode: Int) |
142 | | -read(context: Context) |
143 | | -read(context: Context, fileName: String) |
144 | | -read(context: Context, fileName: String, mode: Int) |
145 | | -``` |
146 | | -**•** |
147 | | -```kotlin |
148 | | -int(key: String, defaultValue: Int): Int |
149 | | -string(key: String, defaultValue: String): String |
150 | | -long(key: String, defaultValue: Long): Long |
151 | | -float(key: String, defaultValue: Float): Float |
152 | | -double(key: String, defaultValue: Double): Double |
153 | | -boolean(key: String, defaultValue: Boolean): Boolean |
154 | | -stringSet(key: String, defaultValue: Set<String>): Set<String> |
155 | | -``` |
156 | | ---- |
157 | | -> **Edit Operations** |
158 | | -
|
159 | | -### **Prefs.** |
160 | | - |
161 | | -```kotlin |
162 | | -edit() |
163 | | -edit(fileName: String) |
164 | | -edit(fileName: String, mode: Int) |
165 | | -edit(context: Context) |
166 | | -edit(context: Context, fileName: String) |
167 | | -edit(context: Context, fileName: String, mode: Int) |
168 | | -``` |
169 | | -**•** |
170 | | -```kotlin |
171 | | -clear(): Boolean |
172 | | -clearAsync() |
173 | | -remove(key: String): Boolean |
174 | | -removeAsync(key: String) |
175 | | -``` |
176 | | - |
177 | | -### About me |
178 | | - |
179 | | -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. |
| 3 | +Under Development |
0 commit comments