Skip to content

Commit

Permalink
fix maui sample
Browse files Browse the repository at this point in the history
  • Loading branch information
roubachof committed Jun 23, 2022
1 parent c06368c commit 06a4ad8
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 168 deletions.
10 changes: 7 additions & 3 deletions Retronado.Maui/ExceptionToImageSourceConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Sample.Converters
{
public class ExceptionToImageSourceConverter : IValueConverter
public class ExceptionToImageSourceConverter : IValueConverter, IMarkupExtension
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Expand All @@ -32,7 +32,6 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
break;
}


return ImageSource.FromFile(imageName);
}

Expand All @@ -41,5 +40,10 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
// One-Way converter only
throw new NotImplementedException();
}

public object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
}
}
}
263 changes: 158 additions & 105 deletions Retronado.Maui/Views/CommandsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,12 @@
xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
xmlns:tlv="clr-namespace:Sharpnado.TaskLoaderView;assembly=Sharpnado.Maui.TaskLoaderView"
xmlns:loc="clr-namespace:Sample.Localization"
xmlns:converters="clr-namespace:Sample.Converters"
ios:Page.UseSafeArea="true"
BackgroundColor="{StaticResource TopElementBackground}"
x:DataType="viewModels:CommandsPageViewModel"
NavigationPage.HasNavigationBar="false">

<ContentPage.Resources>
<ResourceDictionary>
<Style x:Key="TaskLoaderStyle" TargetType="tlv:TaskLoaderView">
<Setter Property="AccentColor" Value="{StaticResource AccentColor}" />
<Setter Property="FontFamily" Value="FontAtariSt" />
<Setter Property="EmptyStateMessage" Value="{x:Static loc:SampleResources.Empty_Screen}" />
<Setter Property="EmptyStateImageSource" Value="dougal.png" />
<Setter Property="TextColor" Value="{StaticResource OnDarkColor}" />
<Setter Property="ErrorImageConverter" Value="{StaticResource ExceptionToImageSourceConverter}" />
<Setter Property="ErrorMessageConverter" Value="{StaticResource ExceptionToErrorMessageConverter}" />
<Setter Property="NotificationBackgroundColor" Value="{StaticResource TosWindows}" />
<Setter Property="NotificationTextColor" Value="{StaticResource TextPrimaryColor}" />
</Style>
</ResourceDictionary>
</ContentPage.Resources>

<ContentPage.Content>
<Grid>
<Grid.RowDefinitions>
Expand All @@ -41,86 +26,154 @@
BackgroundColor="{StaticResource TopElementBackground}"
Theme="Standard" />

<tlv:TaskLoaderView Grid.Row="1"
Style="{StaticResource TaskLoaderStyle}"
TaskLoaderNotifier="{Binding Loader}">
<Grid RowDefinitions="300,*">
<Image Grid.Row="0"
skeleton:Skeleton.BackgroundColor="{StaticResource GreyBackground}"
skeleton:Skeleton.IsBusy="{Binding Loader.ShowLoader}"
Aspect="Fill"
Source="{Binding Loader.Result.ScreenshotUrl}" />

<Frame Grid.Row="0"
Padding="15,5,15,30"
VerticalOptions="End"
CornerRadius="0"
BackgroundColor="{StaticResource DarkOverlay}">
<Grid Padding="0"
ColumnDefinitions="*,60"
RowDefinitions="40,20,20"
RowSpacing="0">
<Label Grid.Row="0"
Grid.Column="0"
Style="{StaticResource GameName}"
Margin="0,0,10,0"
skeleton:Skeleton.BackgroundColor="{StaticResource GreyBackground}"
skeleton:Skeleton.IsBusy="{Binding Loader.ShowLoader}"
Text="{Binding Loader.Result.Name}" />

<Label Grid.Row="1"
Style="{StaticResource GameCompany}"
skeleton:Skeleton.BackgroundColor="{StaticResource GreyBackground}"
skeleton:Skeleton.IsBusy="{Binding Loader.ShowLoader}"
Text="{Binding Loader.Result.MajorCompany}" />

<Label Grid.Row="2"
Style="{StaticResource GameGenre}"
Text="{Binding Loader.Result.MajorGenre}" />

<Image Grid.Row="0"
Grid.RowSpan="3"
Grid.Column="1"
Margin="0,10,0,0"
Source="{Binding Loader.Result.CoverUrl}" />

</Grid>
</Frame>

<Button Grid.Row="1"
HeightRequest="40"
Margin="0,-20,100,0"
Padding="10"
HorizontalOptions="Center"
VerticalOptions="Start"
BackgroundColor="{StaticResource AccentColor}"
Command="{Binding BuyGameCommand}"
FontFamily="FontAtariSt"
Text="BUY IT"
TextColor="{StaticResource TopElementBackground}" />

<Button Grid.Row="1"
HeightRequest="40"
Margin="100,-20,0,0"
Padding="10"
HorizontalOptions="Center"
VerticalOptions="Start"
BackgroundColor="{StaticResource AccentColor}"
Command="{Binding PlayTheGameCommand}"
FontFamily="FontAtariSt"
Text="PLAY IT"
TextColor="{StaticResource TopElementBackground}" />


<Label Grid.Row="1"
Style="{StaticResource GameGenre}"
Margin="15,45,15,0"
Text="{Binding Loader.Result.Summary}"
TextColor="White" />


</Grid>
</tlv:TaskLoaderView>
<RefreshView Grid.Row="1"
IsRefreshing="{Binding Loader.ShowRefresher}"
RefreshColor="{StaticResource AccentColor}"
Command="{Binding Loader.RefreshCommand}">
<ScrollView>
<tlv:TemplatedTaskLoader TaskLoaderNotifier="{Binding Loader}">
<tlv:TemplatedTaskLoader.ResultControlTemplate>
<ControlTemplate>
<Grid RowDefinitions="300,*"
x:DataType="viewModels:CommandsPageViewModel"
BindingContext="{Binding Source={RelativeSource
AncestorType={x:Type viewModels:CommandsPageViewModel}}}">
<Image Grid.Row="0"
skeleton:Skeleton.BackgroundColor="{StaticResource GreyBackground}"
skeleton:Skeleton.IsBusy="{Binding Loader.ShowLoader}"
Aspect="Fill"
Source="{Binding Loader.Result.ScreenshotUrl}" />

<Frame Grid.Row="0"
Padding="15,5,15,30"
VerticalOptions="End"
CornerRadius="0"
BackgroundColor="{StaticResource DarkOverlay}">

<Grid Padding="0"
ColumnDefinitions="*,60"
RowDefinitions="40,20,20"
RowSpacing="0">
<Label Grid.Row="0"
Grid.Column="0"
Style="{StaticResource GameName}"
Margin="0,0,10,0"
skeleton:Skeleton.BackgroundColor="{StaticResource GreyBackground}"
skeleton:Skeleton.IsBusy="{Binding Loader.ShowLoader}"
Text="{Binding Loader.Result.Name}" />

<Label Grid.Row="1"
Style="{StaticResource GameCompany}"
skeleton:Skeleton.BackgroundColor="{StaticResource GreyBackground}"
skeleton:Skeleton.IsBusy="{Binding Loader.ShowLoader}"
Text="{Binding Loader.Result.MajorCompany}" />

<Label Grid.Row="2"
Style="{StaticResource GameGenre}"
Text="{Binding Loader.Result.MajorGenre}" />

<Image Grid.Row="0"
Grid.RowSpan="3"
Grid.Column="1"
Margin="0,10,0,0"
Source="{Binding Loader.Result.CoverUrl}" />

</Grid>
</Frame>

<Button Grid.Row="1"
HeightRequest="40"
Margin="0,-20,100,0"
Padding="10"
HorizontalOptions="Center"
VerticalOptions="Start"
BackgroundColor="{StaticResource AccentColor}"
Command="{Binding BuyGameCommand}"
FontFamily="FontAtariSt"

Text="BUY IT"
TextColor="{StaticResource TopElementBackground}" />

<Button Grid.Row="1"
HeightRequest="40"
Margin="100,-20,0,0"
Padding="10"
HorizontalOptions="Center"
VerticalOptions="Start"
BackgroundColor="{StaticResource AccentColor}"
Command="{Binding PlayTheGameCommand}"
FontFamily="FontAtariSt"
Text="PLAY IT"
TextColor="{StaticResource TopElementBackground}" />


<Label Grid.Row="1"
Style="{StaticResource GameGenre}"
Margin="15,45,15,0"
Text="{Binding Loader.Result.Summary}"
TextColor="White" />
</Grid>
</ControlTemplate>
</tlv:TemplatedTaskLoader.ResultControlTemplate>

<tlv:TemplatedTaskLoader.LoadingControlTemplate>
<ControlTemplate>
<ActivityIndicator Color="{StaticResource AccentColor}"
IsRunning="True"
HorizontalOptions="Center"
VerticalOptions="Center" />
</ControlTemplate>
</tlv:TemplatedTaskLoader.LoadingControlTemplate>

<tlv:TemplatedTaskLoader.ErrorControlTemplate>
<ControlTemplate x:DataType="{x:Null}">
<StackLayout HorizontalOptions="Center"
VerticalOptions="Center"
BindingContext="{Binding Source={RelativeSource AncestorType={x:Type tlv:TemplatedTaskLoader}},
Path=TaskLoaderNotifier}"
Orientation="Vertical"
Spacing="10">
<Frame CornerRadius="50"
HorizontalOptions="Center"
VerticalOptions="Center"
BackgroundColor="Transparent"
HasShadow="False"
IsClippedToBounds="True"
WidthRequest="100"
Padding="0"
HeightRequest="100"
Margin="0,0,0,10">
<Image HorizontalOptions="Center"
VerticalOptions="Center"
WidthRequest="100"
HeightRequest="100"
Source="{Binding Error,
Converter={converters:ExceptionToImageSourceConverter}}" />
</Frame>
<Label Style="{StaticResource TextBodySecondary}"
WidthRequest="300"
Margin="0,0,0,20"
HorizontalTextAlignment="Center"
LineBreakMode="WordWrap"
MaxLines="2"
Text="{Binding Error,
Converter={converters:ExceptionToErrorMessageConverter}}" />

<Button BackgroundColor="{StaticResource AccentColor}"
CornerRadius="10"
Padding="10,0"
HorizontalOptions="Center"
VerticalOptions="End"
Command="{Binding ReloadCommand}"
TextColor="Black"
Text="{x:Static loc:SampleResources.ErrorButton_Retry}" />
</StackLayout>
</ControlTemplate>
</tlv:TemplatedTaskLoader.ErrorControlTemplate>

</tlv:TemplatedTaskLoader>
</ScrollView>
</RefreshView>

<AbsoluteLayout Grid.Row="1"
BackgroundColor="#77002200"
Expand All @@ -138,7 +191,7 @@
<Image x:Name="BusyImage"
Margin="15,30,15,0"
Aspect="AspectFit"
Source="busy_bee_white_bg.png" />
Source="busy_bee_white_bg.png" />
<Label Grid.Row="1"
Style="{StaticResource TextBody}"
Margin="{StaticResource ThicknessLarge}"
Expand All @@ -149,14 +202,14 @@
</AbsoluteLayout>

<tlv:Snackbar Grid.Row="1"
Margin="15"
VerticalOptions="End"
BackgroundColor="White"
FontFamily="FontAtariSt"
IsVisible="{Binding CompositeNotifier.ShowError, Mode=TwoWay}"
Text="{Binding CompositeNotifier.LastError, Converter={StaticResource ExceptionToErrorMessageConverter}}"
TextColor="{StaticResource TextPrimaryColor}"
TextHorizontalOptions="Start" />
Margin="15"
VerticalOptions="End"
BackgroundColor="White"
FontFamily="FontAtariSt"
IsVisible="{Binding CompositeNotifier.ShowLastError, Mode=TwoWay}"
Text="{Binding CompositeNotifier.LastError, Converter={StaticResource ExceptionToErrorMessageConverter}}"
TextColor="{StaticResource TextPrimaryColor}"
TextHorizontalOptions="Start" />
</Grid>
</ContentPage.Content>

Expand Down
Loading

0 comments on commit 06a4ad8

Please sign in to comment.