improve behavior when changing the theme

This commit is contained in:
Philipp Crocoll
2024-12-31 13:04:37 +01:00
parent bf5411bdb8
commit f0d9c8134e
4 changed files with 20 additions and 15 deletions

View File

@@ -42,6 +42,7 @@ using keepass2android.search;
using keepass2android_appSdkStyle;
using KeeTrayTOTP.Libraries;
using AndroidX.AppCompat.Widget;
using Google.Android.Material.Dialog;
using SearchView = AndroidX.AppCompat.Widget.SearchView;
namespace keepass2android
@@ -273,7 +274,11 @@ namespace keepass2android
protected override void OnResume()
{
base.OnResume();
_design.ReapplyTheme();
if (IsFinishing)
{
//can happen e.g. after theme change
return;
}
AppTask.StartInGroupActivity(this);
AppTask.SetupGroupBaseActivityButtons(this);
@@ -300,7 +305,7 @@ namespace keepass2android
RunOnUiThread(() =>
{
var listView = FragmentManager?.FindFragmentById<GroupListFragment>(Resource.Id.list_fragment)
.ListView;
?.ListView;
if (listView != null)
{
int count = listView.Count;
@@ -510,7 +515,7 @@ namespace keepass2android
{
_design.ApplyTheme();
base.OnCreate(savedInstanceState);
Android.Util.Log.Debug("KP2A", "Creating GBA");
AppTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent);

View File

@@ -47,9 +47,6 @@ namespace keepass2android
public void ApplyTheme()
{
_currentThemeId = NightModePreference;
AppCompatDelegate.DefaultNightMode = _currentThemeId.Value;
_secureWindow = SecureWindowPref();
@@ -66,7 +63,8 @@ namespace keepass2android
if (newTheme != _currentThemeId)
{
Kp2aLog.Log("recreating due to theme change.");
_activity.Recreate();
_activity.Recreate();
_activity.Finish(); //withouth this, we'll have two GroupActivities on the backstack afterwards
return;
}
@@ -76,7 +74,7 @@ namespace keepass2android
{
Kp2aLog.Log("recreating due to icon set change.");
_activity.Recreate();
return;
return;
}
@@ -84,7 +82,7 @@ namespace keepass2android
{
Kp2aLog.Log("recreating due to secure window change.");
_activity.Recreate();
return;
return;
}
}

View File

@@ -535,7 +535,12 @@ namespace keepass2android
var displayPrefScreen = ((PreferenceScreen)FindPreference(GetString(Resource.String.display_prefs_key)));
PrepareNoDonationReminderPreference(Activity, displayPrefScreen, FindPreference(GetString(Resource.String.NoDonationReminder_key)));
FindPreference(GetString(Resource.String.design_key)).PreferenceChange += (sender, args) => Activity.Recreate();
FindPreference(GetString(Resource.String.design_key)).PreferenceChange += (sender, args) =>
{
//it would be nicer to recreate, but that - for some reason - causes GroupActivity to be twice on the backstack afterwards :-(
//So better finish here.
Activity.Finish();
};
displayPrefScreen.RemovePreference(unlockedNotificationPref);
@@ -1192,6 +1197,8 @@ namespace keepass2android
{
private ActivityDesign _design;
public static bool BeingRecreated = false;
public AppSettingsActivity()
{
_design = new ActivityDesign(this);

View File

@@ -159,11 +159,6 @@ namespace keepass2android
settingsFragmentManager = new SettingsFragmentManager(this);
}
public static void Launch(Context ctx)
{
ctx.StartActivity(new Intent(ctx, typeof(AppSettingsActivity)));
}
protected override void OnCreate(Bundle savedInstanceState)
{
_design.ApplyTheme();