All Projects → Pulimet → Shpref Library

Pulimet / Shpref Library

💾 Android Kotlin library. Shared preferences wrapper. (2020)

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Shpref Library

Ksprefs
🚀⚡ Kotlin SharedPreferences wrapper & cryptographic preferences android library.
Stars: ✭ 176 (+1000%)
Mutual labels:  library, sharedpreferences
Kau
An extensive collection of Kotlin Android Utils
Stars: ✭ 182 (+1037.5%)
Mutual labels:  library, sharedpreferences
Frideos flutter
An all-in-one Fllutter package for state management, reactive objects, animations, effects, timed widgets etc.
Stars: ✭ 187 (+1068.75%)
Mutual labels:  library, sharedpreferences
Slim.js
Fast & Robust Front-End Micro-framework based on modern standards
Stars: ✭ 789 (+4831.25%)
Mutual labels:  library
Vlany
Linux LD_PRELOAD rootkit (x86 and x86_64 architectures)
Stars: ✭ 804 (+4925%)
Mutual labels:  library
Experiment
🔬 Elixir Library for carefully refactoring critical paths by performing experiments.
Stars: ✭ 6 (-62.5%)
Mutual labels:  library
Matter
Material Design Components in Pure CSS. Materializing HTML at just one class per component 🍰
Stars: ✭ 888 (+5450%)
Mutual labels:  library
Etl
Embedded Template Library
Stars: ✭ 783 (+4793.75%)
Mutual labels:  library
Greedo Layout For Ios
Full aspect ratio grid layout for iOS
Stars: ✭ 837 (+5131.25%)
Mutual labels:  library
Rulerz
Powerful implementation of the Specification pattern in PHP
Stars: ✭ 827 (+5068.75%)
Mutual labels:  library
Cup
CUP, common useful python-lib. (Currently, Most popular python lib in baidu)
Stars: ✭ 826 (+5062.5%)
Mutual labels:  library
Morph Bottom Navigation
This library represents a Bottom Navigation with an awesome morph effect on top of the selected item
Stars: ✭ 803 (+4918.75%)
Mutual labels:  library
System.js
The library System.js designed to improve the quality of writing JavaScript source code. It contains features that allow you refactor source code. Thanks to the clear and readable functions, the code will be good understood and supported accordingly.
Stars: ✭ 6 (-62.5%)
Mutual labels:  library
M3u8
Parser and generator of M3U8-playlists for Apple HLS. Library for Go language. 🎦
Stars: ✭ 800 (+4900%)
Mutual labels:  library
Realm Core
Core database component for the Realm Mobile Database SDKs
Stars: ✭ 836 (+5125%)
Mutual labels:  library
Yasumi
The easy PHP Library for calculating holidays
Stars: ✭ 788 (+4825%)
Mutual labels:  library
Arma3launcherlib
Simple .NET library containing everything needed for a custom Arma 3 launcher.
Stars: ✭ 7 (-56.25%)
Mutual labels:  library
Devtools
The Hoa\Devtools library.
Stars: ✭ 5 (-68.75%)
Mutual labels:  library
Zlib Ng
zlib replacement with optimizations for "next generation" systems.
Stars: ✭ 807 (+4943.75%)
Mutual labels:  library
Tfidf
Simple TF IDF Library
Stars: ✭ 6 (-62.5%)
Mutual labels:  library

Download Android Arsenal License

ShPref-Library

Simplifies the interaction with Shared Preferences on Android. (Bonus: Logger)

Installation

  • Add the dependency from jCenter to your app's (not project) build.gradle file:
repositories {
    jcenter()
}

dependencies {
    implementation 'net.alexandroid.utils:shpref:1.7' // Java version
    implementation 'net.alexandroid.utils:shprefkt:1.7' // Kotlin version
}
  • Add init line in your application class as shown below:
public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        ShPref.init(this, ShPref.APPLY); // Java

        ShPrefKt shpref = ShPrefKt(this); // Kotlin
    }
}
  • Also don't forget to add: android:name=".MyApplication" at your application tag in AndroidManifest.xml
 <application
        android:name=".MyApplication"
        ...>

Release notes

  • 1.7 - Android X migration + versions update + Added Kotlin version
  • 1.6 - Logger separated (https://github.com/Pulimet/MyLogLibrary), appcompat dependency removed
  • 1.5 - Logger methods for visual customization
  • 1.4 - Added remove method to Editor
  • 1.3 - Tests and bug fixes
  • 1.2 - Save doubles support. Put null as a value bugfix. Logs are removed. Added contains and clear methods. New bonus Contextor and Logger classes. Chainning by using Editor. Ability to get values without default value.
  • 1.1 - JavaDoc, readme file, bug fixes

How to use it

On initialization (at yours application class) you should pass default saving mode as a second argument. As you know, there are two options to save: APPLY (faster and asynchronous) or COMMIT.

With ShPref library you can use following types: String, int, boolean, float, double, long and lists with that types.

  • Put:

// Save using a resource as a key
ShPref.put(R.string.some_key, "Sample text");

// Save using a hard coded string
ShPref.put("HardCodedKey", 25);

// Option to chain using Editor class
new ShPref.Editor()
    .put("key1", "key1value")
    .put("key2", "key2value")
    .put("key3", "key3value")
    .commit();

// Saving a List
ArrayList<Integer> list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
    list.add(i);
}
ShPref.putList("myListKey", list);    



  • Get:

// Get a value and if it not exist get a default value that was passed as a second argument
String myString = ShPref.getString(R.string.some_key, "Default value");
int myInt= ShPref.getInt("HardCodedKey", 0); // 0 is default value

// Get values without to set default values (if not exist: getString return null, getBoolena return false and other 0)
String myString = ShPref.getString(R.string.some_key);
int myInt= ShPref.getInt("HardCodedKey"); 

// Get value as an object
Object obj = ShPref.get(R.string_some_key); //excluding double

// Get a list
 List<Integer> list = ShPref.getListOfIntegers("myListKey");



  • Contains:

// Checking for existence
boolean isContains = ShPref.contains(R.string.key_key);



  • Remove:

ShPref.remove(R.string.key_key);
ShPref.remove("HardCodedKey");



  • Clear:

// Remove all values from the preferences.
ShPref.clear();



  • Mode forcing methods:
    For example if you have choosen as default APPLY mode and you need to save or remove something using COMMIT there are special methods for that case:
putC(); removeC(); // Force commit
putA(); removeA(); // Force apply




Bonus

Option to get application Context from anywhere:

Context appContext = Contextor.getInstance().getContext();




License

Copyright 2016 Alexey Korolev

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].