// Path: app/src/main/java/moe/yukinoneko/diycode/api/OAuth.java
// public class OAuth {
//     // 认证类型
//     public static final String GRANT_TYPE_LOGIN = "password";             // 密码
//     public static final String GRANT_TYPE_REFRESH = "refresh_token";      // 刷新令牌
// 
//     public static final String KEY_TOKEN = "Authorization";
//     public static final String TOKEN_PREFIX = "Bearer ";
// 
//     public static String client_id;          // 应用ID
//     public static String client_secret;      // 私钥
// 
//     public static void init(String clientId, String clientSecret) {
//         client_id = clientId;
//         client_secret = clientSecret;
//     }
// }
// 
// Path: app/src/main/java/moe/yukinoneko/diycode/api/Secret.java
// public class Secret {
//     static {
//         System.loadLibrary("secret");
//     }
// 
//     public static native String getClientId();
//     public static native String getSecret();
// }
// 
// Path: app/src/main/java/moe/yukinoneko/diycode/tool/UserHelper.java
// public class UserHelper {
// 
//     private static final String TOKEN = "token";
//     private static final String USER = "user";
// 
//     private static SharedPreferences prefs;
// 
//     public static void init(Context context) {
//         prefs = new SecurePreferences(context.getApplicationContext());
//     }
// 
//     public static void saveToken(Token token) {
//         prefs.edit().putString(TOKEN, GSON.toJson(token)).apply();
//     }
// 
//     public static Token getToken() {
//         String tokenJson = prefs.getString(TOKEN, null);
//         if (tokenJson != null) {
//             return GSON.fromJson(tokenJson, Token.class);
//         }
//         return null;
//     }
// 
//     public static boolean isLogin() {
//         return null != getToken();
//     }
// 
//     public static boolean hasUser() {
//         return null != getUser();
//     }
// 
//     public static void saveUser(User user) {
//         prefs.edit().putString(USER, GSON.toJson(user)).apply();
//     }
// 
//     public static User getUser() {
//         String userJson = prefs.getString(USER, null);
//         if (userJson != null) {
//             return GSON.fromJson(userJson, User.class);
//         }
//         return null;
//     }
// 
//     public static void logout() {
//         prefs.edit().remove(USER).remove(TOKEN).apply();
//     }
// }
// 
// Path: app/src/main/java/moe/yukinoneko/diycode/tool/ErrorHandler.java
// public static Consumer<Throwable> errorConsumer(final Context context) {
//     return new Consumer<Throwable>() {
//         @Override public void accept(@NonNull Throwable throwable) {
//             String errorMessage = null;
//             if (throwable instanceof HttpException) {
//                 HttpException httpException = (HttpException) throwable;
//                 errorMessage = GSON.fromJson(httpException.response().errorBody().charStream(), Error.class).error;
//             } else if (throwable instanceof UnknownHostException) {
//                 errorMessage = context.getString(R.string.tip_network_is_not_available);
//             } else {
//                 errorMessage = throwable.getMessage();
//             }
//             ToastHelper.showShort(context, errorMessage);
//         }
//     };
// }


import android.app.Application;
import io.reactivex.plugins.RxJavaPlugins;
import moe.yukinoneko.diycode.api.OAuth;
import moe.yukinoneko.diycode.api.Secret;
import moe.yukinoneko.diycode.tool.UserHelper;
import static moe.yukinoneko.diycode.tool.ErrorHandler.errorConsumer;
/*
 * Copyright (c) 2017 SamuelGjk <samuel.alva@outlook.com>
 *
 * This file is part of DiyCode
 *
 * DiyCode is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DiyCode is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with DiyCode. If not, see <http://www.gnu.org/licenses/>.
 */

package moe.yukinoneko.diycode;




/**
 * Created by SamuelGjk on 2017/3/23.
 */

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        OAuth.init(Secret.getClientId(), Secret.getSecret());
// Path: app/src/main/java/moe/yukinoneko/diycode/api/OAuth.java
// public class OAuth {
//     // 认证类型
//     public static final String GRANT_TYPE_LOGIN = "password";             // 密码
//     public static final String GRANT_TYPE_REFRESH = "refresh_token";      // 刷新令牌
// 
//     public static final String KEY_TOKEN = "Authorization";
//     public static final String TOKEN_PREFIX = "Bearer ";
// 
//     public static String client_id;          // 应用ID
//     public static String client_secret;      // 私钥
// 
//     public static void init(String clientId, String clientSecret) {
//         client_id = clientId;
//         client_secret = clientSecret;
//     }
// }
// 
// Path: app/src/main/java/moe/yukinoneko/diycode/api/Secret.java
// public class Secret {
//     static {
//         System.loadLibrary("secret");
//     }
// 
//     public static native String getClientId();
//     public static native String getSecret();
// }
// 
// Path: app/src/main/java/moe/yukinoneko/diycode/tool/UserHelper.java
// public class UserHelper {
// 
//     private static final String TOKEN = "token";
//     private static final String USER = "user";
// 
//     private static SharedPreferences prefs;
// 
//     public static void init(Context context) {
//         prefs = new SecurePreferences(context.getApplicationContext());
//     }
// 
//     public static void saveToken(Token token) {
//         prefs.edit().putString(TOKEN, GSON.toJson(token)).apply();
//     }
// 
//     public static Token getToken() {
//         String tokenJson = prefs.getString(TOKEN, null);
//         if (tokenJson != null) {
//             return GSON.fromJson(tokenJson, Token.class);
//         }
//         return null;
//     }
// 
//     public static boolean isLogin() {
//         return null != getToken();
//     }
// 
//     public static boolean hasUser() {
//         return null != getUser();
//     }
// 
//     public static void saveUser(User user) {
//         prefs.edit().putString(USER, GSON.toJson(user)).apply();
//     }
// 
//     public static User getUser() {
//         String userJson = prefs.getString(USER, null);
//         if (userJson != null) {
//             return GSON.fromJson(userJson, User.class);
//         }
//         return null;
//     }
// 
//     public static void logout() {
//         prefs.edit().remove(USER).remove(TOKEN).apply();
//     }
// }
// 
// Path: app/src/main/java/moe/yukinoneko/diycode/tool/ErrorHandler.java
// public static Consumer<Throwable> errorConsumer(final Context context) {
//     return new Consumer<Throwable>() {
//         @Override public void accept(@NonNull Throwable throwable) {
//             String errorMessage = null;
//             if (throwable instanceof HttpException) {
//                 HttpException httpException = (HttpException) throwable;
//                 errorMessage = GSON.fromJson(httpException.response().errorBody().charStream(), Error.class).error;
//             } else if (throwable instanceof UnknownHostException) {
//                 errorMessage = context.getString(R.string.tip_network_is_not_available);
//             } else {
//                 errorMessage = throwable.getMessage();
//             }
//             ToastHelper.showShort(context, errorMessage);
//         }
//     };
// }


// Path: app/src/main/java/moe/yukinoneko/diycode/App.java
import android.app.Application;
import io.reactivex.plugins.RxJavaPlugins;
import moe.yukinoneko.diycode.api.OAuth;
import moe.yukinoneko.diycode.api.Secret;
import moe.yukinoneko.diycode.tool.UserHelper;
import static moe.yukinoneko.diycode.tool.ErrorHandler.errorConsumer;

/*
 * Copyright (c) 2017 SamuelGjk <samuel.alva@outlook.com>
 *
 * This file is part of DiyCode
 *
 * DiyCode is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DiyCode is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with DiyCode. If not, see <http://www.gnu.org/licenses/>.
 */

package moe.yukinoneko.diycode;




/**
 * Created by SamuelGjk on 2017/3/23.
 */

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        OAuth.init(Secret.getClientId(), Secret.getSecret());
        UserHelper.init(this);