package com.ifpdos.debugmenu.action.base;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
import c.l.n;
import com.ifpdos.debugmenu.R;
import com.ifpdos.debugmenu.action.base.ItemInfoAction;
import com.trello.rxlifecycle3.android.ActivityEvent;
import com.trello.rxlifecycle3.components.support.RxAppCompatActivity;
import d.b.a.a.a;
import d.f.a.i2.b;
import d.f.a.j2.e.f;
import f.a.j;
import f.a.w.e.d.c;
import f.a.w.e.d.d;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

/* JADX INFO: loaded from: classes.dex */
public abstract class ItemInfoAction extends AbstractItemAction<f> implements f.a {
    private static final int GET_VALUE_RETRY_COUNT = 20;
    private static final int GET_VALUE_RETRY_INTERVAL = 300;
    private static final String TAG = "ItemInfoAction";
    private int color;
    private boolean isFinish;
    private String item_data;
    public String standard_data;

    public ItemInfoAction(Context context) {
        super(context);
        this.color = -1;
    }

    private String getValueWithRetry(Context context) {
        StringBuilder sbB = a.B("Item.");
        sbB.append(getClass().getSimpleName());
        String string = sbB.toString();
        Log.d(TAG, string + " getValueWithRetry: ---> beginning <---");
        String value = getValue(context);
        boolean zIsValueEffective = isValueEffective(value);
        int i2 = 0;
        while (!zIsValueEffective && i2 <= 20) {
            value = getValue(context);
            zIsValueEffective = isValueEffective(value);
            i2++;
            SystemClock.sleep(300L);
        }
        Log.d(TAG, string + " getValueWithRetry: value = " + value + ", retryCount = " + i2);
        StringBuilder sb = new StringBuilder();
        sb.append(string);
        sb.append(" getValueWithRetry: ---> ending <---");
        Log.d(TAG, sb.toString());
        return value;
    }

    public int getColor(Context context) {
        return this.color;
    }

    public abstract String getValue(Context context);

    public /* synthetic */ void h(Context context, j jVar) {
        String string;
        try {
            string = getValueWithRetry(context);
        } catch (Exception e2) {
            Log.i(TAG, e2.getMessage());
            string = this.mContext.getString(R.string.fail);
        }
        c.a aVar = (c.a) jVar;
        aVar.d(string);
        aVar.b();
    }

    public void i(f fVar, String str) {
        this.isFinish = true;
        this.item_data = str;
        fVar.f2613g.i(str);
        setInfoColor(this.standard_data, this.item_data);
        fVar.f2616j.i(Boolean.TRUE);
        Log.i(TAG, "subscribe Key: " + fVar.f2612f.d() + " Value: " + str);
    }

    public boolean isValueEffective(String str) {
        return true;
    }

    public void setColor(int i2) {
        this.color = i2;
    }

    /* JADX WARN: Multi-variable type inference failed */
    public void setInfoColor(String str) {
        this.standard_data = str;
        String strD = ((f) this.mViewModel).f2613g.d();
        if (this.isFinish) {
            setInfoColor(str, strD);
        }
    }

    @Override // d.f.a.j2.e.f.a
    public void textViewClick() {
    }

    /* JADX WARN: Multi-variable type inference failed */
    @Override // com.ifpdos.debugmenu.action.base.AbstractItemAction
    public void onAttachViewModel(n nVar, f fVar) {
        super.onAttachViewModel(nVar, fVar);
        VM vm = this.mViewModel;
        ((f) vm).f2601b = this;
        ((f) vm).f2618l = this;
    }

    @Override // com.ifpdos.debugmenu.action.base.AbstractItemAction, d.f.a.j2.e.d.a
    @SuppressLint({"CheckResult"})
    public void onBind(final Context context, final f fVar) {
        fVar.f2613g.i(context.getString(R.string.device_loading));
        new d(new Callable() { // from class: d.f.a.p1.oh.d
            @Override // java.util.concurrent.Callable
            public final Object call() {
                final ItemInfoAction itemInfoAction = this.f2860b;
                final Context context2 = context;
                Objects.requireNonNull(itemInfoAction);
                return new f.a.w.e.d.c(new f.a.k() { // from class: d.f.a.p1.oh.c
                    @Override // f.a.k
                    public final void subscribe(f.a.j jVar) {
                        itemInfoAction.h(context2, jVar);
                    }
                });
            }
        }).y(10L, TimeUnit.SECONDS).w(b.a().f2586b).n(f.a.s.b.a.a()).g(((RxAppCompatActivity) this.mContext).bindUntilEvent(ActivityEvent.DESTROY)).u(new f.a.v.c() { // from class: d.f.a.p1.oh.f
            @Override // f.a.v.c
            public final void accept(Object obj) {
                this.f2864b.i(fVar, (String) obj);
            }
        }, new f.a.v.c() { // from class: d.f.a.p1.oh.e
            @Override // f.a.v.c
            public final void accept(Object obj) {
                ItemInfoAction itemInfoAction = this.f2862b;
                d.f.a.j2.e.f fVar2 = fVar;
                Objects.requireNonNull(itemInfoAction);
                Log.e("ItemInfoAction", "Throwable:" + fVar2.f2612f.d(), (Throwable) obj);
                fVar2.f2613g.i(itemInfoAction.mContext.getString(R.string.fail));
                fVar2.f2615i.i(-65536);
                fVar2.f2616j.i(Boolean.TRUE);
            }
        }, f.a.w.b.a.f3725b, f.a.w.b.a.f3726c);
    }

    /* JADX WARN: Multi-variable type inference failed */
    public void setInfoColor(String str, String str2) {
        Log.i(TAG, "standard_data = " + str + "  data = " + str2);
        this.standard_data = str;
        if (!TextUtils.isEmpty(str) && !this.mContext.getString(R.string.fail).equals(str2)) {
            this.color = str.equals(str2) ? -16711936 : -65536;
        } else {
            this.color = this.mContext.getString(R.string.fail).equals(str2) ? -65536 : this.mContext.getString(R.string.pass).equals(str2) ? -16711936 : this.color;
        }
        if (this.mContext.getString(R.string.device_loading).equals(str2)) {
            this.color = -1;
        }
        if (this.mContext.getString(R.string.str_factory_serial_number).equals(((f) this.mViewModel).f2612f.d()) && this.isFinish && !TextUtils.isEmpty(str)) {
            if (!TextUtils.isEmpty(str2) && !this.mContext.getString(R.string.pass).equals(str2)) {
                this.color = -65536;
            } else {
                this.item_data = this.mContext.getString(R.string.pass);
                ((f) this.mViewModel).f2616j.i(Boolean.TRUE);
                ((f) this.mViewModel).f2613g.i(this.item_data);
                this.color = -16711936;
            }
        }
        ((f) this.mViewModel).f2615i.i(Integer.valueOf(this.color));
    }
}
