package com.tencent.mm.pluginsdk.ui.tools;

import android.database.Cursor;
import android.graphics.Bitmap;
import android.os.Build.VERSION;
import android.provider.MediaStore.Images.Media;
import android.provider.MediaStore.Images.Thumbnails;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.platformtools.g;
import com.tencent.mm.pluginsdk.f.h;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.ttpic.baseutils.FileUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class NewFileExplorerUI$a extends BaseAdapter {
    private File vud;
    File[] vue = new File[0];
    final /* synthetic */ NewFileExplorerUI vva;
    private File vvb;
    private boolean vvc = false;
    private ArrayList<File> vvd = new ArrayList();

    public NewFileExplorerUI$a(NewFileExplorerUI newFileExplorerUI) {
        this.vva = newFileExplorerUI;
        AppMethodBeat.i(28186);
        AppMethodBeat.o(28186);
    }

    public final void c(File file, boolean z) {
        this.vvb = file;
        this.vvc = z;
    }

    public final void a(File file, List<String> list) {
        int i = 0;
        AppMethodBeat.i(28187);
        this.vud = file;
        if (this.vud != null && this.vud.canRead() && this.vud.isDirectory()) {
            this.vue = this.vud.listFiles(new 1(this));
            if (this.vue == null) {
                this.vue = new File[0];
            }
            if (this.vue.length > 0) {
                a(this.vue);
                AppMethodBeat.o(28187);
                return;
            }
        } else if (list != null) {
            this.vue = new File[list.size()];
            while (true) {
                int i2 = i;
                if (i2 >= list.size()) {
                    break;
                }
                this.vue[i2] = new File((String) list.get(i2));
                this.vvd.add(this.vue[i2]);
                i = i2 + 1;
            }
        }
        AppMethodBeat.o(28187);
    }

    public final int cdf() {
        AppMethodBeat.i(28188);
        int i = 0;
        Iterator it = this.vvd.iterator();
        while (true) {
            int i2 = i;
            if (it.hasNext()) {
                i = (int) (((File) it.next()).length() + ((long) i2));
            } else {
                AppMethodBeat.o(28188);
                return i2;
            }
        }
    }

    public final ArrayList<String> dlu() {
        AppMethodBeat.i(28189);
        ArrayList arrayList = new ArrayList();
        Iterator it = this.vvd.iterator();
        while (it.hasNext()) {
            File file = (File) it.next();
            if (!(ajX(file.getName()) || aI(file.getName()))) {
                arrayList.add(file.getPath());
            }
        }
        AppMethodBeat.o(28189);
        return arrayList;
    }

    public final ArrayList<String> dlv() {
        AppMethodBeat.i(28190);
        ArrayList arrayList = new ArrayList();
        Iterator it = this.vvd.iterator();
        while (it.hasNext()) {
            File file = (File) it.next();
            if (ajX(file.getName())) {
                arrayList.add(file.getPath());
            }
        }
        AppMethodBeat.o(28190);
        return arrayList;
    }

    public final ArrayList<String> dlw() {
        AppMethodBeat.i(28191);
        ArrayList arrayList = new ArrayList();
        Iterator it = this.vvd.iterator();
        while (it.hasNext()) {
            File file = (File) it.next();
            if (aI(file.getName())) {
                arrayList.add(file.getPath());
            }
        }
        AppMethodBeat.o(28191);
        return arrayList;
    }

    public final File dlx() {
        AppMethodBeat.i(28192);
        if (this.vud.hashCode() == this.vvb.hashCode()) {
            AppMethodBeat.o(28192);
            return null;
        }
        File parentFile = this.vud.getParentFile();
        AppMethodBeat.o(28192);
        return parentFile;
    }

    private void a(File[] fileArr) {
        byte b = (byte) 0;
        AppMethodBeat.i(28193);
        if (fileArr == null || fileArr.length == 0) {
            AppMethodBeat.o(28193);
            return;
        }
        int i;
        ArrayList arrayList = new ArrayList();
        ArrayList<a> arrayList2 = new ArrayList();
        for (File file : fileArr) {
            a aVar = new a(this, (byte) 0);
            aVar.file = file;
            aVar.time = file.lastModified();
            if (file.isDirectory()) {
                aVar.vvf = g.vo(file.getName()).toUpperCase();
                arrayList.add(aVar);
            } else {
                arrayList2.add(aVar);
            }
        }
        Collections.sort(arrayList, new 2(this));
        Collections.sort(arrayList2, new 3(this));
        Iterator it = arrayList.iterator();
        while (true) {
            i = b;
            if (!it.hasNext()) {
                break;
            }
            fileArr[i] = ((a) it.next()).file;
            b = i + 1;
        }
        for (a aVar2 : arrayList2) {
            fileArr[i] = aVar2.file;
            i++;
        }
        AppMethodBeat.o(28193);
    }

    public final int getCount() {
        return this.vue.length;
    }

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

    public final View getView(int i, View view, ViewGroup viewGroup) {
        Bitmap bitmap = null;
        AppMethodBeat.i(28194);
        if (view == null) {
            view = View.inflate(viewGroup.getContext(), 2130969570, null);
            b bVar = new b(this, (byte) 0);
            bVar.vvg = (FrameLayout) view.findViewById(2131824073);
            bVar.vvh = (CheckBox) bVar.vvg.findViewById(2131824075);
            bVar.iqT = (ImageView) view.findViewById(2131823474);
            bVar.gnB = (TextView) view.findViewById(2131823564);
            bVar.pxy = (TextView) view.findViewById(2131823324);
            bVar.enf = (TextView) view.findViewById(2131824074);
            bVar.vvg.setOnClickListener(new 4(this));
            view.setTag(bVar);
        }
        b bVar2 = (b) view.getTag();
        File file = this.vue[i];
        bVar2.gnB.setText(file.getName());
        if (file.isDirectory()) {
            bVar2.iqT.setImageResource(2131230796);
            bVar2.vvg.setVisibility(4);
            bVar2.pxy.setVisibility(0);
            bVar2.enf.setVisibility(8);
            String[] list = file.list(new 5(this));
            int length = list != null ? list.length : 0;
            bVar2.pxy.setText(this.vva.getString(2131299783, new Object[]{Integer.valueOf(length)}));
        } else {
            bVar2.vvg.setVisibility(0);
            bVar2.pxy.setVisibility(0);
            bVar2.enf.setVisibility(0);
            bVar2.pxy.setText(bo.ga(file.length()));
            bVar2.enf.setText(h.c(this.vva, file.lastModified(), true));
            if (ajX(file.getName())) {
                String path = file.getPath();
                Cursor query = this.vva.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[]{"_id"}, "_data=?", new String[]{path}, null);
                if (query != null) {
                    if (query.moveToFirst()) {
                        int i2 = query.getInt(query.getColumnIndex("_id"));
                        query.close();
                        bitmap = Thumbnails.getThumbnail(this.vva.getContentResolver(), (long) i2, 3, null);
                    } else {
                        query.close();
                    }
                }
                if (bitmap != null) {
                    bVar2.iqT.setImageBitmap(bitmap);
                } else {
                    bVar2.iqT.setImageResource(ajW(file.getName()));
                }
            } else {
                bVar2.iqT.setImageResource(ajW(file.getName()));
            }
        }
        bVar2.vvh.setChecked(this.vvd.contains(file));
        bVar2.vvg.setTag(Integer.valueOf(i));
        AppMethodBeat.o(28194);
        return view;
    }

    private static int ajW(String str) {
        AppMethodBeat.i(28195);
        String toLowerCase = str.toLowerCase();
        if (akb(toLowerCase)) {
            AppMethodBeat.o(28195);
            return 2131230821;
        } else if (ajX(toLowerCase)) {
            AppMethodBeat.o(28195);
            return 2130837705;
        } else if (aka(toLowerCase)) {
            AppMethodBeat.o(28195);
            return 2131230809;
        } else if (akf(toLowerCase)) {
            AppMethodBeat.o(28195);
            return 2131230812;
        } else if (akc(toLowerCase)) {
            AppMethodBeat.o(28195);
            return 2131230804;
        } else if (akd(toLowerCase)) {
            AppMethodBeat.o(28195);
            return 2131230807;
        } else if (ake(toLowerCase)) {
            AppMethodBeat.o(28195);
            return 2131230793;
        } else if (aH(toLowerCase)) {
            AppMethodBeat.o(28195);
            return 2131230800;
        } else if (aI(toLowerCase)) {
            AppMethodBeat.o(28195);
            return 2131230817;
        } else if (akh(toLowerCase)) {
            AppMethodBeat.o(28195);
            return 2131230820;
        } else if (akg(toLowerCase)) {
            AppMethodBeat.o(28195);
            return 2131230797;
        } else if (isNumber(toLowerCase)) {
            AppMethodBeat.o(28195);
            return 2131230802;
        } else if (aki(toLowerCase)) {
            AppMethodBeat.o(28195);
            return 2131230803;
        } else {
            AppMethodBeat.o(28195);
            return 2131230813;
        }
    }

    private static boolean ajX(String str) {
        AppMethodBeat.i(28196);
        String toLowerCase = bo.nullAsNil(str).toLowerCase();
        if (VERSION.SDK_INT >= 28 && toLowerCase.endsWith(".heic")) {
            AppMethodBeat.o(28196);
            return true;
        } else if (toLowerCase.endsWith(".bmp") || toLowerCase.endsWith(FileUtils.PIC_POSTFIX_PNG) || toLowerCase.endsWith(FileUtils.PIC_POSTFIX_JPEG) || toLowerCase.endsWith(".jpeg") || toLowerCase.endsWith(".gif")) {
            AppMethodBeat.o(28196);
            return true;
        } else {
            AppMethodBeat.o(28196);
            return false;
        }
    }

    private static boolean aH(String str) {
        AppMethodBeat.i(28197);
        String toLowerCase = bo.nullAsNil(str).toLowerCase();
        if (toLowerCase.endsWith(".mp3") || toLowerCase.endsWith(".wma")) {
            AppMethodBeat.o(28197);
            return true;
        }
        AppMethodBeat.o(28197);
        return false;
    }

    static boolean aI(String str) {
        AppMethodBeat.i(28198);
        String toLowerCase = bo.nullAsNil(str).toLowerCase();
        if (toLowerCase.endsWith(".mp4") || toLowerCase.endsWith(".rm")) {
            AppMethodBeat.o(28198);
            return true;
        }
        AppMethodBeat.o(28198);
        return false;
    }

    private static boolean aka(String str) {
        AppMethodBeat.i(28199);
        String toLowerCase = bo.nullAsNil(str).toLowerCase();
        if (toLowerCase.endsWith(".rar") || toLowerCase.endsWith(".zip") || toLowerCase.endsWith(".7z") || toLowerCase.endsWith("tar") || toLowerCase.endsWith(".iso")) {
            AppMethodBeat.o(28199);
            return true;
        }
        AppMethodBeat.o(28199);
        return false;
    }

    private static boolean akb(String str) {
        AppMethodBeat.i(28200);
        String toLowerCase = bo.nullAsNil(str).toLowerCase();
        if (toLowerCase.endsWith(".doc") || toLowerCase.endsWith(".docx") || toLowerCase.endsWith("wps")) {
            AppMethodBeat.o(28200);
            return true;
        }
        AppMethodBeat.o(28200);
        return false;
    }

    private static boolean akc(String str) {
        AppMethodBeat.i(28201);
        boolean endsWith = bo.nullAsNil(str).toLowerCase().endsWith(".pdf");
        AppMethodBeat.o(28201);
        return endsWith;
    }

    private static boolean akd(String str) {
        AppMethodBeat.i(28202);
        String toLowerCase = bo.nullAsNil(str).toLowerCase();
        if (toLowerCase.endsWith(".ppt") || toLowerCase.endsWith(".pptx")) {
            AppMethodBeat.o(28202);
            return true;
        }
        AppMethodBeat.o(28202);
        return false;
    }

    private static boolean ake(String str) {
        AppMethodBeat.i(28203);
        String toLowerCase = bo.nullAsNil(str).toLowerCase();
        if (toLowerCase.endsWith(".xls") || toLowerCase.endsWith(".xlsx")) {
            AppMethodBeat.o(28203);
            return true;
        }
        AppMethodBeat.o(28203);
        return false;
    }

    private static boolean akf(String str) {
        AppMethodBeat.i(28204);
        String toLowerCase = bo.nullAsNil(str).toLowerCase();
        if (toLowerCase.endsWith(".txt") || toLowerCase.endsWith(".rtf")) {
            AppMethodBeat.o(28204);
            return true;
        }
        AppMethodBeat.o(28204);
        return false;
    }

    private static boolean akg(String str) {
        AppMethodBeat.i(28205);
        boolean endsWith = bo.nullAsNil(str).toLowerCase().endsWith(".key");
        AppMethodBeat.o(28205);
        return endsWith;
    }

    private static boolean akh(String str) {
        AppMethodBeat.i(28206);
        boolean endsWith = bo.nullAsNil(str).toLowerCase().endsWith(".html");
        AppMethodBeat.o(28206);
        return endsWith;
    }

    private static boolean isNumber(String str) {
        AppMethodBeat.i(28207);
        boolean endsWith = bo.nullAsNil(str).toLowerCase().endsWith(".number");
        AppMethodBeat.o(28207);
        return endsWith;
    }

    private static boolean aki(String str) {
        AppMethodBeat.i(28208);
        boolean endsWith = bo.nullAsNil(str).toLowerCase().endsWith(".pages");
        AppMethodBeat.o(28208);
        return endsWith;
    }

    public final /* bridge */ /* synthetic */ Object getItem(int i) {
        return this.vue[i];
    }
}
