package com.ifpdos.debugmenu.action;

import android.content.Context;
import android.util.Log;
import com.ifpdos.debugmenu.R;
import com.ifpdos.debugmenu.action.base.ItemSelectAction;
import com.ifpdos.debugmenu.entity.HdmiOutFormatBody;
import com.ifpdos.debugmenu.entity.ListBody;
import com.ifpdos.debugmenu.event.ViewEvent;
import com.seewo.sdk.SDKDeviceHelper;
import d.f.a.i2.a;
import d.f.a.j2.e.i;
import d.f.a.r2.j3.e;
import d.f.a.r2.j3.f;
import d.f.a.r2.r2;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.Consumer;
import k.c.a.c;
import k.c.a.j;
import org.greenrobot.eventbus.ThreadMode;

/* JADX INFO: loaded from: classes.dex */
public class HDMIOutFormat3588Action extends ItemSelectAction {
    private static final String FORMAT_480P = "480P_60HZ";
    private static final String FORMAT_PREFIX = "FMT_";
    private static final String PROP_NEED_REBOOT = "persist.sys.hdmi_resolution_tip";
    private static final String TAG = "HDMIOutFormatAction";
    private static final String URL_UDI = "/v1/source/hdmi/out/format";
    private static final String URL_UDI_RESOLUTION_LIST = "/v1/source/out/resolution/list";
    private List<String> mNotSupportDvi;

    public HDMIOutFormat3588Action(Context context) {
        super(context);
        this.mNotSupportDvi = getFormatList();
        a.a().f2585b.add(this);
        c.c().k(this);
    }

    private List<String> formatsToEntryList(List<String> list) {
        final ArrayList arrayList = new ArrayList();
        list.forEach(new Consumer() { // from class: d.f.a.p1.u2
            @Override // java.util.function.Consumer
            public final void accept(Object obj) {
                arrayList.add(((String) obj).replace("FMT_", ""));
            }
        });
        if (!arrayList.contains(FORMAT_480P)) {
            arrayList.add(FORMAT_480P);
            this.mNotSupportDvi.add("FMT_480P_60HZ");
        }
        Log.d(TAG, "formatsToEntryList: formatResultList = " + arrayList);
        return arrayList;
    }

    private List<String> getFormatList() {
        ListBody listBody = (ListBody) e.a.b(URL_UDI_RESOLUTION_LIST, ListBody.class);
        StringBuilder sbB = d.b.a.a.a.B("getFormatList: dataList = ");
        Object list = "null";
        if (listBody != null && listBody.getList() != null) {
            list = listBody.getList();
        }
        sbB.append(list);
        Log.d(TAG, sbB.toString());
        return listBody != null ? listBody.getList() : new ArrayList();
    }

    private void postResolutionDisplayEvent(String str) {
        c.c().g(new ViewEvent.UpdateViewEnable(r2.TYPE_C_OUT_FORMAT.ordinal(), !HdmiOutFormatBody.HdmiOutFormatEnum.isOverFourResolutionDisplay(str)));
    }

    /* JADX WARN: Multi-variable type inference failed */
    @j(threadMode = ThreadMode.MAIN)
    public void event(ViewEvent.UpdateViewEntries updateViewEntries) {
        if (updateViewEntries.viewId != r2.HDMI_DVI.ordinal()) {
            Log.d(TAG, "event: event.viewId != Constant.ViewID.HDMI_DVI.ordinal(), ignore event and operation...");
            return;
        }
        List<String> formatList = getFormatList();
        this.mNotSupportDvi = formatList;
        ((i) this.mViewModel).e(formatsToEntryList(formatList));
        int selectIndex = getSelectIndex(this.mContext);
        Log.d(TAG, "on event, change select index " + selectIndex);
        ((i) this.mViewModel).f(selectIndex);
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemSelectAction
    public List<String> getEntryList(Context context) {
        return formatsToEntryList(this.mNotSupportDvi);
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemSelectAction
    public int getSelectIndex(Context context) {
        List<String> list = this.mNotSupportDvi;
        if (list == null || list.isEmpty()) {
            Log.d(TAG, "getSelectIndex: [1/3] HdmiFormatDataList is null or Empty, indexResult = 0");
            return 0;
        }
        StringBuilder sbB = d.b.a.a.a.B("getSelectIndex: [1/3] HdmiFormatDataList = ");
        sbB.append(this.mNotSupportDvi);
        sbB.append(", HdmiFormatDataList.size() = ");
        sbB.append(this.mNotSupportDvi.size());
        Log.d(TAG, sbB.toString());
        HdmiOutFormatBody hdmiOutFormatBody = (HdmiOutFormatBody) e.a.b(URL_UDI, HdmiOutFormatBody.class);
        if (hdmiOutFormatBody == null) {
            Log.d(TAG, "getSelectIndex: [2/3] currentHdmiFormatData is null, indexResult = 0");
            return 0;
        }
        String str = hdmiOutFormatBody.getFormat() + "";
        postResolutionDisplayEvent(str);
        int iIndexOf = this.mNotSupportDvi.indexOf(str);
        Log.d(TAG, "getSelectIndex: [3/3] currentHdmiFormatDataStr = " + str + ", currentHdmiFormatIndex = " + iIndexOf);
        return iIndexOf;
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemSelectAction
    public boolean isEnable() {
        return SDKDeviceHelper.I.isHDMIoutWhenHDMIinEnable();
    }

    /* JADX WARN: Multi-variable type inference failed */
    @j(threadMode = ThreadMode.MAIN)
    public void onEvent(ViewEvent.UpdateViewEnable updateViewEnable) {
        int i2 = updateViewEnable.viewId;
        if (i2 == r2.HDMI_DVI.ordinal() || i2 == r2.TYPE_C_OUT_FORMAT1.ordinal()) {
            d.b.a.a.a.V(d.b.a.a.a.B("onEvent: UpdateViewEnable "), updateViewEnable.isEnabled, TAG);
            if (!updateViewEnable.isEnabled) {
                setEnable((i) this.mViewModel, false);
                return;
            }
            setEnable((i) this.mViewModel, true);
            Integer numD = ((i) this.mViewModel).f2627l.d();
            if (numD != null) {
                postResolutionDisplayEvent(this.mNotSupportDvi.get(numD.intValue()));
            }
        }
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemSelectAction
    public void onSelect(Context context, int i2) {
        HashMap map = new HashMap();
        String str = this.mNotSupportDvi.get(i2);
        map.put("format", str);
        e.a.c(URL_UDI, map, new f(this.mContext));
        postResolutionDisplayEvent(str);
        Log.d(TAG, "onSelect: called, setHdmiFormatData into Udi, index = " + i2 + ", currentHdmiFormatDataSet = " + str);
        if (d.i.f.c.c.g(PROP_NEED_REBOOT, false)) {
            c.n.a.d0(R.string.str_hdmi_hdmiout_format_tip);
        }
    }
}
