diff options
author | David Luhmer <david-dev@live.de> | 2021-10-27 16:47:00 +0300 |
---|---|---|
committer | David Luhmer <david-dev@live.de> | 2021-10-27 16:47:00 +0300 |
commit | 3761e77a6ed4c321a9f20aedc408c6eb8a3c6067 (patch) | |
tree | 541c720be0a710247d2503494d022e07bb1b6814 /News-Android-App/src/main/java | |
parent | 2e23cfbaea9f636ba643eed6a7fcc13b32f4b833 (diff) |
refactor intent exposure
Diffstat (limited to 'News-Android-App/src/main/java')
3 files changed, 28 insertions, 22 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 3cccfc91..10f5ad70 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 @@ -912,7 +912,8 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements } if (requestCode == RESULT_LOGIN) { - Intent intent = getIntent().putExtra(PREF_SERVER_SETTINGS, true); + Intent intent = new Intent(); + intent.putExtra(PREF_SERVER_SETTINGS, true); setResult(RESULT_OK, intent); } @@ -981,12 +982,16 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements } private void ensureCorrectTheme(Intent data) { - String oldListLayout = data.getStringExtra(SettingsActivity.AI_FEED_LIST_LAYOUT); - String newListLayout = mPrefs.getString(SettingsActivity.SP_FEED_LIST_LAYOUT, "0"); + String oldListLayout = data.getStringExtra(SettingsActivity.RI_FEED_LIST_LAYOUT); + String newListLayout = mPrefs.getString(SettingsActivity.SP_FEED_LIST_LAYOUT, "0"); + boolean themeChanged = !newListLayout.equals(oldListLayout); + boolean cacheWasCleared = data.hasExtra(SettingsActivity.RI_CACHE_CLEARED); - if (ThemeChooser.themeRequiresRestartOfUI() || !newListLayout.equals(oldListLayout)) { + Log.d(TAG, "themeChanged: " + themeChanged + " cacheWasCleared: " + cacheWasCleared); + + if (ThemeChooser.themeRequiresRestartOfUI() || themeChanged) { NewsReaderListActivity.this.recreate(); - } else if (data.hasExtra(SettingsActivity.CACHE_CLEARED)) { + } else if (cacheWasCleared) { resetUiAndStartSync(); } } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SettingsActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SettingsActivity.java index 46e90198..27d2e8d1 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SettingsActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SettingsActivity.java @@ -83,10 +83,10 @@ public class SettingsActivity extends AppCompatActivity { public static final String CB_OLED_MODE = "cb_oled_mode"; public static final String SP_FEED_LIST_LAYOUT = "sp_feed_list_layout"; // used for shared prefs - public static final String AI_FEED_LIST_LAYOUT = "ai_feed_list_layout"; // used for intents + public static final String RI_FEED_LIST_LAYOUT = "ai_feed_list_layout"; // used for result intents public static final String SP_FONT_SIZE = "sp_font_size"; - public static final String CACHE_CLEARED = "CACHE_CLEARED"; + public static final String RI_CACHE_CLEARED = "CACHE_CLEARED"; // used for result intents public static final String SP_MAX_CACHE_SIZE = "sp_max_cache_size"; public static final String SP_SORT_ORDER = "sp_sort_order"; public static final String SP_DISPLAY_BROWSER = "sp_display_browser"; @@ -101,6 +101,8 @@ public class SettingsActivity extends AppCompatActivity { protected @Inject SharedPreferences mPrefs; + public Intent resultIntent = new Intent(); + @Override protected void onCreate(Bundle savedInstanceState) { ((NewsReaderApplication) getApplication()).getAppComponent().injectActivity(this); @@ -112,6 +114,10 @@ public class SettingsActivity extends AppCompatActivity { setContentView(R.layout.activity_settings); setupActionBar(); + + // some settings might add a few flags to the result Intent at runtime + // (e.g. clearing cache / switching list layout / theme / ...) + setResult(RESULT_OK, resultIntent); } @Override @@ -124,7 +130,6 @@ public class SettingsActivity extends AppCompatActivity { .commit(); } - private void setupActionBar() { Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); @@ -133,13 +138,11 @@ public class SettingsActivity extends AppCompatActivity { getSupportActionBar().setTitle(R.string.title_activity_settings); } - @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - finish(); - return true; + if (item.getItemId() == android.R.id.home) { + finish(); + return true; } return super.onOptionsItemSelected(item); } @@ -149,9 +152,7 @@ public class SettingsActivity extends AppCompatActivity { super.onStart(); // Fix GHSL-2021-1033 - Intent intent = new Intent(); String feedListLayout = mPrefs.getString(SettingsActivity.SP_FEED_LIST_LAYOUT, "0"); - intent.putExtra(SettingsActivity.AI_FEED_LIST_LAYOUT, feedListLayout); - setResult(RESULT_OK, intent); + resultIntent.putExtra(SettingsActivity.RI_FEED_LIST_LAYOUT, feedListLayout); } } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SettingsFragment.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SettingsFragment.java index e075a0ff..e76eb16c 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SettingsFragment.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SettingsFragment.java @@ -450,15 +450,15 @@ public class SettingsFragment extends PreferenceFragmentCompat { @Override protected void onPostExecute(Void result) { - if(context instanceof Activity) { - Intent intent = ((Activity) context).getIntent(); - intent.putExtra(SettingsActivity.CACHE_CLEARED, true); - ((Activity) context).setResult(RESULT_OK, intent); - } + super.onPostExecute(result); pd.dismiss(); Toast.makeText(context, context.getString(R.string.cache_is_cleared), Toast.LENGTH_SHORT).show(); - super.onPostExecute(result); + + if(context instanceof SettingsActivity) { + SettingsActivity sa = (SettingsActivity) context; + sa.resultIntent.putExtra(SettingsActivity.RI_CACHE_CLEARED, true); + } } } } |