tcoxon / XkcdViewer

Android app to view XKCD comics (including hover text).
http://bytten.net/devlog/xkcdviewer
40 stars 15 forks source link

Enhancement: preload adjacent images. #17

Open tcoxon opened 14 years ago

MatrixFrog commented 13 years ago

By "adjacent" I assume you mean that if the user is looking at comic n, then comics n-1 and n+1 are silently loading in the background. I'm starting to get familiar with the code, and it looks to me like the way to do this would be to keep a few instances of ComicInfo around, instead of just the one. Maybe a map from comic numbers to ComicInfos. Then the getComicInfoFromPage method would just return the value from the map, if it's there. If it's not there, then we follow the current implementation and add it to the map when we're done. Technically, this will only cache the image URL, not the image itself, but I suspect that applying the regexes to the HTML to get the image URL is a large part of the slowness, so it's still probably worth doing.

If I'm not mistaken, this would also have the added bonus of automatically caching the image URL for any of the comics the user has already looked at. I hope I'm not totally misunderstanding your code...