package com.ss.android.ugc.aweme.fe.method;

import X.0CB;
import X.0CH;
import X.0CN;
import X.6Is;
import X.C0753KGa;
import X.C0865KKi;
import X.FIu;
import X.KGV;
import X.KGW;
import android.content.Context;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.commercialize.event.AdCardClose;
import com.ss.android.ugc.aweme.fe.base.BaseCommonJavaMethod;
import java.lang.ref.WeakReference;
import org.json.JSONObject;

public class JsAppDownloadMethod extends BaseCommonJavaMethod implements 6Is, KGW {
    public KGV LIZ;

    static {
        Covode.recordClassIndex(76084);
    }

    @0CN(LIZ = 0CB.ON_PAUSE)
    public void onPause() {
    }

    public void onStateChanged(0CH r2, 0CB r3) {
        super.onStateChanged(r2, r3);
        if (r3 == 0CB.ON_RESUME) {
            onResume();
        } else if (r3 == 0CB.ON_PAUSE) {
            onPause();
        } else if (r3 == 0CB.ON_DESTROY) {
            onDestroy();
        }
    }

    @0CN(LIZ = 0CB.ON_DESTROY)
    public void onDestroy() {
        if (this.LIZ != null && this.mContextRef != null && this.mContextRef.get() != null) {
            this.LIZ = null;
        }
    }

    @0CN(LIZ = 0CB.ON_RESUME)
    public void onResume() {
        if (this.LIZ != null && this.mContextRef != null && this.mContextRef.get() != null) {
            this.mContextRef.get();
        }
    }

    public JsAppDownloadMethod(C0865KKi kKi) {
        super(kKi);
    }

    public BaseCommonJavaMethod attach(WeakReference<Context> weakReference) {
        0CH r1 = (Context) weakReference.get();
        if (r1 instanceof 0CH) {
            r1.getLifecycle().LIZ(this);
        }
        super.attach(weakReference);
        return this;
    }

    public void handle(JSONObject jSONObject, FIu fIu) {
        if (this.mContextRef != null && this.mContextRef.get() != null) {
            if (this.LIZ == null) {
                this.mContextRef.get();
                this.LIZ = new KGV(this);
            }
            String optString = jSONObject.optString("func");
            if (TextUtils.equals("subscribe_app_ad", optString)) {
                if (this.mContextRef.get() != null) {
                    new C0753KGa().LIZ(jSONObject.optJSONObject("data"));
                }
            } else if (TextUtils.equals("unsubscribe_app_ad", optString)) {
                if (this.LIZ != null) {
                    new C0753KGa().LIZ(jSONObject.optJSONObject("data"));
                }
            } else if (TextUtils.equals("download_app_ad", optString)) {
                if (this.LIZ != null && this.mContextRef.get() != null) {
                    JSONObject optJSONObject = jSONObject.optJSONObject("data");
                    new C0753KGa().LIZ(optJSONObject);
                    JSONObject optJSONObject2 = optJSONObject.optJSONObject("extParam");
                    if (optJSONObject2 != null) {
                        optJSONObject2.optString("refer");
                        optJSONObject2.optJSONObject("ad_extra_data");
                    }
                    new AdCardClose(-1).post();
                }
            } else if (TextUtils.equals("cancel_download_app_ad", optString)) {
                KGV kgv = this.LIZ;
                if (kgv != null && kgv.LIZIZ != null) {
                    new C0753KGa().LIZ(jSONObject.optJSONObject("data"));
                }
            } else if (TextUtils.equals("get_download_pause_task", optString)) {
                if (this.LIZ == null) {
                }
            } else if (TextUtils.equals("get_downloading_task", optString)) {
                if (this.LIZ == null) {
                }
            } else if (TextUtils.equals("get_install_status", optString) && this.LIZ != null && jSONObject.length() != 0) {
                jSONObject.optJSONArray("task_list");
            }
        }
    }
}
