All Projects → AliAsadi → PowerPreference

AliAsadi / PowerPreference

Licence: Apache-2.0 license
💾 A Powerful library to control and simplify the usage of shared preference in Android.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to PowerPreference

Android Debug Database
A library for debugging android databases and shared preferences - Make Debugging Great Again
Stars: ✭ 7,946 (+8264.21%)
Mutual labels:  debugging, sharedpreferences, debug, android-debug-database, room-persistence-library, room-database
Android Remote Debugger
A library for remote logging, database debugging, shared preferences and network requests
Stars: ✭ 132 (+38.95%)
Mutual labels:  debugging, sharedpreferences, debug
Einsen
🎯 Einsen is a prioritization app that uses Eisenhower matrix technique as workflow to prioritize a list of tasks & built to Demonstrate use of Jetpack Compose with Modern Android Architecture Components & MVVM Architecture.
Stars: ✭ 821 (+764.21%)
Mutual labels:  android-development, room-persistence-library, room-database
Icecream
🍦 Never use print() to debug again.
Stars: ✭ 5,601 (+5795.79%)
Mutual labels:  debugging, debug
Scyllahide
Advanced usermode anti-anti-debugger. Forked from https://bitbucket.org/NtQuery/scyllahide
Stars: ✭ 2,211 (+2227.37%)
Mutual labels:  debugging, debug
Godbg
Go implementation of the Rust `dbg` macro
Stars: ✭ 172 (+81.05%)
Mutual labels:  debugging, debug
Cli Debugging Cheatsheets
🔥 Collection of command-line debugging cheatsheets for multiple languages and runtimes
Stars: ✭ 239 (+151.58%)
Mutual labels:  debugging, debug
Bugsnag Ruby
Bugsnag error monitoring & reporting software for rails, sinatra, rack and ruby
Stars: ✭ 211 (+122.11%)
Mutual labels:  debugging, debug
gdbundle
Minimalist plugin manager for GDB and LLDB
Stars: ✭ 72 (-24.21%)
Mutual labels:  debugging, debug
debug
A tiny JavaScript debugging utility modelled after Node.js core's debugging technique. Works in Node.js and web browsers
Stars: ✭ 10,554 (+11009.47%)
Mutual labels:  debugging, debug
krumo
Krumo: Structured information display solution for PHP
Stars: ✭ 74 (-22.11%)
Mutual labels:  debugging, debug
bugsnag-java
Bugsnag error reporting for Java.
Stars: ✭ 51 (-46.32%)
Mutual labels:  debugging, debug
Debug Bundle
The DebugBundle allows greater integration of the VarDumper component in the Symfony full-stack framework.
Stars: ✭ 2,033 (+2040%)
Mutual labels:  debugging, debug
Frodo2
Android Library for Logging RxJava2 Components
Stars: ✭ 142 (+49.47%)
Mutual labels:  debugging, android-development
ducky
Chrome extension to overlay a (super adorable) rubber duck, as a virtual companion during rubber duck debugging.
Stars: ✭ 80 (-15.79%)
Mutual labels:  debugging, debug
Gdb Frontend
☕ GDBFrontend is an easy, flexible and extensionable gui debugger.
Stars: ✭ 2,104 (+2114.74%)
Mutual labels:  debugging, debug
Icecream Cpp
🍦 Never use cout/printf to debug again
Stars: ✭ 225 (+136.84%)
Mutual labels:  debugging, debug
iOSUtilitiesSource
IOS Utilities Library for Swift
Stars: ✭ 46 (-51.58%)
Mutual labels:  preferences, shared-preferences
Frodo
Android Library for Logging RxJava Observables and Subscribers.
Stars: ✭ 1,496 (+1474.74%)
Mutual labels:  debugging, android-development
Blender Debugger For Vscode
Blender addon for remote debugging Blender with VS Code (and Visual Studio)
Stars: ✭ 123 (+29.47%)
Mutual labels:  debugging, debug

Power Preference

A Powerful library to control and simplify the usage of shared preference in Android.

Android Arsenal Travis Download

Download

Step 1. Add the JitPack repository to your build file

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

implementation 'com.github.AliAsadi:PowerPreference:2.1.0'

Getting started

Initialize the library in your Application.onCreate() method:

PowerPreference.init(this);

Access the Preference File

There are two ways to access the preference file:

  1. Default File

This is the default file provided by the library.

Preference preference = PowerPreference.getDefaultFile();
  1. Custom File

When you choose a file name, a new file with that name will be created.

Preference preference = PowerPreference.getFileByName("preferenceName");

Save Data

The library can store data in two ways. asynchronously and synchronously.

Also, The library can store any type of data.

Integer, Long, Float, Double, String, ArrayList, Map, Object are all valid data types.

Asynchronous

To write data to a preference file asynchronously, use methods that begin with the put prefix.

The thread you're working on will not be blocked.

  • Insert single value
PowerPreference.getDefaultFile().putString("key",value);
  • Insert multiple values
PowerPreference.getDefaultFile()
        .putString("key", value)
        .putObject("key", value)
              .
              .
        .putMap("key", value);

Synchronous

To write data to a preference file synchronous, use methods that begin with the set prefix.

Until the save operation's result is received, the thread you're working on will be blocked.

boolean result = PowerPreference.getDefaultFile().setString("key",value);

Set can also be called with other types, such as setBoolean() and setObject().

Read Data

To retrieve data from a preference file, use methods that begin with the get prefix.

  1. String
String value = PowerPreference.getDefaultFile().getString("key", defValue);
  1. Object
Object value = PowerPreference.getDefaultFile().getObject("key", Object.class, defValue);
  1. Array
ArrayList<Object> value = PowerPreference.getDefaultFile().getObject("key", Object[].class, defValue);
  1. Map
MapStructure structure = MapStructure.create(HashMap.class, String.class, Object.class);
HashMap<String, Object> value = PowerPreference.getDefaultFile().getMap("key", structure);

Note:

If you don't specify a default value when calling get and the key you're looking for doesn't exist, the library will return default value from the list below.

For Example:

String value = PowerPreference.getDefaultFile().getString("key");

If you call get string without specifying a default value and the key does not exist, the library will return an empty string as a default value.

Type Default
Integer, Long, Float, Double 0
String ""
Object null

You also can choose a default value for each key in you preference file by seDefaults() method see the defaults section for more.

Remove Data

  • Synchronous
PowerPreference.getDefaultFile().remove("key");
  • Asynchronous
PowerPreference.getDefaultFile().removeAsync("key");

Clear Data

1. Clear data from specefic file

  • Synchronous
PowerPreference.getDefaultFile().clear();
  • Asynchronous
PowerPreference.getDefaultFile().clearAsync();

2. Clear data from all files

  • Synchronous
PowerPreference.clearAllData();
  • Asynchronous
PowerPreference.clearAllDataAsync();

Get Data

  1. Get all data for a specefic file
Map<String, ?> data = PowerPreference.getDefaultFile().getData();
  1. Get all data for all files in the app.
List<PreferenceFile> data = PowerPreference.getAllData()

Default Values

Set Default value to be used when reading from shared preference, You can use a different defaults value for every preference file.

There is two option using:

  1. XML
<?xml version="1.0" encoding="utf-8"?>
<defaultMap>
    <entry>
        <key>key</key>
        <value>true</value>
    </entry>

    <entry>
        <key>key</key>
        <value>Hello World!</value>
    </entry>
    
    <entry>
        <key>key</key>
        <value>5</value>
    </entry>
    
    //...etc
    
</defaultMap>
PowerPreference.getDefaultFile().setDefaults(R.xml.preferences_defaults)
  1. HashMap
Map<String, Object> defaults = new HashMap<>();
defaults.put("key", true);
defaults.put("key", "Hello World!");
defaults.put("key", 123);
defaults.put("key", 111L);
defaults.put("key", 1.1f);
defaults.put("key", 1.111d);
defaults.put("key", new Object());
PowerPreference.getDefaultFile().setDefaults(hashMap);

Preference Debbuger

Using the preference debugger, you can easily see and edit all of your app's preferences data.

PowerPreference.showDebugScreen();

License

Copyright 2018 Ali Asadi.

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].