pause the video if being swiped away
This commit is contained in:
parent
3cd30f7f37
commit
e7e31e25f6
4 changed files with 20 additions and 9 deletions
|
@ -20,11 +20,11 @@ import android.widget.EditText;
|
|||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.simplemobiletools.gallery.Constants;
|
||||
import com.simplemobiletools.gallery.models.Medium;
|
||||
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.models.Medium;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
@ -77,7 +77,7 @@ public class ViewPagerActivity extends AppCompatActivity
|
|||
pager.setCurrentItem(pos);
|
||||
pager.addOnPageChangeListener(this);
|
||||
pager.setOnTouchListener(this);
|
||||
pager.setPageTransformer(true, new DepthPageTransformer());
|
||||
//pager.setPageTransformer(true, new DepthPageTransformer());
|
||||
|
||||
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(this);
|
||||
updateActionbarTitle();
|
||||
|
@ -351,7 +351,7 @@ public class ViewPagerActivity extends AppCompatActivity
|
|||
public void onPageScrollStateChanged(int state) {
|
||||
if (state == ViewPager.SCROLL_STATE_DRAGGING) {
|
||||
final MyPagerAdapter adapter = (MyPagerAdapter) pager.getAdapter();
|
||||
adapter.itemDragged();
|
||||
adapter.itemDragged(pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,20 +6,24 @@ import android.support.v4.app.FragmentManager;
|
|||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
|
||||
import com.simplemobiletools.gallery.Constants;
|
||||
import com.simplemobiletools.gallery.models.Medium;
|
||||
import com.simplemobiletools.gallery.fragments.PhotoFragment;
|
||||
import com.simplemobiletools.gallery.fragments.VideoFragment;
|
||||
import com.simplemobiletools.gallery.fragments.ViewPagerFragment;
|
||||
import com.simplemobiletools.gallery.models.Medium;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MyPagerAdapter extends FragmentStatePagerAdapter {
|
||||
private List<Medium> media;
|
||||
private ViewPagerFragment fragment;
|
||||
private Map<Integer, ViewPagerFragment> fragments;
|
||||
|
||||
public MyPagerAdapter(FragmentManager fm, List<Medium> media) {
|
||||
super(fm);
|
||||
this.media = media;
|
||||
fragments = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,7 +38,7 @@ public class MyPagerAdapter extends FragmentStatePagerAdapter {
|
|||
}
|
||||
|
||||
final Medium medium = media.get(position);
|
||||
Bundle bundle = new Bundle();
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putSerializable(Constants.MEDIUM, medium);
|
||||
|
||||
if (medium.getIsVideo()) {
|
||||
|
@ -43,13 +47,14 @@ public class MyPagerAdapter extends FragmentStatePagerAdapter {
|
|||
fragment = new PhotoFragment();
|
||||
}
|
||||
|
||||
fragments.put(position, fragment);
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public void itemDragged() {
|
||||
if (fragment != null) {
|
||||
fragment.itemDragged();
|
||||
public void itemDragged(int pos) {
|
||||
if (fragments.get(pos) != null) {
|
||||
fragments.get(pos).itemDragged();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,6 @@ public class VideoFragment extends ViewPagerFragment
|
|||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
final View view = inflater.inflate(R.layout.pager_video_item, container, false);
|
||||
;
|
||||
|
||||
medium = (Medium) getArguments().getSerializable(Constants.MEDIUM);
|
||||
if (medium == null)
|
||||
|
|
|
@ -19,4 +19,11 @@ public class Medium implements Serializable {
|
|||
public boolean getIsVideo() {
|
||||
return isVideo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Medium {" +
|
||||
"isVideo=" + getIsVideo() +
|
||||
", path=" + getPath() + "}";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue