package com.ifpdos.debugmenu.action;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import com.ifpdos.debugmenu.action.base.ItemSelectAction;
import com.ifpdos.debugmenu.entity.SwitchWithSourceBody;
import d.b.a.a.a;
import d.f.a.r2.j3.e;
import d.f.a.r2.j3.f;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class NFCSwitchWithSourceAction extends ItemSelectAction {
    private final String TAG;
    private final String URL_UDI;
    private final List<String> mOptionsForInvoke;

    public NFCSwitchWithSourceAction(Context context) {
        super(context);
        this.mOptionsForInvoke = getOptionsForInvoke();
        this.URL_UDI = getRequestUdiUrl();
        this.TAG = getClass().getSimpleName();
    }

    private String getStringFromResourceByKeyName(String str) {
        if (!TextUtils.isEmpty(str) && !"".equals(str.trim())) {
            try {
                return this.mContext.getString(this.mContext.getResources().getIdentifier(str, "string", this.mContext.getPackageName()));
            } catch (Exception unused) {
            }
        }
        return null;
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemSelectAction
    public List<String> getEntryList(Context context) {
        ArrayList arrayList = new ArrayList();
        Iterator<String> it = this.mOptionsForInvoke.iterator();
        while (it.hasNext()) {
            arrayList.add(getStringFromResourceByKeyName(it.next()));
        }
        return arrayList;
    }

    public List<String> getOptionsForInvoke() {
        return Arrays.asList(SwitchWithSourceBody.SwitchWithSourceMode.ANDROID.name(), SwitchWithSourceBody.SwitchWithSourceMode.WITH_CHANNEL.name());
    }

    public String getRequestUdiUrl() {
        return "/v1/system/usb/nfc/source";
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemSelectAction
    public int getSelectIndex(Context context) {
        SwitchWithSourceBody switchWithSourceBody = (SwitchWithSourceBody) e.a.b(this.URL_UDI, SwitchWithSourceBody.class);
        if (switchWithSourceBody == null) {
            Log.d(this.TAG, "getSelectIndex: [1/2] currentUsbDeviceSwitchWithSourceData is null, indexResult = 0");
            return 0;
        }
        String str = this.TAG;
        StringBuilder sbB = a.B("getSelectIndex: [1.5/2] valueBody = ");
        sbB.append(switchWithSourceBody.toString());
        Log.d(str, sbB.toString());
        String str2 = switchWithSourceBody.getMode() + "";
        int iIndexOf = this.mOptionsForInvoke.indexOf(str2);
        Log.d(this.TAG, "getSelectIndex: [2/2] currentUsbDeviceSwitchWithSourceModeStr = " + str2 + ", SwitchWithSourceModeIndex = " + iIndexOf);
        return iIndexOf;
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemSelectAction
    public void onSelect(Context context, int i2) {
        String str = this.mOptionsForInvoke.get(i2);
        HashMap map = new HashMap();
        map.put("value", str);
        Log.d(this.TAG, "onSelect: called, setUsbDeviceSwitchWithSourceMode into Udi, index = " + i2 + ", currentUsbDeviceSwitchWithSourceModeSet = " + str);
        e.a.c(this.URL_UDI, map, new f(this.mContext));
    }
}
