[Android] Rescan the media library if the list of directories changed
Ludovic Fauvet
git at videolan.org
Mon Oct 1 16:03:52 CEST 2012
vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Mon Oct 1 14:38:05 2012 +0200| [2dfeb3b828d70f229e341a170f2bed6a08e29f06] | committer: Ludovic Fauvet
Rescan the media library if the list of directories changed
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=2dfeb3b828d70f229e341a170f2bed6a08e29f06
---
vlc-android/src/org/videolan/vlc/gui/MainActivity.java | 13 ++++++++++++-
.../src/org/videolan/vlc/gui/PreferencesActivity.java | 13 +++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 41d74ef..64f754a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -88,6 +88,8 @@ public class MainActivity extends SherlockFragmentActivity {
private static final String PREF_SHOW_INFO = "show_info";
private static final String PREF_FIRST_RUN = "first_run";
+ private static final int ACTIVITY_RESULT_PREFERENCES = 1;
+
private ActionBar mActionBar;
private SlidingMenu mMenu;
private SidebarAdapter mSidebarAdapter;
@@ -429,7 +431,7 @@ public class MainActivity extends SherlockFragmentActivity {
// Preferences
case R.id.ml_menu_preferences:
intent = new Intent(this, PreferencesActivity.class);
- startActivity(intent);
+ startActivityForResult(intent, ACTIVITY_RESULT_PREFERENCES);
break;
// Refresh
case R.id.ml_menu_refresh:
@@ -461,6 +463,15 @@ public class MainActivity extends SherlockFragmentActivity {
return super.onOptionsItemSelected(item);
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == ACTIVITY_RESULT_PREFERENCES) {
+ if (resultCode == PreferencesActivity.RESULT_RESCAN)
+ mScanNeeded = true;
+ }
+ }
+
private void reloadPreferences() {
SharedPreferences sharedPrefs = getSharedPreferences("MainActivity", MODE_PRIVATE);
mCurrentFragment = sharedPrefs.getString("fragment", "video");
diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index 9e10bd6..96aa32e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -47,6 +47,7 @@ public class PreferencesActivity extends PreferenceActivity {
public final static String NAME = "VlcSharedPreferences";
public final static String LAST_MEDIA = "LastMedia";
+ public final static int RESULT_RESCAN = RESULT_FIRST_USER + 1;
@SuppressWarnings("deprecation")
@Override
@@ -54,6 +55,17 @@ public class PreferencesActivity extends PreferenceActivity {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
+ // Create onPrefChange
+ Preference rootDirectoryPref = findPreference("directories_root");
+ rootDirectoryPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ setResult(RESULT_RESCAN);
+ return true;
+ }
+ });
+
// Create onClickListen
Preference directoriesPref = findPreference("directories");
directoriesPref.setOnPreferenceClickListener(
@@ -63,6 +75,7 @@ public class PreferencesActivity extends PreferenceActivity {
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(getApplicationContext(), BrowserActivity.class);
startActivity(intent);
+ setResult(RESULT_RESCAN);
return true;
}
});
More information about the Android
mailing list