Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #166

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions MAUI.FreakyControls/MAUI.FreakyControls.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 25.0.1703.2
# Visual Studio Version 17
VisualStudioVersion = 17.13.35723.152 d17.13
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples", "Samples\Samples.csproj", "{FA323AEE-85A9-4D5D-9726-03C7D1FD71A2}"
EndProject
Expand All @@ -15,21 +14,18 @@ Global
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FA323AEE-85A9-4D5D-9726-03C7D1FD71A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA323AEE-85A9-4D5D-9726-03C7D1FD71A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA323AEE-85A9-4D5D-9726-03C7D1FD71A2}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{FA323AEE-85A9-4D5D-9726-03C7D1FD71A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA323AEE-85A9-4D5D-9726-03C7D1FD71A2}.Release|Any CPU.Build.0 = Release|Any CPU
{864B4829-7286-4921-A185-DA67FE0D1155}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{864B4829-7286-4921-A185-DA67FE0D1155}.Debug|Any CPU.Build.0 = Debug|Any CPU
{864B4829-7286-4921-A185-DA67FE0D1155}.Release|Any CPU.ActiveCfg = Release|Any CPU
{864B4829-7286-4921-A185-DA67FE0D1155}.Release|Any CPU.Build.0 = Release|Any CPU
{C80669FA-43B5-4B68-9819-30BFD1915031}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C80669FA-43B5-4B68-9819-30BFD1915031}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C80669FA-43B5-4B68-9819-30BFD1915031}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C80669FA-43B5-4B68-9819-30BFD1915031}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3A49EF6E-4CF5-41B1-8F23-FCD2AC812C50}
EndGlobalSection
EndGlobal
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class InverseBoolConverter : BaseOneWayValueConverter
{
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is bool boolValue))
if (value is not bool boolValue)
{
throw new ArgumentException("Value must be a boolean", nameof(value));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static class CollectionExtensions
{
public static ObservableCollection<T> ToObservable<T>(this IEnumerable<T> col)
{
return new ObservableCollection<T>(col);
return [.. col];
}

public static IEnumerable<(T item, int index)> WithIndex<T>(this IEnumerable<T> self) => self?.Select((item, index) => (item, index)) ?? new List<(T, int)>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class StreamExtensions
{
public static MemoryStream GetMemoryStream(this Stream stream)
{
MemoryStream memoryStream = new MemoryStream();
MemoryStream memoryStream = new();
stream.CopyTo(memoryStream);
memoryStream.Position = 0;
return memoryStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private static async Task<Stream> DownloadStreamAsync(Uri uri, CancellationToken

// Do not remove this await otherwise the client will dispose before
// the stream even starts
return await StreamWrapper.GetStreamAsync(uri, cancellationToken, client).ConfigureAwait(false);
return await StreamWrapper.GetStreamAsync(uri, client, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public SizeOrScale(float x, float y, SizeOrScaleType type, bool keepAspectRatio)

public bool KeepAspectRatio { get; set; }

public bool IsValid => X > 0 && Y > 0;
public readonly bool IsValid => X > 0 && Y > 0;

public Size GetScale(float width, float height)
public readonly Size GetScale(float width, float height)
{
if (Type == SizeOrScaleType.Scale)
{
Expand All @@ -74,7 +74,7 @@ public Size GetScale(float width, float height)
}
}

public Size GetSize(float width, float height)
public readonly Size GetSize(float width, float height)
{
if (Type == SizeOrScaleType.Scale)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protected override Platforms.Android.SignaturePadCanvasView

private void OnImageStreamRequested(object sender, ImageStreamRequestedEventArgs e)
{
var ctrl = this.PlatformView;
var ctrl = PlatformView;
if (ctrl is not null)
{
var format = e.ImageFormat;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Threading;

namespace Maui.FreakyControls.Wrappers
{
Expand Down Expand Up @@ -83,7 +84,7 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}

public static async Task<Stream> GetStreamAsync(Uri uri, CancellationToken cancellationToken, HttpClient client)
public static async Task<Stream> GetStreamAsync(Uri uri, HttpClient client, CancellationToken cancellationToken)
{
var response = await client.GetAsync(uri, cancellationToken).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
Expand All @@ -96,7 +97,7 @@ public static async Task<Stream> GetStreamAsync(Uri uri, CancellationToken cance

// the HttpResponseMessage needs to be disposed of after the calling code is done with the stream
// otherwise the stream may get disposed before the caller can use it
return new StreamWrapper(await response.Content.ReadAsStreamAsync().ConfigureAwait(false), response);
return new StreamWrapper(await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false), response);
}
}
}
52 changes: 26 additions & 26 deletions MAUI.FreakyControls/Samples/AppShell.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@ namespace Samples;

public partial class AppShell : Shell
{
internal const string buttons = "Buttons";
internal const string checkboxes = "Checkboxes";
internal const string imageViews = "ImageViews";
internal const string inputViews = "InputViews";
internal const string pickers = "Pickers";
internal const string radioButtons = "RadioButtons";
internal const string signaturePreview = "ImageDisplay";
internal const string signatureView = "SignatureView";
internal const string textInputLayout = "TextInputLayouts";
internal const string jumpList = "JumpList";
internal const string pinView = "PinView";
internal const string switches = "Switch";
internal const string zoomImage = "ZoomImage";
internal const string Buttons = "Buttons";
internal const string Checkboxes = "Checkboxes";
internal const string ImageViews = "ImageViews";
internal const string InputViews = "InputViews";
internal const string Pickers = "Pickers";
internal const string RadioButtons = "RadioButtons";
internal const string SignaturePreview = "ImageDisplay";
internal const string SignatureView = "SignatureView";
internal const string TextInputLayout = "TextInputLayouts";
internal const string JumpList = "JumpList";
internal const string PinView = "PinView";
internal const string Switches = "Switch";
internal const string ZoomImage = "ZoomImage";

public AppShell()
{
InitializeComponent();
Routing.RegisterRoute(inputViews, typeof(InputViews.InputViews));
Routing.RegisterRoute(pickers, typeof(Pickers.PickersView));
Routing.RegisterRoute(textInputLayout, typeof(TextInputLayout.TextInputLayoutView));
Routing.RegisterRoute(imageViews, typeof(ImageViews.ImagesPage));
Routing.RegisterRoute(signatureView, typeof(SignatureView.SignatureView));
Routing.RegisterRoute(signaturePreview, typeof(SignatureView.ImageDisplay));
Routing.RegisterRoute(checkboxes, typeof(Checkboxes.CheckboxesView));
Routing.RegisterRoute(radioButtons, typeof(RadioButtons.RadioButtonsView));
Routing.RegisterRoute(buttons, typeof(ButtonsView.ButtonsView));
Routing.RegisterRoute(jumpList, typeof(JumpList.JumpListView));
Routing.RegisterRoute(pinView, typeof(PinView.PinView));
Routing.RegisterRoute(switches, typeof(Switch.SwitchsView));
Routing.RegisterRoute(zoomImage, typeof(ZoomImage.ZoomImageView));
Routing.RegisterRoute(InputViews, typeof(InputViews.InputViews));
Routing.RegisterRoute(Pickers, typeof(Pickers.PickersView));
Routing.RegisterRoute(TextInputLayout, typeof(TextInputLayout.TextInputLayoutView));
Routing.RegisterRoute(ImageViews, typeof(ImageViews.ImagesPage));
Routing.RegisterRoute(SignatureView, typeof(SignatureView.SignatureView));
Routing.RegisterRoute(SignaturePreview, typeof(SignatureView.ImageDisplay));
Routing.RegisterRoute(Checkboxes, typeof(Checkboxes.CheckboxesView));
Routing.RegisterRoute(RadioButtons, typeof(RadioButtons.RadioButtonsView));
Routing.RegisterRoute(Buttons, typeof(ButtonsView.ButtonsView));
Routing.RegisterRoute(JumpList, typeof(JumpList.JumpListView));
Routing.RegisterRoute(PinView, typeof(PinView.PinView));
Routing.RegisterRoute(Switches, typeof(Switch.SwitchsView));
Routing.RegisterRoute(ZoomImage, typeof(ZoomImage.ZoomImageView));
}
}
3 changes: 3 additions & 0 deletions MAUI.FreakyControls/Samples/Checkboxes/CheckboxesView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:constants="clr-namespace:Samples"
xmlns:freakyControls="clr-namespace:Maui.FreakyControls;assembly=Maui.FreakyControls"
xmlns:vm="clr-namespace:Samples.Checkboxes"
x:DataType="vm:CheckboxesViewModel"
Title="CheckboxesView">

<ContentPage.Resources>
<Style TargetType="freakyControls:FreakyChip">
<Setter Property="Padding" Value="10" />
Expand Down
30 changes: 15 additions & 15 deletions MAUI.FreakyControls/Samples/ImageUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ namespace Samples;

public static class ImageUrls
{
public const string female1 = "https://static.displate.com/280x392/displate/2023-12-14/0e8bf99c32274f779851ee93b367ae8b_247fa401e8831ffd3eb34b159e2332f3.jpg";
public const string female2 = "https://img.freepik.com/premium-vector/young-girl-anime-style-character-vector-illustration-design-manga-anime-girl_147933-100.jpg";
public const string female3 = "https://i.pinimg.com/736x/f8/50/02/f8500297dfc066019cae88ebd15dabeb.jpg";
public const string female4 = "https://rukminim2.flixcart.com/image/850/1000/kxkqavk0/poster/m/6/p/medium-anime-girls-original-characters-women-black-hair-long-original-imagayfvhs5gymjt.jpeg?q=90&crop=false";
public const string female5 = "https://i.pinimg.com/originals/6c/65/87/6c6587847c664394540e8f2c7bde3ac3.jpg";
public const string female6 = "https://w0.peakpx.com/wallpaper/368/441/HD-wallpaper-cute-anime-girl-anime-cat-girl-anime-girl-cartoon-cat-girl-cute-anime.jpg";
public const string female7 = "https://i.pinimg.com/736x/db/f4/bc/dbf4bc03c4ce45f944a177c463b3854c.jpg";
public const string female8 = "https://thumbs.dreamstime.com/z/pretty-anime-woman-white-background-generative-ai-art-created-ai-technology-image-pretty-anime-woman-white-background-275547588.jpg";
public const string female9 = "https://e0.pxfuel.com/wallpapers/600/658/desktop-wallpaper-10-cute-girl-anime-anime-top-cool-female-anime.jpg";
public const string female10 = "https://cdn.pixabay.com/photo/2023/02/07/10/49/ai-generated-7773820_640.jpg";
public const string Female1 = "https://static.displate.com/280x392/displate/2023-12-14/0e8bf99c32274f779851ee93b367ae8b_247fa401e8831ffd3eb34b159e2332f3.jpg";
public const string Female2 = "https://img.freepik.com/premium-vector/young-girl-anime-style-character-vector-illustration-design-manga-anime-girl_147933-100.jpg";
public const string Female3 = "https://i.pinimg.com/736x/f8/50/02/f8500297dfc066019cae88ebd15dabeb.jpg";
public const string Female4 = "https://rukminim2.flixcart.com/image/850/1000/kxkqavk0/poster/m/6/p/medium-anime-girls-original-characters-women-black-hair-long-original-imagayfvhs5gymjt.jpeg?q=90&crop=false";
public const string Female5 = "https://i.pinimg.com/originals/6c/65/87/6c6587847c664394540e8f2c7bde3ac3.jpg";
public const string Female6 = "https://w0.peakpx.com/wallpaper/368/441/HD-wallpaper-cute-anime-girl-anime-cat-girl-anime-girl-cartoon-cat-girl-cute-anime.jpg";
public const string Female7 = "https://i.pinimg.com/736x/db/f4/bc/dbf4bc03c4ce45f944a177c463b3854c.jpg";
public const string Female8 = "https://thumbs.dreamstime.com/z/pretty-anime-woman-white-background-generative-ai-art-created-ai-technology-image-pretty-anime-woman-white-background-275547588.jpg";
public const string Female9 = "https://e0.pxfuel.com/wallpapers/600/658/desktop-wallpaper-10-cute-girl-anime-anime-top-cool-female-anime.jpg";
public const string Female10 = "https://cdn.pixabay.com/photo/2023/02/07/10/49/ai-generated-7773820_640.jpg";

public const string male1 = "https://i.pinimg.com/originals/97/28/55/972855ed6c7539a2695d64193f59e041.jpg";
public const string male2 = "https://i.pinimg.com/236x/0f/4a/e5/0f4ae561a4a23b7322ef59519c20de12.jpg";
public const string male3 = "https://wallpapers.com/images/hd/white-hair-jujutsu-kaisen-gojo-0kxukr18bqmg50sk.jpg";
public const string male4 = "https://w0.peakpx.com/wallpaper/871/38/HD-wallpaper-ban-seven-deadly-sins-anime-ban-seven-deadly-sins.jpg";
public const string male5 = "https://i.pinimg.com/originals/3d/08/28/3d08280917ce517431135de1da94c54e.jpg";
public const string Male1 = "https://i.pinimg.com/originals/97/28/55/972855ed6c7539a2695d64193f59e041.jpg";
public const string Male2 = "https://i.pinimg.com/236x/0f/4a/e5/0f4ae561a4a23b7322ef59519c20de12.jpg";
public const string Male3 = "https://wallpapers.com/images/hd/white-hair-jujutsu-kaisen-gojo-0kxukr18bqmg50sk.jpg";
public const string Male4 = "https://w0.peakpx.com/wallpaper/871/38/HD-wallpaper-ban-seven-deadly-sins-anime-ban-seven-deadly-sins.jpg";
public const string Male5 = "https://i.pinimg.com/originals/3d/08/28/3d08280917ce517431135de1da94c54e.jpg";
}
5 changes: 3 additions & 2 deletions MAUI.FreakyControls/Samples/ImageViews/ImagesPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
xmlns:freakyControls="clr-namespace:Maui.FreakyControls;assembly=Maui.FreakyControls"
xmlns:samples="clr-namespace:Samples"
xmlns:vm="clr-namespace:Samples.ImageViews"
Title="ImageViews"
x:DataType="vm:ImagesViewModel">
x:DataType="vm:ImagesViewModel"
Title="ImageViews">

<ScrollView>
<VerticalStackLayout Padding="30" Spacing="10">

Expand Down
2 changes: 1 addition & 1 deletion MAUI.FreakyControls/Samples/InputViews/InputViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public InputViewModel()
{
NamesCollection = Names.ToObservable();

NamesModel = names.Select(x => new AutoCompleteModel { Name = x }).ToList();
NamesModel = [.. names.Select(x => new AutoCompleteModel { Name = x })];
NamesCollectionModel = NamesModel.ToObservable();

EntryCompleteCommand = new Command(ExecuteEntryCompleteCommand);
Expand Down
3 changes: 2 additions & 1 deletion MAUI.FreakyControls/Samples/JumpList/JumpListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public JumpListViewModel()
"Yasmine", "Yael", "Yara", "Yaretzi", "Yvonne", "Yvette", "Yvaine", "Yelena", "Yara", "Yasmine",
"Zachary", "Zoe", "Zachariah", "Zara", "Zayden", "Zuri", "Zane", "Zelda", "Zeke", "Zena"
};
Names = names.OrderBy(x => x).ToList();

Names = [.. names.OrderBy(x => x)];
}
}
16 changes: 8 additions & 8 deletions MAUI.FreakyControls/Samples/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

public partial class MainPage : ContentPage
{
private MainViewModel vm;
private readonly MainViewModel vm;

public MainPage()
{
BindingContext = vm = new MainViewModel();
InitializeComponent();
}

private async void FreakySvgImageView_Tapped(object sender, System.EventArgs e)
private async void FreakySvgImageView_Tapped(object sender, EventArgs e)
{
await this.DisplayAlert("Yo", "Hi from the dotnet bot", "Ok");
await DisplayAlert("Yo", "Hi from the dotnet bot", "Ok");
}

private async void OnButtonClicked(System.Object sender, System.EventArgs e)
private async void OnButtonClicked(object sender, EventArgs e)
{
await this.DisplayAlert("Yo", "I am a freaky button", "Ok");
await DisplayAlert("Yo", "I am a freaky button", "Ok");
}

private async void ListView_ItemTapped(System.Object sender, Microsoft.Maui.Controls.ItemTappedEventArgs e)
private async void ListView_ItemTapped(object sender, ItemTappedEventArgs e)
{
string route = e.Item.ToString();
if (route == AppShell.jumpList)
if (route == AppShell.JumpList)
{
var permission = await Samples.PermissionHelper.CheckAndRequestPermissionAsync<Permissions.Vibrate>();
var permission = await PermissionHelper.CheckAndRequestPermissionAsync<Permissions.Vibrate>();
if (permission != PermissionStatus.Granted)
{
await DisplayAlert("Error", "Needs vibration permission for haptik feedback", "Ok");
Expand Down
36 changes: 18 additions & 18 deletions MAUI.FreakyControls/Samples/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class MainViewModel : BaseViewModel

public List<string> Names => names;

protected List<string> names = new List<string>
{
protected List<string> names =
[
"Ava", "Amelia", "Adam", "Aaron", "Abigail", "Addison", "Alexandra", "Alice", "Ashley", "Aiden",
"Benjamin", "Bella", "Brandon", "Brooke", "Blake", "Brian", "Brooklyn", "Bailey", "Bradley", "Brianna",
"Charlotte", "Caleb", "Chloe", "Carter", "Christopher", "Claire", "Cameron", "Cassidy", "Cooper", "Caroline",
Expand All @@ -39,28 +39,28 @@ public class MainViewModel : BaseViewModel
"Xander", "Ximena", "Xavier", "Xanthe", "Xena", "Xia", "Xylia", "Xyla", "Xerxes", "Xylona",
"Yasmine", "Yael", "Yara", "Yaretzi", "Yvonne", "Yvette", "Yvaine", "Yelena", "Yara", "Yasmine",
"Zachary", "Zoe", "Zachariah", "Zara", "Zayden", "Zuri", "Zane", "Zelda", "Zeke", "Zena"
};
];

public MainViewModel()
{
ImageWasTappedCommand = new AsyncRelayCommand<object>(ImageTappedAsync, new AsyncRelayCommandOptions());
FreakyLongPressedCommand = new AsyncRelayCommand<object>(LongPressedAsync);

Items = new ObservableCollection<string>
{
AppShell.pickers,
AppShell.textInputLayout,
AppShell.inputViews,
AppShell.imageViews,
AppShell.signatureView,
AppShell.checkboxes,
AppShell.radioButtons,
AppShell.buttons,
AppShell.jumpList,
AppShell.pinView,
AppShell.switches,
AppShell.zoomImage
};
Items =
[
AppShell.Pickers,
AppShell.TextInputLayout,
AppShell.InputViews,
AppShell.ImageViews,
AppShell.SignatureView,
AppShell.Checkboxes,
AppShell.RadioButtons,
AppShell.Buttons,
AppShell.JumpList,
AppShell.PinView,
AppShell.Switches,
AppShell.ZoomImage
];
}

public ICommand FreakyLongPressedCommand { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions MAUI.FreakyControls/Samples/Pickers/PickersView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:freakyControls="clr-namespace:Maui.FreakyControls;assembly=Maui.FreakyControls"
xmlns:vm="clr-namespace:Samples.Pickers"
x:DataType="vm:PickersViewModel"
Title="PickersView">

<VerticalStackLayout Padding="30" Spacing="10">
<Label Text="Freaky DatePicker below: " TextColor="Black" />
<Border>
Expand Down
2 changes: 1 addition & 1 deletion MAUI.FreakyControls/Samples/Pickers/PickersView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public partial class PickersView : ContentPage
public PickersView()
{
InitializeComponent();
this.BindingContext = new PickersViewModel();
BindingContext = new PickersViewModel();
}
}
Loading