GithubHelp home page GithubHelp logo

subhrajyotisen / sharedprefmanager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hellosahib/sharedprefmanager

0.0 1.0 0.0 166 KB

An Android library which helps you create an Shared Preferences Manager with just annotations

Kotlin 100.00%

sharedprefmanager's Introduction

SharedPrefManager

โšก An Android library which helps you create an Shared Preferences Manager with just annotations โšก

JitPack

In daily development, you may define SharedPreferenceshelper's for handling lightweight data storage, but every time you create a helper class you have to write a lot of boilerplate singleton code, create contract classes to have those keys saved somewhere and make getter setter every time you want to add something to it ๐Ÿ’ฆ . With this library, I want to reduce that boilerplate code with help of annotations so as to reduce the errors and time while creating SharedPreferencesManagerย 

Gradle Setup

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

dependencies {
    implementation 'com.github.sahibedu.SharedPrefManager:Annotation:{RELEASE}'
    kapt 'com.github.sahibedu.SharedPrefManager:Processor:{RELEASE}'
}

How To Use It

Define an abstract class that contain your fields you want to save and annotate it with @SharedPrefManager

@SharedPrefManager(preferenceName = "someRandomKey")
abstract class Sample1 {
    val isFirstRunDone: Boolean = false
    val iAmNullableString: String? = null
    val iAmInteger: Int = 0
    val iAmLong: Long = 0L

    @PrefKeyInfo(key = "butIWantNewName")
    val iAmFloat: Float = 5f
}

Explaining the Annotations

  • @SharedPrefManager -> It is a Class Level Annotation to be Applied on Abstract Classes. If you want to have a custom name for your preference manager then add it to preferencename field else it takes the class name as key only
  • @PrefKeyInfo -> It is a Field Level Annotation used to Give MetaDataInfo To Preferences Keys. It is an optional Annotation. If you want to have a custom key for respective field then add the key to the annotation, else keys are generated based on the field name

Also Value Given to Fields Will be Taken As Default Values For Shared Pref

๐Ÿ’ฅ That's All For The Code Part from Your Side To Create An SharedPrefManager ๐Ÿ’ฅ

Now For Using it. you just need to pass the context and thats all you require.

Sample1SharedPreferenceManager.getInstance(this)

Now you can use this and access any field with simple code like

// Getter
Sample1SharedPreferenceManager.getInstance(this).isFirstRunDone
// Setter
Sample1SharedPreferenceManager.getInstance(this).isFirstRunDone = true

If you have any suggestions or feedback let me know and we will improve this library together ๐Ÿ˜‰

Made With ๐Ÿถ By Sahib Singh

sharedprefmanager's People

Contributors

servis avatar hellosahib avatar

Watchers

 avatar

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.