diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java index c75f3367f..8562b21af 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java @@ -24,6 +24,7 @@ import com.simplemobiletools.gallery.MyViewPager; import com.simplemobiletools.gallery.R; import com.simplemobiletools.gallery.Utils; import com.simplemobiletools.gallery.adapters.MyPagerAdapter; +import com.simplemobiletools.gallery.fragments.ViewPagerFragment; import com.simplemobiletools.gallery.models.Medium; import java.io.File; @@ -36,7 +37,8 @@ import butterknife.ButterKnife; import butterknife.OnClick; public class ViewPagerActivity extends AppCompatActivity - implements ViewPager.OnPageChangeListener, View.OnSystemUiVisibilityChangeListener, ViewPager.OnTouchListener { + implements ViewPager.OnPageChangeListener, View.OnSystemUiVisibilityChangeListener, ViewPager.OnTouchListener, + ViewPagerFragment.FragmentClickListener { @BindView(R.id.undo_delete) View undoBtn; @BindView(R.id.view_pager) MyViewPager pager; @@ -76,7 +78,7 @@ public class ViewPagerActivity extends AppCompatActivity if (isDirEmpty()) return; - final MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager(), media); + final MyPagerAdapter adapter = new MyPagerAdapter(this, getSupportFragmentManager(), media); pager.setAdapter(adapter); pager.setCurrentItem(pos); pager.addOnPageChangeListener(this); @@ -301,6 +303,7 @@ public class ViewPagerActivity extends AppCompatActivity return myMedia; } + @Override public void fragmentClicked() { deleteFile(); isFullScreen = !isFullScreen; 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 16f0452ec..a7e6f8786 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/adapters/MyPagerAdapter.java +++ b/app/src/main/java/com/simplemobiletools/gallery/adapters/MyPagerAdapter.java @@ -6,6 +6,7 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import com.simplemobiletools.gallery.Constants; +import com.simplemobiletools.gallery.activities.ViewPagerActivity; import com.simplemobiletools.gallery.fragments.PhotoFragment; import com.simplemobiletools.gallery.fragments.VideoFragment; import com.simplemobiletools.gallery.fragments.ViewPagerFragment; @@ -18,9 +19,11 @@ import java.util.Map; public class MyPagerAdapter extends FragmentStatePagerAdapter { private List media; private Map fragments; + private ViewPagerActivity activity; - public MyPagerAdapter(FragmentManager fm, List media) { + public MyPagerAdapter(ViewPagerActivity act, FragmentManager fm, List media) { super(fm); + this.activity = act; this.media = media; fragments = new HashMap<>(); } @@ -45,6 +48,7 @@ public class MyPagerAdapter extends FragmentStatePagerAdapter { fragments.put(position, fragment); fragment.setArguments(bundle); + fragment.setListener(activity); return fragment; } diff --git a/app/src/main/java/com/simplemobiletools/gallery/fragments/PhotoFragment.java b/app/src/main/java/com/simplemobiletools/gallery/fragments/PhotoFragment.java index 00e4c5c15..06086e010 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/fragments/PhotoFragment.java +++ b/app/src/main/java/com/simplemobiletools/gallery/fragments/PhotoFragment.java @@ -9,7 +9,6 @@ import com.davemorrissey.labs.subscaleview.ImageSource; import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; import com.simplemobiletools.gallery.Constants; import com.simplemobiletools.gallery.R; -import com.simplemobiletools.gallery.activities.ViewPagerActivity; import com.simplemobiletools.gallery.models.Medium; public class PhotoFragment extends ViewPagerFragment implements View.OnClickListener { @@ -38,7 +37,7 @@ public class PhotoFragment extends ViewPagerFragment implements View.OnClickList @Override public void onClick(View v) { - ((ViewPagerActivity) getActivity()).fragmentClicked(); + listener.fragmentClicked(); } @Override diff --git a/app/src/main/java/com/simplemobiletools/gallery/fragments/VideoFragment.java b/app/src/main/java/com/simplemobiletools/gallery/fragments/VideoFragment.java index 38177b014..ab7cde613 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/fragments/VideoFragment.java +++ b/app/src/main/java/com/simplemobiletools/gallery/fragments/VideoFragment.java @@ -24,7 +24,6 @@ import android.widget.TextView; import com.simplemobiletools.gallery.Constants; import com.simplemobiletools.gallery.R; import com.simplemobiletools.gallery.Utils; -import com.simplemobiletools.gallery.activities.ViewPagerActivity; import com.simplemobiletools.gallery.models.Medium; import java.io.IOException; @@ -157,7 +156,7 @@ public class VideoFragment extends ViewPagerFragment default: isFullscreen = !isFullscreen; checkFullscreen(); - ((ViewPagerActivity) getActivity()).fragmentClicked(); + listener.fragmentClicked(); break; } } diff --git a/app/src/main/java/com/simplemobiletools/gallery/fragments/ViewPagerFragment.java b/app/src/main/java/com/simplemobiletools/gallery/fragments/ViewPagerFragment.java index e179d702b..55502a4d7 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/fragments/ViewPagerFragment.java +++ b/app/src/main/java/com/simplemobiletools/gallery/fragments/ViewPagerFragment.java @@ -3,7 +3,17 @@ package com.simplemobiletools.gallery.fragments; import android.support.v4.app.Fragment; public abstract class ViewPagerFragment extends Fragment { + protected FragmentClickListener listener; + + public void setListener(FragmentClickListener ln) { + listener = ln; + } + public abstract void itemDragged(); public abstract void systemUiVisibilityChanged(boolean toFullscreen); + + public interface FragmentClickListener { + void fragmentClicked(); + } }