Add few things

main
DJYohann 2 years ago
parent d5b5dc34af
commit ca1000d0c6

@ -1,5 +1,4 @@
using System; using System.Globalization;
using System.Globalization;
namespace App.Converters namespace App.Converters
{ {
@ -13,8 +12,7 @@ namespace App.Converters
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ {
var bytes = System.Convert.FromBase64String(value as string); var bytes = System.Convert.FromBase64String(value as string);
MemoryStream imageDecode = new MemoryStream(bytes); return ImageSource.FromStream(() => new MemoryStream(bytes));
return ImageSource.FromStream(() => imageDecode);
} }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

@ -23,8 +23,10 @@ public static class MauiProgram
}) })
.Services.AddSingleton<IDataManager, StubData>() .Services.AddSingleton<IDataManager, StubData>()
.AddSingleton<ChampionListPageVM>() .AddSingleton<ChampionListPageVM>()
.AddTransient<ChampionDetailPageVM>()
.AddSingleton<ChampionManagerVM>() .AddSingleton<ChampionManagerVM>()
.AddSingleton<ChampionsListPage>(); .AddSingleton<ChampionsListPage>()
.AddSingleton<ChampionDetailPage>();
#if DEBUG #if DEBUG
builder.Logging.AddDebug(); builder.Logging.AddDebug();

@ -5,6 +5,11 @@
xmlns:converters="clr-namespace:App.Converters" xmlns:converters="clr-namespace:App.Converters"
Title="Add Champion" Title="Add Champion"
BackgroundColor="Black"> BackgroundColor="Black">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Edit" Command="{Binding NavigateToChampionEditPageCommand}"/>
<ToolbarItem Text="Edit" Command="{Binding NavigateToChampionEditPageCommand}"/>
</ContentPage.ToolbarItems>
<ContentPage.Resources> <ContentPage.Resources>
<converters:Base64ToImage x:Key="Base64ToImageConv"/> <converters:Base64ToImage x:Key="Base64ToImageConv"/>
@ -28,7 +33,7 @@
<Entry Placeholder="Champion name"/> <Entry Placeholder="Champion name"/>
</StackLayout> </StackLayout>
<StackLayout Orientation="Horizontal" VerticalOptions="CenterAndExpand"> <!--<StackLayout Orientation="Horizontal" VerticalOptions="CenterAndExpand">
<Label Text="Icon"/> <Label Text="Icon"/>
</StackLayout> </StackLayout>
@ -36,7 +41,7 @@
<StackLayout Orientation="Horizontal" VerticalOptions="CenterAndExpand"> <StackLayout Orientation="Horizontal" VerticalOptions="CenterAndExpand">
<Label Text="Image"/> <Label Text="Image"/>
</StackLayout> </StackLayout>-->
<StackLayout Orientation="Horizontal" VerticalOptions="CenterAndExpand"> <StackLayout Orientation="Horizontal" VerticalOptions="CenterAndExpand">
<Label Text="Bio"/> <Label Text="Bio"/>

@ -4,6 +4,7 @@ public partial class ChampionAddEditPage : ContentPage
{ {
public ChampionAddEditPage() public ChampionAddEditPage()
{ {
InitializeComponent(); InitializeComponent();
} }
} }

@ -6,8 +6,8 @@
Title="Champion Page" Title="Champion Page"
BackgroundColor="Black"> BackgroundColor="Black">
<ContentPage.ToolbarItems> <ContentPage.ToolbarItems>
<ToolbarItem Text="Edit" Clicked="ToolbarItem_Clicked"/> <ToolbarItem Text="Edit"
Command="{Binding NaviagteToChampionAddEditPageCommand}"/>
</ContentPage.ToolbarItems> </ContentPage.ToolbarItems>
<ContentPage.Resources> <ContentPage.Resources>
@ -20,23 +20,23 @@
<ScrollView> <ScrollView>
<StackLayout Orientation="Vertical"> <StackLayout Orientation="Vertical">
<Image Source="{Binding Path=Image, Converter={StaticResource Base64ToImageConv}}"/> <Image Source="{Binding Path=ChampionVM.Image, Converter={StaticResource Base64ToImageConv}}"/>
<StackLayout Orientation="Horizontal" Padding="0,0,0,20"> <StackLayout Orientation="Horizontal" Padding="0,0,0,20">
<Label Text="{Binding Name}" <Label Text="{Binding ChampionVM.Name}"
HorizontalOptions="Start" HorizontalOptions="Start"
FontSize="Title"/> FontSize="Title"/>
<Image HorizontalOptions="End"/> <Image HorizontalOptions="End"/>
</StackLayout> </StackLayout>
<Label Text="{Binding Bio}"/> <Label Text="{Binding ChampionVM.Bio}"/>
<Label Text="Characteristics" <Label Text="Characteristics"
FontSize="Title" FontSize="Title"
Padding="0,0,0,20"/> Padding="0,0,0,20"/>
<CollectionView ItemsSource="{Binding Characteristics}" <CollectionView ItemsSource="{Binding ChampionVM.Characteristics}"
ItemsLayout="VerticalGrid, 3"> ItemsLayout="VerticalGrid, 3">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>

@ -1,20 +1,26 @@
using ViewModel; using App.ViewModel;
using ViewModel;
namespace App.Pages; namespace App.Pages;
public partial class ChampionDetailPage : ContentPage public partial class ChampionDetailPage : ContentPage
{ {
#region Properties
public ChampionDetailPageVM ChampionDetailPageVM { get; private set; }
public ChampionManagerVM ChampionManagerVM { get; private set; }
public ChampionVM ChampionVM { get; private set; } public ChampionVM ChampionVM { get; private set; }
public ChampionDetailPage() #endregion
{
//ChampionVM = championVM;
InitializeComponent();
BindingContext = ChampionVM;
}
async void ToolbarItem_Clicked(System.Object sender, System.EventArgs e) public ChampionDetailPage(ChampionDetailPageVM championDetailPageVM, ChampionManagerVM championManagerVM)
{ {
await Navigation.PushModalAsync(new ChampionAddEditPage()); ChampionDetailPageVM = championDetailPageVM;
ChampionManagerVM = championManagerVM;
ChampionVM = ChampionManagerVM.SelectedChampion;
ChampionDetailPageVM.Navigation = Navigation;
InitializeComponent();
BindingContext = this;
} }
} }

@ -6,12 +6,17 @@
x:Class="App.Pages.ChampionsListPage" x:Class="App.Pages.ChampionsListPage"
Title="Champions"> Title="Champions">
<ContentPage.ToolbarItems> <ContentPage.ToolbarItems>
<ToolbarItem Text="Add" Command="{Binding NaviagteToChampionAddEditPageCommand}"/> <ToolbarItem Text="Add"
Command="{Binding NaviagteToChampionAddEditPageCommand}"/>
</ContentPage.ToolbarItems> </ContentPage.ToolbarItems>
<ContentPage.Resources> <ContentPage.Resources>
<converters:Base64ToImage x:Key="Base64ToImageConv"/> <converters:Base64ToImage x:Key="Base64ToImageConv"/>
<ResourceDictionary>
<toolkit:SelectedItemEventArgsConverter x:Key="SelectedItemEventArgsConverter" />
</ResourceDictionary>
<Style TargetType="Button"> <Style TargetType="Button">
<Setter Property="WidthRequest">40</Setter> <Setter Property="WidthRequest">40</Setter>
<Setter Property="HeightRequest">20</Setter> <Setter Property="HeightRequest">20</Setter>
@ -29,10 +34,11 @@
SelectionMode="Single"> SelectionMode="Single">
<ListView.Behaviors> <ListView.Behaviors>
<toolkit:EventToCommandBehavior <toolkit:EventToCommandBehavior
x:TypeArguments="SelectedItemChangedEventArgs"
EventName="ItemSelected" EventName="ItemSelected"
Command="{Binding NavigateToChampionDetailCommand}"/> Command="{Binding NavigateToChampionDetailCommand}"/>
</ListView.Behaviors> </ListView.Behaviors>
<ListView.ItemTemplate> <ListView.ItemTemplate>
<DataTemplate> <DataTemplate>
<ViewCell> <ViewCell>
@ -40,25 +46,24 @@
<SwipeView.RightItems> <SwipeView.RightItems>
<SwipeItems> <SwipeItems>
<SwipeItem Text="Delete" <SwipeItem Text="Delete"
BackgroundColor="{StaticResource DeleteColor}"/> BackgroundColor="{StaticResource DeleteColor}"
IsDestructive="True"/>
<SwipeItem Text="Edit" <SwipeItem Text="Edit"
BackgroundColor="{StaticResource EditColor}"/> BackgroundColor="{StaticResource EditColor}"
Command="{Binding NaviagteToChampionAddEditPageCommand}"
CommandParameter="{Binding .}"/>
</SwipeItems> </SwipeItems>
</SwipeView.RightItems> </SwipeView.RightItems>
<Grid> <SwipeView.Content>
<Grid.ColumnDefinitions> <StackLayout Orientation="Horizontal" Padding="10">
<ColumnDefinition Width="*"/> <Image Source="{Binding Path=Icon, Converter={StaticResource Base64ToImageConv}}"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="{Binding Path=Icon, Converter={StaticResource Base64ToImageConv}}"/>
<StackLayout Grid.Column="1"> <StackLayout Grid.Column="1">
<Label Text="{Binding Name}"/> <Label Text="{Binding Name}"/>
</StackLayout> </StackLayout>
</Grid> </StackLayout>
</SwipeView.Content>
</SwipeView> </SwipeView>
</ViewCell> </ViewCell>
</DataTemplate> </DataTemplate>

@ -1,5 +1,4 @@
using ViewModel; using App.ViewModel;
using App.ViewModel;
namespace App.Pages; namespace App.Pages;
@ -10,7 +9,7 @@ public partial class ChampionsListPage : ContentPage
public ChampionsListPage(ChampionListPageVM championListPageVM) public ChampionsListPage(ChampionListPageVM championListPageVM)
{ {
ChampionListPageVM = championListPageVM; ChampionListPageVM = championListPageVM;
ChampionListPageVM.Navigation = this.Navigation; ChampionListPageVM.Navigation = Navigation;
InitializeComponent(); InitializeComponent();
BindingContext = ChampionListPageVM; BindingContext = ChampionListPageVM;
} }

@ -0,0 +1,31 @@
using System;
using System.Windows.Input;
using ViewModel;
using App.Pages;
namespace App.ViewModel
{
public class ChampionDetailPageVM
{
#region Properties
public INavigation Navigation { get; set; }
#endregion
#region Commands
public ICommand NaviagteToChampionAddEditPageCommand { get; private set; }
#endregion
public ChampionDetailPageVM()
{
NaviagteToChampionAddEditPageCommand = new Command(
execute: async () => await Navigation.PushModalAsync(new ChampionAddEditPage()),
canExecute: () => Navigation is not null
);
}
}
}

@ -1,5 +1,4 @@
using System; using System.Windows.Input;
using System.Windows.Input;
using App.Pages; using App.Pages;
using ViewModel; using ViewModel;
@ -7,27 +6,37 @@ namespace App.ViewModel
{ {
public class ChampionListPageVM public class ChampionListPageVM
{ {
public INavigation Navigation { get; set; } #region Properties
public INavigation Navigation { get; set; }
public ChampionManagerVM ChampionManagerVM { get; private set; } public ChampionManagerVM ChampionManagerVM { get; private set; }
#endregion
#region Commands
public ICommand NavigateToChampionDetailCommand { get; private set; } public ICommand NavigateToChampionDetailCommand { get; private set; }
public ICommand NaviagteToChampionAddEditPageCommand { get; private set; } public ICommand NaviagteToChampionAddEditPageCommand { get; private set; }
#endregion
public ChampionListPageVM(ChampionManagerVM championManager) public ChampionListPageVM(ChampionManagerVM championManager)
{ {
ChampionManagerVM = championManager; ChampionManagerVM = championManager;
NavigateToChampionDetailCommand = new Command ( NavigateToChampionDetailCommand = new Command<ChampionVM>(
execute: async () => await Shell.Current.GoToAsync(nameof(ChampionDetailPage)), execute: async (selectedChampion) =>
canExecute: () => ChampionManagerVM is not null {
ChampionManagerVM.SelectedChampion = selectedChampion;
await Shell.Current.GoToAsync(nameof(ChampionDetailPage));
},
canExecute: (selectedChampion) => ChampionManagerVM is not null && selectedChampion is not null
); );
NaviagteToChampionAddEditPageCommand = new Command( NaviagteToChampionAddEditPageCommand = new Command<ChampionVM>(
execute: async () => await Navigation.PushModalAsync(new ChampionAddEditPage()), execute: async (selectedChampion) => await Navigation.PushModalAsync(new ChampionAddEditPage()),
canExecute: () => ChampionManagerVM is not null canExecute: (selectedChampion) => ChampionManagerVM is not null && Navigation is not null
); );
} }
} }
} }

@ -42,6 +42,8 @@ namespace ViewModel
public int Count { get; set; } = 5; public int Count { get; set; } = 5;
public ChampionVM SelectedChampion { get; set; }
#endregion #endregion
#region Commands #region Commands

Loading…
Cancel
Save