package com.tencent.mm.plugin.clean.ui.fileindexui;

import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.at.a.a.c.a;
import com.tencent.mm.at.o;
import com.tencent.mm.plugin.clean.c.i;
import com.tencent.mm.pluginsdk.f.h;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ak;
import com.tencent.mm.sdk.platformtools.al;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.ui.MMImageView;
import com.tencent.mm.ui.gridviewheaders.GridHeadersGridView.c;
import com.tencent.mm.ui.gridviewheaders.e;
import com.tencent.ytcommon.BuildConfig;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;

public final class b extends BaseAdapter implements e {
    private static int kxm = 0;
    private boolean bbV;
    ArrayList<i> iLD;
    boolean isStop = false;
    OnItemClickListener jMk = new 4(this);
    HashSet<Integer> jur;
    private CleanChattingDetailUI kxl;
    c kxn = new 3(this);
    private ak kxo = new 5(this);
    OnScrollListener kxp = new 6(this);
    private String username;

    public final /* synthetic */ Object getItem(int i) {
        AppMethodBeat.i(18762);
        i tv = tv(i);
        AppMethodBeat.o(18762);
        return tv;
    }

    public b(CleanChattingDetailUI cleanChattingDetailUI, String str) {
        AppMethodBeat.i(18754);
        this.kxl = cleanChattingDetailUI;
        this.jur = new HashSet();
        this.iLD = new ArrayList();
        this.username = str;
        AppMethodBeat.o(18754);
    }

    public final int getCount() {
        AppMethodBeat.i(18755);
        int size = this.iLD.size();
        AppMethodBeat.o(18755);
        return size;
    }

    public final i tv(int i) {
        AppMethodBeat.i(18756);
        i iVar = (i) this.iLD.get(i);
        AppMethodBeat.o(18756);
        return iVar;
    }

    public final long getItemId(int i) {
        return (long) i;
    }

    public final View getView(final int i, View view, ViewGroup viewGroup) {
        c cVar;
        AppMethodBeat.i(18757);
        long currentTimeMillis = System.currentTimeMillis();
        if (view == null) {
            view = this.kxl.getLayoutInflater().inflate(2130969140, viewGroup, false);
            c cVar2 = new c(this);
            cVar2.kxu = (MMImageView) view.findViewById(2131822764);
            cVar2.gnD = (CheckBox) view.findViewById(2131821593);
            cVar2.kxw = view.findViewById(2131822767);
            cVar2.kxx = view.findViewById(2131822766);
            cVar2.kxv = (ImageView) view.findViewById(2131822765);
            cVar2.gxi = (TextView) view.findViewById(2131821227);
            view.setTag(cVar2);
            cVar = cVar2;
        } else {
            cVar = (c) view.getTag();
        }
        i tv = tv(i);
        cVar.kxu.setTag(tv.filePath);
        cVar.kxw.setOnClickListener(new OnClickListener() {
            public final void onClick(View view) {
                AppMethodBeat.i(18747);
                b.a(b.this, i);
                b.this.notifyDataSetChanged();
                AppMethodBeat.o(18747);
            }
        });
        if (this.jur.contains(Integer.valueOf(i))) {
            cVar.gnD.setChecked(true);
            cVar.kxx.setVisibility(0);
        } else {
            cVar.gnD.setChecked(false);
            cVar.kxx.setVisibility(8);
        }
        if (tv.type == 3) {
            cVar.kxv.setVisibility(0);
        } else {
            cVar.kxv.setVisibility(8);
        }
        if (tv.type == 4) {
            o.ahp().b(tv.thumbPath, cVar.kxu);
            cVar.kxu.setImageResource(com.tencent.mm.pluginsdk.model.o.aiD(com.tencent.mm.vfs.e.cv(tv.filePath)));
            cVar.gxi.setText(new com.tencent.mm.vfs.b(tv.filePath).getName());
            cVar.gxi.setVisibility(0);
        } else {
            if (kxm == 0) {
                kxm = view.getMeasuredWidth();
            }
            a aVar = new a();
            aVar.fHe = 1;
            aVar.ePI = false;
            aVar.ePO = kxm;
            aVar.ePN = kxm;
            aVar.ePJ = tv.thumbPath;
            o.ahp().a(tv.thumbPath, cVar.kxu, aVar.ahG());
            cVar.gxi.setVisibility(8);
        }
        ab.d("MicroMsg.CleanChattingDetailAdapter", "getView time=%d", new Object[]{Long.valueOf(System.currentTimeMillis() - currentTimeMillis)});
        AppMethodBeat.o(18757);
        return view;
    }

    public final long tw(int i) {
        AppMethodBeat.i(18758);
        long bfH = ((i) this.iLD.get(i)).bfH();
        AppMethodBeat.o(18758);
        return bfH;
    }

    public final View a(int i, View view, ViewGroup viewGroup) {
        a aVar;
        AppMethodBeat.i(18759);
        if (view == null) {
            ab.v("MicroMsg.CleanChattingDetailAdapter", "convertView is null");
            view = this.kxl.getLayoutInflater().inflate(2130969141, viewGroup, false);
            aVar = new a(this);
            aVar.kxr = (TextView) view.findViewById(2131822768);
            aVar.kxs = (TextView) view.findViewById(2131822769);
            aVar.kxt = (CheckBox) view.findViewById(2131822770);
            view.setTag(aVar);
        } else {
            ab.v("MicroMsg.CleanChattingDetailAdapter", "convertView is not null");
            aVar = (a) view.getTag();
        }
        i tv = tv(i);
        aVar.position = i;
        aVar.kxr.setText(h.formatTime(this.kxl.getString(2131300014), tv.fXb / 1000));
        long bfH = tv.bfH();
        HashSet hashSet = new HashSet();
        for (int i2 = 0; i2 < this.iLD.size(); i2++) {
            if (((i) this.iLD.get(i2)).bfH() == bfH) {
                hashSet.add(Integer.valueOf(i2));
            }
        }
        Iterator it = hashSet.iterator();
        boolean z = true;
        while (it.hasNext()) {
            boolean z2;
            if (this.jur.contains(Integer.valueOf(((Integer) it.next()).intValue()))) {
                z2 = z;
            } else {
                z2 = false;
            }
            z = z2;
        }
        if (z) {
            aVar.kxt.setChecked(true);
        } else {
            aVar.kxt.setChecked(false);
        }
        AppMethodBeat.o(18759);
        return view;
    }

    /* Access modifiers changed, original: final */
    public final void bgi() {
        boolean z;
        AppMethodBeat.i(18760);
        this.kxl.tx(this.jur.size());
        CleanChattingDetailUI cleanChattingDetailUI = this.kxl;
        if (this.jur.size() == this.iLD.size()) {
            z = true;
        } else {
            z = false;
        }
        if (z) {
            cleanChattingDetailUI.kxB.setChecked(true);
        } else {
            cleanChattingDetailUI.kxB.setChecked(false);
        }
        Iterator it = this.jur.iterator();
        long j = 0;
        while (it.hasNext()) {
            j = ((i) this.iLD.get(((Integer) it.next()).intValue())).size + j;
        }
        CleanChattingDetailUI cleanChattingDetailUI2 = this.kxl;
        if (j > 0) {
            cleanChattingDetailUI2.kxC.setText(cleanChattingDetailUI2.getString(2131298867, new Object[]{bo.ga(j)}));
            AppMethodBeat.o(18760);
            return;
        }
        cleanChattingDetailUI2.kxC.setText(BuildConfig.FLAVOR);
        AppMethodBeat.o(18760);
    }

    public final void bgh() {
        AppMethodBeat.i(18761);
        this.jur.clear();
        bgi();
        AppMethodBeat.o(18761);
    }

    static /* synthetic */ void c(b bVar) {
        AppMethodBeat.i(18763);
        if (!bVar.isStop) {
            al.d(new 1(bVar));
        }
        AppMethodBeat.o(18763);
    }
}
