Giter Club home page Giter Club logo

sheldon's Introduction

Build Status Android Arsenal Join the chat at https://gitter.im/Malinskiy/Sheldon Maven Central

Sheldon

Key concepts:

  • Preferences should not be tied to concrete implementation, they should be an interface that you can easily mock in your tests
  • You should be able to provide implementation gateway in your platform layer
  • Get your values through RxJava's Observable
  • Get rid of always specifying a string key when you get or set preference, this should be strongly typed so that your IDE can help with autocompletion and your key<->value pair is always in sync
  • Leverage annotation processing to automatically generate the wiring code between your preferences and platform gateway

Define your interface:

@Preferences(name = "temp")
public interface SomePreferences {
    @Default(name = "name") String DEFAULT_VALUE = "DEFAULT_VALUE";
    @Get(name = "name") Observable<String> getValueName();
    @Set(name = "name") void setValue(String newValue);
    ...
    @Contains Observable<Boolean> contains(String key);
    @Delete void remove(String key);
}

Adapters

Natively supported types are Boolean, Float, Integer, Long and String.

For everything else you have to extend IPreferenceAdapter and implement storing your entity via supported types. You can look at example of generic EnumAdapter. To include your adapter into processing just annotate it with @Adapter.

Each adapter should have a no-args constructor

Defaults

For each parameter you have to always supply a default value as a field in an interface annotated with @Default. Type of parameter should be the same as in getter and setter.

Instantiate the generated implementation

Temp_Preferences preferences = new Temp_Preferences(new SharedPreferencesGatewayBuilder(contextRef));

Probably you'd store this in your dependency graph and inject it by interface For additional info look at the sample

Get it

Gradle:

repositories {
    ...
    mavenCentral()
    ...
}
...
dependencies {
    ...
    apt "com.malinskiy.sheldon2:compiler:$version"
    compile "com.malinskiy.sheldon2:core:$version"
    compile "com.malinskiy.sheldon2:gateway-sharedpreferences:$version"
    ...
}

License

Copyright 2017 Anton Malinskiy

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.

sheldon's People

Contributors

malinskiy avatar tagantroy avatar vacxe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sheldon's Issues

Why doesn't this library have Synchronous API support?

Getting data from shared preference files should be synchronous because once a shared pref file is loaded all its key value pairs are stored in memory, this library forces Asychrnity down the developers throat un-necessarily!

Lack of Kotlin support

Current version doesn't have Kotlin support for interfaces (Default annotation can't be applied to methods, etc.)

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.