Skip to content

Commit

Permalink
🚀 [Code] Updated the functionalities to .NET 8 c5
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmonettelli committed Mar 14, 2024
1 parent 018c019 commit 04ab606
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 31 deletions.
9 changes: 4 additions & 5 deletions Mitawi/Constants/APIConstants.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
namespace Mitawi.Constants
namespace Mitawi.Constants;

public static class APIConstants
{
public static class APIConstants
{
public const string OpenWeatherMapEndpoint = "https://api.openweathermap.org/data/2.5/onecall";
public const string OpenWeatherMapEndpoint = "https://api.openweathermap.org/data/2.5/onecall";
public const string OpenWeatherMapAPIKey = "INSERT_API_KEY_HERE";
}
}
22 changes: 22 additions & 0 deletions Mitawi/Converters/InvertBooleanConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Mitawi.Converters;

public class InvertBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

Check warning on line 5 in Mitawi/Converters/InvertBooleanConverter.cs

View workflow job for this annotation

GitHub Actions / Build_MacCatalyst

Nullability of reference types in type of parameter 'value' of 'object InvertBooleanConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)' doesn't match implicitly implemented member 'object? IValueConverter.Convert(object? value, Type targetType, object? parameter, CultureInfo culture)' (possibly because of nullability attributes).

Check warning on line 5 in Mitawi/Converters/InvertBooleanConverter.cs

View workflow job for this annotation

GitHub Actions / Build_MacCatalyst

Nullability of reference types in type of parameter 'parameter' of 'object InvertBooleanConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)' doesn't match implicitly implemented member 'object? IValueConverter.Convert(object? value, Type targetType, object? parameter, CultureInfo culture)' (possibly because of nullability attributes).

Check warning on line 5 in Mitawi/Converters/InvertBooleanConverter.cs

View workflow job for this annotation

GitHub Actions / Build_Windows

Nullability of reference types in type of parameter 'value' of 'object InvertBooleanConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)' doesn't match implicitly implemented member 'object? IValueConverter.Convert(object? value, Type targetType, object? parameter, CultureInfo culture)' (possibly because of nullability attributes).

Check warning on line 5 in Mitawi/Converters/InvertBooleanConverter.cs

View workflow job for this annotation

GitHub Actions / Build_Windows

Nullability of reference types in type of parameter 'parameter' of 'object InvertBooleanConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)' doesn't match implicitly implemented member 'object? IValueConverter.Convert(object? value, Type targetType, object? parameter, CultureInfo culture)' (possibly because of nullability attributes).

Check warning on line 5 in Mitawi/Converters/InvertBooleanConverter.cs

View workflow job for this annotation

GitHub Actions / Build_Windows

Nullability of reference types in type of parameter 'value' of 'object InvertBooleanConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)' doesn't match implicitly implemented member 'object? IValueConverter.Convert(object? value, Type targetType, object? parameter, CultureInfo culture)' (possibly because of nullability attributes).

Check warning on line 5 in Mitawi/Converters/InvertBooleanConverter.cs

View workflow job for this annotation

GitHub Actions / Build_iOS

Nullability of reference types in type of parameter 'value' of 'object InvertBooleanConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)' doesn't match implicitly implemented member 'object? IValueConverter.Convert(object? value, Type targetType, object? parameter, CultureInfo culture)' (possibly because of nullability attributes).

Check warning on line 5 in Mitawi/Converters/InvertBooleanConverter.cs

View workflow job for this annotation

GitHub Actions / Build_iOS

Nullability of reference types in type of parameter 'parameter' of 'object InvertBooleanConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)' doesn't match implicitly implemented member 'object? IValueConverter.Convert(object? value, Type targetType, object? parameter, CultureInfo culture)' (possibly because of nullability attributes).
{
if (value is bool boolValue)
{
return !boolValue;
}
return value;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

Check warning on line 14 in Mitawi/Converters/InvertBooleanConverter.cs

View workflow job for this annotation

GitHub Actions / Build_MacCatalyst

Nullability of reference types in type of parameter 'value' of 'object InvertBooleanConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)' doesn't match implicitly implemented member 'object? IValueConverter.ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)' (possibly because of nullability attributes).

Check warning on line 14 in Mitawi/Converters/InvertBooleanConverter.cs

View workflow job for this annotation

GitHub Actions / Build_MacCatalyst

Nullability of reference types in type of parameter 'parameter' of 'object InvertBooleanConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)' doesn't match implicitly implemented member 'object? IValueConverter.ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)' (possibly because of nullability attributes).

Check warning on line 14 in Mitawi/Converters/InvertBooleanConverter.cs

View workflow job for this annotation

GitHub Actions / Build_Windows

Nullability of reference types in type of parameter 'value' of 'object InvertBooleanConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)' doesn't match implicitly implemented member 'object? IValueConverter.ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)' (possibly because of nullability attributes).

Check warning on line 14 in Mitawi/Converters/InvertBooleanConverter.cs

View workflow job for this annotation

GitHub Actions / Build_Windows

Nullability of reference types in type of parameter 'parameter' of 'object InvertBooleanConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)' doesn't match implicitly implemented member 'object? IValueConverter.ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)' (possibly because of nullability attributes).

Check warning on line 14 in Mitawi/Converters/InvertBooleanConverter.cs

View workflow job for this annotation

GitHub Actions / Build_iOS

Nullability of reference types in type of parameter 'value' of 'object InvertBooleanConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)' doesn't match implicitly implemented member 'object? IValueConverter.ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)' (possibly because of nullability attributes).

Check warning on line 14 in Mitawi/Converters/InvertBooleanConverter.cs

View workflow job for this annotation

GitHub Actions / Build_iOS

Nullability of reference types in type of parameter 'parameter' of 'object InvertBooleanConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)' doesn't match implicitly implemented member 'object? IValueConverter.ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)' (possibly because of nullability attributes).
{
if (value is bool boolValue)
{
return !boolValue;
}
return value;
}
}
1 change: 1 addition & 0 deletions Mitawi/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private static void RegisterServices(IServiceCollection services)

//Register Views
services.AddSingleton<WelcomePage>();

services.AddSingleton<HomePageOrientation>();
services.AddSingleton<HomePage>();

Expand Down
2 changes: 1 addition & 1 deletion Mitawi/Models/WeatherData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Weather

public class Hourly
{
public bool IsBusy { get; set; }
public bool IsAnimationSkeleton { get; set; }

[JsonPropertyName("dt")]
public long Dt { get; set; }
Expand Down
3 changes: 1 addition & 2 deletions Mitawi/ViewModels/Base/BaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

public partial class BaseViewModel : ObservableObject
{
[ObservableProperty]
private bool isBusy = false;

}
18 changes: 12 additions & 6 deletions Mitawi/ViewModels/HomeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ public partial class HomeViewModel : BaseViewModel
{
private readonly IWeatherDataService _weatherDataService;

[ObservableProperty]
private bool isAnimationSkeleton;

[ObservableProperty]
private bool isLoading;

[ObservableProperty]
private List<Hourly> hourlies;

Expand All @@ -24,21 +30,21 @@ public HomeViewModel(IWeatherDataService weatherDataService)
}

[RelayCommand]
private void FullUpdate()
private async Task FullUpdate()
{
WeatherDataFlow();
await WeatherDataFlow();
}

[RelayCommand]
private void SelectedHourly(Hourly hourly)
{
if (hourly is not null)
{
IsBusy = true;
IsAnimationSkeleton = true;

Task.Delay(1000).ContinueWith((t) =>
{
IsBusy = false;
IsAnimationSkeleton = false;
});

MyHourly = hourly;
Expand All @@ -61,7 +67,7 @@ await Shell.Current.GoToAsync(

private async Task WeatherDataFlow()
{
IsBusy = true;
IsLoading = true;

var placemarkTask = _weatherDataService.GetPlacemarkAsync();
var daysTask = _weatherDataService.GetDaysAsync();
Expand All @@ -76,7 +82,7 @@ private async Task WeatherDataFlow()
// Get current time schedule
MyHourly = Hourlies.ElementAt(0);

IsBusy = false;
IsLoading = false;
}

}
71 changes: 57 additions & 14 deletions Mitawi/Views/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
x:Class="Mitawi.Views.HomePage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:converter="clr-namespace:Mitawi.Converters"
xmlns:ffImageLoading="clr-namespace:FFImageLoading.Maui;assembly=FFImageLoading.Compat.Maui"
xmlns:heyview="clr-namespace:Mitawi.Views"
xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:models="clr-namespace:Mitawi.Models"
Expand All @@ -17,6 +19,8 @@

<ContentPage.Resources>
<ResourceDictionary Source="Orientations/HomePageOrientation.xaml" />

<converter:InvertBooleanConverter x:Key="InvertBooleanConverter" />
</ContentPage.Resources>

<ContentPage.Content>
Expand All @@ -29,7 +33,7 @@
<Border
x:Name="topLayerLower1"
sk:Skeleton.Hide="True"
sk:Skeleton.IsBusy="{Binding IsBusy}"
sk:Skeleton.IsBusy="{Binding IsAnimationSkeleton}"
BackgroundColor="{StaticResource col_thirt}"
StrokeThickness="0"
Style="{StaticResource vsm_orientation_topLayerLower1}">
Expand All @@ -52,7 +56,7 @@
sk:Skeleton.Animation="{sk:DefaultAnimation Source=Fade,
Interval='600',
Parameter='0.3'}"
sk:Skeleton.IsBusy="{Binding IsBusy}"
sk:Skeleton.IsBusy="{Binding IsAnimationSkeleton}"
Stroke="{StaticResource col_twel}"
StrokeThickness="3"
Style="{StaticResource vsm_orientation_topLayerHigher2}">
Expand All @@ -69,7 +73,7 @@
<Grid
x:Name="gridAdminTopLayerHigher2"
Padding="16,0"
sk:Skeleton.IsBusy="{Binding IsBusy}"
sk:Skeleton.IsBusy="{Binding IsAnimationSkeleton}"
sk:Skeleton.IsParent="True"
Style="{StaticResource vsm_orientation_gridAdminTopLayerHigher2}">

Expand Down Expand Up @@ -179,15 +183,15 @@
Grid.Row="3"
Grid.Column="1"
sk:Skeleton.Hide="True"
sk:Skeleton.IsBusy="{Binding IsBusy}"
sk:Skeleton.IsBusy="{Binding IsAnimationSkeleton}"
Source="{Binding MyHourly.Weather[0].Icon, Converter={StaticResource CustomImageUrlScalingConverter}, ConverterParameter=10}" />
<!--#endregion-->

<!--#region Basic description of the climate-->
<StackLayout
x:Name="lookTemperature"
sk:Skeleton.Hide="True"
sk:Skeleton.IsBusy="{Binding IsBusy}"
sk:Skeleton.IsBusy="{Binding IsAnimationSkeleton}"
Style="{StaticResource vsm_orientation_lookTemperature}"
VerticalOptions="CenterAndExpand">
<Label
Expand All @@ -201,7 +205,7 @@
<StackLayout
x:Name="lookWeatherAndDt"
sk:Skeleton.Hide="True"
sk:Skeleton.IsBusy="{Binding IsBusy}"
sk:Skeleton.IsBusy="{Binding IsAnimationSkeleton}"
Style="{StaticResource vsm_orientation_lookWeatherAndDt}">

<Label
Expand Down Expand Up @@ -244,7 +248,7 @@

<Label
Margin="0,8,0,0"
sk:Skeleton.IsBusy="{Binding IsBusy}"
sk:Skeleton.IsBusy="{Binding IsAnimationSkeleton}"
HorizontalTextAlignment="Center"
Style="{OnIdiom Phone={StaticResource TxtSubtitle2_2},
Tablet={StaticResource TxtHeadline6_2}}"
Expand All @@ -267,7 +271,7 @@

<Label
Margin="0,8,0,0"
sk:Skeleton.IsBusy="{Binding IsBusy}"
sk:Skeleton.IsBusy="{Binding IsAnimationSkeleton}"
HorizontalTextAlignment="Center"
Style="{OnIdiom Phone={StaticResource TxtSubtitle2_2},
Tablet={StaticResource TxtHeadline6_2}}"
Expand All @@ -290,7 +294,7 @@

<Label
Margin="0,8,0,0"
sk:Skeleton.IsBusy="{Binding IsBusy}"
sk:Skeleton.IsBusy="{Binding IsAnimationSkeleton}"
HorizontalTextAlignment="Center"
Style="{OnIdiom Phone={StaticResource TxtSubtitle2_2},
Tablet={StaticResource TxtHeadline6_2}}"
Expand Down Expand Up @@ -324,6 +328,7 @@
<StackLayout
Padding="16,0"
HorizontalOptions="EndAndExpand"
IsEnabled="{Binding IsLoading, Converter={StaticResource InvertBooleanConverter}}"
Orientation="Horizontal"
Spacing="6">
<StackLayout.GestureRecognizers>
Expand Down Expand Up @@ -354,9 +359,10 @@

<mct:UniformItemsLayout
x:Name="uniformItemsLayoutForecast24Hours"
sk:Skeleton.IsBusy="{Binding IsBusy}"
sk:Skeleton.IsBusy="{Binding IsAnimationSkeleton}"
sk:Skeleton.IsParent="True"
BindableLayout.ItemsSource="{Binding Hourlies}"
IsEnabled="{Binding IsLoading, Converter={StaticResource InvertBooleanConverter}}"
Style="{StaticResource vsm_orientation_uniformForecast24Hours}">
<BindableLayout.ItemTemplate>
<DataTemplate x:DataType="models:Hourly">
Expand All @@ -368,7 +374,7 @@
Interval='600',
Parameter='0.3'}"
sk:Skeleton.BackgroundColor="{StaticResource col_sec}"
sk:Skeleton.IsBusy="{Binding IsBusy}"
sk:Skeleton.IsBusy="{Binding IsAnimationSkeleton}"
Style="{StaticResource vsm_surfaceHourly}">
<Border.GestureRecognizers>
<TapGestureRecognizer
Expand All @@ -381,7 +387,7 @@
<!--#region Temperature in degrees celsius-->
<Label
x:Name="labelTemperature"
sk:Skeleton.IsBusy="{Binding IsBusy}"
sk:Skeleton.IsBusy="{Binding IsAnimationSkeleton}"
HorizontalTextAlignment="Center"
Style="{StaticResource vsm_labelTemperature}"
Text="{Binding Temp, StringFormat='{0}°', Converter={StaticResource DoubleToIntConverter}}" />
Expand All @@ -391,15 +397,15 @@
<ffImageLoading:CachedImage
x:Name="imageSmallWeather"
sk:Skeleton.Hide="True"
sk:Skeleton.IsBusy="{Binding IsBusy}"
sk:Skeleton.IsBusy="{Binding IsAnimationSkeleton}"
Source="{Binding Weather[0].Icon, Converter={StaticResource CustomImageUrlScalingConverter}, ConverterParameter=2}"
Style="{StaticResource vsm_imageSmallWeather}" />
<!--#endregion-->

<!--#region Time per hour-->
<Label
x:Name="labelHour"
sk:Skeleton.IsBusy="{Binding IsBusy}"
sk:Skeleton.IsBusy="{Binding IsAnimationSkeleton}"
HorizontalTextAlignment="Center"
Style="{StaticResource vsm_labelHour}"
Text="{Binding Dt, Converter={StaticResource UnixTimeToDateTimeConverter}, ConverterParameter=HH:mm}"
Expand All @@ -412,6 +418,43 @@
</mct:UniformItemsLayout>
</ScrollView>
<!--#endregion-->

<BoxView
Grid.Row="0"
Grid.RowSpan="5"
Margin="-16,0,-16,-8"
IsEnabled="{Binding IsLoading}"
IsVisible="{Binding IsLoading}">
<BoxView.Background>
<LinearGradientBrush EndPoint="0,1">
<GradientStop Offset="0" Color="{StaticResource col_prim}" />
<GradientStop Offset="0.5" Color="{StaticResource col_sec}" />
</LinearGradientBrush>
</BoxView.Background>
</BoxView>

<VerticalStackLayout
Grid.Row="0"
Grid.RowSpan="5"
Margin="-16,0,-16,-8"
HorizontalOptions="Center"
IsEnabled="{Binding IsLoading}"
IsVisible="{Binding IsLoading}"
Spacing="10"
VerticalOptions="Center">

<ActivityIndicator
HeightRequest="50"
IsRunning="{Binding IsLoading}"
WidthRequest="50"
Color="White" />

<Label
HorizontalTextAlignment="Center"
Style="{StaticResource TxtSubtitle1_1}"
Text="Loading"
TextColor="White" />
</VerticalStackLayout>
</Grid>
<!--#endregion-->
</ContentPage.Content>
Expand Down
8 changes: 6 additions & 2 deletions Mitawi/Views/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public HomePage()
BindingContext = vm;
}

protected override bool OnBackButtonPressed()
{
return true;
}

private void HomePage_Orientation(object sender, EventArgs e)
{
string visualStateOrientation = Height > Width ? "Portrait" : "Landscape";
Expand All @@ -33,7 +38,7 @@ private void HomePage_Orientation(object sender, EventArgs e)
VisualStateManager.GoToState(uniformItemsLayoutForecast24Hours, visualStateOrientation);
}

private void SelectedWeather_Tapped(object sender, EventArgs e)
private void SelectedWeather_Tapped(object sender, TappedEventArgs e)
{
VisualElement surfaceWeather = sender as VisualElement;
UniformItemsLayout parent = surfaceWeather.Parent as UniformItemsLayout;
Expand All @@ -58,5 +63,4 @@ private static void ChangeSurfaceControls(VisualElement child, bool isSelected)
VisualStateManager.GoToState(imageSmallWeather, visualStateControl);
VisualStateManager.GoToState(labelHour, visualStateControl);
}

}
2 changes: 1 addition & 1 deletion Mitawi/Views/WelcomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void RunWelcomeAnimation()
{ 0.3, 0.5, new Animation(v => imgWeather.Scale = v, 0, 1, Easing.SpringOut) },
{ 0.5, 0.7, new Animation(v => lblPhrase3.Opacity = v, 0, 1, Easing.CubicInOut) },
{ 0.6, 0.8, new Animation(v => lblPhrase4.Opacity = v, 0, 1, Easing.CubicInOut) },
{ 0.8, 1, new Animation(v=>
{ 0.8, 1, new Animation(v =>
{
btnGetStarted.Opacity = v;
btnGetStarted.Scale = v;
Expand Down

0 comments on commit 04ab606

Please sign in to comment.