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

import android.content.Context;
import android.content.Intent;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.m.g;
import com.tencent.mm.model.aw;
import com.tencent.mm.model.bf;
import com.tencent.mm.model.c;
import com.tencent.mm.model.r;
import com.tencent.mm.model.t;
import com.tencent.mm.pluginsdk.b.a;
import com.tencent.mm.pluginsdk.ui.preference.HelperHeaderPreference;
import com.tencent.mm.sdk.e.n;
import com.tencent.mm.sdk.e.n.b;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.storage.ad;
import com.tencent.mm.ui.base.h;
import com.tencent.mm.ui.base.preference.CheckBoxPreference;
import com.tencent.mm.ui.base.preference.f;
import com.tencent.ytcommon.BuildConfig;
import java.util.Timer;
import junit.framework.Assert;

public final class j implements a, b {
    private static boolean isDeleteCancel = false;
    private Context context;
    private f ehK;
    private ad ehM;

    public j(Context context) {
        this.context = context;
    }

    public final boolean IO(String str) {
        AppMethodBeat.i(23556);
        ab.d("MicroMsg.ContactWidgetMediaNote", "handleEvent : key = ".concat(String.valueOf(str)));
        if (bo.nullAsNil(str).length() <= 0) {
            AppMethodBeat.o(23556);
            return false;
        } else if (str.equals("contact_info_medianote_view")) {
            Intent intent = new Intent();
            intent.putExtra("Chat_User", "medianote");
            com.tencent.mm.plugin.profile.b.gkE.d(intent, this.context);
            com.tencent.mm.plugin.profile.b.gkF.BS();
            AppMethodBeat.o(23556);
            return true;
        } else if (str.equals("contact_info_medianote_sync_to_qqmail")) {
            if (r.Ze()) {
                jQ(((CheckBoxPreference) this.ehK.aqO(str)).isChecked());
            } else {
                h.a(this.context, 2131298583, 2131298582, new 1(this), null);
                biW();
            }
            AppMethodBeat.o(23556);
            return true;
        } else if (str.equals("contact_info_medianote_clear_data")) {
            h.d(this.context, this.context.getString(2131298491), BuildConfig.FLAVOR, this.context.getString(2131296871), this.context.getString(2131296868), new 2(this), null);
            AppMethodBeat.o(23556);
            return true;
        } else if (str.equals("contact_info_medianote_install")) {
            u(this.context, true);
            AppMethodBeat.o(23556);
            return true;
        } else if (str.equals("contact_info_medianote_uninstall")) {
            h.d(this.context, this.context.getString(2131303217), BuildConfig.FLAVOR, this.context.getString(2131296871), this.context.getString(2131296868), new 3(this), null);
            AppMethodBeat.o(23556);
            return true;
        } else {
            ab.e("MicroMsg.ContactWidgetMediaNote", "handleEvent : unExpected key = ".concat(String.valueOf(str)));
            AppMethodBeat.o(23556);
            return false;
        }
    }

    private static boolean isOpen() {
        AppMethodBeat.i(23557);
        if ((r.YK() & 16) == 0) {
            AppMethodBeat.o(23557);
            return true;
        }
        AppMethodBeat.o(23557);
        return false;
    }

    private static boolean cbb() {
        AppMethodBeat.i(23558);
        int YD = r.YD();
        if (!r.Ze()) {
            if ((YD & 16384) != 0) {
                YD &= -16385;
                aw.ZK();
                c.Ry().set(7, Integer.valueOf(YD));
            }
            AppMethodBeat.o(23558);
            return false;
        } else if ((YD & 16384) != 0) {
            AppMethodBeat.o(23558);
            return true;
        } else {
            AppMethodBeat.o(23558);
            return false;
        }
    }

    public final boolean a(f fVar, ad adVar, boolean z, int i) {
        boolean z2 = false;
        AppMethodBeat.i(23559);
        Assert.assertTrue(fVar != null);
        if (adVar != null) {
            z2 = true;
        }
        Assert.assertTrue(z2);
        Assert.assertTrue(t.no(adVar.field_username));
        aw.ZK();
        c.Ry().a(this);
        this.ehM = adVar;
        this.ehK = fVar;
        fVar.addPreferencesFromResource(2131165212);
        biW();
        AppMethodBeat.o(23559);
        return true;
    }

    private void biW() {
        boolean z;
        boolean z2 = true;
        AppMethodBeat.i(23560);
        boolean isOpen = isOpen();
        boolean cbb = cbb();
        HelperHeaderPreference helperHeaderPreference = (HelperHeaderPreference) this.ehK.aqO("contact_info_header_helper");
        helperHeaderPreference.ay(this.ehM.field_username, this.ehM.Oj(), this.context.getString(2131298584));
        helperHeaderPreference.sd(isOpen ? 1 : 0);
        this.ehK.ce("contact_info_medianote_install", isOpen);
        f fVar = this.ehK;
        String str = "contact_info_medianote_view";
        if (isOpen) {
            z = false;
        } else {
            z = true;
        }
        fVar.ce(str, z);
        if (!isOpen || r.Ze()) {
            z = isOpen;
        } else {
            if (bo.getInt(g.Nu().getValue("BindQQSwitch"), 1) == 1) {
                z = true;
            } else {
                z = false;
            }
            ab.i("MicroMsg.ContactWidgetMediaNote", "summerqq BindQQSwitch off");
        }
        fVar = this.ehK;
        str = "contact_info_medianote_sync_to_qqmail";
        if (z) {
            z = false;
        } else {
            z = true;
        }
        fVar.ce(str, z);
        fVar = this.ehK;
        str = "contact_info_medianote_clear_data";
        if (isOpen) {
            z = false;
        } else {
            z = true;
        }
        fVar.ce(str, z);
        f fVar2 = this.ehK;
        String str2 = "contact_info_medianote_uninstall";
        if (isOpen) {
            z2 = false;
        }
        fVar2.ce(str2, z2);
        ((CheckBoxPreference) this.ehK.aqO("contact_info_medianote_sync_to_qqmail")).uOT = cbb;
        AppMethodBeat.o(23560);
    }

    public static void u(Context context, boolean z) {
        AppMethodBeat.i(23561);
        String string = z ? context.getString(2131303213) : context.getString(2131303221);
        context.getString(2131297061);
        new Timer().schedule(new 5(h.b(context, string, true, null), new 4(z, context)), 1500);
        AppMethodBeat.o(23561);
    }

    public final boolean biV() {
        AppMethodBeat.i(23562);
        aw.ZK();
        c.Ry().b(this);
        com.tencent.mm.plugin.profile.b.gkF.BS();
        AppMethodBeat.o(23562);
        return true;
    }

    public final void a(int i, n nVar, Object obj) {
        AppMethodBeat.i(23563);
        int g = bo.g(obj, 0);
        ab.d("MicroMsg.ContactWidgetMediaNote", "onNotifyChange event:%d obj:%d stg:%s", new Object[]{Integer.valueOf(i), Integer.valueOf(g), nVar});
        aw.ZK();
        if (nVar != c.Ry() || g <= 0) {
            ab.e("MicroMsg.ContactWidgetMediaNote", "onNotifyChange error obj:%d stg:%s", new Object[]{Integer.valueOf(g), nVar});
            AppMethodBeat.o(23563);
        } else if (g == 40 || g == 34 || g == 7) {
            biW();
            AppMethodBeat.o(23563);
        } else {
            AppMethodBeat.o(23563);
        }
    }

    public final void onActivityResult(int i, int i2, Intent intent) {
    }

    static void jQ(boolean z) {
        AppMethodBeat.i(23564);
        int YD = r.YD();
        if (z) {
            YD |= 16384;
        } else {
            YD &= -16385;
        }
        aw.ZK();
        c.Ry().set(7, Integer.valueOf(YD));
        YD = z ? 1 : 2;
        aw.ZK();
        c.XL().c(new com.tencent.mm.az.g(13, YD));
        AppMethodBeat.o(23564);
    }

    static /* synthetic */ void eI(Context context) {
        AppMethodBeat.i(23565);
        isDeleteCancel = false;
        context.getString(2131297061);
        bf.a("medianote", new 7(h.b(context, context.getString(2131297086), true, new 6())));
        aw.ZK();
        c.XR().aoX("medianote");
        AppMethodBeat.o(23565);
    }
}
