set viewpager item as a medium

This commit is contained in:
tibbi 2016-06-06 16:27:23 +02:00
parent b36d06aafa
commit 9ae1e592ed
3 changed files with 20 additions and 17 deletions

View File

@ -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;

View File

@ -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

View File

@ -10,28 +10,28 @@ import com.simplemobiletools.gallery.ViewPagerFragment;
import java.util.List;
public class MyPagerAdapter extends FragmentStatePagerAdapter {
private List<Media> paths;
private List<Media> media;
public MyPagerAdapter(FragmentManager fm, List<Media> paths) {
public MyPagerAdapter(FragmentManager fm, List<Media> 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<Media> newPaths) {
paths.clear();
paths.addAll(newPaths);
media.clear();
media.addAll(newPaths);
notifyDataSetChanged();
}
}