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