[Android] Update the config file whenever a preference within SharedPreferences has been changed.

This commit is contained in:
Lioncash 2013-10-13 22:06:54 -04:00
parent 8efd5e47c6
commit aa36ba9fad

View File

@ -1,6 +1,9 @@
package org.retroarch.browser.preferences.fragments;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
@ -23,7 +26,7 @@ import org.retroarch.browser.preferences.util.UserPreferences;
* This class can be considered the central activity for the settings, as this class
* provides the backbone for the {@link ViewPager} that handles all of the fragments being used.
*/
public final class PreferenceActivity extends ActionBarActivity implements TabListener, OnPreferenceAttachedListener
public final class PreferenceActivity extends ActionBarActivity implements TabListener, OnPreferenceAttachedListener, OnSharedPreferenceChangeListener
{
// ViewPager for the fragments.
private ViewPager viewPager;
@ -38,9 +41,13 @@ public final class PreferenceActivity extends ActionBarActivity implements TabLi
viewPager = (ViewPager) findViewById(R.id.viewPager);
// Initialize the ViewPager adapter.
PreferencesAdapter adapter = new PreferencesAdapter(getSupportFragmentManager());
final PreferencesAdapter adapter = new PreferencesAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter);
// Register the preference change listener.
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(this);
sPrefs.registerOnSharedPreferenceChangeListener(this);
// Initialize the ActionBar.
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
@ -63,24 +70,6 @@ public final class PreferenceActivity extends ActionBarActivity implements TabLi
} );
}
@Override
public void onDestroy()
{
super.onDestroy();
// Update the config file upon closing the settings.
UserPreferences.updateConfigFile(this);
}
@Override
public void onPause()
{
super.onPause();
// Update the preferences if the setting activity gets paused.
UserPreferences.updateConfigFile(this);
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft)
{
@ -100,6 +89,13 @@ public final class PreferenceActivity extends ActionBarActivity implements TabLi
// Do nothing
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
{
// Update the config file immediately when a preference has changed.
UserPreferences.updateConfigFile(this);
}
@Override
public void onPreferenceAttached(PreferenceScreen root, int xmlId)
{