From c9184df1a9c21a0890742a0e93f6a3d948e6a27e Mon Sep 17 00:00:00 2001 From: Moatasem La Kremed Date: Mon, 20 Feb 2023 03:46:13 +0200 Subject: [PATCH] - MasterViewViewModel [ISSUE TO FIX] GetScreenSize() / screen size static Width & Hight in Android Platform. --- Maukito/ViewModels/MasterViewViewModel.cs | 47 +++++++++++++++-------- Maukito/Views/MasterViewPage.xaml | 25 ++++++------ Maukito/Views/MasterViewPage.xaml.cs | 19 ++++++--- 3 files changed, 54 insertions(+), 37 deletions(-) diff --git a/Maukito/ViewModels/MasterViewViewModel.cs b/Maukito/ViewModels/MasterViewViewModel.cs index 3cd5855..508941e 100644 --- a/Maukito/ViewModels/MasterViewViewModel.cs +++ b/Maukito/ViewModels/MasterViewViewModel.cs @@ -1,6 +1,4 @@ - - -namespace Maukito.ViewModels; +namespace Maukito.ViewModels; public partial class MasterViewViewModel : BaseViewModel { @@ -23,28 +21,43 @@ public MasterViewViewModel() { try { - DisplayHeight = Application.Current.MainPage.Height; + GetScreenSize(); + } + catch (Exception ex) + { + var msg = Snackbar.Make($"{ex.Message} - {ex.InnerException}", null, "X", TimeSpan.FromSeconds(10), BaseSnackbarOptions).Show(); + } + } + + [RelayCommand] + public void GetScreenSize() + { + DisplayHeight = Application.Current.MainPage.Height; - VidMargin = VidMargin - DisplayHeight; + VidMargin = VidMargin - DisplayHeight; - var ScreenHight = Application.Current.MainPage.Height; + var ScreenHight = Application.Current.MainPage.Height; - var HightToAdd = Application.Current.MainPage.Height / 5; + var HightToAdd = Application.Current.MainPage.Height / 5; - var ScreenWidth = Application.Current.MainPage.Width; + var ScreenWidth = Application.Current.MainPage.Width; - var WidthToAdd = Application.Current.MainPage.Width / 5; + var WidthToAdd = Application.Current.MainPage.Width / 5; - //To Add About 20% for Zooming The Video Media element => + //To Add About 20% for Zooming The Video Media element => - VidHight = ScreenHight + HightToAdd; +#if ANDROID - VidWidth = ScreenWidth + HightToAdd; - } - catch (Exception ex) - { - var msg = Snackbar.Make($"{ex.Message} - {ex.InnerException}", null, "X", TimeSpan.FromSeconds(10), BaseSnackbarOptions).Show(); - } + //[ISSUE] TO Fix => For some reason, the Height and Width of the client's screen are not obtained in the + //Android application for the main page of the application. We always get a value of -1 for Width & Hight. + //This problem has been temporarily fixed by specifying a static Width & Hight in Android Platform. + + VidHight = 900; + VidWidth = 600; +#elif IOS + VidHight = ScreenHight + HightToAdd; + VidWidth = ScreenWidth + WidthToAdd; +#endif } [RelayCommand] diff --git a/Maukito/Views/MasterViewPage.xaml b/Maukito/Views/MasterViewPage.xaml index 74fade1..1e9138a 100644 --- a/Maukito/Views/MasterViewPage.xaml +++ b/Maukito/Views/MasterViewPage.xaml @@ -3,6 +3,7 @@ x:Class="Maukito.Views.MasterViewPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + xmlns:mct="clr-namespace:CommunityToolkit.Maui.Behaviors;assembly=CommunityToolkit.Maui" xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" xmlns:vm="clr-namespace:Maukito.ViewModels" x:DataType="vm:MasterViewViewModel" @@ -10,13 +11,16 @@ - + + + - - - - - - -