Git Product home page Git Product logo

appscope's Introduction

appscope

An Android library implementing Service Locator pattern

Examples:

AppScope.init(context, new Gson()); // Initialize one-tine in your Application.onCreate() method
private static final TypedKey<String> COUNTRY_CODE = new TypedKey("countryCode", String.class);
AppScope.put(COUNTRY_CODE, "US"); // bind the key COUNTRY_CODE to the value "US"

.... // Anywhere in app
String country = AppScope.get(COUNTRY_CODE)  ==> Returns "US"

In the example above, the COUNTRY_CODE is persisted (in prefs) and usable across sessions.

The type of the key can be any arbitrary type that the Gson instance can serialize/deserialize.

Use with Gradle

add to your repositories

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

In your app build.gradle, add: compile "com.github.PeelTechnologies:appscope:2.0.0"

If you use Amplitude, also checkout android-typesafe-prefs-amplitude project to automatically sync AppScope properties with Amplitude.

User Guide

TypedKey can take arbitrarily complex Java object that Gson can serialize/deserialize. For example, TypedKey<Customer> may represent a class with nested fields for Address, name, phone numbers, etc.

While defining TypedKeys, add tag AppScope.SURVIVE_RESET in constructor if you want the key to not be cleared when AppScope.reset() is called.

For Junit tests, use AppScope.TestAccess.init() method in setUp(). This is to ensure that any values set by other tests will get cleared

Any key that is tagged as AppScope.NON_PERSISTENT, is stored in a local map, and never written out to the disk.

appscope's People

Contributors

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