package com.ifpdos.debugmenu.action.base;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import c.l.n;
import c.l.t;
import com.trello.rxlifecycle3.android.ActivityEvent;
import com.trello.rxlifecycle3.components.support.RxAppCompatActivity;
import d.f.a.i2.b;
import d.f.a.j2.e.i;
import f.a.s.b.a;
import f.a.v.c;
import f.a.v.d;
import f.a.w.e.d.s;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

/* JADX INFO: loaded from: classes.dex */
public abstract class ItemSelectAction extends AbstractItemAction<i> {
    private static final String TAG = "ItemSelectAction";
    private List<String> mEntries;
    private int mLastIndex;
    public Integer mSave;
    private Integer mSelection;

    public ItemSelectAction(Context context) {
        super(context);
        this.mLastIndex = -1;
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Multi-variable type inference failed */
    public void setNextItem() {
        Integer numD = ((i) this.mViewModel).f2627l.d();
        this.mSelection = numD;
        if (numD == null) {
            return;
        }
        if (numD.intValue() < this.mEntries.size() - 1) {
            this.mSelection = Integer.valueOf(this.mSelection.intValue() + 1);
        } else {
            this.mSelection = 0;
        }
        ((i) this.mViewModel).f2627l.i(this.mSelection);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Multi-variable type inference failed */
    public void setPrevItem() {
        Integer numD = ((i) this.mViewModel).f2627l.d();
        this.mSelection = numD;
        if (numD == null) {
            return;
        }
        if (numD.intValue() > 0) {
            this.mSelection = Integer.valueOf(this.mSelection.intValue() - 1);
        } else {
            this.mSelection = Integer.valueOf(this.mEntries.size() - 1);
        }
        ((i) this.mViewModel).f2627l.i(this.mSelection);
    }

    public abstract List<String> getEntryList(Context context);

    public abstract int getSelectIndex(Context context);

    public /* synthetic */ void h(Integer num) {
        Integer num2 = this.mSave;
        if (num2 == null || num == num2) {
            this.mSave = num;
            return;
        }
        this.mSave = num;
        if (this.mLastIndex != -1) {
            Log.d(TAG, String.format(Locale.US, "%s.java # onSelect(Context context, int index) execute, index = %d", this.mClassName, num));
            onSelect(this.mContext, num.intValue());
        }
    }

    public /* synthetic */ void i(i iVar, Integer num) {
        iVar.f(num.intValue());
        int iIntValue = num.intValue();
        this.mLastIndex = iIntValue;
        Log.d(TAG, String.format(Locale.US, "%s.java # getSelectIndex(Context context) execute over, resultIndex = %d, mLastIndex = %d", this.mClassName, num, Integer.valueOf(iIntValue)));
    }

    public boolean isEnable() {
        return true;
    }

    public /* synthetic */ void j(Throwable th) {
        Log.e(TAG, String.format(Locale.US, "%s.java # getSelectIndex(Context context) execute with a Exception/Error, mLastIndex = %d", this.mClassName, Integer.valueOf(this.mLastIndex)), th);
    }

    public abstract void onSelect(Context context, int i2);

    public void setEnable(i iVar, boolean z) {
        iVar.f2624i.i(Boolean.valueOf(z));
        if (z) {
            iVar.f2625j.i(-1);
        } else {
            iVar.f2625j.i(-7829368);
        }
    }

    /* JADX WARN: Can't rename method to resolve collision */
    /* JADX WARN: Multi-variable type inference failed */
    @Override // com.ifpdos.debugmenu.action.base.AbstractItemAction
    public void onAttachViewModel(n nVar, i iVar) {
        super.onAttachViewModel(nVar, iVar);
        VM vm = this.mViewModel;
        ((i) vm).f2601b = this;
        ((i) vm).f2627l.e(nVar, new t() { // from class: d.f.a.p1.oh.l
            @Override // c.l.t
            public final void d(Object obj) {
                this.a.h((Integer) obj);
            }
        });
    }

    /* JADX WARN: Multi-variable type inference failed */
    @Override // com.ifpdos.debugmenu.action.base.AbstractItemAction, d.f.a.j2.e.d.a
    @SuppressLint({"CheckResult"})
    public void onBind(final Context context, final i iVar) {
        List<String> entryList = getEntryList(context);
        this.mEntries = entryList;
        iVar.e(entryList);
        new s(f.a.i.m(Boolean.TRUE), new d() { // from class: d.f.a.p1.oh.i
            @Override // f.a.v.d
            public final Object apply(Object obj) {
                return Integer.valueOf(this.f2868b.getSelectIndex(context));
            }
        }).w(b.a().f2586b).n(a.a()).y(10L, TimeUnit.SECONDS).g(((RxAppCompatActivity) this.mContext).bindUntilEvent(ActivityEvent.DESTROY)).u(new c() { // from class: d.f.a.p1.oh.k
            @Override // f.a.v.c
            public final void accept(Object obj) {
                this.f2871b.i(iVar, (Integer) obj);
            }
        }, new c() { // from class: d.f.a.p1.oh.j
            @Override // f.a.v.c
            public final void accept(Object obj) {
                this.f2870b.j((Throwable) obj);
            }
        }, f.a.w.b.a.f3725b, f.a.w.b.a.f3726c);
        ((i) this.mViewModel).m = new i.a() { // from class: com.ifpdos.debugmenu.action.base.ItemSelectAction.1
            @Override // d.f.a.j2.e.i.a
            public void keyEvent(View view, int i2, KeyEvent keyEvent) {
                if (keyEvent.getAction() == 0) {
                    if (i2 == 21) {
                        ItemSelectAction.this.setPrevItem();
                    } else if (i2 == 22) {
                        ItemSelectAction.this.setNextItem();
                    }
                }
            }
        };
        setEnable(iVar, isEnable());
    }
}
