package com.ifpdos.debugmenu.action;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import com.cvte.vman.VmanMiddleWare;
import com.cvte.vman.impl.FwUpgradeManager;
import com.ifpdos.debugmenu.R;
import com.ifpdos.debugmenu.action.Show817VersionNoCompareAction;
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.j2.e.f;
import d.f.a.r2.k3.b;
import d.f.a.v0;
import f.a.j;
import f.a.k;
import f.a.w.e.d.c;
import g.a0;
import g.h0.b.l;
import g.h0.c.g;
import g.h0.c.m;
import g.i;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/* JADX INFO: compiled from: Show817VersionNoCompareAction.kt */
/* JADX INFO: loaded from: classes.dex */
@i
public final class Show817VersionNoCompareAction extends ItemInfoAction implements v0 {
    public static final Companion Companion = new Companion(null);
    private static final String TAG = "VL817NoCompareVersion";

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

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

    /* JADX INFO: renamed from: com.ifpdos.debugmenu.action.Show817VersionNoCompareAction$get817Version$2, reason: invalid class name */
    /* JADX INFO: compiled from: Show817VersionNoCompareAction.kt */
    @i
    public static final class AnonymousClass2 extends m implements l<String, a0> {
        public AnonymousClass2() {
            super(1);
        }

        @Override // g.h0.b.l
        public /* bridge */ /* synthetic */ a0 invoke(String str) {
            invoke2(str);
            return a0.a;
        }

        /* JADX INFO: renamed from: invoke, reason: avoid collision after fix types in other method */
        public final void invoke2(String str) {
            g.h0.c.l.f(str, "res");
            if (str.length() > 0) {
                ((f) Show817VersionNoCompareAction.this.mViewModel).f2613g.i(str);
            } else {
                ((f) Show817VersionNoCompareAction.this.mViewModel).f2613g.i(Show817VersionNoCompareAction.this.mContext.getString(R.string.fail));
            }
        }
    }

    /* JADX INFO: renamed from: com.ifpdos.debugmenu.action.Show817VersionNoCompareAction$get817Version$3, reason: invalid class name */
    /* JADX INFO: compiled from: Show817VersionNoCompareAction.kt */
    @i
    public static final class AnonymousClass3 extends m implements l<Throwable, a0> {
        public AnonymousClass3() {
            super(1);
        }

        @Override // g.h0.b.l
        public /* bridge */ /* synthetic */ a0 invoke(Throwable th) {
            invoke2(th);
            return a0.a;
        }

        /* JADX INFO: renamed from: invoke, reason: avoid collision after fix types in other method */
        public final void invoke2(Throwable th) {
            g.h0.c.l.f(th, "throwable");
            if (th instanceof TimeoutException) {
                f fVar = (f) Show817VersionNoCompareAction.this.mViewModel;
                fVar.f2613g.i(Show817VersionNoCompareAction.this.mContext.getString(R.string.fail));
            }
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public Show817VersionNoCompareAction(Context context) {
        super(context);
        g.h0.c.l.f(context, "context");
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void get817Version$lambda$2(j jVar) {
        g.h0.c.l.f(jVar, "emitter");
        String fwVersion = VmanMiddleWare.getInstance().getFwUpgrade().getFwVersion(12);
        Log.i(TAG, "result: " + fwVersion);
        g.h0.c.l.e(fwVersion, "result");
        String str = (String) g.m0.f.E(fwVersion, new String[]{","}, false, 0, 6).get(0);
        a.O("info817: ", str, TAG);
        String strSubstring = str.substring(g.m0.f.m(str, ":", 0, false, 6) + 1);
        g.h0.c.l.e(strSubstring, "this as java.lang.String).substring(startIndex)");
        Log.i(TAG, "versionInfo: " + strSubstring);
        int length = strSubstring.length() - 1;
        int i2 = 0;
        boolean z = false;
        while (i2 <= length) {
            boolean z2 = g.h0.c.l.h(strSubstring.charAt(!z ? i2 : length), 32) <= 0;
            if (z) {
                if (!z2) {
                    break;
                } else {
                    length--;
                }
            } else if (z2) {
                i2++;
            } else {
                z = true;
            }
        }
        if (strSubstring.subSequence(i2, length + 1).toString().length() == 0) {
            ((c.a) jVar).c(new RuntimeException());
            return;
        }
        int length2 = strSubstring.length() - 1;
        int i3 = 0;
        boolean z3 = false;
        while (i3 <= length2) {
            boolean z4 = g.h0.c.l.h(strSubstring.charAt(!z3 ? i3 : length2), 32) <= 0;
            if (z3) {
                if (!z4) {
                    break;
                } else {
                    length2--;
                }
            } else if (z4) {
                i3++;
            } else {
                z3 = true;
            }
        }
        c.a aVar = (c.a) jVar;
        aVar.d(strSubstring.subSequence(i3, length2 + 1).toString());
        aVar.b();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void get817Version$lambda$3(l lVar, Object obj) {
        g.h0.c.l.f(lVar, "$tmp0");
        lVar.invoke(obj);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void get817Version$lambda$4(l lVar, Object obj) {
        g.h0.c.l.f(lVar, "$tmp0");
        lVar.invoke(obj);
    }

    @SuppressLint({"CheckResult"})
    public final void get817Version() {
        f.a.i iVarN = new c(new k() { // from class: d.f.a.p1.k5
            @Override // f.a.k
            public final void subscribe(f.a.j jVar) {
                Show817VersionNoCompareAction.get817Version$lambda$2(jVar);
            }
        }).s(new b(30, FwUpgradeManager.TYPE_FW_CVTE_CAMERA)).y(30L, TimeUnit.SECONDS).w(f.a.z.a.f4044c).n(f.a.s.b.a.a());
        Context context = this.mContext;
        g.h0.c.l.d(context, "null cannot be cast to non-null type com.trello.rxlifecycle3.components.support.RxAppCompatActivity");
        f.a.i iVarG = iVarN.g(((RxAppCompatActivity) context).bindUntilEvent(ActivityEvent.DESTROY));
        final AnonymousClass2 anonymousClass2 = new AnonymousClass2();
        f.a.v.c cVar = new f.a.v.c() { // from class: d.f.a.p1.m5
            @Override // f.a.v.c
            public final void accept(Object obj) {
                Show817VersionNoCompareAction.get817Version$lambda$3(anonymousClass2, obj);
            }
        };
        final AnonymousClass3 anonymousClass3 = new AnonymousClass3();
        iVarG.u(cVar, new f.a.v.c() { // from class: d.f.a.p1.l5
            @Override // f.a.v.c
            public final void accept(Object obj) {
                Show817VersionNoCompareAction.get817Version$lambda$4(anonymousClass3, obj);
            }
        }, f.a.w.b.a.f3725b, f.a.w.b.a.f3726c);
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemInfoAction
    public String getValue(Context context) {
        g.h0.c.l.f(context, "context");
        get817Version();
        String string = this.mContext.getString(R.string.device_loading);
        g.h0.c.l.e(string, "mContext.getString(R.string.device_loading)");
        return string;
    }

    @Override // d.f.a.v0
    public void setStandData(String str) {
        g.h0.c.l.f(str, "data");
        this.standard_data = str;
    }
}
