// Path: app/src/main/java/io/github/emanual/app/api/EmanualAPI.java
// public class EmanualAPI {
//     /**
//      * 下载对应的语言
//      *
//      * @param lang
//      * @param responseHandler
//      */
//     @SuppressLint("DefaultLocale") public static void downloadLang(String lang, AsyncHttpResponseHandler responseHandler) {
//         RestClient.get(String.format("/md-%s/dist/%s.zip", lang.toLowerCase(), lang.toLowerCase()), null, responseHandler);
//     }
// 
//     /**
//      * 获得最新版本的信息
//      *
//      * @param responseHandler
//      */
//     public static void getVersionInfo(AsyncHttpResponseHandler responseHandler) {
//         RestClient.get("/md-release/dist/info.json", null, responseHandler);
//     }
// 
//     /**
//      * 获取对应语言的信息
//      * @param lang
//      * @param responseHandler
//      */
//     public static void getLangInfo(String lang, AsyncHttpResponseHandler responseHandler ){
//         RestClient.get(String.format("/md-%s/dist/%s/info.json", lang.toLowerCase(), lang.toLowerCase()), null, responseHandler);
//     }
// 
//     /**
//      * 获取Book feeds
//      * @param responseHandler
//      */
//     public static void getBookFeeds(AsyncHttpResponseHandler responseHandler){
//         RestClient.get(RestClient.URL_FEEDS,"/feeds-book/feeds/all.min.json", null, responseHandler);
//     }
// 
//     /**
//      * 获取Interview feeds
//      * @param responseHandler
//      */
//     public static void getInterviewFeeds(AsyncHttpResponseHandler responseHandler){
//         RestClient.get(RestClient.URL_FEEDS,"/feeds-interview/feeds/all.min.json", null, responseHandler);
//     }
// }


import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import com.loopj.android.http.JsonHttpResponseHandler;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import cz.msebera.android.httpclient.Header;
import io.github.emanual.app.api.EmanualAPI;
package io.github.emanual.app;





public class CoreService extends Service {
    public static final String Action_CheckVersion = "Action_CheckVersion";

    @Override public int onStartCommand(Intent intent, int flags, int startId) {
        String action = null;
        if (intent != null) {
            action = intent.getAction();
        }
        if (action != null) {
            Log.d("debug", "CoreService-->action-->" + action);
            if (action.equals(Action_CheckVersion)) {
                checkVersion();
            }
        }
        return Service.START_NOT_STICKY;
    }

    private void checkVersion() {
        EmanualAPI.getVersionInfo(new JsonHttpResponseHandler() {
            @Override public void onSuccess(int statusCode, Header[] headers,
                                            JSONObject response) {
                Intent intent = new Intent(Action_CheckVersion);
                try {

                    int version_code = response.getInt("version_code");
                    String version_name = response.getString("version_name");
                    String download_url = response.getString("download_url");
                    String update_time = response.getString("update_time");
// Path: app/src/main/java/io/github/emanual/app/api/EmanualAPI.java
// public class EmanualAPI {
//     /**
//      * 下载对应的语言
//      *
//      * @param lang
//      * @param responseHandler
//      */
//     @SuppressLint("DefaultLocale") public static void downloadLang(String lang, AsyncHttpResponseHandler responseHandler) {
//         RestClient.get(String.format("/md-%s/dist/%s.zip", lang.toLowerCase(), lang.toLowerCase()), null, responseHandler);
//     }
// 
//     /**
//      * 获得最新版本的信息
//      *
//      * @param responseHandler
//      */
//     public static void getVersionInfo(AsyncHttpResponseHandler responseHandler) {
//         RestClient.get("/md-release/dist/info.json", null, responseHandler);
//     }
// 
//     /**
//      * 获取对应语言的信息
//      * @param lang
//      * @param responseHandler
//      */
//     public static void getLangInfo(String lang, AsyncHttpResponseHandler responseHandler ){
//         RestClient.get(String.format("/md-%s/dist/%s/info.json", lang.toLowerCase(), lang.toLowerCase()), null, responseHandler);
//     }
// 
//     /**
//      * 获取Book feeds
//      * @param responseHandler
//      */
//     public static void getBookFeeds(AsyncHttpResponseHandler responseHandler){
//         RestClient.get(RestClient.URL_FEEDS,"/feeds-book/feeds/all.min.json", null, responseHandler);
//     }
// 
//     /**
//      * 获取Interview feeds
//      * @param responseHandler
//      */
//     public static void getInterviewFeeds(AsyncHttpResponseHandler responseHandler){
//         RestClient.get(RestClient.URL_FEEDS,"/feeds-interview/feeds/all.min.json", null, responseHandler);
//     }
// }


// Path: app/src/main/java/io/github/emanual/app/CoreService.java
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import com.loopj.android.http.JsonHttpResponseHandler;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import cz.msebera.android.httpclient.Header;
import io.github.emanual.app.api.EmanualAPI;

package io.github.emanual.app;





public class CoreService extends Service {
    public static final String Action_CheckVersion = "Action_CheckVersion";

    @Override public int onStartCommand(Intent intent, int flags, int startId) {
        String action = null;
        if (intent != null) {
            action = intent.getAction();
        }
        if (action != null) {
            Log.d("debug", "CoreService-->action-->" + action);
            if (action.equals(Action_CheckVersion)) {
                checkVersion();
            }
        }
        return Service.START_NOT_STICKY;
    }

    private void checkVersion() {
        EmanualAPI.getVersionInfo(new JsonHttpResponseHandler() {
            @Override public void onSuccess(int statusCode, Header[] headers,
                                            JSONObject response) {
                Intent intent = new Intent(Action_CheckVersion);
                try {

                    int version_code = response.getInt("version_code");
                    String version_name = response.getString("version_name");
                    String download_url = response.getString("download_url");
                    String update_time = response.getString("update_time");
                    String size = response.getString("size");