// Path: app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
// public class ServiceGenerator {
// 
//     private static String lastToken;
// 
//     private static Gson gson = new GsonBuilder()
//             .registerTypeAdapterFactory(ProteinAdapterFactory.create())
//             .create();
// 
//     private static Cache cache;
// 
//     private static Retrofit retrofit;
// 
//     public static void init(Context context) {
//         if (cache != null) {
//             throw new IllegalStateException("Retrofit cache already initialized.");
//         }
//         cache = new Cache(context.getCacheDir(), 20 * 1024 * 1024);
//     }
// 
//     public static Retrofit retrofit() {
//         return retrofit;
//     }
// 
//     public static <S> S createService(Class<S> serviceClass, final AccessToken token) {
//         String currentToken = token == null ? BuildConfig.DRIBBBLE_CLIENT_ACCESS_TOKEN : token.access_token();
//         if (retrofit == null || !currentToken.equals(lastToken)) {
//             lastToken = currentToken;
//             OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
//             httpClientBuilder.addInterceptor(chain -> {
//                 Request original = chain.request();
// 
//                 Request.Builder requestBuilder = original.newBuilder()
//                         .header("Accept", "application/json")
//                         .header("Authorization", "Bearer" + " " + lastToken)
//                         .method(original.method(), original.body());
// 
//                 Request request = requestBuilder.build();
//                 return chain.proceed(request);
//             }).cache(cache);
//             if (BuildConfig.DEBUG) {
//                 httpClientBuilder.addNetworkInterceptor(new StethoInterceptor());
//             }
//             Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
//                     .baseUrl(ApiConstants.DRIBBBLE_V1_BASE_URL)
//                     .addConverterFactory(GsonConverterFactory.create(gson))
//                     .addCallAdapterFactory(RxJava2CallAdapterFactory.create());
//             OkHttpClient httpClient = httpClientBuilder.build();
//             retrofit = retrofitBuilder.client(httpClient).build();
//         }
// 
//         return retrofit.create(serviceClass);
//     }
// 
// }
// 
// 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";
// 
// }


import android.app.Application;
import android.content.SharedPreferences;
import android.text.TextUtils;
import com.facebook.stetho.Stetho;
import com.ge.protein.data.api.ServiceGenerator;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.squareup.leakcanary.RefWatcher;
import butterknife.ButterKnife;
import hugo.weaving.DebugLog;
/*
 * Copyright 2017 Jiaheng Ge
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ge.protein;




public class ProteinApp extends Application {

    private RefWatcher refWatcher;

    @DebugLog
    @Override
    public void onCreate() {
        super.onCreate();
        ServiceGenerator.init(this);
        if (BuildConfig.DEBUG) {
            Stetho.initializeWithDefaults(this);
        }
        initAccessToken();
        ButterKnife.setDebug(BuildConfig.DEBUG);
        refWatcher = installLeakCanary();
    }

    private void initAccessToken() {
// Path: app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
// public class ServiceGenerator {
// 
//     private static String lastToken;
// 
//     private static Gson gson = new GsonBuilder()
//             .registerTypeAdapterFactory(ProteinAdapterFactory.create())
//             .create();
// 
//     private static Cache cache;
// 
//     private static Retrofit retrofit;
// 
//     public static void init(Context context) {
//         if (cache != null) {
//             throw new IllegalStateException("Retrofit cache already initialized.");
//         }
//         cache = new Cache(context.getCacheDir(), 20 * 1024 * 1024);
//     }
// 
//     public static Retrofit retrofit() {
//         return retrofit;
//     }
// 
//     public static <S> S createService(Class<S> serviceClass, final AccessToken token) {
//         String currentToken = token == null ? BuildConfig.DRIBBBLE_CLIENT_ACCESS_TOKEN : token.access_token();
//         if (retrofit == null || !currentToken.equals(lastToken)) {
//             lastToken = currentToken;
//             OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
//             httpClientBuilder.addInterceptor(chain -> {
//                 Request original = chain.request();
// 
//                 Request.Builder requestBuilder = original.newBuilder()
//                         .header("Accept", "application/json")
//                         .header("Authorization", "Bearer" + " " + lastToken)
//                         .method(original.method(), original.body());
// 
//                 Request request = requestBuilder.build();
//                 return chain.proceed(request);
//             }).cache(cache);
//             if (BuildConfig.DEBUG) {
//                 httpClientBuilder.addNetworkInterceptor(new StethoInterceptor());
//             }
//             Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
//                     .baseUrl(ApiConstants.DRIBBBLE_V1_BASE_URL)
//                     .addConverterFactory(GsonConverterFactory.create(gson))
//                     .addCallAdapterFactory(RxJava2CallAdapterFactory.create());
//             OkHttpClient httpClient = httpClientBuilder.build();
//             retrofit = retrofitBuilder.client(httpClient).build();
//         }
// 
//         return retrofit.create(serviceClass);
//     }
// 
// }
// 
// 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/ProteinApp.java
import android.app.Application;
import android.content.SharedPreferences;
import android.text.TextUtils;
import com.facebook.stetho.Stetho;
import com.ge.protein.data.api.ServiceGenerator;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.squareup.leakcanary.RefWatcher;
import butterknife.ButterKnife;
import hugo.weaving.DebugLog;

/*
 * Copyright 2017 Jiaheng Ge
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ge.protein;




public class ProteinApp extends Application {

    private RefWatcher refWatcher;

    @DebugLog
    @Override
    public void onCreate() {
        super.onCreate();
        ServiceGenerator.init(this);
        if (BuildConfig.DEBUG) {
            Stetho.initializeWithDefaults(this);
        }
        initAccessToken();
        ButterKnife.setDebug(BuildConfig.DEBUG);
        refWatcher = installLeakCanary();
    }

    private void initAccessToken() {
        SharedPreferences sp = getSharedPreferences(Constants.DEFAULT_SHARED_PREFERENCES, MODE_PRIVATE);