Skip to content

Commit

Permalink
Merge pull request #5 from DevEddy/develop
Browse files Browse the repository at this point in the history
Develop into main
  • Loading branch information
DevEddy authored Mar 31, 2023
2 parents bf638ac + 89add59 commit 4741419
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 36 deletions.
8 changes: 8 additions & 0 deletions src/Resolved.It.Maui.App/Resources/Styles/FontIcons.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,13 @@
Color="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource White}}"
FontFamily="{StaticResource MaterialIconsRegular}"
Glyph="{x:Static icons:Material.Settings}"/>

<FontImageSource
x:Key="LogoutIconImageSource"
FontAutoScalingEnabled="True"
Size="25"
Color="{StaticResource White}"
FontFamily="{StaticResource MaterialIconsRegular}"
Glyph="{x:Static icons:Material.Logout}"/>

</ResourceDictionary>
7 changes: 6 additions & 1 deletion src/Resolved.It.Maui.App/ViewModels/BasePageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Resolved.It.Maui.App.ViewModels;

public class BasePageViewModel : ObservableObject
public class BasePageViewModel : ObservableObject, IQueryAttributable
{
private readonly SemaphoreSlim _isBusyLock = new(1, 1);

Expand All @@ -21,6 +21,11 @@ public BasePageViewModel(INavigationService navigationService)
NavigationService = navigationService;
}

public virtual void ApplyQueryAttributes(IDictionary<string, object> query)
{

}

protected async Task IsBusyFor(Func<Task> unitOfWork)
{
await _isBusyLock.WaitAsync();
Expand Down
21 changes: 20 additions & 1 deletion src/Resolved.It.Maui.App/ViewModels/LoginPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using CommunityToolkit.Mvvm.Input;
using Resolved.It.Maui.App.Services;
using Resolved.It.Maui.App.Views;
using Resolved.It.Maui.Core.Extensions;
using Resolved.It.Maui.Core.Validations;
using Resolved.It.Maui.Core.Validations.Rules;

Expand All @@ -28,6 +29,14 @@ public LoginPageViewModel(
Email.Value = "[email protected]";
}

public override void ApplyQueryAttributes(IDictionary<string, object> query)
{
base.ApplyQueryAttributes(query);

if (query!.ValueAsBool("Logout"))
LogoutCommand.ExecuteAsync(null);
}

private bool IsInputValid() => IsValid;

[RelayCommand(CanExecute = nameof(IsInputValid))]
Expand All @@ -42,7 +51,17 @@ await IsBusyFor(
await NavigationService.NavigateToAsync($"//{nameof(MainPage)}");
});
}


[RelayCommand]
private Task LogoutAsync()
{
_settingsService.AuthAccessToken = string.Empty;

Email.Value = string.Empty;
Password.Value = string.Empty;
return Task.CompletedTask;
}

private void CheckValidation()
{
var isEmailValid = Email.IsValid;
Expand Down
17 changes: 16 additions & 1 deletion src/Resolved.It.Maui.App/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.Input;
using Resolved.It.Maui.App.Models;
using Resolved.It.Maui.App.Services;
using Resolved.It.Maui.App.Validations;
using Resolved.It.Maui.App.Views;
using Resolved.It.Maui.Core.Validations;

namespace Resolved.It.Maui.App.ViewModels;

public class MainPageViewModel : BasePageViewModel
public partial class MainPageViewModel : BasePageViewModel
{
public ObservableCollection<Country> Countries { get; } = new(Country.GetCountryList());

Expand All @@ -19,5 +21,18 @@ public MainPageViewModel(INavigationService navigationService)
{
SelectedCountry.Validations.Add(new IsValidCountryRule<Country> { ValidationMessage = "Land is required." });
}

[RelayCommand]
private async Task Logout()
{
await IsBusyFor(
async () =>
{
await Task.Delay(100);
await NavigationService.NavigateToAsync(
$"//{nameof(LoginPage)}",
new Dictionary<string, object> { { "Logout", true } });
});
}
}

8 changes: 8 additions & 0 deletions src/Resolved.It.Maui.App/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
x:DataType="viewModels:MainPageViewModel"
x:Class="Resolved.It.Maui.App.Views.MainPage"
Title="Main">

<ContentPage.ToolbarItems>

<ToolbarItem Text=""
IconImageSource="{StaticResource LogoutIconImageSource}"
Command="{Binding LogoutCommand}" />
</ContentPage.ToolbarItems>

<VerticalStackLayout Spacing="25" Padding="30" >
<resolvedControls:EnhancedEntry
Placeholder="Note"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Platform;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using HorizontalAlignment = Microsoft.UI.Xaml.HorizontalAlignment;

// ReSharper disable once CheckNamespace
Expand All @@ -15,45 +13,27 @@ private static void RemoveBorder(IElementHandler? handler)
{
if (handler?.PlatformView is not Microsoft.UI.Xaml.Controls.TextBox textBox)
return;

textBox.FontWeight = Microsoft.UI.Text.FontWeights.Thin;
textBox.BorderThickness = new Microsoft.UI.Xaml.Thickness(0);
textBox.BorderBrush = Colors.Transparent.ToPlatform();
textBox.Background = Colors.Transparent.ToPlatform();

// https://stackoverflow.com/questions/73998049/net-maui-override-the-default-style-of-a-windows-view-textbox
textBox.Style = new Style
{
TargetType = typeof(Microsoft.UI.Xaml.Controls.TextBox),
Setters =
{
new Setter(Microsoft.UI.Xaml.Controls.Control.FontWeightProperty, Microsoft.UI.Text.FontWeights.Thin),
new Setter(Microsoft.UI.Xaml.Controls.Control.BorderThicknessProperty, new Microsoft.UI.Xaml.Thickness(0)),
new Setter(Microsoft.UI.Xaml.Controls.Control.BorderBrushProperty, Colors.Transparent.ToPlatform()),
new Setter(Microsoft.UI.Xaml.Controls.Control.BackgroundProperty, Colors.Transparent.ToPlatform())
}
};
}

private static void AddEvents(IElementHandler? handler)
{
if (handler?.PlatformView is not Microsoft.UI.Xaml.Controls.TextBox textBox)
return;

textBox.GettingFocus += TextBox_GettingFocus;
}

private static void RemoveEvents(IElementHandler? handler)
{
if (handler?.PlatformView is not Microsoft.UI.Xaml.Controls.TextBox textBox)
return;

textBox.GettingFocus -= TextBox_GettingFocus;
}

private static void TextBox_GettingFocus(UIElement sender, GettingFocusEventArgs args)
{
if (sender is not Microsoft.UI.Xaml.Controls.TextBox textBox)
return;

textBox.BorderThickness = new Microsoft.UI.Xaml.Thickness(0);
textBox.BorderBrush = Colors.Transparent.ToPlatform();
textBox.Background = Colors.Transparent.ToPlatform();
textBox.FocusVisualPrimaryThickness = textBox.BorderThickness;
textBox.FocusVisualSecondaryThickness = textBox.BorderThickness;
textBox.SelectionHighlightColor = new SolidColorBrush(Colors.Transparent.ToWindowsColor());

textBox.Resources.Remove("TextControlBorderThemeThicknessFocused");
textBox.Resources.Remove("TextControlBorderThemeThickness");
textBox.Resources["TextControlBorderThemeThicknessFocused"] = textBox.BorderThickness;
textBox.Resources["TextControlBorderThemeThickness"] = textBox.BorderThickness;
}

private static void FillWidth(IElementHandler? handler)
Expand Down
16 changes: 16 additions & 0 deletions src/Resolved.It.Maui.Core/Extensions/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;

namespace Resolved.It.Maui.Core.Extensions;

public static class DictionaryExtensions
{
public static bool ValueAsBool(this IDictionary<string, object?> dictionary, string key, bool defaultValue = false) =>
dictionary.TryGetValue(key, out var value) && value is bool dictValue
? dictValue
: defaultValue;

public static int ValueAsInt(this IDictionary<string, object?> dictionary, string key, int defaultValue = 0) =>
dictionary.TryGetValue(key, out var value) && value is int intValue
? intValue
: defaultValue;
}

0 comments on commit 4741419

Please sign in to comment.