Skip to content

Commit

Permalink
🐛 Fix the bug when the amount of data from the MyPhotos page goes int…
Browse files Browse the repository at this point in the history
…o the details page
  • Loading branch information
Flyge committed Sep 30, 2017
1 parent 1ec9300 commit 5df208b
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 12 deletions.
40 changes: 40 additions & 0 deletions docs/logs/log_2.5.0_b2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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/
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

import butterknife.BindView;
import me.xiaopan.sketchsample.BaseActivity;
import me.xiaopan.sketchsample.ImageOptions;
import me.xiaopan.sketchsample.BindContentView;
import me.xiaopan.sketchsample.ImageOptions;
import me.xiaopan.sketchsample.R;
import me.xiaopan.sketchsample.bean.Image;
import me.xiaopan.sketchsample.fragment.ImageDetailFragment;
import me.xiaopan.sketchsample.util.DeviceUtils;
import me.xiaopan.sketchsample.widget.SampleImageView;
Expand All @@ -42,9 +39,9 @@ public class ImageDetailActivity extends BaseActivity implements ApplyBackground
@BindView(R.id.image_onlyFragment_background) SampleImageView backgroundImageView;
@BindView(R.id.layout_onlyFragment_content) View contentView;

public static void launch(Activity activity, ArrayList<Image> images, String loadingImageOptionsInfo, int defaultPosition) {
public static void launch(Activity activity, String dataTransferKey, String loadingImageOptionsInfo, int defaultPosition) {
Intent intent = new Intent(activity, ImageDetailActivity.class);
intent.putParcelableArrayListExtra(ImageDetailFragment.PARAM_REQUIRED_STRING_ARRAY_LIST_URLS, images);
intent.putExtra(ImageDetailFragment.PARAM_REQUIRED_STRING_DATA_TRANSFER_KEY, dataTransferKey);
intent.putExtra(ImageDetailFragment.PARAM_REQUIRED_STRING_LOADING_IMAGE_OPTIONS_KEY, loadingImageOptionsInfo);
intent.putExtra(ImageDetailFragment.PARAM_OPTIONAL_INT_DEFAULT_POSITION, defaultPosition);
activity.startActivity(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@
import me.xiaopan.sketchsample.R;
import me.xiaopan.sketchsample.adapter.itemfactory.ImageFragmentItemFactory;
import me.xiaopan.sketchsample.bean.Image;
import me.xiaopan.sketchsample.util.DataTransferStation;
import me.xiaopan.sketchsample.util.PageNumberSetter;
import me.xiaopan.sketchsample.util.ViewPagerPlayer;
import me.xiaopan.sketchsample.widget.DepthPageTransformer;
import me.xiaopan.sketchsample.widget.ZoomOutPageTransformer;

@BindContentView(R.layout.fragment_detail)
public class ImageDetailFragment extends BaseFragment implements ImageZoomer.OnViewTapListener {
public static final String PARAM_REQUIRED_STRING_ARRAY_LIST_URLS = "PARAM_REQUIRED_STRING_ARRAY_LIST_URLS";
public static final String PARAM_REQUIRED_STRING_DATA_TRANSFER_KEY = "PARAM_REQUIRED_STRING_DATA_TRANSFER_KEY";
public static final String PARAM_REQUIRED_STRING_LOADING_IMAGE_OPTIONS_KEY = "PARAM_REQUIRED_STRING_LOADING_IMAGE_OPTIONS_KEY";
public static final String PARAM_OPTIONAL_INT_DEFAULT_POSITION = "PARAM_OPTIONAL_INT_DEFAULT_POSITION";

Expand Down Expand Up @@ -73,11 +74,18 @@ public void onCreate(Bundle savedInstanceState) {
startPlay = new StartPlay();

Bundle arguments = getArguments();
String dataTransferKey = null;
if (arguments != null) {
imageList = arguments.getParcelableArrayList(PARAM_REQUIRED_STRING_ARRAY_LIST_URLS);
dataTransferKey = arguments.getString(PARAM_REQUIRED_STRING_DATA_TRANSFER_KEY);
//noinspection unchecked
imageList = (List<Image>) DataTransferStation.remove(dataTransferKey);
loadingImageOptionsKey = arguments.getString(PARAM_REQUIRED_STRING_LOADING_IMAGE_OPTIONS_KEY);
position = arguments.getInt(PARAM_OPTIONAL_INT_DEFAULT_POSITION);
}

if (imageList == null) {
throw new IllegalArgumentException("Not found image list by dataTransferKey: " + dataTransferKey);
}
}

@Override
Expand All @@ -102,7 +110,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
pagerAdapter.addItemFactory(new ImageFragmentItemFactory(getActivity(), loadingImageOptionsKey));
viewPager.setAdapter(pagerAdapter);
viewPager.setCurrentItem(position);
currentItemTextView.setText(position + 1 + "");
currentItemTextView.setText(String.format("%d", position + 1));
countTextView.setText(String.valueOf(imageList.size()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import me.xiaopan.sketchsample.bean.Image;
import me.xiaopan.sketchsample.event.AppConfigChangedEvent;
import me.xiaopan.sketchsample.util.AppConfig;
import me.xiaopan.sketchsample.util.DataTransferStation;
import me.xiaopan.sketchsample.util.ImageOrientationCorrectTestFileGenerator;
import me.xiaopan.sketchsample.util.ScrollingPauseLoadManager;
import me.xiaopan.sketchsample.widget.HintView;
Expand Down Expand Up @@ -128,7 +129,7 @@ public void onClickImage(int position, String optionsKey) {
imageArrayList.add(new Image(url, url));
}

ImageDetailActivity.launch(getActivity(), imageArrayList, optionsKey, position);
ImageDetailActivity.launch(getActivity(), DataTransferStation.put(imageArrayList), optionsKey, position);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import me.xiaopan.sketchsample.bean.BaiduImageSearchResult;
import me.xiaopan.sketchsample.bean.Image;
import me.xiaopan.sketchsample.net.NetServices;
import me.xiaopan.sketchsample.util.DataTransferStation;
import me.xiaopan.sketchsample.util.ScrollingPauseLoadManager;
import me.xiaopan.sketchsample.widget.HintView;
import retrofit2.Call;
Expand Down Expand Up @@ -215,7 +216,7 @@ public void onItemClick(int position, BaiduImage image, String loadingImageOptio
for (BaiduImage imageItem : imageList) {
urlList.add(new Image(imageItem.getUrl(), imageItem.getUrl()));
}
ImageDetailActivity.launch(getActivity(), urlList, loadingImageOptionsInfo, position - adapter.getHeaderItemCount());
ImageDetailActivity.launch(getActivity(), DataTransferStation.put(urlList), loadingImageOptionsInfo, position - adapter.getHeaderItemCount());
}

private void loadData(int pageIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import me.xiaopan.sketchsample.bean.Image;
import me.xiaopan.sketchsample.bean.UnsplashImage;
import me.xiaopan.sketchsample.net.NetServices;
import me.xiaopan.sketchsample.util.DataTransferStation;
import me.xiaopan.sketchsample.widget.HintView;
import retrofit2.Call;
import retrofit2.Callback;
Expand Down Expand Up @@ -115,7 +116,7 @@ public void onClickImage(int position, UnsplashImage image, String optionsKey) {
imageArrayList.add(new Image(unsplashImage.urls.regular, unsplashImage.urls.raw));
}

ImageDetailActivity.launch(getActivity(), imageArrayList, optionsKey, position);
ImageDetailActivity.launch(getActivity(), DataTransferStation.put(imageArrayList), optionsKey, position);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package me.xiaopan.sketchsample.util;

import java.util.HashMap;
import java.util.Map;

public class DataTransferStation {
private static final Map<String, Object> OBJECT_MAP = new HashMap<>();

private DataTransferStation() {
}

public static String put(Object o) {
if (o == null) {
return null;
}

String key = "DATA_TRANSFER_KEY_" + System.currentTimeMillis();
OBJECT_MAP.put(key, o);
return key;
}

public static Object remove(String key) {
return OBJECT_MAP.remove(key);
}
}

0 comments on commit 5df208b

Please sign in to comment.