package com.seewo.ota.activity;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.seewo.libvui.h.b;
import com.seewo.ota.R;
import d.e.b.a.a;
import d.e.b.a.b;
import d.e.h.a.b;
import java.text.DecimalFormat;

/* JADX INFO: compiled from: UpdateInfoSettings2.java */
/* JADX INFO: loaded from: classes.dex */
public class l2 extends Fragment {
    private boolean A0;
    private d.e.b.a.b C0;
    private d D0;
    private com.seewo.libvui.h.b E0;
    private RelativeLayout d0;
    private RelativeLayout e0;
    private RelativeLayout f0;
    private RelativeLayout g0;
    private RelativeLayout h0;
    private RelativeLayout i0;
    private Switch j0;
    private View k0;
    private Switch l0;
    private View m0;
    private View n0;
    private TextView o0;
    private TextView p0;
    private TextView q0;
    private TextView r0;
    private View s0;
    private ProgressBar t0;
    private Button u0;
    private Button v0;
    private String x0;
    private long y0;
    private String z0;
    private b.a w0 = b.a.NONE;
    private final DecimalFormat B0 = new DecimalFormat("0.0");
    private final Handler F0 = new Handler(Looper.getMainLooper());
    private final BroadcastReceiver G0 = new a();
    private final ServiceConnection H0 = new b();
    private final View.OnClickListener I0 = new View.OnClickListener() { // from class: com.seewo.ota.activity.k1
        @Override // android.view.View.OnClickListener
        public final void onClick(View view) {
            this.f2046b.p2(view);
        }
    };

    /* JADX INFO: compiled from: UpdateInfoSettings2.java */
    class a extends BroadcastReceiver {
        a() {
        }

        @Override // android.content.BroadcastReceiver
        public void onReceive(Context context, Intent intent) {
            if (com.seewo.vcommons.data.c.j(l2.this.i())) {
                return;
            }
            l2.this.i().onBackPressed();
        }
    }

    /* JADX INFO: compiled from: UpdateInfoSettings2.java */
    class b implements ServiceConnection {
        b() {
        }

        @Override // android.content.ServiceConnection
        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            Log.d("UpdateInfoFragment", "OTA onServiceConnected");
            l2.this.C0 = b.a.J(iBinder);
            if (l2.this.C0 != null) {
                try {
                    l2.this.C0.G(l2.this.D0, 1);
                    l2.this.w0 = b.a.values()[l2.this.C0.H(1)];
                } catch (Exception e2) {
                    Log.e("UpdateInfoFragment", e2.getMessage(), e2);
                }
                l2.this.e2();
                if (com.seewo.vcommons.data.c.a(l2.this.i(), "KEY_DISABLE_SYSTEM_UPDATE", false)) {
                    return;
                }
                Handler handler = l2.this.F0;
                final l2 l2Var = l2.this;
                handler.post(new Runnable() { // from class: com.seewo.ota.activity.c1
                    @Override // java.lang.Runnable
                    public final void run() {
                        l2Var.C2();
                    }
                });
            }
        }

        @Override // android.content.ServiceConnection
        public void onServiceDisconnected(ComponentName componentName) {
            Log.d("UpdateInfoFragment", "OTA onServiceDisconnected");
            l2.this.C0 = null;
        }
    }

    /* JADX INFO: compiled from: UpdateInfoSettings2.java */
    static /* synthetic */ class c {
        static final /* synthetic */ int[] a;

        static {
            int[] iArr = new int[b.a.values().length];
            a = iArr;
            try {
                iArr[b.a.NONE.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                a[b.a.CHECKING.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                a[b.a.HAVE.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                a[b.a.DOWNLOADING.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                a[b.a.DOWNLOADED.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void A2(boolean z) {
        this.v0.setEnabled(z);
    }

    private void B2(boolean z) {
        this.d0.setVisibility(z ? 0 : 8);
        this.h0.setVisibility(z ? 0 : 8);
        this.i0.setVisibility(z ? 0 : 8);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void C2() {
        Log.d("UpdateInfoFragment", "updateUI! currentOTAState:" + this.w0);
        int i2 = c.a[this.w0.ordinal()];
        if (i2 == 1) {
            c2();
            w2(false);
            return;
        }
        if (i2 == 2) {
            f2();
            return;
        }
        if (i2 == 3) {
            b2();
        } else if (i2 == 4) {
            a2();
        } else {
            if (i2 != 5) {
                return;
            }
            Z1();
        }
    }

    private void U1() {
        Intent intent = new Intent("com.seewo.ota.service.OTARefreshService");
        intent.setPackage("com.seewo.ota");
        i().bindService(intent, this.H0, 1);
    }

    private void V1() {
        d.e.b.a.b bVar = this.C0;
        if (bVar != null) {
            try {
                bVar.cancel(1);
            } catch (RemoteException e2) {
                Log.e("UpdateInfoFragment", e2.getMessage(), e2);
            }
        }
    }

    private void W1() {
        z2(false);
        w2(true);
    }

    private void X1() {
        com.seewo.libvui.h.b bVar = this.E0;
        if (bVar == null || !bVar.isShowing()) {
            return;
        }
        this.E0.dismiss();
    }

    private void Y1() {
        if (!d.e.c.a.b.a(i())) {
            com.seewo.ota.util.s.a().d(i(), M(R.string.ota_net_error));
        } else {
            x2();
            a2();
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void Z1() {
        z2(true);
        A2(true);
        t2();
        this.d0.setVisibility(0);
        this.e0.setVisibility(0);
        this.f0.setVisibility(8);
        this.g0.setVisibility(8);
        this.o0.setVisibility(0);
        j2(R.string.update_now);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void a2() {
        z2(false);
        A2(false);
        t2();
        this.d0.setVisibility(0);
        this.e0.setVisibility(0);
        this.f0.setVisibility(0);
        this.g0.setVisibility(0);
        this.o0.setVisibility(8);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void b2() {
        z2(true);
        A2(true);
        t2();
        this.d0.setVisibility(0);
        this.e0.setVisibility(0);
        this.f0.setVisibility(8);
        this.g0.setVisibility(8);
        this.o0.setVisibility(8);
        j2(R.string.download);
    }

    private void c2() {
        this.d0.setVisibility(8);
        z2(true);
        A2(true);
    }

    private String d2() {
        String strC = com.seewo.vcommons.data.d.c();
        return strC.length() > 5 ? strC.substring(0, strC.length() - 5).replace('T', '-') : "--";
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void e2() {
        try {
            Bundle bundleC = this.C0.C(1);
            this.x0 = bundleC.getString("UPDATE_VERSION", "");
            this.y0 = bundleC.getLong("UPDATE_SIZE", 0L);
            this.z0 = bundleC.getString("UPDATE_DESC", "");
        } catch (RemoteException e2) {
            Log.e("UpdateInfoFragment", "getInfoFromBundle: ", e2);
        }
    }

    private void f2() {
        this.F0.postDelayed(new Runnable() { // from class: com.seewo.ota.activity.f1
            @Override // java.lang.Runnable
            public final void run() {
                this.f2023b.l2();
            }
        }, 3000L);
    }

    private void g2() {
        this.d0 = (RelativeLayout) this.n0.findViewById(R.id.update_layout);
        this.e0 = (RelativeLayout) this.n0.findViewById(R.id.new_version_layout);
        this.f0 = (RelativeLayout) this.n0.findViewById(R.id.update_progress_layout);
        this.g0 = (RelativeLayout) this.n0.findViewById(R.id.update_check_layout);
        this.h0 = (RelativeLayout) this.n0.findViewById(R.id.current_version_layout);
        this.i0 = (RelativeLayout) this.n0.findViewById(R.id.check_update_layout);
        this.j0 = (Switch) this.n0.findViewById(R.id.disable_update_switch);
        this.k0 = this.n0.findViewById(R.id.disable_system_update);
        this.m0 = this.n0.findViewById(R.id.enable_system_update);
        this.l0 = (Switch) this.n0.findViewById(R.id.enable_update_switch);
        TextView textView = (TextView) this.n0.findViewById(R.id.update_version);
        textView.setOnClickListener(new com.seewo.ota.p.e());
        this.p0 = (TextView) this.n0.findViewById(R.id.update_size);
        this.o0 = (TextView) this.n0.findViewById(R.id.update_downloaded);
        this.q0 = (TextView) this.n0.findViewById(R.id.update_content);
        this.r0 = (TextView) this.n0.findViewById(R.id.update_progress);
        this.s0 = this.n0.findViewById(R.id.update_cancel);
        final ImageView imageView = (ImageView) this.n0.findViewById(R.id.update_auto_check_box);
        ProgressBar progressBar = (ProgressBar) this.n0.findViewById(R.id.download_progress);
        this.t0 = progressBar;
        progressBar.setEnabled(false);
        this.u0 = (Button) this.n0.findViewById(R.id.check_update_button);
        this.v0 = (Button) this.n0.findViewById(R.id.update_button);
        textView.setText(N(R.string.system_update_version, (q().getResources().getBoolean(R.bool.support_use_native_system_version) ? com.seewo.vcommons.data.d.e() : d2()).replace("\\", "")));
        this.u0.setOnClickListener(this.I0);
        this.v0.setOnClickListener(this.I0);
        this.s0.setOnClickListener(this.I0);
        this.v0.setTag(Integer.valueOf(R.string.download));
        this.f0.setVisibility(8);
        this.g0.setVisibility(8);
        imageView.setSelected(com.seewo.vcommons.data.c.k(i()));
        imageView.setOnClickListener(new View.OnClickListener() { // from class: com.seewo.ota.activity.n1
            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                this.f2064b.m2(imageView, view);
            }
        });
        h2();
        i2();
    }

    private void h2() {
        if (!G().getBoolean(R.bool.support_disable_ota_update)) {
            this.k0.setVisibility(8);
            return;
        }
        boolean zA = com.seewo.vcommons.data.c.a(i(), "KEY_DISABLE_SYSTEM_UPDATE", false);
        B2(!zA);
        this.j0.setChecked(zA);
        this.j0.setClickable(false);
        this.k0.setOnClickListener(new View.OnClickListener() { // from class: com.seewo.ota.activity.e1
            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                this.f2021b.n2(view);
            }
        });
    }

    private void i2() {
        if (!G().getBoolean(R.bool.support_enable_ota_update)) {
            this.m0.setVisibility(8);
            return;
        }
        boolean z = !com.seewo.vcommons.data.c.a(i(), "KEY_DISABLE_SYSTEM_UPDATE", false);
        B2(z);
        this.l0.setChecked(z);
        this.m0.setOnClickListener(new View.OnClickListener() { // from class: com.seewo.ota.activity.d1
            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                this.f2010b.o2(view);
            }
        });
    }

    private void j2(int i2) {
        this.v0.setText(i2);
        this.v0.setTag(Integer.valueOf(i2));
    }

    private void s2() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.ifpdos.action.AUTO_OTA_UPDATE_CHANGED");
        i().registerReceiver(this.G0, intentFilter);
    }

    private void t2() {
        this.p0.setText(String.format("%s | %s", this.x0, N(R.string.system_update_size, this.B0.format(this.y0 / 1048576))));
        this.q0.setText(this.z0);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void u2(int i2) {
        X1();
        b.a aVar = new b.a(i());
        aVar.y(R.string.system_update_check_result_title);
        aVar.n(i2);
        aVar.r(R.string.password_setting_ok, new DialogInterface.OnClickListener() { // from class: com.seewo.ota.activity.j1
            @Override // android.content.DialogInterface.OnClickListener
            public final void onClick(DialogInterface dialogInterface, int i3) {
                this.f2040b.q2(dialogInterface, i3);
            }
        });
        com.seewo.libvui.h.b bVarA = aVar.a();
        this.E0 = bVarA;
        bVarA.show();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void v2(int i2) {
        X1();
        com.seewo.libvui.h.b bVar = this.E0;
        if (bVar != null && bVar.isShowing()) {
            this.E0.dismiss();
        }
        b.a aVar = new b.a(i());
        aVar.y(R.string.system_update_check_result_title);
        aVar.n(i2);
        aVar.r(R.string.password_setting_ok, new DialogInterface.OnClickListener() { // from class: com.seewo.ota.activity.m1
            @Override // android.content.DialogInterface.OnClickListener
            public final void onClick(DialogInterface dialogInterface, int i3) {
                this.f2054b.r2(dialogInterface, i3);
            }
        });
        com.seewo.libvui.h.b bVarA = aVar.a();
        this.E0 = bVarA;
        bVarA.show();
    }

    private void w2(boolean z) {
        d.e.b.a.b bVar = this.C0;
        if (bVar == null) {
            u2(R.string.system_update_check_result_no_need_update);
            return;
        }
        try {
            this.A0 = z;
            bVar.x(1, false);
        } catch (RemoteException e2) {
            Log.e("UpdateInfoFragment", e2.getMessage(), e2);
        }
    }

    private void x2() {
        d.e.b.a.b bVar = this.C0;
        if (bVar != null) {
            try {
                bVar.s(1);
            } catch (RemoteException e2) {
                Log.e("UpdateInfoFragment", e2.getMessage(), e2);
            }
        }
    }

    private void y2() {
        d.e.b.a.b bVar = this.C0;
        if (bVar != null) {
            try {
                bVar.y(1);
            } catch (RemoteException e2) {
                Log.e("UpdateInfoFragment", e2.getMessage(), e2);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void z2(boolean z) {
        this.u0.setEnabled(z);
    }

    public /* synthetic */ void l2() {
        try {
            if (a0()) {
                this.w0 = b.a.values()[this.C0.H(1)];
                e2();
                this.F0.post(new Runnable() { // from class: com.seewo.ota.activity.l1
                    @Override // java.lang.Runnable
                    public final void run() {
                        this.f2048b.C2();
                    }
                });
            }
        } catch (RemoteException e2) {
            Log.e("UpdateInfoFragment", e2.getMessage(), e2);
        }
    }

    public /* synthetic */ void m2(ImageView imageView, View view) {
        boolean z = !imageView.isSelected();
        imageView.setSelected(z);
        com.seewo.vcommons.data.c.q(i(), z);
    }

    @Override // androidx.fragment.app.Fragment
    public View n0(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        this.n0 = layoutInflater.inflate(R.layout.system_update_info_layout2, viewGroup, false);
        this.D0 = new d(this, null);
        g2();
        U1();
        s2();
        int i2 = (int) (((double) com.seewo.ota.util.p.a(j1()).x) * 0.15d);
        this.n0.setPadding(i2, 0, i2, 0);
        return this.n0;
    }

    public /* synthetic */ void n2(View view) {
        boolean z = !this.j0.isChecked();
        this.j0.setChecked(z);
        com.seewo.vcommons.data.c.l(i(), "KEY_DISABLE_SYSTEM_UPDATE", z);
        V1();
        i().sendBroadcast(new Intent("com.seewo.ota.action.DISABLE_SYSTEM_UPDATE_CHANGED"));
        B2(!z);
    }

    public /* synthetic */ void o2(View view) {
        boolean z = !this.l0.isChecked();
        this.l0.setChecked(z);
        com.seewo.vcommons.data.c.l(i(), "KEY_DISABLE_SYSTEM_UPDATE", !z);
        V1();
        i().sendBroadcast(new Intent("com.seewo.ota.action.DISABLE_SYSTEM_UPDATE_CHANGED"));
        B2(z);
    }

    public /* synthetic */ void p2(View view) {
        int id = view.getId();
        if (id == R.id.check_update_button) {
            W1();
            return;
        }
        if (id == R.id.update_button) {
            if (((Integer) view.getTag()).intValue() == R.string.download) {
                Y1();
                return;
            } else {
                y2();
                return;
            }
        }
        if (id == R.id.update_cancel) {
            V1();
            b2();
        }
    }

    @Override // androidx.fragment.app.Fragment
    public void q0() {
        super.q0();
        d.e.b.a.b bVar = this.C0;
        if (bVar != null) {
            try {
                bVar.n(this.D0);
            } catch (RemoteException e2) {
                Log.e("UpdateInfoFragment", e2.getMessage(), e2);
            }
        }
        this.C0 = null;
        i().unbindService(this.H0);
        i().unregisterReceiver(this.G0);
    }

    public /* synthetic */ void q2(DialogInterface dialogInterface, int i2) {
        X1();
    }

    public /* synthetic */ void r2(DialogInterface dialogInterface, int i2) {
        X1();
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX INFO: compiled from: UpdateInfoSettings2.java */
    class d extends a.AbstractBinderC0083a {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private int f2050b;

        private d() {
            this.f2050b = -1;
        }

        private void O(final int i2) {
            if (this.f2050b == i2) {
                return;
            }
            this.f2050b = i2;
            l2.this.F0.post(new Runnable() { // from class: com.seewo.ota.activity.i1
                @Override // java.lang.Runnable
                public final void run() {
                    this.f2036b.N(i2);
                }
            });
        }

        @Override // d.e.b.a.a
        public void I(int i2) {
        }

        /* JADX WARN: Removed duplicated region for block: B:13:0x001d  */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        public /* synthetic */ void L(int r4) {
            /*
                r3 = this;
                if (r4 == 0) goto L51
                r0 = 1
                if (r4 == r0) goto L1d
                r0 = 2
                if (r4 == r0) goto Lc
                r0 = 4
                if (r4 == r0) goto L1d
                goto L5b
            Lc:
                com.seewo.ota.activity.l2 r4 = com.seewo.ota.activity.l2.this
                boolean r4 = com.seewo.ota.activity.l2.K1(r4)
                if (r4 == 0) goto L5b
                com.seewo.ota.activity.l2 r4 = com.seewo.ota.activity.l2.this
                r0 = 2131689650(0x7f0f00b2, float:1.9008321E38)
                com.seewo.ota.activity.l2.M1(r4, r0)
                goto L5b
            L1d:
                com.seewo.ota.activity.l2 r4 = com.seewo.ota.activity.l2.this
                boolean r4 = com.seewo.ota.activity.l2.K1(r4)
                if (r4 == 0) goto L5b
                com.seewo.ota.activity.l2 r4 = com.seewo.ota.activity.l2.this
                androidx.fragment.app.d r4 = r4.i()
                boolean r4 = d.e.c.a.b.a(r4)
                if (r4 != 0) goto L48
                com.seewo.ota.util.s r4 = com.seewo.ota.util.s.a()
                com.seewo.ota.activity.l2 r0 = com.seewo.ota.activity.l2.this
                androidx.fragment.app.d r0 = r0.i()
                com.seewo.ota.activity.l2 r1 = com.seewo.ota.activity.l2.this
                r2 = 2131689651(0x7f0f00b3, float:1.9008323E38)
                java.lang.String r1 = r1.M(r2)
                r4.d(r0, r1)
                goto L5b
            L48:
                com.seewo.ota.activity.l2 r4 = com.seewo.ota.activity.l2.this
                r0 = 2131689652(0x7f0f00b4, float:1.9008325E38)
                com.seewo.ota.activity.l2.M1(r4, r0)
                goto L5b
            L51:
                com.seewo.ota.activity.l2 r4 = com.seewo.ota.activity.l2.this
                com.seewo.ota.activity.l2.O1(r4)
                com.seewo.ota.activity.l2 r4 = com.seewo.ota.activity.l2.this
                com.seewo.ota.activity.l2.S1(r4)
            L5b:
                com.seewo.ota.activity.l2 r4 = com.seewo.ota.activity.l2.this
                r0 = 0
                com.seewo.ota.activity.l2.L1(r4, r0)
                return
            */
            throw new UnsupportedOperationException("Method not decompiled: com.seewo.ota.activity.l2.d.L(int):void");
        }

        public /* synthetic */ void M(int i2, int i3) {
            if (i2 == 0) {
                l2.this.b2();
                l2 l2Var = l2.this;
                l2Var.v2(d.e.c.a.b.a(l2Var.i()) ? R.string.ota_unkown : R.string.ota_net_error);
            } else if (i2 == 1) {
                l2.this.r0.setText(l2.this.i().getString(R.string.system_update_progress, new Object[]{Integer.valueOf(i3)}));
                l2.this.t0.setProgress(i3);
            } else {
                if (i2 != 2) {
                    return;
                }
                l2.this.Z1();
            }
        }

        public /* synthetic */ void N(int i2) {
            if (i2 == 1) {
                l2.this.a2();
            } else {
                if (i2 != 3) {
                    return;
                }
                l2.this.f0.setVisibility(8);
                l2.this.z2(true);
                l2.this.A2(true);
            }
        }

        @Override // d.e.b.a.a
        public void d(int i2) {
        }

        @Override // d.e.b.a.a
        public void g(final int i2) {
            Log.d("UpdateInfoFragment", "onCheckResult: " + i2);
            l2.this.z2(true);
            l2.this.F0.post(new Runnable() { // from class: com.seewo.ota.activity.g1
                @Override // java.lang.Runnable
                public final void run() {
                    this.f2027b.L(i2);
                }
            });
        }

        @Override // d.e.b.a.a
        public void j(final int i2, final int i3) {
            Log.d("UpdateInfoFragment", "onDownloadResult: " + i2 + " ,progress: " + i3);
            O(i2);
            l2.this.F0.post(new Runnable() { // from class: com.seewo.ota.activity.h1
                @Override // java.lang.Runnable
                public final void run() {
                    this.f2031b.M(i2, i3);
                }
            });
        }

        /* synthetic */ d(l2 l2Var, a aVar) {
            this();
        }
    }
}
