set default shared preferences values on first startup of app
This commit is contained in:
parent
945149eb14
commit
ade038354a
1 changed files with 24 additions and 9 deletions
|
@ -148,6 +148,14 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
|
|||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
SharedPreferences defaultValueSp = getSharedPreferences(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, Context.MODE_PRIVATE);
|
||||
if(!defaultValueSp.getBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, false)) {
|
||||
PreferenceManager.setDefaultValues(this, R.xml.pref_data_sync, true);
|
||||
PreferenceManager.setDefaultValues(this, R.xml.pref_display, true);
|
||||
PreferenceManager.setDefaultValues(this, R.xml.pref_general, true);
|
||||
PreferenceManager.setDefaultValues(this, R.xml.pref_notification, true);
|
||||
}
|
||||
|
||||
ThemeChooser.chooseTheme(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_newsreader);
|
||||
|
@ -893,18 +901,12 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
|
|||
mApi.initApi(new NextcloudAPI.ApiConnectedListener() {
|
||||
@Override
|
||||
public void onConnected() {
|
||||
String oldLayout = data.getStringExtra(SettingsActivity.SP_FEED_LIST_LAYOUT);
|
||||
String newLayout = PreferenceManager.getDefaultSharedPreferences(NewsReaderListActivity.this).getString(SettingsActivity.SP_FEED_LIST_LAYOUT,"0");
|
||||
|
||||
if(ThemeChooser.getInstance(NewsReaderListActivity.this).themeRequiresRestartOfUI(NewsReaderListActivity.this) || !newLayout.equals(oldLayout)) {
|
||||
NewsReaderListActivity.this.recreate();
|
||||
} else if(data.hasExtra(SettingsActivity.CACHE_CLEARED) && ownCloudSyncService != null) {
|
||||
resetUiAndStartSync();
|
||||
}
|
||||
ensureCorrectTheme(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception ex) {
|
||||
ensureCorrectTheme(data);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
@ -912,12 +914,25 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements
|
|||
} else if(requestCode == RESULT_ADD_NEW_FEED) {
|
||||
if(data != null) {
|
||||
boolean val = data.getBooleanExtra(NewFeedActivity.ADD_NEW_SUCCESS, false);
|
||||
if (val)
|
||||
if (val) {
|
||||
startSync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureCorrectTheme(Intent data) {
|
||||
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String oldListLayout = data.getStringExtra(SettingsActivity.SP_FEED_LIST_LAYOUT);
|
||||
String newListLayout = mPrefs.getString(SettingsActivity.SP_FEED_LIST_LAYOUT,"0");
|
||||
|
||||
if (ThemeChooser.getInstance(NewsReaderListActivity.this).themeRequiresRestartOfUI(NewsReaderListActivity.this) || !newListLayout.equals(oldListLayout)) {
|
||||
NewsReaderListActivity.this.recreate();
|
||||
} else if (data.hasExtra(SettingsActivity.CACHE_CLEARED) && ownCloudSyncService != null) {
|
||||
resetUiAndStartSync();
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public NewsReaderListFragment getSlidingListFragment() {
|
||||
return ((NewsReaderListFragment) getSupportFragmentManager().findFragmentById(R.id.left_drawer));
|
||||
|
|
Loading…
Reference in a new issue