DF1E / SimpleExplorer

Open Source Filemanager
http://forum.xda-developers.com/showthread.php?t=2330864
GNU General Public License v3.0
138 stars 62 forks source link

Lag on large directory #61

Open traabefi opened 9 years ago

traabefi commented 9 years ago

Hello, I'm using your code in my own file explorer. And I am encountering issue with large directories. Once a directory has more than 1k subFiles when I scroll to it I got lag for 1 second. My tested directory has 17k subFiles and I lag very hard when scrolling over it. Can you please resolve it ?

DF1E commented 9 years ago

Are you browsing in directories which needs root or normal like internal storage?

traabefi commented 9 years ago

In normal folder. I already found where was the problem. Where you go to getView() method in BrowserListAdapter there is this method : IconPreview.getFileIcon(file, mViewHolder.icon); When you open it you can see this method: loadFromRes(file, icon); and inside it there is a line: String[] files = file.list(); And that was causing lag. When you create array of 17k members it takes quite a while, so I changed it into this:

  private static void loadFromRes(final File file, final ImageView icon) {
    Drawable mimeIcon = null;

    if (file != null && file.isDirectory()) {
        if (file.canRead())
            mimeIcon = mResources.getDrawable(R.drawable.type_folder);
        else
            mimeIcon = mResources.getDrawable(R.drawable.type_folder_empty);
    } else if (file != null && file.isFile()) {
        final String fileExt = SimpleUtils.getExtension(file.getName());
        mimeIcon = mMimeTypeIconCache.get(fileExt);

        if (mimeIcon == null) {
            final int mimeIconId = MimeTypes.getIconForExt(fileExt);
            if (mimeIconId != 0) {
                mimeIcon = mResources.getDrawable(mimeIconId);
                mMimeTypeIconCache.put(fileExt, mimeIcon);
            }
        }
    }

    if (mimeIcon != null) {
        icon.setImageDrawable(mimeIcon);
    } else {
        // default icon
        icon.setImageResource(R.drawable.type_unknown);
    }
}
DF1E commented 9 years ago

I use file.list() to check if folder has content for setting the correct icon. I will look for a better solution now..

traabefi commented 9 years ago

I know why you use it. The problem is that it causes lag. Maybe try to put it into another thread.