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

import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ListView;
import android.widget.TextView;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.ai.f;
import com.tencent.mm.ai.m;
import com.tencent.mm.kernel.g;
import com.tencent.mm.plugin.setting.model.c;
import com.tencent.mm.plugin.setting.model.i;
import com.tencent.mm.protocal.protobuf.cmb;
import com.tencent.mm.protocal.protobuf.cmc;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.ui.MMActivity;
import com.tencent.mm.ui.base.a;
import com.tencent.mm.ui.base.h;
import com.tencent.smtt.sdk.TbsMediaPlayer$TbsMediaPlayerListener;
import com.tencent.ytcommon.BuildConfig;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

@a(3)
public class SettingsSearchAuthUI extends MMActivity implements f {
    private ListView mListView;
    private ProgressDialog nEK;
    private byte[] qjF;
    private boolean qnu;
    private com.tencent.mm.plugin.fts.ui.widget.a qoG;
    private View qoH;
    private TextView qoI;
    private TextView qoJ;
    private List<cmb> qoK = new ArrayList();
    private a qoL;

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

    public SettingsSearchAuthUI() {
        AppMethodBeat.i(127456);
        AppMethodBeat.o(127456);
    }

    static /* synthetic */ void e(SettingsSearchAuthUI settingsSearchAuthUI) {
        AppMethodBeat.i(127466);
        settingsSearchAuthUI.ciQ();
        AppMethodBeat.o(127466);
    }

    public void onCreate(Bundle bundle) {
        AppMethodBeat.i(127457);
        super.onCreate(bundle);
        initView();
        AppMethodBeat.o(127457);
    }

    public final void initView() {
        AppMethodBeat.i(127458);
        this.qoG = new com.tencent.mm.plugin.fts.ui.widget.a(this);
        this.mListView = (ListView) findViewById(2131827394);
        this.qoL = new a(this, (byte) 0);
        this.mListView.setAdapter(this.qoL);
        this.qoH = findViewById(2131827414);
        this.qoI = (TextView) findViewById(2131827415);
        this.qoJ = (TextView) findViewById(2131827416);
        ciQ();
        getSupportActionBar().setCustomView(this.qoG);
        this.qoG.setSearchViewListener(new 1(this));
        this.qoG.getFtsEditText().setFtsEditTextListener(new 2(this));
        this.qoI.setOnClickListener(new 3(this));
        this.mListView.setOnItemClickListener(new 4(this));
        this.mListView.setOnScrollListener(new OnScrollListener() {
            public final void onScrollStateChanged(AbsListView absListView, int i) {
            }

            public final void onScroll(AbsListView absListView, int i, int i2, int i3) {
                AppMethodBeat.i(127445);
                if (i + i2 == i3) {
                    ab.i("MicroMsg.SettingsSearchAuthUI", "scroll to the end");
                    if (SettingsSearchAuthUI.this.qjF != null) {
                        SettingsSearchAuthUI.a(SettingsSearchAuthUI.this, SettingsSearchAuthUI.this.qjF);
                        SettingsSearchAuthUI.this.qjF = null;
                    }
                }
                AppMethodBeat.o(127445);
            }
        });
        AppMethodBeat.o(127458);
    }

    public void onResume() {
        AppMethodBeat.i(127459);
        super.onResume();
        g.Rg().a(1169, this);
        g.Rg().a(1127, this);
        AppMethodBeat.o(127459);
    }

    public void onPause() {
        AppMethodBeat.i(127460);
        super.onPause();
        g.Rg().b(1169, this);
        g.Rg().b(1127, this);
        AppMethodBeat.o(127460);
    }

    public void finish() {
        AppMethodBeat.i(127462);
        super.finish();
        overridePendingTransition(2131034221, 2131034130);
        AppMethodBeat.o(127462);
    }

    public final int getLayoutId() {
        return 2130970641;
    }

    public void onSceneEnd(int i, int i2, String str, m mVar) {
        AppMethodBeat.i(127463);
        ab.i("MicroMsg.SettingsSearchAuthUI", "errType %d, errCode %d, errMsg %s", new Object[]{Integer.valueOf(i), Integer.valueOf(i2), str});
        if (this.nEK != null) {
            this.nEK.dismiss();
        }
        if (i != 0 || i2 != 0) {
            h.bQ(this, str);
        } else if (mVar.getType() == 1169) {
            byte[] bArr;
            int i3;
            Collection collection;
            i iVar = (i) mVar;
            if (iVar.qjI == null || iVar.qjI.wtv != 1) {
                bArr = null;
            } else {
                bArr = iVar.qjI.wtt.toByteArray();
            }
            this.qjF = bArr;
            if (((i) mVar).qjF != null) {
                i3 = 1;
            } else {
                i3 = 0;
            }
            if (i3 == 0) {
                this.qoK.clear();
            }
            List list = this.qoK;
            i iVar2 = (i) mVar;
            if (iVar2.qjI != null) {
                collection = iVar2.qjI.wtu;
            } else {
                collection = Collections.emptyList();
            }
            list.addAll(collection);
            if (this.qoK.isEmpty()) {
                this.qoH.setVisibility(0);
                this.qoI.setVisibility(8);
                this.qoJ.setVisibility(0);
                this.mListView.setVisibility(8);
                this.qoK.clear();
                ciQ();
                AppMethodBeat.o(127463);
                return;
            }
            this.qoL.qnw = this.qoK;
            this.qoL.notifyDataSetChanged();
            this.qoH.setVisibility(8);
            this.mListView.setVisibility(0);
            ciQ();
            AppMethodBeat.o(127463);
            return;
        } else if (mVar.getType() == 1127) {
            String str2 = ((c) mVar).appId;
            if (!bo.isNullOrNil(str2)) {
                if (!this.qoK.isEmpty()) {
                    Iterator it = this.qoK.iterator();
                    while (it.hasNext()) {
                        if (((cmb) it.next()).csB.equals(str2)) {
                            it.remove();
                            break;
                        }
                    }
                }
                this.qoL.notifyDataSetChanged();
            }
            AppMethodBeat.o(127463);
            return;
        }
        AppMethodBeat.o(127463);
    }

    private void ciQ() {
        AppMethodBeat.i(127461);
        this.mController.removeAllOptionMenu();
        if (!this.qoK.isEmpty()) {
            if (this.qnu) {
                addTextOptionMenu(TbsMediaPlayer$TbsMediaPlayerListener.MEDIA_INFO_VIDEO_TRACK_LAGGING, getString(2131296944), new 6(this));
                AppMethodBeat.o(127461);
                return;
            }
            addTextOptionMenu(TbsMediaPlayer$TbsMediaPlayerListener.MEDIA_INFO_VIDEO_TRACK_LAGGING, getString(2131296969), new 7(this));
        }
        AppMethodBeat.o(127461);
    }

    static /* synthetic */ void a(SettingsSearchAuthUI settingsSearchAuthUI) {
        AppMethodBeat.i(127464);
        settingsSearchAuthUI.qoH.setVisibility(0);
        settingsSearchAuthUI.qoI.setVisibility(0);
        settingsSearchAuthUI.qoJ.setVisibility(8);
        settingsSearchAuthUI.mListView.setVisibility(8);
        settingsSearchAuthUI.qoK.clear();
        settingsSearchAuthUI.ciQ();
        AppMethodBeat.o(127464);
    }

    static /* synthetic */ void c(SettingsSearchAuthUI settingsSearchAuthUI) {
        AppMethodBeat.i(127465);
        settingsSearchAuthUI.qoH.setVisibility(8);
        settingsSearchAuthUI.qoI.setText(BuildConfig.FLAVOR);
        settingsSearchAuthUI.qoK.clear();
        settingsSearchAuthUI.mListView.setVisibility(8);
        settingsSearchAuthUI.ciQ();
        AppMethodBeat.o(127465);
    }

    static /* synthetic */ String cY(List list) {
        AppMethodBeat.i(127469);
        StringBuilder stringBuilder = new StringBuilder();
        for (cmc cmc : list) {
            stringBuilder.append(cmc.qkh);
            stringBuilder.append(",");
        }
        if (stringBuilder.length() > 0) {
            stringBuilder.deleteCharAt(stringBuilder.length() - 1);
        }
        String stringBuilder2 = stringBuilder.toString();
        AppMethodBeat.o(127469);
        return stringBuilder2;
    }
}
