A lightweight library for config and using SharedPreferences

Overview

preferences-helper

Android Arsenal

Download

SharePreferences is very popular with any project and all most all project has SharePreferences for saving data. This library will help you faster in configuration and use SharePreferences in your project. Let's setup and enjoy!

Setup

  1. Add to build.gradle in app level
implementation 'com.github.tntkhang:preferences-helper:1.3.2'
  1. Init the PreferencesHelper in your CustomApplication.java extend from Application with 2 ways:

    • Will use app name as of Preferences file name PrefHelper.initHelper(this);

    • Will use CustomName as the name of SharePreferences file PrefHelper.initHelper(this, "CustomName");

  2. How to use

    SET VALUE:

        PrefHelper.setVal(KEY_BOOLEAN, true);
        PrefHelper.setVal(KEY_DOUBLE, 123.123);
        PrefHelper.setVal(KEY_FLOAT, 234.234f);
        PrefHelper.setVal(KEY_INT, 345);
        PrefHelper.setVal(KEY_LONG, Long.MAX_VALUE);
        PrefHelper.setVal(KEY_STRING, "Khang");

        UserModel userModel = new UserModel("KhangTran", 27);
        PrefHelper.setVal(KEY_OBJECT, userModel);

        List<String> stringList =  Arrays.asList("Tran", "Nguyen", "Thai", "Khang");
        PrefHelper.setVal(KEY_ARRAY_LIST, stringList);

        String[] arr = new String[4];
        arr[0] = "Tran 2";
        arr[1] = "Nguyen 2";
        arr[2] = "Thai 2";
        arr[3] = "Khang 2";
        PrefHelper.setVal(KEY_ARRAY, arr);
        
        Map<String, String> stringMap = new HashMap<>();
        stringMap.put("Tr", "Tran");
        stringMap.put("N", "Nguyen");
        stringMap.put("Th", "Thai");
        stringMap.put("K", "Khang");
        PrefHelper.setVal(KEY_MAP, stringMap);

GET VALUE:

boolean booleanValue = PrefHelper.getBooleanVal(KEY_BOOLEAN, false);
double doubleValue = PrefHelper.getDoubleVal(KEY_DOUBLE, Double.MIN_VALUE);
float floatValue = PrefHelper.getFloatVal(KEY_FLOAT, Float.MIN_VALUE);
int intValue = PrefHelper.getIntVal(KEY_INT, Integer.MIN_VALUE);
long longValue = PrefHelper.getLongVal(KEY_LONG, Long.MIN_VALUE);
String stringValue = PrefHelper.getStringVal(KEY_STRING, "Empty");
UserModel userModel = PrefHelper.getObjectVal(KEY_OBJECT, UserModel.class);
List<String> stringList = PrefHelper.getListVal(KEY_ARRAY_LIST);
String[] strings = PrefHelper.getArrayVal(KEY_ARRAY);
Map<String, String> stringMap = PrefHelper.getMapVal(KEY_MAP);

Map<String, ?> stringMap = PrefHelper.getAll();

DEMO

Download and run project for simple demo

That is, let's enjoy!

You might also like...
This project is an add-on for the excellent J2V8 Project. It allows users to debug JS running in V8 using Chrome DevTools. Uses Stetho for communication with Chrome DevTools.

J2V8-Debugger This project is an add-on for the excellent J2V8 Project. It allows users to debug JS running in V8 using Chrome DevTools. Uses Stetho f

Generate helper methods for compose navigation using KSP

Compose NavGen Generate helper methods for compose navigation using KSP. 🚧 You can try it now, but it's still under development. 🚧 TODO Support defa

Extensions to encrypt DataStore using Tink

encrypted-datastore Extensions to encrypt DataStore using Tink. ⚠️ This tiny library will be maintained until an official solution for DataStore encry

Format numbers using a string pattern with this simple number formatted like ##-####-##

AndroidPattern Format numbers using a string pattern with this simple number formatted like ##-####-## Installation To get a Git project into your bui

Android injection using the Anvil compiler plugin

Tangle creates Dagger bindings for Android classes using the Anvil Kotlin compiler plugin. This is meant to be an alternative to Hilt, for those who'd prefer to enjoy the faster compilation and better flexibility of Anvil.

DEMOMovieDB - Client App using movieDB with Kotlin
DEMOMovieDB - Client App using movieDB with Kotlin

DEMOMovieDB DEMOMovieDB is a gorgeous client application for TMDb on Android, bu

λRPC allows using code with high-order functions as a service
λRPC allows using code with high-order functions as a service

λRPC Simple native RPC with high order functions support. Inspired by @altavir and Communicator. λRPC allows using code with high-order functions as a

A universal memory dumper using Frida

Fridump Fridump (v0.1) is an open source memory dumping tool, primarily aimed to penetration testers and developers. Fridump is using the Frida framew

Sample project displaying process of OTP validation using firebase
Sample project displaying process of OTP validation using firebase

OTP-Validation-using-firebase Sample project displaying process of OTP validation using firebase Screenshots Concepts used Integrated Firebase sdk for

Owner
Khang Tran
Khang Tran
a SharedPreferences replacement for Android with multiprocess support

DEPRECATED - no longer actively maintained Tray - a SharedPreferences replacement for Android If you have read the documentation of the SharedPreferen

HCI @ gcx 2.3k Nov 17, 2022
A lightweight, simplified form validation library for Android

A lightweight, simplified form validation library for Android

İbrahim Süren 91 Nov 9, 2022
Simple Mobile Tools 172 Dec 26, 2022
Trail is a simple logging system for Java and Android. Create logs using the same API and the library will detect automatically in which platform the code is running.

Trail Trail is a simple logging system for Java and Android. Create logs using the same API and the library will detect automatically in which platfor

Mauricio Togneri 13 Aug 29, 2022
Android library to easily serialize and cache your objects to disk using key/value pairs.

Deprecated This project is no longer maintained. No new issues or pull requests will be accepted. You can still use the source or fork the project to

Anup Cowkur 667 Dec 22, 2022
A simple library for validating user input in forms using annotations.

ValidationKomensky for Android A simple library for validating user input in forms using annotations. Features: Validate all views at once and show fe

Inmite s.r.o. 512 Nov 20, 2022
A set of helper classes for using dagger 1 with Android components such as Applications, Activities, Fragments, BroadcastReceivers, and Services.

##fb-android-dagger A set of helper classes for using dagger with Android components such as Applications, Activities, Fragments, BroadcastReceivers,

Andy Dennie 283 Nov 11, 2022
A library for fast and safe delivery of parameters for Activities and Fragments.

MorbidMask - 吸血面具 Read this in other languages: 中文, English, Change Log A library for fast and safe delivery of parameters for Activities and Fragment

Season 67 Mar 29, 2022
A simple and easy to use stopwatch and timer library for android

TimeIt Now with Timer support! A simple and easy to use stopwatch and timer library for android Introduction A stopwatch can be a very important widge

Yashovardhan Dhanania 35 Dec 10, 2022
recompose is a tool for converting Android layouts in XML to Kotlin code using Jetpack Compose.

recompose is a tool for converting Android layouts in XML to Kotlin code using Jetpack Compose.

Sebastian Kaspari 565 Jan 2, 2023