Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lag on large directory #61

Open
traabefi opened this issue Aug 2, 2015 · 4 comments
Open

Lag on large directory #61

traabefi opened this issue Aug 2, 2015 · 4 comments

Comments

@traabefi
Copy link

traabefi commented Aug 2, 2015

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
Copy link
Owner

DF1E commented Aug 3, 2015

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

@traabefi
Copy link
Author

traabefi commented Aug 3, 2015

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
Copy link
Owner

DF1E commented Aug 3, 2015

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

@traabefi
Copy link
Author

traabefi commented Aug 4, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants