Skip to content

Commit

Permalink
🔨 The key is no longer included decodeGifImage
Browse files Browse the repository at this point in the history
  • Loading branch information
Flyge committed Oct 8, 2017
1 parent 372505c commit 6ec3dba
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 76 deletions.
46 changes: 6 additions & 40 deletions docs/logs/log_2.5.0_b2.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,10 @@

bugs:
bugs:
* :bug: 修复由于混淆了 Sketch.onTrimMemory 和 Sketch.onLowMemory 方法导致其内部调用过滤失效的 bug

重构:
* :hammer: key 中不再包含 decodeGifImage ,受此影响已经通过 cacheProcessedImageInDisk 生成的磁盘缓存将全部失效

sample app:
* :bug: 修复在 MyPhotos 页面如果数据量超大的话就会崩溃的 bug

[Sketch]: ../../sketch/src/main/java/me/xiaopan/sketch/Sketch.java
[SketchImageView]: ../../sketch/src/main/java/me/xiaopan/sketch/SketchImageView.java
[SketchUtils]: ../../sketch/src/main/java/me/xiaopan/sketch/util/SketchUtils.java
[ImageShaper]: ../../sketch/src/main/java/me/xiaopan/sketch/shaper/ImageShaper.java
[CancelCause]: ../../sketch/src/main/java/me/xiaopan/sketch/request/CancelCause.java
[DownloadListener]: ../../sketch/src/main/java/me/xiaopan/sketch/request/DownloadListener.java
[LoadListener]: ../../sketch/src/main/java/me/xiaopan/sketch/request/LoadListener.java
[DisplayListener]: ../../sketch/src/main/java/me/xiaopan/sketch/request/DisplayListener.java
[Resize]: ../../sketch/src/main/java/me/xiaopan/sketch/request/Resize.java
[LoadOptions]: ../../sketch/src/main/java/me/xiaopan/sketch/request/LoadOptions.java
[DisplayOptions]: ../../sketch/src/main/java/me/xiaopan/sketch/request/DisplayOptions.java
[DownloadHelper]: ../../sketch/src/main/java/me/xiaopan/sketch/request/DownloadHelper.java
[LoadHelper]: ../../sketch/src/main/java/me/xiaopan/sketch/request/LoadHelper.java
[LoadHelper]: ../../sketch/src/main/java/me/xiaopan/sketch/request/LoadHelper.java
[OptionsFilter]: ../../sketch/src/main/java/me/xiaopan/sketch/optionsfilter/OptionsFilter.java
[Configuration]: ../../sketch/src/main/java/me/xiaopan/sketch/Configuration.java
[ImageZoomer]: ../../sketch/src/main/java/me/xiaopan/sketch/viewfun/zoom/ImageZoomer.java
[Initializer]: ../../sketch/src/main/java/me/xiaopan/sketch/Initializer.java
[UriModel]: ../../sketch/src/main/java/me/xiaopan/sketch/uri/UriModel.java
[AppIconUriModel]: ../../sketch/src/main/java/me/xiaopan/sketch/uri/AppIconUriModel.java
[SLog]: ../../sketch/src/main/java/me/xiaopan/sketch/SLog.java
[ImageProcessor]: ../../sketch/src/main/java/me/xiaopan/sketch/process/ImageProcessor.java
[WrappedImageProcessor]: ../../sketch/src/main/java/me/xiaopan/sketch/process/WrappedImageProcessor.java

[log]: ../wiki/log.md
[resize]: ../wiki/resize.md
[shape_size]: ../wiki/shape_size.md
[pause_download]: ../wiki/pause_download.md
[sketch_image_view]: ../wiki/sketch_image_view.md
[display_apk_or_app_icon]: ../wiki/display_apk_or_app_icon.md
[uri_model]: ../wiki/uri_model.md
[uri]: ../wiki/uri.md
[options_filter]: ../wiki/options_filter.md

[#43]: https://github.com/panpf/sketch/issues/43

[sample-video-thumbnail]: ../../sample-video-thumbnail/
* :lipstick: 重构图片详情页的长按菜单
* :lipstick: 兼容 MIX 2 的全屏显示
18 changes: 9 additions & 9 deletions sample/src/main/java/me/xiaopan/sketchsample/bean/Image.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import android.os.Parcel
import android.os.Parcelable

class Image() : Parcelable {
var regularUrl: String? = null
var highDefinitionUrl: String? = null
var normalQualityUrl: String? = null
var rawQualityUrl: String? = null

constructor(parcel: Parcel) : this() {
regularUrl = parcel.readString()
highDefinitionUrl = parcel.readString()
normalQualityUrl = parcel.readString()
rawQualityUrl = parcel.readString()
}

constructor(regularUrl: String, highDefinitionUrl: String) : this() {
this.regularUrl = regularUrl
this.highDefinitionUrl = highDefinitionUrl
this.normalQualityUrl = regularUrl
this.rawQualityUrl = highDefinitionUrl
}

override fun toString(): String {
return String.format("Image{%s -> %s}", regularUrl, highDefinitionUrl)
return String.format("Image{%s -> %s}", normalQualityUrl, rawQualityUrl)
}

override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(regularUrl)
parcel.writeString(highDefinitionUrl)
parcel.writeString(normalQualityUrl)
parcel.writeString(rawQualityUrl)
}

override fun describeContents(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ImageFragment : BaseFragment() {
val mappingView: MappingView by bindView(R.id.mapping_imageFragment)
val hintView: HintView by bindView(R.id.hint_imageFragment_hint)

private var image: Image? = null
lateinit var image: Image
private var loadingImageOptionsKey: String? = null
private var showTools: Boolean = false

Expand Down Expand Up @@ -83,7 +83,7 @@ class ImageFragment : BaseFragment() {
super.onViewCreated(view, savedInstanceState)

val showHighDefinitionImage = AppConfig.getBoolean(context, AppConfig.Key.SHOW_UNSPLASH_RAW_IMAGE)
finalShowImageUrl = if (showHighDefinitionImage && !TextUtils.isEmpty(image!!.highDefinitionUrl)) image!!.highDefinitionUrl else image!!.regularUrl
finalShowImageUrl = if (showHighDefinitionImage && !TextUtils.isEmpty(image.rawQualityUrl)) image.rawQualityUrl else image.normalQualityUrl

imageZoomHelper.onViewCreated()
hugeImageHelper.onViewCreated()
Expand Down Expand Up @@ -144,7 +144,7 @@ class ImageFragment : BaseFragment() {
var cachedRefBitmap: SketchRefBitmap? = null
var memoryCacheKey: String? = null
if (uriModel != null) {
memoryCacheKey = SketchUtils.makeRequestKey(finalShowImageUrl!!, uriModel, loadingImageOptionsKey!!)
memoryCacheKey = SketchUtils.makeRequestKey(image.normalQualityUrl ?: "", uriModel, loadingImageOptionsKey!!)
cachedRefBitmap = Sketch.with(activity).configuration.memoryCache.get(memoryCacheKey)
}
if (cachedRefBitmap != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ private void saveParams() {
}

private boolean checkMemoryCache() {
if (displayOptions.isCacheInMemoryDisabled()) {
if (displayOptions.isCacheInMemoryDisabled() || displayOptions.isDecodeGifImage()) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected void runLoad() {
}

// Check memory cache
if (!displayOptions.isCacheInDiskDisabled()) {
if (!displayOptions.isCacheInDiskDisabled() && !displayOptions.isDecodeGifImage()) {
setStatus(Status.CHECK_MEMORY_CACHE);
MemoryCache memoryCache = getConfiguration().getMemoryCache();
SketchRefBitmap cachedRefBitmap = memoryCache.get(getMemoryCacheKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,28 @@ public Set<FreeRideManager.DisplayFreeRide> getDisplayFreeRideSet() {

@Override
public synchronized boolean processDisplayFreeRide() {
MemoryCache memoryCache = getConfiguration().getMemoryCache();
SketchRefBitmap cachedRefBitmap = memoryCache.get(getMemoryCacheKey());
if (cachedRefBitmap != null && cachedRefBitmap.isRecycled()) {
memoryCache.remove(getMemoryCacheKey());
SLog.e(getLogName(), "memory cache drawable recycled. processFreeRideRequests. bitmap=%s. %s. %s",
cachedRefBitmap.getInfo(), getThreadName(), getKey());
cachedRefBitmap = null;
}
if (!getOptions().isCacheInDiskDisabled() && !getOptions().isDecodeGifImage()) {
MemoryCache memoryCache = getConfiguration().getMemoryCache();
SketchRefBitmap cachedRefBitmap = memoryCache.get(getMemoryCacheKey());
if (cachedRefBitmap != null && cachedRefBitmap.isRecycled()) {
memoryCache.remove(getMemoryCacheKey());
SLog.e(getLogName(), "memory cache drawable recycled. processFreeRideRequests. bitmap=%s. %s. %s",
cachedRefBitmap.getInfo(), getThreadName(), getKey());
cachedRefBitmap = null;
}

if (cachedRefBitmap != null) {
// 立马标记等待使用,防止被回收
cachedRefBitmap.setIsWaitingUse(String.format("%s:waitingUse:fromMemory", getLogName()), true);

Drawable drawable = new SketchBitmapDrawable(cachedRefBitmap, ImageFrom.MEMORY_CACHE);
displayResult = new DisplayResult(drawable, ImageFrom.MEMORY_CACHE, cachedRefBitmap.getAttrs());
displayCompleted();
return true;
} else {
submitRunLoad();
return false;
if (cachedRefBitmap != null) {
// 立马标记等待使用,防止被回收
cachedRefBitmap.setIsWaitingUse(String.format("%s:waitingUse:fromMemory", getLogName()), true);

Drawable drawable = new SketchBitmapDrawable(cachedRefBitmap, ImageFrom.MEMORY_CACHE);
displayResult = new DisplayResult(drawable, ImageFrom.MEMORY_CACHE, cachedRefBitmap.getAttrs());
displayCompleted();
return true;
}
}

submitRunLoad();
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,6 @@ public String makeKey() {
if (inPreferQualityOverSpeed) {
builder.append("_").append("preferQuality");
}
if (decodeGifImage) {
builder.append("_").append("decodeGifImage");
}
if (bitmapConfig != null) {
builder.append("_").append(bitmapConfig.name());
}
Expand Down

0 comments on commit 6ec3dba

Please sign in to comment.