// Path: app/src/main/java/com/cxsj/runhdu/bean/gson/Status.java
// public class Status {
//     @SerializedName("Result")
//     private boolean result;
// 
//     @SerializedName("Message")
//     private String message;
// 
//     @SerializedName("Which")
//     private int which;
// 
//     public boolean getResult() {
//         return result;
//     }
// 
//     public String getMessage() {
//         return message;
//     }
// 
//     public int getWhich() {
//         return which;
//     }
// 
// }
// 
// Path: app/src/main/java/com/cxsj/runhdu/constant/URLs.java
// public class URLs {
//     public static final String DOWNLOAD = "http://d1.51gugu.com/170258/RunHDU";
//     public static final String LOGIN = "http://112.74.115.231:8080/CXSJ/Login";
//     public static final String REGISTER="http://112.74.115.231:8080/CXSJ/Register";
//     public static final String GET_RUN_INFO = "http://112.74.115.231:8080/chuangxinshijian/ReadAll";
//     public static final String UPLOAD_RUN_INFO = "http://112.74.115.231:8080/chuangxinshijian/Write";
//     public static final String CLEAR_DATA = "http://112.74.115.231:8080/chuangxinshijian/ClearTheTable";
//     public static final String UPDATE_URL = "http://112.74.115.231:8080/chuangxinshijian/VersionCompare";
//     public static final String GET_RUN_TIMES = "http://112.74.115.231:8080/chuangxinshijian/ReadUserNameAndTimesOnly";
//     public static final String UPLOAD_ALL_INFO = "http://112.74.115.231:8080/chuangxinshijian/WriteByJson";
//     public static final String UPLOAD_PROFILE = "http://112.74.115.231:8080/CXSJ/UploadHead";
//     public static final String PROFILE_URL = "http://112.74.115.231:8080/CXSJ/Image/";
//     public static final String FEEDBACK_URL = "http://112.74.115.231:8080/chuangxinshijian/WriteFeedback";
//     public static final String SUNNY_RUN_QUERY_API = "http://hdu.sunnysport.org.cn/api/student/achievements/";
//     public static final String SUNNY_RUN_INFO_API = "http://hdu.sunnysport.org.cn/api/student/info/";
//     public static final String DELETE_ITEM = "http://112.74.115.231:8080/chuangxinshijian/ClearByUserNameAndRunId";
//     public static final String APPLY_FRIEND = "http://112.74.115.231:8080/CXSJ/Apply";
//     public static final String REPLY_FRIEND = "http://112.74.115.231:8080/CXSJ/BeFriend";
//     public static final String GET_FRIEND = "http://112.74.115.231:8080/CXSJ/MyFriends";
//     public static final String DELETE_FRIEND = "http://112.74.115.231:8080/CXSJ/DeleteFriend";
//     public static final String OFF_LINE = "http://112.74.115.231:8080/CXSJ/Xiaxian";
// }
// 
// Path: app/src/main/java/com/cxsj/runhdu/utils/HttpUtil.java
// public class HttpUtil {
//     private static RequestManager manager;
// 
//     public static RequestManager load(String url) {
//         manager = new RequestManager();
//         manager.url(url);
//         return manager;
//     }
// 
//     public static class RequestManager {
//         private Request.Builder requestBuilder = new Request.Builder();
//         private FormBody.Builder formBuilder = new FormBody.Builder();
//         private Call call;
// 
//         private void url(String url) {
//             formBuilder = new FormBody.Builder();
//             requestBuilder = new Request.Builder();
// 
//             requestBuilder = requestBuilder.url(url);
//         }
// 
//         private void cancel() {
//             if (call != null) {
//                 call.cancel();
//             }
//         }
// 
//         public RequestManager addHeader(String key, String value) {
//             requestBuilder.addHeader(key, value);
//             return this;
//         }
// 
//         public RequestManager addParam(String key, String value) {
//             formBuilder = formBuilder.add(key, value);
//             return this;
//         }
// 
//         public void post(Callback callback) {
//             OkHttpClient client = new OkHttpClient.Builder()
//                     .connectTimeout(3, TimeUnit.SECONDS)
//                     .followRedirects(false)
//                     .followSslRedirects(false)
//                     .build();
// 
//             Request request = requestBuilder.post(formBuilder.build()).build();
//             client.newCall(request).enqueue(callback);
//         }
// 
//         public void get(Callback callback) {
//             OkHttpClient client = new OkHttpClient.Builder().build();
//             Request request = requestBuilder.build();
//             call = client.newCall(request);
//             call.enqueue(callback);
//         }
//     }
// }


import com.cxsj.runhdu.bean.gson.Status;
import com.cxsj.runhdu.constant.URLs;
import com.cxsj.runhdu.utils.HttpUtil;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
                try {
                    mHandler.post(() -> {
                        Status status = null;
                        status = new Gson().fromJson(json, Status.class);
                        if (status == null) {
                            callback.onLoginFailure(RETURN_DATA_ERROR, 0);
                        } else {
                            if (status.getResult()) {
                                callback.onLoginSuccess();
                            } else {
                                callback.onLoginFailure(status.getMessage(), status.getWhich());
                            }
                        }
                    });
                } catch (JsonSyntaxException e) {
                    callback.onLoginFailure(RETURN_DATA_ERROR, 0);
                    e.printStackTrace();
                }
            }
        };
    }

    public static void login(String username, String passwordMD5, LoginCallback callback) {
        HttpUtil.load(URLs.LOGIN)
                .addParam("name", username)
                .addParam("password", passwordMD5)
                .post(getCallback(callback));
    }

    public static void register(String username, String passwordMD5, LoginCallback callback) {
// Path: app/src/main/java/com/cxsj/runhdu/bean/gson/Status.java
// public class Status {
//     @SerializedName("Result")
//     private boolean result;
// 
//     @SerializedName("Message")
//     private String message;
// 
//     @SerializedName("Which")
//     private int which;
// 
//     public boolean getResult() {
//         return result;
//     }
// 
//     public String getMessage() {
//         return message;
//     }
// 
//     public int getWhich() {
//         return which;
//     }
// 
// }
// 
// Path: app/src/main/java/com/cxsj/runhdu/constant/URLs.java
// public class URLs {
//     public static final String DOWNLOAD = "http://d1.51gugu.com/170258/RunHDU";
//     public static final String LOGIN = "http://112.74.115.231:8080/CXSJ/Login";
//     public static final String REGISTER="http://112.74.115.231:8080/CXSJ/Register";
//     public static final String GET_RUN_INFO = "http://112.74.115.231:8080/chuangxinshijian/ReadAll";
//     public static final String UPLOAD_RUN_INFO = "http://112.74.115.231:8080/chuangxinshijian/Write";
//     public static final String CLEAR_DATA = "http://112.74.115.231:8080/chuangxinshijian/ClearTheTable";
//     public static final String UPDATE_URL = "http://112.74.115.231:8080/chuangxinshijian/VersionCompare";
//     public static final String GET_RUN_TIMES = "http://112.74.115.231:8080/chuangxinshijian/ReadUserNameAndTimesOnly";
//     public static final String UPLOAD_ALL_INFO = "http://112.74.115.231:8080/chuangxinshijian/WriteByJson";
//     public static final String UPLOAD_PROFILE = "http://112.74.115.231:8080/CXSJ/UploadHead";
//     public static final String PROFILE_URL = "http://112.74.115.231:8080/CXSJ/Image/";
//     public static final String FEEDBACK_URL = "http://112.74.115.231:8080/chuangxinshijian/WriteFeedback";
//     public static final String SUNNY_RUN_QUERY_API = "http://hdu.sunnysport.org.cn/api/student/achievements/";
//     public static final String SUNNY_RUN_INFO_API = "http://hdu.sunnysport.org.cn/api/student/info/";
//     public static final String DELETE_ITEM = "http://112.74.115.231:8080/chuangxinshijian/ClearByUserNameAndRunId";
//     public static final String APPLY_FRIEND = "http://112.74.115.231:8080/CXSJ/Apply";
//     public static final String REPLY_FRIEND = "http://112.74.115.231:8080/CXSJ/BeFriend";
//     public static final String GET_FRIEND = "http://112.74.115.231:8080/CXSJ/MyFriends";
//     public static final String DELETE_FRIEND = "http://112.74.115.231:8080/CXSJ/DeleteFriend";
//     public static final String OFF_LINE = "http://112.74.115.231:8080/CXSJ/Xiaxian";
// }
// 
// Path: app/src/main/java/com/cxsj/runhdu/utils/HttpUtil.java
// public class HttpUtil {
//     private static RequestManager manager;
// 
//     public static RequestManager load(String url) {
//         manager = new RequestManager();
//         manager.url(url);
//         return manager;
//     }
// 
//     public static class RequestManager {
//         private Request.Builder requestBuilder = new Request.Builder();
//         private FormBody.Builder formBuilder = new FormBody.Builder();
//         private Call call;
// 
//         private void url(String url) {
//             formBuilder = new FormBody.Builder();
//             requestBuilder = new Request.Builder();
// 
//             requestBuilder = requestBuilder.url(url);
//         }
// 
//         private void cancel() {
//             if (call != null) {
//                 call.cancel();
//             }
//         }
// 
//         public RequestManager addHeader(String key, String value) {
//             requestBuilder.addHeader(key, value);
//             return this;
//         }
// 
//         public RequestManager addParam(String key, String value) {
//             formBuilder = formBuilder.add(key, value);
//             return this;
//         }
// 
//         public void post(Callback callback) {
//             OkHttpClient client = new OkHttpClient.Builder()
//                     .connectTimeout(3, TimeUnit.SECONDS)
//                     .followRedirects(false)
//                     .followSslRedirects(false)
//                     .build();
// 
//             Request request = requestBuilder.post(formBuilder.build()).build();
//             client.newCall(request).enqueue(callback);
//         }
// 
//         public void get(Callback callback) {
//             OkHttpClient client = new OkHttpClient.Builder().build();
//             Request request = requestBuilder.build();
//             call = client.newCall(request);
//             call.enqueue(callback);
//         }
//     }
// }


// Path: app/src/main/java/com/cxsj/runhdu/Model/LoginModel.java
import com.cxsj.runhdu.bean.gson.Status;
import com.cxsj.runhdu.constant.URLs;
import com.cxsj.runhdu.utils.HttpUtil;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

                try {
                    mHandler.post(() -> {
                        Status status = null;
                        status = new Gson().fromJson(json, Status.class);
                        if (status == null) {
                            callback.onLoginFailure(RETURN_DATA_ERROR, 0);
                        } else {
                            if (status.getResult()) {
                                callback.onLoginSuccess();
                            } else {
                                callback.onLoginFailure(status.getMessage(), status.getWhich());
                            }
                        }
                    });
                } catch (JsonSyntaxException e) {
                    callback.onLoginFailure(RETURN_DATA_ERROR, 0);
                    e.printStackTrace();
                }
            }
        };
    }

    public static void login(String username, String passwordMD5, LoginCallback callback) {
        HttpUtil.load(URLs.LOGIN)
                .addParam("name", username)
                .addParam("password", passwordMD5)
                .post(getCallback(callback));
    }

    public static void register(String username, String passwordMD5, LoginCallback callback) {
        HttpUtil.load(URLs.REGISTER)