package com.tencent.mm.plugin.voiceprint.ui;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.ai.f;
import com.tencent.mm.ai.m;
import com.tencent.mm.model.av;
import com.tencent.mm.model.aw;
import com.tencent.mm.model.r;
import com.tencent.mm.plugin.appbrand.jsapi.i.c;
import com.tencent.mm.plugin.voiceprint.model.i;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.storage.ac.a;
import com.tencent.mm.ui.base.h;
import com.tencent.mm.ui.base.preference.CheckBoxPreference;
import com.tencent.mm.ui.base.preference.MMPreference;
import com.tencent.mm.ui.base.preference.Preference;
import com.tencent.ytcommon.BuildConfig;

public class SettingsVoicePrintUI extends MMPreference implements f {
    private ProgressDialog ehJ = null;
    private com.tencent.mm.ui.base.preference.f ehK;
    private View iym;
    private boolean lYR = false;
    private VoiceHeaderPreference sMc;

    public void onWindowFocusChanged(boolean z) {
        super.onWindowFocusChanged(z);
        AppMethodBeat.at(this, z);
    }

    static /* synthetic */ void a(SettingsVoicePrintUI settingsVoicePrintUI) {
        AppMethodBeat.i(26158);
        settingsVoicePrintUI.cHZ();
        AppMethodBeat.o(26158);
    }

    public void onCreate(Bundle bundle) {
        AppMethodBeat.i(26149);
        super.onCreate(bundle);
        setMMTitle(2131303342);
        aw.Rg().a(c.CTRL_INDEX, this);
        this.iym = findViewById(2131826069);
        initView();
        this.iym.setBackgroundResource(2131690691);
        aw.ZK();
        com.tencent.mm.model.c.Ry().set(a.xJG, Boolean.FALSE);
        aw.ZK();
        com.tencent.mm.model.c.Ry().set(a.xJH, Boolean.FALSE);
        aw.ZK();
        com.tencent.mm.model.c.Ry().set(a.xJI, Boolean.FALSE);
        aw.ZK();
        com.tencent.mm.model.c.Ry().set(a.xJJ, Boolean.FALSE);
        ab.i("MicroMsg.VoiceSettingsUI", "unset all voiceprint config");
        AppMethodBeat.o(26149);
    }

    public void onResume() {
        AppMethodBeat.i(26150);
        super.onResume();
        if (this.lYR) {
            this.lYR = false;
            if (this.ehJ != null && this.ehJ.isShowing()) {
                this.ehJ.dismiss();
            }
            AppCompatActivity appCompatActivity = this.mController.ylL;
            getString(2131297061);
            this.ehJ = h.b(appCompatActivity, getString(2131297086), true, new 1(this));
            ab.d("MicroMsg.VoiceSettingsUI", "resume after create voiceprint, get switch status");
            aw.Rg().a(new i(1), 0);
        }
        AppMethodBeat.o(26150);
    }

    public void onDestroy() {
        AppMethodBeat.i(26151);
        super.onDestroy();
        aw.Rg().b(c.CTRL_INDEX, this);
        if (this.ehJ != null) {
            this.ehJ.dismiss();
        }
        AppMethodBeat.o(26151);
    }

    public final void initView() {
        AppMethodBeat.i(26152);
        aw.ZK();
        int g = bo.g(com.tencent.mm.model.c.Ry().get(40, Integer.valueOf(0)), 0);
        ab.i("MicroMsg.VoiceSettingsUI", "plugSwitch " + g + " " + (g & 131072));
        this.ehK = this.yCw;
        this.sMc = (VoiceHeaderPreference) this.ehK.aqO("settings_voiceprint_header");
        ((CheckBoxPreference) this.ehK.aqO("settings_voiceprint_title")).qg(true);
        this.ehK.notifyDataSetChanged();
        if (this.ehJ != null && this.ehJ.isShowing()) {
            this.ehJ.dismiss();
        }
        AppCompatActivity appCompatActivity = this.mController.ylL;
        getString(2131297061);
        this.ehJ = h.b(appCompatActivity, getString(2131297086), true, new 2(this));
        aw.Rg().a(new i(0), 0);
        this.ehK.ce("settings_voiceprint_unlock", true);
        this.ehK.ce("settings_voiceprint_reset", true);
        this.ehK.ce("settings_voiceprint_create", true);
        setBackBtn(new 3(this));
        AppMethodBeat.o(26152);
    }

    public final int JC() {
        return 2131165295;
    }

    public void onSceneEnd(int i, int i2, String str, m mVar) {
        AppMethodBeat.i(26154);
        ab.d("MicroMsg.VoiceSettingsUI", "onSceneEnd, errType:%d, errCode:%d, sceneType:%d", new Object[]{Integer.valueOf(i), Integer.valueOf(i2), Integer.valueOf(mVar.getType())});
        if (i == 0 || i2 == 0) {
            if (mVar.getType() == c.CTRL_INDEX) {
                i iVar = (i) mVar;
                if (iVar.mStatus == 1) {
                    int i3;
                    ab.d("MicroMsg.VoiceSettingsUI", "voiceprint exist");
                    this.ehK.ce("settings_voiceprint_unlock", false);
                    this.ehK.notifyDataSetChanged();
                    int YF = r.YF();
                    CheckBoxPreference checkBoxPreference = (CheckBoxPreference) this.ehK.aqO("settings_voiceprint_title");
                    ab.d("MicroMsg.VoiceSettingsUI", "opScene.getSwitch:%d", new Object[]{Integer.valueOf(iVar.sLm)});
                    if (iVar.sLm > 0) {
                        ab.d("MicroMsg.VoiceSettingsUI", "voiceprint open");
                        checkBoxPreference.qg(true);
                        this.ehK.ce("settings_voiceprint_reset", false);
                        this.ehK.ce("settings_voiceprint_unlock", false);
                        i3 = 131072 | YF;
                        this.sMc.ej(getString(2131304328), BuildConfig.FLAVOR);
                    } else {
                        ab.d("MicroMsg.VoiceSettingsUI", "voiceprint close");
                        checkBoxPreference.qg(false);
                        this.ehK.ce("settings_voiceprint_reset", true);
                        this.ehK.ce("settings_voiceprint_unlock", true);
                        i3 = -131073 & YF;
                        this.sMc.ej(getString(2131304326), BuildConfig.FLAVOR);
                    }
                    ab.i("MicroMsg.VoiceSettingsUI", "scene end plugSwitch %d", new Object[]{Integer.valueOf(i3)});
                    av.fly.ak("last_login_use_voice", String.valueOf(i3));
                    aw.ZK();
                    com.tencent.mm.model.c.Ry().set(40, Integer.valueOf(i3));
                    this.ehK.ce("settings_voiceprint_create", true);
                    this.ehK.ce("settings_voiceprint_title", false);
                    this.sMc.a(null);
                    this.ehK.notifyDataSetChanged();
                } else {
                    ab.d("MicroMsg.VoiceSettingsUI", "voiceprint not exist");
                    com.tencent.mm.plugin.report.service.h.pYm.e(11390, new Object[]{Integer.valueOf(2)});
                    this.ehK.ce("settings_voiceprint_unlock", true);
                    this.ehK.ce("settings_voiceprint_reset", true);
                    this.ehK.ce("settings_voiceprint_create", true);
                    this.ehK.ce("settings_voiceprint_title", true);
                    this.sMc.ej(getString(2131304330), getString(2131304329));
                    this.sMc.a(new 5(this));
                    this.ehK.notifyDataSetChanged();
                }
            }
            if (this.ehJ != null) {
                this.ehJ.dismiss();
            }
            AppMethodBeat.o(26154);
            return;
        }
        this.ehK.ce("settings_voiceprint_unlock", true);
        this.ehK.ce("settings_voiceprint_reset", true);
        this.ehK.ce("settings_voiceprint_create", true);
        ((CheckBoxPreference) this.ehK.aqO("settings_voiceprint_title")).qg(false);
        this.sMc.ej(getString(2131304326), BuildConfig.FLAVOR);
        this.ehK.notifyDataSetChanged();
        if (this.ehJ != null) {
            this.ehJ.dismiss();
        }
        AppMethodBeat.o(26154);
    }

    private void cHZ() {
        AppMethodBeat.i(26155);
        com.tencent.mm.plugin.report.service.h.pYm.e(11390, new Object[]{Integer.valueOf(3)});
        Intent intent = new Intent();
        intent.setClass(this, VoiceCreateUI.class);
        intent.putExtra("kscene_type", 71);
        intent.putExtra("createVoicePrint", true);
        startActivityForResult(intent, 1);
        this.lYR = false;
        AppMethodBeat.o(26155);
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        AppMethodBeat.i(26156);
        super.onActivityResult(i, i2, intent);
        if (i == 1 && intent != null) {
            this.lYR = intent.getBooleanExtra("KIsCreateSuccess", false);
        }
        AppMethodBeat.o(26156);
    }

    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        AppMethodBeat.i(26157);
        if (iArr == null || iArr.length <= 0) {
            ab.i("MicroMsg.VoiceSettingsUI", "onRequestPermissionsResult grantResults length 0. requestCode[%d], tid[%d]", new Object[]{Integer.valueOf(i), Long.valueOf(Thread.currentThread().getId())});
            AppMethodBeat.o(26157);
            return;
        }
        ab.i("MicroMsg.VoiceSettingsUI", "onRequestPermissionsResult requestCode[%d],grantResults[%d] tid[%d]", new Object[]{Integer.valueOf(i), Integer.valueOf(iArr[0]), Long.valueOf(Thread.currentThread().getId())});
        switch (i) {
            case 80:
                if (iArr[0] != 0) {
                    h.a(this, getString(2131301928), getString(2131301936), getString(2131300878), getString(2131297773), false, new 6(this), new OnClickListener() {
                        public final void onClick(DialogInterface dialogInterface, int i) {
                            AppMethodBeat.i(26148);
                            dialogInterface.dismiss();
                            AppMethodBeat.o(26148);
                        }
                    });
                    break;
                }
                cHZ();
                AppMethodBeat.o(26157);
                return;
        }
        AppMethodBeat.o(26157);
    }

    public final boolean a(com.tencent.mm.ui.base.preference.f fVar, Preference preference) {
        AppMethodBeat.i(26153);
        String str = preference.mKey;
        Intent intent = new Intent();
        if (str.equals("settings_voiceprint_title")) {
            CheckBoxPreference checkBoxPreference = (CheckBoxPreference) fVar.aqO("settings_voiceprint_title");
            ab.d("MicroMsg.VoiceSettingsUI", "checkPref.isChecked() " + checkBoxPreference.isChecked());
            if (this.ehJ != null && this.ehJ.isShowing()) {
                this.ehJ.dismiss();
            }
            AppCompatActivity appCompatActivity = this.mController.ylL;
            getString(2131297061);
            this.ehJ = h.b(appCompatActivity, getString(2131297086), true, new 4(this));
            if (checkBoxPreference.isChecked()) {
                aw.Rg().a(new i(1), 0);
            } else {
                aw.Rg().a(new i(2), 0);
            }
            AppMethodBeat.o(26153);
            return true;
        } else if (str.equals("settings_voiceprint_unlock")) {
            intent.setClass(this, VoiceUnLockUI.class);
            intent.putExtra("kscene_type", 73);
            startActivity(intent);
            AppMethodBeat.o(26153);
            return true;
        } else if (str.equals("settings_voiceprint_reset")) {
            intent.setClass(this, VoiceCreateUI.class);
            intent.putExtra("KvoicePrintReset", true);
            intent.putExtra("kscene_type", 73);
            startActivityForResult(intent, 1);
            AppMethodBeat.o(26153);
            return true;
        } else {
            AppMethodBeat.o(26153);
            return false;
        }
    }
}
