Commit 2dfeb3b8 authored by Ludovic Fauvet's avatar Ludovic Fauvet
Browse files

Rescan the media library if the list of directories changed

parent 3881a509
......@@ -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");
......
......@@ -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;
}
});
......
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