remember the state on orientation change

This commit is contained in:
tibbi 2016-06-09 21:12:46 +02:00
parent 186b5bfd4f
commit ba76a4a215

View file

@ -34,7 +34,7 @@ public class VideoFragment extends ViewPagerFragment
implements View.OnClickListener, SurfaceHolder.Callback, MediaPlayer.OnCompletionListener, MediaPlayer.OnVideoSizeChangedListener,
SeekBar.OnSeekBarChangeListener {
private static final String TAG = VideoFragment.class.getSimpleName();
private static final String MEDIUM = "medium";
private static final String PROGRESS = "progress";
private MediaPlayer mediaPlayer;
private SurfaceView surfaceView;
private SurfaceHolder surfaceHolder;
@ -56,8 +56,9 @@ public class VideoFragment extends ViewPagerFragment
final View view = inflater.inflate(R.layout.pager_video_item, container, false);
medium = (Medium) getArguments().getSerializable(Constants.MEDIUM);
if (medium == null)
return view;
if (savedInstanceState != null) {
currTime = savedInstanceState.getInt(PROGRESS);
}
isFullscreen = (getActivity().getWindow().getDecorView().getSystemUiVisibility() & View.SYSTEM_UI_FLAG_FULLSCREEN) ==
View.SYSTEM_UI_FLAG_FULLSCREEN;
@ -144,7 +145,7 @@ public class VideoFragment extends ViewPagerFragment
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(MEDIUM, medium);
outState.putInt(PROGRESS, currTime);
}
@Override
@ -242,8 +243,10 @@ public class VideoFragment extends ViewPagerFragment
@Override
public void onDestroy() {
super.onDestroy();
if (getActivity() != null && !getActivity().isChangingConfigurations()) {
cleanup();
}
}
private void cleanup() {
pauseVideo();