Implement “withdelay” in Picasso Android (for skimming)
When working with many scrolling images, you must avoid the problem of loading during skimming, and users are scrolling quickly. The simplest and usually best solution is very simple:
Just introduce a small delay (say. 350) before doing anything
If the image is already in the cache, just load it. Otherwise, just wait a minute - and then proceed completely normally
With the spectacular Picasso, it's frustrating that there seems to be a fork. In fact, it has a "with delay" option * * (see https://github.com/square/picasso/issues/248 )
I'm afraid of forks
But is it possible to do so in Picasso, perhaps using a custom "target"? So,
My normal Picasso call (at the end of getview...)
Picasso.
with(State.mainContext).
load(imageFile.getUrl()).
placeholder(R.drawable.default).
noFade().
into(v.im);
And I think I want something like this
Picasso.
with(State.mainContext).
load(imageFile.getUrl()).
placeholder(R.drawable.default).
noFade().
into(new Target()
{
simply wait .350 before proceeding completely normally...
});
I can't do that. Can anyone do it?
resolvent:
Edit:
Obviously, the people of square began to push their things forward https://github.com/square/picasso/pull/665
So lucasr took over and reorganized some code. Now pause / resume can be completed in the group, and all requests have a default_ Group, obviously, the idea of scrolllistener has been abandoned because it is too simple to implement, which annoys them, but it is released by the same code @ a.bertucci
public class SampleScrollListener implements AbsListView.OnScrollListener {
private final Context context;
private static final Object scrollTag = new Object(); // this can be static or not, depending what u want to achieve
public SampleScrollListener(Context context) {
this.context = context;
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
final Picasso picasso = Picasso.with(context);
if (scrollState == SCROLL_STATE_IDLE || scrollState == SCROLL_STATE_TOUCH_SCROLL) {
picasso.resuMetag(scrollTag);
} else {
picasso.pauseTag(scrollTag);
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
int totalItemCount) {
// Do nothing.
}
}
The idea of this implementation is that you can mark your request with context, but you can also mark it with default or custom tags
Original answer:
Picasso has a pullrequest for this function: https://github.com/square/picasso/pull/561
It's a little different from your suggestion, but it works well (I use it on my application). You can choose to pause / continue assigning images to imageviews and pause n resume it with onscrolllistener
Its code is simple:
listView.setOnScrollListener(new PicassoScrollListener(context));
I agree that forks are annoying because they may be outdated, but they can fork themselves and keep them up-to-date until they merge on Picasso
>Picasso original > Add as remote https://github.com/sockeqwe/picasso And get it > create your branch with Picasso / master and pick those 10 submissions from sockeqwe / Picasso > pull Picasso / master at will
This is not ideal, but the programming is done for you, and the effect is very good
Or you can use my application fork compile 'com. Eyeem. Picasso: Picasso: 2.3.3-snapshot' and pay close attention to the pull request until it is merged and you restore it