Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
app
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

LifeLog Android Library

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

Book session on Codementor

Release Codacy Badge

How to add to your project

Add it using jitpack maven distribution.
Add the jitpack maven repository

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

Add the dependency

    dependencies {
	        compile 'in.championswimmer:Lifelog-Android-Library:1.+'
	}

###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 with LifeLog.LOGINACTIVITY_REQUEST_CODE as request code. Handle the returning user like this

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == LifeLog.LOGINACTIVITY_REQUEST_CODE) {
            if (resultCode == RESULT_OK) {
                Toast.makeText(this, "User authenticated", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(this, "User authentication failed", Toast.LENGTH_SHORT).show();
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }

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

me Endpoint

Create an object of MeRequest using the static MeRequest.prepareRequest method.

The data gets actually fetched when you call get()

MeRequest meRequest = MeRequest.prepareRequest();
                    meRequest.get(MainActivity.this, new MeRequest.OnMeFetched() {
                        @Override
                        public void onMeFetched(Me meData) {
                            Log.d(TAG, "onMeFetched: " + meData.getUsername());
                        }
                    });

locations endpoint

Create an object of MeLocationRequest 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 MeLocation objects are at your disposal.

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

Developers

You can’t perform that action at this time.