diff --git a/app/build.gradle b/app/build.gradle index b23a63f19..54776fdc8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,5 +24,5 @@ dependencies { testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.github.bumptech.glide:glide:3.7.0' - compile 'com.commit451:PhotoView:1.2.4' + compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.4.1' } diff --git a/app/src/main/java/gallery/simplemobiletools/com/ViewPagerFragment.java b/app/src/main/java/gallery/simplemobiletools/com/ViewPagerFragment.java new file mode 100644 index 000000000..3330e0be6 --- /dev/null +++ b/app/src/main/java/gallery/simplemobiletools/com/ViewPagerFragment.java @@ -0,0 +1,30 @@ +package gallery.simplemobiletools.com; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.davemorrissey.labs.subscaleview.ImageSource; +import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; + +public class ViewPagerFragment extends Fragment { + private String path; + + public void setPath(String path) { + this.path = path; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = inflater.inflate(R.layout.pager_item, container, false); + + if (path != null) { + final SubsamplingScaleImageView imageView = (SubsamplingScaleImageView) view.findViewById(R.id.photo); + imageView.setImage(ImageSource.uri(path)); + } + + return view; + } +} diff --git a/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java b/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java index 8eb8f716c..c38a9df44 100644 --- a/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java +++ b/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java @@ -26,7 +26,8 @@ public class ViewPagerActivity extends AppCompatActivity { pos = 0; final MyViewPager pager = (MyViewPager) findViewById(R.id.view_pager); - final MyPagerAdapter adapter = new MyPagerAdapter(this, getPhotos()); + final MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager()); + adapter.setPaths(getPhotos()); pager.setAdapter(adapter); pager.setCurrentItem(pos); } diff --git a/app/src/main/java/gallery/simplemobiletools/com/adapters/MyPagerAdapter.java b/app/src/main/java/gallery/simplemobiletools/com/adapters/MyPagerAdapter.java index 66d0c71fa..a429858db 100644 --- a/app/src/main/java/gallery/simplemobiletools/com/adapters/MyPagerAdapter.java +++ b/app/src/main/java/gallery/simplemobiletools/com/adapters/MyPagerAdapter.java @@ -1,22 +1,21 @@ package gallery.simplemobiletools.com.adapters; -import android.content.Context; -import android.support.v4.view.PagerAdapter; -import android.view.View; -import android.view.ViewGroup; - -import com.bumptech.glide.Glide; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentStatePagerAdapter; import java.util.List; -import uk.co.senab.photoview.PhotoView; +import gallery.simplemobiletools.com.ViewPagerFragment; -public class MyPagerAdapter extends PagerAdapter { - private final Context context; - private final List paths; +public class MyPagerAdapter extends FragmentStatePagerAdapter { + private List paths; - public MyPagerAdapter(Context context, List paths) { - this.context = context; + public MyPagerAdapter(FragmentManager fm) { + super(fm); + } + + public void setPaths(List paths) { this.paths = paths; } @@ -26,21 +25,9 @@ public class MyPagerAdapter extends PagerAdapter { } @Override - public boolean isViewFromObject(View view, Object object) { - return view == object; - } - - @Override - public Object instantiateItem(ViewGroup container, int position) { - final PhotoView photoView = new PhotoView(context); - Glide.with(context).load(paths.get(position)).fitCenter().crossFade().into(photoView); - container.addView(photoView); - photoView.setMaximumScale(20f); - return photoView; - } - - @Override - public void destroyItem(ViewGroup container, int position, Object object) { - container.removeView((View) object); + public Fragment getItem(int position) { + final ViewPagerFragment fragment = new ViewPagerFragment(); + fragment.setPath(paths.get(position)); + return fragment; } } diff --git a/app/src/main/res/layout/pager_item.xml b/app/src/main/res/layout/pager_item.xml new file mode 100644 index 000000000..f88b4cf14 --- /dev/null +++ b/app/src/main/res/layout/pager_item.xml @@ -0,0 +1,6 @@ + +