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

import android.content.Context;
import android.content.Intent;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.kernel.g;
import com.tencent.mm.model.r;
import com.tencent.mm.model.t;
import com.tencent.mm.plugin.messenger.foundation.a.j;
import com.tencent.mm.plugin.readerapp.c.c;
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.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 b implements a, com.tencent.mm.sdk.e.n.b {
    Context context;
    private f ehK;
    private ad ehM;

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

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

    static void kc(boolean z) {
        AppMethodBeat.i(76791);
        int YF = r.YF();
        if (z) {
            YF &= -1025;
        } else {
            YF |= 1024;
        }
        g.RP().Ry().set(40, Integer.valueOf(YF));
        ((j) g.K(j.class)).XL().c(new com.tencent.mm.az.g(26, z ? 2 : 1));
        AppMethodBeat.o(76791);
    }

    public final boolean IO(String str) {
        boolean z = false;
        AppMethodBeat.i(76792);
        ab.d("MicroMsg.ContactWidgetReaderAppNews", "handleEvent : key = ".concat(String.valueOf(str)));
        if (bo.nullAsNil(str).length() <= 0) {
            AppMethodBeat.o(76792);
            return false;
        } else if (str.equals("contact_info_readerappnews_view")) {
            Intent intent = new Intent(this.context, ReaderAppUI.class);
            intent.putExtra("type", 20);
            this.context.startActivity(intent);
            com.tencent.mm.plugin.readerapp.b.a.gkF.BS();
            AppMethodBeat.o(76792);
            return true;
        } else if (str.equals("contact_info_readerappnews_subscribe")) {
            this.context.startActivity(new Intent(this.context, ReaderAppSubscribeUI.class));
            AppMethodBeat.o(76792);
            return true;
        } else if (str.equals("contact_info_readerappnews_clear_data")) {
            h.d(this.context, this.context.getString(2131298492), BuildConfig.FLAVOR, this.context.getString(2131296871), this.context.getString(2131296868), new 1(this), null);
            AppMethodBeat.o(76792);
            return true;
        } else if (str.equals("contact_info_readerappnews_recv_remind")) {
            boolean z2;
            CheckBoxPreference checkBoxPreference = (CheckBoxPreference) this.ehK.aqO(str);
            boolean cdX = c.cdX();
            if (cdX) {
                com.tencent.mm.plugin.report.service.h.pYm.e(15413, new Object[]{Integer.valueOf(6), BuildConfig.FLAVOR, BuildConfig.FLAVOR});
            } else {
                com.tencent.mm.plugin.report.service.h.pYm.e(15413, new Object[]{Integer.valueOf(7), BuildConfig.FLAVOR, BuildConfig.FLAVOR});
            }
            if (cdX) {
                z2 = false;
            } else {
                z2 = true;
            }
            checkBoxPreference.uOT = z2;
            if (!cdX) {
                z = true;
            }
            kc(z);
            AppMethodBeat.o(76792);
            return true;
        } else if (str.equals("contact_info_readerappnews_install")) {
            com.tencent.mm.plugin.report.service.h.pYm.e(15413, new Object[]{Integer.valueOf(5), BuildConfig.FLAVOR, BuildConfig.FLAVOR});
            u(this.context, true);
            AppMethodBeat.o(76792);
            return true;
        } else if (str.equals("contact_info_readerappnews_uninstall")) {
            h.d(this.context, this.context.getString(2131303217), BuildConfig.FLAVOR, this.context.getString(2131296871), this.context.getString(2131296868), new 2(this), null);
            AppMethodBeat.o(76792);
            return true;
        } else {
            ab.e("MicroMsg.ContactWidgetReaderAppNews", "handleEvent : unExpected key = ".concat(String.valueOf(str)));
            AppMethodBeat.o(76792);
            return false;
        }
    }

    public final boolean a(f fVar, ad adVar, boolean z, int i) {
        boolean z2 = false;
        AppMethodBeat.i(76793);
        Assert.assertTrue(fVar != null);
        if (adVar != null) {
            z2 = true;
        }
        Assert.assertTrue(z2);
        Assert.assertTrue(t.np(adVar.field_username));
        g.RP().Ry().a(this);
        this.ehM = adVar;
        this.ehK = fVar;
        biW();
        AppMethodBeat.o(76793);
        return true;
    }

    private void biW() {
        AppMethodBeat.i(76794);
        boolean isOpen = isOpen();
        this.ehK.removeAll();
        this.ehK.addPreferencesFromResource(2131165220);
        HelperHeaderPreference helperHeaderPreference = (HelperHeaderPreference) this.ehK.aqO("contact_info_header_helper");
        helperHeaderPreference.ay(this.ehM.field_username, this.ehM.Oj(), this.context.getString(2131298638));
        helperHeaderPreference.sd(isOpen ? 1 : 0);
        CheckBoxPreference checkBoxPreference = (CheckBoxPreference) this.ehK.aqO("contact_info_readerappnews_recv_remind");
        boolean cdX = c.cdX();
        ab.d("MicroMsg.ContactWidgetReaderAppNews", "wantToReceiveNews = ".concat(String.valueOf(cdX)));
        checkBoxPreference.uOT = cdX;
        if (isOpen) {
            this.ehK.aqP("contact_info_readerappnews_install");
            AppMethodBeat.o(76794);
            return;
        }
        this.ehK.aqP("contact_info_readerappnews_subscribe");
        this.ehK.aqP("contact_info_readerappnews_view");
        this.ehK.aqP("contact_info_readerappnews_clear_data");
        this.ehK.aqP("contact_info_readerappnews_uninstall");
        this.ehK.aqP("contact_info_readerappnews_recv_remind");
        AppMethodBeat.o(76794);
    }

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

    public final boolean biV() {
        AppMethodBeat.i(76796);
        g.RP().Ry().b(this);
        com.tencent.mm.plugin.readerapp.b.a.gkF.BS();
        AppMethodBeat.o(76796);
        return true;
    }

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

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