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