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

Remember the last movie and its position

parent 9171e6c9
......@@ -38,6 +38,10 @@ public class PreferencesActivity extends PreferenceActivity {
public final static String TAG = "VLC/PreferencesActivity";
public final static String NAME = "VlcSharedPreferences";
public final static String LAST_MEDIA = "LastMedia";
public final static String LAST_TIME = "LastTime";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......
......@@ -29,11 +29,14 @@ import org.videolan.vlc.Media;
import org.videolan.vlc.MediaLibrary;
import org.videolan.vlc.R;
import org.videolan.vlc.ThumbnailerManager;
import org.videolan.vlc.gui.PreferencesActivity;
import org.videolan.vlc.gui.SearchActivity;
import org.videolan.vlc.interfaces.ISortable;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
......@@ -72,6 +75,17 @@ public class VideoListActivity extends ListActivity implements ISortable {
setListAdapter(mVideoAdapter);
}
@Override
protected void onResume() {
//Get & highlight the last media
SharedPreferences preferences = getSharedPreferences(PreferencesActivity.NAME, Context.MODE_PRIVATE);
String lastPath = preferences.getString("LastMedia", null);
long lastTime = preferences.getLong("LastTime", 0);
mVideoAdapter.setLastMedia(lastTime > 0 ? lastPath : null);
mVideoAdapter.notifyDataSetChanged();
super.onResume();
}
@Override
protected void onDestroy() {
mMediaLibrary.removeUpdateHandler(mHandler);
......
......@@ -30,6 +30,7 @@ import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
......@@ -45,6 +46,7 @@ public class VideoListAdapter extends ArrayAdapter<Media>
public final static int SORT_BY_LENGTH = 1;
private int mSortDirection = 1;
private int mSortBy = SORT_BY_TITLE;
private String mLastPath;
public VideoListAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
......@@ -60,6 +62,10 @@ public class VideoListAdapter extends ArrayAdapter<Media>
}
}
public void setLastMedia(String lastPath) {
mLastPath = lastPath;
}
public void sortBy(int sortby) {
switch (sortby) {
case SORT_BY_TITLE:
......@@ -138,6 +144,7 @@ public class VideoListAdapter extends ArrayAdapter<Media>
holder.thumbnail.setImageBitmap(thumbnail);
}
holder.title.setTextColor(media.getPath().equals(mLastPath) ? Color.RED : Color.WHITE);
holder.more.setTag(media);
holder.more.setOnClickListener(moreClickListener);
......
......@@ -28,6 +28,7 @@ import org.videolan.vlc.LibVLC;
import org.videolan.vlc.LibVlcException;
import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import org.videolan.vlc.gui.PreferencesActivity;
import android.app.Activity;
import android.app.AlertDialog;
......@@ -37,6 +38,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
......@@ -195,10 +197,19 @@ public class VideoPlayerActivity extends Activity {
@Override
protected void onPause() {
if (mLibVLC.isPlaying())
long time = 0;
if (mLibVLC.isPlaying()) {
time = mLibVLC.getTime() - 5000;
mLibVLC.pause();
}
if (mWakeLock.isHeld())
mWakeLock.release();
// Save position
SharedPreferences preferences = getSharedPreferences(PreferencesActivity.NAME, MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putLong(PreferencesActivity.LAST_TIME, time);
editor.commit();
super.onPause();
}
......@@ -777,6 +788,9 @@ public class VideoPlayerActivity extends Activity {
private void load() {
String path = null;
String title = null;
String lastPath = null;
long lastTime = 0;
SharedPreferences preferences = getSharedPreferences(PreferencesActivity.NAME, MODE_PRIVATE);
if (getIntent().getAction() != null
&& getIntent().getAction().equals(Intent.ACTION_VIEW)) {
......@@ -786,11 +800,21 @@ public class VideoPlayerActivity extends Activity {
/* Started from VideoListActivity */
path = getIntent().getExtras().getString("filePath");
}
if (path != null && path.length() > 0) {
mLibVLC.readMedia(path);
if (!mWakeLock.isHeld())
mWakeLock.acquire();
// Save media for next time, and restore position if it's the same one as before
lastPath = preferences.getString(PreferencesActivity.LAST_MEDIA, null);
lastTime = preferences.getLong(PreferencesActivity.LAST_TIME, 0);
SharedPreferences.Editor editor = preferences.edit();
editor.putString(PreferencesActivity.LAST_MEDIA, path);
editor.commit();
if (lastTime > 0 && path.equals(lastPath))
mLibVLC.setTime(lastTime);
title = new File(path).getName();
int dotIndex = title.lastIndexOf('.');
if (dotIndex != -1)
......
Markdown is supported
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