From 43bcfe52a48f93313716bae0e12443c51625a74e Mon Sep 17 00:00:00 2001 From: Andrea Cioccarelli Date: Thu, 17 Sep 2020 01:40:11 +0200 Subject: [PATCH 1/4] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b427658..32da2dc 100755 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@

KsPrefs

-

Simplify SharedPreferences. 100% Kotlin.

+

SharedPreferences. 100% Kotlin.

Download from Bintray CircleCI @@ -149,7 +149,7 @@ Here is a table representing when values are saved to the storage, depending on The best (and default) practise while dealing with SharedPreferences is to use `APPLY`. It is asynchronous and fast. `COMMIT` is also available, though it should not be used unless you have a valid reason to, given its synchronous and strict nature, as well as `NONE`, for no-op (Does not save anything, used internally for `queue()`).
`save()` and `push()` always refer to the commit strategy to decide how to save their updates to the persistent XML preference storage. -Here is a table representing various features of different commit strategies. See ![this](https://stackoverflow.com/questions/5960678/whats-the-difference-between-commit-and-apply-in-sharedpreferences) for more information. +Here is a table representing various features of different commit strategies. Check out the official documentation [here](https://developer.android.com/reference/android/content/SharedPreferences.Editor.html) and see [this](https://stackoverflow.com/questions/5960678/whats-the-difference-between-commit-and-apply-in-sharedpreferences) post for more intel. | `CommitStrategy` | APPLY | COMMIT | NONE | |--------|--------------------|--------------------|------| From 56ad17cee84c5e4d45fe22fc9f69d1f09b869d91 Mon Sep 17 00:00:00 2001 From: Andrea Cioccarelli Date: Thu, 17 Sep 2020 14:35:02 +0200 Subject: [PATCH 2/4] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 32da2dc..1113188 100755 --- a/README.md +++ b/README.md @@ -168,7 +168,9 @@ Not writing the changes to the file makes enqueuing a valid choice for both batc - `queue()` takes a key and a value, and saves the changes in-memory.
- `queue()` does not actually send updates to the storage. You can do so by calling `save()` (Or by using `push()` subsequently).

-This segment touches a broader concept, which is storing scope. There are two storing scopes for SharedPreferences: + +This segment touches a broader concept, which is storing scope. +There are two storing scopes for SharedPreferences: - in-memory (key-value pairs are kept in memory). This is fast to read to/write from, but does not persist application restarts. - XML (key-value pairs are kept on a file). Writing to a file is mildly expensive but it allows preferences to survive across application restarts.
Here is a table explaining how different methods inside KsPrefs touch and go through those storing scopes. From 960c63ba204ebe92d37bbacf38239f98e4397315 Mon Sep 17 00:00:00 2001 From: Andrea Cioccarelli Date: Thu, 1 Oct 2020 00:20:21 +0200 Subject: [PATCH 3/4] Updated version name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1113188..9c7c6f2 100755 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ ### TLDR ```gradle -implementation 'com.cioccarellia:ksprefs:2.2.0' +implementation 'com.cioccarellia:ksprefs:2.2.1' ``` - :zap: Powerful SharedPreferences wrapper. From ddeaec84ac9d125e097146c52b672e5eb74c2e47 Mon Sep 17 00:00:00 2001 From: Andrea Cioccarelli Date: Thu, 1 Oct 2020 08:39:03 +0200 Subject: [PATCH 4/4] Updated docs for `PrefsCenter` --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9c7c6f2..a1955a5 100755 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ implementation 'com.cioccarellia:ksprefs:2.2.1' ``` -- :zap: Powerful SharedPreferences wrapper. +- :zap: Powerful SharedPreferences wrapper & API. - :rocket: Easy to pick up & use right away for any project. - :gear: Fully customizable behaviour. - :lock: Built-in cryptography (PlainText, Base64, AES CBC, AES ECB, Android KeyStore + AES GCM / + RSA). @@ -216,3 +216,17 @@ val accentColor by prefs.dynamic("accent_color", "#2106F3") When you set a value for this property, it is also updated on the XML preference file, as it is a dynamic reference to the preference. +## API +KsPrefs provides some customizable data structures, to abstract preference reads/writes even further. + +### Preferences Center +A `PrefsCenter` is an extremely simple and straightforward class. It is used to enclose and contain all the SharedPreferences-specific operations, like providing a key, doing some value specific post-read/pre-write operation, providing the fallback value or the return type. + +```kotlin +object StartCounterPrefCenter : PrefsCenter(App.prefs) { + private const val counterKey = "start_counter" + + fun increment() = prefs.push(counterKey, read() + 1) + fun read() = prefs.pull(counterKey, 0) +} +```