Code Monkey home page Code Monkey logo

sharedprefdao's Introduction

SharedPrefDao

Add to your project:

dependencies {
    ...
    implementation 'com.github.coletz:sharedprefdao:0.1.1'
    kapt 'com.github.coletz:sharedprefdao:0.1.1'
    ...
}

Don't forget to apply plugin: 'kotlin-kapt' and add maven { url "https://jitpack.io" } to your repositories

Usage:

  1. Annotate an interface with @SharedPrefDao
  2. Add var for each key you want in your Dao
  3. Set default values for your entries with @get:DefaultValue("myDefaultValue")
  4. In order to set an empty string as default value, use EMPTY_STRING constant;
@SharedPrefDao(name = AppConfig.SHARED_PREF_NAME)
interface SettingsDao {

    @get:DefaultValue("5")
    var volume: Int?
    @get:DefaultValue("PlayerOne")
    var username: String?
    @get:DefaultValue("true")
    var shouldShowTutorial: Boolean
}

sharedprefdao's People

Contributors

dario-traceon avatar dcoletto avatar coletz avatar

Watchers

James Cloos avatar

sharedprefdao's Issues

Avoid using String as "defaultValue" type

right now we are using String for defaultValue type, so we have "true" or "false" for boolean value or "1", "0.0" etc. for numeric values.
We should use Any type or implement multiple properties like defaultBoolean, defaultInt, defaultDouble etc. in order to improve type safety and avoid possible issue (like misspelling or confusion between dot and comma for decimal numbers)

Handle List objects

Handle also list objects (at least List, would be nice to handle also primitives and even better of serializable objects).
To save/extract a list of string it is enough to add a separator (which should be customizable);
This has bad performances, but can be pretty handy for short lists

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.