Skip to content

Commit

Permalink
🔨 OptionsFilterRegistry reame to OptionsFilterManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Flyge committed Oct 29, 2017
1 parent ada2554 commit 179e0bc
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 37 deletions.
1 change: 1 addition & 0 deletions docs/logs/log_2.6.0_p1.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* :hammer: ErrorTracker.onTileSortError() 重命名为 onBlockSortError
* :hammer: 所有 tile 相关的名字 全部改成了 block
* :hammer: UriModelRegistry 重命名为 UriModelManager
* :hammer: OptionsFilterRegistry 重命名为 OptionsFilterManager

sample app:
* :bug: 修复 UNSPLASH 页面没有加载完数据就切换到别的页面时崩溃的 BUG
Expand Down
10 changes: 5 additions & 5 deletions docs/wiki/options_filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class TestOptionsFilter implements OptionsFilter {
}
```

2.然后通过 [OptionsFilterRegistry] 注册 TestOptionsFilter 即可,如下:
2.然后通过 [OptionsFilterManager] 注册 TestOptionsFilter 即可,如下:

```java
OptinsFilterRegistry optinsFilterRegistry = Sketch.with(context).getConfiguration().getOptinsFilterRegistry();
optinsFilterRegistry.add(new OptionsFilterRegistry());
OptinsFilterManager optinsFilterManager = Sketch.with(context).getConfiguration().getOptinsFilterManager();
optinsFilterManager.add(new TestOptionsFilter());
```

### 内置的 OptionsFilter
Expand All @@ -33,10 +33,10 @@ Sketch 内置了四种 [OptionsFilter],如下:
* [PauseDownloadOptionsFilter]:用来控制暂停下载,配合 [MobileDataPauseDownloadController] 可实现移动数据下暂停下载,另参考 [移动数据或有流量限制的 WIFI 下暂停下载图片,节省流量][pause_download]
* [PauseLoadOptionsFilter]:用来控制暂停加载,配合 [ScrollingPauseLoadManager] 可实现列表滑动中暂停加载,另参考 [列表滑动时暂停加载图片,提升列表滑动流畅度][pause_load]

上述四个 [OptionsFilter], [Configuration][OptionsFilterRegistry] 都提供了开关控制,详情请参考源码
上述四个 [OptionsFilter], [Configuration][OptionsFilterManager] 都提供了开关控制,详情请参考源码

[OptionsFilter]: ../../sketch/src/main/java/me/xiaopan/sketch/optionsfilter/OptionsFilter.java
[OptionsFilterRegistry]: ../../sketch/src/main/java/me/xiaopan/sketch/optionsfilter/OptionsFilterRegistry.java
[OptionsFilterManager]: ../../sketch/src/main/java/me/xiaopan/sketch/optionsfilter/OptionsFilterManager.java
[LowQualityOptionsFilter]: ../../sketch/src/main/java/me/xiaopan/sketch/optionsfilter/LowQualityOptionsFilter.java
[InPreferQualityOverSpeedOptionsFilter]: ../../sketch/src/main/java/me/xiaopan/sketch/optionsfilter/InPreferQualityOverSpeedOptionsFilter.java
[PauseDownloadOptionsFilter]: ../../sketch/src/main/java/me/xiaopan/sketch/optionsfilter/PauseDownloadOptionsFilter.java
Expand Down
50 changes: 25 additions & 25 deletions sketch/src/main/java/me/xiaopan/sketch/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import me.xiaopan.sketch.http.HurlStack;
import me.xiaopan.sketch.http.ImageDownloader;
import me.xiaopan.sketch.optionsfilter.OptionsFilter;
import me.xiaopan.sketch.optionsfilter.OptionsFilterRegistry;
import me.xiaopan.sketch.optionsfilter.OptionsFilterManager;
import me.xiaopan.sketch.process.ImageProcessor;
import me.xiaopan.sketch.process.ResizeImageProcessor;
import me.xiaopan.sketch.request.FreeRideManager;
Expand All @@ -62,7 +62,7 @@ public final class Configuration {
private Context context;

private UriModelManager uriModelManager;
private OptionsFilterRegistry optionsFilterRegistry;
private OptionsFilterManager optionsFilterManager;

private DiskCache diskCache;
private BitmapPool bitmapPool;
Expand Down Expand Up @@ -90,7 +90,7 @@ public final class Configuration {
this.context = context;

this.uriModelManager = new UriModelManager();
this.optionsFilterRegistry = new OptionsFilterRegistry();
this.optionsFilterManager = new OptionsFilterManager();

// 由于默认的缓存文件名称从 URLEncoder 加密变成了 MD5 所以这里要升级一下版本号,好清除旧的缓存
this.diskCache = new LruDiskCache(context, this, 2, DiskCache.DISK_CACHE_MAX_SIZE);
Expand Down Expand Up @@ -142,10 +142,10 @@ public UriModelManager getUriModelManager() {
/**
* 获取 {@link OptionsFilter} 管理器
*
* @return {@link OptionsFilterRegistry}. {@link OptionsFilter} 管理器
* @return {@link OptionsFilterManager}. {@link OptionsFilter} 管理器
*/
public OptionsFilterRegistry getOptionsFilterRegistry() {
return optionsFilterRegistry;
public OptionsFilterManager getOptionsFilterManager() {
return optionsFilterManager;
}

/**
Expand Down Expand Up @@ -636,7 +636,7 @@ public Configuration setErrorTracker(@NonNull ErrorTracker errorTracker) {
*/
@SuppressWarnings("unused")
public boolean isPauseDownloadEnabled() {
return optionsFilterRegistry.isPauseDownloadEnabled();
return optionsFilterManager.isPauseDownloadEnabled();
}

/**
Expand All @@ -648,8 +648,8 @@ public boolean isPauseDownloadEnabled() {
@SuppressWarnings("UnusedReturnValue")
@NonNull
public Configuration setPauseDownloadEnabled(boolean pauseDownloadEnabled) {
if (optionsFilterRegistry.isPauseDownloadEnabled() != pauseDownloadEnabled) {
optionsFilterRegistry.setPauseDownloadEnabled(pauseDownloadEnabled);
if (optionsFilterManager.isPauseDownloadEnabled() != pauseDownloadEnabled) {
optionsFilterManager.setPauseDownloadEnabled(pauseDownloadEnabled);
SLog.w(NAME, "pauseDownload=%s", pauseDownloadEnabled);
}
return this;
Expand All @@ -659,7 +659,7 @@ public Configuration setPauseDownloadEnabled(boolean pauseDownloadEnabled) {
* 全局暂停加载新图片?
*/
public boolean isPauseLoadEnabled() {
return optionsFilterRegistry.isPauseLoadEnabled();
return optionsFilterManager.isPauseLoadEnabled();
}

/**
Expand All @@ -671,8 +671,8 @@ public boolean isPauseLoadEnabled() {
@SuppressWarnings("UnusedReturnValue")
@NonNull
public Configuration setPauseLoadEnabled(boolean pauseLoadEnabled) {
if (optionsFilterRegistry.isPauseLoadEnabled() != pauseLoadEnabled) {
optionsFilterRegistry.setPauseLoadEnabled(pauseLoadEnabled);
if (optionsFilterManager.isPauseLoadEnabled() != pauseLoadEnabled) {
optionsFilterManager.setPauseLoadEnabled(pauseLoadEnabled);
SLog.w(NAME, "pauseLoad=%s", pauseLoadEnabled);
}
return this;
Expand All @@ -682,7 +682,7 @@ public Configuration setPauseLoadEnabled(boolean pauseLoadEnabled) {
* 全局使用低质量的图片?
*/
public boolean isLowQualityImageEnabled() {
return optionsFilterRegistry.isLowQualityImageEnabled();
return optionsFilterManager.isLowQualityImageEnabled();
}

/**
Expand All @@ -693,8 +693,8 @@ public boolean isLowQualityImageEnabled() {
*/
@NonNull
public Configuration setLowQualityImageEnabled(boolean lowQualityImageEnabled) {
if (optionsFilterRegistry.isLowQualityImageEnabled() != lowQualityImageEnabled) {
optionsFilterRegistry.setLowQualityImageEnabled(lowQualityImageEnabled);
if (optionsFilterManager.isLowQualityImageEnabled() != lowQualityImageEnabled) {
optionsFilterManager.setLowQualityImageEnabled(lowQualityImageEnabled);
SLog.w(NAME, "lowQualityImage=%s", lowQualityImageEnabled);
}
return this;
Expand All @@ -707,7 +707,7 @@ public Configuration setLowQualityImageEnabled(boolean lowQualityImageEnabled) {
*/
@SuppressWarnings("unused")
public boolean isInPreferQualityOverSpeedEnabled() {
return optionsFilterRegistry.isInPreferQualityOverSpeedEnabled();
return optionsFilterManager.isInPreferQualityOverSpeedEnabled();
}

/**
Expand All @@ -718,8 +718,8 @@ public boolean isInPreferQualityOverSpeedEnabled() {
*/
@NonNull
public Configuration setInPreferQualityOverSpeedEnabled(boolean inPreferQualityOverSpeedEnabled) {
if (optionsFilterRegistry.isInPreferQualityOverSpeedEnabled() != inPreferQualityOverSpeedEnabled) {
optionsFilterRegistry.setInPreferQualityOverSpeedEnabled(inPreferQualityOverSpeedEnabled);
if (optionsFilterManager.isInPreferQualityOverSpeedEnabled() != inPreferQualityOverSpeedEnabled) {
optionsFilterManager.setInPreferQualityOverSpeedEnabled(inPreferQualityOverSpeedEnabled);
SLog.w(NAME, "inPreferQualityOverSpeed=%s", inPreferQualityOverSpeedEnabled);
}
return this;
Expand All @@ -730,7 +730,7 @@ public Configuration setInPreferQualityOverSpeedEnabled(boolean inPreferQualityO
*/
@SuppressWarnings("unused")
public boolean isMobileDataPauseDownloadEnabled() {
return optionsFilterRegistry.isMobileDataPauseDownloadEnabled();
return optionsFilterManager.isMobileDataPauseDownloadEnabled();
}

/**
Expand All @@ -742,7 +742,7 @@ public boolean isMobileDataPauseDownloadEnabled() {
@NonNull
public Configuration setMobileDataPauseDownloadEnabled(boolean mobileDataPauseDownloadEnabled) {
if (isMobileDataPauseDownloadEnabled() != mobileDataPauseDownloadEnabled) {
optionsFilterRegistry.setMobileDataPauseDownloadEnabled(this, mobileDataPauseDownloadEnabled);
optionsFilterManager.setMobileDataPauseDownloadEnabled(this, mobileDataPauseDownloadEnabled);
SLog.w(NAME, "mobileDataPauseDownload=%s", isMobileDataPauseDownloadEnabled());
}
return this;
Expand All @@ -752,7 +752,7 @@ public Configuration setMobileDataPauseDownloadEnabled(boolean mobileDataPauseDo
public String getInfo() {
return NAME + ": " +
"\n" + "uriModelManager:" + uriModelManager.getKey() +
"\n" + "optionsFilterRegistry:" + optionsFilterRegistry.getKey() +
"\n" + "optionsFilterManager:" + optionsFilterManager.getKey() +

"\n" + "diskCache:" + diskCache.getKey() +
"\n" + "bitmapPool:" + bitmapPool.getKey() +
Expand All @@ -775,10 +775,10 @@ public String getInfo() {
"\n" + "requestFactory:" + requestFactory.getKey() +
"\n" + "errorTracker:" + errorTracker.getKey() +

"\n" + "pauseDownload:" + optionsFilterRegistry.isPauseDownloadEnabled() +
"\n" + "pauseLoad:" + optionsFilterRegistry.isPauseLoadEnabled() +
"\n" + "lowQualityImage:" + optionsFilterRegistry.isLowQualityImageEnabled() +
"\n" + "inPreferQualityOverSpeed:" + optionsFilterRegistry.isInPreferQualityOverSpeedEnabled() +
"\n" + "pauseDownload:" + optionsFilterManager.isPauseDownloadEnabled() +
"\n" + "pauseLoad:" + optionsFilterManager.isPauseLoadEnabled() +
"\n" + "lowQualityImage:" + optionsFilterManager.isLowQualityImageEnabled() +
"\n" + "inPreferQualityOverSpeed:" + optionsFilterManager.isInPreferQualityOverSpeedEnabled() +
"\n" + "mobileDataPauseDownload:" + isMobileDataPauseDownloadEnabled();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import me.xiaopan.sketch.Identifier;
import me.xiaopan.sketch.request.DownloadOptions;

public class OptionsFilterRegistry implements Identifier {
public class OptionsFilterManager implements Identifier {

private PauseDownloadOptionsFilter pauseDownloadOptionsFilter;
private PauseLoadOptionsFilter pauseLoadOptionsFilter;
Expand All @@ -35,7 +35,7 @@ public class OptionsFilterRegistry implements Identifier {
private List<OptionsFilter> extrasFilters;

@NonNull
public OptionsFilterRegistry add(@NonNull OptionsFilter optionsFilter) {
public OptionsFilterManager add(@NonNull OptionsFilter optionsFilter) {
//noinspection ConstantConditions
if (optionsFilter != null) {
if (extrasFilters == null) {
Expand All @@ -47,7 +47,7 @@ public OptionsFilterRegistry add(@NonNull OptionsFilter optionsFilter) {
}

@NonNull
public OptionsFilterRegistry add(int index, @NonNull OptionsFilter optionsFilter) {
public OptionsFilterManager add(int index, @NonNull OptionsFilter optionsFilter) {
//noinspection ConstantConditions
if (optionsFilter != null) {
if (extrasFilters == null) {
Expand Down Expand Up @@ -187,6 +187,6 @@ public void setMobileDataPauseDownloadEnabled(Configuration configuration, boole
@NonNull
@Override
public String getKey() {
return "OptionsFilterRegistry";
return "OptionsFilterManager";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ protected void preProcessOptions() {
}
}

configuration.getOptionsFilterRegistry().filter(displayOptions);
configuration.getOptionsFilterManager().filter(displayOptions);

// 根据 URI 和显示选项生成请求 key
key = SketchUtils.makeRequestKey(uri, uriModel, displayOptions.makeKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private boolean checkParam() {
}

protected void preProcessOptions() {
sketch.getConfiguration().getOptionsFilterRegistry().filter(downloadOptions);
sketch.getConfiguration().getOptionsFilterManager().filter(downloadOptions);

// 根据 URI 和下载选项生成请求 key
key = SketchUtils.makeRequestKey(uri, uriModel, downloadOptions.makeKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ protected void preProcessOptions() {
}


configuration.getOptionsFilterRegistry().filter(loadOptions);
configuration.getOptionsFilterManager().filter(loadOptions);

// 根据 URI 和加载选项生成请求 ID
key = SketchUtils.makeRequestKey(uri, uriModel, loadOptions.makeKey());
Expand Down

0 comments on commit 179e0bc

Please sign in to comment.