package com.ifpdos.debugmenu.action;

import android.content.Context;
import android.os.Handler;
import android.util.Log;
import com.google.gson.Gson;
import com.ifpdos.debugmenu.BooleanValue;
import com.ifpdos.debugmenu.R;
import com.ifpdos.debugmenu.action.SuperHighLightSwitchAction;
import com.ifpdos.debugmenu.action.base.ItemSwitchAction;
import com.ifpdos.udi.sdk.IEventHandler;
import com.ifpdos.udi.sdk.UdiSdk;
import d.f.a.j2.e.j;
import d.f.a.r2.j3.e;
import d.f.a.r2.j3.f;
import f.a.y.a;
import g.g;
import g.h0.c.l;
import g.i;
import g.k;
import java.util.List;
import okhttp3.Request;
import okhttp3.Response;

/* JADX INFO: compiled from: SuperHighLightSwitchAction.kt */
/* JADX INFO: loaded from: classes.dex */
@i
public final class SuperHighLightSwitchAction extends ItemSwitchAction {
    public static final Companion Companion = new Companion(null);
    private static final String URL_SUPER_HIGH_LIGHT = "/v1/osservice/superhighlight/switch";
    private static final String URL_SUPER_HIGH_LIGHT_ENABLE = "/v1/osservice/superhighlight/enable";
    private final g gson$delegate;
    private final g mainHandler$delegate;

    /* JADX INFO: compiled from: SuperHighLightSwitchAction.kt */
    @i
    public static final class Companion {
        private Companion() {
        }

        public /* synthetic */ Companion(g.h0.c.g gVar) {
            this();
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public SuperHighLightSwitchAction(Context context) {
        super(context);
        l.f(context, "context");
        this.mainHandler$delegate = a.v0(SuperHighLightSwitchAction$mainHandler$2.INSTANCE);
        this.gson$delegate = a.v0(SuperHighLightSwitchAction$gson$2.INSTANCE);
        UdiSdk.registerEvents((List<String>) a.w0(URL_SUPER_HIGH_LIGHT_ENABLE), new IEventHandler() { // from class: d.f.a.p1.s6
            @Override // com.ifpdos.udi.sdk.IEventHandler
            public final void onEvent(String str, String str2) {
                SuperHighLightSwitchAction._init_$lambda$4(this.a, str, str2);
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void _init_$lambda$4(final SuperHighLightSwitchAction superHighLightSwitchAction, String str, String str2) {
        Object objL;
        l.f(superHighLightSwitchAction, "this$0");
        Log.d(superHighLightSwitchAction.tag, "event: " + str + ", data: " + str2);
        if (l.a(str, URL_SUPER_HIGH_LIGHT_ENABLE)) {
            try {
                final BooleanValue booleanValue = (BooleanValue) superHighLightSwitchAction.getGson().fromJson(str2, BooleanValue.class);
                if (booleanValue != null) {
                    l.e(booleanValue, "fromJson(data, BooleanValue::class.java)");
                    objL = Boolean.valueOf(superHighLightSwitchAction.getMainHandler().post(new Runnable() { // from class: d.f.a.p1.t6
                        /* JADX WARN: Multi-variable type inference failed */
                        @Override // java.lang.Runnable
                        public final void run() {
                            SuperHighLightSwitchAction superHighLightSwitchAction2 = this.f2930b;
                            BooleanValue booleanValue2 = booleanValue;
                            SuperHighLightSwitchAction.Companion companion = SuperHighLightSwitchAction.Companion;
                            g.h0.c.l.f(superHighLightSwitchAction2, "$this_runCatching");
                            g.h0.c.l.f(booleanValue2, "$value");
                            superHighLightSwitchAction2.setEnable((d.f.a.j2.e.j) superHighLightSwitchAction2.mViewModel, booleanValue2.getValue());
                        }
                    }));
                } else {
                    objL = null;
                }
            } catch (Throwable th) {
                objL = a.L(th);
            }
            Throwable thA = g.l.a(objL);
            if (thA != null) {
                Log.e(superHighLightSwitchAction.tag, "onEvent error: ", thA);
            }
        }
    }

    private final Gson getGson() {
        return (Gson) this.gson$delegate.getValue();
    }

    private final Handler getMainHandler() {
        return (Handler) this.mainHandler$delegate.getValue();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void onSwitch$lambda$5(SuperHighLightSwitchAction superHighLightSwitchAction) {
        l.f(superHighLightSwitchAction, "this$0");
        superHighLightSwitchAction.postRequest(true);
        c.n.a.o();
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Multi-variable type inference failed */
    public static final void onSwitch$lambda$6(SuperHighLightSwitchAction superHighLightSwitchAction) {
        l.f(superHighLightSwitchAction, "this$0");
        superHighLightSwitchAction.mSave = null;
        ((j) superHighLightSwitchAction.mViewModel).e();
        c.n.a.o();
    }

    private final void postRequest(boolean z) {
        e.a.c(URL_SUPER_HIGH_LIGHT, a.y0(new k("value", String.valueOf(z))), new f<String>() { // from class: com.ifpdos.debugmenu.action.SuperHighLightSwitchAction.postRequest.1
            @Override // d.f.a.r2.j3.f, d.f.a.r2.j3.c
            public void onError(Response response, int i2, Exception exc) {
                Log.e(SuperHighLightSwitchAction.this.tag, "onError: " + i2, exc);
            }

            @Override // d.f.a.r2.j3.f, d.f.a.r2.j3.c
            public void onFailure(Request request, Exception exc) {
                l.f(exc, "e");
                Log.e(SuperHighLightSwitchAction.this.tag, "onFailure:", exc);
            }

            @Override // d.f.a.r2.j3.f, d.f.a.r2.j3.c
            public void onSuccess(Response response, String str) {
                d.b.a.a.a.N("onSuccess: ", str, SuperHighLightSwitchAction.this.tag);
            }
        });
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemSwitchAction
    public boolean isEnable() {
        BooleanValue booleanValue = (BooleanValue) e.a.b(URL_SUPER_HIGH_LIGHT_ENABLE, BooleanValue.class);
        if (booleanValue != null) {
            return booleanValue.getValue();
        }
        return false;
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemSwitchAction
    public boolean isOn(Context context) {
        BooleanValue booleanValue = (BooleanValue) e.a.b(URL_SUPER_HIGH_LIGHT, BooleanValue.class);
        if (booleanValue != null) {
            return booleanValue.getValue();
        }
        return false;
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemSwitchAction
    public void onSwitch(Context context, boolean z) {
        l.f(context, "context");
        if (z) {
            c.n.a.W(R.string.str_super_high_light, R.string.str_super_high_light_tip, new d.f.a.s1.e() { // from class: d.f.a.p1.r6
                @Override // d.f.a.s1.e
                public final void call() {
                    SuperHighLightSwitchAction.onSwitch$lambda$5(this.a);
                }
            }, new d.f.a.s1.e() { // from class: d.f.a.p1.q6
                @Override // d.f.a.s1.e
                public final void call() {
                    SuperHighLightSwitchAction.onSwitch$lambda$6(this.a);
                }
            });
        } else {
            postRequest(false);
        }
    }
}
