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

import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.ai.f;
import com.tencent.mm.model.aw;
import com.tencent.mm.model.c;
import com.tencent.mm.plugin.label.e;
import com.tencent.mm.plugin.report.service.h;
import com.tencent.mm.pluginsdk.ui.e.j;
import com.tencent.mm.sdk.e.k;
import com.tencent.mm.sdk.e.m;
import com.tencent.mm.sdk.e.n.b;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ak;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.storage.af;
import com.tencent.mm.ui.base.n.d;
import com.tencent.mm.ui.contact.s;
import com.tencent.mm.ui.widget.b.a;
import com.tencent.ytcommon.BuildConfig;
import java.util.ArrayList;
import java.util.HashMap;

public class ContactLabelManagerUI extends ContactLabelBaseUI implements OnCreateContextMenuListener, OnItemClickListener, f, d {
    private int alc;
    private int jLX = 0;
    private int jLY = 0;
    private a jMO;
    private View laJ;
    private ak mHandler = new 1(this);
    private ListView mListView;
    private b nHX = b.nIm;
    private View nHY;
    private View nHZ;
    private a nIa;
    private ArrayList<af> nIb = new ArrayList();
    private HashMap<Integer, Integer> nIc = new HashMap();
    private boolean nId = true;
    private OnClickListener nIe = new OnClickListener() {
        public final void onClick(View view) {
            AppMethodBeat.i(22591);
            ContactLabelManagerUI.b(ContactLabelManagerUI.this);
            AppMethodBeat.o(22591);
        }
    };
    private k.a nIf = new k.a() {
        public final void a(String str, m mVar) {
            AppMethodBeat.i(22592);
            if (!bo.isNullOrNil(str)) {
                ContactLabelManagerUI.a(ContactLabelManagerUI.this);
            }
            AppMethodBeat.o(22592);
        }
    };
    private b nIg = new 8(this);

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

    public ContactLabelManagerUI() {
        AppMethodBeat.i(22606);
        AppMethodBeat.o(22606);
    }

    static /* synthetic */ void a(ContactLabelManagerUI contactLabelManagerUI) {
        AppMethodBeat.i(22621);
        contactLabelManagerUI.iz(false);
        AppMethodBeat.o(22621);
    }

    public final int getLayoutId() {
        return 2130969227;
    }

    public void onCreate(Bundle bundle) {
        AppMethodBeat.i(22608);
        super.onCreate(bundle);
        initView();
        aw.RS().aa(new 13(this));
        e.bIZ().c(this.nIf);
        h.pYm.e(16097, new Object[]{Integer.valueOf(2), Integer.valueOf(0), Integer.valueOf(2)});
        AppMethodBeat.o(22608);
    }

    public void onResume() {
        AppMethodBeat.i(22609);
        aw.Rg().a(636, this);
        aw.ZK();
        c.XM().a(this.nIg);
        iz(true);
        super.onResume();
        AppMethodBeat.o(22609);
    }

    public void onPause() {
        AppMethodBeat.i(22610);
        aw.Rg().b(636, this);
        aw.ZK();
        c.XM().b(this.nIg);
        super.onPause();
        AppMethodBeat.o(22610);
    }

    public void onDestroy() {
        AppMethodBeat.i(22611);
        e.bIZ().d(this.nIf);
        super.onDestroy();
        AppMethodBeat.o(22611);
    }

    public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
        AppMethodBeat.i(22612);
        if (this.nIa != null && i >= 0) {
            af xA = this.nIa.xA(i);
            if (xA != null) {
                String str = xA.field_labelID;
                String str2 = xA.field_labelName;
                Intent intent = new Intent();
                intent.putExtra("label_id", str);
                intent.putExtra("label_name", str2);
                intent.putExtra("label_source", "label_source_Address");
                intent.setClass(this, ContactLabelEditUI.class);
                startActivity(intent);
                if (bo.isNullOrNil(str)) {
                    if (this.nIb == null || this.nIb.isEmpty()) {
                        h.pYm.e(11347, new Object[]{Integer.valueOf(1), Integer.valueOf(0)});
                        AppMethodBeat.o(22612);
                        return;
                    }
                    h.pYm.e(11347, new Object[]{Integer.valueOf(1), Integer.valueOf(1)});
                }
            }
        }
        AppMethodBeat.o(22612);
    }

    public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenuInfo contextMenuInfo) {
        AppMethodBeat.i(22613);
        int i = ((AdapterContextMenuInfo) contextMenuInfo).position;
        if (this.nIa != null && i >= 0) {
            af xA = this.nIa.xA(i);
            if (xA != null) {
                contextMenu.setHeaderTitle(j.b(view.getContext(), xA.field_labelName));
                contextMenu.add(0, 0, 0, getString(2131296881));
                contextMenu.add(0, 1, 1, getString(2131296894));
            }
        }
        super.onCreateContextMenu(contextMenu, view, contextMenuInfo);
        AppMethodBeat.o(22613);
    }

    public void onMMMenuItemSelected(MenuItem menuItem, int i) {
        AppMethodBeat.i(22614);
        int i2 = ((AdapterContextMenuInfo) menuItem.getMenuInfo()).position;
        if (this.nIa != null && i2 >= 0) {
            af xA = this.nIa.xA(i2);
            switch (i) {
                case 0:
                    com.tencent.mm.ui.base.h.d(this, getString(2131300884), BuildConfig.FLAVOR, getString(2131296881), getString(2131296868), new 2(this, xA), new 3(this));
                    AppMethodBeat.o(22614);
                    return;
                case 1:
                    Intent intent = new Intent();
                    intent.setClass(this, ContactLabelEditUI.class);
                    intent.putExtra("label_id", xA.field_labelID);
                    intent.putExtra("label_name", xA.field_labelName);
                    intent.putExtra("label_source", "label_source_Address");
                    startActivity(intent);
                    break;
            }
        }
        AppMethodBeat.o(22614);
    }

    public void onSceneEnd(int i, int i2, String str, com.tencent.mm.ai.m mVar) {
        AppMethodBeat.i(22615);
        ab.i("MicroMsg.Label.ContactLabelManagerUI", "cpan[onSceneEnd]errType:%d errCode:%d errMsg:%s", new Object[]{Integer.valueOf(i), Integer.valueOf(i2), str});
        switch (mVar.getType()) {
            case 636:
                if (i == 0 && i2 == 0) {
                    PM(((com.tencent.mm.plugin.label.b.b) mVar).nHx);
                    AppMethodBeat.o(22615);
                    return;
                }
                ab.w("MicroMsg.Label.ContactLabelManagerUI", "cpan[onSceneEnd] delete fail.");
                bJh();
                AppMethodBeat.o(22615);
                return;
            default:
                ab.w("MicroMsg.Label.ContactLabelManagerUI", "unknow type.");
                AppMethodBeat.o(22615);
                return;
        }
    }

    private synchronized void iz(boolean z) {
        AppMethodBeat.i(22616);
        ab.d("MicroMsg.Label.ContactLabelManagerUI", "loading%s", new Object[]{String.valueOf(z)});
        if (z && this.mHandler != null) {
            this.mHandler.sendEmptyMessageDelayed(5002, 400);
        }
        aw.RS().aa(new 4(this, z));
        AppMethodBeat.o(22616);
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        AppMethodBeat.i(22617);
        ab.i("MicroMsg.Label.ContactLabelManagerUI", "dz[onActivityResult] requestCode:%d resultCode:%d", new Object[]{Integer.valueOf(i), Integer.valueOf(i2)});
        if (i2 != -1) {
            AppMethodBeat.o(22617);
            return;
        }
        switch (i) {
            case 7001:
                String stringExtra = intent.getStringExtra("Select_Contact");
                ab.i("MicroMsg.Label.ContactLabelManagerUI", "dz[onActivityResult] %s", new Object[]{String.valueOf(stringExtra)});
                if (!bo.isNullOrNil(stringExtra)) {
                    Intent intent2 = new Intent(intent);
                    intent2.putExtra("label_source", "label_source_Address");
                    intent2.setClass(this, ContactLabelEditUI.class);
                    intent2.putExtra("Select_Contact", stringExtra);
                    startActivity(intent2);
                    break;
                }
                break;
        }
        super.onActivityResult(i, i2, intent);
        AppMethodBeat.o(22617);
    }

    private void PM(String str) {
        AppMethodBeat.i(22618);
        if (e.bIZ().pI(str)) {
            bJi();
            AppMethodBeat.o(22618);
            return;
        }
        ab.w("MicroMsg.Label.ContactLabelManagerUI", "cpan[doDeleteContactLabel] fail.");
        bJh();
        AppMethodBeat.o(22618);
    }

    private void bJh() {
        AppMethodBeat.i(22619);
        bJc();
        JN(getString(2131298856));
        AppMethodBeat.o(22619);
    }

    private void bJi() {
        AppMethodBeat.i(22620);
        bJc();
        iz(false);
        AppMethodBeat.o(22620);
    }

    public final void initView() {
        AppMethodBeat.i(22607);
        this.alc = com.tencent.mm.bz.a.al(this.mController.ylL, 2131427813);
        setMMTitle(getString(2131300882));
        addTextOptionMenu(0, getString(2131300891), new 9(this));
        setBackBtn(new 10(this));
        this.nIa = new a(this);
        this.laJ = findViewById(2131823065);
        this.nHY = findViewById(2131823067);
        this.nHZ = findViewById(2131823068);
        this.nHZ.setOnClickListener(this.nIe);
        this.mListView = (ListView) findViewById(2131823066);
        this.jMO = new a(this);
        this.mListView.setOnTouchListener(new 11(this));
        this.mListView.setOnItemLongClickListener(new 12(this));
        this.mListView.setAdapter(this.nIa);
        this.mListView.setOnItemClickListener(this);
        AppMethodBeat.o(22607);
    }

    static /* synthetic */ void b(ContactLabelManagerUI contactLabelManagerUI) {
        AppMethodBeat.i(22622);
        if (contactLabelManagerUI.nIb == null || contactLabelManagerUI.nIb.isEmpty()) {
            h.pYm.e(11347, new Object[]{Integer.valueOf(1), Integer.valueOf(0)});
        } else {
            h.pYm.e(11347, new Object[]{Integer.valueOf(1), Integer.valueOf(1)});
        }
        ab.i("MicroMsg.Label.ContactLabelManagerUI", "dz[dealAddLabel]");
        Intent intent = new Intent();
        intent.putExtra("list_attr", s.C(s.znE, 1024));
        intent.putExtra("list_type", 1);
        intent.putExtra("titile", contactLabelManagerUI.getString(2131300881));
        intent.putExtra("show_too_many_member", false);
        intent.putExtra("scene", 5);
        intent.putExtra("label_source", "label_source_Address");
        com.tencent.mm.bp.d.b(contactLabelManagerUI, ".ui.contact.SelectContactUI", intent, 7001);
        AppMethodBeat.o(22622);
    }
}
