package com.tencent.mm.plugin.webview.luggage.a;

import android.os.Bundle;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.ipcinvoker.wx_extension.service.ToolsProcessIPCService;
import com.tencent.mm.plugin.downloader.b.a$b;
import com.tencent.mm.plugin.downloader.f.a;
import com.tencent.mm.plugin.downloader.model.c;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ah;
import com.tencent.mm.sdk.platformtools.at;
import org.json.JSONException;
import org.json.JSONObject;

public class b$1 implements a$b {
    public final void E(int i, long j) {
        AppMethodBeat.i(6421);
        a hv;
        JSONObject jSONObject;
        Bundle bundle;
        switch (i) {
            case 1:
                hv = c.hv(j);
                if (hv != null) {
                    jSONObject = new JSONObject();
                    try {
                        jSONObject.put("appid", hv.field_appId);
                        jSONObject.put("download_id", hv.field_downloadId);
                        jSONObject.put("state", "download_start");
                        bundle = new Bundle();
                        bundle.putString("name", "wxdownload:state_change");
                        bundle.putString("data", jSONObject.toString());
                        ToolsProcessIPCService.a(bundle, a.class, null);
                        AppMethodBeat.o(6421);
                        return;
                    } catch (JSONException e) {
                    }
                }
                AppMethodBeat.o(6421);
                return;
            case 2:
                hv = c.hv(j);
                if (hv != null) {
                    jSONObject = new JSONObject();
                    try {
                        jSONObject.put("appid", hv.field_appId);
                        jSONObject.put("download_id", hv.field_downloadId);
                        if (hv.field_fromDownloadApp && hv.field_downloadInWifi && !at.isWifi(ah.getContext())) {
                            jSONObject.put("state", "download_wait_for_wifi");
                        } else {
                            jSONObject.put("state", "download_pause");
                        }
                        bundle = new Bundle();
                        bundle.putString("name", "wxdownload:state_change");
                        bundle.putString("data", jSONObject.toString());
                        ToolsProcessIPCService.a(bundle, a.class, null);
                        AppMethodBeat.o(6421);
                        return;
                    } catch (JSONException e2) {
                    }
                }
                AppMethodBeat.o(6421);
                return;
            case 3:
                hv = c.hv(j);
                if (hv != null) {
                    jSONObject = new JSONObject();
                    try {
                        jSONObject.put("appid", hv.field_appId);
                        jSONObject.put("download_id", hv.field_downloadId);
                        jSONObject.put("state", "download_succ");
                        bundle = new Bundle();
                        bundle.putString("name", "wxdownload:state_change");
                        bundle.putString("data", jSONObject.toString());
                        ToolsProcessIPCService.a(bundle, a.class, null);
                        AppMethodBeat.o(6421);
                        return;
                    } catch (JSONException e3) {
                    }
                }
                AppMethodBeat.o(6421);
                return;
            case 4:
                hv = c.hv(j);
                if (hv != null) {
                    jSONObject = new JSONObject();
                    try {
                        jSONObject.put("appid", hv.field_appId);
                        jSONObject.put("download_id", hv.field_downloadId);
                        jSONObject.put("state", "download_removed");
                        bundle = new Bundle();
                        bundle.putString("name", "wxdownload:state_change");
                        bundle.putString("data", jSONObject.toString());
                        ToolsProcessIPCService.a(bundle, a.class, null);
                        AppMethodBeat.o(6421);
                        return;
                    } catch (JSONException e4) {
                    }
                }
                AppMethodBeat.o(6421);
                return;
            case 5:
                hv = c.hv(j);
                if (hv != null) {
                    jSONObject = new JSONObject();
                    try {
                        jSONObject.put("appid", hv.field_appId);
                        jSONObject.put("download_id", hv.field_downloadId);
                        jSONObject.put("state", "download_fail");
                        bundle = new Bundle();
                        bundle.putString("name", "wxdownload:state_change");
                        bundle.putString("data", jSONObject.toString());
                        ToolsProcessIPCService.a(bundle, a.class, null);
                        AppMethodBeat.o(6421);
                        return;
                    } catch (JSONException e5) {
                    }
                }
                AppMethodBeat.o(6421);
                return;
            case 6:
                hv = c.hv(j);
                if (hv != null && hv.field_totalSize != 0) {
                    int i2 = (int) ((((double) hv.field_downloadedSize) / ((double) hv.field_totalSize)) * 100.0d);
                    ab.d("MicroMsg.JsDownloadEventDispatch", "onDownloadTaskProgressChanged, progressFloat: %f", new Object[]{Float.valueOf((((float) hv.field_downloadedSize) / ((float) hv.field_totalSize)) * 100.0f)});
                    JSONObject jSONObject2 = new JSONObject();
                    try {
                        jSONObject2.put("appid", hv.field_appId);
                        jSONObject2.put("download_id", hv.field_downloadId);
                        jSONObject2.put("progress", i2);
                        jSONObject2.put("progress_float", (double) r2);
                        bundle = new Bundle();
                        bundle.putString("name", "wxdownload:progress_change");
                        bundle.putString("data", jSONObject2.toString());
                        ToolsProcessIPCService.a(bundle, a.class, null);
                        AppMethodBeat.o(6421);
                        return;
                    } catch (JSONException e6) {
                        break;
                    }
                }
                ab.w("MicroMsg.JsDownloadEventDispatch", "loadDownloadProgress failed");
                AppMethodBeat.o(6421);
                return;
                break;
            case 7:
                hv = c.hv(j);
                if (hv != null) {
                    jSONObject = new JSONObject();
                    try {
                        jSONObject.put("appid", hv.field_appId);
                        jSONObject.put("download_id", hv.field_downloadId);
                        jSONObject.put("state", "download_resumed");
                        bundle = new Bundle();
                        bundle.putString("name", "wxdownload:state_change");
                        bundle.putString("data", jSONObject.toString());
                        ToolsProcessIPCService.a(bundle, a.class, null);
                        AppMethodBeat.o(6421);
                        return;
                    } catch (JSONException e7) {
                    }
                }
                AppMethodBeat.o(6421);
                return;
        }
        AppMethodBeat.o(6421);
    }
}
