From ade038354ae643df255a5cea522eb57f5fad6d3b Mon Sep 17 00:00:00 2001 From: David Luhmer Date: Sat, 13 Oct 2018 13:09:19 +0200 Subject: [PATCH] set default shared preferences values on first startup of app --- .../NewsReaderListActivity.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java index 59d6dfe5..977d4dd1 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java @@ -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));