Commit 7d5d28c1 authored by Sébastien Toque's avatar Sébastien Toque
Browse files

Only save last media & position on exit and if not at the beginning

parent d0b93a1e
...@@ -105,8 +105,8 @@ public class VideoListFragment extends SherlockListFragment implements ISortable ...@@ -105,8 +105,8 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
public void onResume() { public void onResume() {
//Get & highlight the last media //Get & highlight the last media
SharedPreferences preferences = getActivity().getSharedPreferences(PreferencesActivity.NAME, Context.MODE_PRIVATE); SharedPreferences preferences = getActivity().getSharedPreferences(PreferencesActivity.NAME, Context.MODE_PRIVATE);
String lastPath = preferences.getString("LastMedia", null); String lastPath = preferences.getString(PreferencesActivity.LAST_MEDIA, null);
long lastTime = preferences.getLong("LastTime", 0); long lastTime = preferences.getLong(PreferencesActivity.LAST_TIME, 0);
mVideoAdapter.setLastMedia(lastTime, lastPath); mVideoAdapter.setLastMedia(lastTime, lastPath);
mVideoAdapter.notifyDataSetChanged(); mVideoAdapter.notifyDataSetChanged();
mMediaLibrary.addUpdateHandler(mHandler); mMediaLibrary.addUpdateHandler(mHandler);
......
...@@ -81,6 +81,7 @@ public class VideoPlayerActivity extends Activity { ...@@ -81,6 +81,7 @@ public class VideoPlayerActivity extends Activity {
private SurfaceView mSurface; private SurfaceView mSurface;
private SurfaceHolder mSurfaceHolder; private SurfaceHolder mSurfaceHolder;
private LibVLC mLibVLC; private LibVLC mLibVLC;
private String mLocation;
private static final int SURFACE_BEST_FIT = 0; private static final int SURFACE_BEST_FIT = 0;
private static final int SURFACE_FIT_HORIZONTAL = 1; private static final int SURFACE_FIT_HORIZONTAL = 1;
...@@ -212,10 +213,13 @@ public class VideoPlayerActivity extends Activity { ...@@ -212,10 +213,13 @@ public class VideoPlayerActivity extends Activity {
mSurface.setKeepScreenOn(false); mSurface.setKeepScreenOn(false);
// Save position // Save position
SharedPreferences preferences = getSharedPreferences(PreferencesActivity.NAME, MODE_PRIVATE); if (time >= 0) {
SharedPreferences.Editor editor = preferences.edit(); SharedPreferences preferences = getSharedPreferences(PreferencesActivity.NAME, MODE_PRIVATE);
editor.putLong(PreferencesActivity.LAST_TIME, time); SharedPreferences.Editor editor = preferences.edit();
editor.commit(); editor.putString(PreferencesActivity.LAST_MEDIA, mLocation);
editor.putLong(PreferencesActivity.LAST_TIME, time);
editor.commit();
}
super.onPause(); super.onPause();
} }
...@@ -827,7 +831,7 @@ public class VideoPlayerActivity extends Activity { ...@@ -827,7 +831,7 @@ public class VideoPlayerActivity extends Activity {
* *
*/ */
private void load() { private void load() {
String location = null; mLocation = null;
String title = null; String title = null;
String lastLocation = null; String lastLocation = null;
long lastTime = 0; long lastTime = 0;
...@@ -836,27 +840,24 @@ public class VideoPlayerActivity extends Activity { ...@@ -836,27 +840,24 @@ public class VideoPlayerActivity extends Activity {
if (getIntent().getAction() != null if (getIntent().getAction() != null
&& getIntent().getAction().equals(Intent.ACTION_VIEW)) { && getIntent().getAction().equals(Intent.ACTION_VIEW)) {
/* Started from external application */ /* Started from external application */
location = getIntent().getDataString(); mLocation = getIntent().getDataString();
} else if(getIntent().getExtras() != null) { } else if(getIntent().getExtras() != null) {
/* Started from VideoListActivity */ /* Started from VideoListActivity */
location = getIntent().getExtras().getString("itemLocation"); mLocation = getIntent().getExtras().getString("itemLocation");
} }
if (location != null && location.length() > 0) { if (mLocation != null && mLocation.length() > 0) {
mLibVLC.readMedia(location, false); mLibVLC.readMedia(mLocation, false);
mSurface.setKeepScreenOn(true); mSurface.setKeepScreenOn(true);
// Save media for next time, and restore position if it's the same one as before // Save media for next time, and restore position if it's the same one as before
lastLocation = preferences.getString(PreferencesActivity.LAST_MEDIA, null); lastLocation = preferences.getString(PreferencesActivity.LAST_MEDIA, null);
lastTime = preferences.getLong(PreferencesActivity.LAST_TIME, 0); lastTime = preferences.getLong(PreferencesActivity.LAST_TIME, 0);
SharedPreferences.Editor editor = preferences.edit(); if (lastTime > 0 && mLocation.equals(lastLocation))
editor.putString(PreferencesActivity.LAST_MEDIA, location);
editor.commit();
if (lastTime > 0 && location.equals(lastLocation))
mLibVLC.setTime(lastTime); mLibVLC.setTime(lastTime);
try { try {
title = URLDecoder.decode(location, "UTF-8"); title = URLDecoder.decode(mLocation, "UTF-8");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
} }
if (title.startsWith("file:")) { if (title.startsWith("file:")) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment