Coder Social home page Coder Social logo

pranavpandey / dynamic-preferences Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 2.0 1001 KB

Manage shared preferences on Android.

Home Page: https://dynamic.pranavpandey.com

License: Apache License 2.0

Java 100.00%
android library manage shared preferences

dynamic-preferences's Introduction

Dynamic Preferences

License Build Status Release

A library to manage shared preferences on Android 4.0 (API 14) and above.

It uses AndroidX so, first migrate your project to AndroidX.
Since v2.1.0, it is dependent on Java 8 due to the dependency on Dynamic Utils.
Since v2.3.1, it is targeting Java 17 to provide maximum compatibility.


Contents


Installation

It can be installed by adding the following dependency to your build.gradle file:

dependencies {
    // For AndroidX enabled projects.
    implementation 'com.pranavpandey.android:dynamic-preferences:2.3.1'
}

Usage

It provides various methods to save, load and delete keys and preferences. Please read below about the various supported operations.

For a complete reference, please read the documentation.

Initialize

DynamicPreferences must be initialized once before accessing its methods.

// Initialize with application context.
DynamicPreferences.initializeInstance(applicationContext);

After initializing, its various public methods can be accessed via getting the initialized instance.

Save

It supports the saving of boolean, int, String and Set<String> value types into the shared preferences.

// Save a value in the default shared preferences.
DynamicPreferences.getInstance().save(key, value);

// Save a value in the supplied shared preferences.
DynamicPreferences.getInstance().save(preferences, key, value);

Load

It supports the retrieval of boolean, int, String and Set<String> value types from the shared preferences.

// Retrieve a value from the default shared preferences.
DynamicPreferences.getInstance().load(key, defaultValue);

// Retrieve a value from the supplied shared preferences.
DynamicPreferences.getInstance().save(preferences, key, defaultValue);

Delete

It supports the deletion of a particular key or a complete shared preferences.

// Remove a key from the default shared preferences.
DynamicPreferences.getInstance().delete(key);

// Remove a key from the supplied shared preferences.
DynamicPreferences.getInstance().delete(preferences, key);

// Delete a shared preferences.
DynamicPreferences.getInstance().deleteSharedPreference(preferences);

Dependency

It depends on the dynamic-utils to perform various internal operations. So, its functions can also be used to perform other useful operations.


Author

Pranav Pandey

GitHub Follow on Twitter Donate via PayPal


License

Copyright 2019-2023 Pranav Pandey

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.