package com.seewo.ota.update.device.ui;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import butterknife.internal.Utils;
import com.seewo.libvui.h.e;
import com.seewo.ota.R;
import com.seewo.sdk.model.SDKUpgradeResult;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class DeviceUpgradeV2Activity extends Activity {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private b f2289b = b.START;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private boolean f2290f;

    static class HardwareAdp extends RecyclerView.h<H> {
        private Context a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        List<a> f2291b;

        static class H extends RecyclerView.d0 {

            @BindView(R.id.hardware_name)
            TextView mHardwareName;

            @BindView(R.id.hardware_state)
            TextView mHardwareState;

            @BindView(R.id.progressbar)
            ProgressBar mProgressbar;

            H(View view) {
                super(view);
                ButterKnife.bind(this, view);
            }
        }

        public class H_ViewBinding implements Unbinder {
            private H a;

            public H_ViewBinding(H h2, View view) {
                this.a = h2;
                h2.mHardwareName = (TextView) Utils.findRequiredViewAsType(view, R.id.hardware_name, "field 'mHardwareName'", TextView.class);
                h2.mHardwareState = (TextView) Utils.findRequiredViewAsType(view, R.id.hardware_state, "field 'mHardwareState'", TextView.class);
                h2.mProgressbar = (ProgressBar) Utils.findRequiredViewAsType(view, R.id.progressbar, "field 'mProgressbar'", ProgressBar.class);
            }

            @Override // butterknife.Unbinder
            public void unbind() {
                H h2 = this.a;
                if (h2 == null) {
                    throw new IllegalStateException("Bindings already cleared.");
                }
                this.a = null;
                h2.mHardwareName = null;
                h2.mHardwareState = null;
                h2.mProgressbar = null;
            }
        }

        HardwareAdp(Context context, List<a> list) {
            this.a = context;
            this.f2291b = list;
        }

        @Override // androidx.recyclerview.widget.RecyclerView.h
        /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
        public void onBindViewHolder(H h2, int i2) {
            a aVar = this.f2291b.get(i2);
            h2.mHardwareName.setText(aVar.a);
            h2.mHardwareState.setText(aVar.f2300b);
            h2.mProgressbar.setProgress(aVar.f2301c);
        }

        @Override // androidx.recyclerview.widget.RecyclerView.h
        /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
        public H onCreateViewHolder(ViewGroup viewGroup, int i2) {
            return new H(View.inflate(this.a, R.layout.item_hardware_upgrade_process, null));
        }

        @Override // androidx.recyclerview.widget.RecyclerView.h
        public int getItemCount() {
            return this.f2291b.size();
        }
    }

    static class UpgradingDialogController {
        private DeviceUpgradeV2Activity a;

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

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        private List<com.seewo.ota.v.s.t.c> f2293c;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        private HardwareAdp f2295e;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        private com.seewo.sdk.interfaces.q f2298h;

        /* JADX INFO: renamed from: i, reason: collision with root package name */
        private boolean f2299i;

        @BindView(R.id.recycler_view)
        RecyclerView mRecyclerView;

        @BindView(R.id.upgrade_tip)
        TextView mUpgradeTip;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        private List<a> f2294d = new ArrayList();

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        private CountDownTimer f2296f = new a(10000, 100);

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        private int f2297g = 0;

        class a extends CountDownTimer {
            a(long j2, long j3) {
                super(j2, j3);
            }

            @Override // android.os.CountDownTimer
            public void onFinish() {
            }

            @Override // android.os.CountDownTimer
            public void onTick(long j2) {
                UpgradingDialogController upgradingDialogController = UpgradingDialogController.this;
                upgradingDialogController.g(upgradingDialogController.f2297g, null, (int) (((10000 - j2) * 90) / 10000));
            }
        }

        UpgradingDialogController(DeviceUpgradeV2Activity deviceUpgradeV2Activity, View view, Dialog dialog, List<com.seewo.ota.v.s.t.c> list) {
            this.a = deviceUpgradeV2Activity;
            this.f2292b = dialog;
            this.f2293c = list;
            ButterKnife.bind(this, view);
            this.mUpgradeTip.setText(R.string.hardware_updating_dialog_head);
            for (int i2 = 0; i2 < this.f2293c.size(); i2++) {
                this.f2294d.add(new a(this.f2293c.get(i2).getName(), null, 0));
            }
            HardwareAdp hardwareAdp = new HardwareAdp(deviceUpgradeV2Activity, this.f2294d);
            this.f2295e = hardwareAdp;
            this.mRecyclerView.setAdapter(hardwareAdp);
            this.mRecyclerView.setLayoutManager(new LinearLayoutManager(deviceUpgradeV2Activity));
            this.f2292b.setOnDismissListener(new DialogInterface.OnDismissListener() { // from class: com.seewo.ota.update.device.ui.j
                @Override // android.content.DialogInterface.OnDismissListener
                public final void onDismiss(DialogInterface dialogInterface) {
                    this.f2311b.c(dialogInterface);
                }
            });
        }

        /* JADX INFO: Access modifiers changed from: private */
        public void g(int i2, String str, int i3) {
            if (i3 == 100) {
                Log.d("@UpgradingDC", "notifyProgressState max progress. position: " + i2 + ", state: " + str);
            }
            this.f2294d.get(i2).f2300b = str;
            this.f2294d.get(i2).f2301c = i3;
            this.f2295e.notifyItemChanged(i2);
        }

        private void h() {
            Log.i("@UpgradingDC", "onFailed upgrade failed. ");
            this.mUpgradeTip.setText(R.string.hardware_updating_dialog_fail);
            this.f2292b.setCanceledOnTouchOutside(true);
        }

        private void i() {
            Log.i("@UpgradingDC", "onSuccess upgrade success. ");
            this.mUpgradeTip.postDelayed(new Runnable() { // from class: com.seewo.ota.update.device.ui.k
                @Override // java.lang.Runnable
                public final void run() {
                    this.f2312b.e();
                }
            }, 3000L);
        }

        public /* synthetic */ void c(DialogInterface dialogInterface) {
            Log.d("@UpgradingDC", "dialog dismiss.");
            this.f2296f.cancel();
            if (this.a.f2289b != b.ASK_FOR_REBOOT) {
                Log.i("@UpgradingDC", "upgradingDialog dismiss, now is " + this.a.f2289b + "has fail: " + this.f2299i + ", finish.");
                this.a.f2289b = b.END;
                this.a.finish();
            }
        }

        public /* synthetic */ void d(SDKUpgradeResult sDKUpgradeResult) {
            if (this.a.f2289b != b.UPGRADING) {
                Log.i("@UpgradingDC", this.f2293c.get(this.f2297g).getName() + " " + this.f2297g + " upgrade cancel. exit.");
                return;
            }
            g(this.f2297g, sDKUpgradeResult.name(), 100);
            if (!this.f2299i && sDKUpgradeResult != SDKUpgradeResult.SUCCESS) {
                this.f2299i = true;
            }
            int i2 = this.f2297g + 1;
            this.f2297g = i2;
            if (i2 >= this.f2293c.size()) {
                if (this.f2299i) {
                    h();
                    return;
                } else {
                    i();
                    return;
                }
            }
            Log.d("@UpgradingDC", this.f2293c.get(this.f2297g).getName() + " " + this.f2297g + " call next upgrade. ");
            this.f2293c.get(this.f2297g).b(this.f2298h);
            this.f2296f.start();
        }

        public /* synthetic */ void e() {
            this.f2292b.dismiss();
            this.a.e(this.f2293c).show();
            this.a.f2289b = b.ASK_FOR_REBOOT;
        }

        public /* synthetic */ void f(final SDKUpgradeResult sDKUpgradeResult) {
            Log.d("@UpgradingDC", this.f2293c.get(this.f2297g).getName() + " " + this.f2297g + " upgrade callback. ");
            this.f2296f.cancel();
            this.mUpgradeTip.postDelayed(new Runnable() { // from class: com.seewo.ota.update.device.ui.i
                @Override // java.lang.Runnable
                public final void run() {
                    this.f2309b.d(sDKUpgradeResult);
                }
            }, 100L);
        }

        void j() {
            com.seewo.ota.v.s.t.c cVar = this.f2293c.get(this.f2297g);
            com.seewo.sdk.interfaces.q qVar = new com.seewo.sdk.interfaces.q() { // from class: com.seewo.ota.update.device.ui.h
                @Override // com.seewo.sdk.interfaces.q
                public final void a(SDKUpgradeResult sDKUpgradeResult) {
                    this.a.f(sDKUpgradeResult);
                }
            };
            this.f2298h = qVar;
            cVar.b(qVar);
            this.f2296f.start();
        }
    }

    public class UpgradingDialogController_ViewBinding implements Unbinder {
        private UpgradingDialogController a;

        public UpgradingDialogController_ViewBinding(UpgradingDialogController upgradingDialogController, View view) {
            this.a = upgradingDialogController;
            upgradingDialogController.mUpgradeTip = (TextView) Utils.findRequiredViewAsType(view, R.id.upgrade_tip, "field 'mUpgradeTip'", TextView.class);
            upgradingDialogController.mRecyclerView = (RecyclerView) Utils.findRequiredViewAsType(view, R.id.recycler_view, "field 'mRecyclerView'", RecyclerView.class);
        }

        @Override // butterknife.Unbinder
        public void unbind() {
            UpgradingDialogController upgradingDialogController = this.a;
            if (upgradingDialogController == null) {
                throw new IllegalStateException("Bindings already cleared.");
            }
            this.a = null;
            upgradingDialogController.mUpgradeTip = null;
            upgradingDialogController.mRecyclerView = null;
        }
    }

    static class a {
        String a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        String f2300b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        int f2301c;

        a(String str, String str2, int i2) {
            this.a = str;
            this.f2300b = str2;
            this.f2301c = i2;
        }
    }

    private enum b {
        START,
        CONFIRMING,
        UPGRADING,
        ASK_FOR_REBOOT,
        END
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX INFO: renamed from: d, reason: merged with bridge method [inline-methods] */
    public void p(List<com.seewo.ota.v.s.t.c> list) {
        f(list).show();
        this.f2289b = b.CONFIRMING;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public com.seewo.libvui.h.b e(List<com.seewo.ota.v.s.t.c> list) {
        StringBuilder sb = new StringBuilder();
        Iterator<com.seewo.ota.v.s.t.c> it = list.iterator();
        while (it.hasNext()) {
            sb.append(it.next().getName());
            sb.append("\n");
        }
        e.a aVar = new e.a(this);
        aVar.y(R.string.update_dialog_title);
        aVar.o(getString(R.string.hardware_update_end_dialog_message, new Object[]{sb.toString()}));
        aVar.p(R.string.btn_cancel, new DialogInterface.OnClickListener() { // from class: com.seewo.ota.update.device.ui.d
            @Override // android.content.DialogInterface.OnClickListener
            public final void onClick(DialogInterface dialogInterface, int i2) {
                DeviceUpgradeV2Activity.h(dialogInterface, i2);
            }
        });
        aVar.w(R.string.btn_ok, new DialogInterface.OnClickListener() { // from class: com.seewo.ota.update.device.ui.e
            @Override // android.content.DialogInterface.OnClickListener
            public final void onClick(DialogInterface dialogInterface, int i2) {
                this.f2306b.i(dialogInterface, i2);
            }
        });
        com.seewo.libvui.h.b bVarA = aVar.a();
        bVarA.setOnDismissListener(new DialogInterface.OnDismissListener() { // from class: com.seewo.ota.update.device.ui.n
            @Override // android.content.DialogInterface.OnDismissListener
            public final void onDismiss(DialogInterface dialogInterface) {
                this.f2315b.j(dialogInterface);
            }
        });
        bVarA.setCanceledOnTouchOutside(true);
        bVarA.setOnDismissListener(new DialogInterface.OnDismissListener() { // from class: com.seewo.ota.update.device.ui.g
            @Override // android.content.DialogInterface.OnDismissListener
            public final void onDismiss(DialogInterface dialogInterface) {
                this.f2308b.k(dialogInterface);
            }
        });
        return bVarA;
    }

    private com.seewo.libvui.h.b f(final List<com.seewo.ota.v.s.t.c> list) {
        StringBuilder sb = new StringBuilder();
        Iterator<com.seewo.ota.v.s.t.c> it = list.iterator();
        while (it.hasNext()) {
            sb.append(it.next().getName());
            sb.append("\n");
        }
        e.a aVar = new e.a(this);
        aVar.y(R.string.update_dialog_title);
        aVar.o(getString(R.string.hardware_update_tip_dialog_message, new Object[]{sb.toString()}));
        aVar.p(R.string.btn_cancel, new DialogInterface.OnClickListener() { // from class: com.seewo.ota.update.device.ui.l
            @Override // android.content.DialogInterface.OnClickListener
            public final void onClick(DialogInterface dialogInterface, int i2) {
                DeviceUpgradeV2Activity.l(dialogInterface, i2);
            }
        });
        aVar.w(R.string.btn_ok, new DialogInterface.OnClickListener() { // from class: com.seewo.ota.update.device.ui.b
            @Override // android.content.DialogInterface.OnClickListener
            public final void onClick(DialogInterface dialogInterface, int i2) {
                this.f2302b.m(list, dialogInterface, i2);
            }
        });
        com.seewo.libvui.h.b bVarA = aVar.a();
        bVarA.setCanceledOnTouchOutside(false);
        bVarA.setOnKeyListener(new DialogInterface.OnKeyListener() { // from class: com.seewo.ota.update.device.ui.m
            @Override // android.content.DialogInterface.OnKeyListener
            public final boolean onKey(DialogInterface dialogInterface, int i2, KeyEvent keyEvent) {
                return this.f2314b.n(dialogInterface, i2, keyEvent);
            }
        });
        bVarA.setOnDismissListener(new DialogInterface.OnDismissListener() { // from class: com.seewo.ota.update.device.ui.f
            @Override // android.content.DialogInterface.OnDismissListener
            public final void onDismiss(DialogInterface dialogInterface) {
                this.f2307b.o(dialogInterface);
            }
        });
        return bVarA;
    }

    private com.seewo.libvui.h.b g(List<com.seewo.ota.v.s.t.c> list) {
        View viewInflate = View.inflate(this, R.layout.layout_hardware_upgrading, null);
        e.a aVar = new e.a(this);
        aVar.y(R.string.update_dialog_title);
        aVar.l(viewInflate);
        aVar.v(0);
        aVar.u(0);
        com.seewo.libvui.h.b bVarA = aVar.a();
        bVarA.setCanceledOnTouchOutside(false);
        new UpgradingDialogController(this, viewInflate, bVarA, list).j();
        return bVarA;
    }

    static /* synthetic */ void h(DialogInterface dialogInterface, int i2) {
        Log.d("@DeviceUpgradeV2Act", "customer cancel update, exit.");
        dialogInterface.dismiss();
    }

    static /* synthetic */ void l(DialogInterface dialogInterface, int i2) {
        Log.d("@DeviceUpgradeV2Act", "customer cancel update, exit.");
        dialogInterface.dismiss();
    }

    public /* synthetic */ void i(DialogInterface dialogInterface, int i2) {
        Log.d("@DeviceUpgradeV2Act", "customer confirm update, exit.");
        dialogInterface.dismiss();
        this.f2290f = true;
    }

    public /* synthetic */ void j(DialogInterface dialogInterface) {
        finish();
    }

    public /* synthetic */ void k(DialogInterface dialogInterface) {
        Log.i("@DeviceUpgradeV2Act", "upgradeEndDialog dismiss, finish.");
        this.f2289b = b.END;
        finish();
    }

    public /* synthetic */ void m(List list, DialogInterface dialogInterface, int i2) {
        Log.d("@DeviceUpgradeV2Act", "customer confirm update, exit.");
        dialogInterface.dismiss();
        g(list).show();
        this.f2289b = b.UPGRADING;
    }

    public /* synthetic */ boolean n(DialogInterface dialogInterface, int i2, KeyEvent keyEvent) {
        if (i2 != 4) {
            return false;
        }
        dialogInterface.dismiss();
        finish();
        return true;
    }

    public /* synthetic */ void o(DialogInterface dialogInterface) {
        if (this.f2289b != b.UPGRADING) {
            Log.i("@DeviceUpgradeV2Act", "upgradeTipDialog dismiss, now is " + this.f2289b + ", finish.");
            finish();
        }
    }

    @Override // android.app.Activity
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        requestWindowFeature(1);
        setContentView(R.layout.activity_device_upgrade_v2);
        ButterKnife.bind(this);
        if (!com.seewo.ota.data.b.i().y()) {
            Log.d("@DeviceUpgradeV2Act", "not use device upgrade v2. exit.");
            finish();
            return;
        }
        final List<com.seewo.ota.v.s.t.c> listA = com.seewo.ota.v.s.t.e.f2573b.a();
        if (listA.isEmpty()) {
            Log.d("@DeviceUpgradeV2Act", "nothing update, exit.");
            finish();
        } else if (d.e.g.a.o().q()) {
            p(listA);
        } else {
            d.e.g.a.o().m(this, new com.seewo.sdk.interfaces.s() { // from class: com.seewo.ota.update.device.ui.c
                @Override // com.seewo.sdk.interfaces.s
                public final void a() {
                    this.a.p(listA);
                }
            });
        }
    }

    @Override // android.app.Activity
    protected void onDestroy() {
        super.onDestroy();
        if (this.f2290f) {
            d.e.g.g.a.d();
        }
    }
}
