Check if selected theme it's not the current

This commit is contained in:
Mauricio Colli 2017-02-25 16:04:10 -03:00
parent f8d9e0fa60
commit 6ec393699e
1 changed files with 21 additions and 17 deletions

View File

@ -98,6 +98,8 @@ public class SettingsFragment extends PreferenceFragment
downloadPathAudioPreference = findPreference(DOWNLOAD_PATH_AUDIO_PREFERENCE); downloadPathAudioPreference = findPreference(DOWNLOAD_PATH_AUDIO_PREFERENCE);
themePreference = findPreference(THEME); themePreference = findPreference(THEME);
final String currentTheme = defaultPreferences.getString(THEME, "Light");
prefListener = new SharedPreferences.OnSharedPreferenceChangeListener() { prefListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
@ -139,25 +141,27 @@ public class SettingsFragment extends PreferenceFragment
} }
else if (key == THEME) else if (key == THEME)
{ {
String theme = sharedPreferences.getString(THEME, "Light"); String selectedTheme = sharedPreferences.getString(THEME, "Light");
themePreference.setSummary(theme); themePreference.setSummary(selectedTheme);
new AlertDialog.Builder(activity) if(!selectedTheme.equals(currentTheme)) { // If it's not the current theme
.setTitle(R.string.restart_title) new AlertDialog.Builder(activity)
.setMessage(R.string.msg_restart) .setTitle(R.string.restart_title)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { .setMessage(R.string.msg_restart)
@Override .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { @Override
Intent intentToMain = new Intent(activity, MainActivity.class); public void onClick(DialogInterface dialog, int which) {
intentToMain.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); Intent intentToMain = new Intent(activity, MainActivity.class);
activity.startActivity(intentToMain); intentToMain.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
activity.startActivity(intentToMain);
activity.finish(); activity.finish();
Runtime.getRuntime().exit(0); Runtime.getRuntime().exit(0);
} }
}) })
.setNegativeButton(R.string.later, null) .setNegativeButton(R.string.later, null)
.create().show(); .create().show();
}
} }
updateSummary(); updateSummary();
} }