Closed klinker41 closed 7 years ago
Preloading images is pretty tough with Glide unfortunately, talon does it, but I am not sure how well it actually works? It is very confusing setting up the data sources for it, just something to be aware of, might be better to store the images outside of glide and just provide a file or content Uri for them
Looks like preloading images should be as simple as this:
Glide.with(this)
.load(uri)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.preload();
http://stackoverflow.com/questions/34720980/glide-preload-doesnt-save-in-cache
I believe that the problem with that was that it only ran on the UI thread
Looks like downloadOnly()
might also be appropriate: https://github.com/bumptech/glide/wiki/Loading-and-Caching-on-Background-Threads
Created database tables to hold cached data with https://github.com/klinker41/article-android/commit/7f90956a381a63d6326900dd7ba9c8422ff0d4ab
Store and load articles from the database with https://github.com/klinker41/article-android/commit/117cb2864de14158b1e92276edf7bdcc6a72c778
Preloading articles now supported with https://github.com/klinker41/article-android/commit/ebf46c8d3e53293b8b68937ca7e4e8595447190d
This is as simple as
ArticleUtils utils = new ArticleUtils(apiToken);
utils.preloadArticle(context, url, callback);
Callback is optional and will give you back an article object after it has finished loading. It is safe to call this method more than once on the same article, only the first time will a network call be made and any later time we'll simply return the cached article.
Images are now preloaded and cached with https://github.com/klinker41/article-android/commit/1f24c20eb8e4a5d58dc47703bfec1b8b628ed043
You shouldn't have to worry about invalidating images in the cache. Glide/Android will handle that for you
Ok, I'm not going to worry about this anymore then. I had to invalidate articles in Source after a set amount of time, but that was because we were downloading so much content. Since these are just text for random articles that you open occasionally, it shouldn't add up to a significant amount for years.
Yeah I wouldn't think so, but we are more casual users haha it may be a few hundred MB for some users after awhile!
We should allow the user to invoke the APIs directly if they wish instead of starting it via the activity. This will allow them to preload the article in the background so that it is available immediately to the user.
Use case for this would be an offline reader app, downloading an article instantly when an SMS is received with a link so that there is no load time later, etc.
This would also help to give the perception of a speedy app. If we need to go to a chrome custom tab instead of our own article, then that could be done instantly instead of waiting for the result from our server.
Implementation wise, a simple SQLite database should work fine to store the article information and HTML, very similar to what Source currently has. Then we would just need to query that database before making a request to the server for the data.
We would also have to preload the images so that they are available when offline and viewing an article. I believe that talon does this already, so we could borrow that implementation.
ArticleUtils
(also update the readme on how to use this)