// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
// 
//     public static TypeAdapterFactory create() {
//         return new AutoValueGson_ProteinAdapterFactory();
//     }
// }
// 
// Path: app/src/main/java/com/ge/protein/data/api/ErrorUtils.java
// public class ErrorUtils {
// 
//     public static APIError parseError(Response<?> response) {
//         Converter<ResponseBody, APIError> converter = ServiceGenerator.retrofit()
//                 .responseBodyConverter(APIError.class, new Annotation[0]);
// 
//         APIError error;
// 
//         try {
//             error = converter.convert(response.errorBody());
//         } catch (IOException e) {
//             return null;
//         }
// 
//         return error;
//     }
// }
// 
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
// 
//     public abstract String access_token();
// 
//     public abstract String token_type();
// 
//     public abstract String scope();
// 
//     public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
//         return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
//     }
// }
// 
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
// 
//     private MainPresenter mainPresenter;
// 
//     @DebugLog
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         FirebaseCrashUtils.log("MainActivity created");
//         setContentView(R.layout.activity_main);
// 
//         mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
//         mainPresenter.start();
//     }
// }
// 
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
// 
//     private static AccountManager accountManager = new AccountManager();
//     private AccessToken accessToken;
//     private User me;
// 
//     private AccountManager() {
//     }
// 
//     public static AccountManager getInstance() {
//         return accountManager;
//     }
// 
//     public AccessToken getAccessToken() {
//         return accessToken;
//     }
// 
//     public void setAccessToken(AccessToken accessToken) {
//         this.accessToken = accessToken;
//     }
// 
//     public void setAccessToken(String token) {
//         accessToken = new GsonBuilder()
//                 .registerTypeAdapterFactory(ProteinAdapterFactory.create())
//                 .create()
//                 .fromJson(token, AccessToken.class);
//     }
// 
//     public boolean isLogin() {
//         return accessToken != null;
//     }
// 
//     public User getMe() {
//         return me;
//     }
// 
//     public void setMe(User me) {
//         this.me = me;
//     }
// 
//     public void clear() {
//         accessToken = null;
//         me = null;
//     }
// }
// 
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
// 
//     private Constants() {
//         throw new AssertionError("No construction for constant class");
//     }
// 
//     public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
// 
//     public static final String ACCESS_TOKEN_KEY = "access_token";
// 
//     public static final String USER = "user";
// 
// }
// 
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
//     if(reference == null) {
//         throw new NullPointerException(String.valueOf(errorMessage));
//     } else {
//         return reference;
//     }
// }


import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.api.ErrorUtils;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.google.gson.GsonBuilder;
import com.trello.rxlifecycle2.LifecycleProvider;

    @Override
    public void start() {

    }

    @Override
    public void getAccessToken(String code) {
        view.setProgressDialogVisibility(true);
        repository.getAccessToken(code)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
                .subscribe(accessTokenResponse -> {
                    view.setProgressDialogVisibility(false);

                    if (accessTokenResponse.isSuccessful()) {
                        AccessToken accessToken = accessTokenResponse.body();
                        AccountManager.getInstance().setAccessToken(accessToken);

                        SharedPreferences sp = view.getContext().getSharedPreferences(
                                Constants.DEFAULT_SHARED_PREFERENCES, Context.MODE_PRIVATE);
                        SharedPreferences.Editor editor = sp.edit();
                        String strRepre = new GsonBuilder()
                                .registerTypeAdapterFactory(ProteinAdapterFactory.create())
                                .create()
                                .toJson(accessToken);
                        editor.putString(Constants.ACCESS_TOKEN_KEY, strRepre);
                        editor.apply();

// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
// 
//     public static TypeAdapterFactory create() {
//         return new AutoValueGson_ProteinAdapterFactory();
//     }
// }
// 
// Path: app/src/main/java/com/ge/protein/data/api/ErrorUtils.java
// public class ErrorUtils {
// 
//     public static APIError parseError(Response<?> response) {
//         Converter<ResponseBody, APIError> converter = ServiceGenerator.retrofit()
//                 .responseBodyConverter(APIError.class, new Annotation[0]);
// 
//         APIError error;
// 
//         try {
//             error = converter.convert(response.errorBody());
//         } catch (IOException e) {
//             return null;
//         }
// 
//         return error;
//     }
// }
// 
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
// 
//     public abstract String access_token();
// 
//     public abstract String token_type();
// 
//     public abstract String scope();
// 
//     public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
//         return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
//     }
// }
// 
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
// 
//     private MainPresenter mainPresenter;
// 
//     @DebugLog
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         FirebaseCrashUtils.log("MainActivity created");
//         setContentView(R.layout.activity_main);
// 
//         mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
//         mainPresenter.start();
//     }
// }
// 
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
// 
//     private static AccountManager accountManager = new AccountManager();
//     private AccessToken accessToken;
//     private User me;
// 
//     private AccountManager() {
//     }
// 
//     public static AccountManager getInstance() {
//         return accountManager;
//     }
// 
//     public AccessToken getAccessToken() {
//         return accessToken;
//     }
// 
//     public void setAccessToken(AccessToken accessToken) {
//         this.accessToken = accessToken;
//     }
// 
//     public void setAccessToken(String token) {
//         accessToken = new GsonBuilder()
//                 .registerTypeAdapterFactory(ProteinAdapterFactory.create())
//                 .create()
//                 .fromJson(token, AccessToken.class);
//     }
// 
//     public boolean isLogin() {
//         return accessToken != null;
//     }
// 
//     public User getMe() {
//         return me;
//     }
// 
//     public void setMe(User me) {
//         this.me = me;
//     }
// 
//     public void clear() {
//         accessToken = null;
//         me = null;
//     }
// }
// 
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
// 
//     private Constants() {
//         throw new AssertionError("No construction for constant class");
//     }
// 
//     public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
// 
//     public static final String ACCESS_TOKEN_KEY = "access_token";
// 
//     public static final String USER = "user";
// 
// }
// 
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
//     if(reference == null) {
//         throw new NullPointerException(String.valueOf(errorMessage));
//     } else {
//         return reference;
//     }
// }


// Path: app/src/main/java/com/ge/protein/auth/AuthPresenter.java
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.api.ErrorUtils;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.google.gson.GsonBuilder;
import com.trello.rxlifecycle2.LifecycleProvider;


    @Override
    public void start() {

    }

    @Override
    public void getAccessToken(String code) {
        view.setProgressDialogVisibility(true);
        repository.getAccessToken(code)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
                .subscribe(accessTokenResponse -> {
                    view.setProgressDialogVisibility(false);

                    if (accessTokenResponse.isSuccessful()) {
                        AccessToken accessToken = accessTokenResponse.body();
                        AccountManager.getInstance().setAccessToken(accessToken);

                        SharedPreferences sp = view.getContext().getSharedPreferences(
                                Constants.DEFAULT_SHARED_PREFERENCES, Context.MODE_PRIVATE);
                        SharedPreferences.Editor editor = sp.edit();
                        String strRepre = new GsonBuilder()
                                .registerTypeAdapterFactory(ProteinAdapterFactory.create())
                                .create()
                                .toJson(accessToken);
                        editor.putString(Constants.ACCESS_TOKEN_KEY, strRepre);
                        editor.apply();

                        Intent intent = new Intent(view.getContext(), MainActivity.class);