Skip to content

Commit

Permalink
- MasterViewViewModel [ISSUE TO FIX] GetScreenSize() / screen size st…
Browse files Browse the repository at this point in the history
…atic Width & Hight in Android Platform.
  • Loading branch information
Kremed committed Feb 20, 2023
1 parent 1542464 commit c9184df
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 37 deletions.
47 changes: 30 additions & 17 deletions Maukito/ViewModels/MasterViewViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@


namespace Maukito.ViewModels;
namespace Maukito.ViewModels;

public partial class MasterViewViewModel : BaseViewModel
{
Expand All @@ -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]
Expand Down
25 changes: 11 additions & 14 deletions Maukito/Views/MasterViewPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
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"
Shell.NavBarIsVisible="False">

<!--
Notes For You :
1- install NeuGet : CommunityToolkit.Maui.MediaElement
1- install NuGet : CommunityToolkit.Maui.MediaElement
2- Add this line to MauiProgram.cs : .UseMauiCommunityToolkitMediaElement()
3- add This Line To The Page : xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
3- Add This Line To The Page : xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
4- Go To ViewModels and take a look into MasterViewViewModel
5- Add Your Video File into : Resources/Raw
-->


<Page.Behaviors>
<mct:StatusBarBehavior StatusBarColor="Transparent" StatusBarStyle="{AppThemeBinding Dark='LightContent', Light='LightContent'}" />
</Page.Behaviors>
<Grid
Padding="20"
HorizontalOptions="FillAndExpand"
Expand Down Expand Up @@ -72,7 +76,7 @@


<Entry
Margin="0,0,5,0"
Margin="10,0,10,0"
BackgroundColor="White"
FontFamily="Medium"
FontSize="12"
Expand Down Expand Up @@ -153,9 +157,6 @@
RowSpacing="0"
VerticalOptions="CenterAndExpand">




<Border
Grid.Row="1"
Grid.Column="0"
Expand All @@ -171,7 +172,7 @@


<Entry
Margin="0,0,0,0"
Margin="10,0,10,0"
BackgroundColor="White"
FontFamily="Medium"
FontSize="12"
Expand Down Expand Up @@ -200,7 +201,7 @@


<Entry
Margin="0,0,5,0"
Margin="10,0,10,0"
BackgroundColor="White"
FontFamily="Medium"
FontSize="12"
Expand All @@ -215,8 +216,6 @@

</Border>



<Border
Grid.Row="3"
Grid.Column="0"
Expand All @@ -232,7 +231,7 @@


<Entry
Margin="0,0,5,0"
Margin="10,0,10,0"
BackgroundColor="White"
FontFamily="Medium"
FontSize="12"
Expand All @@ -247,8 +246,6 @@

</Border>



<Button
Grid.Row="4"
Grid.Column="0"
Expand Down
19 changes: 13 additions & 6 deletions Maukito/Views/MasterViewPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
namespace Maukito.Views;

namespace Maukito.Views;

public partial class MasterViewPage : ContentPage
{
public MasterViewPage(MasterViewViewModel viewModel)
{
InitializeComponent();
BindingContext = viewModel;
}
public MasterViewPage(MasterViewViewModel viewModel)
{
InitializeComponent();

BindingContext = viewModel;
}

protected override void LayoutChildren(double x, double y, double width, double height)
{
base.LayoutChildren(x, y, width, height);
}
}

0 comments on commit c9184df

Please sign in to comment.