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

import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ProgressBar;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.seewo.ota.R;
import com.seewo.ota.v.s.s.r0;
import java.util.concurrent.TimeUnit;

/* JADX INFO: loaded from: classes.dex */
public class DeviceUpdateDialog extends Dialog {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    protected Handler f2287b;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    protected e.a.r.b f2288f;

    @BindView(R.id.auto_upgrade_point)
    TextView mAutoUpgradePoint;

    @BindView(R.id.auto_upgrade_progressbar)
    ProgressBar mAutoUpgradeProgress;

    public DeviceUpdateDialog(Context context) {
        this(context, -1);
    }

    private void a() {
        Log.i("DeviceUpdateDialog", "delayDismiss: DeviceUpgrade");
        this.f2287b.postDelayed(new Runnable() { // from class: com.seewo.ota.update.device.ui.r
            @Override // java.lang.Runnable
            public final void run() {
                this.f2319b.dismiss();
            }
        }, 3000L);
    }

    private void e() {
        this.f2288f = e.a.h.B(1000L, TimeUnit.MILLISECONDS).U(99L).T(e.a.x.a.b()).G(e.a.q.b.a.a()).O(new e.a.t.c() { // from class: com.seewo.ota.update.device.ui.a
            @Override // e.a.t.c
            public final void accept(Object obj) throws Exception {
                this.a.d((Long) obj);
            }
        });
    }

    public void b() {
        e.a.r.b bVar = this.f2288f;
        if (bVar != null) {
            bVar.dispose();
        }
        this.mAutoUpgradePoint.setText(getContext().getResources().getString(R.string.device_update_failed_message));
    }

    public void c(boolean z) {
        Log.v("DeviceUpdateDialog", "finishUpgrade: " + z);
        e.a.r.b bVar = this.f2288f;
        if (bVar != null) {
            bVar.dispose();
        }
        if (z) {
            this.mAutoUpgradeProgress.setProgress(100);
            this.mAutoUpgradePoint.setText(getContext().getResources().getString(R.string.auto_upgrade_result));
        } else {
            this.mAutoUpgradePoint.setText(getContext().getResources().getString(R.string.device_update_failed_message));
        }
        a();
    }

    public /* synthetic */ void d(Long l) throws Exception {
        this.mAutoUpgradeProgress.setProgress(l.intValue() + 1);
    }

    @Override // android.app.Dialog, android.content.DialogInterface
    public void dismiss() {
        super.dismiss();
        this.f2287b.removeCallbacksAndMessages(null);
        e.a.r.b bVar = this.f2288f;
        if (bVar != null) {
            bVar.dispose();
        }
    }

    public void f() {
        e.a.r.b bVar = this.f2288f;
        if (bVar != null) {
            bVar.dispose();
        }
        this.mAutoUpgradeProgress.setProgress(100);
    }

    public void g(r0 r0Var) {
        Log.d("DeviceUpdateDialog", "updateDeviceTask " + r0Var.getName());
        e.a.r.b bVar = this.f2288f;
        if (bVar != null) {
            bVar.dispose();
        }
        this.mAutoUpgradeProgress.setProgress(0);
        this.mAutoUpgradePoint.setText(r0Var.getUpdateTip());
        e();
    }

    @Override // android.app.Dialog
    public void show() {
        super.show();
        this.mAutoUpgradeProgress.setProgress(0);
    }

    public DeviceUpdateDialog(Context context, int i2) {
        WindowManager.LayoutParams attributes;
        super(context, R.style.Transparent);
        this.f2287b = new Handler(Looper.getMainLooper());
        setCancelable(false);
        setCanceledOnTouchOutside(false);
        Window window = getWindow();
        if (window != null && (attributes = window.getAttributes()) != null) {
            attributes.height = -1;
            attributes.width = -1;
            attributes.gravity = 17;
        }
        setCancelable(true);
        if (context.getResources().getBoolean(R.bool.support_feature_not_title)) {
            requestWindowFeature(1);
        }
        setContentView(R.layout.activity_auto_upgrade);
        ButterKnife.bind(this);
        getWindow().setType(2018);
    }
}
