实施" withDelay"在毕加索的Andr​​oid(为略读) [英] Implementing "withDelay" in Picasso Android (for skimming)

查看:329
本文介绍了实施" withDelay"在毕加索的Andr​​oid(为略读)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多滚动图像时,你必须避免负载的问题,同时掠过,而用户快速滚动。最简单,往往是最好的解决方案是非常简单的:

When dealing with many scrolling images, you have to avoid the problem of loading while skimming, while the user is fast scrolling. The simplest and often best solution is remarkably simple:

只是做任何事情之前引入一个小的延迟(例如0.350)

如果图像已经在缓存中,只需加载它。否则,只是等待了一下 - 然后进行完全正常

If the image is already in cache, just load it. Otherwise just wait a bit - and then proceed totally normally.

通过华丽的毕加索,德pressingly它看起来像有一个这其实不只是这一点,它有一个withDelay选项**(见的 https://github.com/square/picasso/issues/248

With the magnificent Picasso, depressingly it looks like there is a fork which in fact does just this, it has a "withDelay" option** (see https://github.com/square/picasso/issues/248)

我很害怕叉。

但有可能做到这一点的毕加索,也许是使用自定义的目标?因此,

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

我的普通电话毕加索(在getView年底...)

My ordinary Picasso call (at the end of a 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 it, can anyone do it?

推荐答案

编辑:

所以显然球员在广场刚刚开始推进自己的东西。 https://github.com/square/picasso/pull/665

so apparently the guys at Square just starting to move forward with their stuff. https://github.com/square/picasso/pull/665

所以Lucasr接管并重新组织了一些code。现在暂停/恢复可以在一组来完成,所有的请求有一个 DEFAULT_GROUP 键,显然ScrollListener想法被抛弃,因为它太简单实现他们费心,但这是相同的code @ a.bertucci发布。

so Lucasr took over and re-organize some of the code. Now the pause/resume can be done in groups, all requests have a DEFAULT_GROUP and apparently the ScrollListener idea was ditched because it's too much of a simple implementation for them to bother, but it's the same code @a.bertucci posted.

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 goes with the idea that you'll tag your requests with the context apparently, but just as easily you could tag with default or your custom tags.

原来的答案:

目前已经是一个PullRequest毕加索此功能在这里: https://github.com/square /毕加索/拉/ 561

There's already a PullRequest on Picasso for this feature here: https://github.com/square/picasso/pull/561

这是从你的建议有点不同,但它的伟大工程(我用我的应用程序)。您可以选择暂停/继续派遣图像到ImageViews并使用 onScrollListener 暂停ñ恢复了。

It's a bit different from what you suggested, but it works great (I'm using on my app). You have an option to pause/resume dispatching the images to the ImageViews and use an onScrollListener to pause n resume it.

在code因为它很简单:

The code for it is simply:

listView.setOnScrollListener(new PicassoScrollListener(context));

我同意,叉是讨厌的,因为他们可以得到过时,但可以自己叉它,它保持最新,直到它被毕加索合并。

I agree that forks are annoying because they can get outdated, but can fork it yourself, and keep it up-to-date until it gets merged on Picasso.

  • 叉毕加索原
  • 添加为一个远程 https://github.com/sockeqwe/picasso ,并把它拿来
  • 创建您的分支了毕加索/主,樱桃挑选sockeqwe /毕加索
  • 10者提交
  • 在拉毕加索/主,只要你想经常
  • fork Picasso original
  • add this as a remote https://github.com/sockeqwe/picasso and fetch it
  • create your branch out of picasso/master and cherry pick those 10 commits from sockeqwe/picasso
  • pull picasso/master as often as you want

这不是理想的,但编程都为你做好了,它工作得很好。

It's not ideal, but the programming is all done for you and it works very well.

另外,您可以使用我的应用程序叉子编译com.eyeem.picasso:毕加索:2.3.3-快照,并保持在该拉的请求的眼睛,直到它得到合并,你恢复。

Alternatively you can use my app fork compile 'com.eyeem.picasso:picasso:2.3.3-SNAPSHOT' and keep an eye on that pull request until it gets merged and you revert.

这篇关于实施" withDelay"在毕加索的Andr​​oid(为略读)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆