Back to project page PodioPuzzle.
The source code is released under:
Apache License
If you think the Android project PodioPuzzle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.podio.podiopuzzle.services; //from ww w. j a v a 2s. c o m import android.content.Context; import android.preference.PreferenceManager; import com.podio.podiopuzzle.config.AppConfig; import com.podio.podiopuzzle.config.PodioConfig; import com.podio.podiopuzzle.model.LoginResponseEntity; import com.podio.podiopuzzle.model.Organization; import com.podio.podiopuzzle.model.OrganizationResponseEntity; import com.podio.podiopuzzle.services.Retrofit.RetrofitHelper; import java.util.List; import retrofit.Callback; import retrofit.RetrofitError; import retrofit.client.Response; /** * Created by Linggom on 10/29/2014. */ public class Podio { private static Podio mPodio; private RetrofitHelper mHelperApi; private Context mContext; public static synchronized Podio getInstance(Context context){ if (mPodio == null){ mPodio = new Podio(context); } return mPodio; } /** * * @param username * Username of the user * @param password * Password of the user * @param callback * Listener when login api hit already finish */ public void login(String username, String password, final Callback<LoginResponseEntity> callback ){ if (mContext == null) { throw new NullPointerException(); } else if (callback == null){ throw new NullPointerException(); } mHelperApi.getService().login( PodioConfig.API_GRANT_TYPE, username, password, PodioConfig.API_KEY, null, PodioConfig.API_SECRET, new Callback<LoginResponseEntity>() { @Override public void success(LoginResponseEntity loginResponseEntity, Response response) { if (loginResponseEntity != null){ PreferenceManager .getDefaultSharedPreferences(mContext) .edit() .putString(AppConfig.SP_KEY_ACCESS_TOKEN, loginResponseEntity.getAccess_token()) .commit(); } callback.success(loginResponseEntity, response); } @Override public void failure(RetrofitError error) { callback.failure(error); } } ); } /** * @param callback * Listener from user when already finish hit api */ public void getOrganization(Callback<List<Organization>> callback){ if (mContext == null) { throw new NullPointerException(); } else if (callback == null){ throw new NullPointerException(); } String acces_token = PodioConfig.API_ORG_HEADER_AUTH_PREFIX + PreferenceManager.getDefaultSharedPreferences(mContext).getString(AppConfig.SP_KEY_ACCESS_TOKEN, null); mHelperApi.getService().getOrganization(acces_token, callback); } private Podio(Context context){ this.mContext = context; mHelperApi = new RetrofitHelper(); } /** * reset the state of podio */ public void reset() { PreferenceManager .getDefaultSharedPreferences(mContext).edit() .putString(AppConfig.SP_KEY_ACCESS_TOKEN, null).commit(); } /** * * @return * true if user is already login, false if user is not login yet */ public boolean isLogin() { return PreferenceManager .getDefaultSharedPreferences(mContext) .getString(AppConfig.SP_KEY_ACCESS_TOKEN, null) == null ? false : true; } }