导航菜单

页面标题

页面副标题

公务员之家 v1.0.1 - OssHttpHelper.java 源代码

正在查看: 公务员之家 v1.0.1 应用的 OssHttpHelper.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.shineyie.android.oss;

import android.content.Context;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.shineyie.android.base.ReqResult;
import com.shineyie.android.base.ServerResult;
import com.shineyie.android.base.http.BaseReqCallback;
import com.shineyie.android.base.util.LogUtil;
import com.shineyie.android.oss.entity.CategoryList;
import com.shineyie.android.oss.entity.DirInfo;
import com.shineyie.android.oss.entity.DirSubItemInfo;
import com.shineyie.android.oss.entity.GetAllFirstResRet;
import com.shineyie.android.oss.entity.GetAppInfoRet;
import com.shineyie.android.oss.entity.KdFilesInfo;
import com.shineyie.android.oss.entity.KdResList;
import com.shineyie.android.oss.entity.MsAttachResList;
import com.shineyie.android.oss.entity.MsCategoryList;
import com.shineyie.android.oss.entity.MsResList;
import com.shineyie.android.oss.entity.VideoTutorialCategoryList;
import java.lang.reflect.Type;
import java.util.List;

public class OssHttpHelper {
    private static final String BASE_DEBUG_URL = "http://test-ijj-static-api.ijianji.cn/api/v1/";
    private static final String BASE_RELEASE_URL = "http://ijj-static-api.ijianji.cn/api/v1/";
    private static final String TAG = "OssHttpHelper";
    private static OssHttpHelper instance;
    private static Context sContext;
    private String mAppId;
    private String mAppInfoUrl;
    private OssInternalHttpHelper mHttpHelper;
    private static String base_url = "http://ijj-static-api.ijianji.cn/api/v1/";
    private static String base_app_info_url = base_url + "appInfo/appId/";

    public interface ICallback<T> {
        void onResult(boolean z, T t);
    }

    private OssHttpHelper() {
        checkInit();
        this.mAppId = sContext.getPackageName();
        this.mAppInfoUrl = base_app_info_url + this.mAppId;
        this.mHttpHelper = new OssInternalHttpHelper(sContext, base_url);
        ParamHelper.init(this.mAppId);
    }

    private void checkInit() {
        if (sContext == null) {
            throw new RuntimeException("OssHttpHelper: checkInit: you have to call the init(Context context, boolean debug) method first.");
        }
    }

    public static synchronized void init(Context context, boolean z) {
        String str;
        synchronized (OssHttpHelper.class) {
            if (z) {
                str = BASE_DEBUG_URL;
            } else {
                str = BASE_RELEASE_URL;
            }
            init(context, str);
        }
    }

    public static synchronized void init(Context context, String str) {
        synchronized (OssHttpHelper.class) {
            sContext = context;
            if (context == null) {
                throw new IllegalArgumentException("OssHttpHelper: init:the param context can not be null.");
            }
            base_url = str;
            base_app_info_url = base_url + "appInfo/appId/";
        }
    }

    public static synchronized OssHttpHelper getInstance(Context context) {
        OssHttpHelper ossHttpHelper;
        synchronized (OssHttpHelper.class) {
            init(context, false);
            if (instance == null) {
                instance = new OssHttpHelper();
            }
            ossHttpHelper = instance;
        }
        return ossHttpHelper;
    }

    public static synchronized OssHttpHelper getInstance() {
        OssHttpHelper ossHttpHelper;
        synchronized (OssHttpHelper.class) {
            if (instance == null) {
                instance = new OssHttpHelper();
            }
            ossHttpHelper = instance;
        }
        return ossHttpHelper;
    }

    public String getAppId() {
        return this.mAppId;
    }

    public void setAppId(String str) {
        this.mAppId = str;
        this.mAppInfoUrl = base_app_info_url + this.mAppId;
    }

    public void getAppInfo(final ICallback<GetAppInfoRet> iCallback) {
        this.mHttpHelper.getAppInfo(this.mAppInfoUrl, ParamHelper.createGetAppInfoParam(), new BaseReqCallback<ReqResult>() {
            public void onResult(boolean z, ReqResult reqResult) {
                OssHttpHelper.this.handleResult("getAppInfo", z, reqResult, iCallback, GetAppInfoRet.class);
            }
        });
    }

    public void getFileUrl(String str, String str2, String str3, final ICallback<String> iCallback) {
        this.mHttpHelper.getFileUrl(ParamHelper.createGetFileUrlParam(str, str2, str3), new BaseReqCallback<ReqResult>() {
            public void onResult(boolean z, ReqResult reqResult) {
                OssHttpHelper.this.handleResult("getFileUrl", z, reqResult, iCallback, String.class);
            }
        });
    }

    public void getOssKinds(String str, String str2, String str3, int i, final ICallback<List<DirInfo>> iCallback) {
        this.mHttpHelper.getOssKinds(ParamHelper.createGetOssKindsParam(str, str2, str3, i), new BaseReqCallback<ReqResult>() {
            public void onResult(boolean z, ReqResult reqResult) {
                OssHttpHelper.this.handleResult("getOssKinds", z, reqResult, iCallback, new TypeToken<List<DirInfo>>() {
                }.getType());
            }
        });
    }

    public void getOssVideoList(String str, String str2, String str3, int i, int i2, int i3, final ICallback<List<DirSubItemInfo>> iCallback) {
        this.mHttpHelper.getOssVideoList(ParamHelper.createGetOssVideoListParam(str, str2, str3, i, i2, i3), new BaseReqCallback<ReqResult>() {
            public void onResult(boolean z, ReqResult reqResult) {
                OssHttpHelper.this.handleResult("getOssVideoList", z, reqResult, iCallback, new TypeToken<List<DirSubItemInfo>>() {
                }.getType());
            }
        });
    }

    @Deprecated
    public void getKdAllCategory(String str, String str2, int i, int i2, int i3, final ICallback<CategoryList> iCallback) {
        this.mHttpHelper.getKdAllCategory(ParamHelper.createGetAllCategoryParam(str, str2, i, i2, 1, i3), new BaseReqCallback<ReqResult>() {
            public void onResult(boolean z, ReqResult reqResult) {
                OssHttpHelper.this.handleResult("getKdAllCategory", z, reqResult, iCallback, CategoryList.class);
            }
        });
    }

    public void getMsAllCategory(String str, String str2, int i, int i2, int i3, int i4, final ICallback<MsCategoryList> iCallback) {
        this.mHttpHelper.getMsAllCategory(ParamHelper.createGetAllCategoryParam(str, str2, i, i2, i4, i3), new BaseReqCallback<ReqResult>() {
            public void onResult(boolean z, ReqResult reqResult) {
                OssHttpHelper.this.handleResult("getMsAllCategory", z, reqResult, iCallback, MsCategoryList.class);
            }
        });
    }

    public void getKdResList(String str, String str2, int i, int i2, int i3, int i4, int i5, String str3, final ICallback<KdResList> iCallback) {
        this.mHttpHelper.getKdResource(ParamHelper.createKdResourceParam(str, str2, i, i2, i3, i4, i5, str3), new BaseReqCallback<ReqResult>() {
            public void onResult(boolean z, ReqResult reqResult) {
                OssHttpHelper.this.handleResult("getKdResList", z, reqResult, iCallback, KdResList.class);
            }
        });
    }

    public void getMsResList(String str, String str2, int i, int i2, int i3, int i4, int i5, int i6, final ICallback<MsResList> iCallback) {
        this.mHttpHelper.getMsResource(ParamHelper.createMsResourceParam(str, str2, i, i2, i3, i4, i5, i6), new BaseReqCallback<ReqResult>() {
            public void onResult(boolean z, ReqResult reqResult) {
                OssHttpHelper.this.handleResult("getMsResList", z, reqResult, iCallback, MsResList.class);
            }
        });
    }

    public void getKdFiles(String str, String str2, int i, final ICallback<KdFilesInfo> iCallback) {
        this.mHttpHelper.getFiles(ParamHelper.createGetFilesParam(str, str2, 1, i), new BaseReqCallback<ReqResult>() {
            public void onResult(boolean z, ReqResult reqResult) {
                OssHttpHelper.this.handleResult("getKdFiles", z, reqResult, iCallback, KdFilesInfo.class);
            }
        });
    }

    public void getMsAttachResList(String str, String str2, int i, int i2, int i3, int i4, int i5, int i6, boolean z, final ICallback<MsAttachResList> iCallback) {
        this.mHttpHelper.getMsAttachRes(ParamHelper.createMsAttachResParam(str, str2, i, i2, i3, i4, i5, i6, z ? 2 : 1), new BaseReqCallback<ReqResult>() {
            public void onResult(boolean z2, ReqResult reqResult) {
                OssHttpHelper.this.handleResult("getMsAttachResList", z2, reqResult, iCallback, MsAttachResList.class);
            }
        });
    }

    public void getMsAttachRecommendResList(String str, String str2, int i, int i2, int i3, int i4, int i5, boolean z, final ICallback<MsAttachResList> iCallback) {
        this.mHttpHelper.getMsAttachRecommendRes(ParamHelper.createMsAttachRecommendParam(str, str2, i, i2, i3, i4, i5, z ? 2 : 1), new BaseReqCallback<ReqResult>() {
            public void onResult(boolean z2, ReqResult reqResult) {
                OssHttpHelper.this.handleResult("getMsAttachRecommendResList", z2, reqResult, iCallback, MsAttachResList.class);
            }
        });
    }

    public void getMsAttachResShowList(String str, String str2, int i, int i2, int i3, int i4, int i5, boolean z, final ICallback<VideoTutorialCategoryList> iCallback) {
        this.mHttpHelper.getMsAttachResShow(ParamHelper.createMsAttachResShowParam(str, str2, i, i2, i3, i4, i5, z ? 2 : 1), new BaseReqCallback<ReqResult>() {
            public void onResult(boolean z2, ReqResult reqResult) {
                OssHttpHelper.this.handleResult("getMsAttachResShowList", z2, reqResult, iCallback, VideoTutorialCategoryList.class);
            }
        });
    }

    public void getAllFirstRes(String str, String str2, final ICallback<GetAllFirstResRet> iCallback) {
        this.mHttpHelper.getAllFirstRes(ParamHelper.createGetAllFirstResParam(str, str2), new BaseReqCallback<ReqResult>() {
            public void onResult(boolean z, ReqResult reqResult) {
                OssHttpHelper.this.handleResult("getAllFirstRes", z, reqResult, iCallback, GetAllFirstResRet.class);
            }
        });
    }

    public <T> void handleResult(String str, boolean z, ReqResult reqResult, ICallback<T> iCallback, Type type) {
        Object obj = null;
        boolean z2 = false;
        if (!z) {
            if (iCallback != 0) {
                iCallback.onResult(false, null);
                return;
            }
            return;
        }
        ServerResult serverResult = (ServerResult) reqResult.getServerResult();
        if (serverResult == null) {
            LogUtil.e(TAG, str + " : onResult : 服务器返回结果出错");
            if (iCallback != 0) {
                iCallback.onResult(false, null);
                return;
            }
            return;
        }
        if (serverResult.getCode() == 200) {
            z2 = true;
            try {
                Gson gson = new Gson();
                obj = gson.fromJson(gson.toJson(serverResult.getData()), type);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        LogUtil.i(TAG, str + " : onResult : " + serverResult.getMsg());
        if (iCallback != 0) {
            iCallback.onResult(z2, obj);
        }
    }
}