diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2020-05-06 17:18:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-06 17:18:47 +0200 |
commit | 0a8e1ac48407ad436e6297a5caba66f9f8321a12 (patch) | |
tree | 73ebcf05a7a322a3eb34aea35834ea4ed2f28acf | |
parent | 626c6aebe5d3817a7bef2a26f875241c2f1f8541 (diff) | |
parent | 30381ca09a886f203fa716d698dfe2c323c21ac9 (diff) | |
download | AntennaPod-0a8e1ac48407ad436e6297a5caba66f9f8321a12.zip |
Merge pull request #4125 from ByteHamster/theme-switch-without-restart
Switch theme without user obstruction
3 files changed, 16 insertions, 12 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index a452113d4..9e647bcaa 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -74,6 +74,7 @@ public class MainActivity extends CastEnabledActivity { private LockableBottomSheetBehavior sheetBehavior; private long lastBackButtonPressTime = 0; private RecyclerView.RecycledViewPool recycledViewPool = new RecyclerView.RecycledViewPool(); + private int lastTheme = 0; @NonNull public static Intent getIntentToOpenFeed(@NonNull Context context, long feedId) { @@ -85,7 +86,8 @@ public class MainActivity extends CastEnabledActivity { @Override public void onCreate(Bundle savedInstanceState) { - setTheme(UserPreferences.getNoTitleTheme()); + lastTheme = UserPreferences.getNoTitleTheme(); + setTheme(lastTheme); super.onCreate(savedInstanceState); StorageUtils.checkStorageAvailability(this); setContentView(R.layout.main); @@ -313,11 +315,12 @@ public class MainActivity extends CastEnabledActivity { super.onStart(); EventBus.getDefault().register(this); RatingDialog.init(this); - } - @Override - protected void onPause() { - super.onPause(); + if (lastTheme != UserPreferences.getNoTitleTheme()) { + // Nav drawer is empty for half a second after recreating. Don't confuse users with that. + drawerLayout.closeDrawer(navDrawer); + recreate(); + } } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java index ea8774358..4f6010b75 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java @@ -28,6 +28,8 @@ import de.danoeh.antennapod.fragment.preferences.UserInterfacePreferencesFragmen * PreferenceController. */ public class PreferenceActivity extends AppCompatActivity implements SearchPreferenceResultListener { + private static final String FRAGMENT_TAG = "tag_preferences"; + @Override protected void onCreate(Bundle savedInstanceState) { setTheme(UserPreferences.getTheme()); @@ -44,8 +46,11 @@ public class PreferenceActivity extends AppCompatActivity implements SearchPrefe ViewGroup.LayoutParams.MATCH_PARENT)); setContentView(root); - getSupportFragmentManager().beginTransaction().replace(R.id.content, new MainPreferencesFragment()).commit(); - + if (getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG) == null) { + getSupportFragmentManager().beginTransaction() + .replace(R.id.content, new MainPreferencesFragment(), FRAGMENT_TAG) + .commit(); + } } private PreferenceFragmentCompat getPreferenceScreen(int screen) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/UserInterfacePreferencesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/UserInterfacePreferencesFragment.java index 0ea8d5b93..a44623f48 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/UserInterfacePreferencesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/UserInterfacePreferencesFragment.java @@ -35,11 +35,7 @@ public class UserInterfacePreferencesFragment extends PreferenceFragmentCompat { findPreference(UserPreferences.PREF_THEME) .setOnPreferenceChangeListener( (preference, newValue) -> { - Intent i = new Intent(getActivity(), MainActivity.class); - i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK - | Intent.FLAG_ACTIVITY_NEW_TASK); - getActivity().finish(); - startActivity(i); + getActivity().recreate(); return true; } ); |