Code Monkey home page Code Monkey logo

lifelog-android-library's Introduction

#LifeLog Android Library This is an Android (not pure java) wrapper for the LifeLog Web API.

##QuickStart I will upload this maven & jcenter soon, bear with the cumbersome process of manually downloading source and adding it till then

###Initialise In your Application class, inside the onCreate body, add this

LifeLog.initialise("clientid", "secret", "https://callbackurl.com");

Replace clientid, secret and callbackurl with your respective values of the app that you have registered on LifeLog.

###Login and authentication ####Login To log the user in for the first time, use this simple static method

LifeLog.doLogin(MainActivity.this)

Note that, after login is completed, we will return back to same activity. Internally, doLogin makes a startActivityForResult call. Handle the returning user like this

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == LifeLog.LOGINACTIVITY_REQUEST_CODE) {
            //we are logged in, do what you please now
            Toast.makeText(this, "User authenticated", Toast.LENGTH_SHORT).show();
        }
    }

####Checking Authentication state You would want to check if the user is authenticated or not. Even if he is, we may need to refresh the auth token. Again, simple code for that.

LifeLog.checkAuthentication(this, new LifeLog.OnAuthenticationChecked() {
    @Override
    public void onAuthChecked(boolean authenticated) {
        if (authenticated) {
            //User is authenticated, we can do API requests now
        } else {
            //User is not authenticated. Make him login (or whatever suits your app's flow)
            //LifeLog.doLogin(MainActivity.this);
        }
    }
});

###API Requests ####Location endpoint Create an object of LifeLogLocationAPI using one of the two prepareRequest methods. One allows you to specify start and end time. Other doesn't. You can set either of start or end time to be null as well.

The data fetching actually starts when get is called. After the data is fetched, the onLocationFetched callback is hit. A List<> of LifeLogLocation objects are at your disposal.

LifeLogLocationAPI llLocation = LifeLogLocationAPI.prepareRequest(500);
    llLocation.get(MainActivity.this, new LifeLogLocationAPI.OnLocationFetched() {
        @Override
        public void onLocationFetched(ArrayList<LifeLogLocationAPI.LifeLogLocation> locations) {
            for (LifeLogLocationAPI.LifeLogLocation loc : locations) {
                String id = loc.getId();
                Calendar startTime = loc.getStartTime();
                //continue likewise
            }
        }
    });

lifelog-android-library's People

Contributors

championswimmer avatar

Watchers

James Cloos 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.