Implementing "withDelay" in Picasso Android (for skimming)

When working with many scrollable images, you need to avoid problems with loading while skimming, while the user performs fast scrolling. The simplest and often the best solution is remarkably simple:

just enter a little delay (say 0.350) before doing anything .

If the image is already in the cache, just download it. Otherwise, just wait a bit - and then continue completely normal.

With gorgeous Picasso, it looks depressing that there is a fork that actually does just that, it has the option "withDelay" ** (see https://github.com/square/picasso/issues/248 )

I'm scared of forks.

But is it possible to do this in Picasso, perhaps using a custom "Target"? Thus,

My usual Picasso call (at the end of getView ...)

Picasso. with(State.mainContext). load(imageFile.getUrl()). placeholder(R.drawable.default). noFade(). into(v.im); 

whereas 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 this, can anyone do this?

+3
android picasso lazy-loading async-loading
source share
2 answers

change

therefore, apparently, the guys in the square are just starting to move forward with their things. https://github.com/square/picasso/pull/665

therefore, Lucasr took over and re-organized part of the code. Now pause / resume can be performed in groups, all requests have DEFAULT_GROUP , and, apparently, the idea of ​​ScrollListener has been crossed out because there is too much simple implementation for them, but this is 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. } } 

This implementation comes with the idea that you tag your requests with context, but you can also easily tag your own tags by default.

original answer:

There is already a PullRequest for Picasso for this feature: https://github.com/square/picasso/pull/561

This is a little different than what you suggested, but it works fine (I use in my application). You have the option to pause / resume sending images to ImageViews and use onScrollListener to pause its resumption.

The code for it is simple:

 listView.setOnScrollListener(new PicassoScrollListener(context)); 

I agree that forks are annoying because they can become obsolete, but they can develop it themselves and keep it in the know until it is drained into Picasso.

  • Picasso original fork
  • add this as a remote https://github.com/sockeqwe/picasso and select it
  • create your picasso / master branch and cherry, pick these 10 commits from sockeqwe / picasso.
  • pull a picasso / master as often as you want

This is not perfect, but the programming is done for you, and it works very well.

Alternatively, you can use my compile 'com.eyeem.picasso:picasso:2.3.3-SNAPSHOT' application fork compile 'com.eyeem.picasso:picasso:2.3.3-SNAPSHOT' and keep an eye on this tensile request until it is merged and you return.

+10
source share

The ability to pause / resume the request will be part of the next version of Picasso 2.4. Just yesterday, the pull request containing this function was merged in the main branch. This makes it easy to identify the scroll listener that pauses / resumes Picasso during flinging, as shown in the sample code that is reported below:

 public class SampleScrollListener implements AbsListView.OnScrollListener { private final Context context; 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(context); } else { picasso.pauseTag(context); } } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { // Do nothing. } } 
+6
source share

All Articles