Giter Club home page Giter Club logo

easy-content-providers's Introduction

Easy Content Providers

Easy integration with Android's built-in and custom content providers data. It even comes with a Sample app and Stetho extension for debugging purposes.

Android Arsenal

Why and When

We often experiment with new features, new apps, new ideas or we just code through a hackathon project that's built on-top of Android's content providers.. In such cases, we need tools to get what we want with minimum friction. This is where easy-content-providers come in - we can get all android stored data very easily and we can debug results through Chrome dev tools (based on Stetho implementation).

The library uses reflection and some additional operations to make the ORM implementation generic, this is great for flexibility and POCs but might not be sufficient for high performance production apps. Also, if you don't define the exact columns you want, the mapping will happen on all columns (select * from ...). Sometimes, this is not what you want.

Example Usage

Gradle:

dependencies {
    compile 'me.everything:providers-android:1.0.1'
}

Getting all calendars:

CalanderProvider provider = new CalendarProvider(context);
List<Calendar> calendars = provider.getCalendars().getList();

Full documentation can be found at the wiki.

Inspecting provider data

Gradle:

dependencies {
    compile 'me.everything:providers-stetho:1.0.1' 
}

Leveraging Stetho's ability to inspect SQLite databases, you can visualize, explore and modify all provider data.

Screenshot

In the above example, all providers can be seen expanded, "provider-calendar" is selected and it's items appear in the table to the right.

Adding your own providers

And of course, you can see your own providers by registring them. In our example (check sample app):

... 
providersStetho.registerProvider("provider-custom", "posts", new ProvidersStetho.QueryExecutor<Post>() {
    @Override
    public Data<Post> onQuery(String query) {
        PostsProvider provider = new PostsProvider(getApplicationContext());
        return provider.getPosts();
    }
});	
...

Which looks like so:

Screenshot

SQL Quering

Stetho allows to query SQLite databases from within it's console. Currently, Android providers are interactable with sql, with the following limitations:

  • Only all-inclusive queries are possible select * from "tablename"

  • Results may take a few seconds to appear.

  • Querying tables in provider-calendar can only be done like so:

    • #events:id=3 - select from events where calendar id = 3
    • #instances:id=100 - select from instances where event id = 100
    • #reminders:id=100 - select from reminders where event id = 100
    • #attendees:id=100 - select from attendees where event id = 100

    Screenshot

We are inclined to rid ourselves of these limitations. Stay tuned for upcoming developments.

Sample App

Try it out with our sample app. Download the apk, run it on a connected device, open chrome://inspect in Chrome and start inspecting the providers to your delight.

Notice the app lists items from each provider. Take a look at the app's source code to see how this was implemented.

Screenshot




Author

Roman Kushnarenko - sromku

License

Apache License 2.0

easy-content-providers's People

Contributors

joeysim avatar sromku avatar thucnguyenhuu avatar

Watchers

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