From a48123444473895140451d1f83270e28db9cc1e3 Mon Sep 17 00:00:00 2001 From: Liam Morrow Date: Tue, 17 Dec 2024 20:11:51 +1100 Subject: [PATCH] Fix: Status bar overlap In android, there has been an issue where the status bar did not always reserve space for itself. It was found that this is a localisation issue, and we were creating invalid CSS as decimals were being split by commas. Fixes: #156 --- .../Platforms/Android/MainActivity.cs | 37 +++++++++++++------ LiftLog.Ui/Pages/Settings/AppConfigPage.razor | 9 ----- .../Repository/PreferencesRepository.cs | 10 ----- LiftLog.Ui/Shared/MainLayout.razor | 2 +- LiftLog.Ui/Shared/Smart/NavBar.razor | 2 +- LiftLog.Ui/Store/Settings/SettingsActions.cs | 2 - LiftLog.Ui/Store/Settings/SettingsEffects.cs | 6 --- LiftLog.Ui/Store/Settings/SettingsReducers.cs | 6 --- LiftLog.Ui/Store/Settings/SettingsState.cs | 2 - .../Settings/SettingsStateInitMiddleware.cs | 3 -- LiftLog.Ui/i18n/UiStrings.it-IT.resx | 6 --- LiftLog.Ui/i18n/UiStrings.resx | 6 --- 12 files changed, 28 insertions(+), 63 deletions(-) diff --git a/LiftLog.Maui/Platforms/Android/MainActivity.cs b/LiftLog.Maui/Platforms/Android/MainActivity.cs index 54b42880..913f8912 100644 --- a/LiftLog.Maui/Platforms/Android/MainActivity.cs +++ b/LiftLog.Maui/Platforms/Android/MainActivity.cs @@ -1,4 +1,5 @@ -using Android; +using System.Globalization; +using Android; using Android.App; using Android.Content.PM; using Android.Content.Res; @@ -48,10 +49,14 @@ protected override void OnCreate(Bundle? savedInstanceState) IPlatformApplication.Current?.Services.GetRequiredService(); if (insetsManager is not null) { - insetsManager.SystemSafeInsetBottom = - $"{WebViewSoftInputPatch.GetNavBarHeight() / Resources!.DisplayMetrics!.Density}px"; - insetsManager.SystemSafeInsetTop = - $"{WebViewSoftInputPatch.GetStatusBarHeight() / Resources.DisplayMetrics.Density}px"; + insetsManager.SystemSafeInsetBottom = string.Create( + CultureInfo.InvariantCulture, + $"{WebViewSoftInputPatch.GetNavBarHeight() / Resources!.DisplayMetrics!.Density}px" + ); + insetsManager.SystemSafeInsetTop = string.Create( + CultureInfo.InvariantCulture, + $"{WebViewSoftInputPatch.GetStatusBarHeight() / Resources.DisplayMetrics.Density}px" + ); ViewCompat.SetOnApplyWindowInsetsListener( Window!.DecorView, new WindowInsetsListener(insetsManager!, Resources.DisplayMetrics.Density) @@ -86,15 +91,25 @@ WindowInsetsCompat insets } if (top == 0 || bottom == 0) { - insetsManager.SystemSafeInsetBottom = - $"{WebViewSoftInputPatch.GetNavBarHeight() / density}px"; - insetsManager.SystemSafeInsetTop = - $"{WebViewSoftInputPatch.GetStatusBarHeight() / density}px"; + insetsManager.SystemSafeInsetBottom = string.Create( + CultureInfo.InvariantCulture, + $"{WebViewSoftInputPatch.GetNavBarHeight() / density}px" + ); + insetsManager.SystemSafeInsetTop = string.Create( + CultureInfo.InvariantCulture, + $"{WebViewSoftInputPatch.GetStatusBarHeight() / density}px" + ); insetsManager.NotifyInsetsChanged(); return insets; } - insetsManager.SystemSafeInsetTop = $"{top}px"; - insetsManager.SystemSafeInsetBottom = $"{bottom}px"; + insetsManager.SystemSafeInsetTop = string.Create( + CultureInfo.InvariantCulture, + $"{top}px" + ); + insetsManager.SystemSafeInsetBottom = string.Create( + CultureInfo.InvariantCulture, + $"{bottom}px" + ); insetsManager.NotifyInsetsChanged(); return insets; } diff --git a/LiftLog.Ui/Pages/Settings/AppConfigPage.razor b/LiftLog.Ui/Pages/Settings/AppConfigPage.razor index 01f23fa2..624076fb 100644 --- a/LiftLog.Ui/Pages/Settings/AppConfigPage.razor +++ b/LiftLog.Ui/Pages/Settings/AppConfigPage.razor @@ -2,7 +2,6 @@ @inject IState SettingsState @inject IDispatcher Dispatcher @inject IThemeProvider ThemeProvider -@inject IDeviceService DeviceService @inherits Fluxor.Blazor.Web.Components.FluxorComponent @@ -10,11 +9,6 @@ - @* If android, we need a status bar fix sometimes *@ - @if(DeviceService.GetDeviceType() == DeviceType.Android) - { - - } @UiStrings.ResetTips @@ -48,9 +42,6 @@ private void SetShowTips(bool value) => Dispatcher.Dispatch(new SetShowTipsAction(value)); - private void SetStatusBarFix(bool value) - => Dispatcher.Dispatch(new SetStatusBarFixAction(value)); - private void ResetTips() => Dispatcher.Dispatch(new SetTipToShowAction(1)); diff --git a/LiftLog.Ui/Repository/PreferencesRepository.cs b/LiftLog.Ui/Repository/PreferencesRepository.cs index 09d25a5a..8b8e03a6 100644 --- a/LiftLog.Ui/Repository/PreferencesRepository.cs +++ b/LiftLog.Ui/Repository/PreferencesRepository.cs @@ -90,16 +90,6 @@ public async Task GetShowFeedAsync() return await preferenceStore.GetItemAsync("showFeed") is "True" or null; } - public async Task SetStatusBarFixAsync(bool statusBarFix) - { - await preferenceStore.SetItemAsync("statusBarFix", statusBarFix.ToString()); - } - - public async Task GetStatusBarFixAsync() - { - return await preferenceStore.GetItemAsync("statusBarFix") is "True"; - } - public async Task GetHasRequestedNotificationPermissionAsync() { return await preferenceStore.GetItemAsync("hasRequestedNotificationPermission") is "True"; diff --git a/LiftLog.Ui/Shared/MainLayout.razor b/LiftLog.Ui/Shared/MainLayout.razor index d2201d28..75deac13 100644 --- a/LiftLog.Ui/Shared/MainLayout.razor +++ b/LiftLog.Ui/Shared/MainLayout.razor @@ -129,7 +129,7 @@ private string Justify => AppState.Value.BackNavigationUrl is null ? "justify-center" : "justify-start"; - private string TopInset => SettingsState.Value.StatusBarFix ? "46px" : InsetsManager.SystemSafeInsetTop; + private string TopInset => InsetsManager.SystemSafeInsetTop; private RenderFragment? RenderBackButton() { diff --git a/LiftLog.Ui/Shared/Smart/NavBar.razor b/LiftLog.Ui/Shared/Smart/NavBar.razor index 656f8575..66f22ae7 100644 --- a/LiftLog.Ui/Shared/Smart/NavBar.razor +++ b/LiftLog.Ui/Shared/Smart/NavBar.razor @@ -27,7 +27,7 @@ @code { - private string BottomInset => SettingsState.Value.StatusBarFix ? "32px" : InsetsManager.SystemSafeInsetBottom; + private string BottomInset => InsetsManager.SystemSafeInsetBottom; protected override void OnInitialized() { diff --git a/LiftLog.Ui/Store/Settings/SettingsActions.cs b/LiftLog.Ui/Store/Settings/SettingsActions.cs index 89e5910b..d8253882 100644 --- a/LiftLog.Ui/Store/Settings/SettingsActions.cs +++ b/LiftLog.Ui/Store/Settings/SettingsActions.cs @@ -40,8 +40,6 @@ public record SetTipToShowAction(int TipToShow); public record SetShowFeedAction(bool ShowFeed); -public record SetStatusBarFixAction(bool StatusBarFix); - public record ExecuteRemoteBackupAction(RemoteBackupSettings Settings, bool Force = false); public record RemoteBackupSucceededEvent(); diff --git a/LiftLog.Ui/Store/Settings/SettingsEffects.cs b/LiftLog.Ui/Store/Settings/SettingsEffects.cs index 87bc8ac0..6ddceecd 100644 --- a/LiftLog.Ui/Store/Settings/SettingsEffects.cs +++ b/LiftLog.Ui/Store/Settings/SettingsEffects.cs @@ -220,12 +220,6 @@ IDispatcher _ await preferencesRepository.SetLastSuccessfulRemoteBackupHashAsync(action.Hash); } - [EffectMethod] - public async Task HandleStatusBarFixAction(SetStatusBarFixAction action, IDispatcher dispatcher) - { - await preferencesRepository.SetStatusBarFixAsync(action.StatusBarFix); - } - [EffectMethod] public async Task ExecuteRemoteBackup(ExecuteRemoteBackupAction action, IDispatcher dispatcher) { diff --git a/LiftLog.Ui/Store/Settings/SettingsReducers.cs b/LiftLog.Ui/Store/Settings/SettingsReducers.cs index 00b52119..3273d7df 100644 --- a/LiftLog.Ui/Store/Settings/SettingsReducers.cs +++ b/LiftLog.Ui/Store/Settings/SettingsReducers.cs @@ -65,12 +65,6 @@ state with ShowFeed = action.ShowFeed, }; - [ReducerMethod] - public static SettingsState SetStatusBarFix( - SettingsState state, - SetStatusBarFixAction action - ) => state with { StatusBarFix = action.StatusBarFix }; - [ReducerMethod] public static SettingsState SetRestNotifications( SettingsState state, diff --git a/LiftLog.Ui/Store/Settings/SettingsState.cs b/LiftLog.Ui/Store/Settings/SettingsState.cs index 1b817d7e..75190600 100644 --- a/LiftLog.Ui/Store/Settings/SettingsState.cs +++ b/LiftLog.Ui/Store/Settings/SettingsState.cs @@ -14,7 +14,6 @@ public record SettingsState( bool ShowTips, int TipToShow, bool ShowFeed, - bool StatusBarFix, bool RestNotifications, RemoteBackupSettings RemoteBackupSettings, string LastSuccessfulRemoteBackupHash, @@ -34,7 +33,6 @@ bool BackupReminder ShowTips: true, TipToShow: 1, ShowFeed: true, - StatusBarFix: false, RestNotifications: true, RemoteBackupSettings: new RemoteBackupSettings(string.Empty, string.Empty, false), LastSuccessfulRemoteBackupHash: string.Empty, diff --git a/LiftLog.Ui/Store/Settings/SettingsStateInitMiddleware.cs b/LiftLog.Ui/Store/Settings/SettingsStateInitMiddleware.cs index 998b3042..3f7a4b3c 100644 --- a/LiftLog.Ui/Store/Settings/SettingsStateInitMiddleware.cs +++ b/LiftLog.Ui/Store/Settings/SettingsStateInitMiddleware.cs @@ -20,7 +20,6 @@ public override async Task InitializeAsync(IDispatcher dispatch, IStore store) showTips, tipToShow, showFeed, - statusBarFix, restNotifications, remoteBackupSettings, lastSuccessfulRemoteBackupHash, @@ -32,7 +31,6 @@ public override async Task InitializeAsync(IDispatcher dispatch, IStore store) preferencesRepository.GetShowTipsAsync(), preferencesRepository.GetTipToShowAsync(), preferencesRepository.GetShowFeedAsync(), - preferencesRepository.GetStatusBarFixAsync(), preferencesRepository.GetRestNotificationsAsync(), preferencesRepository.GetRemoteBackupSettingsAsync(), preferencesRepository.GetLastSuccessfulRemoteBackupHashAsync(), @@ -48,7 +46,6 @@ public override async Task InitializeAsync(IDispatcher dispatch, IStore store) ShowTips = showTips, TipToShow = tipToShow, ShowFeed = showFeed, - StatusBarFix = statusBarFix, RestNotifications = restNotifications, RemoteBackupSettings = remoteBackupSettings, LastSuccessfulRemoteBackupHash = lastSuccessfulRemoteBackupHash, diff --git a/LiftLog.Ui/i18n/UiStrings.it-IT.resx b/LiftLog.Ui/i18n/UiStrings.it-IT.resx index f6eba1ef..b741e127 100644 --- a/LiftLog.Ui/i18n/UiStrings.it-IT.resx +++ b/LiftLog.Ui/i18n/UiStrings.it-IT.resx @@ -448,12 +448,6 @@ Mostra il feed nella barra di navigazione - - Fix barra di stato - - - Risolve il problema della sovrapposizione della barra di stato sui controlli in alcuni dispositivi. - Mostra suggerimenti diff --git a/LiftLog.Ui/i18n/UiStrings.resx b/LiftLog.Ui/i18n/UiStrings.resx index aa7f19d1..79d8af2d 100644 --- a/LiftLog.Ui/i18n/UiStrings.resx +++ b/LiftLog.Ui/i18n/UiStrings.resx @@ -500,12 +500,6 @@ Display the feed in the navigation bar - - Status bar fix - - - Fixes the status bar overlapping the page title controls on some devices - Show tips