Skip to content

Commit d98a401

Browse files
authored
LIB-17: Add readme (#5)
* add readme * fix some formatting * more formatting * more language fixes * add license.txt
1 parent 021584a commit d98a401

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Simply Made Apps
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# PreferenceHelper
2+
A more painless way to set/get with SharedPreferences.
3+
# Getting Started
4+
Add it in your root build.gradle at the end of repositories:
5+
```groovy
6+
allprojects {
7+
repositories {
8+
maven { url 'https://jitpack.io' }
9+
}
10+
}
11+
```
12+
Add the following to the dependencies section of app/build.gradle (check Releases for the latest version):
13+
```
14+
implementation 'com.github.simplymadeapps:PreferenceHelper:1.1.1'
15+
```
16+
17+
# Usage
18+
Init the library in the `Application.onCreate()` method. You can also put this at that top of your start activity's `onCreate()`. All that matters is `init()` is called before any other calls to the PreferenceHelper.
19+
```java
20+
public class MyApplication extends Application {
21+
@Override
22+
public void onCreate() {
23+
super.onCreate();
24+
PreferenceHelper.init(this);
25+
}
26+
}
27+
```
28+
Now that the library has been initialized, you can easily use `put()` and `get()`.
29+
30+
Storing an object:
31+
```
32+
PreferenceHelper.put("current_user_name", "John Doe");
33+
```
34+
35+
Getting an object:
36+
```
37+
String username = PreferenceHelper.get("current_user_name", "No Name");
38+
```
39+
40+
The library is using the object type of the input or fallback to determine what SharedPreference method to use (ex, putString, putLong, putInt, etc).
41+
This can cause confusion when you pass in a null object as one of these parameters. If you need to store a null object or retrieve an object with a null fallback you should pass in that object type.
42+
43+
Storing a null string:
44+
```
45+
PreferenceHelper.put("current_user_name", null, String.class);
46+
```
47+
48+
Getting a set with a null fallback:
49+
```
50+
Set<String> usernames = PreferenceHelper.get("all_names", null, Set.class);
51+
```
52+
Note that primitive types (int, boolean, float, long) cannot be null.
53+
54+
55+
You can also check if a value has been stored with:
56+
```
57+
boolean key_exists = PreferenceHelper.contains("some_key");
58+
```
59+
60+
The library can only store what the default SharedPreferences stores (String, int, boolean, float, long, Set<String>). It currently does not support storing of a custom objects. This may be expanded upon in the future.
61+
62+
# Contributing
63+
1. Fork it
64+
2. Create your feature branch (`git checkout -b my-new-feature`)
65+
3. Commit your changes (`git commit -am 'Add some feature'`)
66+
4. Push to the branch (`git push origin my-new-feature`)
67+
5. Create new Pull Request
68+
69+
# License
70+
The library is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).

0 commit comments

Comments
 (0)