set viewpager item as a medium
This commit is contained in:
parent
b36d06aafa
commit
9ae1e592ed
3 changed files with 20 additions and 17 deletions
|
@ -1,6 +1,9 @@
|
||||||
package com.simplemobiletools.gallery;
|
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 String path;
|
||||||
private final boolean isVideo;
|
private final boolean isVideo;
|
||||||
|
|
||||||
|
|
|
@ -11,25 +11,25 @@ import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
|
||||||
import com.simplemobiletools.gallery.activities.ViewPagerActivity;
|
import com.simplemobiletools.gallery.activities.ViewPagerActivity;
|
||||||
|
|
||||||
public class ViewPagerFragment extends Fragment implements View.OnClickListener {
|
public class ViewPagerFragment extends Fragment implements View.OnClickListener {
|
||||||
private static final String PATH = "path";
|
private static final String MEDIUM = "medium";
|
||||||
private String path;
|
private Media medium;
|
||||||
|
|
||||||
public void setPath(String path) {
|
public void setMedium(Media medium) {
|
||||||
this.path = path;
|
this.medium = medium;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
final View view = inflater.inflate(R.layout.pager_item, container, false);
|
final View view = inflater.inflate(R.layout.pager_item, container, false);
|
||||||
|
|
||||||
if (path == null && savedInstanceState != null) {
|
if (medium == null && savedInstanceState != null) {
|
||||||
path = savedInstanceState.getString(PATH);
|
medium = (Media) savedInstanceState.getSerializable(MEDIUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path != null) {
|
if (medium != null) {
|
||||||
final SubsamplingScaleImageView imageView = (SubsamplingScaleImageView) view.findViewById(R.id.photo);
|
final SubsamplingScaleImageView imageView = (SubsamplingScaleImageView) view.findViewById(R.id.photo);
|
||||||
imageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_USE_EXIF);
|
imageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_USE_EXIF);
|
||||||
imageView.setImage(ImageSource.uri(path));
|
imageView.setImage(ImageSource.uri(medium.getPath()));
|
||||||
imageView.setMaxScale(5f);
|
imageView.setMaxScale(5f);
|
||||||
imageView.setOnClickListener(this);
|
imageView.setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public class ViewPagerFragment extends Fragment implements View.OnClickListener
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putString(PATH, path);
|
outState.putSerializable(MEDIUM, medium);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,28 +10,28 @@ import com.simplemobiletools.gallery.ViewPagerFragment;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MyPagerAdapter extends FragmentStatePagerAdapter {
|
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);
|
super(fm);
|
||||||
this.paths = paths;
|
this.media = media;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return paths.size();
|
return media.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Fragment getItem(int position) {
|
public Fragment getItem(int position) {
|
||||||
final ViewPagerFragment fragment = new ViewPagerFragment();
|
final ViewPagerFragment fragment = new ViewPagerFragment();
|
||||||
fragment.setPath(paths.get(position).getPath());
|
fragment.setMedium(media.get(position));
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateItems(List<Media> newPaths) {
|
public void updateItems(List<Media> newPaths) {
|
||||||
paths.clear();
|
media.clear();
|
||||||
paths.addAll(newPaths);
|
media.addAll(newPaths);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue