Skip to content

Commit d33d4b7

Browse files
committed
fix TaskLoader initialization when using global style, fix commands with no parameters, CurrentLoadingTask is now available
1 parent 7f8913b commit d33d4b7

File tree

8 files changed

+185
-25
lines changed

8 files changed

+185
-25
lines changed

Clean-BinObj.ps1

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# PowerShell script that recursively deletes all 'bin' and 'obj' (or any other specified) folders inside current folder
2+
3+
$CurrentPath = (Get-Location -PSProvider FileSystem).ProviderPath
4+
5+
# recursively get all folders matching given includes, except ignored folders
6+
$FoldersToRemove = Get-ChildItem .\ -include bin,obj -Recurse | where {$_ -notmatch '_tools' -and $_ -notmatch '_build'} | foreach {$_.fullname}
7+
8+
# recursively get all folders matching given includes
9+
$AllFolders = Get-ChildItem .\ -include bin,obj -Recurse | foreach {$_.fullname}
10+
11+
# subtract arrays to calculate ignored ones
12+
$IgnoredFolders = $AllFolders | where {$FoldersToRemove -notcontains $_}
13+
14+
# remove folders and print to output
15+
if($FoldersToRemove -ne $null)
16+
{
17+
Write-Host
18+
foreach ($item in $FoldersToRemove)
19+
{
20+
remove-item $item -Force -Recurse;
21+
Write-Host "Removed: ." -nonewline;
22+
Write-Host $item.replace($CurrentPath, "");
23+
}
24+
}
25+
26+
# print ignored folders to output
27+
if($IgnoredFolders -ne $null)
28+
{
29+
Write-Host
30+
foreach ($item in $IgnoredFolders)
31+
{
32+
Write-Host "Ignored: ." -nonewline;
33+
Write-Host $item.replace($CurrentPath, "");
34+
}
35+
36+
Write-Host
37+
Write-Host $IgnoredFolders.count "folders ignored" -foregroundcolor yellow
38+
}
39+
40+
# print summary of the operation
41+
Write-Host
42+
if($FoldersToRemove -ne $null)
43+
{
44+
Write-Host $FoldersToRemove.count "folders removed" -foregroundcolor green
45+
}
46+
else { Write-Host "No folders to remove" -foregroundcolor green }
47+
48+
Write-Host
49+
50+
# prevent closing the window immediately
51+
$dummy = Read-Host "Completed, press enter to continue."

Retronado/Sample/Styles/Global.xaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
55
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
66
xmlns:converters="clr-namespace:Sample.Converters;assembly=Sample"
7+
xmlns:customViews="clr-namespace:Sharpnado.Presentation.Forms.CustomViews;assembly=Sharpnado.TaskLoaderView"
8+
xmlns:localization="clr-namespace:Sample.Localization;assembly=Sample"
79
xmlns:views="clr-namespace:Sample.Views;assembly=Sample">
810

911
<ResourceDictionary.MergedDictionaries>
@@ -48,12 +50,13 @@
4850
<converters:ExceptionToErrorMessageConverter x:Key="ExceptionToErrorMessageConverter" />
4951
<converters:CyclicLoadingLottieConverter x:Key="CyclicLoadingLottieConverter" />
5052
<converters:ExceptionToLottieConverter x:Key="ExceptionToLottieConverter" />
51-
<converters:StringToImageSourceResourceConverter x:Key="StringToImageSourceResourceConverter"/>
52-
<converters:ListCountToVisibilityConverter x:Key="ListCountToVisibilityConverter"/>
53+
<converters:StringToImageSourceResourceConverter x:Key="StringToImageSourceResourceConverter" />
54+
<converters:ListCountToVisibilityConverter x:Key="ListCountToVisibilityConverter" />
5355

54-
<!--<Style TargetType="customViews:TaskLoaderView">
55-
<Setter Property="AccentColor" Value="{StaticResource PrimaryColor}"/>
56-
<Setter Property="TextColor" Value="{StaticResource OnSurfaceColor}"/>
57-
</Style>-->
56+
<Style TargetType="customViews:TaskLoaderView">
57+
<Setter Property="AccentColor" Value="{StaticResource PrimaryColor}" />
58+
<Setter Property="RetryButtonText" Value="{localization:Translate ErrorButton_Retry}" />
59+
<Setter Property="TextColor" Value="{StaticResource OnSurfaceColor}" />
60+
</Style>
5861

5962
</ResourceDictionary>

Retronado/Sample/ViewModels/LoadOnDemandViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public LoadOnDemandViewModel(IRetroGamingService retroGamingService)
1616
{
1717
_retroGamingService = retroGamingService;
1818

19-
RandomGameLoaderCommand = new TaskLoaderCommand<Game>(GetRandomGame);
19+
RandomGameLoaderCommand = new TaskLoaderCommand<object, Game>(_ => GetRandomGame());
2020
}
2121

22-
public TaskLoaderCommand<Game> RandomGameLoaderCommand { get; }
22+
public TaskLoaderCommand<object, Game> RandomGameLoaderCommand { get; }
2323

2424
private async Task<Game> GetRandomGame()
2525
{

Retronado/Sample/Views/DefaultViewsPage.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
<Setter Property="FontFamily" Value="{StaticResource FontAtariSt}" />
2727
<Setter Property="EmptyStateMessage" Value="{loc:Translate Empty_Screen}" />
2828
<Setter Property="EmptyStateImageSource" Value="{inf:ImageResource Sample.Images.dougal.png}" />
29-
<Setter Property="RetryButtonText" Value="{loc:Translate ErrorButton_Retry}" />
3029
<Setter Property="TextColor" Value="{StaticResource OnDarkColor}" />
3130
<Setter Property="ErrorImageConverter" Value="{StaticResource ExceptionToImageSourceConverter}" />
3231
<Setter Property="ErrorMessageConverter" Value="{StaticResource ExceptionToErrorMessageConverter}" />

Sharpnado.TaskLoaderView/Sharpnado.TaskLoaderView.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<RootNamespace>Sharpnado.Presentation.Forms</RootNamespace>
88

99
<Product>$(AssemblyName) ($(TargetFramework))</Product>
10-
<AssemblyVersion>2.0.0.0</AssemblyVersion>
11-
<AssemblyFileVersion>2.0.0.0</AssemblyFileVersion>
12-
<Version>2.0.0.0</Version>
10+
<AssemblyVersion>2.0.1.0</AssemblyVersion>
11+
<AssemblyFileVersion>2.0.1.0</AssemblyFileVersion>
12+
<Version>2.0.1.0</Version>
1313
<PackOnBuild>true</PackOnBuild>
1414
<NeutralLanguage>en</NeutralLanguage>
1515

Sharpnado.TaskLoaderView/TaskLoaderCommand.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,43 @@ public override void Execute(object parameter)
5353

5454
public class TaskLoaderCommand<T> : TaskLoaderCommandBase
5555
{
56-
private readonly Func<Task<T>> _taskSource;
56+
private readonly Func<T, Task> _taskSource;
5757

58-
public TaskLoaderCommand(Func<Task<T>> taskSource, Func<object, bool> canExecute = null)
58+
public TaskLoaderCommand(Func<T, Task> taskSource, Func<object, bool> canExecute = null)
5959
: base(canExecute)
6060
{
6161
_taskSource = taskSource;
62-
Notifier = new TaskLoaderNotifier<T>();
62+
Notifier = new TaskLoaderNotifier();
6363
}
6464

65-
public TaskLoaderNotifier<T> Notifier { get; }
65+
public TaskLoaderNotifier Notifier { get; }
6666

6767
protected override bool IsExecuting => !Notifier.IsNotStarted && Notifier.IsNotCompleted;
6868

6969
public override void Execute(object parameter)
7070
{
71-
Notifier.Load(_taskSource);
71+
Notifier.Load(() => _taskSource((T)parameter));
72+
}
73+
}
74+
75+
public class TaskLoaderCommand<TParam, TTask> : TaskLoaderCommandBase
76+
{
77+
private readonly Func<TParam, Task<TTask>> _taskSource;
78+
79+
public TaskLoaderCommand(Func<TParam, Task<TTask>> taskSource, Func<object, bool> canExecute = null)
80+
: base(canExecute)
81+
{
82+
_taskSource = taskSource;
83+
Notifier = new TaskLoaderNotifier<TTask>();
84+
}
85+
86+
public TaskLoaderNotifier<TTask> Notifier { get; }
87+
88+
protected override bool IsExecuting => !Notifier.IsNotStarted && Notifier.IsNotCompleted;
89+
90+
public override void Execute(object parameter)
91+
{
92+
Notifier.Load(() => _taskSource((TParam)parameter));
7293
}
7394
}
7495
}

Sharpnado.TaskLoaderView/TaskLoaderNotifier.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public interface ITaskLoaderNotifier
4646

4747
bool ShowErrorNotification { get; }
4848

49+
ITaskMonitor CurrentLoadingTask { get; }
50+
4951
void Load();
5052

5153
void Reset();
@@ -137,9 +139,9 @@ public Exception Error
137139
set => SetAndRaise(ref _error, value);
138140
}
139141

140-
protected object SyncRoot { get; } = new object();
142+
public ITaskMonitor CurrentLoadingTask { get; protected set; }
141143

142-
protected ITaskMonitor CurrentLoadingTask { get; set; }
144+
protected object SyncRoot { get; } = new object();
143145

144146
public abstract void Load();
145147

0 commit comments

Comments
 (0)