From 9ae1e592ed6d8261f8028f304b9939173facaa7e Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 6 Jun 2016 16:27:23 +0200 Subject: [PATCH] set viewpager item as a medium --- .../com/simplemobiletools/gallery/Media.java | 5 ++++- .../gallery/ViewPagerFragment.java | 18 +++++++++--------- .../gallery/adapters/MyPagerAdapter.java | 14 +++++++------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/gallery/Media.java b/app/src/main/java/com/simplemobiletools/gallery/Media.java index 83d82a66e..1c096a3a0 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/Media.java +++ b/app/src/main/java/com/simplemobiletools/gallery/Media.java @@ -1,6 +1,9 @@ package com.simplemobiletools.gallery; -public class Media { +import java.io.Serializable; + +public class Media implements Serializable { + private static final long serialVersionUID = -6543139465975455L; private final String path; private final boolean isVideo; diff --git a/app/src/main/java/com/simplemobiletools/gallery/ViewPagerFragment.java b/app/src/main/java/com/simplemobiletools/gallery/ViewPagerFragment.java index 2e2d0501f..62baae60c 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/ViewPagerFragment.java +++ b/app/src/main/java/com/simplemobiletools/gallery/ViewPagerFragment.java @@ -11,25 +11,25 @@ import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; import com.simplemobiletools.gallery.activities.ViewPagerActivity; public class ViewPagerFragment extends Fragment implements View.OnClickListener { - private static final String PATH = "path"; - private String path; + private static final String MEDIUM = "medium"; + private Media medium; - public void setPath(String path) { - this.path = path; + public void setMedium(Media medium) { + this.medium = medium; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.pager_item, container, false); - if (path == null && savedInstanceState != null) { - path = savedInstanceState.getString(PATH); + if (medium == null && savedInstanceState != null) { + medium = (Media) savedInstanceState.getSerializable(MEDIUM); } - if (path != null) { + if (medium != null) { final SubsamplingScaleImageView imageView = (SubsamplingScaleImageView) view.findViewById(R.id.photo); imageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_USE_EXIF); - imageView.setImage(ImageSource.uri(path)); + imageView.setImage(ImageSource.uri(medium.getPath())); imageView.setMaxScale(5f); imageView.setOnClickListener(this); } @@ -40,7 +40,7 @@ public class ViewPagerFragment extends Fragment implements View.OnClickListener @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putString(PATH, path); + outState.putSerializable(MEDIUM, medium); } @Override diff --git a/app/src/main/java/com/simplemobiletools/gallery/adapters/MyPagerAdapter.java b/app/src/main/java/com/simplemobiletools/gallery/adapters/MyPagerAdapter.java index ab2f637bf..6ede1c19c 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/adapters/MyPagerAdapter.java +++ b/app/src/main/java/com/simplemobiletools/gallery/adapters/MyPagerAdapter.java @@ -10,28 +10,28 @@ import com.simplemobiletools.gallery.ViewPagerFragment; import java.util.List; public class MyPagerAdapter extends FragmentStatePagerAdapter { - private List paths; + private List media; - public MyPagerAdapter(FragmentManager fm, List paths) { + public MyPagerAdapter(FragmentManager fm, List media) { super(fm); - this.paths = paths; + this.media = media; } @Override public int getCount() { - return paths.size(); + return media.size(); } @Override public Fragment getItem(int position) { final ViewPagerFragment fragment = new ViewPagerFragment(); - fragment.setPath(paths.get(position).getPath()); + fragment.setMedium(media.get(position)); return fragment; } public void updateItems(List newPaths) { - paths.clear(); - paths.addAll(newPaths); + media.clear(); + media.addAll(newPaths); notifyDataSetChanged(); } }