Skip to content

Commit

Permalink
🐛 Fix bugs from Baidu's gif images that can not be played
Browse files Browse the repository at this point in the history
  • Loading branch information
Flyge committed Sep 12, 2017
1 parent 1291845 commit e8b93e3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected void onSetData(int i, BaiduImage image) {
headParams.height = (int) (itemWidth / (image.getWidth() / (float) image.getHeight()));
imageView.setLayoutParams(headParams);

imageView.displayImage(image.getSourceUrl());
imageView.displayImage(image.getUrl());
}
}
}
15 changes: 11 additions & 4 deletions sample/src/main/java/me/xiaopan/sketchsample/bean/BaiduImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

import com.google.gson.annotations.SerializedName;

import java.util.List;

public class BaiduImage {

@SerializedName("thumbURL")
private String sourceUrl;
@SerializedName("replaceUrl")
private List<ReplaceUrl> replaceUrlList;

@SerializedName("width")
private int width;

@SerializedName("height")
private int height;

public String getSourceUrl() {
return sourceUrl;
public String getUrl() {
return replaceUrlList != null && replaceUrlList.size() > 0 ? replaceUrlList.get(0).objUrl : null;
}

public int getWidth() {
Expand All @@ -24,4 +26,9 @@ public int getWidth() {
public int getHeight() {
return height;
}

public static class ReplaceUrl {
@SerializedName("ObjURL")
public String objUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void onItemClick(int position, BaiduImage image, String loadingImageOptio
List<BaiduImage> imageList = adapter.getDataList();
ArrayList<Image> urlList = new ArrayList<>();
for (BaiduImage imageItem : imageList) {
urlList.add(new Image(imageItem.getSourceUrl(), imageItem.getSourceUrl()));
urlList.add(new Image(imageItem.getUrl(), imageItem.getUrl()));
}
ImageDetailActivity.launch(getActivity(), urlList, loadingImageOptionsInfo, position - adapter.getHeaderItemCount());
}
Expand Down Expand Up @@ -268,7 +268,7 @@ private void filterEmptyImage(Response<BaiduImageSearchResult> response) {
Iterator<BaiduImage> imageIterator = imageList.iterator();
while (imageIterator.hasNext()) {
BaiduImage image = imageIterator.next();
if (image.getSourceUrl() == null || "".equals(image.getSourceUrl())) {
if (image.getUrl() == null || "".equals(image.getUrl())) {
imageIterator.remove();
}
}
Expand All @@ -289,11 +289,11 @@ public void onClick(View v) {
fragment.onRefresh();
}
});
fragment.refreshLayout.setRefreshing(false);
} else {
fragment.adapter.loadMoreFailed();
Toast.makeText(fragment.getActivity(), HintView.getCauseByException(fragment.getActivity(), t), Toast.LENGTH_LONG).show();
}

fragment.refreshLayout.setRefreshing(false);
}

private void create(SearchFragment fragment, Response<BaiduImageSearchResult> response) {
Expand All @@ -311,7 +311,7 @@ private void create(SearchFragment fragment, Response<BaiduImageSearchResult> re
fragment.recyclerView.setAdapter(adapter);
fragment.adapter = adapter;

fragment.changeBackground(images.get(0).getSourceUrl());
fragment.changeBackground(images.get(0).getUrl());
}

private void loadMore(SearchFragment fragment, Response<BaiduImageSearchResult> response) {
Expand All @@ -325,7 +325,7 @@ private void loadMore(SearchFragment fragment, Response<BaiduImageSearchResult>
fragment.adapter.addAll(images);
fragment.adapter.loadMoreFinished(images.size() < 20);

fragment.changeBackground(images.get(0).getSourceUrl());
fragment.changeBackground(images.get(0).getUrl());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ public void onClick(View v) {
fragment.onRefresh();
}
});
fragment.refreshLayout.setRefreshing(false);
} else {
fragment.adapter.loadMoreFailed();
Toast.makeText(fragment.getActivity(), HintView.getCauseByException(fragment.getActivity(), t), Toast.LENGTH_LONG).show();
}

fragment.refreshLayout.setRefreshing(false);
}

private void create(UnsplashPhotosFragment fragment, Response<List<UnsplashImage>> response) {
Expand Down

0 comments on commit e8b93e3

Please sign in to comment.